stacktrace-cli 0.19.0__py3-none-any.whl → 0.19.1__py3-none-any.whl

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.
stacktrace/__init__.py CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import logging as _logging
4
4
 
5
- __version__ = "0.19.0"
5
+ __version__ = "0.19.1"
6
6
 
7
7
  # Only the daemon attaches a handler (ADR-0048). Without this one, a WARNING
8
8
  # logged in any other process would reach Python's last-resort handler and
stacktrace/cloud/boot.py CHANGED
@@ -6,18 +6,28 @@ One worker at a time holds `boot.lock`, from its own `daemon status` check
6
6
  until the daemon it starts answers. So a worker never replaces the client's
7
7
  files while a daemon runs or is starting: a second hook's worker waits, checks
8
8
  again, and finds the daemon up.
9
+
10
+ Each failure, and each daemon this worker had to start, is one line in
11
+ `session-start.log` (docs/specs/plugin-installation.md, "Session-start log").
12
+ The SessionStart adapters write their own failures through `write_log` here.
9
13
  """
10
14
 
11
15
  import fcntl
16
+ import json
12
17
  import os
13
18
  import pwd
19
+ import re
14
20
  import shlex
21
+ import stat
15
22
  import subprocess
16
23
  import sys
17
24
  import time
25
+ from contextlib import contextmanager
18
26
  from datetime import datetime, timezone
19
27
 
20
28
  STATE, UPDATE_ENV = "", ""
29
+ #: The session's agent kind, from the scope argument, or `-` when there is none.
30
+ KIND = "-"
21
31
  #: How long an update may take before the installed client runs instead.
22
32
  UPDATE_SECONDS = 120
23
33
  #: How long the lock waits for the daemon this worker started to answer.
@@ -26,6 +36,113 @@ START_SECONDS = 30
26
36
  #: transition lock while it uploads to Fleet, and refuses until it finishes.
27
37
  REGISTER_ATTEMPTS = 10
28
38
 
39
+ LOG_NAME = "session-start.log"
40
+ #: Past this size the log keeps only its last `LOG_LINES` lines.
41
+ LOG_BYTES = 64 * 1024
42
+ LOG_LINES = 500
43
+ #: An agent kind's shape. The kinds themselves are not listed: a new one needs no change here.
44
+ KIND_SHAPE = re.compile(r"[a-z][a-z0-9-]{0,31}")
45
+ STAGES = (
46
+ "input",
47
+ "scope",
48
+ "launch",
49
+ "lock",
50
+ "update",
51
+ "daemon-start",
52
+ "daemon-started",
53
+ "register",
54
+ "bootstrap",
55
+ )
56
+ #: A fixed word or an exception's type name. Never a message, a path or a value.
57
+ DETAIL = re.compile(r"[A-Za-z][A-Za-z0-9_.-]{0,63}")
58
+
59
+
60
+ def log_root():
61
+ """`state_root()` from `stacktrace.private_state`. Setup copies this file to
62
+ run on system Python, where the package need not import."""
63
+ default = os.path.join(os.path.expanduser("~"), ".local", "state", "stacktrace")
64
+ return os.environ.get("STACKTRACE_STATE_DIR", default)
65
+
66
+
67
+ def write_log(path, agent_kind, stage, detail):
68
+ """Append one line to the session-start log and trim it; never raise.
69
+
70
+ The writer accepts only a name-shaped kind, a known stage and a word-shaped detail, so
71
+ a call site that passes anything else writes `-` rather than the text."""
72
+ try:
73
+ if stage not in STAGES:
74
+ return
75
+ kind = (
76
+ agent_kind if isinstance(agent_kind, str) and KIND_SHAPE.fullmatch(agent_kind) else "-"
77
+ )
78
+ detail = detail if isinstance(detail, str) and DETAIL.fullmatch(detail) else "-"
79
+ line = f"{datetime.now(timezone.utc):%Y-%m-%dT%H:%M:%SZ} {kind} cli {stage} {detail}\n" # noqa: UP017 - legacy wrapper uses system Python, including 3.10
80
+ descriptor = os.open(path, os.O_RDWR | os.O_APPEND | os.O_CREAT | os.O_NOFOLLOW, 0o600)
81
+ except Exception: # noqa: BLE001 - logging never fails the session
82
+ return
83
+ try:
84
+ # Bounded wait: a writer holds the lock for one append and trim.
85
+ for _ in range(20):
86
+ try:
87
+ fcntl.flock(descriptor, fcntl.LOCK_EX | fcntl.LOCK_NB)
88
+ break
89
+ except BlockingIOError:
90
+ time.sleep(0.01)
91
+ else:
92
+ return
93
+ os.write(descriptor, line.encode("utf-8"))
94
+ size = os.fstat(descriptor).st_size
95
+ if size > LOG_BYTES:
96
+ kept = os.pread(descriptor, size, 0).splitlines(keepends=True)[-LOG_LINES:]
97
+ os.ftruncate(descriptor, 0)
98
+ os.write(descriptor, b"".join(kept))
99
+ except Exception: # noqa: BLE001, S110 - logging never fails the session
100
+ pass
101
+ finally:
102
+ os.close(descriptor)
103
+
104
+
105
+ def _private_directory(path):
106
+ """`ensure_private_directory` from `stacktrace.private_state`, for the same reason."""
107
+ os.makedirs(path, mode=0o700, exist_ok=True)
108
+ metadata = os.lstat(path)
109
+ if not stat.S_ISDIR(metadata.st_mode) or metadata.st_uid != os.getuid():
110
+ raise OSError("state directory is not a user-owned directory")
111
+ if stat.S_IMODE(metadata.st_mode) != 0o700:
112
+ os.chmod(path, 0o700)
113
+
114
+
115
+ def log(stage, detail):
116
+ """One line for this worker's session; never raise."""
117
+ try:
118
+ root = log_root()
119
+ _private_directory(root)
120
+ write_log(os.path.join(root, LOG_NAME), KIND, stage, detail)
121
+ except Exception: # noqa: BLE001, S110 - logging never fails the session
122
+ pass
123
+
124
+
125
+ @contextmanager
126
+ def stage(name):
127
+ """Log a failure inside this block by its type, once, and let it propagate."""
128
+ try:
129
+ yield
130
+ except Exception as error:
131
+ if not getattr(error, "session_start_logged", False):
132
+ setattr(error, "session_start_logged", True) # noqa: B010 - any exception type
133
+ log(name, type(error).__name__)
134
+ raise
135
+
136
+
137
+ def kind_of(arguments):
138
+ """The agent kind the scope argument names, else `-`."""
139
+ try:
140
+ scope = json.loads(arguments[0])
141
+ kind = scope.get("agent_kind") if isinstance(scope, dict) else None
142
+ except Exception: # noqa: BLE001 - registration reports a bad scope
143
+ return "-"
144
+ return kind if isinstance(kind, str) and KIND_SHAPE.fullmatch(kind) else "-"
145
+
29
146
 
