twsrt 3.3.2__tar.gz → 3.4.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 (30) hide show
  1. {twsrt-3.3.2 → twsrt-3.4.0}/PKG-INFO +100 -32
  2. {twsrt-3.3.2 → twsrt-3.4.0}/README.md +99 -31
  3. {twsrt-3.3.2 → twsrt-3.4.0}/pyproject.toml +2 -2
  4. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/bin/cli.py +71 -15
  5. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/agent.py +2 -0
  6. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/codex.py +3 -1
  7. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/config.py +14 -0
  8. twsrt-3.4.0/src/twsrt/lib/copilot.py +226 -0
  9. twsrt-3.4.0/src/twsrt/lib/copilot_jetbrains.py +206 -0
  10. twsrt-3.4.0/src/twsrt/lib/copilot_sandbox.py +209 -0
  11. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/doctor.py +30 -8
  12. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/models.py +11 -2
  13. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/probe.py +50 -4
  14. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt.egg-info/PKG-INFO +100 -32
  15. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt.egg-info/SOURCES.txt +2 -0
  16. twsrt-3.3.2/src/twsrt/lib/copilot.py +0 -98
  17. {twsrt-3.3.2 → twsrt-3.4.0}/setup.cfg +0 -0
  18. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/__init__.py +0 -0
  19. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/bin/__init__.py +0 -0
  20. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/__init__.py +0 -0
  21. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/claude.py +0 -0
  22. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/composition.py +0 -0
  23. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/jsonc.py +0 -0
  24. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/profiles.py +0 -0
  25. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/sources.py +0 -0
  26. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt/lib/symlink.py +0 -0
  27. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt.egg-info/dependency_links.txt +0 -0
  28. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt.egg-info/entry_points.txt +0 -0
  29. {twsrt-3.3.2 → twsrt-3.4.0}/src/twsrt.egg-info/requires.txt +0 -0
  30. {twsrt-3.3.2 → twsrt-3.4.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.3.2
3
+ Version: 3.4.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
@@ -50,9 +50,9 @@ policy once and compiles it into every agent:
50
50
  │ twsrt generate -w
51
51
  ┌──────────────┬─────┴────────┬────────────────┐
52
52
  ▼ ▼ ▼ ▼
53
- ~/.srt-settings Claude Code Codex Copilot CLI
54
- (SRT sandbox) settings.json config.toml launch flags
55
- + .rules
53
+ ~/.srt-settings Claude Code Codex Copilot CLI + JetBrains
54
+ (SRT sandbox) settings.json config.toml settings.json, flags,
55
+ + .rules github-copilot.xml
56
56
  ```
57
57
 
58
58
  ## How it works
@@ -75,8 +75,9 @@ Three ideas explain the whole tool.
75
75
  ───────────────────────────────────────────────────────────────────────
76
76
  ┌──────────────────────────┼──────────────────────────┐
77
77
  ▼ ▼ ▼
78
- Claude generator Codex generator Copilot generator
79
- settings.full.json config.toml + .rules CLI flags
78
+ Claude generator Codex generator Copilot generators
79
+ settings.full.json config.toml + .rules settings.json + flags,
80
+ github-copilot.xml
80
81
 
81
82
  twsrt show prints stage 1 generate <agent> prints stage 2
82
83
  generate <agent> -w writes stage 1 (all of it) + stage 2 (that agent)
@@ -92,7 +93,7 @@ Three ideas explain the whole tool.
92
93
 
93
94
  | | Canonical config | Agent configs |
94
95
  |---|---|---|
95
- | Files | `~/.srt-settings.json`, `bash-rules.json` | Claude `settings.full.json`, Codex `config.toml` + `.rules`, Copilot flags |
96
+ | Files | `~/.srt-settings.json`, `bash-rules.json` | Claude `settings.full.json`, Codex `config.toml` + `.rules`, Copilot `settings.json` + flags, JetBrains `github-copilot.xml` |
96
97
  | Role | Source of truth; SRT enforcement file | Lossy translations into each agent's native model |
97
98
  | Depends on | Profile only | Canonical config + agent + `--yolo` |
98
99
  | Inspect | `twsrt show [srt\|bash]` | `twsrt generate <agent>` |
@@ -251,7 +252,11 @@ srt = ["work"]
251
252
  claude_settings = "~/.claude/settings.full.json" # must not be settings.json (symlink anchor)
252
253
  codex_config = "~/.codex/config.toml"
253
254
  codex_rules = "~/.codex/rules/twsrt.rules" # optional, needs codex_config: escalation rules
254
- copilot_output = "~/.config/twsrt/copilot-flags.txt"
255
+ copilot_settings = "~/.copilot/settings.json" # Copilot CLI native sandbox (ADR 0009)
256
+ copilot_output = "~/.config/twsrt/copilot-flags.txt" # optional, independent of copilot_settings
257
+ copilot_jetbrains_xml = [ # one file per JetBrains product and version
258
+ "~/Library/Application Support/JetBrains/IntelliJIdea2026.2/options/github-copilot.xml",
259
+ ]
255
260
  # claude_settings_yolo / copilot_output_yolo: optional, each needs its full-mode key;
256
261
  # default inserts ".yolo" before the suffix
257
262
 
@@ -366,8 +371,8 @@ srt-p() { local p=$1 d; shift; d=$(twsrt generate claude -w -p "$p" --project
366
371
  **What `--project` changes.** Only where outputs land: `./.twsrt/` of the
367
372
  current directory (`cd` first). No symlink flip, no `[claude_sync]` donor,
368
373
  no global file touched; the preview works as usual. `all` means
369
- `claude`; Codex and Copilot are rejected because they read no per-launch
370
- settings file. Omitting `-p` compiles `default_profile`, the full policy.
374
+ `claude`; Codex, Copilot and Copilot JetBrains are rejected because they read
375
+ no per-launch settings file. Omitting `-p` compiles `default_profile`, the full policy.
371
376
  `--project` also adds `./.twsrt` to the compiled `denyWrite`, because Claude
372
377
  reloads settings mid-session and an agent able to write them could loosen
373
378
  its own policy. `config.toml`, the fragments and the global outputs stay
@@ -380,17 +385,17 @@ Security properties and the residual gap:
380
385
 
381
386
  ## Agents
382
387
 
383
- | | Claude Code | Codex | Copilot CLI |
384
- |---|---|---|---|
385
- | twsrt writes | `~/.claude/settings.full.json` (+ symlink) | `~/.codex/config.toml` profile + `.rules` | flag snippet |
386
- | Kernel layer | native sandbox, opt-in | native sandbox, always on | none: run it under `srt` |
387
- | App layer | permission rules | escalation rules | CLI flags per launch |
388
- | Built-in tools | in-process, app rules only | sandboxed subprocesses | in-process, flags only |
389
- | `ask` tier | native | Codex default, not restated | absent: mapped to deny (warned) |
390
- | Full vs yolo output | differs | identical | differs |
391
- | Known trap | relative `sandbox.filesystem` paths anchor at the settings-file root, not the cwd | `sandbox_mode` in any layer disables the profile | ask → deny fidelity loss |
392
-
393
- Rule-by-rule translation for all three:
388
+ | | Claude Code | Codex | Copilot CLI | Copilot in JetBrains |
389
+ |---|---|---|---|---|
390
+ | twsrt writes | `~/.claude/settings.full.json` (+ symlink) | `~/.codex/config.toml` profile + `.rules` | `settings.json` `sandbox`/`allowedUrls`/`deniedUrls` + flag snippet | `github-copilot.xml` sandbox options, per IDE |
391
+ | Kernel layer | native sandbox, opt-in | native sandbox, always on | native sandbox (`copilot_settings`); flags-only mode: run it under `srt` | native sandbox |
392
+ | App layer | permission rules | escalation rules | CLI flags per launch, URL rules | — |
393
+ | Built-in tools | in-process, app rules only | sandboxed subprocesses | in-process, checked in software | in-process, checked in software |
394
+ | `ask` tier | native | Codex default, not restated | absent: mapped to deny (warned) | — |
395
+ | Full vs yolo output | differs | identical | `settings.json` identical, flags differ | identical |
396
+ | Known trap | relative `sandbox.filesystem` paths anchor at the settings-file root, not the cwd | `sandbox_mode` in any layer disables the profile | path globs are lost (warned) | a running IDE's file is skipped; new IDE versions need a new path |
397
+
398
+ Rule-by-rule translation:
394
399
  [Rule mapping per agent](doc/REFERENCE.md#rule-mapping-per-agent).
395
400
 
396
401
  ### Claude Code
@@ -434,6 +439,17 @@ Rule-by-rule translation for all three:
434
439
  `[claude_sync]`, every mode switch first copies those unmanaged keys from
435
440
  the current file into the target, so both converge.
436
441
  [Sync rules](doc/REFERENCE.md#claude-full-and-yolo-sync).
442
+ - **Adding your own settings.** Keys outside twsrt's sections (hooks,
443
+ plugins, `env`, `statusLine`, non-`WebFetch`/`Edit` allows, Claude-only
444
+ sandbox keys) survive every `-w`. Edit them in the file `settings.json`
445
+ links to, through the link itself: with `[claude_sync]` that file is the
446
+ donor on the next mode switch and overwrites the other mode's unmanaged
447
+ keys, so edits made only in the inactive file are lost. Without
448
+ `[claude_sync]`, add the key to both mode files. A key that should differ
449
+ per mode goes into `[claude_sync] mode_specific`. Keep `settings.json` a
450
+ symlink; a tool that replaces it with a regular file makes `-w` stop.
451
+ Anything in twsrt's sections belongs in the policy: hand edits there are
452
+ replaced. Preview the merged result with `twsrt generate claude` (no `-w`).
437
453
  - **Gotcha.** Relative entries in a hand-written `sandbox.filesystem`
438
454
  (e.g. a repo's `.claude/settings.json`) anchor at that file's root, not
439
455
  the launch cwd; `twsrt doctor` reports them as `claude-relative-sandbox-path`.
@@ -457,19 +473,71 @@ is preserved. Restart Codex after generation.
457
473
 
458
474
  ### Copilot CLI
459
475
 
460
- twsrt does not manage Copilot's `~/.copilot/settings.json`; it emits a flag
461
- snippet for the launch command (written to `copilot_output`; preview it with
462
- `twsrt generate copilot`). Nothing kernel-guards Copilot's
463
- tools, so run it under the SRT wrapper, which enforces the paths and domains:
476
+ Two modes, chosen by the `[targets]` keys
477
+ ([ADR 0009](doc/adr/0009-copilot-native-sandbox.md)):
478
+
479
+ | Mode | Keys | Paths and domains enforced by |
480
+ |---|---|---|
481
+ | **Native sandbox** (recommended) | `copilot_settings`, optionally `copilot_output` | Copilot's own sandbox, from `settings.json` |
482
+ | Flags only | `copilot_output` | the SRT wrapper (`srt -c "copilot …"`) |
483
+
484
+ Never combine the two: run Copilot either with its native sandbox or under
485
+ srt.
486
+
487
+ **Native sandbox.** twsrt merges three keys into `~/.copilot/settings.json`:
488
+ `sandbox` (paths, hosts, fixed hardening such as `enabled: true` and
489
+ `allowBypass: false`), `allowedUrls` and `deniedUrls`. Every other key
490
+ (model, theme, …) is kept. twsrt owns these three keys outright: a URL you
491
+ approve permanently inside Copilot shows up in `twsrt diff` and disappears on
492
+ the next `-w`, so add it to the policy instead. The same file serves full and
493
+ yolo mode. What does not translate is warned on every `generate`:
494
+
495
+ - Path wildcards: Copilot paths are literal. A glob below a fixed prefix
496
+ (`~/.rsenv/vaults/*/envs`) is expanded once at generate time; `/**/.env`,
497
+ `**/*.pem` and cwd-relative entries are dropped. Copilot itself keeps
498
+ `.git/hooks` and `.git/config` read-only.
499
+ - srt-only fields: `allowUnixSockets`, `allowMachLookup`,
500
+ `enableWeakerNetworkIsolation`, `ignoreViolations`. Copilot's own Seatbelt
501
+ profile decides; docker.sock, ssh-agent and the pasteboard were blocked in
502
+ probes.
503
+ - In-process tools: Copilot confines shell, MCP and LSP processes at OS
504
+ level; its file tools and web fetch are checked in software only. The
505
+ flag snippet's `--allow-tool 'read'`, `'edit'`, `'write'` therefore rely on
506
+ that software check.
507
+
508
+ **Flags only.** Without `copilot_settings`, twsrt does not touch
509
+ `settings.json` and the snippet also carries `--allow-url`/`--deny-url`. Run
510
+ Copilot under the SRT wrapper, which enforces the paths and domains:
464
511
 
465
512
  ```bash
466
513
  srt -c "copilot --allow-tool 'shell' --deny-tool 'shell(rm)' --allow-url 'github.com' ..."
467
514
  ```
468
515
 
469
- Ask rules become `--deny-tool` with a warning. With `--yolo` the snippet
470
- starts with `--yolo` and keeps only `--deny-tool` and `--deny-url`; deny
471
- flags still take precedence over `--yolo`.
472
- [Copilot flags](doc/REFERENCE.md#copilot-flags).
516
+ In the flags file, ask rules become `--deny-tool` with a warning. Bash
517
+ deny and ask rules exist only as `--deny-tool` flags, so with
518
+ `copilot_settings` alone (no `copilot_output`) they are not enforced for
519
+ Copilot CLI, and twsrt warns. With `--yolo`
520
+ the snippet starts with `--yolo` and keeps only `--deny-tool` (and
521
+ `--deny-url` in flags-only mode); deny flags still take precedence over
522
+ `--yolo`. [Copilot flags](doc/REFERENCE.md#copilot-flags),
523
+ [Copilot native sandbox](doc/REFERENCE.md#copilot-native-sandbox).
524
+
525
+ ### Copilot in JetBrains IDEs
526
+
527
+ The JetBrains plugin reads its own settings, not `~/.copilot/settings.json`.
528
+ List every IDE's file in `copilot_jetbrains_xml` (one per product and
529
+ version, e.g. IntelliJ IDEA, PyCharm, RustRover); agent name
530
+ `copilot-jetbrains`. twsrt replaces only the `sandbox*` options in component
531
+ `github-copilot` and keeps everything else (terminal rules, auth provider).
532
+
533
+ - **Close the IDE before `-w`.** A running IDE holds `<config>/.lock` and
534
+ overrides external edits; `-w` skips that file with a warning shown in red
535
+ (the IDE keeps its previous policy) and writes everything else; exit is 0.
536
+ `twsrt diff copilot-jetbrains` then shows it as drift.
537
+ - **New IDE version, new path.** After an IDE upgrade, add the new config
538
+ directory's file to `copilot_jetbrains_xml`; twsrt does not discover them.
539
+ - The plugin has no URL rules, no LSP/extension switch and no environment
540
+ masking; those parts of the policy do not reach the IDE (warned).
473
541
 
474
542
  **`--add-dir` is a trust grant.** Besides file access, Copilot loads the added
475
543
  directory's `.github/skills` and `.github/agents` as trusted configuration.
@@ -503,8 +571,8 @@ otherwise `default_profile` is compared and reports drift.
503
571
 
504
572
  **How `test` works.** Each effective SRT rule becomes a probe command
505
573
  (`head -c 1` on a denied file, an append-open that writes nothing on a
506
- write rule, `curl -I` per domain, plus a canary host outside the
507
- allowlist). Each probe runs twice: plainly as a control, then under
574
+ write rule, `curl -I` per domain, srt's proxy answer for a made-up
575
+ subdomain of each `*.` wildcard, plus a canary host outside the allowlist). Each probe runs twice: plainly as a control, then under
508
576
  `srt -s <settings> -c`. A deny rule passes when the control succeeds and the
509
577
  sandboxed run fails, so a missing file can never count as protected. The
510
578
  probe set is derived from the compiled file, never authored: change the
@@ -549,7 +617,7 @@ Threat model, rationale and every known gap:
549
617
  | `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 |
550
618
  | `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 |
551
619
  | `twsrt show [srt\|bash] [-p P]` | Print the compiled canonical document exactly as `-w` would write it. Writes nothing |
552
- | `twsrt generate [agent] [-p P]` | Preview: print the agent translation (`claude`, `codex`, `copilot`, default `all`) to stdout and list every file `-w` would write on stderr. Runs the same compile and merge checks as `-w`. Writes nothing |
620
+ | `twsrt generate [agent] [-p P]` | Preview: print the agent translation (`claude`, `codex`, `copilot`, `copilot-jetbrains`, default `all`) to stdout and list every file `-w` would write on stderr. Runs the same compile and merge checks as `-w`. Writes nothing |
553
621
  | `twsrt generate [agent] -w` | Write those files: the canonical outputs (always, whichever agent) and the agent targets |
554
622
  | `twsrt generate [agent] --yolo` | Yolo mode: no ask rules, `*.yolo.*` targets, yolo sandbox overrides |
555
623
  | `twsrt generate claude -w -p P --project` | Write profile `P` to `./.twsrt/`; nothing global is written |
@@ -36,9 +36,9 @@ policy once and compiles it into every agent:
36
36
  │ twsrt generate -w
37
37
  ┌──────────────┬─────┴────────┬────────────────┐
38
38
  ▼ ▼ ▼ ▼
39
- ~/.srt-settings Claude Code Codex Copilot CLI
40
- (SRT sandbox) settings.json config.toml launch flags
41
- + .rules
39
+ ~/.srt-settings Claude Code Codex Copilot CLI + JetBrains
40
+ (SRT sandbox) settings.json config.toml settings.json, flags,
41
+ + .rules github-copilot.xml
42
42
  ```
43
43
 
44
44
  ## How it works
@@ -61,8 +61,9 @@ Three ideas explain the whole tool.
61
61
  ───────────────────────────────────────────────────────────────────────
62
62
  ┌──────────────────────────┼──────────────────────────┐
63
63
  ▼ ▼ ▼
64
- Claude generator Codex generator Copilot generator
65
- settings.full.json config.toml + .rules CLI flags
64
+ Claude generator Codex generator Copilot generators
65
+ settings.full.json config.toml + .rules settings.json + flags,
66
+ github-copilot.xml
66
67
 
67
68
  twsrt show prints stage 1 generate <agent> prints stage 2
68
69
  generate <agent> -w writes stage 1 (all of it) + stage 2 (that agent)
@@ -78,7 +79,7 @@ Three ideas explain the whole tool.
78
79
 
79
80
  | | Canonical config | Agent configs |
80
81
  |---|---|---|
81
- | Files | `~/.srt-settings.json`, `bash-rules.json` | Claude `settings.full.json`, Codex `config.toml` + `.rules`, Copilot flags |
82
+ | Files | `~/.srt-settings.json`, `bash-rules.json` | Claude `settings.full.json`, Codex `config.toml` + `.rules`, Copilot `settings.json` + flags, JetBrains `github-copilot.xml` |
82
83
  | Role | Source of truth; SRT enforcement file | Lossy translations into each agent's native model |
83
84
  | Depends on | Profile only | Canonical config + agent + `--yolo` |
84
85
  | Inspect | `twsrt show [srt\|bash]` | `twsrt generate <agent>` |
@@ -237,7 +238,11 @@ srt = ["work"]
237
238
  claude_settings = "~/.claude/settings.full.json" # must not be settings.json (symlink anchor)
238
239
  codex_config = "~/.codex/config.toml"
239
240
  codex_rules = "~/.codex/rules/twsrt.rules" # optional, needs codex_config: escalation rules
240
- copilot_output = "~/.config/twsrt/copilot-flags.txt"
241
+ copilot_settings = "~/.copilot/settings.json" # Copilot CLI native sandbox (ADR 0009)
242
+ copilot_output = "~/.config/twsrt/copilot-flags.txt" # optional, independent of copilot_settings
243
+ copilot_jetbrains_xml = [ # one file per JetBrains product and version
244
+ "~/Library/Application Support/JetBrains/IntelliJIdea2026.2/options/github-copilot.xml",
245
+ ]
241
246
  # claude_settings_yolo / copilot_output_yolo: optional, each needs its full-mode key;
242
247
  # default inserts ".yolo" before the suffix
243
248
 
@@ -352,8 +357,8 @@ srt-p() { local p=$1 d; shift; d=$(twsrt generate claude -w -p "$p" --project
352
357
  **What `--project` changes.** Only where outputs land: `./.twsrt/` of the
353
358
  current directory (`cd` first). No symlink flip, no `[claude_sync]` donor,
354
359
  no global file touched; the preview works as usual. `all` means
355
- `claude`; Codex and Copilot are rejected because they read no per-launch
356
- settings file. Omitting `-p` compiles `default_profile`, the full policy.
360
+ `claude`; Codex, Copilot and Copilot JetBrains are rejected because they read
361
+ no per-launch settings file. Omitting `-p` compiles `default_profile`, the full policy.
357
362
  `--project` also adds `./.twsrt` to the compiled `denyWrite`, because Claude
358
363
  reloads settings mid-session and an agent able to write them could loosen
359
364
  its own policy. `config.toml`, the fragments and the global outputs stay
@@ -366,17 +371,17 @@ Security properties and the residual gap:
366
371
 
367
372
  ## Agents
368
373
 
369
- | | Claude Code | Codex | Copilot CLI |
370
- |---|---|---|---|
371
- | twsrt writes | `~/.claude/settings.full.json` (+ symlink) | `~/.codex/config.toml` profile + `.rules` | flag snippet |
372
- | Kernel layer | native sandbox, opt-in | native sandbox, always on | none: run it under `srt` |
373
- | App layer | permission rules | escalation rules | CLI flags per launch |
374
- | Built-in tools | in-process, app rules only | sandboxed subprocesses | in-process, flags only |
375
- | `ask` tier | native | Codex default, not restated | absent: mapped to deny (warned) |
376
- | Full vs yolo output | differs | identical | differs |
377
- | Known trap | relative `sandbox.filesystem` paths anchor at the settings-file root, not the cwd | `sandbox_mode` in any layer disables the profile | ask → deny fidelity loss |
378
-
379
- Rule-by-rule translation for all three:
374
+ | | Claude Code | Codex | Copilot CLI | Copilot in JetBrains |
375
+ |---|---|---|---|---|
376
+ | twsrt writes | `~/.claude/settings.full.json` (+ symlink) | `~/.codex/config.toml` profile + `.rules` | `settings.json` `sandbox`/`allowedUrls`/`deniedUrls` + flag snippet | `github-copilot.xml` sandbox options, per IDE |
377
+ | Kernel layer | native sandbox, opt-in | native sandbox, always on | native sandbox (`copilot_settings`); flags-only mode: run it under `srt` | native sandbox |
378
+ | App layer | permission rules | escalation rules | CLI flags per launch, URL rules | — |
379
+ | Built-in tools | in-process, app rules only | sandboxed subprocesses | in-process, checked in software | in-process, checked in software |
380
+ | `ask` tier | native | Codex default, not restated | absent: mapped to deny (warned) | — |
381
+ | Full vs yolo output | differs | identical | `settings.json` identical, flags differ | identical |
382
+ | Known trap | relative `sandbox.filesystem` paths anchor at the settings-file root, not the cwd | `sandbox_mode` in any layer disables the profile | path globs are lost (warned) | a running IDE's file is skipped; new IDE versions need a new path |
383
+
384
+ Rule-by-rule translation:
380
385
  [Rule mapping per agent](doc/REFERENCE.md#rule-mapping-per-agent).
381
386
 
382
387
  ### Claude Code
@@ -420,6 +425,17 @@ Rule-by-rule translation for all three:
420
425
  `[claude_sync]`, every mode switch first copies those unmanaged keys from
421
426
  the current file into the target, so both converge.
422
427
  [Sync rules](doc/REFERENCE.md#claude-full-and-yolo-sync).
428
+ - **Adding your own settings.** Keys outside twsrt's sections (hooks,
429
+ plugins, `env`, `statusLine`, non-`WebFetch`/`Edit` allows, Claude-only
430
+ sandbox keys) survive every `-w`. Edit them in the file `settings.json`
431
+ links to, through the link itself: with `[claude_sync]` that file is the
432
+ donor on the next mode switch and overwrites the other mode's unmanaged
433
+ keys, so edits made only in the inactive file are lost. Without
434
+ `[claude_sync]`, add the key to both mode files. A key that should differ
435
+ per mode goes into `[claude_sync] mode_specific`. Keep `settings.json` a
436
+ symlink; a tool that replaces it with a regular file makes `-w` stop.
437
+ Anything in twsrt's sections belongs in the policy: hand edits there are
438
+ replaced. Preview the merged result with `twsrt generate claude` (no `-w`).
423
439
  - **Gotcha.** Relative entries in a hand-written `sandbox.filesystem`
424
440
  (e.g. a repo's `.claude/settings.json`) anchor at that file's root, not
425
441
  the launch cwd; `twsrt doctor` reports them as `claude-relative-sandbox-path`.
@@ -443,19 +459,71 @@ is preserved. Restart Codex after generation.
443
459
 
444
460
  ### Copilot CLI
445
461
 
446
- twsrt does not manage Copilot's `~/.copilot/settings.json`; it emits a flag
447
- snippet for the launch command (written to `copilot_output`; preview it with
448
- `twsrt generate copilot`). Nothing kernel-guards Copilot's
449
- tools, so run it under the SRT wrapper, which enforces the paths and domains:
462
+ Two modes, chosen by the `[targets]` keys
463
+ ([ADR 0009](doc/adr/0009-copilot-native-sandbox.md)):
464
+
465
+ | Mode | Keys | Paths and domains enforced by |
466
+ |---|---|---|
467
+ | **Native sandbox** (recommended) | `copilot_settings`, optionally `copilot_output` | Copilot's own sandbox, from `settings.json` |
468
+ | Flags only | `copilot_output` | the SRT wrapper (`srt -c "copilot …"`) |
469
+
470
+ Never combine the two: run Copilot either with its native sandbox or under
471
+ srt.
472
+
473
+ **Native sandbox.** twsrt merges three keys into `~/.copilot/settings.json`:
474
+ `sandbox` (paths, hosts, fixed hardening such as `enabled: true` and
475
+ `allowBypass: false`), `allowedUrls` and `deniedUrls`. Every other key
476
+ (model, theme, …) is kept. twsrt owns these three keys outright: a URL you
477
+ approve permanently inside Copilot shows up in `twsrt diff` and disappears on
478
+ the next `-w`, so add it to the policy instead. The same file serves full and
479
+ yolo mode. What does not translate is warned on every `generate`:
480
+
481
+ - Path wildcards: Copilot paths are literal. A glob below a fixed prefix
482
+ (`~/.rsenv/vaults/*/envs`) is expanded once at generate time; `/**/.env`,
483
+ `**/*.pem` and cwd-relative entries are dropped. Copilot itself keeps
484
+ `.git/hooks` and `.git/config` read-only.
485
+ - srt-only fields: `allowUnixSockets`, `allowMachLookup`,
486
+ `enableWeakerNetworkIsolation`, `ignoreViolations`. Copilot's own Seatbelt
487
+ profile decides; docker.sock, ssh-agent and the pasteboard were blocked in
488
+ probes.
489
+ - In-process tools: Copilot confines shell, MCP and LSP processes at OS
490
+ level; its file tools and web fetch are checked in software only. The
491
+ flag snippet's `--allow-tool 'read'`, `'edit'`, `'write'` therefore rely on
492
+ that software check.
493
+
494
+ **Flags only.** Without `copilot_settings`, twsrt does not touch
495
+ `settings.json` and the snippet also carries `--allow-url`/`--deny-url`. Run
496
+ Copilot under the SRT wrapper, which enforces the paths and domains:
450
497
 
451
498
  ```bash
452
499
  srt -c "copilot --allow-tool 'shell' --deny-tool 'shell(rm)' --allow-url 'github.com' ..."
453
500
  ```
454
501
 
455
- Ask rules become `--deny-tool` with a warning. With `--yolo` the snippet
456
- starts with `--yolo` and keeps only `--deny-tool` and `--deny-url`; deny
457
- flags still take precedence over `--yolo`.
458
- [Copilot flags](doc/REFERENCE.md#copilot-flags).
502
+ In the flags file, ask rules become `--deny-tool` with a warning. Bash
503
+ deny and ask rules exist only as `--deny-tool` flags, so with
504
+ `copilot_settings` alone (no `copilot_output`) they are not enforced for
505
+ Copilot CLI, and twsrt warns. With `--yolo`
506
+ the snippet starts with `--yolo` and keeps only `--deny-tool` (and
507
+ `--deny-url` in flags-only mode); deny flags still take precedence over
508
+ `--yolo`. [Copilot flags](doc/REFERENCE.md#copilot-flags),
509
+ [Copilot native sandbox](doc/REFERENCE.md#copilot-native-sandbox).
510
+
511
+ ### Copilot in JetBrains IDEs
512
+
513
+ The JetBrains plugin reads its own settings, not `~/.copilot/settings.json`.
514
+ List every IDE's file in `copilot_jetbrains_xml` (one per product and
515
+ version, e.g. IntelliJ IDEA, PyCharm, RustRover); agent name
516
+ `copilot-jetbrains`. twsrt replaces only the `sandbox*` options in component
517
+ `github-copilot` and keeps everything else (terminal rules, auth provider).
518
+
519
+ - **Close the IDE before `-w`.** A running IDE holds `<config>/.lock` and
520
+ overrides external edits; `-w` skips that file with a warning shown in red
521
+ (the IDE keeps its previous policy) and writes everything else; exit is 0.
522
+ `twsrt diff copilot-jetbrains` then shows it as drift.
523
+ - **New IDE version, new path.** After an IDE upgrade, add the new config
524
+ directory's file to `copilot_jetbrains_xml`; twsrt does not discover them.
525
+ - The plugin has no URL rules, no LSP/extension switch and no environment
526
+ masking; those parts of the policy do not reach the IDE (warned).
459
527
 
460
528
  **`--add-dir` is a trust grant.** Besides file access, Copilot loads the added
461
529
  directory's `.github/skills` and `.github/agents` as trusted configuration.
@@ -489,8 +557,8 @@ otherwise `default_profile` is compared and reports drift.
489
557
 
490
558
  **How `test` works.** Each effective SRT rule becomes a probe command
491
559
  (`head -c 1` on a denied file, an append-open that writes nothing on a
492
- write rule, `curl -I` per domain, plus a canary host outside the
493
- allowlist). Each probe runs twice: plainly as a control, then under
560
+ write rule, `curl -I` per domain, srt's proxy answer for a made-up
561
+ subdomain of each `*.` wildcard, plus a canary host outside the allowlist). Each probe runs twice: plainly as a control, then under
494
562
  `srt -s <settings> -c`. A deny rule passes when the control succeeds and the
495
563
  sandboxed run fails, so a missing file can never count as protected. The
496
564
  probe set is derived from the compiled file, never authored: change the
@@ -535,7 +603,7 @@ Threat model, rationale and every known gap:
535
603
  | `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 |
536
604
  | `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 |
537
605
  | `twsrt show [srt\|bash] [-p P]` | Print the compiled canonical document exactly as `-w` would write it. Writes nothing |
538
- | `twsrt generate [agent] [-p P]` | Preview: print the agent translation (`claude`, `codex`, `copilot`, default `all`) to stdout and list every file `-w` would write on stderr. Runs the same compile and merge checks as `-w`. Writes nothing |
606
+ | `twsrt generate [agent] [-p P]` | Preview: print the agent translation (`claude`, `codex`, `copilot`, `copilot-jetbrains`, default `all`) to stdout and list every file `-w` would write on stderr. Runs the same compile and merge checks as `-w`. Writes nothing |
539
607
  | `twsrt generate [agent] -w` | Write those files: the canonical outputs (always, whichever agent) and the agent targets |
540
608
  | `twsrt generate [agent] --yolo` | Yolo mode: no ask rules, `*.yolo.*` targets, yolo sandbox overrides |
541
609
  | `twsrt generate claude -w -p P --project` | Write profile `P` to `./.twsrt/`; nothing global is written |
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twsrt"
3
- version = "3.3.2"
3
+ version = "3.4.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.3.2"
48
+ current_version = "3.4.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.3.2"
24
+ __version__ = "3.4.0"
25
25
 
26
26
  app = typer.Typer(
27
27
  name="twsrt",
@@ -41,8 +41,11 @@ def _error(message: str) -> None:
41
41
  typer.secho(f"Error: {message}", fg=typer.colors.RED, bold=True, err=True)
42
42
 
43
43
 
44
- def _warning(message: str) -> None:
45
- typer.secho(f"Warning: {message}", fg=typer.colors.YELLOW, err=True)
44
+ def _warning(message: str, urgent: bool = False) -> None:
45
+ """urgent: still a Warning (exit 0), but red, for a target left on an old
46
+ policy; red alone does not mean failure, the "Error:" label does."""
47
+ color = typer.colors.RED if urgent else typer.colors.YELLOW
48
+ typer.secho(f"Warning: {message}", fg=color, bold=urgent, err=True)
46
49
 
47
50
 
48
51
  def _info(message: str) -> None:
@@ -240,9 +243,20 @@ srt = ["base"]
240
243
  # anchor, pointed at the full or yolo file by `generate -w claude`.
241
244
  # claude_settings = "~/.claude/settings.full.json"
242
245
 
243
- # GitHub Copilot CLI flags file.
246
+ # GitHub Copilot CLI native sandbox (ADR 0009): twsrt owns the keys sandbox,
247
+ # allowedUrls and deniedUrls in this file and always writes enabled = true.
248
+ # copilot_settings = "~/.copilot/settings.json"
249
+
250
+ # GitHub Copilot CLI flags file. Independent of copilot_settings; without
251
+ # copilot_settings it also carries --allow-url/--deny-url (SRT-wrapper mode).
244
252
  # copilot_output = "copilot-flags.txt"
245
253
 
254
+ # Copilot in JetBrains IDEs: one github-copilot.xml per product and version.
255
+ # Add new IDE versions by hand. Files of a running IDE are skipped by -w.
256
+ # copilot_jetbrains_xml = [
257
+ # "~/Library/Application Support/JetBrains/IntelliJIdea2026.2/options/github-copilot.xml",
258
+ # ]
259
+
246
260
  # Codex user config; twsrt merges only its own permission profile into it.
247
261
  # codex_config = "~/.codex/config.toml"
248
262
 
@@ -677,7 +691,8 @@ def generate(
677
691
  ctx: typer.Context,
678
692
  agent: str = typer.Argument(
679
693
  "all",
680
- help="claude, copilot, codex, or all (every agent set in \\[targets])",
694
+ help="claude, copilot, codex, copilot-jetbrains, or all "
695
+ "(every agent set in \\[targets])",
681
696
  ),
682
697
  write: bool = typer.Option(
683
698
  False,
@@ -779,6 +794,16 @@ def generate(
779
794
  typer.echo(str(twsrt_dir))
780
795
  return
781
796
 
797
+ locked = _locked_jetbrains_files(staged, config)
798
+ for path in locked:
799
+ _warning(
800
+ f"JetBrains IDE is running (lock found), so -w will skip {path}; "
801
+ "close the IDE and re-run generate -w (a stale lock left by a "
802
+ f"crashed IDE must be removed: {path.parent.parent / '.lock'})",
803
+ urgent=True,
804
+ )
805
+ del staged[path]
806
+
782
807
  if write:
783
808
  for document in compiled.documents.values():
784
809
  _atomic_write(document.output_path, _serialize(document.document))
@@ -844,7 +869,7 @@ def show(
844
869
  def diff(
845
870
  ctx: typer.Context,
846
871
  agent: str = typer.Argument(
847
- "all", help="Target agent: claude, copilot, codex, or all"
872
+ "all", help="Target agent: claude, copilot, codex, copilot-jetbrains, or all"
848
873
  ),
849
874
  yolo: bool = typer.Option(False, "--yolo", help="Diff yolo agent targets"),
850
875
  profile: str | None = typer.Option(
@@ -875,7 +900,8 @@ def diff(
875
900
 
876
901
  for generator in generators:
877
902
  target = _resolve_target(generator.name, config)
878
- if not target.exists():
903
+ # copilot-jetbrains reports each missing file as drift (FR-030).
904
+ if generator.name != "copilot-jetbrains" and not target.exists():
879
905
  _error(f"Target file not found for {generator.name}: {target}")
880
906
  raise typer.Exit(2)
881
907
  if (
@@ -1282,7 +1308,9 @@ def _compile(
1282
1308
  srt = compiled.srt_result
1283
1309
  config.network_config = srt.network_config
1284
1310
  config.filesystem_config = srt.filesystem_config
1285
- config.sandbox_config = srt.sandbox_config
1311
+ config.srt_sandbox_config = dict(srt.sandbox_config)
1312
+ # A copy: apply_sandbox_overrides updates sandbox_config in place.
1313
+ config.sandbox_config = dict(srt.sandbox_config)
1286
1314
  config.srt_sandbox_enabled = srt.sandbox_config.get("enabled")
1287
1315
  config.yolo = yolo
1288
1316
  config.apply_sandbox_overrides()
@@ -1307,7 +1335,8 @@ def _select_generators(agent: str, config: AppConfig) -> list:
1307
1335
  _note(
1308
1336
  "no agent targets set in [targets] of config.toml, so only the "
1309
1337
  "canonical outputs are handled. To add an agent, set "
1310
- "claude_settings, copilot_output or codex_config."
1338
+ "claude_settings, copilot_settings, copilot_output, codex_config or "
1339
+ "copilot_jetbrains_xml."
1311
1340
  )
1312
1341
  return []
1313
1342
  for name in requested:
@@ -1334,6 +1363,8 @@ def _stage_agent_files(
1334
1363
  ) -> dict[Path, str]:
1335
1364
  from twsrt.lib.claude import selective_merge
1336
1365
  from twsrt.lib.codex import CodexGenerator
1366
+ from twsrt.lib.copilot import CopilotGenerator
1367
+ from twsrt.lib.copilot_jetbrains import CopilotJetbrainsGenerator
1337
1368
 
1338
1369
  staged: dict[Path, str] = {}
1339
1370
  for generator in generators:
@@ -1365,17 +1396,34 @@ def _stage_agent_files(
1365
1396
  document = generated
1366
1397
  staged[target] = json.dumps(document, indent=2) + "\n"
1367
1398
  elif generator.name == "copilot":
1368
- target = _resolve_target("copilot", config)
1369
- staged[target] = rendered[generator.name] + "\n"
1399
+ assert isinstance(generator, CopilotGenerator)
1400
+ if config.copilot_output_path is not None:
1401
+ target = _resolve_target("copilot", config)
1402
+ staged[target] = generator.generate_flags(compiled.rules, config) + "\n"
1403
+ staged.update(generator.render_settings(compiled.rules, config))
1370
1404
  elif generator.name == "codex":
1371
1405
  assert isinstance(generator, CodexGenerator)
1372
1406
  staged.update(generator.render_write_files(compiled.rules, config))
1407
+ elif generator.name == "copilot-jetbrains":
1408
+ assert isinstance(generator, CopilotJetbrainsGenerator)
1409
+ staged.update(generator.render_write_files(compiled.rules, config))
1373
1410
  return staged
1374
1411
 
1375
1412
 
1413
+ def _locked_jetbrains_files(staged: dict[Path, str], config: AppConfig) -> list[Path]:
1414
+ """Staged JetBrains XML files whose IDE is running (ADR 0009 decision 5)."""
1415
+ from twsrt.lib.copilot_jetbrains import locked
1416
+
1417
+ return [
1418
+ path
1419
+ for path in config.copilot_jetbrains_xml_paths
1420
+ if path in staged and locked(path)
1421
+ ]
1422
+
1423
+
1376
1424
  def _project_agent(agent: str) -> str:
1377
1425
  """Project mode serves agents that take a settings file per launch."""
1378
- if agent in ("codex", "copilot"):
1426
+ if agent in ("codex", "copilot", "copilot-jetbrains"):
1379
1427
  raise ValueError(
1380
1428
  f"agent {agent!r} is not supported with --project: only Claude "
1381
1429
  "(--settings) and srt (-s) read a per-launch settings file"
@@ -1450,22 +1498,30 @@ def _write_agent_files(staged: dict[Path, str], config: AppConfig) -> None:
1450
1498
  def _print_generator_warnings(
1451
1499
  generators: list, compiled: CompilationResult, config: AppConfig
1452
1500
  ) -> None:
1501
+ # Both Copilot generators share build_policy, hence its warnings: print once.
1502
+ seen: set[str] = set()
1453
1503
  for generator in generators:
1454
1504
  warnings = generator.compatibility_warnings(compiled.rules, config)
1455
1505
  log.debug(
1456
1506
  "Compatibility warnings agent=%s count=%d", generator.name, len(warnings)
1457
1507
  )
1458
1508
  for warning in warnings:
1459
- _warning(warning)
1509
+ if warning not in seen:
1510
+ seen.add(warning)
1511
+ _warning(warning)
1460
1512
 
1461
1513
 
1462
1514
  def _resolve_target(agent: str, config: AppConfig) -> Path:
1463
1515
  """The agent's target for the current mode.
1464
1516
 
1465
- Codex has a single target: its permission profile serves both modes.
1517
+ Codex has a single target: its permission profile serves both modes. So do
1518
+ Copilot's settings.json and the JetBrains XML files (ADR 0009); only the
1519
+ Copilot flags file has a yolo variant.
1466
1520
  """
1467
1521
  full = config.require_target(agent)
1468
- if not config.yolo or agent == "codex":
1522
+ if not config.yolo or agent in ("codex", "copilot-jetbrains"):
1523
+ return full
1524
+ if agent == "copilot" and config.copilot_output_path is None:
1469
1525
  return full
1470
1526
  explicit = (
1471
1527
  config.claude_yolo_path if agent == "claude" else config.copilot_yolo_path
@@ -32,11 +32,13 @@ def _build_registry() -> dict[str, AgentGenerator]:
32
32
  from twsrt.lib.claude import ClaudeGenerator
33
33
  from twsrt.lib.codex import CodexGenerator
34
34
  from twsrt.lib.copilot import CopilotGenerator
35
+ from twsrt.lib.copilot_jetbrains import CopilotJetbrainsGenerator
35
36
 
36
37
  return {
37
38
  "claude": ClaudeGenerator(),
38
39
  "copilot": CopilotGenerator(),
39
40
  "codex": CodexGenerator(),
41
+ "copilot-jetbrains": CopilotJetbrainsGenerator(),
40
42
  }
41
43
 
42
44