twsrt 3.3.0__tar.gz → 3.3.2__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.0 → twsrt-3.3.2}/PKG-INFO +8 -3
  2. {twsrt-3.3.0 → twsrt-3.3.2}/README.md +7 -2
  3. {twsrt-3.3.0 → twsrt-3.3.2}/pyproject.toml +2 -2
  4. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/bin/cli.py +60 -41
  5. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/config.py +4 -5
  6. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/sources.py +16 -0
  7. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt.egg-info/PKG-INFO +8 -3
  8. {twsrt-3.3.0 → twsrt-3.3.2}/setup.cfg +0 -0
  9. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/__init__.py +0 -0
  10. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/bin/__init__.py +0 -0
  11. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/__init__.py +0 -0
  12. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/agent.py +0 -0
  13. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/claude.py +0 -0
  14. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/codex.py +0 -0
  15. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/composition.py +0 -0
  16. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/copilot.py +0 -0
  17. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/doctor.py +0 -0
  18. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/jsonc.py +0 -0
  19. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/models.py +0 -0
  20. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/probe.py +0 -0
  21. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/profiles.py +0 -0
  22. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt/lib/symlink.py +0 -0
  23. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt.egg-info/SOURCES.txt +0 -0
  24. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt.egg-info/dependency_links.txt +0 -0
  25. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt.egg-info/entry_points.txt +0 -0
  26. {twsrt-3.3.0 → twsrt-3.3.2}/src/twsrt.egg-info/requires.txt +0 -0
  27. {twsrt-3.3.0 → twsrt-3.3.2}/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.0
3
+ Version: 3.3.2
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
 
@@ -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
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twsrt"
3
- version = "3.3.0"
3
+ version = "3.3.2"
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.0"
48
+ current_version = "3.3.2"
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.0"
24
+ __version__ = "3.3.2"
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
 
@@ -22,24 +22,40 @@ 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",
28
35
  "allowLocalBinding",
36
+ "allowMachLookup",
29
37
  "httpProxyPort",
30
38
  "socksProxyPort",
31
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.
32
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.
33
46
  _SANDBOX_CONFIG_KEYS = (
34
47
  "enabled",
35
48
  "enableWeakerNetworkIsolation",
36
49
  "enableWeakerNestedSandbox",
37
50
  "ignoreViolations",
38
51
  )
52
+ # SRT path/domain lists that become SecurityRules (not pass-through config).
53
+ # Validated as string lists and sorted on compile.
39
54
  _SRT_LISTS = {
40
55
  "filesystem": ("allowWrite", "denyWrite", "denyRead"),
41
56
  "network": ("allowedDomains", "deniedDomains"),
42
57
  }
58
+ # The only top-level keys a Bash source document may carry.
43
59
  _BASH_ACTIONS = ("allow", "ask", "deny")
44
60
  # Lists whose order carries no meaning, sorted on compile for stable output.
45
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.0
3
+ Version: 3.3.2
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
 
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
File without changes
File without changes