30
147
  def note(text):
31
148
  with open(os.path.join(STATE, "update.log"), "a", encoding="utf-8") as log:
@@ -82,21 +199,26 @@ def update():
82
199
  f"not updating: {user} cannot run uv or write the install; "
83
200
  "rebuild the environment to update the client"
84
201
  )
202
+ log("update", "not-permitted")
85
203
  return
86
204
  environment = {**os.environ, **{k: v for k, v in values.items() if k.startswith("UV_")}}
87
- with open(os.path.join(STATE, "update.log"), "a", encoding="utf-8") as log:
205
+ with open(os.path.join(STATE, "update.log"), "a", encoding="utf-8") as output:
88
206
  try:
89
- subprocess.run(
207
+ result = subprocess.run(
90
208
  [uv, "tool", "upgrade", "stacktrace-cli"],
91
209
  env=environment,
92
210
  stdin=subprocess.DEVNULL,
93
- stdout=log,
211
+ stdout=output,
94
212
  stderr=subprocess.STDOUT,
95
213
  timeout=UPDATE_SECONDS,
96
214
  check=False,
97
215
  )
98
216
  except (OSError, subprocess.SubprocessError) as error:
99
217
  note(f"update stopped: {type(error).__name__}; the installed client runs")
218
+ log("update", type(error).__name__)
219
+ return
220
+ if result.returncode:
221
+ log("update", "nonzero-exit")
100
222
 
101
223
 
102
224
  def configure():
@@ -135,9 +257,11 @@ def configure():
135
257
 
136
258
 
137
259
  def ensure_daemon():
138
- lock = os.open(os.path.join(STATE, "boot.lock"), os.O_CREAT | os.O_RDWR, 0o600)
260
+ with stage("lock"):
261
+ lock = os.open(os.path.join(STATE, "boot.lock"), os.O_CREAT | os.O_RDWR, 0o600)
139
262
  try:
140
- fcntl.flock(lock, fcntl.LOCK_EX)
263
+ with stage("lock"):
264
+ fcntl.flock(lock, fcntl.LOCK_EX)
141
265
  configure()
142
266
  _ensure_daemon()
143
267
  finally:
@@ -153,10 +277,12 @@ def _ensure_daemon():
153
277
  # answer says nothing. Either may be a live client.
154
278
  if answer == "no":
155
279
  if os.environ.get("CLAUDE_CODE_REMOTE") == "true":
156
- update()
280
+ with stage("update"):
281
+ update()
157
282
  else:
158
283
  note(f"not updating: daemon status said {answer or 'nothing'}, not that no daemon runs")
159
- with open(os.path.join(STATE, "daemon.log"), "a", encoding="utf-8") as out:
284
+ daemon_log = os.path.join(STATE, "daemon.log")
285
+ with stage("daemon-start"), open(daemon_log, "a", encoding="utf-8") as out:
160
286
  subprocess.Popen(
161
287
  ["stacktrace", "daemon", "start", "--no-reasoning"],
162
288
  stdin=subprocess.DEVNULL,
@@ -165,33 +291,46 @@ def _ensure_daemon():
165
291
  start_new_session=True,
166
292
  )
167
293
  deadline = time.monotonic() + START_SECONDS
168
- while time.monotonic() < deadline and running() != "yes":
294
+ while time.monotonic() < deadline:
295
+ if running() == "yes":
296
+ log(
297
+ "daemon-started",
298
+ "was-stopped"
299
+ if answer == "no"
300
+ else "was-unresponsive"
301
+ if answer == "unresponsive"
302
+ else "no-status",
303
+ )
304
+ return
169
305
  time.sleep(0.5)
306
+ log("daemon-start", "timeout")
170
307
 
171
308
 
172
309
  def main():
310
+ global KIND
311
+ KIND = kind_of(sys.argv[3:4])
173
312
  os.makedirs(STATE, mode=0o700, exist_ok=True)
174
313
  os.chmod(STATE, 0o700)
175
314
  ensure_daemon()
176
315
  if len(sys.argv) > 3:
177
- import json
178
-
179
- from stacktrace.hooks.session import register
316
+ with stage("register"):
317
+ from stacktrace.hooks.session import register
180
318
 
181
- scope = json.loads(sys.argv[3])
182
- for attempt in range(REGISTER_ATTEMPTS):
183
- try:
184
- register(scope)
185
- return
186
- except Exception: # a busy daemon refuses or times out alike
187
- if attempt == REGISTER_ATTEMPTS - 1:
188
- raise
189
- time.sleep(1)
319
+ scope = json.loads(sys.argv[3])
320
+ for attempt in range(REGISTER_ATTEMPTS):
321
+ try:
322
+ register(scope)
323
+ return
324
+ except Exception: # a busy daemon refuses or times out alike
325
+ if attempt == REGISTER_ATTEMPTS - 1:
326
+ raise
327
+ time.sleep(1)
190
328
 
191
329
 
192
330
  if __name__ == "__main__":
193
331
  STATE, UPDATE_ENV = sys.argv[1], sys.argv[2]
194
332
  try:
195
- main()
333
+ with stage("bootstrap"):
334
+ main()
196
335
  except Exception: # noqa: BLE001 - never expose native payloads or credentials
197
336
  note("session bootstrap failed; inspect daemon status and rerun setup")
@@ -410,6 +410,8 @@ def _write_spool(path: Path, markers: Sequence[Marker]) -> None:
410
410
 
411
411
  def block_marker(
412
412
  keep: Callable[[Marker], None],
413
+ *,
414
+ clock: Callable[[], datetime] = lambda: datetime.now(UTC),
413
415
  ) -> Callable[[dict[str, object], Detection, DetectionEntry, int], None]:
414
416
  """Keep the marker of a detection block of a tool call or a prompt. Write
415
417
  no finding (ADR-0178).
@@ -448,7 +450,7 @@ def block_marker(
448
450
  outcome="blocked",
449
451
  where="hook",
450
452
  rules_version=__version__,
451
- blocked_at=datetime.now(UTC),
453
+ blocked_at=clock(),
452
454
  )
453
455
  )
454
456
 
@@ -457,6 +459,8 @@ def block_marker(
457
459
 
458
460
  def component_denial_recorder(
459
461
  keep: Callable[[Marker], object],
462
+ *,
463
+ clock: Callable[[], datetime] = lambda: datetime.now(UTC),
460
464
  ) -> Callable[[dict[str, object], str, PolicyEntry | None, int, Entry | None], None]:
461
465
  """Keep a component deny's marker. Write no finding (ADR-0184).
462
466
 
@@ -526,7 +530,7 @@ def component_denial_recorder(
526
530
  gate_evidence=gate_evidence(
527
531
  rule_id, resolved.evidence if resolved is not None else ()
528
532
  ),
529
- blocked_at=datetime.now(UTC),
533
+ blocked_at=clock(),
530
534
  )
531
535
  )
