prizmkit 1.1.190 → 1.1.192
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/bin/create-prizmkit.js +4 -4
- package/bundled/VERSION.json +3 -3
- package/bundled/adapters/antigravity/assets/prizmkit-hook.cjs +150 -0
- package/bundled/adapters/antigravity/hooks-adapter.js +195 -0
- package/bundled/adapters/antigravity/paths.js +14 -0
- package/bundled/adapters/antigravity/rules-adapter.js +54 -0
- package/bundled/adapters/antigravity/skill-adapter.js +38 -0
- package/bundled/adapters/codex/skill-adapter.js +28 -8
- package/bundled/adapters/cursor/skill-adapter.js +13 -4
- package/bundled/adapters/pi/skill-adapter.js +28 -7
- package/bundled/dev-pipeline/.env.example +4 -12
- package/bundled/dev-pipeline/README.md +21 -15
- package/bundled/dev-pipeline/assets/skill-subagent-integration.md +3 -6
- package/bundled/dev-pipeline/prizmkit_runtime/atomic_io.py +48 -0
- package/bundled/dev-pipeline/prizmkit_runtime/checkpoint_state.py +66 -23
- package/bundled/dev-pipeline/prizmkit_runtime/cli.py +10 -7
- package/bundled/dev-pipeline/prizmkit_runtime/commands.py +2 -21
- package/bundled/dev-pipeline/prizmkit_runtime/config.py +29 -70
- package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +125 -67
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +89 -442
- package/bundled/dev-pipeline/prizmkit_runtime/heartbeat.py +93 -49
- package/bundled/dev-pipeline/prizmkit_runtime/interoperability.py +1 -3
- package/bundled/dev-pipeline/prizmkit_runtime/paths.py +0 -6
- package/bundled/dev-pipeline/prizmkit_runtime/platform_detection.py +49 -18
- package/bundled/dev-pipeline/prizmkit_runtime/processes.py +206 -151
- package/bundled/dev-pipeline/prizmkit_runtime/reset.py +2 -23
- package/bundled/dev-pipeline/prizmkit_runtime/reset_preserve.py +15 -134
- package/bundled/dev-pipeline/prizmkit_runtime/results.py +25 -0
- package/bundled/dev-pipeline/prizmkit_runtime/runner_bookkeeping.py +68 -83
- package/bundled/dev-pipeline/prizmkit_runtime/runner_classification.py +15 -5
- package/bundled/dev-pipeline/prizmkit_runtime/runner_models.py +1 -29
- package/bundled/dev-pipeline/prizmkit_runtime/runner_prompts.py +0 -2
- package/bundled/dev-pipeline/prizmkit_runtime/runner_status.py +7 -2
- package/bundled/dev-pipeline/prizmkit_runtime/runners.py +282 -217
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_commit.py +124 -122
- package/bundled/dev-pipeline/prizmkit_runtime/runtime_helper.py +90 -9
- package/bundled/dev-pipeline/prizmkit_runtime/sessions.py +369 -154
- package/bundled/dev-pipeline/prizmkit_runtime/status.py +3 -3
- package/bundled/dev-pipeline/prizmkit_runtime/stream_progress.py +2780 -0
- package/bundled/dev-pipeline/prizmkit_runtime/task_checkout.py +27 -101
- package/bundled/dev-pipeline/prizmkit_runtime/test_result.py +58 -4
- package/bundled/dev-pipeline/scripts/check-session-status.py +43 -19
- package/bundled/dev-pipeline/scripts/continuation.py +6 -4
- package/bundled/dev-pipeline/scripts/detect-stuck.py +28 -28
- package/bundled/dev-pipeline/scripts/generate-bootstrap-prompt.py +7 -2
- package/bundled/dev-pipeline/scripts/generate-bugfix-prompt.py +7 -2
- package/bundled/dev-pipeline/scripts/init-bugfix-pipeline.py +10 -7
- package/bundled/dev-pipeline/scripts/init-change-artifact.py +8 -2
- package/bundled/dev-pipeline/scripts/init-pipeline.py +14 -69
- package/bundled/dev-pipeline/scripts/parse-stream-progress.py +31 -2328
- package/bundled/dev-pipeline/scripts/patch-completion-notes.py +4 -24
- package/bundled/dev-pipeline/scripts/prompt_framework.py +56 -9
- package/bundled/dev-pipeline/scripts/status_common.py +591 -0
- package/bundled/dev-pipeline/scripts/update-bug-status.py +85 -463
- package/bundled/dev-pipeline/scripts/update-checkpoint.py +227 -65
- package/bundled/dev-pipeline/scripts/update-feature-status.py +76 -509
- package/bundled/dev-pipeline/scripts/utils.py +10 -15
- package/bundled/dev-pipeline/templates/bootstrap-tier3.md +4 -4
- package/bundled/dev-pipeline/templates/bug-fix-list-schema.json +7 -0
- package/bundled/dev-pipeline/templates/bugfix-bootstrap-prompt.md +1 -1
- package/bundled/dev-pipeline/templates/sections/artifact-manifest.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-manual-verification.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-review.md +1 -1
- package/bundled/dev-pipeline/templates/sections/bugfix-phase-test.md +2 -1
- package/bundled/dev-pipeline/templates/sections/checkpoint-system.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification-auto.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification-opencli.md +2 -2
- package/bundled/dev-pipeline/templates/sections/phase-browser-verification.md +2 -2
- package/bundled/dev-pipeline/templates/sections/phase-prizmkit-test.md +2 -1
- package/bundled/dev-pipeline/templates/sections/phase-review-full.md +1 -1
- package/bundled/dev-pipeline/templates/sections/phase-specify-plan-full.md +3 -6
- package/bundled/dev-pipeline/templates/session-status-schema.json +2 -5
- package/bundled/dev-pipeline/tests/_helpers.py +418 -0
- package/bundled/dev-pipeline/tests/conftest.py +45 -1
- package/bundled/dev-pipeline/tests/live_ai_cli_log_smoke.py +1 -0
- package/bundled/dev-pipeline/tests/test_auto_skip.py +4 -69
- package/bundled/dev-pipeline/tests/test_checkpoint_state.py +126 -1
- package/bundled/dev-pipeline/tests/test_daemon_and_scripts.py +257 -0
- package/bundled/dev-pipeline/tests/test_e2e_pipeline_run.py +500 -0
- package/bundled/dev-pipeline/tests/test_generate_bootstrap_prompt.py +59 -117
- package/bundled/dev-pipeline/tests/test_generate_bugfix_prompt.py +12 -10
- package/bundled/dev-pipeline/tests/test_python_runner_parity.py +561 -3094
- package/bundled/dev-pipeline/tests/test_recovery_workflow.py +7 -8
- package/bundled/dev-pipeline/tests/test_repository_bootstrap.py +0 -1
- package/bundled/dev-pipeline/tests/test_reset_modes.py +15 -27
- package/bundled/dev-pipeline/tests/test_reset_preserve.py +54 -139
- package/bundled/dev-pipeline/tests/test_runner_bookkeeping.py +766 -0
- package/bundled/dev-pipeline/tests/test_runner_lifecycle.py +1257 -0
- package/bundled/dev-pipeline/tests/test_runtime_helper.py +97 -20
- package/bundled/dev-pipeline/tests/test_session_launch.py +1101 -0
- package/bundled/dev-pipeline/tests/test_stream_progress.py +585 -0
- package/bundled/dev-pipeline/tests/test_unified_cli.py +490 -2006
- package/bundled/dev-pipeline/tests/test_utils.py +3 -3
- package/bundled/rules/USAGE.md +1 -0
- package/bundled/skills/_metadata.json +9 -63
- package/bundled/skills/app-planner/SKILL.md +32 -303
- package/bundled/skills/app-planner/references/app-design-guide.md +0 -4
- package/bundled/skills/app-planner/references/generated-plan-review.md +2 -1
- package/bundled/skills/app-planner/references/project-brief-guide.md +14 -0
- package/bundled/skills/app-planner/references/project-conventions-discovery.md +4 -6
- package/bundled/skills/app-planner/references/project-state-detection.md +2 -3
- package/bundled/skills/bug-fix-workflow/SKILL.md +1 -2
- package/bundled/skills/bug-fix-workflow/references/bug-diagnosis.md +4 -7
- package/bundled/skills/bug-planner/SKILL.md +54 -435
- package/bundled/skills/bug-planner/references/generated-plan-review.md +3 -2
- package/bundled/skills/bug-planner/references/input-formats.md +32 -0
- package/bundled/skills/bugfix-pipeline-launcher/SKILL.md +4 -6
- package/bundled/skills/bugfix-pipeline-launcher/references/configuration.md +4 -28
- package/bundled/skills/feature-pipeline-launcher/SKILL.md +4 -6
- package/bundled/skills/feature-pipeline-launcher/references/configuration.md +4 -28
- package/bundled/skills/feature-planner/SKILL.md +60 -439
- package/bundled/skills/feature-planner/assets/planning-guide.md +1 -1
- package/bundled/skills/feature-planner/references/completeness-review.md +34 -0
- package/bundled/skills/feature-planner/references/decomposition-patterns.md +2 -2
- package/bundled/skills/feature-planner/references/error-recovery.md +1 -1
- package/bundled/skills/feature-planner/references/generated-plan-review.md +3 -2
- package/bundled/skills/feature-planner/references/incremental-feature-planning.md +3 -1
- package/bundled/skills/feature-workflow/SKILL.md +1 -2
- package/bundled/skills/prizmkit/SKILL.md +7 -1
- package/bundled/skills/prizmkit-code-review/SKILL.md +14 -6
- package/bundled/skills/prizmkit-code-review/references/independent-code-review.md +7 -4
- package/bundled/skills/prizmkit-code-review/references/review-report-template.md +16 -0
- package/bundled/skills/prizmkit-code-review/scripts/render_review_report.py +58 -20
- package/bundled/skills/prizmkit-implement/SKILL.md +1 -1
- package/bundled/skills/prizmkit-init/SKILL.md +25 -128
- package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
- package/bundled/skills/prizmkit-init/references/config-schema.md +2 -2
- package/bundled/skills/prizmkit-plan/SKILL.md +6 -8
- package/bundled/skills/prizmkit-plan/references/clarify-guide.md +1 -1
- package/bundled/skills/prizmkit-plan/references/independent-plan-review.md +5 -2
- package/bundled/skills/prizmkit-plan/references/review-plan-spec-loop.md +6 -5
- package/bundled/skills/prizmkit-prizm-docs/SKILL.md +1 -13
- package/bundled/skills/prizmkit-prizm-docs/assets/prizm-docs-format.md +1 -1
- package/bundled/skills/prizmkit-prizm-docs/references/op-init.md +1 -1
- package/bundled/skills/prizmkit-prizm-docs/references/op-update.md +1 -1
- package/bundled/skills/prizmkit-retrospective/SKILL.md +6 -4
- package/bundled/skills/prizmkit-test/SKILL.md +25 -133
- package/bundled/skills/prizmkit-test/references/independent-test-review.md +5 -2
- package/bundled/skills/prizmkit-test/references/test-coverage-model.md +6 -0
- package/bundled/skills/prizmkit-workflow/SKILL.md +2 -3
- package/bundled/skills/prizmkit-workflow/references/workflow-state-protocol.md +4 -3
- package/bundled/skills/recovery-workflow/SKILL.md +7 -7
- package/bundled/skills/recovery-workflow/evals/evals.json +1 -1
- package/bundled/skills/recovery-workflow/references/detection.md +1 -3
- package/bundled/skills/recovery-workflow/scripts/detect-recovery-state.py +0 -6
- package/bundled/templates/project-memory-template.md +1 -2
- package/package.json +1 -1
- package/src/ai-cli-launch.js +1 -1
- package/src/clean.js +40 -4
- package/src/config.js +64 -4
- package/src/detect-platform.js +10 -6
- package/src/external-skills.js +2 -2
- package/src/index.js +1 -0
- package/src/manifest.js +1 -1
- package/src/platforms.js +6 -2
- package/src/prompts.js +11 -3
- package/src/scaffold.js +87 -11
- package/src/upgrade.js +9 -3
- package/bundled/dev-pipeline/SCHEMA_ANALYSIS.md +0 -53
- package/bundled/dev-pipeline/scripts/generate-refactor-prompt.py +0 -649
- package/bundled/dev-pipeline/scripts/init-refactor-pipeline.py +0 -463
- package/bundled/dev-pipeline/scripts/update-refactor-status.py +0 -1512
- package/bundled/dev-pipeline/templates/refactor-bootstrap-prompt.md +0 -240
- package/bundled/dev-pipeline/templates/refactor-list-schema.json +0 -266
- package/bundled/dev-pipeline/templates/sections/refactor-critical-paths.md +0 -15
- package/bundled/dev-pipeline/templates/sections/refactor-mission.md +0 -9
- package/bundled/dev-pipeline/templates/sections/refactor-phase-commit-report.md +0 -24
- package/bundled/dev-pipeline/templates/sections/refactor-phase-implement.md +0 -16
- package/bundled/dev-pipeline/templates/sections/refactor-phase-init.md +0 -9
- package/bundled/dev-pipeline/templates/sections/refactor-phase-plan.md +0 -22
- package/bundled/dev-pipeline/templates/sections/refactor-phase-review.md +0 -19
- package/bundled/dev-pipeline/templates/sections/refactor-phase-test.md +0 -24
- package/bundled/dev-pipeline/templates/sections/refactor-reminders.md +0 -12
- package/bundled/dev-pipeline/templates/sections/refactor-session-context.md +0 -6
- package/bundled/dev-pipeline/templates/sections/refactor-task-contract.md +0 -52
- package/bundled/dev-pipeline/tests/test_generate_refactor_prompt.py +0 -478
- package/bundled/skills/feature-planner/assets/evaluation-guide.md +0 -44
- package/bundled/skills/refactor-pipeline-launcher/SKILL.md +0 -219
- package/bundled/skills/refactor-pipeline-launcher/references/configuration.md +0 -78
- package/bundled/skills/refactor-planner/SKILL.md +0 -467
- package/bundled/skills/refactor-planner/assets/planning-guide.md +0 -291
- package/bundled/skills/refactor-planner/references/behavior-preservation.md +0 -187
- package/bundled/skills/refactor-planner/references/error-recovery.md +0 -45
- package/bundled/skills/refactor-planner/references/fast-path.md +0 -59
- package/bundled/skills/refactor-planner/references/generated-plan-review.md +0 -107
- package/bundled/skills/refactor-planner/references/planning-phases.md +0 -172
- package/bundled/skills/refactor-planner/references/refactor-scoping-guide.md +0 -230
- package/bundled/skills/refactor-planner/scripts/validate-and-generate-refactor.py +0 -1120
- package/bundled/skills/refactor-workflow/SKILL.md +0 -205
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import importlib.util
|
|
6
5
|
import json
|
|
7
6
|
import os
|
|
8
7
|
import queue
|
|
@@ -17,6 +16,7 @@ from collections.abc import Callable, Mapping, Sequence
|
|
|
17
16
|
from dataclasses import dataclass, field
|
|
18
17
|
from pathlib import Path
|
|
19
18
|
|
|
19
|
+
from .atomic_io import write_json_atomic
|
|
20
20
|
from .checkpoint_state import load_checkpoint_state
|
|
21
21
|
from .heartbeat import HeartbeatConfig, HeartbeatMonitor, HeartbeatState, observe_heartbeat_state, write_stale_marker
|
|
22
22
|
from .launch_profiles import HeadlessLaunchProfile
|
|
@@ -30,6 +30,7 @@ from .processes import (
|
|
|
30
30
|
terminate_process_tree,
|
|
31
31
|
)
|
|
32
32
|
from .status import ProgressSummary
|
|
33
|
+
from .stream_progress import ProgressTracker, SemanticLogNormalizer
|
|
33
34
|
|
|
34
35
|
|
|
35
36
|
@dataclass(frozen=True)
|
|
@@ -67,6 +68,7 @@ class AISessionConfig:
|
|
|
67
68
|
heartbeat_stale_threshold_seconds: float = 0
|
|
68
69
|
stale_kill_grace_seconds: float = 10
|
|
69
70
|
live_progress_interval_seconds: float = 30
|
|
71
|
+
heartbeat_interval_seconds: float = 1.0
|
|
70
72
|
live_banner: bool = True
|
|
71
73
|
suppress_stream_output: bool = False
|
|
72
74
|
codex_subagent_timeout_seconds: int = 3300
|
|
@@ -121,7 +123,11 @@ HelpRunner = Callable[[Sequence[str]], str]
|
|
|
121
123
|
|
|
122
124
|
def _normalize_platform(platform: str | None) -> str:
|
|
123
125
|
normalized = (platform or "").strip().lower()
|
|
124
|
-
return
|
|
126
|
+
return (
|
|
127
|
+
normalized
|
|
128
|
+
if normalized in {"claude", "codex", "codebuddy", "pi", "cursor", "antigravity", "custom"}
|
|
129
|
+
else "codebuddy"
|
|
130
|
+
)
|
|
125
131
|
|
|
126
132
|
|
|
127
133
|
def _prompt_text(path: Path) -> str:
|
|
@@ -135,6 +141,8 @@ def _default_help_runner(command: Sequence[str]) -> str:
|
|
|
135
141
|
stdout=subprocess.PIPE,
|
|
136
142
|
stderr=subprocess.STDOUT,
|
|
137
143
|
text=True,
|
|
144
|
+
encoding="utf-8",
|
|
145
|
+
errors="replace",
|
|
138
146
|
check=False,
|
|
139
147
|
timeout=10,
|
|
140
148
|
)
|
|
@@ -151,6 +159,8 @@ def _default_cursor_probe_runner(command: Sequence[str]) -> str:
|
|
|
151
159
|
stdout=subprocess.PIPE,
|
|
152
160
|
stderr=subprocess.STDOUT,
|
|
153
161
|
text=True,
|
|
162
|
+
encoding="utf-8",
|
|
163
|
+
errors="replace",
|
|
154
164
|
check=False,
|
|
155
165
|
timeout=10,
|
|
156
166
|
)
|
|
@@ -199,6 +209,24 @@ def detect_stream_json_support(
|
|
|
199
209
|
return StreamJsonSupport(True, "cursor-stream-json", "cursor-version-help")
|
|
200
210
|
notes = tuple(f"{flag} not found" if flag.startswith("--") else flag for flag in missing)
|
|
201
211
|
return StreamJsonSupport(False, "", "cursor-version-help", notes)
|
|
212
|
+
if normalized == "antigravity" or command_name in {"agy", "antigravity"}:
|
|
213
|
+
help_output = runner((cli_command, "--help"))
|
|
214
|
+
required = (
|
|
215
|
+
"--print",
|
|
216
|
+
"--dangerously-skip-permissions",
|
|
217
|
+
"--output-format",
|
|
218
|
+
"--input-format",
|
|
219
|
+
"stream-json",
|
|
220
|
+
)
|
|
221
|
+
missing = tuple(flag for flag in required if flag not in help_output)
|
|
222
|
+
if not missing:
|
|
223
|
+
return StreamJsonSupport(True, "antigravity-stream-json", "agy-help")
|
|
224
|
+
return StreamJsonSupport(
|
|
225
|
+
False,
|
|
226
|
+
"",
|
|
227
|
+
"agy-help",
|
|
228
|
+
tuple(f"{flag} not found" for flag in missing),
|
|
229
|
+
)
|
|
202
230
|
if normalized == "pi" or command_name == "pi":
|
|
203
231
|
help_output = runner((cli_command, "--help"))
|
|
204
232
|
required = ("--mode", "--approve", "--no-session", "--tools", "--model", "--thinking")
|
|
@@ -249,6 +277,40 @@ def build_ai_session_command(config: AISessionConfig) -> AISessionCommand:
|
|
|
249
277
|
argv.extend(config.extra_args)
|
|
250
278
|
return AISessionCommand(tuple(argv), prompt, "pi", "stdin", prompt)
|
|
251
279
|
|
|
280
|
+
if platform == "antigravity":
|
|
281
|
+
if config.use_stream_json:
|
|
282
|
+
argv = [
|
|
283
|
+
config.cli_command,
|
|
284
|
+
"--dangerously-skip-permissions",
|
|
285
|
+
"--input-format",
|
|
286
|
+
"stream-json",
|
|
287
|
+
"--output-format",
|
|
288
|
+
"stream-json",
|
|
289
|
+
]
|
|
290
|
+
if config.model:
|
|
291
|
+
argv.extend(["--model", config.model])
|
|
292
|
+
if config.effort:
|
|
293
|
+
argv.extend(["--effort", config.effort])
|
|
294
|
+
argv.extend(config.extra_args)
|
|
295
|
+
stdin_payload = json.dumps(
|
|
296
|
+
{"event": "user", "message": {"content": prompt}},
|
|
297
|
+
ensure_ascii=False,
|
|
298
|
+
) + "\n"
|
|
299
|
+
return AISessionCommand(tuple(argv), stdin_payload, "antigravity", "stdin", prompt)
|
|
300
|
+
|
|
301
|
+
argv = [
|
|
302
|
+
config.cli_command,
|
|
303
|
+
"-p",
|
|
304
|
+
prompt,
|
|
305
|
+
"--dangerously-skip-permissions",
|
|
306
|
+
]
|
|
307
|
+
if config.model:
|
|
308
|
+
argv.extend(["--model", config.model])
|
|
309
|
+
if config.effort:
|
|
310
|
+
argv.extend(["--effort", config.effort])
|
|
311
|
+
argv.extend(config.extra_args)
|
|
312
|
+
return AISessionCommand(tuple(argv), None, "antigravity", "argument", prompt)
|
|
313
|
+
|
|
252
314
|
if platform == "cursor":
|
|
253
315
|
argv = [
|
|
254
316
|
config.cli_command,
|
|
@@ -264,14 +326,15 @@ def build_ai_session_command(config: AISessionConfig) -> AISessionCommand:
|
|
|
264
326
|
return AISessionCommand(tuple(argv), prompt, "cursor", "stdin", prompt)
|
|
265
327
|
|
|
266
328
|
if platform == "claude":
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
prompt
|
|
329
|
+
use_stdin = os.name == "nt"
|
|
330
|
+
argv = [config.cli_command, "-p"]
|
|
331
|
+
if not use_stdin:
|
|
332
|
+
argv.append(prompt)
|
|
333
|
+
argv.extend([
|
|
271
334
|
"--dangerously-skip-permissions",
|
|
272
335
|
"--disallowedTools",
|
|
273
336
|
"EnterWorktree",
|
|
274
|
-
]
|
|
337
|
+
])
|
|
275
338
|
if config.verbose or config.use_stream_json:
|
|
276
339
|
argv.append("--verbose")
|
|
277
340
|
if config.use_stream_json:
|
|
@@ -281,7 +344,13 @@ def build_ai_session_command(config: AISessionConfig) -> AISessionCommand:
|
|
|
281
344
|
if config.model:
|
|
282
345
|
argv.extend(["--model", config.model])
|
|
283
346
|
argv.extend(config.extra_args)
|
|
284
|
-
return AISessionCommand(
|
|
347
|
+
return AISessionCommand(
|
|
348
|
+
tuple(argv),
|
|
349
|
+
prompt if use_stdin else None,
|
|
350
|
+
"claude",
|
|
351
|
+
"stdin" if use_stdin else "argument",
|
|
352
|
+
prompt,
|
|
353
|
+
)
|
|
285
354
|
|
|
286
355
|
if platform == "codex":
|
|
287
356
|
argv = [
|
|
@@ -368,8 +437,11 @@ def recover_session_log(session_log: Path, backup_log: Path, min_size: int = 102
|
|
|
368
437
|
recovered = True
|
|
369
438
|
cleaned = False
|
|
370
439
|
if backup_log.exists():
|
|
371
|
-
|
|
372
|
-
|
|
440
|
+
try:
|
|
441
|
+
backup_log.unlink()
|
|
442
|
+
cleaned = True
|
|
443
|
+
except OSError:
|
|
444
|
+
cleaned = False
|
|
373
445
|
return LogRecoveryResult(
|
|
374
446
|
recovered=recovered,
|
|
375
447
|
cleaned_backup=cleaned,
|
|
@@ -394,6 +466,20 @@ def _permission_denial_text(event: object) -> str:
|
|
|
394
466
|
return text[:500] if any(marker in lower for marker in markers) else ""
|
|
395
467
|
|
|
396
468
|
|
|
469
|
+
def _antigravity_conversation_id(event: Mapping[str, object]) -> str:
|
|
470
|
+
for key in ("conversation_id",):
|
|
471
|
+
value = event.get(key)
|
|
472
|
+
if isinstance(value, str) and value.strip():
|
|
473
|
+
return value.strip()
|
|
474
|
+
for container_key in ("init", "step_update", "result"):
|
|
475
|
+
container = event.get(container_key)
|
|
476
|
+
if isinstance(container, Mapping):
|
|
477
|
+
value = container.get("conversation_id")
|
|
478
|
+
if isinstance(value, str) and value.strip():
|
|
479
|
+
return value.strip()
|
|
480
|
+
return ""
|
|
481
|
+
|
|
482
|
+
|
|
397
483
|
def parse_stream_progress_lines(
|
|
398
484
|
lines: Sequence[str],
|
|
399
485
|
provider_hint: str | None = None,
|
|
@@ -404,7 +490,9 @@ def parse_stream_progress_lines(
|
|
|
404
490
|
claude_session_id = ""
|
|
405
491
|
cb_session_id = ""
|
|
406
492
|
cursor_session_id = ""
|
|
493
|
+
antigravity_session_id = ""
|
|
407
494
|
cursor_stream = _normalize_platform(provider_hint) == "cursor"
|
|
495
|
+
antigravity_stream = _normalize_platform(provider_hint) == "antigravity"
|
|
408
496
|
result_subtype = ""
|
|
409
497
|
stop_reason = ""
|
|
410
498
|
has_usage = False
|
|
@@ -425,29 +513,116 @@ def parse_stream_progress_lines(
|
|
|
425
513
|
continue
|
|
426
514
|
if not isinstance(event, dict):
|
|
427
515
|
continue
|
|
428
|
-
|
|
516
|
+
has_ag_event = isinstance(event.get("event"), str) and not event.get("type")
|
|
517
|
+
if has_ag_event:
|
|
518
|
+
antigravity_stream = True
|
|
519
|
+
event_type = str(event.get("type") or event.get("event") or "")
|
|
429
520
|
if event_type:
|
|
430
521
|
event_type_counts[event_type] += 1
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
522
|
+
|
|
523
|
+
if antigravity_stream:
|
|
524
|
+
conv_id = _antigravity_conversation_id(event)
|
|
525
|
+
if conv_id and not antigravity_session_id:
|
|
526
|
+
antigravity_session_id = conv_id
|
|
527
|
+
|
|
528
|
+
if not antigravity_stream:
|
|
529
|
+
if isinstance(event.get("sessionId"), str) and not cb_session_id:
|
|
530
|
+
cb_session_id = event["sessionId"].strip()
|
|
531
|
+
if event_type == "tool_call":
|
|
532
|
+
cursor_stream = True
|
|
533
|
+
if not cursor_session_id and claude_session_id:
|
|
534
|
+
cursor_session_id = claude_session_id
|
|
535
|
+
claude_session_id = ""
|
|
536
|
+
if cursor_stream and isinstance(event.get("session_id"), str) and not cursor_session_id:
|
|
537
|
+
cursor_session_id = event["session_id"].strip()
|
|
538
|
+
if event_type == "system" and event.get("subtype") == "init":
|
|
539
|
+
session_id = event.get("session_id")
|
|
540
|
+
if isinstance(session_id, str):
|
|
541
|
+
if cursor_stream:
|
|
542
|
+
cursor_session_id = cursor_session_id or session_id.strip()
|
|
543
|
+
else:
|
|
544
|
+
claude_session_id = session_id.strip()
|
|
545
|
+
|
|
546
|
+
if antigravity_stream and event_type == "step_update":
|
|
547
|
+
step_payload = event.get("step_update") if isinstance(event.get("step_update"), dict) else event
|
|
548
|
+
if step_payload.get("usage") not in (None, "", {}):
|
|
549
|
+
has_usage = True
|
|
550
|
+
tool_info = step_payload.get("tool_info") if isinstance(step_payload.get("tool_info"), dict) else {}
|
|
551
|
+
for err_candidate in (step_payload.get("error"), tool_info.get("error")):
|
|
552
|
+
if isinstance(err_candidate, dict):
|
|
553
|
+
code = err_candidate.get("code") or err_candidate.get("type")
|
|
554
|
+
if code and not fatal_error_code:
|
|
555
|
+
fatal_error_code = str(code)
|
|
556
|
+
message = err_candidate.get("message")
|
|
557
|
+
if message:
|
|
558
|
+
errors.append(str(message)[:500])
|
|
559
|
+
elif err_candidate:
|
|
560
|
+
errors.append(str(err_candidate)[:500])
|
|
561
|
+
|
|
447
562
|
if event_type == "result":
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
563
|
+
if antigravity_stream or has_ag_event:
|
|
564
|
+
result_payload = event.get("result") if isinstance(event.get("result"), dict) else event
|
|
565
|
+
raw_status = str(
|
|
566
|
+
result_payload.get("status")
|
|
567
|
+
or event.get("status")
|
|
568
|
+
or result_payload.get("subtype")
|
|
569
|
+
or event.get("subtype")
|
|
570
|
+
or ""
|
|
571
|
+
)
|
|
572
|
+
error_val = result_payload.get("error") if result_payload.get("error") is not None else event.get("error")
|
|
573
|
+
is_error = bool(
|
|
574
|
+
event.get("is_error")
|
|
575
|
+
or result_payload.get("is_error")
|
|
576
|
+
or error_val
|
|
577
|
+
or raw_status.strip().lower() in {"error", "failed", "failure", "aborted", "cancelled", "canceled"}
|
|
578
|
+
)
|
|
579
|
+
normalized_status = raw_status.strip().lower()
|
|
580
|
+
if is_error:
|
|
581
|
+
result_subtype = "error"
|
|
582
|
+
elif normalized_status in {"", "success", "ok", "completed"}:
|
|
583
|
+
result_subtype = "success"
|
|
584
|
+
else:
|
|
585
|
+
result_subtype = normalized_status
|
|
586
|
+
stop_reason = str(
|
|
587
|
+
result_payload.get("stop_reason")
|
|
588
|
+
or event.get("stop_reason")
|
|
589
|
+
or raw_status
|
|
590
|
+
or ""
|
|
591
|
+
)
|
|
592
|
+
resp_val = (
|
|
593
|
+
result_payload.get("response")
|
|
594
|
+
or result_payload.get("result")
|
|
595
|
+
or result_payload.get("message")
|
|
596
|
+
or event.get("response")
|
|
597
|
+
or event.get("message")
|
|
598
|
+
or ""
|
|
599
|
+
)
|
|
600
|
+
if isinstance(resp_val, dict):
|
|
601
|
+
resp_val = ""
|
|
602
|
+
if isinstance(error_val, dict):
|
|
603
|
+
code = error_val.get("code") or error_val.get("type")
|
|
604
|
+
if code and not fatal_error_code:
|
|
605
|
+
fatal_error_code = str(code)
|
|
606
|
+
err_text = str(error_val.get("message") or "")
|
|
607
|
+
if err_text:
|
|
608
|
+
errors.append(err_text[:500])
|
|
609
|
+
elif error_val:
|
|
610
|
+
err_text = str(error_val)
|
|
611
|
+
errors.append(err_text[:500])
|
|
612
|
+
else:
|
|
613
|
+
err_text = ""
|
|
614
|
+
terminal_result_text = str(resp_val or err_text or "")[:1000]
|
|
615
|
+
if result_payload.get("usage") not in (None, "", {}):
|
|
616
|
+
has_usage = True
|
|
617
|
+
for key in ("fatal_error_code", "api_error_code", "error_code"):
|
|
618
|
+
value = result_payload.get(key)
|
|
619
|
+
if value and not fatal_error_code:
|
|
620
|
+
fatal_error_code = str(value)
|
|
621
|
+
break
|
|
622
|
+
else:
|
|
623
|
+
result_subtype = str(event.get("subtype") or event.get("result_subtype") or "")
|
|
624
|
+
stop_reason = str(event.get("stop_reason") or "")
|
|
625
|
+
terminal_result_text = str(event.get("result") or event.get("message") or "")[:1000]
|
|
451
626
|
if event_type in {"turn.failed", "error"}:
|
|
452
627
|
message = event.get("error") or event.get("message") or event
|
|
453
628
|
errors.append(str(message)[:500])
|
|
@@ -475,6 +650,7 @@ def parse_stream_progress_lines(
|
|
|
475
650
|
claude_session_id=claude_session_id,
|
|
476
651
|
cb_session_id=cb_session_id,
|
|
477
652
|
cursor_session_id=cursor_session_id,
|
|
653
|
+
antigravity_session_id=antigravity_session_id,
|
|
478
654
|
result_subtype=result_subtype,
|
|
479
655
|
stop_reason=stop_reason,
|
|
480
656
|
has_usage=has_usage,
|
|
@@ -503,6 +679,7 @@ class _FallbackProgressTracker:
|
|
|
503
679
|
claude_session_id=current.claude_session_id or self._summary.claude_session_id,
|
|
504
680
|
cb_session_id=current.cb_session_id or self._summary.cb_session_id,
|
|
505
681
|
cursor_session_id=current.cursor_session_id or self._summary.cursor_session_id,
|
|
682
|
+
antigravity_session_id=current.antigravity_session_id or self._summary.antigravity_session_id,
|
|
506
683
|
result_subtype=current.result_subtype or self._summary.result_subtype,
|
|
507
684
|
stop_reason=current.stop_reason or self._summary.stop_reason,
|
|
508
685
|
has_usage=current.has_usage or self._summary.has_usage,
|
|
@@ -518,22 +695,7 @@ class _FallbackProgressTracker:
|
|
|
518
695
|
|
|
519
696
|
|
|
520
697
|
def _load_stream_parser_classes() -> tuple[type | None, type | None]:
|
|
521
|
-
|
|
522
|
-
spec = importlib.util.spec_from_file_location("prizmkit_parse_stream_progress", parser_path)
|
|
523
|
-
if spec is None or spec.loader is None:
|
|
524
|
-
return None, None
|
|
525
|
-
module = importlib.util.module_from_spec(spec)
|
|
526
|
-
spec.loader.exec_module(module)
|
|
527
|
-
return (
|
|
528
|
-
getattr(module, "ProgressTracker", None),
|
|
529
|
-
getattr(module, "SemanticLogNormalizer", None),
|
|
530
|
-
)
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
def _load_progress_tracker_class():
|
|
534
|
-
"""Backward-compatible access to the shared aggregate tracker class."""
|
|
535
|
-
tracker_class, _ = _load_stream_parser_classes()
|
|
536
|
-
return tracker_class
|
|
698
|
+
return ProgressTracker, SemanticLogNormalizer
|
|
537
699
|
|
|
538
700
|
|
|
539
701
|
def _fallback_semantic_output(line: str, event: object | None) -> str:
|
|
@@ -541,7 +703,7 @@ def _fallback_semantic_output(line: str, event: object | None) -> str:
|
|
|
541
703
|
if not isinstance(event, dict):
|
|
542
704
|
text = line.rstrip("\n")
|
|
543
705
|
return f"[OUTPUT] {text}\n" if text else ""
|
|
544
|
-
event_type = str(event.get("type") or "event")
|
|
706
|
+
event_type = str(event.get("type") or event.get("event") or "event")
|
|
545
707
|
value = event.get("error") or event.get("result") or event.get("message")
|
|
546
708
|
if isinstance(value, str) and value.strip():
|
|
547
709
|
label = "[ERROR]" if event.get("error") else "[OUTPUT]"
|
|
@@ -549,13 +711,6 @@ def _fallback_semantic_output(line: str, event: object | None) -> str:
|
|
|
549
711
|
return f"[OUTPUT] event={event_type}\n"
|
|
550
712
|
|
|
551
713
|
|
|
552
|
-
def _write_progress_summary(progress_path: Path | None, summary: ProgressSummary) -> None:
|
|
553
|
-
if progress_path is None:
|
|
554
|
-
return
|
|
555
|
-
progress_path.parent.mkdir(parents=True, exist_ok=True)
|
|
556
|
-
progress_path.write_text(json.dumps(summary.to_dict(), indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
557
|
-
|
|
558
|
-
|
|
559
714
|
def _progress_refresh_key(data: Mapping[str, object]) -> tuple[object, ...]:
|
|
560
715
|
event_counts = data.get("event_type_counts")
|
|
561
716
|
return (
|
|
@@ -574,8 +729,7 @@ def _progress_refresh_key(data: Mapping[str, object]) -> tuple[object, ...]:
|
|
|
574
729
|
|
|
575
730
|
|
|
576
731
|
def _write_progress_data(progress_path: Path, data: Mapping[str, object]) -> None:
|
|
577
|
-
progress_path
|
|
578
|
-
progress_path.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
|
732
|
+
write_json_atomic(progress_path, dict(data), indent=2, sort_keys=True, ensure_ascii=True, fsync=False)
|
|
579
733
|
|
|
580
734
|
|
|
581
735
|
def _start_idle_progress_refresh(
|
|
@@ -590,8 +744,13 @@ def _start_idle_progress_refresh(
|
|
|
590
744
|
|
|
591
745
|
def maybe_write(force: bool = False) -> None:
|
|
592
746
|
nonlocal last_key
|
|
593
|
-
|
|
594
|
-
|
|
747
|
+
if getattr(tracker, "SUPPORTS_UNLOCKED_CHILD_REFRESH", False):
|
|
748
|
+
tracker.refresh_child_session_activity(lock=tracker_lock)
|
|
749
|
+
with tracker_lock:
|
|
750
|
+
data = tracker.to_dict(refresh_child_activity=False)
|
|
751
|
+
else:
|
|
752
|
+
with tracker_lock:
|
|
753
|
+
data = tracker.to_dict()
|
|
595
754
|
key = _progress_refresh_key(data)
|
|
596
755
|
if force or key != last_key:
|
|
597
756
|
_write_progress_data(progress_path, data)
|
|
@@ -970,14 +1129,14 @@ def _reader_thread(
|
|
|
970
1129
|
tracker.last_text_snippet = stripped[:120]
|
|
971
1130
|
tracker._detect_terminal_error(stripped, require_error_context=True)
|
|
972
1131
|
except Exception as exc:
|
|
973
|
-
tracker_failure = f"[ERROR] progress parser rejected event={str(event.get('type') or 'unknown') if isinstance(event, dict) else 'text'}: {type(exc).__name__}\n"
|
|
1132
|
+
tracker_failure = f"[ERROR] progress parser rejected event={str(event.get('type') or event.get('event') or 'unknown') if isinstance(event, dict) else 'text'}: {type(exc).__name__}\n"
|
|
974
1133
|
try:
|
|
975
1134
|
if normalizer is not None:
|
|
976
1135
|
rendered = normalizer.process_event(event) if isinstance(event, dict) else normalizer.process_text(line)
|
|
977
1136
|
else:
|
|
978
1137
|
rendered = _fallback_semantic_output(line, event)
|
|
979
1138
|
except Exception as exc:
|
|
980
|
-
event_name = str(event.get("type") or "unknown") if isinstance(event, dict) else "text"
|
|
1139
|
+
event_name = str(event.get("type") or event.get("event") or "unknown") if isinstance(event, dict) else "text"
|
|
981
1140
|
rendered = (
|
|
982
1141
|
f"[ERROR] semantic log adapter rejected event={event_name}: {type(exc).__name__}\n"
|
|
983
1142
|
+ _fallback_semantic_output(line, event)
|
|
@@ -990,6 +1149,18 @@ def _reader_thread(
|
|
|
990
1149
|
backup_fh.flush()
|
|
991
1150
|
if live_output:
|
|
992
1151
|
_emit_live_output(rendered)
|
|
1152
|
+
if (
|
|
1153
|
+
refresh_progress is not None
|
|
1154
|
+
and isinstance(event, dict)
|
|
1155
|
+
and (
|
|
1156
|
+
event.get("type") in {"result", "turn.completed", "turn.failed", "agent_end"}
|
|
1157
|
+
or event.get("event") == "result"
|
|
1158
|
+
)
|
|
1159
|
+
):
|
|
1160
|
+
try:
|
|
1161
|
+
refresh_progress(True)
|
|
1162
|
+
except Exception:
|
|
1163
|
+
pass
|
|
993
1164
|
if normalizer is not None:
|
|
994
1165
|
trailing = normalizer.finish()
|
|
995
1166
|
if trailing:
|
|
@@ -999,8 +1170,13 @@ def _reader_thread(
|
|
|
999
1170
|
backup_fh.flush()
|
|
1000
1171
|
if live_output:
|
|
1001
1172
|
_emit_live_output(trailing)
|
|
1002
|
-
|
|
1003
|
-
|
|
1173
|
+
if getattr(tracker, "SUPPORTS_UNLOCKED_CHILD_REFRESH", False):
|
|
1174
|
+
tracker.refresh_child_session_activity(lock=tracker_lock)
|
|
1175
|
+
with tracker_lock:
|
|
1176
|
+
final_data = tracker.to_dict(refresh_child_activity=False)
|
|
1177
|
+
else:
|
|
1178
|
+
with tracker_lock:
|
|
1179
|
+
final_data = tracker.to_dict()
|
|
1004
1180
|
finally:
|
|
1005
1181
|
if refresh_progress is not None:
|
|
1006
1182
|
try:
|
|
@@ -1013,7 +1189,10 @@ def _reader_thread(
|
|
|
1013
1189
|
if not final_data:
|
|
1014
1190
|
try:
|
|
1015
1191
|
with tracker_lock:
|
|
1016
|
-
|
|
1192
|
+
if getattr(tracker, "SUPPORTS_UNLOCKED_CHILD_REFRESH", False):
|
|
1193
|
+
final_data = tracker.to_dict(refresh_child_activity=False)
|
|
1194
|
+
else:
|
|
1195
|
+
final_data = tracker.to_dict()
|
|
1017
1196
|
except Exception:
|
|
1018
1197
|
final_data = {}
|
|
1019
1198
|
try:
|
|
@@ -1054,6 +1233,7 @@ def _summary_from_progress_dict(data: Mapping[str, object], fallback: ProgressSu
|
|
|
1054
1233
|
claude_session_id=str(data.get("claude_session_id") or fallback.claude_session_id),
|
|
1055
1234
|
cb_session_id=str(data.get("cb_session_id") or fallback.cb_session_id),
|
|
1056
1235
|
cursor_session_id=str(data.get("cursor_session_id") or fallback.cursor_session_id),
|
|
1236
|
+
antigravity_session_id=str(data.get("antigravity_session_id") or fallback.antigravity_session_id),
|
|
1057
1237
|
result_subtype=str(data.get("result_subtype") or fallback.result_subtype),
|
|
1058
1238
|
stop_reason=str(data.get("stop_reason") or fallback.stop_reason),
|
|
1059
1239
|
has_usage=bool(data.get("has_usage") or fallback.has_usage),
|
|
@@ -1093,52 +1273,16 @@ class AISessionLauncher:
|
|
|
1093
1273
|
if self.config.live_output and self.config.live_banner:
|
|
1094
1274
|
_emit_session_start(self.config, command, session_log, backup_log)
|
|
1095
1275
|
|
|
1096
|
-
handle = launch_process(spec, stderr=subprocess.STDOUT)
|
|
1097
|
-
assert handle.popen is not None
|
|
1098
|
-
reader_result_queue: queue.Queue[dict[str, object]] = queue.Queue(maxsize=1)
|
|
1099
|
-
reader = threading.Thread(
|
|
1100
|
-
target=_reader_thread,
|
|
1101
|
-
args=(
|
|
1102
|
-
handle.popen.stdout,
|
|
1103
|
-
session_log,
|
|
1104
|
-
backup_log,
|
|
1105
|
-
reader_result_queue,
|
|
1106
|
-
self.config.progress_path,
|
|
1107
|
-
self.config.live_output and self.config.verbose and not self.config.suppress_stream_output,
|
|
1108
|
-
self.config.platform,
|
|
1109
|
-
),
|
|
1110
|
-
daemon=True,
|
|
1111
|
-
)
|
|
1112
|
-
reader.start()
|
|
1113
|
-
if handle.popen.stdin is not None:
|
|
1114
|
-
if command.stdin_text is not None:
|
|
1115
|
-
handle.popen.stdin.write(command.stdin_text)
|
|
1116
|
-
handle.popen.stdin.close()
|
|
1117
|
-
|
|
1118
|
-
heartbeat = None
|
|
1119
1276
|
live_progress_interval = max(1.0, float(self.config.live_progress_interval_seconds or 30))
|
|
1120
1277
|
kill_threshold_seconds = max(0.0, float(self.config.stale_kill_threshold_seconds or 0))
|
|
1121
1278
|
stale_threshold_seconds = max(0.0, float(self.config.heartbeat_stale_threshold_seconds or 0))
|
|
1122
1279
|
if stale_threshold_seconds <= 0:
|
|
1123
1280
|
stale_threshold_seconds = kill_threshold_seconds
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
handle,
|
|
1130
|
-
HeartbeatConfig(
|
|
1131
|
-
heartbeat_file=heartbeat_path,
|
|
1132
|
-
session_log=session_log,
|
|
1133
|
-
progress_file=self.config.progress_path,
|
|
1134
|
-
marker_dir=session_log.parent,
|
|
1135
|
-
interval_seconds=0.1,
|
|
1136
|
-
stale_after_seconds=stale_threshold_seconds,
|
|
1137
|
-
kill_after_seconds=kill_threshold_seconds,
|
|
1138
|
-
grace_seconds=self.config.stale_kill_grace_seconds,
|
|
1139
|
-
),
|
|
1140
|
-
)
|
|
1141
|
-
heartbeat.start()
|
|
1281
|
+
heartbeat_interval = (
|
|
1282
|
+
min(1.0, max(0.05, kill_threshold_seconds / 4.0))
|
|
1283
|
+
if 0 < kill_threshold_seconds < 4.0
|
|
1284
|
+
else min(5.0, max(0.5, float(self.config.heartbeat_interval_seconds or 1.0)))
|
|
1285
|
+
)
|
|
1142
1286
|
|
|
1143
1287
|
started = time.time()
|
|
1144
1288
|
timed_out = False
|
|
@@ -1147,7 +1291,56 @@ class AISessionLauncher:
|
|
|
1147
1291
|
last_progress_line = ""
|
|
1148
1292
|
last_progress_emit = 0.0
|
|
1149
1293
|
display_heartbeat_state = None
|
|
1294
|
+
handle: ProcessHandle | None = None
|
|
1295
|
+
reader: threading.Thread | None = None
|
|
1296
|
+
heartbeat: HeartbeatMonitor | None = None
|
|
1297
|
+
interrupted = False
|
|
1298
|
+
reader_result_queue: queue.Queue[dict[str, object]] = queue.Queue(maxsize=1)
|
|
1299
|
+
|
|
1150
1300
|
try:
|
|
1301
|
+
handle = launch_process(spec, stderr=subprocess.STDOUT)
|
|
1302
|
+
assert handle.popen is not None
|
|
1303
|
+
reader = threading.Thread(
|
|
1304
|
+
target=_reader_thread,
|
|
1305
|
+
args=(
|
|
1306
|
+
handle.popen.stdout,
|
|
1307
|
+
session_log,
|
|
1308
|
+
backup_log,
|
|
1309
|
+
reader_result_queue,
|
|
1310
|
+
self.config.progress_path,
|
|
1311
|
+
self.config.live_output and self.config.verbose and not self.config.suppress_stream_output,
|
|
1312
|
+
self.config.platform,
|
|
1313
|
+
),
|
|
1314
|
+
daemon=True,
|
|
1315
|
+
)
|
|
1316
|
+
reader.start()
|
|
1317
|
+
if handle.popen.stdin is not None:
|
|
1318
|
+
try:
|
|
1319
|
+
if command.stdin_text is not None:
|
|
1320
|
+
handle.popen.stdin.write(command.stdin_text)
|
|
1321
|
+
handle.popen.stdin.close()
|
|
1322
|
+
except (BrokenPipeError, OSError):
|
|
1323
|
+
pass
|
|
1324
|
+
|
|
1325
|
+
heartbeat_path = self.config.heartbeat_path
|
|
1326
|
+
if heartbeat_path is None and kill_threshold_seconds > 0:
|
|
1327
|
+
heartbeat_path = session_log.with_name("heartbeat.json")
|
|
1328
|
+
if heartbeat_path is not None:
|
|
1329
|
+
heartbeat = HeartbeatMonitor(
|
|
1330
|
+
handle,
|
|
1331
|
+
HeartbeatConfig(
|
|
1332
|
+
heartbeat_file=heartbeat_path,
|
|
1333
|
+
session_log=session_log,
|
|
1334
|
+
progress_file=self.config.progress_path,
|
|
1335
|
+
marker_dir=session_log.parent,
|
|
1336
|
+
interval_seconds=heartbeat_interval,
|
|
1337
|
+
stale_after_seconds=stale_threshold_seconds,
|
|
1338
|
+
kill_after_seconds=kill_threshold_seconds,
|
|
1339
|
+
grace_seconds=self.config.stale_kill_grace_seconds,
|
|
1340
|
+
),
|
|
1341
|
+
)
|
|
1342
|
+
heartbeat.start()
|
|
1343
|
+
|
|
1151
1344
|
while True:
|
|
1152
1345
|
timeout = 0.2
|
|
1153
1346
|
if self.config.total_timeout_seconds is not None:
|
|
@@ -1177,59 +1370,81 @@ class AISessionLauncher:
|
|
|
1177
1370
|
stale_threshold_seconds=stale_threshold_seconds,
|
|
1178
1371
|
)
|
|
1179
1372
|
last_progress_emit = now
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
_emit_ai_interruption_received(
|
|
1184
|
-
interruption,
|
|
1185
|
-
command=command,
|
|
1186
|
-
handle=handle,
|
|
1187
|
-
started_epoch=started,
|
|
1188
|
-
session_log=session_log,
|
|
1189
|
-
progress_path=self.config.progress_path,
|
|
1190
|
-
checkpoint_path=self.config.checkpoint_path,
|
|
1191
|
-
heartbeat_state=monitor_state,
|
|
1192
|
-
)
|
|
1193
|
-
except Exception as diagnostic_error:
|
|
1194
|
-
_emit_interrupt_line(
|
|
1195
|
-
f"diagnostic collection failed error={type(diagnostic_error).__name__}; "
|
|
1196
|
-
"continuing existing process-tree cleanup"
|
|
1197
|
-
)
|
|
1198
|
-
with shield_interruption_signals():
|
|
1199
|
-
termination = terminate_process_tree(
|
|
1200
|
-
handle,
|
|
1201
|
-
"interrupted",
|
|
1202
|
-
grace_seconds=self.config.stale_kill_grace_seconds,
|
|
1203
|
-
)
|
|
1204
|
-
_emit_ai_interruption_termination(termination)
|
|
1205
|
-
raise
|
|
1206
|
-
if self.config.live_output and (not self.config.verbose or self.config.suppress_stream_output):
|
|
1207
|
-
final_heartbeat_state = _display_heartbeat_state(
|
|
1208
|
-
session_log,
|
|
1209
|
-
self.config.progress_path,
|
|
1210
|
-
heartbeat.state if heartbeat is not None else None,
|
|
1211
|
-
display_heartbeat_state,
|
|
1212
|
-
interval_seconds=live_progress_interval,
|
|
1213
|
-
stale_threshold_seconds=stale_threshold_seconds,
|
|
1214
|
-
)
|
|
1215
|
-
display_heartbeat_state = final_heartbeat_state
|
|
1216
|
-
if final_heartbeat_state.details == "progress":
|
|
1217
|
-
final_line = _compact_progress_line(
|
|
1218
|
-
started,
|
|
1373
|
+
|
|
1374
|
+
if self.config.live_output and (not self.config.verbose or self.config.suppress_stream_output):
|
|
1375
|
+
final_heartbeat_state = _display_heartbeat_state(
|
|
1219
1376
|
session_log,
|
|
1220
1377
|
self.config.progress_path,
|
|
1221
|
-
|
|
1222
|
-
|
|
1378
|
+
heartbeat.state if heartbeat is not None else None,
|
|
1379
|
+
display_heartbeat_state,
|
|
1380
|
+
interval_seconds=live_progress_interval,
|
|
1223
1381
|
stale_threshold_seconds=stale_threshold_seconds,
|
|
1224
1382
|
)
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1383
|
+
display_heartbeat_state = final_heartbeat_state
|
|
1384
|
+
if final_heartbeat_state.details == "progress":
|
|
1385
|
+
final_line = _compact_progress_line(
|
|
1386
|
+
started,
|
|
1387
|
+
session_log,
|
|
1388
|
+
self.config.progress_path,
|
|
1389
|
+
final_heartbeat_state,
|
|
1390
|
+
checkpoint_path=self.config.checkpoint_path,
|
|
1391
|
+
stale_threshold_seconds=stale_threshold_seconds,
|
|
1392
|
+
)
|
|
1393
|
+
if final_line != last_progress_line:
|
|
1394
|
+
_emit_live_line(final_line)
|
|
1395
|
+
last_progress_line = final_line
|
|
1396
|
+
except KeyboardInterrupt as interruption:
|
|
1397
|
+
interrupted = True
|
|
1398
|
+
with shield_interruption_signals():
|
|
1399
|
+
monitor_state = heartbeat.state if heartbeat is not None else display_heartbeat_state
|
|
1400
|
+
if handle is not None:
|
|
1401
|
+
try:
|
|
1402
|
+
_emit_ai_interruption_received(
|
|
1403
|
+
interruption,
|
|
1404
|
+
command=command,
|
|
1405
|
+
handle=handle,
|
|
1406
|
+
started_epoch=started,
|
|
1407
|
+
session_log=session_log,
|
|
1408
|
+
progress_path=self.config.progress_path,
|
|
1409
|
+
checkpoint_path=self.config.checkpoint_path,
|
|
1410
|
+
heartbeat_state=monitor_state,
|
|
1411
|
+
)
|
|
1412
|
+
except Exception as diagnostic_error:
|
|
1413
|
+
_emit_interrupt_line(
|
|
1414
|
+
f"diagnostic collection failed error={type(diagnostic_error).__name__}; "
|
|
1415
|
+
"continuing existing process-tree cleanup"
|
|
1416
|
+
)
|
|
1417
|
+
termination = terminate_process_tree(
|
|
1418
|
+
handle,
|
|
1419
|
+
"interrupted",
|
|
1420
|
+
grace_seconds=self.config.stale_kill_grace_seconds,
|
|
1421
|
+
)
|
|
1422
|
+
_emit_ai_interruption_termination(termination)
|
|
1423
|
+
raise
|
|
1424
|
+
finally:
|
|
1425
|
+
if reader is not None and not interrupted:
|
|
1426
|
+
reader.join(timeout=1.5)
|
|
1427
|
+
if (
|
|
1428
|
+
reader.is_alive()
|
|
1429
|
+
and handle is not None
|
|
1430
|
+
and handle.popen is not None
|
|
1431
|
+
and handle.popen.poll() is not None
|
|
1432
|
+
):
|
|
1433
|
+
terminate_process_tree(handle, "lingering_child_pipes", grace_seconds=0.5)
|
|
1434
|
+
reader.join(timeout=3.5)
|
|
1435
|
+
heartbeat_result = heartbeat.stop() if heartbeat is not None else None
|
|
1436
|
+
if reader is not None and interrupted:
|
|
1437
|
+
reader.join(timeout=1.0)
|
|
1438
|
+
if not interrupted and heartbeat_result and heartbeat_result.killed:
|
|
1439
|
+
termination_reason = heartbeat_result.reason
|
|
1440
|
+
stale_marker = heartbeat_result.marker_path
|
|
1441
|
+
if interrupted:
|
|
1442
|
+
try:
|
|
1443
|
+
recover_session_log(session_log, backup_log)
|
|
1444
|
+
except OSError:
|
|
1445
|
+
pass
|
|
1446
|
+
|
|
1447
|
+
assert handle is not None and handle.popen is not None
|
|
1233
1448
|
if termination_reason is None and kill_threshold_seconds > 0 and handle.popen.returncode is None:
|
|
1234
1449
|
stale_marker = write_stale_marker(
|
|
1235
1450
|
session_log.parent,
|
|
@@ -1255,7 +1470,7 @@ class AISessionLauncher:
|
|
|
1255
1470
|
merged_progress.update(reader_progress)
|
|
1256
1471
|
fallback_summary = ProgressSummary()
|
|
1257
1472
|
if self.config.progress_path is not None:
|
|
1258
|
-
self.config.progress_path
|
|
1473
|
+
_write_progress_data(self.config.progress_path, merged_progress)
|
|
1259
1474
|
final_summary = _summary_from_progress_dict(merged_progress, fallback_summary)
|
|
1260
1475
|
ended = time.time()
|
|
1261
1476
|
result = AISessionResult(
|