twsrt 3.2.0__tar.gz → 3.3.0__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.2.0 → twsrt-3.3.0}/PKG-INFO +10 -8
  2. {twsrt-3.2.0 → twsrt-3.3.0}/README.md +9 -7
  3. {twsrt-3.2.0 → twsrt-3.3.0}/pyproject.toml +2 -2
  4. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/bin/cli.py +25 -20
  5. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/config.py +24 -2
  6. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/sources.py +3 -1
  7. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt.egg-info/PKG-INFO +10 -8
  8. {twsrt-3.2.0 → twsrt-3.3.0}/setup.cfg +0 -0
  9. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/__init__.py +0 -0
  10. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/bin/__init__.py +0 -0
  11. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/__init__.py +0 -0
  12. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/agent.py +0 -0
  13. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/claude.py +0 -0
  14. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/codex.py +0 -0
  15. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/composition.py +0 -0
  16. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/copilot.py +0 -0
  17. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/doctor.py +0 -0
  18. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/jsonc.py +0 -0
  19. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/models.py +0 -0
  20. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/probe.py +0 -0
  21. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/profiles.py +0 -0
  22. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt/lib/symlink.py +0 -0
  23. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt.egg-info/SOURCES.txt +0 -0
  24. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt.egg-info/dependency_links.txt +0 -0
  25. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt.egg-info/entry_points.txt +0 -0
  26. {twsrt-3.2.0 → twsrt-3.3.0}/src/twsrt.egg-info/requires.txt +0 -0
  27. {twsrt-3.2.0 → twsrt-3.3.0}/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.2.0
3
+ Version: 3.3.0
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
@@ -213,7 +213,7 @@ from a plain terminal
213
213
 
214
214
  | Term | Meaning |
215
215
  |---|---|
216
- | Source kind | A canonical document type: `srt` (filesystem and network policy) and `bash` (command allow/ask/deny lists) |
216
+ | Source kind | A canonical document type: `srt` (filesystem and network policy, required) and `bash` (command allow/ask/deny lists, optional) |
217
217
  | Fragment | One named `.jsonc` file holding a slice of policy for one source kind. Fragments never include each other |
218
218
  | Profile | An ordered selection of fragments per source kind; may `extend` other profiles. `default_profile` applies when `-p` is omitted |
219
219
  | Target | An agent config file translated from the canonical output |
@@ -233,7 +233,7 @@ path = "srt/base.jsonc"
233
233
  [sources.srt.fragments.work]
234
234
  path = "srt/work.jsonc"
235
235
 
236
- [sources.bash] # output omitted: bash-rules.json next to config.toml
236
+ [sources.bash] # optional; output omitted: bash-rules.json next to config.toml
237
237
  [sources.bash.fragments.base]
238
238
  path = "bash/base.jsonc"
239
239
 
@@ -269,10 +269,12 @@ allowUnsandboxedCommands = false
269
269
  enabled = false
270
270
  ```
271
271
 
272
- Only `schema_version`, `default_profile`, both `[sources.*]` kinds and one
273
- profile are required. `config --init` writes exactly that, plus
274
- `[sandbox_overrides.yolo]`, and leaves every other key commented out with
275
- its default value.
272
+ Only `schema_version`, `default_profile`, `[sources.srt]` and one profile are
273
+ required. Without `[sources.bash]` no command rules exist: nothing is compiled
274
+ to `bash-rules.json` and no agent gets Bash allow/ask/deny entries; a profile
275
+ must then not name `bash`. `config --init` writes exactly the required keys,
276
+ plus `[sandbox_overrides.yolo]`, and leaves every other key, `[sources.bash]`
277
+ included, commented out with its default value.
276
278
 
277
279
  `output` is optional per source kind and defaults to `srt-settings.json` /
278
280
  `bash-rules.json` next to `config.toml`. srt itself reads only
@@ -342,7 +344,7 @@ repository and loaded per launch instead of the global files:
342
344
  ```