532
536
 
stacktrace/hooks/codex.py CHANGED
@@ -2,16 +2,15 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import json
6
5
  import re
7
6
  from collections.abc import Callable, Mapping
8
7
  from pathlib import Path, PurePath
9
8
  from typing import BinaryIO, TextIO
10
9
 
11
10
  from stacktrace.daemon.policy_runtime import Result, Scope
12
- from stacktrace.hooks.claude import MAX_HOOK_BYTES, authorize, with_occurrence
11
+ from stacktrace.hooks.claude import authorize, with_occurrence
13
12
  from stacktrace.hooks.claude import run_hook as run_native_hook
14
- from stacktrace.hooks.session import launch_bootstrap
13
+ from stacktrace.hooks.session import launch_bootstrap, start_session
15
14
 
16
15
  # Stable Codex 0.163.0 exposes canonical model namespaces, not raw provenance.
17
16
  # Unresolved or hashed names use the MCP default.
@@ -115,13 +114,11 @@ def run_hook(
115
114
 
116
115
 
117
116
  def run_session_start(stdin: BinaryIO, environment: Mapping[str, str]) -> None:
118
- try:
119
- raw = stdin.read(MAX_HOOK_BYTES + 1)
120
- if len(raw) > MAX_HOOK_BYTES:
121
- return
122
- payload = json.loads(raw)
123
- if not isinstance(payload, dict) or payload.get("hook_event_name") != "SessionStart":
124
- return
125
- launch_bootstrap(scope_from_hook(payload, environment))
126
- except Exception: # noqa: BLE001 - never expose native input or operational failures
127
- return
117
+ start_session(
118
+ stdin,
119
+ environment,
120
+ "codex",
121
+ "SessionStart",
122
+ lambda payload: scope_from_hook(payload, environment),
123
+ launch_bootstrap,
124
+ )
@@ -3,15 +3,14 @@ cloud call's ids leave this module."""
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
- import json
7
6
  from collections.abc import Callable, Mapping
8
7
  from pathlib import Path
9
8
  from typing import BinaryIO, TextIO
10
9
 
11
10
  from stacktrace.daemon.policy_runtime import Result, Scope
12
- from stacktrace.hooks.claude import MAX_HOOK_BYTES, authorize, with_occurrence
11
+ from stacktrace.hooks.claude import authorize, with_occurrence
13
12
  from stacktrace.hooks.claude import run_hook as run_native_hook
14
- from stacktrace.hooks.session import launch_bootstrap
13
+ from stacktrace.hooks.session import launch_bootstrap, start_session
15
14
 
16
15
 
17
16
  def scope_from_hook(environment: Mapping[str, str]) -> dict[str, object]:
@@ -96,13 +95,11 @@ def run_hook(
96
95
 
97
96
 
98
97
  def run_session_start(stdin: BinaryIO, environment: Mapping[str, str]) -> None:
99
- try:
100
- raw = stdin.read(MAX_HOOK_BYTES + 1)
101
- if len(raw) > MAX_HOOK_BYTES:
102
- return
103
- payload = json.loads(raw)
104
- if not isinstance(payload, dict) or payload.get("hook_event_name") != "sessionStart":
105
- return
106
- launch_bootstrap(scope_from_hook(environment))
107
- except Exception: # noqa: BLE001 - never expose native input or operational failures
108
- return
98
+ start_session(
99
+ stdin,
100
+ environment,
101
+ "cursor",
102
+ "sessionStart",
103
+ lambda _: scope_from_hook(environment),
104
+ launch_bootstrap,
105
+ )
stacktrace/hooks/devin.py CHANGED
@@ -2,15 +2,14 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import json
6
5
  from collections.abc import Callable, Mapping
7
6
  from pathlib import Path
8
7
  from typing import BinaryIO, TextIO
9
8
 
10
9
  from stacktrace.daemon.policy_runtime import Result, Scope
11
- from stacktrace.hooks.claude import MAX_HOOK_BYTES, authorize, with_occurrence
10
+ from stacktrace.hooks.claude import authorize, with_occurrence
12
11
  from stacktrace.hooks.claude import run_hook as run_native_hook
13
- from stacktrace.hooks.session import launch_bootstrap
12
+ from stacktrace.hooks.session import launch_bootstrap, start_session
14
13
 
15
14
  #: Devin's generic MCP tool, which names its server in its own input.
16
15
  GENERIC_MCP = "mcp_call_tool"
@@ -113,13 +112,11 @@ def run_hook(
113
112
 
114
113
 
115
114
  def run_session_start(stdin: BinaryIO, environment: Mapping[str, str]) -> None:
116
- try:
117
- raw = stdin.read(MAX_HOOK_BYTES + 1)
118
- if len(raw) > MAX_HOOK_BYTES:
119
- return
120
- payload = json.loads(raw)
121
- if not isinstance(payload, dict) or payload.get("hook_event_name") != "SessionStart":
122
- return
123
- launch_bootstrap(scope_from_hook(environment))
124
- except Exception: # noqa: BLE001 - never expose native input or operational failures
125
- return
115
+ start_session(
116
+ stdin,
117
+ environment,
118
+ "devin",
119
+ "SessionStart",
120
+ lambda _: scope_from_hook(environment),
121
+ launch_bootstrap,
122
+ )
@@ -5,13 +5,14 @@ from __future__ import annotations
5
5
  import json
6
6
  import subprocess
7
7
  import sys
8
- from collections.abc import Mapping
8
+ from collections.abc import Callable, Mapping
9
9
  from pathlib import Path
10
10
  from typing import BinaryIO
11
11
 
12
12
  from stacktrace.daemon.client import _round_trip
13
13
  from stacktrace.daemon.paths import RuntimePaths
14
14
  from stacktrace.hooks.claude import MAX_HOOK_BYTES
15
+ from stacktrace.private_state import ensure_private_directory, state_root
15
16
 
16
17
 
17
18
  def scope_from_environment(environment: Mapping[str, str]) -> dict[str, object]:
@@ -62,15 +63,65 @@ def launch_bootstrap(scope: dict[str, object]) -> None:
62
63
  )
63
64
 
64
65
 
65
- def run_session_start(stdin: BinaryIO, environment: Mapping[str, str]) -> None:
66
+ def log_failure(environment: Mapping[str, str], agent_kind: str, stage: str, detail: str) -> None:
67
+ """One line in `session-start.log` under the state root; never raise.
68
+
69
+ `detail` is a fixed word or an exception's type name. Native session input,
70
+ paths and exception messages never reach the log."""
71
+ try:
72
+ root = state_root(environment)
73
+ ensure_private_directory(root)
74
+ from stacktrace.cloud.boot import LOG_NAME, write_log
75
+
76
+ write_log(str(root / LOG_NAME), agent_kind, stage, detail)
77
+ except Exception: # noqa: BLE001, S110 - logging never fails the session
78
+ pass
79
+
80
+
81
+ def start_session(
82
+ stdin: BinaryIO,
83
+ environment: Mapping[str, str],
84
+ agent_kind: str,
85
+ event: str,
86
+ scope_of: Callable[[dict[str, object]], dict[str, object]],
87
+ launch: Callable[[dict[str, object]], None],
88
+ ) -> None:
89
+ """Read one bounded SessionStart event and launch the boot worker for its scope.
90
+
91
+ Every failure is one line in the session-start log and ends the hook quietly."""
66
92
  try:
67
93
  raw = stdin.read(MAX_HOOK_BYTES + 1)
68
- if len(raw) > MAX_HOOK_BYTES:
69
- return
94
+ except Exception as error: # noqa: BLE001 - native session input must never reach logs
95
+ log_failure(environment, agent_kind, "input", type(error).__name__)
96
+ return
97
+ if len(raw) > MAX_HOOK_BYTES:
98
+ log_failure(environment, agent_kind, "input", "oversized")
99
+ return
100
+ try:
70
101
  payload = json.loads(raw)
71
- if not isinstance(payload, dict) or payload.get("hook_event_name") != "SessionStart":
72
- return
73
- scope = scope_from_environment(environment)
74
- launch_bootstrap(scope)
75
- except Exception: # noqa: BLE001 - native session input must never reach logs or telemetry
102
+ except Exception: # noqa: BLE001 - too deep a document is invalid JSON here too
103
+ log_failure(environment, agent_kind, "input", "invalid-json")
104
+ return
105
+ if not isinstance(payload, dict) or payload.get("hook_event_name") != event:
106
+ log_failure(environment, agent_kind, "input", "wrong-event")
76
107
  return
108
+ try:
109
+ scope = scope_of(payload)
110
+ except Exception as error: # noqa: BLE001
111
+ log_failure(environment, agent_kind, "scope", type(error).__name__)
112
+ return
113
+ try:
114
+ launch(scope)
115
+ except Exception as error: # noqa: BLE001
116
+ log_failure(environment, agent_kind, "launch", type(error).__name__)
117
+
118
+
119
+ def run_session_start(stdin: BinaryIO, environment: Mapping[str, str]) -> None:
120
+ start_session(
121
+ stdin,
122
+ environment,
123
+ "claude-code",
124
+ "SessionStart",
125
+ lambda _: scope_from_environment(environment),
126
+ launch_bootstrap,
127
+ )
stacktrace/remote/cli.py CHANGED
@@ -269,6 +269,10 @@ def policy_status() -> None:
269
269
  try:
270
270
  status = default_policy_service().status()
271
271
  except PolicyServiceError as exc:
272
+ if exc.code == "not_installed":
273
+ click.echo("Service: not installed")
274
+ click.echo("For hook policy, run: stacktrace remote policy hooks status")
275
+ return
272
276
  raise click.ClickException(exc.code) from exc
273
277
  click.echo(f"Service: {'installed' if status.service_installed else 'not installed'}")
274
278
  click.echo(f"User: {status.user}")
@@ -248,6 +248,8 @@ class PolicyServiceManager(Protocol):
248
248
 
249
249
  def is_installed(self, paths: ServicePaths) -> bool: ...
250
250
 
251
+ def has_remnant(self, paths: ServicePaths) -> bool: ...
252
+
251
253
 
252
254
  Compiler = Callable[[JsonObject, Enrollment], JsonObject]
253
255
  ClientFactory = Callable[[str, str], PolicyClient]
@@ -581,6 +583,8 @@ class PolicyService:
581
583
  raise PolicyServiceError("service_uninstall_failed") from exc
582
584
 
583
585
  def status(self) -> PolicyStatus:
586
+ if not self._any_install_remains():
587
+ raise PolicyServiceError("not_installed")
584
588
  _verify_state_storage(self._paths, trusted_uid=self._trusted_uid, create=False)
585
589
  _trusted_state_file_exists(
586
590
  self._paths.state,
@@ -606,6 +610,23 @@ class PolicyService:
606
610
  last_error_at=state.last_error_at,
607
611
  )
608
612
 
613
+ def _any_install_remains(self) -> bool:
614
+ # Existence only: the enrollment is root-only, and status runs
615
+ # unprivileged. Anything left behind keeps the strict checks below,
616
+ # so a half-removed install still reports state_lost.
617
+ for path in (self._paths.enrollment, self._paths.state):
618
+ try:
619
+ path.lstat()
620
+ except FileNotFoundError:
621
+ continue
622
+ except OSError:
623
+ return True
624
+ return True
625
+ try:
626
+ return self._manager.has_remnant(self._paths)
627
+ except OSError as exc:
628
+ raise PolicyServiceError("service_status_failed") from exc
629
+
609
630
  def apply(self) -> ApplyResult:
610
631
  self._require_root()
611
632
  _verify_state_storage(self._paths, trusted_uid=self._trusted_uid, create=False)
@@ -867,6 +888,9 @@ class LaunchdPolicyManager:
867
888
  def is_installed(self, paths: ServicePaths) -> bool:
868
889
  return paths.launchd_plist.is_file()
869
890
 
891
+ def has_remnant(self, paths: ServicePaths) -> bool:
892
+ return paths.launchd_plist.is_file()
893
+
870
894
 
871
895
  class SystemdPolicyManager:
872
896
  def install(self, paths: ServicePaths) -> None:
@@ -923,6 +947,9 @@ class SystemdPolicyManager:
923
947
  def is_installed(self, paths: ServicePaths) -> bool:
924
948
  return paths.systemd_service.is_file() and paths.systemd_timer.is_file()
925
949
 
950
+ def has_remnant(self, paths: ServicePaths) -> bool:
951
+ return paths.systemd_service.is_file() or paths.systemd_timer.is_file()
952
+
926
953
 
927
954
  def _validate_mcp_selectors(value: object) -> None:
928
955
  if not isinstance(value, list) or len(value) > MAX_COLLECTION_ITEMS:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: stacktrace-cli
3
- Version: 0.19.0
3
+ Version: 0.19.1
4
4
  Summary: CLI for Stacktrace — Detection and Response platform for AI Agents.
5
5
  Project-URL: Homepage, https://stacktrace.ai
6
6
  Author-email: "Stacktrace AI, Inc" <founders@stacktrace.ai>
@@ -52,7 +52,7 @@ Requires Python 3.11 or newer.
52
52
 
53
53
  ```console
54
54
  $ stacktrace --version
55
- stacktrace 0.19.0
55
+ stacktrace 0.19.1
56
56
  ```
57
57
 
58
58
  ## Python package namespace
@@ -1,4 +1,4 @@
1
- stacktrace/__init__.py,sha256=NVOL_5Km8srQZqDtRLLddWyZvtz-zvNVKGo4Y6lL7KU,485
1
+ stacktrace/__init__.py,sha256=IKLuQTmpzf06JOYFFULNOn_5gf7bJBiktLNSu858PY8,485
2
2
  stacktrace/__main__.py,sha256=sb5puf0HWE4CNhPcUSK-C4eTcD8BEm3G_7h9qhQ_upo,310
3
3
  stacktrace/analysis.py,sha256=uPA9n_OhVbSOEPxofBo2lTLkVYjylvgAdP9Km7V4lmk,27783
4
4
  stacktrace/build.py,sha256=lXMXBMoQtXC5qVMAWBsJavcVfXPmJiAZgV3cRBqUvyk,4846
@@ -12,7 +12,7 @@ stacktrace/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  stacktrace/sdk.py,sha256=99XoWTFh0201H0paggiGsKNwrAEPiOELxKwherjjy10,8801
13
13
  stacktrace/cloud/__init__.py,sha256=yZJlXyMelYeHYo20erLQ7l7gBR1T_Du0Q60738738ic,1586
14
14
  stacktrace/cloud/agent_metadata.py,sha256=ygAvAqUlO_2KWzFtgp3w3sehtwcIWA1Lz3RzqO4En2Q,3866
15
- stacktrace/cloud/boot.py,sha256=EdQG0EDJOc9wANYUhp86hJb8Ipd466cpl_-42IZYZIs,6899
15
+ stacktrace/cloud/boot.py,sha256=otF3mzNhTqEjetpgfeINnfFWDMZv2Mszmob1aNsCjw0,12128
16
16
  stacktrace/cloud/profile.py,sha256=AHdX-D-BC7prJptEA8rtsUHRZxU3wmal0FlPx1GOyQ0,2437
17
17
  stacktrace/cloud/setup.sh,sha256=VACWdFn9SMfR3inCpBN4sbuVgBradQD-OmHdAy59Jxg,8087
18
18
  stacktrace/core/__init__.py,sha256=nE1MJ7QG6Y7wIOiJpF0nLIgHWzcrodU_tH19Hf77jnU,611
@@ -61,7 +61,7 @@ stacktrace/daemon/fleet.py,sha256=uDqTddy3i2ICmT_FFgpjb0BpIlFf8t0RbJFd4SnYvaA,33
61
61
  stacktrace/daemon/gateway.py,sha256=MhsGTmJau0zYqDjZbnh5QCUnS8PByXUzXqgRlY5v_Cw,6724
62
62
  stacktrace/daemon/gateway_policy.py,sha256=rHahc3hAtcTVUxlKU1_5nhFXQpl0qWQZVHqnMFGoO4s,8347
63
63
  stacktrace/daemon/identity.py,sha256=QIgmcRxT3qNikTIiotla6BvUMd_QJ35Ai5rF0jvsKPI,4484
64
- stacktrace/daemon/inline_hook.py,sha256=oyr0lQfLUDwg7h4chTDWywdQ9DXCc332AcVWCxyueYQ,22307
64
+ stacktrace/daemon/inline_hook.py,sha256=2GDMepEVitlZvl0JaAa5PKvE2gzNRyJSvGvRuaTVDLY,22427
65
65
  stacktrace/daemon/jobs.py,sha256=4inKEM5-Zn_3DBJLLvjJIGc7s9UUMjw54EHhlBW72CE,15007
66
66
  stacktrace/daemon/lifecycle.py,sha256=2FPewlnJyJoqLeBK1H4IP5mlYFgl8W_DEU6q6AcNYzc,5600
67
67
  stacktrace/daemon/observer.py,sha256=_GZxJhksQqJ4SEOtQd7-9qkRLvEMVQZumHZ0CuOHc6o,51046
@@ -129,11 +129,11 @@ stacktrace/gateway/tetrate/otlp.py,sha256=mh9UUkD-bEZcCFWEj77vYsRYoPPTRcj6zo-lNd
129
129
  stacktrace/gateway/tetrate/requestlog.py,sha256=vDj4T2d2T515l35gaU7IEsxz-_-z0Ifoi7MSLSRjeW8,5913
130
130
  stacktrace/hooks/__init__.py,sha256=kJWbZ0TLEUeaCP0dQL-H9O57WYVpbnqAMI3DsQtSoE4,71
131
131
  stacktrace/hooks/claude.py,sha256=4fdHF0KLv-mRzpa-PrIjZsuwi-_wRZYb4_wWw8mB1i8,18385
132
- stacktrace/hooks/codex.py,sha256=l-62eb_iXb9-3P7XH81SwHXpiDn8M9at9P1zBptkvHU,5197
133
- stacktrace/hooks/cursor.py,sha256=XTqALl71Mw6_-Ccb6LJJFMbz38IUoD59bo2N1FaN260,4377
134
- stacktrace/hooks/devin.py,sha256=Pi0utMP0OGwCo9KLZ-Hlwawsv7D7qchEQK8yTLwA7wQ,4822
132
+ stacktrace/hooks/codex.py,sha256=uzx14HxYJKt-GZlAW3wNeZCst6Flnhv6BE_4iApz130,4948
133
+ stacktrace/hooks/cursor.py,sha256=8mc699bLq8aGlkPjM9Hg2V7vxsYDrHrh8UZL0EKeyUA,4123
134
+ stacktrace/hooks/devin.py,sha256=Bs_8hM4vyhZKvGN1k_HmXIZ8HSYSmcv9Z2YzCW8cDGM,4567
135
135
  stacktrace/hooks/journal.py,sha256=KSl0ZvTg4n6s8-efCHPeylxGb6L5K7Eelc9m3S8tKSk,7122
136
- stacktrace/hooks/session.py,sha256=wL0yCVNpAQAjuLFj4vuwlZw4HN7L6U-W0UwQC-0iHt8,2728
136
+ stacktrace/hooks/session.py,sha256=DeYGDNjggXlvY4AqKrVgLqEj2_bkGrr51mUiFMYcbS8,4646
137
137
  stacktrace/monitor/__init__.py,sha256=E9DmMo5E2qmbf_M6nhUF9UGk7d6EpxW1YpPo2R9RvHw,465
138
138
  stacktrace/monitor/costs.py,sha256=xK-RJUgNg0sIELluLBeQrAyphmmINgdUJQnlKfyF6JQ,31476
139
139
  stacktrace/monitor/inventory.py,sha256=pPoc-GUDwG5PChO7d018wYmteiHfuJRczcJicF8rlGA,19620
@@ -158,7 +158,7 @@ stacktrace/monitor/site/fonts/dm-mono-500-latin.woff2,sha256=DiY9tSeXCG52NnnFT4T
158
158
  stacktrace/monitor/site/fonts/dm-sans-latin.woff2,sha256=qlMHFrDTUYZq99v6Pu5BIPs28tBxuv-MI0GFFBhlx_8,62556
159
159
  stacktrace/monitor/site/fonts/playfair-display-600-italic-latin.woff2,sha256=MwigA4adCGqQPiNmamCAOZ2rnjSWTQc7_OjIXMB2yBU,23228
160
160
  stacktrace/remote/__init__.py,sha256=Ba5yZEovOFNDWfgj0ycJkvglUTLN3C47RUQyX-r4opI,82
161
- stacktrace/remote/cli.py,sha256=7NMf5O4OSJZhgC_wmRuvulEvH-Oe062M1JWdYXR6-yM,23325
161
+ stacktrace/remote/cli.py,sha256=FaKjZR2rD7sxmrnFYWuons02avtPUf7ZZca-FHRiOs4,23519
162
162
  stacktrace/remote/client.py,sha256=nrWSaLRthFUcm4aq3g9mO09jNI0tGgs2gwB4nZ4fmsw,24505
163
163
  stacktrace/remote/config.py,sha256=ZSlckMUs9bc87pomQRtY7v1D3UgLo2HT31j9-VzIR0M,6849
164
164
  stacktrace/remote/detect_payload.py,sha256=DYkJsGINg84YU0Jo5wtc0c3k9yM7XFwiQ6cAAHsnP7M,26427
@@ -167,7 +167,7 @@ stacktrace/remote/identity.py,sha256=J-v0cvoCrDaF9-Lp9cI5pnS65PylHiLZ_b0i_LCJDsc
167
167
  stacktrace/remote/payload.py,sha256=NyXdibGtg3poKz5JbEUg1q40iCGGQ6FSB43wYdBtCbg,17637
168
168
  stacktrace/remote/policy.py,sha256=HQseYp4ji4NJ5_GKMrZxLgWN_CokVOgkx3Yh2L6-IAA,4057
169
169
  stacktrace/remote/policy_localize.py,sha256=n0PyugCqr80Rudk8AlGVjYKmu6XbNOc1aNLLmStHFD8,8394
170
- stacktrace/remote/policy_service.py,sha256=HI085X1IuhpG-wfG-3xdjx06XUeuax5pVYxTuuCQ5zg,60141
170
+ stacktrace/remote/policy_service.py,sha256=IgX6rPqv8_OF6AXLeDW9a1aW97C1TZN2DXTdwJHt-X8,61220
171
171
  stacktrace/remote/policy_show.py,sha256=EG5J1LcQmPmS94GViwGtV9HJ88V-H0-sXmV5bNALKxs,6747
172
172
  stacktrace/remote/policy_worker.py,sha256=A2Leimiqlw_8lkEZFD0nZ2QKGTfOZnnGRD8__LYympQ,2561
173
173
  stacktrace/remote/redact.py,sha256=PM16z5xBwGZfizj7YccaVToA76jH2gxOVqUsz3Jq-Ik,61324
@@ -192,7 +192,7 @@ stacktrace/telemetry/state.py,sha256=xR8CoN9YX5uA3TBYgJy9lqXLctXoHjLS3kcImMwY7B8
192
192
  stacktrace/webhook/__init__.py,sha256=6knjTNQA1ErM-AO6fQ60_TZqZzbVjQeDMU1XIPPCpo0,35
193
193
  stacktrace/webhook/cli.py,sha256=0wJ1_TfSNxrgNjFKOw9sticuJ0ucMMxdJNv8X2a9SZk,7467
194
194
  stacktrace/webhook/config.py,sha256=yOgW-zCy_4-MkqgcEqaDDUIGx3xI7BqniNr6meZI90E,8651
195
- stacktrace_cli-0.19.0.dist-info/METADATA,sha256=2dyokesK1jOLUHBSjEQF8kfFmysA2tba3xiZJZ-onjk,12790
196
- stacktrace_cli-0.19.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
197
- stacktrace_cli-0.19.0.dist-info/entry_points.txt,sha256=UmjeMBiOdmGfbMZCVfJWT7r0onKRYqPnCZJ1Xhz1UPY,103
198
- stacktrace_cli-0.19.0.dist-info/RECORD,,
195
+ stacktrace_cli-0.19.1.dist-info/METADATA,sha256=C8ImsAwg_XeEHWW8lmRg8hKv6YXL11487OjyQAsm52c,12790
196
+ stacktrace_cli-0.19.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
197
+ stacktrace_cli-0.19.1.dist-info/entry_points.txt,sha256=UmjeMBiOdmGfbMZCVfJWT7r0onKRYqPnCZJ1Xhz1UPY,103
198
+ stacktrace_cli-0.19.1.dist-info/RECORD,,