twsrt 3.3.1__tar.gz → 3.3.3__tar.gz

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.
Files changed (27) hide show
  1. {twsrt-3.3.1 → twsrt-3.3.3}/PKG-INFO +10 -5
  2. {twsrt-3.3.1 → twsrt-3.3.3}/README.md +9 -4
  3. {twsrt-3.3.1 → twsrt-3.3.3}/pyproject.toml +2 -2
  4. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/bin/cli.py +60 -41
  5. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/config.py +4 -5
  6. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/doctor.py +30 -8
  7. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/probe.py +50 -4
  8. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/sources.py +15 -1
  9. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt.egg-info/PKG-INFO +10 -5
  10. {twsrt-3.3.1 → twsrt-3.3.3}/setup.cfg +0 -0
  11. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/__init__.py +0 -0
  12. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/bin/__init__.py +0 -0
  13. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/__init__.py +0 -0
  14. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/agent.py +0 -0
  15. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/claude.py +0 -0
  16. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/codex.py +0 -0
  17. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/composition.py +0 -0
  18. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/copilot.py +0 -0
  19. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/jsonc.py +0 -0
  20. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/models.py +0 -0
  21. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/profiles.py +0 -0
  22. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt/lib/symlink.py +0 -0
  23. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt.egg-info/SOURCES.txt +0 -0
  24. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt.egg-info/dependency_links.txt +0 -0
  25. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt.egg-info/entry_points.txt +0 -0
  26. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt.egg-info/requires.txt +0 -0
  27. {twsrt-3.3.1 → twsrt-3.3.3}/src/twsrt.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twsrt
3
- Version: 3.3.1
3
+ Version: 3.3.3
4
4
  Summary: Agent security configuration generator — translates canonical security rules into agent-specific configs
5
5
  Author-email: sysid <sysid@gmx.de>
6
6
  License-Expression: BSD-3-Clause
@@ -288,10 +288,15 @@ An agent is configured only when its `[targets]` key is set. `generate` and
288
288
 
289
289
  | Agent argument | Agent configured | Agent not configured |
290
290
  |---|---|---|
291
- | `all` (default) | previewed / written / diffed | skipped, with a note on stderr |
292
- | named, e.g. `codex` | previewed / written / diffed | error, exit 1, no output |
291
+ | `all` (default) | previewed / written / diffed | skipped, `Info:` note on stderr, exit 0 |
292
+ | named, e.g. `codex` | previewed / written / diffed | skipped, `Info:` note on stderr, exit 0 |
293
293
 
294
294
  If no agent is configured, `generate -w` writes only the canonical outputs.
295
+ The one exception is `generate --project`: it copies hooks from the global
296
+ Claude target, so a missing `claude_settings` is an error there.
297
+
298
+ Likewise `show bash` and `edit bash` without `[sources.bash]` print an
299
+ `Info:` note and exit 0; an unknown source kind is an error.
295
300
 
296
301
  ### Fragments
297
302
 
@@ -498,8 +503,8 @@ otherwise `default_profile` is compared and reports drift.
498
503
 
499
504
  **How `test` works.** Each effective SRT rule becomes a probe command
500
505
  (`head -c 1` on a denied file, an append-open that writes nothing on a
501
- write rule, `curl -I` per domain, plus a canary host outside the
502
- allowlist). Each probe runs twice: plainly as a control, then under
506
+ write rule, `curl -I` per domain, srt's proxy answer for a made-up
507
+ subdomain of each `*.` wildcard, plus a canary host outside the allowlist). Each probe runs twice: plainly as a control, then under
503
508
  `srt -s <settings> -c`. A deny rule passes when the control succeeds and the
504
509
  sandboxed run fails, so a missing file can never count as protected. The
505
510
  probe set is derived from the compiled file, never authored: change the
@@ -274,10 +274,15 @@ An agent is configured only when its `[targets]` key is set. `generate` and
274
274
 
275
275
  | Agent argument | Agent configured | Agent not configured |
276
276
  |---|---|---|
277
- | `all` (default) | previewed / written / diffed | skipped, with a note on stderr |
278
- | named, e.g. `codex` | previewed / written / diffed | error, exit 1, no output |
277
+ | `all` (default) | previewed / written / diffed | skipped, `Info:` note on stderr, exit 0 |
278
+ | named, e.g. `codex` | previewed / written / diffed | skipped, `Info:` note on stderr, exit 0 |
279
279
 