343
345
  twsrt generate claude -w -p slim --project
344
346
  → ./.twsrt/srt-settings.json canonical srt (instead of ~/.srt-settings.json)
345
- → ./.twsrt/bash-rules.json canonical bash
347
+ → ./.twsrt/bash-rules.json canonical bash (only with [sources.bash])
346
348
  → ./.twsrt/claude-settings[.yolo].json Claude target (instead of ~/.claude/settings.full.json)
347
349
  → ./.twsrt/.gitignore "*"
348
350
  stdout: the absolute .twsrt directory
@@ -199,7 +199,7 @@ from a plain terminal
199
199
 
200
200
  | Term | Meaning |
201
201
  |---|---|
202
- | Source kind | A canonical document type: `srt` (filesystem and network policy) and `bash` (command allow/ask/deny lists) |
202
+ | Source kind | A canonical document type: `srt` (filesystem and network policy, required) and `bash` (command allow/ask/deny lists, optional) |
203
203
  | Fragment | One named `.jsonc` file holding a slice of policy for one source kind. Fragments never include each other |
204
204
  | Profile | An ordered selection of fragments per source kind; may `extend` other profiles. `default_profile` applies when `-p` is omitted |
205
205
  | Target | An agent config file translated from the canonical output |
@@ -219,7 +219,7 @@ path = "srt/base.jsonc"
219
219
  [sources.srt.fragments.work]
220
220
  path = "srt/work.jsonc"
221
221
 
222
- [sources.bash] # output omitted: bash-rules.json next to config.toml
222
+ [sources.bash] # optional; output omitted: bash-rules.json next to config.toml
223
223
  [sources.bash.fragments.base]
224
224
  path = "bash/base.jsonc"
225
225
 
@@ -255,10 +255,12 @@ allowUnsandboxedCommands = false
255
255
  enabled = false
256
256
  ```
257
257
 
258
- Only `schema_version`, `default_profile`, both `[sources.*]` kinds and one
259
- profile are required. `config --init` writes exactly that, plus
260
- `[sandbox_overrides.yolo]`, and leaves every other key commented out with
261
- its default value.
258
+ Only `schema_version`, `default_profile`, `[sources.srt]` and one profile are
259
+ required. Without `[sources.bash]` no command rules exist: nothing is compiled
260
+ to `bash-rules.json` and no agent gets Bash allow/ask/deny entries; a profile
261
+ must then not name `bash`. `config --init` writes exactly the required keys,
262
+ plus `[sandbox_overrides.yolo]`, and leaves every other key, `[sources.bash]`
263
+ included, commented out with its default value.
262
264
 
263
265
  `output` is optional per source kind and defaults to `srt-settings.json` /
264
266
  `bash-rules.json` next to `config.toml`. srt itself reads only
@@ -328,7 +330,7 @@ repository and loaded per launch instead of the global files:
328
330
  ```
329
331
  twsrt generate claude -w -p slim --project
330
332
  → ./.twsrt/srt-settings.json canonical srt (instead of ~/.srt-settings.json)
331
- → ./.twsrt/bash-rules.json canonical bash
333
+ → ./.twsrt/bash-rules.json canonical bash (only with [sources.bash])
332
334
  → ./.twsrt/claude-settings[.yolo].json Claude target (instead of ~/.claude/settings.full.json)
333
335
  → ./.twsrt/.gitignore "*"
334
336
  stdout: the absolute .twsrt directory
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twsrt"
3
- version = "3.2.0"
3
+ version = "3.3.0"
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.2.0"
48
+ current_version = "3.3.0"
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.2.0"
24
+ __version__ = "3.3.0"
25
25
 
