stacktrace-cli 0.15.0__py3-none-any.whl → 0.17.0__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 +1 -1
- stacktrace/cloud/boot.py +12 -1
- stacktrace/correlate/composition.py +9 -0
- stacktrace/cost/evidence.py +0 -10
- stacktrace/daemon/cli.py +17 -4
- stacktrace/daemon/config.py +12 -0
- stacktrace/daemon/policy_collect.py +128 -7
- stacktrace/daemon/policy_runtime.py +75 -15
- stacktrace/daemon/presentation.py +7 -0
- stacktrace/daemon/runtime.py +6 -1
- stacktrace/daemon/store.py +7 -0
- stacktrace/detector/deterministic.py +86 -7
- stacktrace/detector/personal_data.py +111 -20
- stacktrace/detector/prompts/jev-v3/stacktrace-infra-unsafe-action.json +1 -1
- stacktrace/detector/rules.py +3 -0
- stacktrace/detector/tlds.txt +1289 -0
- stacktrace/finding_contract.py +20 -0
- stacktrace/hooks/claude.py +25 -22
- stacktrace/hooks/cursor.py +84 -0
- stacktrace/monitor/render.py +1 -0
- stacktrace/monitor/site/app.js +1 -0
- stacktrace/remote/hook_policy.py +25 -3
- stacktrace/remote/policy.py +17 -1
- stacktrace/remote/policy_localize.py +211 -0
- stacktrace/remote/policy_worker.py +14 -1
- stacktrace/sessions/entrypoint.py +9 -6
- {stacktrace_cli-0.15.0.dist-info → stacktrace_cli-0.17.0.dist-info}/METADATA +10 -8
- {stacktrace_cli-0.15.0.dist-info → stacktrace_cli-0.17.0.dist-info}/RECORD +30 -27
- {stacktrace_cli-0.15.0.dist-info → stacktrace_cli-0.17.0.dist-info}/WHEEL +0 -0
- {stacktrace_cli-0.15.0.dist-info → stacktrace_cli-0.17.0.dist-info}/entry_points.txt +0 -0
stacktrace/__init__.py
CHANGED
stacktrace/cloud/boot.py
CHANGED
|
@@ -22,6 +22,9 @@ STATE, UPDATE_ENV = "", ""
|
|
|
22
22
|
UPDATE_SECONDS = 120
|
|
23
23
|
#: How long the lock waits for the daemon this worker started to answer.
|
|
24
24
|
START_SECONDS = 30
|
|
25
|
+
#: Registration attempts, a second apart. A daemon that just started holds its
|
|
26
|
+
#: transition lock while it uploads to Fleet, and refuses until it finishes.
|
|
27
|
+
REGISTER_ATTEMPTS = 10
|
|
25
28
|
|
|
26
29
|
|
|
27
30
|
def note(text):
|
|
@@ -175,7 +178,15 @@ def main():
|
|
|
175
178
|
|
|
176
179
|
from stacktrace.hooks.session import register
|
|
177
180
|
|
|
178
|
-
|
|
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)
|
|
179
190
|
|
|
180
191
|
|
|
181
192
|
if __name__ == "__main__":
|
|
@@ -266,6 +266,15 @@ def _declared_builtins(document: dict[str, Any], name: str) -> frozenset[str]:
|
|
|
266
266
|
return frozenset(names)
|
|
267
267
|
|
|
268
268
|
|
|
269
|
+
def declared_builtin_skills(document: dict[str, Any]) -> frozenset[str]:
|
|
270
|
+
"""The skills a BOM's agent ships, read as `composition_from_bom` reads them.
|
|
271
|
+
|
|
272
|
+
Hook admission asks this of a freshly collected BOM, so that both readers
|
|
273
|
+
of `openaca:builtin_skills` refuse the same malformed values.
|
|
274
|
+
"""
|
|
275
|
+
return _declared_builtins(document, _BUILTIN_SKILLS_PROPERTY)
|
|
276
|
+
|
|
277
|
+
|
|
269
278
|
def root_property(document: dict[str, Any], name: str) -> str | None:
|
|
270
279
|
"""One `metadata.component` property's value, or `None`.
|
|
271
280
|
|
stacktrace/cost/evidence.py
CHANGED
|
@@ -57,13 +57,3 @@ def tokens(count: int) -> str:
|
|
|
57
57
|
|
|
58
58
|
def _short(value: Decimal) -> str:
|
|
59
59
|
return f"{value:f}".rstrip("0").rstrip(".") if "." in f"{value:f}" else f"{value:f}"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def exact_tokens(count: int) -> str:
|
|
63
|
-
"""A limit someone set, stated exactly: `600M tokens`, `12.5M tokens`,
|
|
64
|
-
`500k tokens`, `1,234 tokens`."""
|
|
65
|
-
if count >= 1_000_000 and count % 100_000 == 0:
|
|
66
|
-
return f"{_short(Decimal(count) / 1_000_000)}M tokens"
|
|
67
|
-
if count >= 1_000 and count % 100 == 0:
|
|
68
|
-
return f"{_short(Decimal(count) / 1_000)}k tokens"
|
|
69
|
-
return f"{count:,} tokens"
|
stacktrace/daemon/cli.py
CHANGED
|
@@ -106,6 +106,12 @@ def _retry_while_starting(
|
|
|
106
106
|
" that fallback: a finding still uploads immediately when the scan commits it."
|
|
107
107
|
" Defaults to STACKTRACE_FLEET_INTERVAL, then 5m.",
|
|
108
108
|
)
|
|
109
|
+
@click.option(
|
|
110
|
+
"--policy-interval",
|
|
111
|
+
default=None,
|
|
112
|
+
help="How often to fetch Fleet policy. Minimum 1s."
|
|
113
|
+
" Defaults to STACKTRACE_POLICY_INTERVAL, then 1m.",
|
|
114
|
+
)
|
|
109
115
|
@click.option(
|
|
110
116
|
"--webhook-interval",
|
|
111
117
|
default=None,
|
|
@@ -141,6 +147,7 @@ def run_command(
|
|
|
141
147
|
scan_since: str | None,
|
|
142
148
|
agent_kinds: tuple[str, ...],
|
|
143
149
|
fleet_interval: str | None,
|
|
150
|
+
policy_interval: str | None,
|
|
144
151
|
webhook_interval: str | None,
|
|
145
152
|
bom_interval: str | None,
|
|
146
153
|
reasoning: bool,
|
|
@@ -168,6 +175,7 @@ def run_command(
|
|
|
168
175
|
scan_since=scan_since,
|
|
169
176
|
agent_kinds=agent_kinds,
|
|
170
177
|
fleet_interval=fleet_interval,
|
|
178
|
+
policy_interval=policy_interval,
|
|
171
179
|
webhook_interval=webhook_interval,
|
|
172
180
|
bom_interval=bom_interval,
|
|
173
181
|
reasoning=reasoning_flag,
|
|
@@ -203,10 +211,10 @@ def run_command(
|
|
|
203
211
|
def _reject_unobservable_kinds(config: DaemonConfig) -> None:
|
|
204
212
|
"""A kind with no observer would scan nothing, silently.
|
|
205
213
|
|
|
206
|
-
Fails at startup rather than at the first tick:
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
214
|
+
Fails at startup rather than at the first tick: a kind OpenACA builds a
|
|
215
|
+
BOM for can still be one OpenAIDR reads no sessions of, and a daemon
|
|
216
|
+
quietly finding nothing for one is the failure this refusal exists to make
|
|
217
|
+
loud. What can be observed is OpenAIDR's answer (ADR-0107).
|
|
210
218
|
"""
|
|
211
219
|
from stacktrace.sessions.access import observable_kinds
|
|
212
220
|
|
|
@@ -518,6 +526,11 @@ def start(reasoning: bool) -> None:
|
|
|
518
526
|
os.environ.pop(_JEV_KEY_ENV, None)
|
|
519
527
|
os.environ["STACKTRACE_REASONING"] = "false"
|
|
520
528
|
|
|
529
|
+
try:
|
|
530
|
+
DaemonConfig.resolve()
|
|
531
|
+
except ValueError as error:
|
|
532
|
+
raise click.ClickException(str(error)) from error
|
|
533
|
+
|
|
521
534
|
warning = ensure_internal_saved()
|
|
522
535
|
if warning is not None:
|
|
523
536
|
click.echo(f"stacktrace: {warning}", err=True)
|
stacktrace/daemon/config.py
CHANGED
|
@@ -26,6 +26,7 @@ SETTINGS: tuple[tuple[str, str, str], ...] = (
|
|
|
26
26
|
("scan_since", "STACKTRACE_SCAN_SINCE", "3d"),
|
|
27
27
|
("agent_kinds", "STACKTRACE_AGENT_KIND", "all"),
|
|
28
28
|
("fleet_interval", "STACKTRACE_FLEET_INTERVAL", "5m"),
|
|
29
|
+
("policy_interval", "STACKTRACE_POLICY_INTERVAL", "1m"),
|
|
29
30
|
("webhook_interval", "STACKTRACE_WEBHOOK_INTERVAL", "1m"),
|
|
30
31
|
("bom_interval", "STACKTRACE_BOM_INTERVAL", "6h"),
|
|
31
32
|
# ADR-0081: opt-in only. A detached `start` inherits this the same way it
|
|
@@ -167,6 +168,7 @@ class DaemonConfig:
|
|
|
167
168
|
scan_since: Setting
|
|
168
169
|
agent_kinds: Setting
|
|
169
170
|
fleet_interval: Setting
|
|
171
|
+
policy_interval: Setting
|
|
170
172
|
webhook_interval: Setting
|
|
171
173
|
bom_interval: Setting
|
|
172
174
|
reasoning: Setting
|
|
@@ -185,6 +187,13 @@ class DaemonConfig:
|
|
|
185
187
|
def fleet_interval_seconds(self) -> float:
|
|
186
188
|
return parse_duration(self.fleet_interval.value)
|
|
187
189
|
|
|
190
|
+
@property
|
|
191
|
+
def policy_interval_seconds(self) -> float:
|
|
192
|
+
seconds = parse_duration(self.policy_interval.value)
|
|
193
|
+
if seconds == 0:
|
|
194
|
+
raise ValueError("policy interval must be at least 1s")
|
|
195
|
+
return seconds
|
|
196
|
+
|
|
188
197
|
@property
|
|
189
198
|
def webhook_interval_seconds(self) -> float:
|
|
190
199
|
return parse_duration(self.webhook_interval.value)
|
|
@@ -250,6 +259,7 @@ class DaemonConfig:
|
|
|
250
259
|
scan_since: str | None = None,
|
|
251
260
|
agent_kinds: Sequence[str] = (),
|
|
252
261
|
fleet_interval: str | None = None,
|
|
262
|
+
policy_interval: str | None = None,
|
|
253
263
|
webhook_interval: str | None = None,
|
|
254
264
|
bom_interval: str | None = None,
|
|
255
265
|
reasoning: bool | None = None,
|
|
@@ -268,6 +278,7 @@ class DaemonConfig:
|
|
|
268
278
|
"scan_since": scan_since,
|
|
269
279
|
"agent_kinds": ",".join(agent_kinds) if agent_kinds else None,
|
|
270
280
|
"fleet_interval": fleet_interval,
|
|
281
|
+
"policy_interval": policy_interval,
|
|
271
282
|
"webhook_interval": webhook_interval,
|
|
272
283
|
"bom_interval": bom_interval,
|
|
273
284
|
"reasoning": None if reasoning is None else ("true" if reasoning else "false"),
|
|
@@ -295,6 +306,7 @@ class DaemonConfig:
|
|
|
295
306
|
config.scan_interval_seconds,
|
|
296
307
|
config.scan_since_window,
|
|
297
308
|
config.fleet_interval_seconds,
|
|
309
|
+
config.policy_interval_seconds,
|
|
298
310
|
config.webhook_interval_seconds,
|
|
299
311
|
config.bom_interval_seconds,
|
|
300
312
|
config.reasoning_enabled,
|
|
@@ -14,6 +14,7 @@ import os
|
|
|
14
14
|
import signal
|
|
15
15
|
import subprocess
|
|
16
16
|
import sys
|
|
17
|
+
from collections.abc import Iterable, Mapping
|
|
17
18
|
from dataclasses import asdict
|
|
18
19
|
from pathlib import Path
|
|
19
20
|
from typing import Any
|
|
@@ -22,7 +23,9 @@ from uuid import uuid4
|
|
|
22
23
|
import openaca.core
|
|
23
24
|
from openaca.core import ComponentRef, Policy, apply_risk_gates, parse_policy
|
|
24
25
|
|
|
26
|
+
from stacktrace.correlate.composition import declared_builtin_skills
|
|
25
27
|
from stacktrace.policy_display import MAX_RULE_DETAIL, policy_rows, valid_rule_detail
|
|
28
|
+
from stacktrace.remote.policy_localize import collect_local_agents, localize_policy
|
|
26
29
|
|
|
27
30
|
from .policy_runtime import Collected, Entry, EvidenceIds, Scope
|
|
28
31
|
|
|
@@ -34,6 +37,9 @@ def collector_available(agent_kind: str = "claude-code") -> bool:
|
|
|
34
37
|
collector = getattr(openaca.core, "collect_policy_evidence", None)
|
|
35
38
|
if not callable(collector):
|
|
36
39
|
return False
|
|
40
|
+
if agent_kind == "cursor":
|
|
41
|
+
# Releases before Cursor accept `agent_kind` but reject this kind at runtime.
|
|
42
|
+
return agent_kind in getattr(openaca.core, "POLICY_EVIDENCE_AGENT_KINDS", ())
|
|
37
43
|
return agent_kind != "codex" or "agent_kind" in inspect.signature(collector).parameters
|
|
38
44
|
|
|
39
45
|
|
|
@@ -60,12 +66,16 @@ def _source(ref: ComponentRef, scope: Scope) -> str | None:
|
|
|
60
66
|
return None
|
|
61
67
|
|
|
62
68
|
|
|
63
|
-
def evaluate_bundle(
|
|
69
|
+
def evaluate_bundle(
|
|
70
|
+
policy: Policy, evidence: Any, scope: Scope, origins: Mapping[str, str] | None = None
|
|
71
|
+
) -> tuple[Entry, ...]:
|
|
64
72
|
"""Project facade decisions onto host selectors; never duplicate DSL matching.
|
|
65
73
|
|
|
66
74
|
`Any` is the version-gated PolicyEvidence returned by the new facade. Older
|
|
67
75
|
pinned releases remain usable with admission disabled, and enable refuses
|
|
68
76
|
them. The facade contract tests exercise the new API with the dependency PR.
|
|
77
|
+
`origins` maps a rule that `localize_policy` added to the Fleet rule it
|
|
78
|
+
stands for, so a denial names the rule the administrator wrote.
|
|
69
79
|
"""
|
|
70
80
|
decisions = apply_risk_gates(
|
|
71
81
|
policy,
|
|
@@ -106,12 +116,29 @@ def evaluate_bundle(policy: Policy, evidence: Any, scope: Scope) -> tuple[Entry,
|
|
|
106
116
|
continue
|
|
107
117
|
blocked = decision.blocked
|
|
108
118
|
rule = next(iter(getattr(decision, "rule_paths", ())), None) if blocked else None
|
|
119
|
+
rule = (origins or {}).get(rule, rule) if rule is not None else None
|
|
109
120
|
detail = descriptions.get(rule) if rule is not None else None
|
|
110
121
|
if detail is not None and len(detail) > MAX_RULE_DETAIL:
|
|
111
122
|
detail = detail[: MAX_RULE_DETAIL - 3] + "..."
|
|
112
123
|
if scope.agent_kind == "codex":
|
|
113
124
|
entries.append((Entry("mcp_tool", name, "codex", blocked, rule, detail), 0))
|
|
114
125
|
continue
|
|
126
|
+
if scope.agent_kind == "cursor":
|
|
127
|
+
if component_type != "mcp_server" or ref.extra.get("enabled") is False:
|
|
128
|
+
continue
|
|
129
|
+
# Cursor names a plugin's server `plugin-<plugin>-<server>`, and a project
|
|
130
|
+
# server shadows a user server of the same name.
|
|
131
|
+
manifest = Path(ref.source_manifest).resolve()
|
|
132
|
+
if decision.controlled_by_plugin:
|
|
133
|
+
alias, rank = f"plugin-{decision.subject.ref.name}-{name}", 0
|
|
134
|
+
elif manifest == (Path(scope.project_root) / ".cursor" / "mcp.json").resolve():
|
|
135
|
+
alias, rank = name, 1
|
|
136
|
+
elif manifest == Path(scope.global_config).resolve():
|
|
137
|
+
alias, rank = name, 0
|
|
138
|
+
else:
|
|
139
|
+
continue
|
|
140
|
+
entries.append((Entry("mcp_tool", alias, "cursor", blocked, rule, detail), rank))
|
|
141
|
+
continue
|
|
115
142
|
owner = decision.subject.ref.name if decision.controlled_by_plugin else None
|
|
116
143
|
source = "plugin" if owner else _source(ref, scope)
|
|
117
144
|
rank = 1 if source in {"project", "local"} and not owner and ":" not in name else 0
|
|
@@ -145,6 +172,42 @@ def evaluate_bundle(policy: Policy, evidence: Any, scope: Scope) -> tuple[Entry,
|
|
|
145
172
|
)
|
|
146
173
|
|
|
147
174
|
|
|
175
|
+
def unclaimed_builtin_skills(evidence: Any, declared: Iterable[str]) -> tuple[str, ...]:
|
|
176
|
+
"""The built-in skill names that no collected skill or command takes.
|
|
177
|
+
|
|
178
|
+
Installed always wins, as in correlation: the names are ordinary words
|
|
179
|
+
that a user's own skill may take. A collected skill counts even when no
|
|
180
|
+
selector places it, so a built-in name never admits an installed skill.
|
|
181
|
+
"""
|
|
182
|
+
taken: set[object] = set()
|
|
183
|
+
for component in evidence.components:
|
|
184
|
+
ref = component.ref
|
|
185
|
+
if ref.extra.get("component_type") not in {"skill", "command"}:
|
|
186
|
+
continue
|
|
187
|
+
taken.add(ref.name)
|
|
188
|
+
path = ref.extra.get("component_path")
|
|
189
|
+
if isinstance(path, list) and path and isinstance(path[-1], dict):
|
|
190
|
+
taken.add(path[-1].get("name"))
|
|
191
|
+
return tuple(sorted(set(declared) - taken))
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def builtin_claim_paths(scope: Scope, name: str) -> tuple[str, ...]:
|
|
195
|
+
"""The files an installed skill or command named `name` would be read from.
|
|
196
|
+
|
|
197
|
+
Only the direct surfaces. A project skill under a nested `.claude` directory
|
|
198
|
+
waits for the hourly collection. A name that is not one path segment names
|
|
199
|
+
no file.
|
|
200
|
+
"""
|
|
201
|
+
if name in {".", ".."} or "/" in name or "\\" in name or "\x00" in name:
|
|
202
|
+
return ()
|
|
203
|
+
roots = (Path(scope.config_root), Path(scope.project_root) / ".claude")
|
|
204
|
+
return tuple(
|
|
205
|
+
str(path)
|
|
206
|
+
for root in roots
|
|
207
|
+
for path in (root / "skills" / name / "SKILL.md", root / "commands" / f"{name}.md")
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
|
|
148
211
|
def inventory_digest(evidence: Any) -> str:
|
|
149
212
|
"""Hash collected identity, configuration and graph ownership without exporting them."""
|
|
150
213
|
graphs: dict[int, str] = {}
|
|
@@ -199,7 +262,12 @@ def collect_bounded(document: dict[str, object], scope: Scope) -> Collected:
|
|
|
199
262
|
if process.returncode or len(output) > MAX_BUNDLE_BYTES:
|
|
200
263
|
raise ValueError("policy_evidence_unavailable")
|
|
201
264
|
bundle = json.loads(output)
|
|
202
|
-
if not isinstance(bundle, dict) or set(bundle) != {
|
|
265
|
+
if not isinstance(bundle, dict) or set(bundle) != {
|
|
266
|
+
"entries",
|
|
267
|
+
"evidence",
|
|
268
|
+
"watch_paths",
|
|
269
|
+
"builtin_skills",
|
|
270
|
+
}:
|
|
203
271
|
raise ValueError("policy_evidence_invalid")
|
|
204
272
|
identifiers = bundle["evidence"]
|
|
205
273
|
if not isinstance(identifiers, dict) or set(identifiers) != {
|
|
@@ -250,7 +318,14 @@ def collect_bounded(document: dict[str, object], scope: Scope) -> Collected:
|
|
|
250
318
|
)
|
|
251
319
|
):
|
|
252
320
|
raise ValueError("policy_evidence_invalid")
|
|
253
|
-
|
|
321
|
+
builtins = bundle["builtin_skills"]
|
|
322
|
+
if (
|
|
323
|
+
not isinstance(builtins, list)
|
|
324
|
+
or len(builtins) > 4096
|
|
325
|
+
or any(not isinstance(name, str) or not name or len(name) > 4096 for name in builtins)
|
|
326
|
+
):
|
|
327
|
+
raise ValueError("policy_evidence_invalid")
|
|
328
|
+
return Collected(tuple(entries), EvidenceIds(**identifiers), tuple(paths), frozenset(builtins))
|
|
254
329
|
|
|
255
330
|
|
|
256
331
|
def main() -> int:
|
|
@@ -273,7 +348,14 @@ def main() -> int:
|
|
|
273
348
|
# as the launching host, without mutating the resident daemon's env.
|
|
274
349
|
root = Path(scope.config_root)
|
|
275
350
|
target: Path | None = root
|
|
276
|
-
if scope.agent_kind == "
|
|
351
|
+
if scope.agent_kind == "cursor":
|
|
352
|
+
# OpenACA reads Cursor only from this home's root (its ADR-0054).
|
|
353
|
+
if root != (Path.home() / ".cursor").resolve() or Path(scope.global_config) != (
|
|
354
|
+
root / "mcp.json"
|
|
355
|
+
):
|
|
356
|
+
raise ValueError("invalid_global_config")
|
|
357
|
+
target = None
|
|
358
|
+
elif scope.agent_kind == "codex":
|
|
277
359
|
if Path(scope.global_config) != (root / "config.toml").resolve():
|
|
278
360
|
raise ValueError("invalid_global_config")
|
|
279
361
|
os.environ["CODEX_HOME"] = str(root)
|
|
@@ -298,7 +380,7 @@ def main() -> int:
|
|
|
298
380
|
os.dup2(quiet.fileno(), 2)
|
|
299
381
|
policy = parse_policy(request["document"])
|
|
300
382
|
options: dict[str, Any] = (
|
|
301
|
-
{"agent_kind": scope.agent_kind} if scope.agent_kind
|
|
383
|
+
{"agent_kind": scope.agent_kind} if scope.agent_kind != "claude-code" else {}
|
|
302
384
|
)
|
|
303
385
|
if "allow_partial_inventory" in inspect.signature(collector).parameters:
|
|
304
386
|
options["allow_partial_inventory"] = True
|
|
@@ -322,7 +404,40 @@ def main() -> int:
|
|
|
322
404
|
if component.ref.source_manifest
|
|
323
405
|
}
|
|
324
406
|
)
|
|
325
|
-
|
|
407
|
+
# `PolicyEvidence` carries neither built-ins nor upload forms. The
|
|
408
|
+
# BOM the uploader would collect here carries both. Without it the
|
|
409
|
+
# document applies as Fleet wrote it and no skill is built-in.
|
|
410
|
+
agents = collect_local_agents(
|
|
411
|
+
config_dir=target, project=Path(scope.project_root), agent_kind=scope.agent_kind
|
|
412
|
+
)
|
|
413
|
+
localized = localize_policy(
|
|
414
|
+
request["document"], agents, project=Path(scope.project_root)
|
|
415
|
+
)
|
|
416
|
+
entries = evaluate_bundle(
|
|
417
|
+
parse_policy(localized.document), evidence, scope, localized.origins
|
|
418
|
+
)
|
|
419
|
+
# Only the Claude adapter sends skill and command actions.
|
|
420
|
+
declared = frozenset[str]().union(*(declared_builtin_skills(a.bom) for a in agents))
|
|
421
|
+
builtins = (
|
|
422
|
+
unclaimed_builtin_skills(evidence, declared)
|
|
423
|
+
if scope.agent_kind == "claude-code"
|
|
424
|
+
else ()
|
|
425
|
+
)
|
|
426
|
+
# A file in an existing directory leaves the directory unchanged.
|
|
427
|
+
# Watch where an installed skill or command with a built-in name goes.
|
|
428
|
+
paths = sorted(
|
|
429
|
+
{*paths, *(p for name in builtins for p in builtin_claim_paths(scope, name))}
|
|
430
|
+
)
|
|
431
|
+
if scope.agent_kind == "cursor":
|
|
432
|
+
# Cursor caches each plugin at `<marketplace>/<plugin>/<version>`. A new
|
|
433
|
+
# plugin or version changes only the directory above it.
|
|
434
|
+
cache = root / "plugins" / "cache"
|
|
435
|
+
paths = sorted(
|
|
436
|
+
{
|
|
437
|
+
*paths,
|
|
438
|
+
*(str(p) for p in (*cache.glob("*"), *cache.glob("*/*")) if p.is_dir()),
|
|
439
|
+
}
|
|
440
|
+
)
|
|
326
441
|
os.dup2(saved_stdout, 1)
|
|
327
442
|
os.close(saved_stdout)
|
|
328
443
|
output = json.dumps(
|
|
@@ -332,9 +447,15 @@ def main() -> int:
|
|
|
332
447
|
],
|
|
333
448
|
"evidence": asdict(identifiers),
|
|
334
449
|
"watch_paths": paths,
|
|
450
|
+
"builtin_skills": list(builtins),
|
|
335
451
|
}
|
|
336
452
|
).encode()
|
|
337
|
-
if
|
|
453
|
+
if (
|
|
454
|
+
len(entries) > 4096
|
|
455
|
+
or len(paths) > 4096
|
|
456
|
+
or len(builtins) > 4096
|
|
457
|
+
or len(output) > MAX_BUNDLE_BYTES
|
|
458
|
+
):
|
|
338
459
|
return 1
|
|
339
460
|
sys.stdout.buffer.write(output)
|
|
340
461
|
return 0
|
|
@@ -28,6 +28,8 @@ from stacktrace.remote.sync import _asset_transition_lock
|
|
|
28
28
|
|
|
29
29
|
REFRESH_INTERVAL = 3600.0
|
|
30
30
|
MAX_SCOPES = 64
|
|
31
|
+
#: Agent kinds with a native admission adapter, and each one's global configuration file.
|
|
32
|
+
GLOBAL_CONFIG = {"claude-code": ".claude.json", "codex": "config.toml", "cursor": "mcp.json"}
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
@dataclass(frozen=True)
|
|
@@ -38,16 +40,13 @@ class Scope:
|
|
|
38
40
|
agent_kind: str = "claude-code"
|
|
39
41
|
|
|
40
42
|
def __post_init__(self) -> None:
|
|
41
|
-
if self.agent_kind not in
|
|
43
|
+
if self.agent_kind not in GLOBAL_CONFIG:
|
|
42
44
|
raise ValueError("unsupported_agent")
|
|
43
45
|
if not self.global_config:
|
|
44
46
|
object.__setattr__(
|
|
45
47
|
self,
|
|
46
48
|
"global_config",
|
|
47
|
-
str(
|
|
48
|
-
Path(self.config_root)
|
|
49
|
-
/ ("config.toml" if self.agent_kind == "codex" else ".claude.json")
|
|
50
|
-
),
|
|
49
|
+
str(Path(self.config_root) / GLOBAL_CONFIG[self.agent_kind]),
|
|
51
50
|
)
|
|
52
51
|
for value in (self.config_root, self.project_root, self.global_config):
|
|
53
52
|
if not value or len(value) > 4096 or "\x00" in value or not Path(value).is_absolute():
|
|
@@ -104,6 +103,8 @@ class Collected:
|
|
|
104
103
|
entries: tuple[Entry, ...]
|
|
105
104
|
evidence: EvidenceIds
|
|
106
105
|
watch_paths: tuple[str, ...] = ()
|
|
106
|
+
#: Skills the agent ships, by a name no collected skill or command takes.
|
|
107
|
+
builtin_skills: frozenset[str] = frozenset()
|
|
107
108
|
|
|
108
109
|
|
|
109
110
|
@dataclass(frozen=True)
|
|
@@ -117,6 +118,7 @@ class Snapshot:
|
|
|
117
118
|
collected_wall_at: float
|
|
118
119
|
rules: Mapping[tuple[str, str, str], tuple[str | None, str | None]]
|
|
119
120
|
document_json: str
|
|
121
|
+
builtin_skills: frozenset[str] = frozenset()
|
|
120
122
|
|
|
121
123
|
|
|
122
124
|
class DecisionCache:
|
|
@@ -171,6 +173,7 @@ class DecisionCache:
|
|
|
171
173
|
collected_at: float,
|
|
172
174
|
collected_wall_at: float | None = None,
|
|
173
175
|
evidence: EvidenceIds | None = None,
|
|
176
|
+
builtin_skills: frozenset[str] = frozenset(),
|
|
174
177
|
) -> bool:
|
|
175
178
|
with self.guard:
|
|
176
179
|
if token != self.capture(token.scope):
|
|
@@ -191,6 +194,7 @@ class DecisionCache:
|
|
|
191
194
|
self.wall_clock() if collected_wall_at is None else collected_wall_at,
|
|
192
195
|
MappingProxyType(rules),
|
|
193
196
|
json.dumps(self.state.document, separators=(",", ":")),
|
|
197
|
+
builtin_skills,
|
|
194
198
|
)
|
|
195
199
|
return True
|
|
196
200
|
|
|
@@ -222,7 +226,13 @@ class DecisionCache:
|
|
|
222
226
|
blocked = snapshot.decisions.get((kind, name, source))
|
|
223
227
|
if blocked is None:
|
|
224
228
|
return self._default(
|
|
225
|
-
snapshot.policy,
|
|
229
|
+
snapshot.policy,
|
|
230
|
+
revision,
|
|
231
|
+
kind,
|
|
232
|
+
name,
|
|
233
|
+
source,
|
|
234
|
+
"subject_unresolved",
|
|
235
|
+
snapshot.builtin_skills,
|
|
226
236
|
)
|
|
227
237
|
return Result(
|
|
228
238
|
"deny" if blocked else "allow",
|
|
@@ -233,11 +243,25 @@ class DecisionCache:
|
|
|
233
243
|
|
|
234
244
|
@staticmethod
|
|
235
245
|
def _default(
|
|
236
|
-
policy: Policy | None,
|
|
246
|
+
policy: Policy | None,
|
|
247
|
+
revision: int | None,
|
|
248
|
+
kind: str,
|
|
249
|
+
name: str,
|
|
250
|
+
source: str,
|
|
251
|
+
reason: str,
|
|
252
|
+
builtin_skills: frozenset[str] = frozenset(),
|
|
237
253
|
) -> Result:
|
|
238
|
-
"""Use defaults from the same policy as the active decision table.
|
|
254
|
+
"""Use defaults from the same policy as the active decision table.
|
|
255
|
+
|
|
256
|
+
A skill the agent ships has no policy target, so no default applies to
|
|
257
|
+
it. The collector already removed every name an installed skill takes.
|
|
258
|
+
A namespaced name is a plugin's, and the plugin default decides it. The
|
|
259
|
+
rule stays out of `decide`: a gateway has no local BOM to name them.
|
|
260
|
+
"""
|
|
239
261
|
if policy is None:
|
|
240
262
|
return Result("defer", reason, revision)
|
|
263
|
+
if kind in {"skill", "command"} and ":" not in name and name in builtin_skills:
|
|
264
|
+
return Result("allow", "builtin_skill", revision)
|
|
241
265
|
return decide(Subject(kind, name, source), policy, revision) or Result(
|
|
242
266
|
"defer", reason, revision
|
|
243
267
|
)
|
|
@@ -259,7 +283,7 @@ def decide(subject: Subject, policy: Policy, revision: int | None = None) -> Res
|
|
|
259
283
|
subject no evidence resolved, and the gateway, which sees names only.
|
|
260
284
|
"""
|
|
261
285
|
kind, name, source = subject.kind, subject.name, subject.source
|
|
262
|
-
if kind == "mcp_tool" and source in {"user", "project", "local", "codex"}:
|
|
286
|
+
if kind == "mcp_tool" and source in {"user", "project", "local", "codex", "cursor"}:
|
|
263
287
|
default = policy.mcps.default
|
|
264
288
|
category = "mcps"
|
|
265
289
|
elif (
|
|
@@ -293,6 +317,11 @@ def configuration_digest(scope: Scope, watch_paths: tuple[str, ...]) -> str:
|
|
|
293
317
|
str(project / ".claude" / "settings.json"),
|
|
294
318
|
str(project / ".claude" / "settings.local.json"),
|
|
295
319
|
str(root / "plugins" / "installed_plugins.json"),
|
|
320
|
+
# A new entry here can take a built-in skill's name and end its exemption.
|
|
321
|
+
str(root / "skills"),
|
|
322
|
+
str(root / "commands"),
|
|
323
|
+
str(project / ".claude" / "skills"),
|
|
324
|
+
str(project / ".claude" / "commands"),
|
|
296
325
|
*watch_paths,
|
|
297
326
|
}
|
|
298
327
|
if scope.agent_kind == "codex":
|
|
@@ -304,6 +333,19 @@ def configuration_digest(scope: Scope, watch_paths: tuple[str, ...]) -> str:
|
|
|
304
333
|
str(project / ".codex/config.toml"),
|
|
305
334
|
*watch_paths,
|
|
306
335
|
}
|
|
336
|
+
elif scope.agent_kind == "cursor":
|
|
337
|
+
# A plugin install adds a cache directory before any manifest we already watch.
|
|
338
|
+
paths = {
|
|
339
|
+
str(root),
|
|
340
|
+
str(root / "mcp.json"),
|
|
341
|
+
str(root / "plugins"),
|
|
342
|
+
str(root / "plugins" / "cache"),
|
|
343
|
+
str(root / "plugins" / "local"),
|
|
344
|
+
str(root / "plugins" / "local-marketplaces.json"),
|
|
345
|
+
str(project / ".cursor"),
|
|
346
|
+
str(project / ".cursor" / "mcp.json"),
|
|
347
|
+
*watch_paths,
|
|
348
|
+
}
|
|
307
349
|
records = []
|
|
308
350
|
for name in sorted(paths):
|
|
309
351
|
try:
|
|
@@ -324,6 +366,7 @@ class PolicyRuntime:
|
|
|
324
366
|
config_path: Path,
|
|
325
367
|
*,
|
|
326
368
|
collect: Callable[[dict[str, object], Scope], Collected],
|
|
369
|
+
poll_interval: float = 60,
|
|
327
370
|
clock: Callable[[], float] = monotonic,
|
|
328
371
|
wall_clock: Callable[[], float] = time,
|
|
329
372
|
) -> None:
|
|
@@ -334,6 +377,8 @@ class PolicyRuntime:
|
|
|
334
377
|
self.collect = collect
|
|
335
378
|
self.clock = clock
|
|
336
379
|
self.wall_clock = wall_clock
|
|
380
|
+
self.poll_interval = poll_interval
|
|
381
|
+
self._attempt_interval = min(30, poll_interval)
|
|
337
382
|
self._fetch_at = float("-inf")
|
|
338
383
|
self._attempts: dict[Scope, float] = {}
|
|
339
384
|
self._digests: dict[Scope, str] = {}
|
|
@@ -344,7 +389,17 @@ class PolicyRuntime:
|
|
|
344
389
|
#: gateway treats a policy older than its time to live as no policy
|
|
345
390
|
#: (ADR-0151), and a fetch certifies only its own binding's policy.
|
|
346
391
|
self._refreshed: tuple[Binding, float] | None = None
|
|
347
|
-
self.worker = JobThread(
|
|
392
|
+
self.worker = JobThread(
|
|
393
|
+
Job(
|
|
394
|
+
"policy",
|
|
395
|
+
self._attempt_interval,
|
|
396
|
+
self.reconcile,
|
|
397
|
+
clock=clock,
|
|
398
|
+
minimum_gap=min(2, self._attempt_interval),
|
|
399
|
+
wakeable=True,
|
|
400
|
+
),
|
|
401
|
+
clock=clock,
|
|
402
|
+
)
|
|
348
403
|
|
|
349
404
|
@property
|
|
350
405
|
def refreshed_at(self) -> float | None:
|
|
@@ -389,7 +444,7 @@ class PolicyRuntime:
|
|
|
389
444
|
with _asset_transition_lock(self.config_path, timeout=0.1):
|
|
390
445
|
self._read_inputs(load_remote_config(self.config_path))
|
|
391
446
|
return
|
|
392
|
-
if self.clock() - self._fetch_at >=
|
|
447
|
+
if self.clock() - self._fetch_at >= self.poll_interval:
|
|
393
448
|
self._fetch_at = self.clock()
|
|
394
449
|
try:
|
|
395
450
|
self.fetcher.refresh()
|
|
@@ -437,7 +492,12 @@ class PolicyRuntime:
|
|
|
437
492
|
self.cache.invalidate(scope)
|
|
438
493
|
self._digests[scope] = digest
|
|
439
494
|
if config.token and self.cache.publish(
|
|
440
|
-
token,
|
|
495
|
+
token,
|
|
496
|
+
collected.entries,
|
|
497
|
+
started,
|
|
498
|
+
wall_started,
|
|
499
|
+
collected.evidence,
|
|
500
|
+
collected.builtin_skills,
|
|
441
501
|
):
|
|
442
502
|
self._paths[scope] = collected.watch_paths
|
|
443
503
|
self._digests[scope] = configuration_digest(scope, collected.watch_paths)
|
|
@@ -454,7 +514,7 @@ class PolicyRuntime:
|
|
|
454
514
|
self._error = "policy_evidence_unavailable"
|
|
455
515
|
|
|
456
516
|
def _due(self, scope: Scope) -> bool:
|
|
457
|
-
if self.clock() - self._attempts.get(scope, float("-inf")) <
|
|
517
|
+
if self.clock() - self._attempts.get(scope, float("-inf")) < self._attempt_interval:
|
|
458
518
|
return False
|
|
459
519
|
snapshot = self.cache.snapshots.get(scope)
|
|
460
520
|
return (
|
|
@@ -468,7 +528,7 @@ class PolicyRuntime:
|
|
|
468
528
|
try:
|
|
469
529
|
if set(value) != {"agent_kind", "config_root", "global_config", "project_root"}:
|
|
470
530
|
return False
|
|
471
|
-
if value["agent_kind"] not in
|
|
531
|
+
if value["agent_kind"] not in GLOBAL_CONFIG or not all(
|
|
472
532
|
isinstance(item, str) for item in value.values()
|
|
473
533
|
):
|
|
474
534
|
return False
|
|
@@ -508,7 +568,7 @@ class PolicyRuntime:
|
|
|
508
568
|
for key, value in action.items()
|
|
509
569
|
):
|
|
510
570
|
return Result("defer", "invalid_action")
|
|
511
|
-
if action["agent_kind"] not in
|
|
571
|
+
if action["agent_kind"] not in GLOBAL_CONFIG:
|
|
512
572
|
return Result("defer", "unsupported_agent")
|
|
513
573
|
kind, name, source = action["action_kind"], action["name"], action["source"]
|
|
514
574
|
if kind not in {"mcp_tool", "skill", "command", "plugin_agent"}:
|
|
@@ -63,6 +63,13 @@ _GUIDANCE = {
|
|
|
63
63
|
"read it. If the agent needs this access, grant it to the agent's own credential."
|
|
64
64
|
),
|
|
65
65
|
),
|
|
66
|
+
"stacktrace-pii-egress": (
|
|
67
|
+
"Personal data appeared in an outbound tool call",
|
|
68
|
+
(
|
|
69
|
+
"Find out whose data it was. Then follow your process for personal data "
|
|
70
|
+
"that another company received."
|
|
71
|
+
),
|
|
72
|
+
),
|
|
66
73
|
# Retired by ADR-0149. Findings stored before then still name them.
|
|
67
74
|
"stacktrace-mcp-transient-failure": (
|
|
68
75
|
"MCP auth failure followed by recovery on a server",
|
stacktrace/daemon/runtime.py
CHANGED
|
@@ -297,7 +297,12 @@ def run_daemon(
|
|
|
297
297
|
"config": settings.as_document(),
|
|
298
298
|
}
|
|
299
299
|
server.on_shutdown = stop.set
|
|
300
|
-
policy = PolicyRuntime(
|
|
300
|
+
policy = PolicyRuntime(
|
|
301
|
+
paths.state,
|
|
302
|
+
remote_config_path(),
|
|
303
|
+
collect=collect_bounded,
|
|
304
|
+
poll_interval=settings.policy_interval_seconds,
|
|
305
|
+
)
|
|
301
306
|
server.on_authorize = policy.authorize
|
|
302
307
|
server.on_policy_register = policy.register
|
|
303
308
|
server.on_policy_status = policy.status
|