prizmkit 1.1.191 → 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/bundled/VERSION.json +3 -3
- package/bundled/adapters/antigravity/skill-adapter.js +13 -4
- 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 +5 -10
- 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 +24 -76
- package/bundled/dev-pipeline/prizmkit_runtime/daemon.py +125 -67
- package/bundled/dev-pipeline/prizmkit_runtime/gitops.py +77 -430
- 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 +36 -14
- 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 +276 -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 +183 -130
- package/bundled/dev-pipeline/prizmkit_runtime/status.py +1 -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 -2616
- 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 +5 -12
- 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/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 +431 -3099
- 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 +155 -2034
- package/bundled/dev-pipeline/tests/test_utils.py +3 -3
- 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 +24 -127
- package/bundled/skills/prizmkit-init/assets/project-brief-template.md +3 -3
- 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/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/scaffold.js +28 -7
- 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,10 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import ctypes
|
|
6
|
+
import json
|
|
5
7
|
import os
|
|
8
|
+
import shutil
|
|
6
9
|
import signal
|
|
7
10
|
import subprocess
|
|
8
11
|
import sys
|
|
@@ -13,6 +16,69 @@ from contextlib import contextmanager
|
|
|
13
16
|
from dataclasses import dataclass, field
|
|
14
17
|
from pathlib import Path
|
|
15
18
|
|
|
19
|
+
from .atomic_io import write_text_atomic
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class PidLockError(RuntimeError):
|
|
23
|
+
"""Raised when an exclusive PID directory lock is held or cannot be acquired."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _lock_owner_pid(lock_path: Path) -> int:
|
|
27
|
+
for _attempt in range(5):
|
|
28
|
+
try:
|
|
29
|
+
data = json.loads((lock_path / "owner.json").read_text(encoding="utf-8"))
|
|
30
|
+
return int(data.get("pid") or 0) if isinstance(data, dict) else 0
|
|
31
|
+
except FileNotFoundError:
|
|
32
|
+
time.sleep(0.01)
|
|
33
|
+
except (OSError, ValueError, json.JSONDecodeError):
|
|
34
|
+
return 0
|
|
35
|
+
return 0
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _remove_stale_pid_lock(lock_path: Path, error_label: str) -> None:
|
|
39
|
+
stale_path = lock_path.with_name(f"{lock_path.name}.stale-{os.getpid()}-{os.urandom(6).hex()}")
|
|
40
|
+
try:
|
|
41
|
+
os.rename(lock_path, stale_path)
|
|
42
|
+
except FileNotFoundError:
|
|
43
|
+
return
|
|
44
|
+
except OSError as exc:
|
|
45
|
+
raise PidLockError(f"Cannot claim stale {error_label} {lock_path}: {exc}") from exc
|
|
46
|
+
shutil.rmtree(stale_path, ignore_errors=True)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@contextmanager
|
|
50
|
+
def exclusive_pid_lock(
|
|
51
|
+
lock_path: Path,
|
|
52
|
+
*,
|
|
53
|
+
busy_message: str | None = None,
|
|
54
|
+
error_label: str = "lock",
|
|
55
|
+
) -> Iterator[None]:
|
|
56
|
+
"""Acquire an exclusive directory lock, reclaiming locks from exited PIDs."""
|
|
57
|
+
lock_path.parent.mkdir(parents=True, exist_ok=True)
|
|
58
|
+
acquired = False
|
|
59
|
+
for _attempt in range(3):
|
|
60
|
+
try:
|
|
61
|
+
lock_path.mkdir()
|
|
62
|
+
acquired = True
|
|
63
|
+
break
|
|
64
|
+
except FileExistsError:
|
|
65
|
+
owner_pid = _lock_owner_pid(lock_path)
|
|
66
|
+
if is_pid_running(owner_pid):
|
|
67
|
+
message = busy_message or f"{error_label} is already held (PID {owner_pid})"
|
|
68
|
+
raise PidLockError(message.format(pid=owner_pid))
|
|
69
|
+
_remove_stale_pid_lock(lock_path, error_label)
|
|
70
|
+
except OSError as exc:
|
|
71
|
+
raise PidLockError(f"Cannot acquire {error_label} {lock_path}: {exc}") from exc
|
|
72
|
+
if not acquired:
|
|
73
|
+
raise PidLockError(f"Cannot acquire {error_label} {lock_path}")
|
|
74
|
+
try:
|
|
75
|
+
(lock_path / "owner.json").write_text(json.dumps({"pid": os.getpid()}) + "\n", encoding="utf-8")
|
|
76
|
+
yield
|
|
77
|
+
finally:
|
|
78
|
+
owner_pid = _lock_owner_pid(lock_path)
|
|
79
|
+
if owner_pid in {0, os.getpid()}:
|
|
80
|
+
shutil.rmtree(lock_path, ignore_errors=True)
|
|
81
|
+
|
|
16
82
|
|
|
17
83
|
@dataclass(frozen=True)
|
|
18
84
|
class InterruptionDetails:
|
|
@@ -98,6 +164,7 @@ class ProcessSpec:
|
|
|
98
164
|
pid_file: Path | None = None
|
|
99
165
|
stdin_text: str | None = None
|
|
100
166
|
start_new_process_group: bool = True
|
|
167
|
+
detached: bool = False
|
|
101
168
|
|
|
102
169
|
|
|
103
170
|
@dataclass(frozen=True)
|
|
@@ -153,20 +220,18 @@ def shield_interruption_signals() -> Iterator[None]:
|
|
|
153
220
|
signal.signal(signal_number, handler)
|
|
154
221
|
|
|
155
222
|
|
|
156
|
-
def _creationflags_for_platform(start_new_process_group: bool) -> int:
|
|
157
|
-
if os.name != "nt"
|
|
223
|
+
def _creationflags_for_platform(start_new_process_group: bool, *, detached: bool = False) -> int:
|
|
224
|
+
if os.name != "nt":
|
|
158
225
|
return 0
|
|
159
226
|
flags = 0
|
|
160
|
-
|
|
227
|
+
if start_new_process_group:
|
|
228
|
+
flags |= getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
|
|
229
|
+
if detached:
|
|
230
|
+
flags |= getattr(subprocess, "DETACHED_PROCESS", 0)
|
|
231
|
+
flags |= getattr(subprocess, "CREATE_NO_WINDOW", 0)
|
|
161
232
|
return flags
|
|
162
233
|
|
|
163
234
|
|
|
164
|
-
def _preexec_fn_for_platform(start_new_process_group: bool):
|
|
165
|
-
if os.name == "nt" or not start_new_process_group:
|
|
166
|
-
return None
|
|
167
|
-
return os.setsid
|
|
168
|
-
|
|
169
|
-
|
|
170
235
|
def _process_env(overrides: Mapping[str, str], unsets: Sequence[str] = ()) -> dict[str, str]:
|
|
171
236
|
env = dict(os.environ)
|
|
172
237
|
for key in unsets:
|
|
@@ -183,8 +248,9 @@ def launch_process(
|
|
|
183
248
|
stdin=subprocess.PIPE,
|
|
184
249
|
text: bool = True,
|
|
185
250
|
) -> ProcessHandle:
|
|
186
|
-
"""Launch a child process with POSIX
|
|
251
|
+
"""Launch a child process with POSIX session or Windows process flags."""
|
|
187
252
|
spec.cwd.mkdir(parents=True, exist_ok=True)
|
|
253
|
+
text_kwargs = {"encoding": "utf-8", "errors": "replace"} if text else {}
|
|
188
254
|
process = subprocess.Popen(
|
|
189
255
|
[str(part) for part in spec.command],
|
|
190
256
|
cwd=spec.cwd,
|
|
@@ -193,12 +259,12 @@ def launch_process(
|
|
|
193
259
|
stdout=stdout,
|
|
194
260
|
stderr=stderr,
|
|
195
261
|
text=text,
|
|
196
|
-
|
|
197
|
-
creationflags=_creationflags_for_platform(spec.start_new_process_group),
|
|
262
|
+
start_new_session=(os.name != "nt" and spec.start_new_process_group),
|
|
263
|
+
creationflags=_creationflags_for_platform(spec.start_new_process_group, detached=spec.detached),
|
|
264
|
+
**text_kwargs,
|
|
198
265
|
)
|
|
199
266
|
if spec.pid_file is not None:
|
|
200
|
-
spec.pid_file
|
|
201
|
-
spec.pid_file.write_text(f"{process.pid}\n", encoding="utf-8")
|
|
267
|
+
write_text_atomic(spec.pid_file, f"{process.pid}\n")
|
|
202
268
|
return ProcessHandle(pid=process.pid, spec=spec, status="running", popen=process)
|
|
203
269
|
|
|
204
270
|
|
|
@@ -206,96 +272,150 @@ def is_process_running(handle: ProcessHandle) -> bool:
|
|
|
206
272
|
"""Return true when the process appears alive."""
|
|
207
273
|
if handle.popen is not None:
|
|
208
274
|
return handle.popen.poll() is None
|
|
209
|
-
|
|
210
|
-
|
|
275
|
+
return is_pid_running(handle.pid)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _signal_posix_tree(pid: int, sig: int, label: str, details: list[str]) -> None:
|
|
211
279
|
try:
|
|
212
|
-
os.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
280
|
+
os.killpg(pid, sig)
|
|
281
|
+
details.append(f"{label}_process_group")
|
|
282
|
+
except OSError as exc:
|
|
283
|
+
details.append(f"{label}_group_failed={type(exc).__name__}")
|
|
284
|
+
try:
|
|
285
|
+
os.kill(pid, sig)
|
|
286
|
+
details.append(f"{label}_process")
|
|
287
|
+
except OSError as inner:
|
|
288
|
+
details.append(f"{label}_process_failed={type(inner).__name__}")
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _run_windows_taskkill(pid: int, *, force: bool) -> subprocess.CompletedProcess[str]:
|
|
292
|
+
command = ["taskkill", "/PID", str(pid), "/T"]
|
|
293
|
+
if force:
|
|
294
|
+
command.append("/F")
|
|
295
|
+
return subprocess.run(
|
|
296
|
+
command,
|
|
297
|
+
stdout=subprocess.PIPE,
|
|
298
|
+
stderr=subprocess.PIPE,
|
|
299
|
+
text=True,
|
|
300
|
+
encoding="utf-8",
|
|
301
|
+
errors="replace",
|
|
302
|
+
check=False,
|
|
303
|
+
)
|
|
216
304
|
|
|
217
305
|
|
|
218
|
-
def
|
|
219
|
-
|
|
306
|
+
def _terminate_tree_impl(
|
|
307
|
+
pid: int,
|
|
308
|
+
*,
|
|
220
309
|
reason: str,
|
|
221
|
-
grace_seconds: float
|
|
310
|
+
grace_seconds: float,
|
|
311
|
+
process: subprocess.Popen[str] | None = None,
|
|
222
312
|
) -> ProcessTerminationResult:
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
POSIX uses the process group created at launch. Windows uses taskkill-style
|
|
226
|
-
tree termination when available. Both paths are best effort and safe for
|
|
227
|
-
tests with short-lived fake processes.
|
|
228
|
-
"""
|
|
229
|
-
pid = handle.pid
|
|
230
|
-
if pid is None:
|
|
231
|
-
return ProcessTerminationResult(pid=None, reason=reason, terminated=False, forced=False, return_code=None)
|
|
232
|
-
|
|
313
|
+
still_running = (lambda: process.poll() is None) if process is not None else (lambda: is_pid_running(pid))
|
|
233
314
|
details: list[str] = []
|
|
234
315
|
forced = False
|
|
235
|
-
|
|
316
|
+
taskkill_ok = False
|
|
317
|
+
grace = max(0.0, grace_seconds)
|
|
236
318
|
|
|
237
319
|
if os.name == "nt":
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
320
|
+
if grace > 0:
|
|
321
|
+
completed = _run_windows_taskkill(pid, force=False)
|
|
322
|
+
details.append(f"taskkill_graceful_exit={completed.returncode}")
|
|
323
|
+
taskkill_ok = completed.returncode == 0
|
|
324
|
+
deadline = time.monotonic() + grace
|
|
325
|
+
while still_running() and time.monotonic() < deadline:
|
|
326
|
+
time.sleep(0.05)
|
|
327
|
+
if still_running():
|
|
328
|
+
forced = True
|
|
329
|
+
completed = _run_windows_taskkill(pid, force=True)
|
|
330
|
+
details.append(f"taskkill_exit={completed.returncode}")
|
|
331
|
+
taskkill_ok = taskkill_ok or (completed.returncode == 0)
|
|
332
|
+
force_deadline = time.monotonic() + min(grace, 2.0)
|
|
333
|
+
while still_running() and time.monotonic() < force_deadline:
|
|
334
|
+
time.sleep(0.05)
|
|
335
|
+
else:
|
|
336
|
+
forced = True
|
|
337
|
+
completed = _run_windows_taskkill(pid, force=True)
|
|
338
|
+
details.append(f"taskkill_exit={completed.returncode}")
|
|
339
|
+
taskkill_ok = completed.returncode == 0
|
|
247
340
|
else:
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
except ProcessLookupError:
|
|
252
|
-
pass
|
|
253
|
-
except OSError as exc:
|
|
254
|
-
details.append(f"sigterm_group_failed={type(exc).__name__}")
|
|
255
|
-
try:
|
|
256
|
-
os.kill(pid, signal.SIGTERM)
|
|
257
|
-
details.append("sigterm_process")
|
|
258
|
-
except OSError as inner:
|
|
259
|
-
details.append(f"sigterm_process_failed={type(inner).__name__}")
|
|
260
|
-
|
|
261
|
-
deadline = time.monotonic() + max(0.0, grace_seconds)
|
|
262
|
-
while process is not None and process.poll() is None and time.monotonic() < deadline:
|
|
341
|
+
_signal_posix_tree(pid, signal.SIGTERM, "sigterm", details)
|
|
342
|
+
deadline = time.monotonic() + grace
|
|
343
|
+
while still_running() and time.monotonic() < deadline:
|
|
263
344
|
time.sleep(0.05)
|
|
264
|
-
if
|
|
345
|
+
if still_running():
|
|
265
346
|
forced = True
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
except OSError as exc:
|
|
272
|
-
details.append(f"sigkill_group_failed={type(exc).__name__}")
|
|
273
|
-
try:
|
|
274
|
-
os.kill(pid, signal.SIGKILL)
|
|
275
|
-
details.append("sigkill_process")
|
|
276
|
-
except OSError as inner:
|
|
277
|
-
details.append(f"sigkill_process_failed={type(inner).__name__}")
|
|
347
|
+
_signal_posix_tree(pid, signal.SIGKILL, "sigkill", details)
|
|
348
|
+
if grace > 0:
|
|
349
|
+
force_deadline = time.monotonic() + min(grace, 2.0)
|
|
350
|
+
while still_running() and time.monotonic() < force_deadline:
|
|
351
|
+
time.sleep(0.05)
|
|
278
352
|
|
|
279
353
|
return_code = None
|
|
280
354
|
if process is not None:
|
|
281
355
|
try:
|
|
282
|
-
return_code = process.wait(timeout=max(0.1,
|
|
356
|
+
return_code = process.wait(timeout=max(0.1, grace))
|
|
283
357
|
except subprocess.TimeoutExpired:
|
|
284
358
|
return_code = process.poll()
|
|
359
|
+
|
|
360
|
+
terminated = (taskkill_ok or (not still_running())) if os.name == "nt" else (not still_running())
|
|
285
361
|
return ProcessTerminationResult(
|
|
286
362
|
pid=pid,
|
|
287
363
|
reason=reason,
|
|
288
|
-
terminated=
|
|
364
|
+
terminated=terminated,
|
|
289
365
|
forced=forced,
|
|
290
366
|
return_code=return_code,
|
|
291
367
|
details=tuple(details),
|
|
292
368
|
)
|
|
293
369
|
|
|
294
370
|
|
|
371
|
+
def terminate_process_tree(
|
|
372
|
+
handle: ProcessHandle,
|
|
373
|
+
reason: str,
|
|
374
|
+
grace_seconds: float = 10.0,
|
|
375
|
+
) -> ProcessTerminationResult:
|
|
376
|
+
"""Terminate a process tree without relying on shell runtime logic.
|
|
377
|
+
|
|
378
|
+
POSIX uses the process group/session created at launch. Windows tries
|
|
379
|
+
graceful taskkill before forced ``taskkill /T /F`` when grace > 0.
|
|
380
|
+
"""
|
|
381
|
+
pid = handle.pid
|
|
382
|
+
if pid is None:
|
|
383
|
+
return ProcessTerminationResult(pid=None, reason=reason, terminated=False, forced=False, return_code=None)
|
|
384
|
+
return _terminate_tree_impl(pid, reason=reason, grace_seconds=grace_seconds, process=handle.popen)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def _windows_pid_running(pid: int) -> bool:
|
|
388
|
+
win_dll = getattr(ctypes, "WinDLL", None)
|
|
389
|
+
if win_dll is None:
|
|
390
|
+
try:
|
|
391
|
+
os.kill(pid, 0)
|
|
392
|
+
except PermissionError:
|
|
393
|
+
return True
|
|
394
|
+
except OSError:
|
|
395
|
+
return False
|
|
396
|
+
return True
|
|
397
|
+
kernel32 = win_dll("kernel32", use_last_error=True)
|
|
398
|
+
process_query_limited_information = 0x1000
|
|
399
|
+
still_active = 259
|
|
400
|
+
error_access_denied = 5
|
|
401
|
+
handle = kernel32.OpenProcess(process_query_limited_information, False, int(pid))
|
|
402
|
+
if not handle:
|
|
403
|
+
return ctypes.get_last_error() == error_access_denied
|
|
404
|
+
try:
|
|
405
|
+
exit_code = ctypes.c_ulong()
|
|
406
|
+
if not kernel32.GetExitCodeProcess(handle, ctypes.byref(exit_code)):
|
|
407
|
+
return False
|
|
408
|
+
return exit_code.value == still_active
|
|
409
|
+
finally:
|
|
410
|
+
kernel32.CloseHandle(handle)
|
|
411
|
+
|
|
412
|
+
|
|
295
413
|
def is_pid_running(pid: int | None) -> bool:
|
|
296
414
|
"""Return true when a PID appears alive."""
|
|
297
415
|
if pid is None or pid <= 0:
|
|
298
416
|
return False
|
|
417
|
+
if os.name == "nt":
|
|
418
|
+
return _windows_pid_running(pid)
|
|
299
419
|
try:
|
|
300
420
|
os.kill(pid, 0)
|
|
301
421
|
except ProcessLookupError:
|
|
@@ -304,15 +424,14 @@ def is_pid_running(pid: int | None) -> bool:
|
|
|
304
424
|
return True
|
|
305
425
|
except OSError:
|
|
306
426
|
return False
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return False
|
|
427
|
+
try:
|
|
428
|
+
waited_pid, _status = os.waitpid(pid, os.WNOHANG)
|
|
429
|
+
except ChildProcessError:
|
|
430
|
+
return True
|
|
431
|
+
except OSError:
|
|
432
|
+
return True
|
|
433
|
+
if waited_pid == pid:
|
|
434
|
+
return False
|
|
316
435
|
return True
|
|
317
436
|
|
|
318
437
|
|
|
@@ -321,83 +440,19 @@ def terminate_pid_tree(
|
|
|
321
440
|
reason: str,
|
|
322
441
|
grace_seconds: float = 10.0,
|
|
323
442
|
) -> ProcessTerminationResult:
|
|
324
|
-
"""Terminate a PID-backed process tree without requiring a live Popen.
|
|
325
|
-
|
|
326
|
-
Daemon stop commands reconstruct process state from a PID file, so the
|
|
327
|
-
original ``subprocess.Popen`` object is not available. POSIX daemons are
|
|
328
|
-
launched in a process group whose id is the daemon PID; Windows uses the
|
|
329
|
-
same taskkill-style tree termination strategy as ``terminate_process_tree``.
|
|
330
|
-
"""
|
|
443
|
+
"""Terminate a PID-backed process tree without requiring a live Popen."""
|
|
331
444
|
if pid is None or pid <= 0:
|
|
332
445
|
return ProcessTerminationResult(pid=pid, reason=reason, terminated=False, forced=False, return_code=None)
|
|
333
|
-
|
|
334
|
-
details: list[str] = []
|
|
335
|
-
forced = False
|
|
336
446
|
if not is_pid_running(pid):
|
|
337
|
-
return ProcessTerminationResult(pid=pid, reason=reason, terminated=False, forced=False, return_code=None, details=("not_running",))
|
|
338
|
-
|
|
339
|
-
if os.name == "nt":
|
|
340
|
-
completed = subprocess.run(
|
|
341
|
-
["taskkill", "/PID", str(pid), "/T", "/F"],
|
|
342
|
-
stdout=subprocess.PIPE,
|
|
343
|
-
stderr=subprocess.PIPE,
|
|
344
|
-
text=True,
|
|
345
|
-
check=False,
|
|
346
|
-
)
|
|
347
|
-
details.append(f"taskkill_exit={completed.returncode}")
|
|
348
447
|
return ProcessTerminationResult(
|
|
349
448
|
pid=pid,
|
|
350
449
|
reason=reason,
|
|
351
|
-
terminated=
|
|
352
|
-
forced=
|
|
450
|
+
terminated=False,
|
|
451
|
+
forced=False,
|
|
353
452
|
return_code=None,
|
|
354
|
-
details=
|
|
453
|
+
details=("not_running",),
|
|
355
454
|
)
|
|
356
|
-
|
|
357
|
-
try:
|
|
358
|
-
os.killpg(pid, signal.SIGTERM)
|
|
359
|
-
details.append("sigterm_process_group")
|
|
360
|
-
except ProcessLookupError:
|
|
361
|
-
pass
|
|
362
|
-
except OSError as exc:
|
|
363
|
-
details.append(f"sigterm_group_failed={type(exc).__name__}")
|
|
364
|
-
try:
|
|
365
|
-
os.kill(pid, signal.SIGTERM)
|
|
366
|
-
details.append("sigterm_process")
|
|
367
|
-
except OSError as inner:
|
|
368
|
-
details.append(f"sigterm_process_failed={type(inner).__name__}")
|
|
369
|
-
|
|
370
|
-
deadline = time.monotonic() + max(0.0, grace_seconds)
|
|
371
|
-
while is_pid_running(pid) and time.monotonic() < deadline:
|
|
372
|
-
time.sleep(0.05)
|
|
373
|
-
|
|
374
|
-
if is_pid_running(pid):
|
|
375
|
-
forced = True
|
|
376
|
-
try:
|
|
377
|
-
os.killpg(pid, signal.SIGKILL)
|
|
378
|
-
details.append("sigkill_process_group")
|
|
379
|
-
except ProcessLookupError:
|
|
380
|
-
pass
|
|
381
|
-
except OSError as exc:
|
|
382
|
-
details.append(f"sigkill_group_failed={type(exc).__name__}")
|
|
383
|
-
try:
|
|
384
|
-
os.kill(pid, signal.SIGKILL)
|
|
385
|
-
details.append("sigkill_process")
|
|
386
|
-
except OSError as inner:
|
|
387
|
-
details.append(f"sigkill_process_failed={type(inner).__name__}")
|
|
388
|
-
|
|
389
|
-
deadline = time.monotonic() + max(0.0, min(grace_seconds, 2.0))
|
|
390
|
-
while is_pid_running(pid) and time.monotonic() < deadline:
|
|
391
|
-
time.sleep(0.05)
|
|
392
|
-
|
|
393
|
-
return ProcessTerminationResult(
|
|
394
|
-
pid=pid,
|
|
395
|
-
reason=reason,
|
|
396
|
-
terminated=not is_pid_running(pid),
|
|
397
|
-
forced=forced,
|
|
398
|
-
return_code=None,
|
|
399
|
-
details=tuple(details),
|
|
400
|
-
)
|
|
455
|
+
return _terminate_tree_impl(pid, reason=reason, grace_seconds=grace_seconds)
|
|
401
456
|
|
|
402
457
|
|
|
403
458
|
|
|
@@ -10,19 +10,14 @@ from collections.abc import Sequence
|
|
|
10
10
|
from dataclasses import dataclass
|
|
11
11
|
from pathlib import Path
|
|
12
12
|
|
|
13
|
-
from .commands import CommandResult # type: ignore # runtime boundary import
|
|
14
13
|
from .gitops import (
|
|
15
|
-
BranchContext,
|
|
16
|
-
WorktreePolicy,
|
|
17
14
|
default_branch,
|
|
18
|
-
guarded_worktree_remove,
|
|
19
15
|
list_reset_branches,
|
|
20
16
|
reset_cleanup_branch,
|
|
21
|
-
worktree_runtime_context,
|
|
22
17
|
)
|
|
18
|
+
from .results import CommandResult
|
|
23
19
|
from .runner_models import RunnerFamily, family_for
|
|
24
20
|
from .task_checkout import (
|
|
25
|
-
CHECKOUT_MODE_WORKTREE,
|
|
26
21
|
TaskCheckout,
|
|
27
22
|
load_task_checkout,
|
|
28
23
|
mark_task_checkout_reset_locked,
|
|
@@ -60,7 +55,6 @@ class ResetItem:
|
|
|
60
55
|
FAMILY_LABELS = {
|
|
61
56
|
"feature": "feature",
|
|
62
57
|
"bugfix": "bug",
|
|
63
|
-
"refactor": "refactor",
|
|
64
58
|
}
|
|
65
59
|
|
|
66
60
|
FILTER_FLAGS = {
|
|
@@ -73,21 +67,18 @@ FILTER_FLAGS = {
|
|
|
73
67
|
ID_FIELD_BY_KIND = {
|
|
74
68
|
"feature": "id",
|
|
75
69
|
"bugfix": "id",
|
|
76
|
-
"refactor": "id",
|
|
77
70
|
}
|
|
78
71
|
|
|
79
72
|
|
|
80
73
|
TITLE_FIELD_BY_KIND = {
|
|
81
74
|
"feature": "title",
|
|
82
75
|
"bugfix": "title",
|
|
83
|
-
"refactor": "title",
|
|
84
76
|
}
|
|
85
77
|
|
|
86
78
|
|
|
87
79
|
BRANCH_PREFIX_BY_KIND = {
|
|
88
80
|
"feature": "dev",
|
|
89
81
|
"bugfix": "bugfix",
|
|
90
|
-
"refactor": "refactor",
|
|
91
82
|
}
|
|
92
83
|
|
|
93
84
|
STALLED_FILTER_STATUSES = {
|
|
@@ -100,7 +91,7 @@ STALLED_FILTER_STATUSES = {
|
|
|
100
91
|
|
|
101
92
|
|
|
102
93
|
def run_reset_command(kind: str, legacy_args: tuple[str, ...], paths) -> CommandResult:
|
|
103
|
-
"""Run a manual reset command for feature
|
|
94
|
+
"""Run a manual reset command for feature or bugfix."""
|
|
104
95
|
family = family_for(kind, paths)
|
|
105
96
|
try:
|
|
106
97
|
options = _parse_reset_args(family, legacy_args)
|
|
@@ -377,18 +368,6 @@ def _reset_one(family: RunnerFamily, item: ResetItem, options: ResetOptions, pro
|
|
|
377
368
|
if checkout is not None and (checkout.is_active or checkout.is_completed):
|
|
378
369
|
if checkout.active_dev_branch not in branches:
|
|
379
370
|
branches.insert(0, checkout.active_dev_branch)
|
|
380
|
-
if checkout.checkout_mode == CHECKOUT_MODE_WORKTREE:
|
|
381
|
-
runtime = worktree_runtime_context(
|
|
382
|
-
BranchContext(checkout.base_branch, checkout.active_dev_branch, project_root),
|
|
383
|
-
WorktreePolicy(True, True, True, Path(checkout.worktree_path).parent),
|
|
384
|
-
)
|
|
385
|
-
if runtime.worktree_path != Path(checkout.worktree_path).resolve():
|
|
386
|
-
lines.append(f"ERROR: Reset {item.item_id} worktree identity resolves to an unexpected path")
|
|
387
|
-
return False
|
|
388
|
-
removal = guarded_worktree_remove(runtime, delete_branch=False)
|
|
389
|
-
if not removal.ok:
|
|
390
|
-
lines.append(f"ERROR: Reset {item.item_id} could not remove linked worktree: {removal.reason}")
|
|
391
|
-
return False
|
|
392
371
|
|
|
393
372
|
for branch in branches:
|
|
394
373
|
cleanup = reset_cleanup_branch(project_root, branch, return_branch=return_branch, delete=options.clean)
|