26
26
  app = typer.Typer(
27
27
  name="twsrt",
@@ -158,9 +158,9 @@ default_profile = "default"
158
158
  # -----------------------------------------------------------------------------
159
159
  # Canonical source kinds
160
160
  # -----------------------------------------------------------------------------
161
- # Both registered kinds, srt and bash, are required. Each kind has one generated
162
- # strict-JSON output and one or more named JSONC fragments. Output paths must be
163
- # distinct and must not be the same path as any input fragment.
161
+ # srt is required; bash is optional. Each kind has one generated strict-JSON
162
+ # output and one or more named JSONC fragments. Output paths must be distinct
163
+ # and must not be the same path as any input fragment.
164
164
  # `output` is optional and defaults to a file next to this config.toml.
165
165
 
166
166
  [sources.srt]
@@ -178,13 +178,17 @@ path = "srt/base.jsonc"
178
178
  # [sources.srt.fragments.work]
179
179
  # path = "srt/work.jsonc"
180
180
 
181
- [sources.bash]
182
- # Compiled command-policy JSON consumed by the agent generators.
183
- # Default: bash-rules.json next to this file.
184
- # output = "bash-rules.json"
185
-
186
- [sources.bash.fragments.base]
187
- path = "bash/base.jsonc"
181
+ # Optional agent command policy (allow/ask/deny Bash rules). Without it, no
182
+ # command rules are generated. To enable, uncomment this table, its base
183
+ # fragment and `bash = ["base"]` in [profiles.default]; the values shown are
184
+ # the defaults.
185
+ # [sources.bash]
186
+ # # Compiled command-policy JSON consumed by the agent generators.
187
+ # # Default: bash-rules.json next to this file.
188
+ # # output = "bash-rules.json"
189
+ #
190
+ # [sources.bash.fragments.base]
191
+ # path = "bash/base.jsonc"
188
192
 
189
193
  # Additional Bash fragment example:
190
194
  # [sources.bash.fragments.work]
@@ -194,13 +198,14 @@ path = "bash/base.jsonc"
194
198
  # -----------------------------------------------------------------------------
195
199
  # Profiles
196
200
  # -----------------------------------------------------------------------------
197
- # A resolved profile must select at least one fragment for every source kind.
201
+ # A resolved profile must select at least one fragment for every configured
202
+ # source kind, and may name only configured kinds.
198
203
  # Parents resolve before children; repeated fragment names are deduplicated.
199
204
  # Inheritance adds compatible fragments—it does not override conflicting values.
200
205
 
201
206
  [profiles.default]
202
207
  srt = ["base"]
203
- bash = ["base"]
208
+ # bash = ["base"]
204
209
 
205
210
  # Profile inheritance and additional selection example:
206
211
  # [profiles.work]
@@ -408,7 +413,7 @@ def edit(
408
413
  Fragments are never compiled before opening, so one with a syntax error
409
414
  still opens -- that is exactly when you need an editor.
410
415
  """
411
- from twsrt.lib.config import load_config
416
+ from twsrt.lib.config import load_config, source_kind_error
412
417
  from twsrt.lib.profiles import resolve_profile
413
418
 
414
419
  config_path: Path = ctx.obj["config_path"]
@@ -427,8 +432,7 @@ def edit(
427
432
  raise typer.Exit(1)
428
433
 
429
434
  if kind != "all" and kind not in config.sources:
430
- available = ", ".join(sorted(config.sources))
431
- _error(f"Unknown source kind {kind!r}; available: {available}")
435
+ _error(source_kind_error(kind, config.sources))
432
436
  raise typer.Exit(1)
433
437
 
434
438
  # config.sources order, so srt precedes bash exactly as config.toml reads.
@@ -805,6 +809,8 @@ def show(
805
809
  write for the profile. Agent and --yolo do not change canonical
806
810
  documents, so neither is accepted here.
807
811
  """
812
+ from twsrt.lib.config import source_kind_error
813
+
808
814
  try:
809
815
  _, compiled = _compile(ctx.obj["config_path"], profile, yolo=False)
810
816
  except (OSError, ValueError) as exc:
@@ -813,8 +819,7 @@ def show(
813
819
  raise typer.Exit(1)
814
820
 
815
821
  if kind not in compiled.documents:
816
- available = ", ".join(sorted(compiled.documents))
817
- _error(f"Unknown source kind {kind!r}; available: {available}")
822
+ _error(source_kind_error(kind, compiled.documents))
818
823
  raise typer.Exit(1)
819
824
 
820
825
  typer.echo(_serialize(compiled.documents[kind].document), nl=False)
@@ -1242,9 +1247,9 @@ def _compile(
1242
1247
  config = load_config(config_path)
1243
1248
  extra_deny_write: list[str] = []
1244
1249
  if twsrt_dir is not None:
1245
- for kind, name in DEFAULT_OUTPUT_NAMES.items():
1250
+ for kind, source in list(config.sources.items()):
1246
1251
  config.sources[kind] = replace(
1247
- config.sources[kind], output_path=twsrt_dir / name
1252
+ source, output_path=twsrt_dir / DEFAULT_OUTPUT_NAMES[kind]
1248
1253
  )
1249
1254
  # Claude hot-reloads --settings: an agent able to write here could
1250
1255
  # loosen its own policy mid-session.
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import tomllib
6
+ from collections.abc import Iterable
6
7
  from pathlib import Path
7
8
  from typing import Any, cast
8
9
 
@@ -16,11 +17,24 @@ from twsrt.lib.models import (
16
17
 
17
18
  SCHEMA_VERSION = 1
18
19
  SOURCE_KINDS = ("srt", "bash")
20
+ # srt is the sandbox itself. bash is optional: without it no command rules
21
+ # exist and every bash code path is skipped.
22
+ REQUIRED_SOURCE_KINDS = ("srt",)
19
23
  # Canonical output file names: next to config.toml when [sources.<kind>].output
20
24
  # is omitted, and inside ./.twsrt/ under `generate --project`.
21
25
  DEFAULT_OUTPUT_NAMES = {"srt": "srt-settings.json", "bash": "bash-rules.json"}
22
26
 
23
27
 
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
+ )
34
+ available = ", ".join(sorted(configured))
35
+ return f"Unknown source kind {kind!r}; available: {available}"
36
+
37
+
24
38
  def load_config(config_path: Path) -> AppConfig:
25
39
  """Load and validate the canonical twsrt configuration."""
26
40
  if not config_path.exists():
@@ -69,7 +83,8 @@ def load_config(config_path: Path) -> AppConfig:
69
83
  # orchestration consumes config.sources instead of these compatibility
70
84
  # accessors.
71
85
  config.srt_path = sources["srt"].output_path
72
- config.bash_rules_path = sources["bash"].output_path
86
+ if "bash" in sources:
87
+ config.bash_rules_path = sources["bash"].output_path
73
88
  _apply_target_paths(config, targets, base_dir)
74
89
  config.sandbox_overrides = dict(data.get("sandbox_overrides", {}))
75
90
  config.claude_sync = _build_claude_sync(data.get("claude_sync"))
@@ -148,7 +163,7 @@ def _build_sources(raw: dict[str, Any], base_dir: Path) -> dict[str, CanonicalSo
148
163
  fragments=fragments,
149
164
  )
150
165
 
151
- missing = [kind for kind in SOURCE_KINDS if kind not in sources]
166
+ missing = [kind for kind in REQUIRED_SOURCE_KINDS if kind not in sources]
152
167
  if missing:
153
168
  raise ValueError(f"Missing canonical source kind(s): {', '.join(missing)}")
154
169
  return sources
@@ -196,6 +211,13 @@ def _build_profiles(
196
211
  if not isinstance(blob, dict):
197
212
  raise ValueError(f"profiles.{name} must be a table")
198
213
  profile_blob = cast(dict[str, Any], blob)
214
+ unconfigured = set(profile_blob) & (set(SOURCE_KINDS) - set(sources))
215
+ if unconfigured:
216
+ kind = min(unconfigured)
217
+ raise ValueError(
218
+ f"profiles.{name}: source kind {kind!r} not configured; add "
219
+ f"[sources.{kind}] or remove profiles.{name}.{kind}"
220
+ )
199
221
  unknown = set(profile_blob) - {"extends", *sources}
200
222
  if unknown:
201
223
  raise ValueError(
@@ -84,7 +84,9 @@ def compile_sources(
84
84
  )
85
85
 
86
86
  srt_result = parse_srt_document(documents["srt"].document)
87
- bash_rules = parse_bash_document(documents["bash"].document)
87
+ bash_rules = (
88
+ parse_bash_document(documents["bash"].document) if "bash" in documents else []
89
+ )
88
90
  return CompilationResult(
89
91
  profile_name=profile.name,
90
92
  documents=documents,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twsrt
3
- Version: 3.2.0
3
+ Version: 3.3.0
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
@@ -213,7 +213,7 @@ from a plain terminal
213
213
 
214
214
  | Term | Meaning |
215
215
  |---|---|
216
- | Source kind | A canonical document type: `srt` (filesystem and network policy) and `bash` (command allow/ask/deny lists) |
216
+ | Source kind | A canonical document type: `srt` (filesystem and network policy, required) and `bash` (command allow/ask/deny lists, optional) |
217
217
  | Fragment | One named `.jsonc` file holding a slice of policy for one source kind. Fragments never include each other |
218
218
  | Profile | An ordered selection of fragments per source kind; may `extend` other profiles. `default_profile` applies when `-p` is omitted |
219
219
  | Target | An agent config file translated from the canonical output |
@@ -233,7 +233,7 @@ path = "srt/base.jsonc"
233
233
  [sources.srt.fragments.work]
234
234
  path = "srt/work.jsonc"
235
235
 
236
- [sources.bash] # output omitted: bash-rules.json next to config.toml
236
+ [sources.bash] # optional; output omitted: bash-rules.json next to config.toml
237
237
  [sources.bash.fragments.base]
238
238
  path = "bash/base.jsonc"
239
239
 
@@ -269,10 +269,12 @@ allowUnsandboxedCommands = false
269
269
  enabled = false
270
270
  ```
271
271
 
272
- Only `schema_version`, `default_profile`, both `[sources.*]` kinds and one
273
- profile are required. `config --init` writes exactly that, plus
274
- `[sandbox_overrides.yolo]`, and leaves every other key commented out with
275
- its default value.
272
+ Only `schema_version`, `default_profile`, `[sources.srt]` and one profile are
273
+ required. Without `[sources.bash]` no command rules exist: nothing is compiled
274
+ to `bash-rules.json` and no agent gets Bash allow/ask/deny entries; a profile
275
+ must then not name `bash`. `config --init` writes exactly the required keys,
276
+ plus `[sandbox_overrides.yolo]`, and leaves every other key, `[sources.bash]`
277
+ included, commented out with its default value.
276
278
 
277
279
  `output` is optional per source kind and defaults to `srt-settings.json` /
278
280
  `bash-rules.json` next to `config.toml`. srt itself reads only
@@ -342,7 +344,7 @@ repository and loaded per launch instead of the global files:
342
344
  ```
343
345
  twsrt generate claude -w -p slim --project
344
346
  → ./.twsrt/srt-settings.json canonical srt (instead of ~/.srt-settings.json)
345
- → ./.twsrt/bash-rules.json canonical bash
347
+ → ./.twsrt/bash-rules.json canonical bash (only with [sources.bash])
346
348
  → ./.twsrt/claude-settings[.yolo].json Claude target (instead of ~/.claude/settings.full.json)
347
349
  → ./.twsrt/.gitignore "*"
348
350
  stdout: the absolute .twsrt directory
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