280
280
  If no agent is configured, `generate -w` writes only the canonical outputs.
281
+ The one exception is `generate --project`: it copies hooks from the global
282
+ Claude target, so a missing `claude_settings` is an error there.
283
+
284
+ Likewise `show bash` and `edit bash` without `[sources.bash]` print an
285
+ `Info:` note and exit 0; an unknown source kind is an error.
281
286
 
282
287
  ### Fragments
283
288
 
@@ -484,8 +489,8 @@ otherwise `default_profile` is compared and reports drift.
484
489
 
485
490
  **How `test` works.** Each effective SRT rule becomes a probe command
486
491
  (`head -c 1` on a denied file, an append-open that writes nothing on a
487
- write rule, `curl -I` per domain, plus a canary host outside the
488
- allowlist). Each probe runs twice: plainly as a control, then under
492
+ write rule, `curl -I` per domain, srt's proxy answer for a made-up
493
+ subdomain of each `*.` wildcard, plus a canary host outside the allowlist). Each probe runs twice: plainly as a control, then under
489
494
  `srt -s <settings> -c`. A deny rule passes when the control succeeds and the
490
495
  sandboxed run fails, so a missing file can never count as protected. The
491
496
  probe set is derived from the compiled file, never authored: change the
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twsrt"
3
- version = "3.3.1"
3
+ version = "3.3.3"
4
4
  description = "Agent security configuration generator — translates canonical security rules into agent-specific configs"
5
5
  readme = "README.md"
6
6
  license = "BSD-3-Clause"
@@ -45,7 +45,7 @@ dev = [
45
45
  ]
46
46
 
47
47
  [tool.bumpversion]
48
- current_version = "3.3.1"
48
+ current_version = "3.3.3"
49
49
  commit = true
50
50
  tag = false
51
51
  tag_name = "v{new_version}"
@@ -21,7 +21,7 @@ from twsrt.lib.models import (
21
21
  yolo_path,
22
22
  )
23
23
 
24
- __version__ = "3.3.1"
24
+ __version__ = "3.3.3"
25
25
 
