prizmkit 1.1.198 → 1.1.200
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/bundled/VERSION.json +3 -3
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +65 -8
- package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +52 -9
- package/bundled/dev-pipeline/prizmkit_runtime/runners.py +188 -22
- package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +257 -1
- package/bundled/skills/_metadata.json +1 -1
- package/package.json +1 -1
package/bundled/VERSION.json
CHANGED
|
@@ -295,21 +295,43 @@ def _wip_pathspecs(paths: Sequence[str] | None) -> tuple[str, ...]:
|
|
|
295
295
|
return _literal_pathspecs(paths) if paths is not None else (".",)
|
|
296
296
|
|
|
297
297
|
|
|
298
|
+
def partition_addable_paths(
|
|
299
|
+
add_paths: Sequence[str],
|
|
300
|
+
indexed_result: GitCommandResult,
|
|
301
|
+
) -> tuple[tuple[str, ...], tuple[str, ...]]:
|
|
302
|
+
"""Split addable paths into tracked index entries and untracked paths."""
|
|
303
|
+
indexed_paths = {path for path in indexed_result.stdout.split("\0") if path}
|
|
304
|
+
tracked = tuple(path for path in add_paths if path in indexed_paths)
|
|
305
|
+
untracked = tuple(path for path in add_paths if path not in indexed_paths)
|
|
306
|
+
return tracked, untracked
|
|
307
|
+
|
|
308
|
+
|
|
298
309
|
def branch_save_wip_plan(
|
|
299
310
|
context: BranchContext,
|
|
300
311
|
*,
|
|
301
312
|
commit_paths: Sequence[str] | None = None,
|
|
302
313
|
add_paths: Sequence[str] | None = None,
|
|
314
|
+
tracked_add_paths: Sequence[str] | None = None,
|
|
303
315
|
) -> GitCommandPlan:
|
|
304
316
|
"""Plan WIP preservation that fails when task state cannot be committed."""
|
|
305
317
|
commit_pathspecs = _wip_pathspecs(commit_paths)
|
|
306
|
-
add_pathspecs = _wip_pathspecs(add_paths if add_paths is not None else commit_paths)
|
|
307
318
|
commands = [
|
|
308
319
|
_git("rev-parse", "--abbrev-ref", "HEAD", description="verify current branch"),
|
|
309
320
|
_git("ls-files", "-u", description="require no unmerged paths before WIP commit"),
|
|
310
321
|
]
|
|
311
|
-
if
|
|
312
|
-
|
|
322
|
+
if tracked_add_paths is None:
|
|
323
|
+
add_pathspecs = _wip_pathspecs(add_paths if add_paths is not None else commit_paths)
|
|
324
|
+
if add_pathspecs:
|
|
325
|
+
commands.append(_git("add", "-A", "--", *add_pathspecs, description="stage Git-visible work"))
|
|
326
|
+
else:
|
|
327
|
+
if tracked_add_paths:
|
|
328
|
+
commands.append(
|
|
329
|
+
_git("add", "-u", "--", *_literal_pathspecs(tracked_add_paths), description="stage tracked Git-visible work")
|
|
330
|
+
)
|
|
331
|
+
if add_paths:
|
|
332
|
+
commands.append(
|
|
333
|
+
_git("add", "-A", "--", *_literal_pathspecs(add_paths), description="stage untracked Git-visible work")
|
|
334
|
+
)
|
|
313
335
|
commands.extend(
|
|
314
336
|
(
|
|
315
337
|
_git(
|
|
@@ -343,18 +365,41 @@ def branch_ensure_return_plan(
|
|
|
343
365
|
*,
|
|
344
366
|
commit_paths: Sequence[str] | None = None,
|
|
345
367
|
add_paths: Sequence[str] | None = None,
|
|
368
|
+
tracked_add_paths: Sequence[str] | None = None,
|
|
346
369
|
) -> GitCommandPlan:
|
|
347
370
|
"""Plan a fail-closed WIP commit followed by a clean base return."""
|
|
348
371
|
commit_pathspecs = _wip_pathspecs(commit_paths)
|
|
349
|
-
add_pathspecs = _wip_pathspecs(add_paths if add_paths is not None else commit_paths)
|
|
350
372
|
commands = [
|
|
351
373
|
_git("rebase", "--abort", allow_failure=True, description="abort in-progress rebase"),
|
|
352
374
|
_git("rev-parse", "--abbrev-ref", "HEAD", description="detect current branch"),
|
|
353
375
|
_git("ls-files", "-u", description="require no unmerged paths before WIP commit"),
|
|
354
376
|
_git("status", "--porcelain", "--", ".", *HIDDEN_TOOL_WORKTREE_EXCLUDES, description="detect WIP before checkout"),
|
|
355
377
|
]
|
|
356
|
-
if
|
|
357
|
-
|
|
378
|
+
if tracked_add_paths is None:
|
|
379
|
+
add_pathspecs = _wip_pathspecs(add_paths if add_paths is not None else commit_paths)
|
|
380
|
+
if add_pathspecs:
|
|
381
|
+
commands.append(_git("add", "-A", "--", *add_pathspecs, description="stage Git-visible WIP before checkout"))
|
|
382
|
+
else:
|
|
383
|
+
if tracked_add_paths:
|
|
384
|
+
commands.append(
|
|
385
|
+
_git(
|
|
386
|
+
"add",
|
|
387
|
+
"-u",
|
|
388
|
+
"--",
|
|
389
|
+
*_literal_pathspecs(tracked_add_paths),
|
|
390
|
+
description="stage tracked Git-visible WIP before checkout",
|
|
391
|
+
)
|
|
392
|
+
)
|
|
393
|
+
if add_paths:
|
|
394
|
+
commands.append(
|
|
395
|
+
_git(
|
|
396
|
+
"add",
|
|
397
|
+
"-A",
|
|
398
|
+
"--",
|
|
399
|
+
*_literal_pathspecs(add_paths),
|
|
400
|
+
description="stage untracked Git-visible WIP before checkout",
|
|
401
|
+
)
|
|
402
|
+
)
|
|
358
403
|
commands.extend(
|
|
359
404
|
(
|
|
360
405
|
_git(
|
|
@@ -543,9 +588,15 @@ def branch_save_wip(project_root: Path, working_branch: str) -> GitPlanResult:
|
|
|
543
588
|
add_paths, indexed = addable_task_paths(project_root, paths)
|
|
544
589
|
if indexed.return_code != 0:
|
|
545
590
|
return _status_failure_plan(default_plan.name, indexed, "resolve task-visible WIP paths")
|
|
591
|
+
tracked_add, untracked_add = partition_addable_paths(add_paths, indexed)
|
|
546
592
|
return run_git_plan(
|
|
547
593
|
project_root,
|
|
548
|
-
branch_save_wip_plan(
|
|
594
|
+
branch_save_wip_plan(
|
|
595
|
+
context,
|
|
596
|
+
commit_paths=paths,
|
|
597
|
+
add_paths=untracked_add,
|
|
598
|
+
tracked_add_paths=tracked_add,
|
|
599
|
+
),
|
|
549
600
|
)
|
|
550
601
|
|
|
551
602
|
|
|
@@ -767,9 +818,15 @@ def branch_ensure_return(project_root: Path, base_branch: str, working_branch: s
|
|
|
767
818
|
add_paths, indexed = addable_task_paths(project_root, paths)
|
|
768
819
|
if indexed.return_code != 0:
|
|
769
820
|
return _status_failure_plan("branch_ensure_return", indexed, "resolve task-visible WIP paths before base return")
|
|
821
|
+
tracked_add, untracked_add = partition_addable_paths(add_paths, indexed)
|
|
770
822
|
return run_git_plan(
|
|
771
823
|
project_root,
|
|
772
|
-
branch_ensure_return_plan(
|
|
824
|
+
branch_ensure_return_plan(
|
|
825
|
+
context,
|
|
826
|
+
commit_paths=paths,
|
|
827
|
+
add_paths=untracked_add,
|
|
828
|
+
tracked_add_paths=tracked_add,
|
|
829
|
+
),
|
|
773
830
|
)
|
|
774
831
|
|
|
775
832
|
|
|
@@ -19,6 +19,7 @@ from .gitops import (
|
|
|
19
19
|
addable_task_paths,
|
|
20
20
|
literal_pathspecs,
|
|
21
21
|
parse_status_record_paths,
|
|
22
|
+
partition_addable_paths,
|
|
22
23
|
run_git_command,
|
|
23
24
|
visible_task_paths,
|
|
24
25
|
)
|
|
@@ -182,6 +183,43 @@ def _changed_paths_in(project_root: Path, paths: Sequence[str]) -> tuple[str, ..
|
|
|
182
183
|
return parse_status_record_paths(result.stdout)
|
|
183
184
|
|
|
184
185
|
|
|
186
|
+
def _stage_exact_paths(
|
|
187
|
+
project_root: Path,
|
|
188
|
+
paths: Sequence[str],
|
|
189
|
+
*,
|
|
190
|
+
add_paths: Sequence[str] | None = None,
|
|
191
|
+
indexed_result: GitCommandResult | None = None,
|
|
192
|
+
) -> GitCommandResult | None:
|
|
193
|
+
"""Stage tracked entries via ``git add -u`` and untracked entries via ``git add -A``.
|
|
194
|
+
|
|
195
|
+
Passing an already-tracked path under an ignored parent directory to ``git add -A``
|
|
196
|
+
causes Git to exit 1 with an ignored-file hint; using ``add -u`` for indexed paths
|
|
197
|
+
avoids false staging failures while keeping untracked ignored paths excluded.
|
|
198
|
+
"""
|
|
199
|
+
if add_paths is None or indexed_result is None:
|
|
200
|
+
add_paths, indexed_result = addable_task_paths(project_root, paths)
|
|
201
|
+
if indexed_result.return_code != 0:
|
|
202
|
+
return indexed_result
|
|
203
|
+
if not add_paths:
|
|
204
|
+
return None
|
|
205
|
+
tracked_paths, untracked_paths = partition_addable_paths(add_paths, indexed_result)
|
|
206
|
+
if tracked_paths:
|
|
207
|
+
tracked_add = run_git_command(
|
|
208
|
+
project_root,
|
|
209
|
+
("add", "-u", "--", *literal_pathspecs(tracked_paths)),
|
|
210
|
+
)
|
|
211
|
+
if tracked_add.return_code != 0:
|
|
212
|
+
return tracked_add
|
|
213
|
+
if untracked_paths:
|
|
214
|
+
untracked_add = run_git_command(
|
|
215
|
+
project_root,
|
|
216
|
+
("add", "-A", "--", *literal_pathspecs(untracked_paths)),
|
|
217
|
+
)
|
|
218
|
+
if untracked_add.return_code != 0:
|
|
219
|
+
return untracked_add
|
|
220
|
+
return None
|
|
221
|
+
|
|
222
|
+
|
|
185
223
|
def commit_bookkeeping_changes(
|
|
186
224
|
project_root: Path,
|
|
187
225
|
family: RunnerFamily,
|
|
@@ -197,10 +235,10 @@ def commit_bookkeeping_changes(
|
|
|
197
235
|
)
|
|
198
236
|
if not paths:
|
|
199
237
|
return BookkeepingResult(attempted=False, committed=False)
|
|
238
|
+
stage_failure = _stage_exact_paths(project_root, paths)
|
|
239
|
+
if stage_failure is not None:
|
|
240
|
+
return BookkeepingResult(attempted=True, committed=False, result=stage_failure)
|
|
200
241
|
pathspecs = literal_pathspecs(paths)
|
|
201
|
-
add = run_git_command(project_root, ("add", "-A", "--", *pathspecs))
|
|
202
|
-
if add.return_code != 0:
|
|
203
|
-
return BookkeepingResult(attempted=True, committed=False, result=add)
|
|
204
242
|
result = run_git_command(project_root, ("commit", "--no-verify", "-m", message, "--", *pathspecs))
|
|
205
243
|
return BookkeepingResult(attempted=True, committed=result.return_code == 0, result=result)
|
|
206
244
|
|
|
@@ -279,9 +317,14 @@ def _commit_visible_task_paths(project_root: Path, commit_message_args: tuple[st
|
|
|
279
317
|
if indexed_result.return_code != 0:
|
|
280
318
|
return BookkeepingResult(attempted=True, committed=False, result=indexed_result)
|
|
281
319
|
if add_paths:
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
320
|
+
stage_failure = _stage_exact_paths(
|
|
321
|
+
project_root,
|
|
322
|
+
paths,
|
|
323
|
+
add_paths=add_paths,
|
|
324
|
+
indexed_result=indexed_result,
|
|
325
|
+
)
|
|
326
|
+
if stage_failure is not None:
|
|
327
|
+
return BookkeepingResult(attempted=True, committed=False, result=stage_failure)
|
|
285
328
|
result = run_git_command(
|
|
286
329
|
project_root,
|
|
287
330
|
("commit", "--no-verify", *commit_message_args, "--", *literal_pathspecs(paths)),
|
|
@@ -394,10 +437,10 @@ def sync_terminal_failure_bookkeeping_to_base(
|
|
|
394
437
|
changed = _changed_paths_in(project_root, git_candidates)
|
|
395
438
|
if not changed:
|
|
396
439
|
return BookkeepingResult(attempted=False, committed=False)
|
|
440
|
+
stage_failure = _stage_exact_paths(project_root, changed)
|
|
441
|
+
if stage_failure is not None:
|
|
442
|
+
return BookkeepingResult(attempted=True, committed=False, result=stage_failure)
|
|
397
443
|
pathspecs = literal_pathspecs(changed)
|
|
398
|
-
add = run_git_command(project_root, ("add", "-A", "--", *pathspecs))
|
|
399
|
-
if add.return_code != 0:
|
|
400
|
-
return BookkeepingResult(attempted=True, committed=False, result=add)
|
|
401
444
|
commit = run_git_command(
|
|
402
445
|
project_root,
|
|
403
446
|
("commit", "--no-verify", "-m", f"chore({item_id}): record {family.kind} status {status}", "--", *pathspecs),
|
|
@@ -10,7 +10,7 @@ import sys
|
|
|
10
10
|
import tempfile
|
|
11
11
|
import threading
|
|
12
12
|
import time
|
|
13
|
-
from collections.abc import Iterator, Mapping
|
|
13
|
+
from collections.abc import Iterator, Mapping, Sequence
|
|
14
14
|
from contextlib import contextmanager
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
|
|
@@ -286,6 +286,62 @@ def _emit_warning(message: str) -> None:
|
|
|
286
286
|
_emit_info(message, level="WARN")
|
|
287
287
|
|
|
288
288
|
|
|
289
|
+
def _emit_bookkeeping_failure(label: str, item_id: str, result_obj) -> None:
|
|
290
|
+
"""Emit structured Git failure diagnostics without altering flow control."""
|
|
291
|
+
git_result = getattr(result_obj, "result", None)
|
|
292
|
+
if git_result is None:
|
|
293
|
+
return
|
|
294
|
+
args = " ".join(str(arg) for arg in getattr(git_result, "args", ())) or "(unknown)"
|
|
295
|
+
return_code = getattr(git_result, "return_code", None)
|
|
296
|
+
_emit_warning(f"{label} failed for {item_id} (git {args}, exit={return_code})")
|
|
297
|
+
detail = str(getattr(git_result, "stderr", "") or getattr(git_result, "stdout", "")).strip()
|
|
298
|
+
for line in detail.splitlines()[:3]:
|
|
299
|
+
text = line.strip()
|
|
300
|
+
if text:
|
|
301
|
+
_emit_warning(f" {text[:300]}")
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def _load_item_metadata_from_list(list_path: Path, family: RunnerFamily, item_id: str) -> dict[str, object]:
|
|
305
|
+
"""Read title/description metadata for one item from its plan list when available."""
|
|
306
|
+
if not item_id or not list_path.is_file():
|
|
307
|
+
return {}
|
|
308
|
+
try:
|
|
309
|
+
payload = json.loads(list_path.read_text(encoding="utf-8"))
|
|
310
|
+
except (OSError, ValueError, TypeError):
|
|
311
|
+
return {}
|
|
312
|
+
if not isinstance(payload, Mapping):
|
|
313
|
+
return {}
|
|
314
|
+
items = payload.get(family.list_key)
|
|
315
|
+
if not isinstance(items, list):
|
|
316
|
+
return {}
|
|
317
|
+
for entry in items:
|
|
318
|
+
if not isinstance(entry, Mapping) or str(entry.get("id") or "") != item_id:
|
|
319
|
+
continue
|
|
320
|
+
loaded: dict[str, object] = {}
|
|
321
|
+
for key in ("title", "description"):
|
|
322
|
+
value = entry.get(key)
|
|
323
|
+
if isinstance(value, str) and value.strip():
|
|
324
|
+
loaded[key] = value
|
|
325
|
+
return loaded
|
|
326
|
+
return {}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def _enrich_item_metadata(
|
|
330
|
+
metadata: Mapping[str, object] | None,
|
|
331
|
+
list_path: Path,
|
|
332
|
+
family: RunnerFamily,
|
|
333
|
+
item_id: str,
|
|
334
|
+
) -> dict[str, object]:
|
|
335
|
+
"""Ensure item metadata includes title/description when the caller omitted them."""
|
|
336
|
+
enriched = dict(metadata or {})
|
|
337
|
+
if enriched.get("title") and enriched.get("description"):
|
|
338
|
+
return enriched
|
|
339
|
+
for key, value in _load_item_metadata_from_list(list_path, family, item_id).items():
|
|
340
|
+
if not enriched.get(key):
|
|
341
|
+
enriched[key] = value
|
|
342
|
+
return enriched
|
|
343
|
+
|
|
344
|
+
|
|
289
345
|
def _family_label(family: RunnerFamily) -> str:
|
|
290
346
|
return {"feature": "Feature", "bugfix": "Bug"}.get(family.kind, family.kind.title())
|
|
291
347
|
|
|
@@ -648,7 +704,8 @@ def _preview_item(
|
|
|
648
704
|
if not config.ai_client.command:
|
|
649
705
|
raise RuntimeError("No supported AI CLI command was found")
|
|
650
706
|
_validate_effort_config(config)
|
|
651
|
-
|
|
707
|
+
enriched_initial = _enrich_item_metadata(initial_metadata, invocation.list_path, family, item_id)
|
|
708
|
+
metadata = _with_recovery_metadata(family, item_id, enriched_initial)
|
|
652
709
|
retry_count = int(metadata.get("retry_count") or 0)
|
|
653
710
|
session_id = f"{item_id}-dry-run"
|
|
654
711
|
_emit_item_header(family, invocation, item_id, metadata, paths)
|
|
@@ -712,7 +769,8 @@ def _process_item_locked(
|
|
|
712
769
|
checkout = load_task_checkout(family.state_dir, family.task_type, item_id)
|
|
713
770
|
if checkout is not None and checkout.is_completed:
|
|
714
771
|
raise RuntimeError(f"Task {item_id} is completed; run explicit reset or clean before rerunning")
|
|
715
|
-
|
|
772
|
+
enriched_initial = _enrich_item_metadata(initial_metadata, invocation.list_path, family, item_id)
|
|
773
|
+
metadata = _with_recovery_metadata(family, item_id, enriched_initial, checkout)
|
|
716
774
|
base_branch = _resolve_base_branch(paths.project_root, metadata, active_branch, family, item_id)
|
|
717
775
|
branch_name = _resolve_working_branch(family, item_id, metadata, env, active_branch, paths.project_root)
|
|
718
776
|
branch_context = BranchContext(base_branch, branch_name, paths.project_root)
|
|
@@ -903,16 +961,20 @@ def _process_item_locked(
|
|
|
903
961
|
base_branch,
|
|
904
962
|
recovered_session_id,
|
|
905
963
|
session_paths,
|
|
964
|
+
artifact_path=recovery_artifact,
|
|
965
|
+
metadata=metadata,
|
|
906
966
|
)
|
|
907
967
|
start = start_item(status_family, status_invocation, item_id, status_root)
|
|
908
968
|
if not start.ok:
|
|
909
969
|
raise RuntimeError(start.text)
|
|
910
|
-
commit_pre_branch_bookkeeping(
|
|
970
|
+
pre_bookkeeping = commit_pre_branch_bookkeeping(
|
|
911
971
|
status_root,
|
|
912
972
|
status_family,
|
|
913
973
|
item_id,
|
|
914
974
|
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
915
975
|
)
|
|
976
|
+
if getattr(pre_bookkeeping, "attempted", False) and not getattr(pre_bookkeeping, "ok", True):
|
|
977
|
+
_emit_bookkeeping_failure("pre-branch bookkeeping", item_id, pre_bookkeeping)
|
|
916
978
|
|
|
917
979
|
previous_fingerprint = metadata.get("last_progress_fingerprint")
|
|
918
980
|
previous_no_progress_count = int(metadata.get("no_progress_count") or 0)
|
|
@@ -1135,6 +1197,8 @@ def _process_item_locked(
|
|
|
1135
1197
|
session_id,
|
|
1136
1198
|
session_paths,
|
|
1137
1199
|
classification_fatal_error_code=classification.fatal_error_code,
|
|
1200
|
+
artifact_path=prompt.artifact_path,
|
|
1201
|
+
metadata=metadata,
|
|
1138
1202
|
)
|
|
1139
1203
|
if accepted_with_warning and completed_status == "completed":
|
|
1140
1204
|
reason = classification.reason or "no_semantic_completion"
|
|
@@ -1371,6 +1435,9 @@ def _finalize_recovered_success(
|
|
|
1371
1435
|
base_branch: str,
|
|
1372
1436
|
session_id: str,
|
|
1373
1437
|
session_paths: SessionPaths,
|
|
1438
|
+
*,
|
|
1439
|
+
artifact_path: Path | None = None,
|
|
1440
|
+
metadata: Mapping[str, object] | None = None,
|
|
1374
1441
|
) -> str:
|
|
1375
1442
|
update = update_item(
|
|
1376
1443
|
status_family,
|
|
@@ -1400,6 +1467,8 @@ def _finalize_recovered_success(
|
|
|
1400
1467
|
session_id,
|
|
1401
1468
|
session_paths,
|
|
1402
1469
|
classification_fatal_error_code="",
|
|
1470
|
+
artifact_path=artifact_path,
|
|
1471
|
+
metadata=metadata,
|
|
1403
1472
|
)
|
|
1404
1473
|
|
|
1405
1474
|
|
|
@@ -1410,8 +1479,15 @@ def _patch_completion_notes_if_present(
|
|
|
1410
1479
|
status_family: RunnerFamily,
|
|
1411
1480
|
status_invocation: RunnerInvocation,
|
|
1412
1481
|
item_id: str,
|
|
1482
|
+
*,
|
|
1483
|
+
artifact_path: Path | None = None,
|
|
1484
|
+
metadata: Mapping[str, object] | None = None,
|
|
1413
1485
|
) -> None:
|
|
1414
|
-
|
|
1486
|
+
resolved_artifact_dir = artifact_path
|
|
1487
|
+
if resolved_artifact_dir is None:
|
|
1488
|
+
resolved_metadata = _enrich_item_metadata(metadata, status_invocation.list_path, status_family, item_id)
|
|
1489
|
+
resolved_artifact_dir = _artifact_path_for_item(execution_root, status_family, item_id, resolved_metadata)
|
|
1490
|
+
summary_file = resolved_artifact_dir / "completion-summary.json"
|
|
1415
1491
|
pipeline_root = getattr(paths, "pipeline_root", None)
|
|
1416
1492
|
if pipeline_root is None or not summary_file.is_file() or not status_invocation.list_path.is_file():
|
|
1417
1493
|
return
|
|
@@ -1456,6 +1532,34 @@ def _patch_completion_notes_if_present(
|
|
|
1456
1532
|
_emit_info(f"Checked completion-summary.json for {item_id}; no non-empty completion notes patched")
|
|
1457
1533
|
|
|
1458
1534
|
|
|
1535
|
+
def _resolve_post_merge_artifact_dir(
|
|
1536
|
+
project_root: Path,
|
|
1537
|
+
execution_root: Path,
|
|
1538
|
+
status_family: RunnerFamily,
|
|
1539
|
+
status_invocation: RunnerInvocation,
|
|
1540
|
+
item_id: str,
|
|
1541
|
+
artifact_path: Path | None,
|
|
1542
|
+
metadata: Mapping[str, object] | None,
|
|
1543
|
+
) -> Path:
|
|
1544
|
+
if artifact_path is not None:
|
|
1545
|
+
if execution_root != project_root:
|
|
1546
|
+
try:
|
|
1547
|
+
rel = artifact_path.resolve().relative_to(execution_root.resolve())
|
|
1548
|
+
project_candidate = project_root / rel
|
|
1549
|
+
if (project_candidate / "retrospective-result.json").is_file():
|
|
1550
|
+
return project_candidate
|
|
1551
|
+
except (OSError, ValueError):
|
|
1552
|
+
pass
|
|
1553
|
+
return artifact_path
|
|
1554
|
+
resolved_metadata = _enrich_item_metadata(metadata, status_invocation.list_path, status_family, item_id)
|
|
1555
|
+
artifact_dir = _artifact_path_for_item(project_root, status_family, item_id, resolved_metadata)
|
|
1556
|
+
if not (artifact_dir / "retrospective-result.json").is_file() and execution_root != project_root:
|
|
1557
|
+
fallback_dir = _artifact_path_for_item(execution_root, status_family, item_id, resolved_metadata)
|
|
1558
|
+
if (fallback_dir / "retrospective-result.json").is_file():
|
|
1559
|
+
return fallback_dir
|
|
1560
|
+
return artifact_dir
|
|
1561
|
+
|
|
1562
|
+
|
|
1459
1563
|
def _complete_success_merge(
|
|
1460
1564
|
family: RunnerFamily,
|
|
1461
1565
|
item_id: str,
|
|
@@ -1472,6 +1576,8 @@ def _complete_success_merge(
|
|
|
1472
1576
|
session_paths: SessionPaths,
|
|
1473
1577
|
*,
|
|
1474
1578
|
classification_fatal_error_code: str = "",
|
|
1579
|
+
artifact_path: Path | None = None,
|
|
1580
|
+
metadata: Mapping[str, object] | None = None,
|
|
1475
1581
|
) -> str:
|
|
1476
1582
|
env = _runner_env_for_paths(paths)
|
|
1477
1583
|
if new_status == "completed":
|
|
@@ -1482,6 +1588,8 @@ def _complete_success_merge(
|
|
|
1482
1588
|
status_family,
|
|
1483
1589
|
status_invocation,
|
|
1484
1590
|
item_id,
|
|
1591
|
+
artifact_path=artifact_path,
|
|
1592
|
+
metadata=metadata,
|
|
1485
1593
|
)
|
|
1486
1594
|
final_bookkeeping = commit_final_bookkeeping(
|
|
1487
1595
|
status_root,
|
|
@@ -1491,9 +1599,21 @@ def _complete_success_merge(
|
|
|
1491
1599
|
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
1492
1600
|
)
|
|
1493
1601
|
task_commit = commit_task_branch_changes(execution_root, family, item_id, new_status)
|
|
1494
|
-
|
|
1602
|
+
final_bookkeeping_ok = getattr(final_bookkeeping, "ok", True)
|
|
1603
|
+
task_commit_ok = getattr(task_commit, "ok", True)
|
|
1604
|
+
finalization_committed = final_bookkeeping_ok and task_commit_ok
|
|
1495
1605
|
if not finalization_committed:
|
|
1496
1606
|
_emit_warning(f"Task finalization commit failed for {item_id}; merge was not attempted and the task checkout remains active")
|
|
1607
|
+
if not final_bookkeeping_ok:
|
|
1608
|
+
_emit_bookkeeping_failure("final bookkeeping", item_id, final_bookkeeping)
|
|
1609
|
+
if not task_commit_ok:
|
|
1610
|
+
_emit_bookkeeping_failure("task branch finalization", item_id, task_commit)
|
|
1611
|
+
if not final_bookkeeping_ok and not task_commit_ok:
|
|
1612
|
+
failure_reason = "finalization_commit_failed"
|
|
1613
|
+
elif not final_bookkeeping_ok:
|
|
1614
|
+
failure_reason = "finalization_bookkeeping_commit_failed"
|
|
1615
|
+
else:
|
|
1616
|
+
failure_reason = "finalization_task_commit_failed"
|
|
1497
1617
|
_write_session_status(
|
|
1498
1618
|
session_paths,
|
|
1499
1619
|
status="commit_missing",
|
|
@@ -1502,7 +1622,7 @@ def _complete_success_merge(
|
|
|
1502
1622
|
task_type=family.task_type,
|
|
1503
1623
|
base_branch=base_branch,
|
|
1504
1624
|
active_dev_branch=branch_name,
|
|
1505
|
-
reason=
|
|
1625
|
+
reason=failure_reason,
|
|
1506
1626
|
fatal_error_code=classification_fatal_error_code,
|
|
1507
1627
|
)
|
|
1508
1628
|
update = update_item(
|
|
@@ -1520,14 +1640,18 @@ def _complete_success_merge(
|
|
|
1520
1640
|
raise RuntimeError(update.text)
|
|
1521
1641
|
_emit_update_summary(family, item_id, update)
|
|
1522
1642
|
commit_missing_status = _status_from_update(update)
|
|
1523
|
-
commit_final_bookkeeping(
|
|
1643
|
+
fallback_bookkeeping = commit_final_bookkeeping(
|
|
1524
1644
|
status_root,
|
|
1525
1645
|
status_family,
|
|
1526
1646
|
item_id,
|
|
1527
1647
|
commit_missing_status,
|
|
1528
1648
|
**_bookkeeping_list_kwargs(status_family, status_invocation),
|
|
1529
1649
|
)
|
|
1530
|
-
|
|
1650
|
+
if getattr(fallback_bookkeeping, "attempted", False) and not getattr(fallback_bookkeeping, "ok", True):
|
|
1651
|
+
_emit_bookkeeping_failure("commit_missing bookkeeping", item_id, fallback_bookkeeping)
|
|
1652
|
+
wip = _save_failure_wip(execution_root, family, item_id, commit_missing_status)
|
|
1653
|
+
if getattr(wip, "attempted", False) and not getattr(wip, "ok", True):
|
|
1654
|
+
_emit_bookkeeping_failure("commit_missing WIP preservation", item_id, wip)
|
|
1531
1655
|
return commit_missing_status
|
|
1532
1656
|
|
|
1533
1657
|
_emit_info(f"Merging {branch_name} into {base_branch}...")
|
|
@@ -1549,12 +1673,22 @@ def _complete_success_merge(
|
|
|
1549
1673
|
raise RuntimeError(f"Task {item_id} checkout identity disappeared before completion")
|
|
1550
1674
|
complete_task_checkout_locked(family.state_dir, checkout)
|
|
1551
1675
|
_emit_success(f"Merged {branch_name} into {base_branch}")
|
|
1552
|
-
artifact_dir =
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1676
|
+
artifact_dir = _resolve_post_merge_artifact_dir(
|
|
1677
|
+
paths.project_root,
|
|
1678
|
+
execution_root,
|
|
1679
|
+
status_family,
|
|
1680
|
+
status_invocation,
|
|
1681
|
+
item_id,
|
|
1682
|
+
artifact_path,
|
|
1683
|
+
metadata,
|
|
1684
|
+
)
|
|
1685
|
+
_emit_pending_rule_proposals_for_item(
|
|
1686
|
+
family,
|
|
1687
|
+
item_id,
|
|
1688
|
+
artifact_dir,
|
|
1689
|
+
paths.project_root,
|
|
1690
|
+
metadata=metadata,
|
|
1691
|
+
)
|
|
1558
1692
|
return new_status
|
|
1559
1693
|
abort_in_progress_git_operation(paths.project_root)
|
|
1560
1694
|
_emit_warning(
|
|
@@ -1761,6 +1895,37 @@ def _latest_session_id(state_dir: Path, item_id: str) -> str:
|
|
|
1761
1895
|
return sorted(sessions)[-1] if sessions else ""
|
|
1762
1896
|
|
|
1763
1897
|
|
|
1898
|
+
def _spec_match_rank(candidate: Path, item_id: str, index: int) -> tuple[int, int, int, int]:
|
|
1899
|
+
"""Rank same-prefix spec directories so active v1 checkpoints beat legacy siblings."""
|
|
1900
|
+
checkpoint = candidate / "workflow-checkpoint.json"
|
|
1901
|
+
if not checkpoint.is_file():
|
|
1902
|
+
return (0, 0, 0, -index)
|
|
1903
|
+
try:
|
|
1904
|
+
data = json.loads(checkpoint.read_text(encoding="utf-8"))
|
|
1905
|
+
except (OSError, ValueError, TypeError):
|
|
1906
|
+
return (0, 0, 0, -index)
|
|
1907
|
+
if not isinstance(data, Mapping):
|
|
1908
|
+
return (0, 0, 0, -index)
|
|
1909
|
+
matches_item = int(str(data.get("item_id") or "") == item_id)
|
|
1910
|
+
has_active_v1 = int(
|
|
1911
|
+
bool(matches_item)
|
|
1912
|
+
and isinstance(data.get("feature_state"), Mapping)
|
|
1913
|
+
and bool(data.get("feature_state"))
|
|
1914
|
+
)
|
|
1915
|
+
try:
|
|
1916
|
+
mtime_ns = checkpoint.stat().st_mtime_ns if matches_item else 0
|
|
1917
|
+
except OSError:
|
|
1918
|
+
mtime_ns = 0
|
|
1919
|
+
return (has_active_v1, matches_item, mtime_ns, -index)
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
def _select_best_spec_match(matches: Sequence[Path], item_id: str) -> Path:
|
|
1923
|
+
return max(
|
|
1924
|
+
enumerate(matches),
|
|
1925
|
+
key=lambda pair: _spec_match_rank(pair[1], item_id, pair[0]),
|
|
1926
|
+
)[1]
|
|
1927
|
+
|
|
1928
|
+
|
|
1764
1929
|
def _artifact_path_for_item(project_root: Path, family: RunnerFamily, item_id: str, metadata: dict[str, object]) -> Path:
|
|
1765
1930
|
if family.kind == "feature":
|
|
1766
1931
|
title = str(metadata.get("title") or "")
|
|
@@ -1773,7 +1938,7 @@ def _artifact_path_for_item(project_root: Path, family: RunnerFamily, item_id: s
|
|
|
1773
1938
|
except OSError:
|
|
1774
1939
|
matches = []
|
|
1775
1940
|
if matches:
|
|
1776
|
-
return matches
|
|
1941
|
+
return _select_best_spec_match(matches, item_id)
|
|
1777
1942
|
return project_root / ".prizmkit" / family.artifact_root_name / item_id
|
|
1778
1943
|
|
|
1779
1944
|
|
|
@@ -1782,18 +1947,19 @@ def _emit_pending_rule_proposals_for_item(
|
|
|
1782
1947
|
item_id: str,
|
|
1783
1948
|
artifact_dir: Path | None,
|
|
1784
1949
|
project_root: Path,
|
|
1950
|
+
metadata: Mapping[str, object] | None = None,
|
|
1785
1951
|
) -> list[dict[str, str]]:
|
|
1786
1952
|
"""Log RULES_PROPOSED entries from retrospective-result.json on completion."""
|
|
1787
1953
|
candidate_dirs: list[Path] = []
|
|
1788
1954
|
if artifact_dir is not None:
|
|
1789
1955
|
candidate_dirs.append(artifact_dir)
|
|
1790
|
-
|
|
1791
|
-
|
|
1956
|
+
else:
|
|
1957
|
+
resolved_dir = _artifact_path_for_item(project_root, family, item_id, dict(metadata or {}))
|
|
1792
1958
|
candidate_dirs.append(resolved_dir)
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1959
|
+
if family.kind == "feature":
|
|
1960
|
+
exact_dir = project_root / ".prizmkit" / "specs" / item_id
|
|
1961
|
+
if exact_dir not in candidate_dirs:
|
|
1962
|
+
candidate_dirs.append(exact_dir)
|
|
1797
1963
|
|
|
1798
1964
|
result_file = next(
|
|
1799
1965
|
(candidate / "retrospective-result.json" for candidate in candidate_dirs if (candidate / "retrospective-result.json").is_file()),
|
|
@@ -12,9 +12,22 @@ from contextlib import nullcontext
|
|
|
12
12
|
from dataclasses import dataclass
|
|
13
13
|
from datetime import datetime, timezone
|
|
14
14
|
from pathlib import Path
|
|
15
|
+
from urllib.parse import urlparse
|
|
16
|
+
from urllib.request import url2pathname
|
|
15
17
|
|
|
16
18
|
from .atomic_io import write_json_atomic
|
|
17
19
|
|
|
20
|
+
_SAFE_ANTIGRAVITY_SESSION_ID_RE = re.compile(r"^[A-Za-z0-9._-]+$")
|
|
21
|
+
_ANTIGRAVITY_SUBAGENT_HEADER_RE = re.compile(r"(?:^|\r?\n)Created the following subagent:\s*\{")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _is_safe_antigravity_session_id(session_id: str) -> bool:
|
|
25
|
+
return bool(
|
|
26
|
+
session_id
|
|
27
|
+
and session_id not in {".", ".."}
|
|
28
|
+
and _SAFE_ANTIGRAVITY_SESSION_ID_RE.fullmatch(session_id)
|
|
29
|
+
)
|
|
30
|
+
|
|
18
31
|
# Ordered pipeline phases — index defines forward-only progression.
|
|
19
32
|
# Phase detection is monotonic: once a phase is reached, earlier phases
|
|
20
33
|
# cannot be re-entered (prevents false positives from file content mentions).
|
|
@@ -987,6 +1000,12 @@ class ProgressTracker:
|
|
|
987
1000
|
self._codex_child_session_paths = {}
|
|
988
1001
|
self._claude_child_session_files = []
|
|
989
1002
|
self._cb_child_session_files = []
|
|
1003
|
+
self._ag_child_session_ids = set()
|
|
1004
|
+
self._ag_child_log_uris = {}
|
|
1005
|
+
self._ag_child_session_files = {}
|
|
1006
|
+
self._ag_parent_transcript_path = ""
|
|
1007
|
+
self._ag_parent_transcript_offset = 0
|
|
1008
|
+
self._ag_parent_transcript_mtime_ns = 0
|
|
990
1009
|
self._last_child_scan_at = 0.0
|
|
991
1010
|
self._last_claude_fallback_scan_at = 0.0
|
|
992
1011
|
self._last_claude_fallback_scan_key = ""
|
|
@@ -1125,6 +1144,14 @@ class ProgressTracker:
|
|
|
1125
1144
|
error_text = _cursor_compact_value(tool_err, 500)
|
|
1126
1145
|
self._append_error(error_text)
|
|
1127
1146
|
self._detect_terminal_error(error_text, require_error_context=False)
|
|
1147
|
+
if tool_name == "invoke_subagent" and info.get("output") is not None:
|
|
1148
|
+
for child_id, log_uri in self._extract_antigravity_subagent_refs(
|
|
1149
|
+
info.get("output"),
|
|
1150
|
+
parent_session_id=self.antigravity_session_id,
|
|
1151
|
+
):
|
|
1152
|
+
self._ag_child_session_ids.add(child_id)
|
|
1153
|
+
if log_uri and child_id not in self._ag_child_log_uris:
|
|
1154
|
+
self._ag_child_log_uris[child_id] = log_uri
|
|
1128
1155
|
step_err = payload.get("error")
|
|
1129
1156
|
if step_err:
|
|
1130
1157
|
error_text = _cursor_compact_value(step_err, 500)
|
|
@@ -2613,6 +2640,195 @@ class ProgressTracker:
|
|
|
2613
2640
|
return []
|
|
2614
2641
|
return []
|
|
2615
2642
|
|
|
2643
|
+
def _antigravity_brain_dir(self) -> Path:
|
|
2644
|
+
"""Return the Antigravity brain directory for transcript lookup."""
|
|
2645
|
+
brain_dir = os.environ.get("ANTIGRAVITY_BRAIN_DIR")
|
|
2646
|
+
if brain_dir:
|
|
2647
|
+
return Path(brain_dir).expanduser()
|
|
2648
|
+
app_data = os.environ.get("ANTIGRAVITY_APP_DATA_DIR")
|
|
2649
|
+
if app_data:
|
|
2650
|
+
return Path(app_data).expanduser() / "brain"
|
|
2651
|
+
ag_home = os.environ.get("ANTIGRAVITY_HOME")
|
|
2652
|
+
if ag_home:
|
|
2653
|
+
return Path(ag_home).expanduser() / "brain"
|
|
2654
|
+
gemini_home = os.environ.get("GEMINI_HOME")
|
|
2655
|
+
if gemini_home:
|
|
2656
|
+
return Path(gemini_home).expanduser() / "antigravity-cli" / "brain"
|
|
2657
|
+
return Path.home() / ".gemini" / "antigravity-cli" / "brain"
|
|
2658
|
+
|
|
2659
|
+
def _extract_antigravity_subagent_refs(
|
|
2660
|
+
self,
|
|
2661
|
+
payload: object,
|
|
2662
|
+
*,
|
|
2663
|
+
parent_session_id: str,
|
|
2664
|
+
) -> list[tuple[str, str]]:
|
|
2665
|
+
"""Extract safe Antigravity child (conversationId, logAbsoluteUri) pairs."""
|
|
2666
|
+
refs: list[tuple[str, str]] = []
|
|
2667
|
+
seen: set[str] = set()
|
|
2668
|
+
|
|
2669
|
+
def add_ref(raw_obj: object) -> None:
|
|
2670
|
+
if not isinstance(raw_obj, dict):
|
|
2671
|
+
return
|
|
2672
|
+
raw_id = raw_obj.get("conversationId") or raw_obj.get("conversation_id")
|
|
2673
|
+
if not isinstance(raw_id, str):
|
|
2674
|
+
return
|
|
2675
|
+
child_id = raw_id.strip()
|
|
2676
|
+
if not _is_safe_antigravity_session_id(child_id) or child_id == parent_session_id or child_id in seen:
|
|
2677
|
+
return
|
|
2678
|
+
raw_uri = raw_obj.get("logAbsoluteUri") or raw_obj.get("log_absolute_uri")
|
|
2679
|
+
log_uri = raw_uri.strip() if isinstance(raw_uri, str) else ""
|
|
2680
|
+
seen.add(child_id)
|
|
2681
|
+
refs.append((child_id, log_uri))
|
|
2682
|
+
|
|
2683
|
+
if isinstance(payload, dict):
|
|
2684
|
+
add_ref(payload)
|
|
2685
|
+
nested = payload.get("content") or payload.get("output")
|
|
2686
|
+
if isinstance(nested, dict):
|
|
2687
|
+
add_ref(nested)
|
|
2688
|
+
return refs
|
|
2689
|
+
if isinstance(nested, str):
|
|
2690
|
+
payload = nested
|
|
2691
|
+
else:
|
|
2692
|
+
return refs
|
|
2693
|
+
|
|
2694
|
+
if isinstance(payload, str):
|
|
2695
|
+
decoder = json.JSONDecoder()
|
|
2696
|
+
for match in _ANTIGRAVITY_SUBAGENT_HEADER_RE.finditer(payload):
|
|
2697
|
+
prefix = payload[: match.start()]
|
|
2698
|
+
if (
|
|
2699
|
+
"Command exited with code " in prefix
|
|
2700
|
+
or "Command output:" in prefix
|
|
2701
|
+
or "Showing lines " in prefix
|
|
2702
|
+
or "Partial read (" in prefix
|
|
2703
|
+
):
|
|
2704
|
+
continue
|
|
2705
|
+
brace_idx = match.end() - 1
|
|
2706
|
+
try:
|
|
2707
|
+
parsed, _ = decoder.raw_decode(payload, brace_idx)
|
|
2708
|
+
except (ValueError, json.JSONDecodeError):
|
|
2709
|
+
continue
|
|
2710
|
+
add_ref(parsed)
|
|
2711
|
+
return refs
|
|
2712
|
+
|
|
2713
|
+
def _resolve_antigravity_child_transcript(
|
|
2714
|
+
self,
|
|
2715
|
+
*,
|
|
2716
|
+
brain_dir: Path,
|
|
2717
|
+
child_id: str,
|
|
2718
|
+
log_uri: str = "",
|
|
2719
|
+
) -> Path | None:
|
|
2720
|
+
"""Resolve an Antigravity subagent transcript path confined to brain_dir."""
|
|
2721
|
+
if not _is_safe_antigravity_session_id(child_id):
|
|
2722
|
+
return None
|
|
2723
|
+
candidate = brain_dir / child_id / ".system_generated" / "logs" / "transcript.jsonl"
|
|
2724
|
+
try:
|
|
2725
|
+
if candidate.is_file():
|
|
2726
|
+
return candidate
|
|
2727
|
+
except OSError:
|
|
2728
|
+
return None
|
|
2729
|
+
if log_uri.startswith("file://"):
|
|
2730
|
+
try:
|
|
2731
|
+
parsed = urlparse(log_uri)
|
|
2732
|
+
if parsed.scheme != "file" or parsed.netloc not in ("", "localhost"):
|
|
2733
|
+
return None
|
|
2734
|
+
raw_path = url2pathname(parsed.path)
|
|
2735
|
+
if not raw_path:
|
|
2736
|
+
return None
|
|
2737
|
+
brain_resolved = brain_dir.resolve()
|
|
2738
|
+
target_resolved = Path(raw_path).resolve()
|
|
2739
|
+
if target_resolved.is_relative_to(brain_resolved) and target_resolved.is_file():
|
|
2740
|
+
return target_resolved
|
|
2741
|
+
except (OSError, ValueError):
|
|
2742
|
+
return None
|
|
2743
|
+
return None
|
|
2744
|
+
|
|
2745
|
+
def _find_antigravity_child_session_files(
|
|
2746
|
+
self,
|
|
2747
|
+
*,
|
|
2748
|
+
ag_session_id: str,
|
|
2749
|
+
known_child_ids: set[str],
|
|
2750
|
+
known_log_uris: dict[str, str],
|
|
2751
|
+
cached_files: dict[str, Path],
|
|
2752
|
+
parent_transcript_path: str,
|
|
2753
|
+
parent_offset: int,
|
|
2754
|
+
parent_mtime_ns: int,
|
|
2755
|
+
) -> tuple[dict[str, Path], set[str], dict[str, str], str, int, int]:
|
|
2756
|
+
"""Incrementally discover and resolve Antigravity child subagent transcripts."""
|
|
2757
|
+
discovered_ids: set[str] = set()
|
|
2758
|
+
discovered_uris: dict[str, str] = {}
|
|
2759
|
+
found_files: dict[str, Path] = {}
|
|
2760
|
+
for child_id, cached_path in cached_files.items():
|
|
2761
|
+
try:
|
|
2762
|
+
if os.path.isfile(cached_path):
|
|
2763
|
+
found_files[child_id] = cached_path
|
|
2764
|
+
except OSError:
|
|
2765
|
+
continue
|
|
2766
|
+
|
|
2767
|
+
if not _is_safe_antigravity_session_id(ag_session_id):
|
|
2768
|
+
return found_files, discovered_ids, discovered_uris, parent_transcript_path, parent_offset, parent_mtime_ns
|
|
2769
|
+
|
|
2770
|
+
brain_dir = self._antigravity_brain_dir()
|
|
2771
|
+
parent_transcript = brain_dir / ag_session_id / ".system_generated" / "logs" / "transcript.jsonl"
|
|
2772
|
+
parent_path_str = str(parent_transcript)
|
|
2773
|
+
offset = parent_offset if parent_path_str == parent_transcript_path else 0
|
|
2774
|
+
mtime_ns = parent_mtime_ns if parent_path_str == parent_transcript_path else 0
|
|
2775
|
+
|
|
2776
|
+
try:
|
|
2777
|
+
stat = os.stat(parent_transcript)
|
|
2778
|
+
except OSError:
|
|
2779
|
+
stat = None
|
|
2780
|
+
|
|
2781
|
+
if stat is not None:
|
|
2782
|
+
cur_mtime_ns = getattr(stat, "st_mtime_ns", int(stat.st_mtime * 1_000_000_000))
|
|
2783
|
+
if stat.st_size < offset:
|
|
2784
|
+
offset = 0
|
|
2785
|
+
if stat.st_size > offset or cur_mtime_ns != mtime_ns:
|
|
2786
|
+
try:
|
|
2787
|
+
with open(parent_transcript, "rb") as fh:
|
|
2788
|
+
fh.seek(offset)
|
|
2789
|
+
chunk = fh.read()
|
|
2790
|
+
except OSError:
|
|
2791
|
+
chunk = b""
|
|
2792
|
+
if chunk:
|
|
2793
|
+
last_nl = chunk.rfind(b"\n")
|
|
2794
|
+
if last_nl >= 0:
|
|
2795
|
+
complete_block = chunk[: last_nl + 1]
|
|
2796
|
+
offset += last_nl + 1
|
|
2797
|
+
for raw_line in complete_block.splitlines():
|
|
2798
|
+
if b"Created the following subagent" not in raw_line:
|
|
2799
|
+
continue
|
|
2800
|
+
try:
|
|
2801
|
+
obj = json.loads(raw_line.decode("utf-8", errors="replace"))
|
|
2802
|
+
except (ValueError, json.JSONDecodeError):
|
|
2803
|
+
continue
|
|
2804
|
+
if not isinstance(obj, dict):
|
|
2805
|
+
continue
|
|
2806
|
+
if obj.get("type") not in (None, "", "GENERIC"):
|
|
2807
|
+
continue
|
|
2808
|
+
for child_id, log_uri in self._extract_antigravity_subagent_refs(
|
|
2809
|
+
obj.get("content"),
|
|
2810
|
+
parent_session_id=ag_session_id,
|
|
2811
|
+
):
|
|
2812
|
+
discovered_ids.add(child_id)
|
|
2813
|
+
if log_uri:
|
|
2814
|
+
discovered_uris[child_id] = log_uri
|
|
2815
|
+
mtime_ns = cur_mtime_ns
|
|
2816
|
+
|
|
2817
|
+
merged_uris = dict(known_log_uris)
|
|
2818
|
+
merged_uris.update(discovered_uris)
|
|
2819
|
+
for child_id in sorted(known_child_ids | discovered_ids):
|
|
2820
|
+
if child_id in found_files:
|
|
2821
|
+
continue
|
|
2822
|
+
resolved = self._resolve_antigravity_child_transcript(
|
|
2823
|
+
brain_dir=brain_dir,
|
|
2824
|
+
child_id=child_id,
|
|
2825
|
+
log_uri=merged_uris.get(child_id, ""),
|
|
2826
|
+
)
|
|
2827
|
+
if resolved is not None:
|
|
2828
|
+
found_files[child_id] = resolved
|
|
2829
|
+
|
|
2830
|
+
return found_files, discovered_ids, discovered_uris, parent_path_str, offset, mtime_ns
|
|
2831
|
+
|
|
2616
2832
|
def refresh_child_session_activity(self, force=False, *, lock=None):
|
|
2617
2833
|
"""Refresh child transcript file stats (safe to perform I/O outside lock)."""
|
|
2618
2834
|
lock_ctx = lock if lock is not None else nullcontext()
|
|
@@ -2626,8 +2842,13 @@ class ProgressTracker:
|
|
|
2626
2842
|
has_tracked_claude = self._has_tracked_claude_subagent_task()
|
|
2627
2843
|
cb_sid = self.cb_session_id if provider_hint in {"", "codebuddy"} and event_format in {"", "stream-json"} else ""
|
|
2628
2844
|
cb_cwd = self.cb_cwd
|
|
2845
|
+
ag_sid = (
|
|
2846
|
+
self.antigravity_session_id
|
|
2847
|
+
if provider_hint in {"", "antigravity"} and event_format in {"", "antigravity-stream-json"}
|
|
2848
|
+
else ""
|
|
2849
|
+
)
|
|
2629
2850
|
|
|
2630
|
-
if not codex_ids and not claude_sid and not cb_sid:
|
|
2851
|
+
if not codex_ids and not claude_sid and not cb_sid and not ag_sid:
|
|
2631
2852
|
self.child_session_files = []
|
|
2632
2853
|
self.child_total_bytes = 0
|
|
2633
2854
|
self.child_activity_signature = ""
|
|
@@ -2643,9 +2864,18 @@ class ProgressTracker:
|
|
|
2643
2864
|
codex_paths = dict(self._codex_child_session_paths)
|
|
2644
2865
|
claude_files = list(self._claude_child_session_files)
|
|
2645
2866
|
cb_files = list(self._cb_child_session_files)
|
|
2867
|
+
ag_known_ids = set(self._ag_child_session_ids)
|
|
2868
|
+
ag_known_uris = dict(self._ag_child_log_uris)
|
|
2869
|
+
ag_files = dict(self._ag_child_session_files)
|
|
2870
|
+
ag_parent_path = self._ag_parent_transcript_path
|
|
2871
|
+
ag_parent_offset = self._ag_parent_transcript_offset
|
|
2872
|
+
ag_parent_mtime_ns = self._ag_parent_transcript_mtime_ns
|
|
2646
2873
|
last_fallback_key = self._last_claude_fallback_scan_key
|
|
2647
2874
|
last_fallback_at = self._last_claude_fallback_scan_at
|
|
2648
2875
|
|
|
2876
|
+
ag_discovered_ids: set[str] = set()
|
|
2877
|
+
ag_discovered_uris: dict[str, str] = {}
|
|
2878
|
+
|
|
2649
2879
|
# Perform all filesystem probes & stats outside lock so stdout reader never stalls.
|
|
2650
2880
|
if should_scan:
|
|
2651
2881
|
for thread_id in codex_ids:
|
|
@@ -2667,6 +2897,23 @@ class ProgressTracker:
|
|
|
2667
2897
|
cached_files=claude_files,
|
|
2668
2898
|
)
|
|
2669
2899
|
cb_files = self._find_cb_child_session_files(cb_session_id=cb_sid, cb_cwd=cb_cwd)
|
|
2900
|
+
if ag_sid:
|
|
2901
|
+
(
|
|
2902
|
+
ag_files,
|
|
2903
|
+
ag_discovered_ids,
|
|
2904
|
+
ag_discovered_uris,
|
|
2905
|
+
ag_parent_path,
|
|
2906
|
+
ag_parent_offset,
|
|
2907
|
+
ag_parent_mtime_ns,
|
|
2908
|
+
) = self._find_antigravity_child_session_files(
|
|
2909
|
+
ag_session_id=ag_sid,
|
|
2910
|
+
known_child_ids=ag_known_ids,
|
|
2911
|
+
known_log_uris=ag_known_uris,
|
|
2912
|
+
cached_files=ag_files,
|
|
2913
|
+
parent_transcript_path=ag_parent_path,
|
|
2914
|
+
parent_offset=ag_parent_offset,
|
|
2915
|
+
parent_mtime_ns=ag_parent_mtime_ns,
|
|
2916
|
+
)
|
|
2670
2917
|
scan_completed_at = time.monotonic()
|
|
2671
2918
|
else:
|
|
2672
2919
|
scan_completed_at = None
|
|
@@ -2712,6 +2959,9 @@ class ProgressTracker:
|
|
|
2712
2959
|
identifier = parent_name if parent_name.startswith("agent-") else path.name
|
|
2713
2960
|
add_file("codebuddy", identifier, path)
|
|
2714
2961
|
|
|
2962
|
+
for child_id, path in sorted(ag_files.items()):
|
|
2963
|
+
add_file("antigravity", child_id, path)
|
|
2964
|
+
|
|
2715
2965
|
new_signature = "|".join(signature_parts)
|
|
2716
2966
|
last_activity_at = (
|
|
2717
2967
|
datetime.fromtimestamp(max_mtime, timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
@@ -2724,6 +2974,12 @@ class ProgressTracker:
|
|
|
2724
2974
|
self._codex_child_session_paths.update(codex_paths)
|
|
2725
2975
|
self._claude_child_session_files = claude_files
|
|
2726
2976
|
self._cb_child_session_files = cb_files
|
|
2977
|
+
self._ag_child_session_ids.update(ag_discovered_ids)
|
|
2978
|
+
self._ag_child_log_uris.update(ag_discovered_uris)
|
|
2979
|
+
self._ag_child_session_files = ag_files
|
|
2980
|
+
self._ag_parent_transcript_path = ag_parent_path
|
|
2981
|
+
self._ag_parent_transcript_offset = ag_parent_offset
|
|
2982
|
+
self._ag_parent_transcript_mtime_ns = ag_parent_mtime_ns
|
|
2727
2983
|
self._last_claude_fallback_scan_key = last_fallback_key
|
|
2728
2984
|
self._last_claude_fallback_scan_at = last_fallback_at
|
|
2729
2985
|
if scan_completed_at is not None:
|