twsrt 2.0.0__tar.gz → 2.2.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.
- {twsrt-2.0.0 → twsrt-2.2.0}/PKG-INFO +21 -28
- {twsrt-2.0.0 → twsrt-2.2.0}/README.md +19 -27
- {twsrt-2.0.0 → twsrt-2.2.0}/pyproject.toml +3 -2
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/bin/cli.py +165 -59
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/doctor.py +157 -38
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt.egg-info/PKG-INFO +21 -28
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt.egg-info/requires.txt +1 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/setup.cfg +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/__init__.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/bin/__init__.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/__init__.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/agent.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/claude.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/codex.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/composition.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/config.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/copilot.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/jsonc.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/models.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/probe.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/profiles.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/sources.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt/lib/symlink.py +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt.egg-info/SOURCES.txt +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt.egg-info/dependency_links.txt +0 -0
- {twsrt-2.0.0 → twsrt-2.2.0}/src/twsrt.egg-info/entry_points.txt +0 -0
- {twsrt-2.0.0 → twsrt-2.2.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: 2.
|
|
3
|
+
Version: 2.2.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
|
|
@@ -8,6 +8,7 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Requires-Python: >=3.11
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: rich>=14.3.3
|
|
11
12
|
Requires-Dist: tomlkit>=0.13.2
|
|
12
13
|
Requires-Dist: typer>=0.15.1
|
|
13
14
|
|
|
@@ -179,7 +180,7 @@ Profiles extend each other but only ever *add*:
|
|
|
179
180
|
uv tool install twsrt # or: pip install twsrt
|
|
180
181
|
|
|
181
182
|
twsrt config --init # writes ~/.config/twsrt/config.toml + starter fragments
|
|
182
|
-
twsrt edit # opens
|
|
183
|
+
twsrt edit # opens every fragment: deny paths, domains, command rules
|
|
183
184
|
|
|
184
185
|
twsrt show # print the compiled canonical ~/.srt-settings.json
|
|
185
186
|
twsrt generate claude # preview the Claude translation; writes nothing
|
|
@@ -324,28 +325,6 @@ srt-p() { local p=$1 d; shift; d=$(twsrt generate claude -w -p "$p" --project
|
|
|
324
325
|
srt -s "$d/srt-settings.json" "$@"; }
|
|
325
326
|
```
|
|
326
327
|
|
|
327
|
-
**Dropping a global rule.** Composition only adds, so a project never
|
|
328
|
-
subtracts. Put a rule you may want to drop into its own fragment and give
|
|
329
|
-
the project a profile that leaves it out (`twsrt profiles` lists them):
|
|
330
|
-
|
|
331
|
-
```toml
|
|
332
|
-
[profiles.default]
|
|
333
|
-
srt = ["base", "cloud-creds"]
|
|
334
|
-
|
|
335
|
-
[profiles.slim] # same as default, without cloud-creds
|
|
336
|
-
srt = ["base"]
|
|
337
|
-
bash = ["base"] # every profile selects fragments for every source kind
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
**Why the launch line needs both flags.** `--settings X` loads the project
|
|
341
|
-
policy; `--setting-sources project,local` skips `~/.claude/settings.json`.
|
|
342
|
-
Claude unions list settings across scopes, so without the second flag every
|
|
343
|
-
deny the project profile dropped silently comes back from the global file.
|
|
344
|
-
Because the global file is skipped, `X` also carries your user settings
|
|
345
|
-
(hooks, plugins, model): it is the selective merge of the project policy
|
|
346
|
-
onto the global Claude target of the same mode, which must exist
|
|
347
|
-
(`twsrt generate claude -w [--yolo]` once).
|
|
348
|
-
|
|
349
328
|
**What `--project` changes.** Only where outputs land: `./.twsrt/` of the
|
|
350
329
|
current directory (`cd` first). No symlink flip, no `[claude_sync]` donor,
|
|
351
330
|
no global file touched; preview and `-w -n` work as usual. `all` means
|
|
@@ -429,8 +408,8 @@ is preserved. Restart Codex after generation.
|
|
|
429
408
|
|
|
430
409
|
### Copilot CLI
|
|
431
410
|
|
|
432
|
-
|
|
433
|
-
command (to stdout, or to `copilot_output`). Nothing kernel-guards Copilot's
|
|
411
|
+
twsrt does not manage Copilot's `~/.copilot/settings.json`; it emits a flag
|
|
412
|
+
snippet for the launch command (to stdout, or to `copilot_output`). Nothing kernel-guards Copilot's
|
|
434
413
|
tools, so run it under the SRT wrapper, which enforces the paths and domains:
|
|
435
414
|
|
|
436
415
|
```bash
|
|
@@ -442,6 +421,12 @@ starts with `--yolo` and keeps only `--deny-tool` and `--deny-url`; deny
|
|
|
442
421
|
flags still take precedence over `--yolo`.
|
|
443
422
|
[Copilot flags](doc/REFERENCE.md#copilot-flags).
|
|
444
423
|
|
|
424
|
+
**`--add-dir` is a trust grant.** Besides file access, Copilot loads the added
|
|
425
|
+
directory's `.github/skills` and `.github/agents` as trusted configuration.
|
|
426
|
+
Start Copilot inside the repository instead, or add only directories whose
|
|
427
|
+
agent definitions you trust. twsrt does not emit `--add-dir`
|
|
428
|
+
([SECURITY_CONCEPT.md §7.1](SECURITY_CONCEPT.md#71-what-twsrt-does-not-protect-against)).
|
|
429
|
+
|
|
445
430
|
## Verifying the policy
|
|
446
431
|
|
|
447
432
|
Three read-only commands answer three different questions:
|
|
@@ -509,8 +494,8 @@ Threat model, rationale and every known gap:
|
|
|
509
494
|
| Command | Effect |
|
|
510
495
|
|---|---|
|
|
511
496
|
| `twsrt config [--init]` | Open `config.toml` in `$EDITOR` (fallback `vi`); `--init` first creates it and starter fragments, never overwriting an existing file |
|
|
512
|
-
| `twsrt edit [srt\|bash] [-p P] [-n]` | Open
|
|
513
|
-
| `twsrt profiles` |
|
|
497
|
+
| `twsrt edit [srt\|bash] [-p P] [-n]` | Open every registered fragment (only profile P's with `-p`) in `$EDITOR`, then report whether targets are stale; `-n` only names them |
|
|
498
|
+
| `twsrt profiles` | Table of every profile with its parents and resolved fragments per source kind; `*` marks `default_profile`, inherited fragments are dimmed, `invalid` marks one that cannot compile on its own |
|
|
514
499
|
| `twsrt show [srt\|bash] [-p P]` | Print the compiled canonical document exactly as `-w` would write it. Writes nothing |
|
|
515
500
|
| `twsrt generate [agent] [-p P]` | Print the agent translation (`claude`, `codex`, `copilot`, default `all`). Writes nothing |
|
|
516
501
|
| `twsrt generate [agent] -w` | Write the canonical outputs (always, whichever agent) and the agent target |
|
|
@@ -552,3 +537,11 @@ make ty # type check with ty
|
|
|
552
537
|
make static-analysis # all of the above
|
|
553
538
|
make install # uv tool install -e . plus shell completion
|
|
554
539
|
```
|
|
540
|
+
|
|
541
|
+
`scripts/srt-schema.mjs` prints the config key tree of the installed srt (Node; srt ships no JSON
|
|
542
|
+
schema). Run it after an srt upgrade to spot new keys; srt silently drops unknown keys outside
|
|
543
|
+
`credentials`.
|
|
544
|
+
|
|
545
|
+
`scripts/copilot-schema.py` does the same for the `sandbox` key of Copilot CLI's
|
|
546
|
+
`~/.copilot/settings.json` (uv script), read from the JSON schema shipped with the newest build
|
|
547
|
+
under `~/.copilot/pkg/`.
|
|
@@ -166,7 +166,7 @@ Profiles extend each other but only ever *add*:
|
|
|
166
166
|
uv tool install twsrt # or: pip install twsrt
|
|
167
167
|
|
|
168
168
|
twsrt config --init # writes ~/.config/twsrt/config.toml + starter fragments
|
|
169
|
-
twsrt edit # opens
|
|
169
|
+
twsrt edit # opens every fragment: deny paths, domains, command rules
|
|
170
170
|
|
|
171
171
|
twsrt show # print the compiled canonical ~/.srt-settings.json
|
|
172
172
|
twsrt generate claude # preview the Claude translation; writes nothing
|
|
@@ -311,28 +311,6 @@ srt-p() { local p=$1 d; shift; d=$(twsrt generate claude -w -p "$p" --project
|
|
|
311
311
|
srt -s "$d/srt-settings.json" "$@"; }
|
|
312
312
|
```
|
|
313
313
|
|
|
314
|
-
**Dropping a global rule.** Composition only adds, so a project never
|
|
315
|
-
subtracts. Put a rule you may want to drop into its own fragment and give
|
|
316
|
-
the project a profile that leaves it out (`twsrt profiles` lists them):
|
|
317
|
-
|
|
318
|
-
```toml
|
|
319
|
-
[profiles.default]
|
|
320
|
-
srt = ["base", "cloud-creds"]
|
|
321
|
-
|
|
322
|
-
[profiles.slim] # same as default, without cloud-creds
|
|
323
|
-
srt = ["base"]
|
|
324
|
-
bash = ["base"] # every profile selects fragments for every source kind
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
**Why the launch line needs both flags.** `--settings X` loads the project
|
|
328
|
-
policy; `--setting-sources project,local` skips `~/.claude/settings.json`.
|
|
329
|
-
Claude unions list settings across scopes, so without the second flag every
|
|
330
|
-
deny the project profile dropped silently comes back from the global file.
|
|
331
|
-
Because the global file is skipped, `X` also carries your user settings
|
|
332
|
-
(hooks, plugins, model): it is the selective merge of the project policy
|
|
333
|
-
onto the global Claude target of the same mode, which must exist
|
|
334
|
-
(`twsrt generate claude -w [--yolo]` once).
|
|
335
|
-
|
|
336
314
|
**What `--project` changes.** Only where outputs land: `./.twsrt/` of the
|
|
337
315
|
current directory (`cd` first). No symlink flip, no `[claude_sync]` donor,
|
|
338
316
|
no global file touched; preview and `-w -n` work as usual. `all` means
|
|
@@ -416,8 +394,8 @@ is preserved. Restart Codex after generation.
|
|
|
416
394
|
|
|
417
395
|
### Copilot CLI
|
|
418
396
|
|
|
419
|
-
|
|
420
|
-
command (to stdout, or to `copilot_output`). Nothing kernel-guards Copilot's
|
|
397
|
+
twsrt does not manage Copilot's `~/.copilot/settings.json`; it emits a flag
|
|
398
|
+
snippet for the launch command (to stdout, or to `copilot_output`). Nothing kernel-guards Copilot's
|
|
421
399
|
tools, so run it under the SRT wrapper, which enforces the paths and domains:
|
|
422
400
|
|
|
423
401
|
```bash
|
|
@@ -429,6 +407,12 @@ starts with `--yolo` and keeps only `--deny-tool` and `--deny-url`; deny
|
|
|
429
407
|
flags still take precedence over `--yolo`.
|
|
430
408
|
[Copilot flags](doc/REFERENCE.md#copilot-flags).
|
|
431
409
|
|
|
410
|
+
**`--add-dir` is a trust grant.** Besides file access, Copilot loads the added
|
|
411
|
+
directory's `.github/skills` and `.github/agents` as trusted configuration.
|
|
412
|
+
Start Copilot inside the repository instead, or add only directories whose
|
|
413
|
+
agent definitions you trust. twsrt does not emit `--add-dir`
|
|
414
|
+
([SECURITY_CONCEPT.md §7.1](SECURITY_CONCEPT.md#71-what-twsrt-does-not-protect-against)).
|
|
415
|
+
|
|
432
416
|
## Verifying the policy
|
|
433
417
|
|
|
434
418
|
Three read-only commands answer three different questions:
|
|
@@ -496,8 +480,8 @@ Threat model, rationale and every known gap:
|
|
|
496
480
|
| Command | Effect |
|
|
497
481
|
|---|---|
|
|
498
482
|
| `twsrt config [--init]` | Open `config.toml` in `$EDITOR` (fallback `vi`); `--init` first creates it and starter fragments, never overwriting an existing file |
|
|
499
|
-
| `twsrt edit [srt\|bash] [-p P] [-n]` | Open
|
|
500
|
-
| `twsrt profiles` |
|
|
483
|
+
| `twsrt edit [srt\|bash] [-p P] [-n]` | Open every registered fragment (only profile P's with `-p`) in `$EDITOR`, then report whether targets are stale; `-n` only names them |
|
|
484
|
+
| `twsrt profiles` | Table of every profile with its parents and resolved fragments per source kind; `*` marks `default_profile`, inherited fragments are dimmed, `invalid` marks one that cannot compile on its own |
|
|
501
485
|
| `twsrt show [srt\|bash] [-p P]` | Print the compiled canonical document exactly as `-w` would write it. Writes nothing |
|
|
502
486
|
| `twsrt generate [agent] [-p P]` | Print the agent translation (`claude`, `codex`, `copilot`, default `all`). Writes nothing |
|
|
503
487
|
| `twsrt generate [agent] -w` | Write the canonical outputs (always, whichever agent) and the agent target |
|
|
@@ -539,3 +523,11 @@ make ty # type check with ty
|
|
|
539
523
|
make static-analysis # all of the above
|
|
540
524
|
make install # uv tool install -e . plus shell completion
|
|
541
525
|
```
|
|
526
|
+
|
|
527
|
+
`scripts/srt-schema.mjs` prints the config key tree of the installed srt (Node; srt ships no JSON
|
|
528
|
+
schema). Run it after an srt upgrade to spot new keys; srt silently drops unknown keys outside
|
|
529
|
+
`credentials`.
|
|
530
|
+
|
|
531
|
+
`scripts/copilot-schema.py` does the same for the `sandbox` key of Copilot CLI's
|
|
532
|
+
`~/.copilot/settings.json` (uv script), read from the JSON schema shipped with the newest build
|
|
533
|
+
under `~/.copilot/pkg/`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "twsrt"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.2.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"
|
|
@@ -13,6 +13,7 @@ classifiers = [
|
|
|
13
13
|
"Programming Language :: Python :: 3",
|
|
14
14
|
]
|
|
15
15
|
dependencies = [
|
|
16
|
+
"rich>=14.3.3",
|
|
16
17
|
"tomlkit>=0.13.2",
|
|
17
18
|
"typer>=0.15.1",
|
|
18
19
|
]
|
|
@@ -44,7 +45,7 @@ dev = [
|
|
|
44
45
|
]
|
|
45
46
|
|
|
46
47
|
[tool.bumpversion]
|
|
47
|
-
current_version = "2.
|
|
48
|
+
current_version = "2.2.0"
|
|
48
49
|
commit = true
|
|
49
50
|
tag = false
|
|
50
51
|
tag_name = "v{new_version}"
|
|
@@ -16,7 +16,7 @@ import typer
|
|
|
16
16
|
|
|
17
17
|
from twsrt.lib.models import AppConfig, CompilationResult, yolo_path
|
|
18
18
|
|
|
19
|
-
__version__ = "2.
|
|
19
|
+
__version__ = "2.2.0"
|
|
20
20
|
|
|
21
21
|
app = typer.Typer(
|
|
22
22
|
name="twsrt",
|
|
@@ -75,6 +75,20 @@ def _debug(message: str) -> None:
|
|
|
75
75
|
typer.secho(f"Debug: {message}", fg=typer.colors.CYAN, dim=True, err=True)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
def _console():
|
|
79
|
+
"""Rich console on stdout, created per call so it binds the current
|
|
80
|
+
sys.stdout (CliRunner swaps it) and honours NO_COLOR.
|
|
81
|
+
|
|
82
|
+
Pass user data as rich.text.Text, never as a plain str: rich parses a
|
|
83
|
+
`[...]` in a rule or path as markup and silently drops it. Print lines with
|
|
84
|
+
soft_wrap=True so a piped line is never broken at 80 columns.
|
|
85
|
+
"""
|
|
86
|
+
from rich.console import Console
|
|
87
|
+
|
|
88
|
+
# NO_COLOR counts when set at all, as in main(); rich alone ignores "".
|
|
89
|
+
return Console(color_system=None if "NO_COLOR" in os.environ else "auto")
|
|
90
|
+
|
|
91
|
+
|
|
78
92
|
class _CliLogHandler(logging.Handler):
|
|
79
93
|
def emit(self, record: logging.LogRecord) -> None:
|
|
80
94
|
_debug(self.format(record))
|
|
@@ -369,11 +383,14 @@ def edit(
|
|
|
369
383
|
False, "--dry-run", "-n", help="Name the fragments, open nothing"
|
|
370
384
|
),
|
|
371
385
|
) -> None:
|
|
372
|
-
"""Open
|
|
386
|
+
"""Open canonical-source fragments in $EDITOR.
|
|
387
|
+
|
|
388
|
+
Without --profile every registered fragment opens; with it, only the
|
|
389
|
+
fragments that profile resolves to (inherited ones included).
|
|
373
390
|
|
|
374
391
|
The complement of `config`: that opens the registry, this opens the policy.
|
|
375
|
-
|
|
376
|
-
|
|
392
|
+
Fragments are never compiled before opening, so one with a syntax error
|
|
393
|
+
still opens -- that is exactly when you need an editor.
|
|
377
394
|
"""
|
|
378
395
|
from twsrt.lib.config import load_config
|
|
379
396
|
from twsrt.lib.profiles import resolve_profile
|
|
@@ -381,7 +398,13 @@ def edit(
|
|
|
381
398
|
config_path: Path = ctx.obj["config_path"]
|
|
382
399
|
try:
|
|
383
400
|
config = load_config(config_path)
|
|
384
|
-
|
|
401
|
+
if profile is None:
|
|
402
|
+
fragments_by_kind = {
|
|
403
|
+
source_kind: list(source.fragments.values())
|
|
404
|
+
for source_kind, source in config.sources.items()
|
|
405
|
+
}
|
|
406
|
+
else:
|
|
407
|
+
fragments_by_kind = resolve_profile(config, profile).fragments
|
|
385
408
|
except (OSError, ValueError) as exc:
|
|
386
409
|
log.debug("Edit setup failed", exc_info=True)
|
|
387
410
|
_error(str(exc))
|
|
@@ -397,13 +420,11 @@ def edit(
|
|
|
397
420
|
for source_kind in config.sources:
|
|
398
421
|
if kind not in ("all", source_kind):
|
|
399
422
|
continue
|
|
400
|
-
for fragment in
|
|
423
|
+
for fragment in fragments_by_kind.get(source_kind, []):
|
|
401
424
|
if fragment.path not in paths:
|
|
402
425
|
paths.append(fragment.path)
|
|
403
426
|
|
|
404
|
-
log.debug(
|
|
405
|
-
"Editing profile %r kind=%s fragments=%d", resolved.name, kind, len(paths)
|
|
406
|
-
)
|
|
427
|
+
log.debug("Editing profile %r kind=%s fragments=%d", profile, kind, len(paths))
|
|
407
428
|
for path in paths:
|
|
408
429
|
try:
|
|
409
430
|
absent = not path.exists()
|
|
@@ -441,10 +462,14 @@ def edit(
|
|
|
441
462
|
def profiles(ctx: typer.Context) -> None:
|
|
442
463
|
"""List the configured profiles and the fragments each one resolves to.
|
|
443
464
|
|
|
444
|
-
`*` marks default_profile.
|
|
445
|
-
|
|
446
|
-
|
|
465
|
+
`*` marks default_profile. Fragments a profile selects itself are shown
|
|
466
|
+
plain, inherited ones dimmed. A profile that cannot be used on its own
|
|
467
|
+
(e.g. a mixin selecting no fragment for some source kind) is listed as
|
|
468
|
+
invalid instead of failing the whole listing.
|
|
447
469
|
"""
|
|
470
|
+
from rich.table import Table
|
|
471
|
+
from rich.text import Text
|
|
472
|
+
|
|
448
473
|
from twsrt.lib.config import load_config
|
|
449
474
|
from twsrt.lib.profiles import resolve_profile
|
|
450
475
|
|
|
@@ -455,27 +480,39 @@ def profiles(ctx: typer.Context) -> None:
|
|
|
455
480
|
_error(str(exc))
|
|
456
481
|
raise typer.Exit(1)
|
|
457
482
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
483
|
+
table = Table(caption="* default profile", caption_justify="left")
|
|
484
|
+
table.add_column("Profile", style="bold cyan", no_wrap=True)
|
|
485
|
+
table.add_column("Extends", style="magenta")
|
|
486
|
+
# config.sources order, so srt precedes bash as in config.toml.
|
|
487
|
+
for kind in config.sources:
|
|
488
|
+
table.add_column(kind)
|
|
489
|
+
|
|
490
|
+
for name in sorted(config.profiles):
|
|
491
|
+
profile = config.profiles[name]
|
|
492
|
+
label = (
|
|
493
|
+
Text(f"{name} *", style="bold green")
|
|
494
|
+
if name == config.default_profile
|
|
495
|
+
else Text(name)
|
|
496
|
+
)
|
|
497
|
+
extends = ", ".join(profile.extends)
|
|
464
498
|
try:
|
|
465
499
|
resolved = resolve_profile(config, name)
|
|
466
500
|
except ValueError as exc:
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
)
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
501
|
+
invalid = Text(f"invalid: {exc}", style="red")
|
|
502
|
+
table.add_row(label, extends, invalid, *[""] * (len(config.sources) - 1))
|
|
503
|
+
continue
|
|
504
|
+
cells = []
|
|
505
|
+
for kind in config.sources:
|
|
506
|
+
own = profile.selections.get(kind, [])
|
|
507
|
+
cell = Text()
|
|
508
|
+
for index, fragment in enumerate(resolved.fragments[kind]):
|
|
509
|
+
if index:
|
|
510
|
+
cell.append(", ")
|
|
511
|
+
cell.append(fragment.name, style="" if fragment.name in own else "dim")
|
|
512
|
+
cells.append(cell)
|
|
513
|
+
table.add_row(label, extends, *cells)
|
|
514
|
+
|
|
515
|
+
_console().print(table)
|
|
479
516
|
|
|
480
517
|
|
|
481
518
|
@app.command()
|
|
@@ -521,11 +558,6 @@ def doctor(
|
|
|
521
558
|
_success("doctor: no findings")
|
|
522
559
|
return
|
|
523
560
|
|
|
524
|
-
colors = {
|
|
525
|
-
"error": typer.colors.RED,
|
|
526
|
-
"warning": typer.colors.YELLOW,
|
|
527
|
-
"info": typer.colors.CYAN,
|
|
528
|
-
}
|
|
529
561
|
levels = {
|
|
530
562
|
"error": show_error,
|
|
531
563
|
"warning": show_warn,
|
|
@@ -538,26 +570,58 @@ def doctor(
|
|
|
538
570
|
else:
|
|
539
571
|
shown = {"error", "warning"}
|
|
540
572
|
# The filter is display only: counts and the exit code see every finding.
|
|
541
|
-
|
|
542
|
-
width = max((len(finding.code) for finding in visible), default=0)
|
|
543
|
-
for finding in visible:
|
|
544
|
-
typer.secho(
|
|
545
|
-
f"{finding.severity:<7} {finding.code:<{width}} {finding.message}",
|
|
546
|
-
fg=colors[finding.severity],
|
|
547
|
-
)
|
|
573
|
+
_print_findings([finding for finding in findings if finding.severity in shown])
|
|
548
574
|
counts = {
|
|
549
575
|
severity: sum(finding.severity == severity for finding in findings)
|
|
550
|
-
for severity in
|
|
576
|
+
for severity in _SEVERITY_STYLES
|
|
551
577
|
}
|
|
552
578
|
errors, warnings = counts["error"], counts["warning"]
|
|
553
|
-
typer.
|
|
579
|
+
typer.secho(
|
|
554
580
|
f"doctor: {errors} error{'' if errors == 1 else 's'}, "
|
|
555
|
-
f"{warnings} warning{'' if warnings == 1 else 's'}, {counts['info']} info"
|
|
581
|
+
f"{warnings} warning{'' if warnings == 1 else 's'}, {counts['info']} info",
|
|
582
|
+
fg=typer.colors.RED
|
|
583
|
+
if errors
|
|
584
|
+
else typer.colors.YELLOW
|
|
585
|
+
if warnings
|
|
586
|
+
else typer.colors.GREEN,
|
|
587
|
+
bold=bool(errors),
|
|
556
588
|
)
|
|
557
589
|
if errors:
|
|
558
590
|
raise typer.Exit(1)
|
|
559
591
|
|
|
560
592
|
|
|
593
|
+
_SEVERITY_STYLES = {"error": "bold red", "warning": "yellow", "info": "cyan"}
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def _print_findings(findings: list) -> None:
|
|
597
|
+
"""Grouped by location (where to fix it), most severe location first.
|
|
598
|
+
|
|
599
|
+
findings arrive ordered by severity, so first appearance orders the groups.
|
|
600
|
+
Each affected entry gets its own line, aligned under the message.
|
|
601
|
+
"""
|
|
602
|
+
from rich.text import Text
|
|
603
|
+
|
|
604
|
+
console = _console()
|
|
605
|
+
groups: dict[str, list] = {}
|
|
606
|
+
for finding in findings:
|
|
607
|
+
groups.setdefault(finding.location, []).append(finding)
|
|
608
|
+
width = max((len(finding.code) for finding in findings), default=0)
|
|
609
|
+
indent = " " * (2 + len("warning") + 2 + width + 2)
|
|
610
|
+
for location, group in groups.items():
|
|
611
|
+
console.print(Text(location, style="bold"), soft_wrap=True)
|
|
612
|
+
for finding in group:
|
|
613
|
+
line = Text(" ")
|
|
614
|
+
line.append(
|
|
615
|
+
f"{finding.severity:<7}", style=_SEVERITY_STYLES[finding.severity]
|
|
616
|
+
)
|
|
617
|
+
line.append(f" {finding.code:<{width}} ", style="dim")
|
|
618
|
+
line.append(finding.message)
|
|
619
|
+
console.print(line, soft_wrap=True)
|
|
620
|
+
for item in finding.items:
|
|
621
|
+
console.print(Text(f"{indent}• {item}"), soft_wrap=True)
|
|
622
|
+
console.print()
|
|
623
|
+
|
|
624
|
+
|
|
561
625
|
def _report_stale_targets(config_path: Path, profile: str | None) -> None:
|
|
562
626
|
"""After editing, say whether the generated targets still match the sources.
|
|
563
627
|
|
|
@@ -768,6 +832,7 @@ def diff(
|
|
|
768
832
|
)
|
|
769
833
|
drifted = _canonical_drift(compiled)
|
|
770
834
|
has_drift = bool(drifted)
|
|
835
|
+
agent_drift = False
|
|
771
836
|
for kind in compiled.documents:
|
|
772
837
|
if kind in drifted:
|
|
773
838
|
_drift(f"{kind} canonical: drift")
|
|
@@ -801,22 +866,48 @@ def diff(
|
|
|
801
866
|
if result.matched:
|
|
802
867
|
_success(f"{generator.name}: no drift")
|
|
803
868
|
else:
|
|
804
|
-
has_drift = True
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
869
|
+
has_drift = agent_drift = True
|
|
870
|
+
_print_agent_drift(generator.name, target, result)
|
|
871
|
+
|
|
872
|
+
if agent_drift:
|
|
873
|
+
from rich.text import Text
|
|
874
|
+
|
|
875
|
+
_console().print(
|
|
876
|
+
Text.assemble(
|
|
877
|
+
("+ missing from target", "green"),
|
|
878
|
+
" ",
|
|
879
|
+
("- in target, not in sources", "red"),
|
|
880
|
+
),
|
|
881
|
+
soft_wrap=True,
|
|
882
|
+
)
|
|
814
883
|
_print_generator_warnings(generators, compiled, config)
|
|
815
884
|
|
|
816
885
|
if has_drift:
|
|
817
886
|
raise typer.Exit(1)
|
|
818
887
|
|
|
819
888
|
|
|
889
|
+
def _print_agent_drift(name: str, target: Path, result) -> None:
|
|
890
|
+
"""Header naming the drifted file, then one bare entry per line; the
|
|
891
|
+
+/- legend is printed once after all targets."""
|
|
892
|
+
from rich.text import Text
|
|
893
|
+
|
|
894
|
+
console = _console()
|
|
895
|
+
console.print(
|
|
896
|
+
Text.assemble(
|
|
897
|
+
(f"{name}: ", "bold"),
|
|
898
|
+
(f"{len(result.missing)} missing, {len(result.extra)} extra", "yellow"),
|
|
899
|
+
" ",
|
|
900
|
+
(str(target), "dim"),
|
|
901
|
+
),
|
|
902
|
+
soft_wrap=True,
|
|
903
|
+
)
|
|
904
|
+
for entry in result.missing:
|
|
905
|
+
console.print(Text(f" + {entry}", style="green"), soft_wrap=True)
|
|
906
|
+
for entry in result.extra:
|
|
907
|
+
console.print(Text(f" - {entry}", style="red"), soft_wrap=True)
|
|
908
|
+
console.print()
|
|
909
|
+
|
|
910
|
+
|
|
820
911
|
@app.command(name="test")
|
|
821
912
|
def test_command(
|
|
822
913
|
ctx: typer.Context,
|
|
@@ -1027,17 +1118,32 @@ def _print_probe_result(result, widths: tuple[int, int]) -> None:
|
|
|
1027
1118
|
|
|
1028
1119
|
|
|
1029
1120
|
def _print_probe_details(results: list) -> None:
|
|
1121
|
+
"""One block per failed probe. Deliberately unboxed and soft-wrapped: the
|
|
1122
|
+
command line must copy-paste intact to reproduce the verdict by hand."""
|
|
1123
|
+
from rich.text import Text
|
|
1124
|
+
|
|
1030
1125
|
from twsrt.lib.probe import Status
|
|
1031
1126
|
|
|
1127
|
+
console = _console()
|
|
1032
1128
|
for result in results:
|
|
1033
1129
|
if result.status in (Status.PASS, Status.SKIP):
|
|
1034
1130
|
continue
|
|
1035
1131
|
probe = result.probe
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1132
|
+
status = result.status.value
|
|
1133
|
+
console.print()
|
|
1134
|
+
console.print(
|
|
1135
|
+
Text.assemble(
|
|
1136
|
+
(status, f"bold {_PROBE_STATUS_COLORS[status]}"),
|
|
1137
|
+
(f" {probe.kind} ", "dim"),
|
|
1138
|
+
(probe.rule, "bold"),
|
|
1139
|
+
),
|
|
1140
|
+
soft_wrap=True,
|
|
1141
|
+
)
|
|
1142
|
+
fields = [("reason", result.reason), ("command", probe.command)]
|
|
1039
1143
|
if result.sandbox_stderr.strip():
|
|
1040
|
-
|
|
1144
|
+
fields.append(("stderr", result.sandbox_stderr.strip()))
|
|
1145
|
+
for label, value in fields:
|
|
1146
|
+
console.print(Text.assemble((f" {label}: ", "dim"), value), soft_wrap=True)
|
|
1041
1147
|
|
|
1042
1148
|
|
|
1043
1149
|
def _print_probe_summary(results: list, widths: tuple[int, int]) -> None:
|
|
@@ -30,6 +30,58 @@ _DOMAIN_LISTS = ("allowedDomains", "deniedDomains")
|
|
|
30
30
|
_BASH_LISTS = ("allow", "ask", "deny")
|
|
31
31
|
_ALLOW_PATH_LISTS = ("allowWrite", "allowRead")
|
|
32
32
|
|
|
33
|
+
# Keys srt's config schema accepts; srt strips anything else without a word.
|
|
34
|
+
# ponytail: hand-copied from SandboxRuntimeConfigSchema in sandbox-runtime
|
|
35
|
+
# 0.0.78 (dist/sandbox/sandbox-config.js); a newer srt key is reported until
|
|
36
|
+
# added here. Upgrade path: read the schema from the installed srt.
|
|
37
|
+
_SRT_SCHEMA_KEYS = {
|
|
38
|
+
"": {
|
|
39
|
+
"network",
|
|
40
|
+
"filesystem",
|
|
41
|
+
"credentials",
|
|
42
|
+
"ignoreViolations",
|
|
43
|
+
"enableWeakerNestedSandbox",
|
|
44
|
+
"enableWeakerNetworkIsolation",
|
|
45
|
+
"allowAppleEvents",
|
|
46
|
+
"ripgrep",
|
|
47
|
+
"mandatoryDenySearchDepth",
|
|
48
|
+
"allowPty",
|
|
49
|
+
"seccomp",
|
|
50
|
+
"bwrapPath",
|
|
51
|
+
"socatPath",
|
|
52
|
+
"javaAgentJarPath",
|
|
53
|
+
"windows",
|
|
54
|
+
"git",
|
|
55
|
+
# Not in srt's schema, but twsrt maps it to Claude's sandbox.enabled.
|
|
56
|
+
"enabled",
|
|
57
|
+
},
|
|
58
|
+
"network": {
|
|
59
|
+
"allowedDomains",
|
|
60
|
+
"deniedDomains",
|
|
61
|
+
"deniedDomainReasons",
|
|
62
|
+
"strictAllowlist",
|
|
63
|
+
"deniedResolvedAddresses",
|
|
64
|
+
"allowUnixSockets",
|
|
65
|
+
"allowAllUnixSockets",
|
|
66
|
+
"allowLocalBinding",
|
|
67
|
+
"allowMachLookup",
|
|
68
|
+
"httpProxyPort",
|
|
69
|
+
"socksProxyPort",
|
|
70
|
+
"mitmProxy",
|
|
71
|
+
"filterRequest",
|
|
72
|
+
"tlsTerminate",
|
|
73
|
+
"parentProxy",
|
|
74
|
+
},
|
|
75
|
+
"filesystem": {
|
|
76
|
+
"disabled",
|
|
77
|
+
"denyRead",
|
|
78
|
+
"allowRead",
|
|
79
|
+
"allowWrite",
|
|
80
|
+
"denyWrite",
|
|
81
|
+
"allowGitConfig",
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
|
|
33
85
|
# `// doctor-ignore` or `// doctor-ignore: free-text reason` after an entry.
|
|
34
86
|
_IGNORE_DIRECTIVE = re.compile(r"//\s*doctor-ignore\b")
|
|
35
87
|
# A JSON string literal that is a value, not an object key.
|
|
@@ -41,9 +93,17 @@ Ignores = dict[Path, set[str]]
|
|
|
41
93
|
|
|
42
94
|
@dataclass(frozen=True)
|
|
43
95
|
class Finding:
|
|
96
|
+
"""One diagnostic, structured so output can group and list it.
|
|
97
|
+
|
|
98
|
+
location is where to fix it: a fragment, `profile 'x'` or a settings file.
|
|
99
|
+
items are the affected entries, one per output line; message summarises them.
|
|
100
|
+
"""
|
|
101
|
+
|
|
44
102
|
severity: str
|
|
45
103
|
code: str
|
|
104
|
+
location: str
|
|
46
105
|
message: str
|
|
106
|
+
items: tuple[str, ...] = ()
|
|
47
107
|
|
|
48
108
|
|
|
49
109
|
def diagnose(
|
|
@@ -60,10 +120,11 @@ def diagnose(
|
|
|
60
120
|
resolved = _resolve_profiles(config, findings)
|
|
61
121
|
_compile_profiles(config, resolved, broken, findings)
|
|
62
122
|
_check_profile_structure(config, findings)
|
|
63
|
-
_check_unused_fragments(config, findings)
|
|
123
|
+
_check_unused_fragments(config, base_dir, findings)
|
|
64
124
|
for profile in resolved.values():
|
|
65
125
|
_check_profile_lists(profile, loaded, ignores, base_dir, findings)
|
|
66
126
|
_check_patterns(config, loaded, ignores, base_dir, findings)
|
|
127
|
+
_check_unknown_srt_keys(config, loaded, base_dir, findings)
|
|
67
128
|
_check_symlinked_denies(config, loaded, ignores, base_dir, findings)
|
|
68
129
|
_check_broad_allow_write(config, loaded, ignores, base_dir, findings)
|
|
69
130
|
_check_claude_files(claude_files, findings)
|
|
@@ -93,7 +154,8 @@ def _load_fragments(
|
|
|
93
154
|
Finding(
|
|
94
155
|
"error",
|
|
95
156
|
"fragment-load",
|
|
96
|
-
|
|
157
|
+
_show(fragment.path, base_dir),
|
|
158
|
+
str(exc),
|
|
97
159
|
)
|
|
98
160
|
)
|
|
99
161
|
return loaded, broken, ignores
|
|
@@ -131,7 +193,8 @@ def _resolve_profiles(
|
|
|
131
193
|
Finding(
|
|
132
194
|
"warning",
|
|
133
195
|
"profile-incomplete",
|
|
134
|
-
f"profile {name!r}
|
|
196
|
+
f"profile {name!r}",
|
|
197
|
+
f"cannot be used on its own: {exc}",
|
|
135
198
|
)
|
|
136
199
|
)
|
|
137
200
|
return resolved
|
|
@@ -154,7 +217,7 @@ def _compile_profiles(
|
|
|
154
217
|
compile_sources(config, profile)
|
|
155
218
|
except (OSError, ValueError) as exc:
|
|
156
219
|
findings.append(
|
|
157
|
-
Finding("error", "profile-compile", f"profile {name!r}
|
|
220
|
+
Finding("error", "profile-compile", f"profile {name!r}", str(exc))
|
|
158
221
|
)
|
|
159
222
|
|
|
160
223
|
|
|
@@ -175,8 +238,8 @@ def _check_profile_structure(config: AppConfig, findings: list[Finding]) -> None
|
|
|
175
238
|
Finding(
|
|
176
239
|
"warning",
|
|
177
240
|
"redundant-extends",
|
|
178
|
-
f"profile {name!r}
|
|
179
|
-
f"inherited via {via[0]!r}",
|
|
241
|
+
f"profile {name!r}",
|
|
242
|
+
f"extends {parent!r} is already inherited via {via[0]!r}",
|
|
180
243
|
)
|
|
181
244
|
)
|
|
182
245
|
inherited = _inherited_selections(config, name)
|
|
@@ -188,8 +251,9 @@ def _check_profile_structure(config: AppConfig, findings: list[Finding]) -> None
|
|
|
188
251
|
Finding(
|
|
189
252
|
"warning",
|
|
190
253
|
"inherited-fragment",
|
|
191
|
-
f"profile {name!r}
|
|
192
|
-
f"
|
|
254
|
+
f"profile {name!r}",
|
|
255
|
+
f"{kind} fragment {fragment!r} is already inherited "
|
|
256
|
+
f"from {owner!r}",
|
|
193
257
|
)
|
|
194
258
|
)
|
|
195
259
|
|
|
@@ -211,7 +275,9 @@ def _inherited_selections(config: AppConfig, name: str) -> dict[tuple[str, str],
|
|
|
211
275
|
return owners
|
|
212
276
|
|
|
213
277
|
|
|
214
|
-
def _check_unused_fragments(
|
|
278
|
+
def _check_unused_fragments(
|
|
279
|
+
config: AppConfig, base_dir: Path, findings: list[Finding]
|
|
280
|
+
) -> None:
|
|
215
281
|
used = {
|
|
216
282
|
(kind, fragment)
|
|
217
283
|
for profile in config.profiles.values()
|
|
@@ -219,12 +285,13 @@ def _check_unused_fragments(config: AppConfig, findings: list[Finding]) -> None:
|
|
|
219
285
|
for fragment in selected
|
|
220
286
|
}
|
|
221
287
|
for kind, source in config.sources.items():
|
|
222
|
-
for fragment in source.fragments:
|
|
288
|
+
for fragment, registered in source.fragments.items():
|
|
223
289
|
if (kind, fragment) not in used:
|
|
224
290
|
findings.append(
|
|
225
291
|
Finding(
|
|
226
292
|
"warning",
|
|
227
293
|
"unused-fragment",
|
|
294
|
+
_show(registered.path, base_dir),
|
|
228
295
|
f"{kind} fragment {fragment!r} is selected by no profile",
|
|
229
296
|
)
|
|
230
297
|
)
|
|
@@ -244,18 +311,14 @@ def _check_profile_lists(
|
|
|
244
311
|
key = list_name.rsplit(".", 1)[-1]
|
|
245
312
|
# Grouped per contributing fragment: one finding per file and list.
|
|
246
313
|
covered: dict[Path, list[str]] = {}
|
|
314
|
+
# (redundant copy, earlier copies) -> duplicated entries.
|
|
315
|
+
duplicated: dict[tuple[Path, tuple[Path, ...]], list[str]] = {}
|
|
247
316
|
for value, origins in values.items():
|
|
248
|
-
if len(origins) > 1 and not _ignored(ignores, origins, value):
|
|
249
|
-
shown = ", ".join(_show(path, base_dir) for path in origins)
|
|
250
|
-
findings.append(
|
|
251
|
-
Finding(
|
|
252
|
-
"warning",
|
|
253
|
-
"duplicate-rule",
|
|
254
|
-
f"{list_name}: {value!r} appears in {shown}",
|
|
255
|
-
)
|
|
256
|
-
)
|
|
257
317
|
if _ignored(ignores, origins, value):
|
|
258
318
|
continue
|
|
319
|
+
if len(origins) > 1:
|
|
320
|
+
key_pair = (origins[-1], tuple(origins[:-1]))
|
|
321
|
+
duplicated.setdefault(key_pair, []).append(repr(value))
|
|
259
322
|
for other, other_origins in values.items():
|
|
260
323
|
if _covers(key, other, value):
|
|
261
324
|
where = (
|
|
@@ -267,14 +330,27 @@ def _check_profile_lists(
|
|
|
267
330
|
f"{value!r} by {other!r}{where}"
|
|
268
331
|
)
|
|
269
332
|
break
|
|
333
|
+
for (origin, earlier), items in duplicated.items():
|
|
334
|
+
shown = ", ".join(_show(path, base_dir) for path in earlier)
|
|
335
|
+
findings.append(
|
|
336
|
+
Finding(
|
|
337
|
+
"warning",
|
|
338
|
+
"duplicate-rule",
|
|
339
|
+
_show(origin, base_dir),
|
|
340
|
+
f"{list_name}: {_count(items, 'entry', 'entries')} "
|
|
341
|
+
f"also in {shown}",
|
|
342
|
+
tuple(items),
|
|
343
|
+
)
|
|
344
|
+
)
|
|
270
345
|
for origin, items in covered.items():
|
|
271
346
|
findings.append(
|
|
272
347
|
Finding(
|
|
273
348
|
"warning",
|
|
274
349
|
"subsumed-rule",
|
|
275
|
-
|
|
276
|
-
f"{_count(items, 'entry', 'entries')}
|
|
277
|
-
|
|
350
|
+
_show(origin, base_dir),
|
|
351
|
+
f"{list_name}: {_count(items, 'entry', 'entries')} "
|
|
352
|
+
"already covered",
|
|
353
|
+
tuple(items),
|
|
278
354
|
)
|
|
279
355
|
)
|
|
280
356
|
if key == "allowedDomains":
|
|
@@ -370,9 +446,10 @@ def _check_wildcard_apex(
|
|
|
370
446
|
Finding(
|
|
371
447
|
"info",
|
|
372
448
|
"wildcard-apex",
|
|
373
|
-
|
|
374
|
-
f"{_count(items, 'wildcard', 'wildcards')} not
|
|
375
|
-
"apex domain (add it where needed)
|
|
449
|
+
_show(origin, base_dir),
|
|
450
|
+
f"{list_name}: {_count(items, 'wildcard', 'wildcards')} not "
|
|
451
|
+
"matching the bare apex domain (add it where needed)",
|
|
452
|
+
tuple(items),
|
|
376
453
|
)
|
|
377
454
|
)
|
|
378
455
|
|
|
@@ -434,9 +511,10 @@ def _check_patterns(
|
|
|
434
511
|
Finding(
|
|
435
512
|
severity,
|
|
436
513
|
code,
|
|
437
|
-
|
|
438
|
-
f"{
|
|
439
|
-
f"{
|
|
514
|
+
where,
|
|
515
|
+
f"filesystem.{key}: "
|
|
516
|
+
f"{_count(hits[code], 'entry', 'entries')} {description}",
|
|
517
|
+
tuple(hits[code]),
|
|
440
518
|
)
|
|
441
519
|
)
|
|
442
520
|
|
|
@@ -454,6 +532,43 @@ def _path_trap(key: str, entry: str) -> str | None:
|
|
|
454
532
|
return None
|
|
455
533
|
|
|
456
534
|
|
|
535
|
+
def _check_unknown_srt_keys(
|
|
536
|
+
config: AppConfig,
|
|
537
|
+
loaded: dict[Path, dict[str, Any]],
|
|
538
|
+
base_dir: Path,
|
|
539
|
+
findings: list[Finding],
|
|
540
|
+
) -> None:
|
|
541
|
+
"""A key outside srt's schema is stripped by srt and dropped by twsrt.
|
|
542
|
+
|
|
543
|
+
Typical cause: a Claude-only setting such as excludedCommands placed in a
|
|
544
|
+
fragment, where it silently does nothing.
|
|
545
|
+
"""
|
|
546
|
+
for fragment in config.sources["srt"].fragments.values():
|
|
547
|
+
document = loaded.get(fragment.path, {})
|
|
548
|
+
unknown: list[str] = []
|
|
549
|
+
for section, known in _SRT_SCHEMA_KEYS.items():
|
|
550
|
+
container = document.get(section, {}) if section else document
|
|
551
|
+
if not isinstance(container, dict):
|
|
552
|
+
continue
|
|
553
|
+
unknown += [
|
|
554
|
+
repr(f"{section}.{key}" if section else key)
|
|
555
|
+
for key in container
|
|
556
|
+
if key not in known
|
|
557
|
+
]
|
|
558
|
+
if unknown:
|
|
559
|
+
findings.append(
|
|
560
|
+
Finding(
|
|
561
|
+
"warning",
|
|
562
|
+
"unknown-srt-key",
|
|
563
|
+
_show(fragment.path, base_dir),
|
|
564
|
+
f"{_count(unknown, 'key', 'keys')} srt ignores and twsrt maps "
|
|
565
|
+
"to no agent; Claude-only settings belong in "
|
|
566
|
+
"[sandbox_overrides]",
|
|
567
|
+
tuple(unknown),
|
|
568
|
+
)
|
|
569
|
+
)
|
|
570
|
+
|
|
571
|
+
|
|
457
572
|
def _count(items: list[str], singular: str, plural: str) -> str:
|
|
458
573
|
return f"{len(items)} {singular if len(items) == 1 else plural}"
|
|
459
574
|
|
|
@@ -514,10 +629,11 @@ def _check_symlinked_denies(
|
|
|
514
629
|
Finding(
|
|
515
630
|
"warning",
|
|
516
631
|
"symlinked-deny-path",
|
|
517
|
-
|
|
518
|
-
f"{_count(items, 'entry', 'entries')}
|
|
519
|
-
"sandbox matches the real path, so
|
|
520
|
-
|
|
632
|
+
_show(origin, base_dir),
|
|
633
|
+
f"filesystem.{key}: {_count(items, 'entry', 'entries')} "
|
|
634
|
+
"through a symlink; the sandbox matches the real path, so "
|
|
635
|
+
"list it too",
|
|
636
|
+
tuple(items),
|
|
521
637
|
)
|
|
522
638
|
)
|
|
523
639
|
|
|
@@ -551,10 +667,11 @@ def _check_broad_allow_write(
|
|
|
551
667
|
Finding(
|
|
552
668
|
"warning",
|
|
553
669
|
"broad-allow-write",
|
|
554
|
-
|
|
555
|
-
f"{_count(items, 'entry', 'entries')}
|
|
556
|
-
"root; in Claude Code they also
|
|
557
|
-
|
|
670
|
+
_show(origin, base_dir),
|
|
671
|
+
f"filesystem.allowWrite: {_count(items, 'entry', 'entries')} "
|
|
672
|
+
"covering home, / or a config root; in Claude Code they also "
|
|
673
|
+
"auto-approve edits (ADR 0002)",
|
|
674
|
+
tuple(items),
|
|
558
675
|
)
|
|
559
676
|
)
|
|
560
677
|
|
|
@@ -588,10 +705,12 @@ def _check_claude_files(claude_files: Sequence[Path], findings: list[Finding]) -
|
|
|
588
705
|
Finding(
|
|
589
706
|
"warning",
|
|
590
707
|
"claude-relative-sandbox-path",
|
|
591
|
-
|
|
708
|
+
str(path),
|
|
709
|
+
f"sandbox.filesystem.{key}: "
|
|
592
710
|
f"{_count(relative, 'entry', 'entries')} anchored at the "
|
|
593
711
|
"settings-file root, not the launch directory; use "
|
|
594
|
-
"Read()/Edit() rules instead
|
|
712
|
+
"Read()/Edit() rules instead",
|
|
713
|
+
tuple(relative),
|
|
595
714
|
)
|
|
596
715
|
)
|
|
597
716
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: twsrt
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.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
|
|
@@ -8,6 +8,7 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Requires-Python: >=3.11
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: rich>=14.3.3
|
|
11
12
|
Requires-Dist: tomlkit>=0.13.2
|
|
12
13
|
Requires-Dist: typer>=0.15.1
|
|
13
14
|
|
|
@@ -179,7 +180,7 @@ Profiles extend each other but only ever *add*:
|
|
|
179
180
|
uv tool install twsrt # or: pip install twsrt
|
|
180
181
|
|
|
181
182
|
twsrt config --init # writes ~/.config/twsrt/config.toml + starter fragments
|
|
182
|
-
twsrt edit # opens
|
|
183
|
+
twsrt edit # opens every fragment: deny paths, domains, command rules
|
|
183
184
|
|
|
184
185
|
twsrt show # print the compiled canonical ~/.srt-settings.json
|
|
185
186
|
twsrt generate claude # preview the Claude translation; writes nothing
|
|
@@ -324,28 +325,6 @@ srt-p() { local p=$1 d; shift; d=$(twsrt generate claude -w -p "$p" --project
|
|
|
324
325
|
srt -s "$d/srt-settings.json" "$@"; }
|
|
325
326
|
```
|
|
326
327
|
|
|
327
|
-
**Dropping a global rule.** Composition only adds, so a project never
|
|
328
|
-
subtracts. Put a rule you may want to drop into its own fragment and give
|
|
329
|
-
the project a profile that leaves it out (`twsrt profiles` lists them):
|
|
330
|
-
|
|
331
|
-
```toml
|
|
332
|
-
[profiles.default]
|
|
333
|
-
srt = ["base", "cloud-creds"]
|
|
334
|
-
|
|
335
|
-
[profiles.slim] # same as default, without cloud-creds
|
|
336
|
-
srt = ["base"]
|
|
337
|
-
bash = ["base"] # every profile selects fragments for every source kind
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
**Why the launch line needs both flags.** `--settings X` loads the project
|
|
341
|
-
policy; `--setting-sources project,local` skips `~/.claude/settings.json`.
|
|
342
|
-
Claude unions list settings across scopes, so without the second flag every
|
|
343
|
-
deny the project profile dropped silently comes back from the global file.
|
|
344
|
-
Because the global file is skipped, `X` also carries your user settings
|
|
345
|
-
(hooks, plugins, model): it is the selective merge of the project policy
|
|
346
|
-
onto the global Claude target of the same mode, which must exist
|
|
347
|
-
(`twsrt generate claude -w [--yolo]` once).
|
|
348
|
-
|
|
349
328
|
**What `--project` changes.** Only where outputs land: `./.twsrt/` of the
|
|
350
329
|
current directory (`cd` first). No symlink flip, no `[claude_sync]` donor,
|
|
351
330
|
no global file touched; preview and `-w -n` work as usual. `all` means
|
|
@@ -429,8 +408,8 @@ is preserved. Restart Codex after generation.
|
|
|
429
408
|
|
|
430
409
|
### Copilot CLI
|
|
431
410
|
|
|
432
|
-
|
|
433
|
-
command (to stdout, or to `copilot_output`). Nothing kernel-guards Copilot's
|
|
411
|
+
twsrt does not manage Copilot's `~/.copilot/settings.json`; it emits a flag
|
|
412
|
+
snippet for the launch command (to stdout, or to `copilot_output`). Nothing kernel-guards Copilot's
|
|
434
413
|
tools, so run it under the SRT wrapper, which enforces the paths and domains:
|
|
435
414
|
|
|
436
415
|
```bash
|
|
@@ -442,6 +421,12 @@ starts with `--yolo` and keeps only `--deny-tool` and `--deny-url`; deny
|
|
|
442
421
|
flags still take precedence over `--yolo`.
|
|
443
422
|
[Copilot flags](doc/REFERENCE.md#copilot-flags).
|
|
444
423
|
|
|
424
|
+
**`--add-dir` is a trust grant.** Besides file access, Copilot loads the added
|
|
425
|
+
directory's `.github/skills` and `.github/agents` as trusted configuration.
|
|
426
|
+
Start Copilot inside the repository instead, or add only directories whose
|
|
427
|
+
agent definitions you trust. twsrt does not emit `--add-dir`
|
|
428
|
+
([SECURITY_CONCEPT.md §7.1](SECURITY_CONCEPT.md#71-what-twsrt-does-not-protect-against)).
|
|
429
|
+
|
|
445
430
|
## Verifying the policy
|
|
446
431
|
|
|
447
432
|
Three read-only commands answer three different questions:
|
|
@@ -509,8 +494,8 @@ Threat model, rationale and every known gap:
|
|
|
509
494
|
| Command | Effect |
|
|
510
495
|
|---|---|
|
|
511
496
|
| `twsrt config [--init]` | Open `config.toml` in `$EDITOR` (fallback `vi`); `--init` first creates it and starter fragments, never overwriting an existing file |
|
|
512
|
-
| `twsrt edit [srt\|bash] [-p P] [-n]` | Open
|
|
513
|
-
| `twsrt profiles` |
|
|
497
|
+
| `twsrt edit [srt\|bash] [-p P] [-n]` | Open every registered fragment (only profile P's with `-p`) in `$EDITOR`, then report whether targets are stale; `-n` only names them |
|
|
498
|
+
| `twsrt profiles` | Table of every profile with its parents and resolved fragments per source kind; `*` marks `default_profile`, inherited fragments are dimmed, `invalid` marks one that cannot compile on its own |
|
|
514
499
|
| `twsrt show [srt\|bash] [-p P]` | Print the compiled canonical document exactly as `-w` would write it. Writes nothing |
|
|
515
500
|
| `twsrt generate [agent] [-p P]` | Print the agent translation (`claude`, `codex`, `copilot`, default `all`). Writes nothing |
|
|
516
501
|
| `twsrt generate [agent] -w` | Write the canonical outputs (always, whichever agent) and the agent target |
|
|
@@ -552,3 +537,11 @@ make ty # type check with ty
|
|
|
552
537
|
make static-analysis # all of the above
|
|
553
538
|
make install # uv tool install -e . plus shell completion
|
|
554
539
|
```
|
|
540
|
+
|
|
541
|
+
`scripts/srt-schema.mjs` prints the config key tree of the installed srt (Node; srt ships no JSON
|
|
542
|
+
schema). Run it after an srt upgrade to spot new keys; srt silently drops unknown keys outside
|
|
543
|
+
`credentials`.
|
|
544
|
+
|
|
545
|
+
`scripts/copilot-schema.py` does the same for the `sandbox` key of Copilot CLI's
|
|
546
|
+
`~/.copilot/settings.json` (uv script), read from the JSON schema shipped with the newest build
|
|
547
|
+
under `~/.copilot/pkg/`.
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|