26
26
  app = typer.Typer(
27
27
  name="twsrt",
@@ -45,11 +45,6 @@ def _warning(message: str) -> None:
45
45
  typer.secho(f"Warning: {message}", fg=typer.colors.YELLOW, err=True)
46
46
 
47
47
 
48
- def _alert(message: str) -> None:
49
- """Red stderr note for a successful run whose outcome is easy to misread."""
50
- typer.secho(message, fg=typer.colors.RED, bold=True, err=True)
51
-
52
-
53
48
  def _info(message: str) -> None:
54
49
  typer.secho(message, fg=typer.colors.CYAN)
55
50
 
@@ -58,8 +53,17 @@ def _success(message: str) -> None:
58
53
  typer.secho(message, fg=typer.colors.GREEN)
59
54
 
60
55
 
61
- def _note(message: str) -> None:
62
- """Narrate a side effect on stderr; stdout carries only a command's result."""
56
+ def _note(message: str, bold: bool = False) -> None:
57
+ """Info on stderr: nothing failed, but the user should know.
58
+
59
+ Labelled like _error and _warning, so a skipped optional item never reads
60
+ as a failure. stdout carries only a command's result.
61
+ """
62
+ typer.secho(f"Info: {message}", fg=typer.colors.CYAN, bold=bold, err=True)
63
+
64
+
65
+ def _would_write(message: str) -> None:
66
+ """Narrate a file the preview would write, on stderr."""
63
67
  typer.secho(message, fg=typer.colors.CYAN, err=True)
64
68
 
65
69
 
@@ -413,7 +417,7 @@ def edit(
413
417
  Fragments are never compiled before opening, so one with a syntax error
414
418
  still opens -- that is exactly when you need an editor.
415
419
  """
416
- from twsrt.lib.config import load_config, source_kind_error
420
+ from twsrt.lib.config import SOURCE_KINDS, load_config, source_kind_error
417
421
  from twsrt.lib.profiles import resolve_profile
418
422
 
419
423
  config_path: Path = ctx.obj["config_path"]
@@ -431,6 +435,9 @@ def edit(
431
435
  _error(str(exc))
432
436
  raise typer.Exit(1)
433
437
 
438
+ if kind in SOURCE_KINDS and kind not in config.sources:
439
+ _note(f"nothing to edit: {_unconfigured_kind(kind)}")
440
+ return
434
441
  if kind != "all" and kind not in config.sources:
435
442
  _error(source_kind_error(kind, config.sources))
436
443
  raise typer.Exit(1)
@@ -455,7 +462,7 @@ def edit(
455
462
  continue
456
463
  if absent:
457
464
  # Registered but absent: opening it is how a new fragment is created.
458
- _warning(f"Fragment does not exist yet: {path}")
465
+ _note(f"fragment does not exist yet, the editor creates it: {path}")
459
466
 
460
467
  editor = _resolve_editor()
461
468
  argv = _editor_argv(editor, paths)
@@ -713,8 +720,8 @@ def generate(
713
720
  srt settings, overwriting hand edits there.
714
721
 
715
722
  Agent configs are translated from the canonical config; the agent argument
716
- only picks which translations run. `all` skips agents without a \\[targets]
717
- key; naming one explicitly fails. The preview does not print the canonical
723
+ only picks which translations run. An agent without a \\[targets] key is
724
+ skipped with an Info note, whether named or covered by `all`. The preview does not print the canonical
718
725
  outputs: use `twsrt show`.
719
726
 
720
727
  Claude modes via a symlink: Claude Code reads only settings.json next to
@@ -734,6 +741,9 @@ def generate(
734
741
  if twsrt_dir is not None:
735
742
  agent = _project_agent(agent)
736
743
  config, compiled = _compile(ctx.obj["config_path"], profile, yolo, twsrt_dir)
744
+ if twsrt_dir is not None:
745
+ # Not optional here: --project copies hooks from the global target.
746
+ config.require_target("claude")
737
747
  generators = _select_generators(agent, config)
738
748
  log.debug(
739
749
  "Generating agents=%s write=%s",
@@ -786,11 +796,13 @@ def generate(
786
796
  typer.echo(output)
787
797
 
788
798
  for document in compiled.documents.values():
789
- _note(f"Would write canonical: {document.output_path}")
799
+ _would_write(f"Would write canonical: {document.output_path}")
790
800
  for path in staged:
791
- _note(f"Would write agent target: {path}")
792
- _alert(
793
- "Nothing written: preview only. Re-run with -w/--write to write the files above."
801
+ _would_write(f"Would write agent target: {path}")
802
+ _note(
803
+ "nothing written (preview only). "
804
+ "Re-run with -w/--write to write the files above.",
805
+ bold=True,
794
806
  )
795
807
 
796
808
 
@@ -809,7 +821,7 @@ def show(
809
821
  write for the profile. Agent and --yolo do not change canonical
810
822
  documents, so neither is accepted here.
811
823
  """
812
- from twsrt.lib.config import source_kind_error
824
+ from twsrt.lib.config import SOURCE_KINDS, source_kind_error
813
825
 
814
826
  try:
815
827
  _, compiled = _compile(ctx.obj["config_path"], profile, yolo=False)
@@ -818,6 +830,9 @@ def show(
818
830
  _error(str(exc))
819
831
  raise typer.Exit(1)
820
832
 
833
+ if kind in SOURCE_KINDS and kind not in compiled.documents:
834
+ _note(f"nothing to show: {_unconfigured_kind(kind)}")
835
+ return
821
836
  if kind not in compiled.documents:
822
837
  _error(source_kind_error(kind, compiled.documents))
823
838
  raise typer.Exit(1)
@@ -1275,36 +1290,40 @@ def _compile(
1275
1290
 
1276
1291
 
1277
1292
  def _select_generators(agent: str, config: AppConfig) -> list:
1278
- """ "all" means every configured agent; a named agent must be configured.
1293
+ """The configured agents among those requested ("all" or one name).
1279
1294
 
1280
- An agent is configured by its [targets] key alone, so preview, write and
1281
- diff all see the same set: an unset key never falls back to a real path.
1295
+ Agents are optional: an unconfigured one is skipped with an Info note,
1296
+ whether named or covered by "all". An agent is configured by its [targets]
1297
+ key alone, so preview, write and diff all see the same set: an unset key
1298
+ never falls back to a real path.
1282
1299
  """
1283
1300
  from twsrt.lib.agent import GENERATORS
1284
1301
 
1285
- if agent == "all":
1286
- generators = [
1287
- generator
1288
- for name, generator in GENERATORS.items()
1289
- if config.agent_target(name) is not None
1290
- ]
1291
- if not generators:
1302
+ if agent != "all" and agent not in GENERATORS:
1303
+ raise ValueError(f"Unknown agent {agent!r}. Available: {', '.join(GENERATORS)}")
1304
+ requested = list(GENERATORS) if agent == "all" else [agent]
1305
+ configured = [name for name in requested if config.agent_target(name) is not None]
1306
+ if agent == "all" and not configured:
1307
+ _note(
1308
+ "no agent targets set in [targets] of config.toml, so only the "
1309
+ "canonical outputs are handled. To add an agent, set "
1310
+ "claude_settings, copilot_output or codex_config."
1311
+ )
1312
+ return []
1313
+ for name in requested:
1314
+ if name not in configured:
1292
1315
  _note(
1293
- "No agents configured: set claude_settings, copilot_output or "
1294
- "codex_config in [targets] of config.toml"
1316
+ f"{name} skipped: [targets].{AGENT_TARGET_KEYS[name]} "
1317
+ "is not set in config.toml"
1295
1318
  )
1296
- return []
1297
- for name in GENERATORS:
1298
- if config.agent_target(name) is None:
1299
- _note(
1300
- f"{name}: not configured "
1301
- f"(set [targets].{AGENT_TARGET_KEYS[name]} to enable)"
1302
- )
1303
- return generators
1304
- if agent not in GENERATORS:
1305
- raise ValueError(f"Unknown agent {agent!r}. Available: {', '.join(GENERATORS)}")
1306
- config.require_target(agent)
1307
- return [GENERATORS[agent]]
1319
+ return [GENERATORS[name] for name in configured]
1320
+
1321
+
1322
+ def _unconfigured_kind(kind: str) -> str:
1323
+ return (
1324
+ f"source kind {kind!r} is not configured "
1325
+ f"(add [sources.{kind}] to config.toml to enable it)"
1326
+ )
1308
1327
 
1309
1328
 
1310
1329
  def _stage_agent_files(
@@ -26,11 +26,10 @@ DEFAULT_OUTPUT_NAMES = {"srt": "srt-settings.json", "bash": "bash-rules.json"}
26
26
 
27
27
 
28
28
  def source_kind_error(kind: str, configured: Iterable[str]) -> str:
29
- """Why *kind* cannot be used: registered but not configured, or unknown."""
30
- if kind in SOURCE_KINDS:
31
- return (
32
- f"Source kind {kind!r} not configured: add [sources.{kind}] to config.toml"
33
- )
29
+ """Why *kind* cannot be used: it is not a source kind at all.
30
+
31
+ A known but unconfigured kind is not an error: the CLI reports it as Info.
32
+ """
34
33
  available = ", ".join(sorted(configured))
35
34
  return f"Unknown source kind {kind!r}; available: {available}"
36
35
 
@@ -353,8 +353,10 @@ def _check_profile_lists(
353
353
  tuple(items),
354
354
  )
355
355
  )
356
- if key == "allowedDomains":
357
- _check_wildcard_apex(list_name, values, ignores, base_dir, findings)
356
+ if key in _DOMAIN_LISTS:
357
+ _check_wildcard_apex(
358
+ key, list_name, values, ignores, base_dir, findings
359
+ )
358
360
 
359
361
 
360
362
  def _profile_lists(
@@ -418,8 +420,10 @@ def _domain_covers(parent: str, child: str) -> bool:
418
420
  if ":" in parent or ":" in child:
419
421
  return False # ponytail: port-qualified entries are not compared
420
422
  if not child.startswith("*"):
421
- # `twsrt test` cannot dial a wildcard: a concrete host below one is
422
- # that rule's only live probe, so it is never dead weight.
423
+ # A concrete host below a wildcard is never dead weight: `twsrt test`
424
+ # probes the wildcard only via srt's filter decision for a made-up
425
+ # subdomain; the concrete host is its only end-to-end probe (a real
426
+ # connection, judged against a control run).
423
427
  return False
424
428
  if parent == "*":
425
429
  return True
@@ -427,7 +431,25 @@ def _domain_covers(parent: str, child: str) -> bool:
427
431
  return parent.startswith("*.") and child.endswith(parent[1:])
428
432
 
429
433
 
434
+ # list key -> (severity, code, description after "<n> wildcards ").
435
+ _WILDCARD_APEX = {
436
+ "allowedDomains": (
437
+ "info",
438
+ "wildcard-apex",
439
+ "not matching the bare apex domain (add it where needed)",
440
+ ),
441
+ # A deny leaves the apex open: Claude's WebFetch deny skips it, and srt
442
+ # blocks it only while no allowedDomains entry (e.g. "*") admits it.
443
+ "deniedDomains": (
444
+ "warning",
445
+ "wildcard-deny-apex",
446
+ "leaving the bare apex domain not denied; list it too",
447
+ ),
448
+ }
449
+
450
+
430
451
  def _check_wildcard_apex(
452
+ key: str,
431
453
  list_name: str,
432
454
  values: dict[str, list[Path]],
433
455
  ignores: Ignores,
@@ -435,6 +457,7 @@ def _check_wildcard_apex(
435
457
  findings: list[Finding],
436
458
  ) -> None:
437
459
  """Grouped by the wildcard's fragment, so profiles sharing it dedup."""
460
+ severity, code, description = _WILDCARD_APEX[key]
438
461
  missing: dict[Path, list[str]] = {}
439
462
  for value, origins in values.items():
440
463
  if _ignored(ignores, origins, value):
@@ -444,11 +467,10 @@ def _check_wildcard_apex(
444
467
  for origin, items in missing.items():
445
468
  findings.append(
446
469
  Finding(
447
- "info",
448
- "wildcard-apex",
470
+ severity,
471
+ code,
449
472
  _show(origin, base_dir),
450
- f"{list_name}: {_count(items, 'wildcard', 'wildcards')} not "
451
- "matching the bare apex domain (add it where needed)",
473
+ f"{list_name}: {_count(items, 'wildcard', 'wildcards')} {description}",
452
474
  tuple(items),
453
475
  )
454
476
  )
@@ -30,6 +30,10 @@ Runner = Callable[..., subprocess.CompletedProcess]
30
30
  ScratchFactory = Callable[[Path], Path]
31
31
 
32
32
  _CURL = "curl -sS -m 10 -o /dev/null -I https://{host}/"
33
+ # Prints srt's answer to the CONNECT: the filter decides on the hostname before
34
+ # any DNS lookup, so the answer is a verdict even for a host that does not exist.
35
+ _CONNECT = "curl -sS -m 10 -o /dev/null -w '%{{http_connect}}' https://{host}/"
36
+ _WILDCARD_LABEL = "twsrt-probe"
33
37
  _CANARY_DOMAINS = ("example.com", "example.org", "example.net")
34
38
  _WALK_DEPTH = 4
35
39
  _STDERR_LIMIT = 400
@@ -72,6 +76,8 @@ class Probe:
72
76
  # The .srt-settings.json key this probe verifies; derived from kind unless
73
77
  # given (the allowlist canary is a net-deny probe of allowedDomains).
74
78
  section: str = ""
79
+ # Judged by the srt proxy's CONNECT status on stdout, not by exit codes.
80
+ proxy_verdict: bool = False
75
81
 
76
82
  def __post_init__(self) -> None:
77
83
  if not self.section:
@@ -94,7 +100,8 @@ class ProbeResult:
94
100
  status: Status
95
101
  control_exit: int | None = None
96
102
  sandbox_exit: int | None = None
97
- # stderr only, last 400 chars; stdout of either run is never captured.
103
+ # stderr only, last 400 chars; stdout is never kept (a proxy-verdict probe
104
+ # reads its CONNECT status from stdout, which ends up in reason).
98
105
  control_stderr: str = ""
99
106
  sandbox_stderr: str = ""
100
107
  duration_ms: int = 0
@@ -394,6 +401,20 @@ def _concrete_write_probe(
394
401
 
395
402
 
396
403
  def _network(host: str, kind: str, expect: Expect) -> Probe:
404
+ if host.startswith("*.") and not _is_glob(host[2:]):
405
+ # *.x matches any subdomain of x (never x itself); a made-up label
406
+ # stands in for all of them. No control run: outside the sandbox the
407
+ # host does not resolve, and the proxy's answer is the witness.
408
+ concrete = f"{_WILDCARD_LABEL}.{host[2:]}"
409
+ log.debug("%s %s: probing synthetic subdomain %s", kind, host, concrete)
410
+ return Probe(
411
+ kind,
412
+ host,
413
+ _CONNECT.format(host=concrete),
414
+ expect,
415
+ control=False,
416
+ proxy_verdict=True,
417
+ )
397
418
  if _is_glob(host):
398
419
  return _skip(kind, host, expect, "wildcard domain: no concrete host")
399
420
  return Probe(kind, host, _CURL.format(host=host), expect)
@@ -473,10 +494,32 @@ def judge(
473
494
  return Status.PASS, ""
474
495
 
475
496
 
497
+ def judge_proxy(expect: Expect, code: str) -> tuple[Status, str]:
498
+ """Verdict from srt's answer to the CONNECT, as printed by curl.
499
+
500
+ 403 is srt's policy denial; any other answer means the filter let the
501
+ request through (502: the upstream did not resolve). Without an answer
502
+ (000, empty) curl never reached the proxy and nothing was judged.
503
+ """
504
+ code = code.strip()
505
+ if code in ("", "000"):
506
+ return Status.ERROR, "no proxy answer: curl did not reach the srt proxy"
507
+ blocked = code == "403"
508
+ if expect is Expect.DENY and not blocked:
509
+ return Status.FAIL, f"not blocked: proxy answered {code}"
510
+ if expect is Expect.ALLOW and blocked:
511
+ return Status.FAIL, "blocked but should be allowed: proxy answered 403"
512
+ return Status.PASS, f"proxy answered {code}"
513
+
514
+
476
515
  def run_probe(
477
516
  probe: Probe, settings: Path, timeout: float, run: Runner | None = None
478
517
  ) -> ProbeResult:
479
- """Execute control and sandboxed run; stdout is discarded, never captured."""
518
+ """Execute control and sandboxed run.
519
+
520
+ stdout is discarded, except the sandboxed run of a proxy-verdict probe:
521
+ there it carries only curl's three-digit CONNECT status.
522
+ """
480
523
  run = run or subprocess.run
481
524
  if probe.skip_reason is not None:
482
525
  return ProbeResult(probe, Status.SKIP, reason=probe.skip_reason)
@@ -502,6 +545,7 @@ def run_probe(
502
545
  ["srt", "-s", str(settings), "-c", probe.command],
503
546
  timeout,
504
547
  capture=True,
548
+ stdout=probe.proxy_verdict,
505
549
  )
506
550
  _remove(artifact)
507
551
  except subprocess.TimeoutExpired:
@@ -518,6 +562,8 @@ def run_probe(
518
562
  stderr = (completed.stderr or "")[-_STDERR_LIMIT:]
519
563
  if "sandbox_apply" in stderr:
520
564
  status, reason = Status.ERROR, "srt could not apply the sandbox"
565
+ elif probe.proxy_verdict:
566
+ status, reason = judge_proxy(probe.expect, completed.stdout or "")
521
567
  else:
522
568
  status, reason = judge(
523
569
  probe.expect,
@@ -597,7 +643,7 @@ def _srt_version(run: Runner, which: Callable[[str], str | None]) -> str:
597
643
 
598
644
 
599
645
  def _execute(
600
- run: Runner, argv: list[str], timeout: float, capture: bool
646
+ run: Runner, argv: list[str], timeout: float, capture: bool, stdout: bool = False
601
647
  ) -> subprocess.CompletedProcess:
602
648
  log.debug("exec: %s", shlex.join(argv))
603
649
  started = time.monotonic()
@@ -605,7 +651,7 @@ def _execute(
605
651
  completed = run(
606
652
  argv,
607
653
  stdin=subprocess.DEVNULL,
608
- stdout=subprocess.DEVNULL,
654
+ stdout=subprocess.PIPE if stdout else subprocess.DEVNULL,
609
655
  stderr=subprocess.PIPE if capture else subprocess.DEVNULL,
610
656
  text=True,
611
657
  timeout=timeout,
@@ -22,6 +22,13 @@ from twsrt.lib.models import (
22
22
  SrtResult,
23
23
  )
24
24
 
25
+ # Allowlists of SRT keys that read_srt copies verbatim into SrtResult's
26
+ # *_config dicts. Each key has a same-named counterpart in Claude Code's
27
+ # sandbox section; ClaudeGenerator merges the dicts in, and ClaudeGenerator.diff
28
+ # compares exactly these keys. Any other SRT key is dropped here, so a key
29
+ # Claude Code does not honour (e.g. allowPty) stays out: forwarding it would
30
+ # only add a dead setting. The doctor's schema check is separate (doctor.py).
31
+ # Pass-through keys under sandbox.network.
25
32
  _NETWORK_CONFIG_KEYS = (
26
33
  "allowUnixSockets",
27
34
  "allowAllUnixSockets",
@@ -30,18 +37,25 @@ _NETWORK_CONFIG_KEYS = (
30
37
  "httpProxyPort",
31
38
  "socksProxyPort",
32
39
  )
40
+ # Keys under sandbox.filesystem. Read so the diff can see them, but the
41
+ # generator empties all three (ADR 0002): their paths go out as Read/Edit
42
+ # permission rules instead.
33
43
  _FILESYSTEM_CONFIG_KEYS = ("allowWrite", "denyWrite", "denyRead")
44
+ # Pass-through keys at the top level of sandbox. "enabled" is twsrt's own key
45
+ # (not in srt's schema) for Claude's sandbox.enabled.
34
46
  _SANDBOX_CONFIG_KEYS = (
35
47
  "enabled",
36
- "allowPty",
37
48
  "enableWeakerNetworkIsolation",
38
49
  "enableWeakerNestedSandbox",
39
50
  "ignoreViolations",
40
51
  )
52
+ # SRT path/domain lists that become SecurityRules (not pass-through config).
53
+ # Validated as string lists and sorted on compile.
41
54
  _SRT_LISTS = {
42
55
  "filesystem": ("allowWrite", "denyWrite", "denyRead"),
43
56
  "network": ("allowedDomains", "deniedDomains"),
44
57
  }
58
+ # The only top-level keys a Bash source document may carry.
45
59
  _BASH_ACTIONS = ("allow", "ask", "deny")
46
60
  # Lists whose order carries no meaning, sorted on compile for stable output.
47
61
  # Anything else -- notably unknown pass-through keys -- keeps fragment order.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twsrt
3
- Version: 3.3.1
3
+ Version: 3.3.3
4
4
  Summary: Agent security configuration generator — translates canonical security rules into agent-specific configs
5
5
  Author-email: sysid <sysid@gmx.de>
6
6
  License-Expression: BSD-3-Clause
@@ -288,10 +288,15 @@ An agent is configured only when its `[targets]` key is set. `generate` and
288
288
 
289
289
  | Agent argument | Agent configured | Agent not configured |
290
290
  |---|---|---|
291
- | `all` (default) | previewed / written / diffed | skipped, with a note on stderr |
292
- | named, e.g. `codex` | previewed / written / diffed | error, exit 1, no output |
291
+ | `all` (default) | previewed / written / diffed | skipped, `Info:` note on stderr, exit 0 |
292
+ | named, e.g. `codex` | previewed / written / diffed | skipped, `Info:` note on stderr, exit 0 |
293
293
 
294
294
  If no agent is configured, `generate -w` writes only the canonical outputs.
295
+ The one exception is `generate --project`: it copies hooks from the global
296
+ Claude target, so a missing `claude_settings` is an error there.
297
+
298
+ Likewise `show bash` and `edit bash` without `[sources.bash]` print an
299
+ `Info:` note and exit 0; an unknown source kind is an error.
295
300
 
296
301
  ### Fragments
297
302
 
@@ -498,8 +503,8 @@ otherwise `default_profile` is compared and reports drift.
498
503
 
499
504
  **How `test` works.** Each effective SRT rule becomes a probe command
500
505
  (`head -c 1` on a denied file, an append-open that writes nothing on a
501
- write rule, `curl -I` per domain, plus a canary host outside the
502
- allowlist). Each probe runs twice: plainly as a control, then under
506
+ write rule, `curl -I` per domain, srt's proxy answer for a made-up
507
+ subdomain of each `*.` wildcard, plus a canary host outside the allowlist). Each probe runs twice: plainly as a control, then under
503
508
  `srt -s <settings> -c`. A deny rule passes when the control succeeds and the
504
509
  sandboxed run fails, so a missing file can never count as protected. The
505
510
  probe set is derived from the compiled file, never authored: change the
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes