scriptvault 0.3.0__tar.gz → 0.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 (29) hide show
  1. {scriptvault-0.3.0/src/scriptvault.egg-info → scriptvault-0.4.0}/PKG-INFO +79 -4
  2. {scriptvault-0.3.0 → scriptvault-0.4.0}/README.md +78 -3
  3. {scriptvault-0.3.0 → scriptvault-0.4.0}/pyproject.toml +1 -1
  4. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault/__init__.py +2 -2
  5. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault/cli.py +91 -44
  6. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault/run.py +16 -8
  7. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault/templates.py +93 -6
  8. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault/term.py +1 -1
  9. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault/vault.py +129 -70
  10. {scriptvault-0.3.0 → scriptvault-0.4.0/src/scriptvault.egg-info}/PKG-INFO +79 -4
  11. {scriptvault-0.3.0 → scriptvault-0.4.0}/tests/test_add.py +74 -0
  12. {scriptvault-0.3.0 → scriptvault-0.4.0}/tests/test_completion.py +20 -0
  13. {scriptvault-0.3.0 → scriptvault-0.4.0}/tests/test_guide.py +3 -0
  14. {scriptvault-0.3.0 → scriptvault-0.4.0}/tests/test_init.py +96 -0
  15. scriptvault-0.4.0/tests/test_list.py +386 -0
  16. {scriptvault-0.3.0 → scriptvault-0.4.0}/tests/test_run.py +237 -3
  17. scriptvault-0.3.0/tests/test_list.py +0 -118
  18. {scriptvault-0.3.0 → scriptvault-0.4.0}/LICENSE +0 -0
  19. {scriptvault-0.3.0 → scriptvault-0.4.0}/setup.cfg +0 -0
  20. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault/__main__.py +0 -0
  21. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault/envfile.py +0 -0
  22. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault.egg-info/SOURCES.txt +0 -0
  23. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault.egg-info/dependency_links.txt +0 -0
  24. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault.egg-info/entry_points.txt +0 -0
  25. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault.egg-info/requires.txt +0 -0
  26. {scriptvault-0.3.0 → scriptvault-0.4.0}/src/scriptvault.egg-info/top_level.txt +0 -0
  27. {scriptvault-0.3.0 → scriptvault-0.4.0}/tests/test_edit.py +0 -0
  28. {scriptvault-0.3.0 → scriptvault-0.4.0}/tests/test_hooks.py +0 -0
  29. {scriptvault-0.3.0 → scriptvault-0.4.0}/tests/test_real.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptvault
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Store and run project commands in a hidden vault directory
5
5
  Author: Majwt
6
6
  License-Expression: MIT
@@ -41,6 +41,10 @@ From a checkout:
41
41
  pipx install --editable .
42
42
  ```
43
43
 
44
+ For maintainers, `sv set-version 0.4.0` sets the version in `pyproject.toml`
45
+ and `src/scriptvault/__init__.py`. It uses the project environment created by
46
+ `sv build` and rejects invalid versions before changing either file.
47
+
44
48
  ## Quick start
45
49
 
46
50
  Initialize a vault in a project directory:
@@ -119,7 +123,15 @@ sv run c-hello build
119
123
  sv c-hello build
120
124
  ```
121
125
 
122
- Implied run (`sv deploy`) only works for root vault scripts.
126
+ or with the qualified `include:target` form, which names one include
127
+ explicitly (useful when two includes define the same target):
128
+
129
+ ```bash
130
+ sv run c-hello:build
131
+ sv c-hello:build
132
+ ```
133
+
134
+ Implied run (`sv deploy`) works for plain and qualified target names.
123
135
 
124
136
  ## Scripts
125
137
 
@@ -132,6 +144,23 @@ A file at `.sv/scripts/hello.sh` becomes `sv hello`.
132
144
  echo "Hello from $SV_NAME"
133
145
  ```
134
146
 
147
+ File-script metadata can be defined without `cmd`:
148
+
149
+ ```toml
150
+ [scripts.hello]
151
+ description = "Print a greeting"
152
+ ```
153
+
154
+ This requires a same-name script file in `.sv/scripts/`, such as `hello` or
155
+ `hello.sh`, with a shebang. Without a matching file, `cmd` is required.
156
+
157
+ Scripts and orchestrations accept either `desc` or `description`. If both are
158
+ set, `description` takes precedence. Descriptions are shown beside names in
159
+ `sv list`.
160
+
161
+ Listings use colors on supported terminals. Piped output, JSON, `TERM=dumb`,
162
+ and environments with `NO_COLOR` set remain plain.
163
+
135
164
  ### Inline scripts
136
165
 
137
166
  Define a command in `vault.toml`:
@@ -148,6 +177,49 @@ sv add hello
148
177
  sv add hello --in < script.sh
149
178
  ```
150
179
 
180
+ ### Local And Hidden Scripts
181
+
182
+ ```sh
183
+ sv add personal --local
184
+ sv add personal --local --in < script.sh
185
+ sv run personal
186
+ sv list --all
187
+ ```
188
+
189
+ Local scripts live in `.sv/local/scripts/`. `sv init` and `sv add --local`
190
+ ensure `.sv/.gitignore` ignores `/local/`, preserving existing ignore rules.
191
+ Local scripts are hidden from `sv list` by default but remain callable by
192
+ name, including from orchestration steps. Local and shared names must not
193
+ conflict. Gitignore rules do not untrack files already committed.
194
+
195
+ Shared helpers can also be hidden:
196
+
197
+ ```toml
198
+ [scripts.helper]
199
+ hidden = true
200
+ cmd = "echo helper"
201
+ ```
202
+
203
+ `hidden = true` also works for file-script metadata and orchestrations.
204
+ `sv list --all` reveals hidden targets, including with `--json` or `--nested`.
205
+ Hiding is a listing preference, not access control or secret protection.
206
+
207
+ ### Source-Only Helpers
208
+
209
+ Put reusable shell helpers in `.sv/lib/`, outside the runnable script directory:
210
+
211
+ ```bash
212
+ source "$SV_LIB/helper.sh"
213
+ source "$SV_TOP_LIB/git-version.sh"
214
+ ```
215
+
216
+ `SV_LIB` points to the owning vault's library directory. `SV_TOP_LIB` points
217
+ to the outermost vault's library directory in the current execution chain.
218
+ If a nested vault is invoked on its own, both point to that nested vault's
219
+ library. These paths are injected even when the directories do not yet exist.
220
+ Helpers are not runnable targets and never appear in `sv list`, even with
221
+ `--all`. Sourcing keeps their functions and variables in the calling shell.
222
+
151
223
  ## Running targets
152
224
 
153
225
  ```sh
@@ -208,8 +280,11 @@ Precedence, from lowest to highest:
208
280
 
209
281
  Injected variables:
210
282
 
211
- - `SV_ROOT`: project root
212
- - `SV_DIR`: `.sv` directory
283
+ - `SV_TOP_ROOT`: outermost vault's root directory in the execution chain
284
+ - `SV_TOP_LIB`: that outermost vault's `.sv/lib` directory
285
+ - `SV_ROOT`: root directory of the vault owning the current script or orchestration
286
+ - `SV_DIR`: that owning vault's `.sv` directory
287
+ - `SV_LIB`: that owning vault's `.sv/lib` directory
213
288
  - `SV_CWD`: current working directory at invocation
214
289
  - `SV_NAME`: target name, when running a named script
215
290
 
@@ -20,6 +20,10 @@ From a checkout:
20
20
  pipx install --editable .
21
21
  ```
22
22
 
23
+ For maintainers, `sv set-version 0.4.0` sets the version in `pyproject.toml`
24
+ and `src/scriptvault/__init__.py`. It uses the project environment created by
25
+ `sv build` and rejects invalid versions before changing either file.
26
+
23
27
  ## Quick start
24
28
 
25
29
  Initialize a vault in a project directory:
@@ -98,7 +102,15 @@ sv run c-hello build
98
102
  sv c-hello build
99
103
  ```
100
104
 
101
- Implied run (`sv deploy`) only works for root vault scripts.
105
+ or with the qualified `include:target` form, which names one include
106
+ explicitly (useful when two includes define the same target):
107
+
108
+ ```bash
109
+ sv run c-hello:build
110
+ sv c-hello:build
111
+ ```
112
+
113
+ Implied run (`sv deploy`) works for plain and qualified target names.
102
114
 
103
115
  ## Scripts
104
116
 
@@ -111,6 +123,23 @@ A file at `.sv/scripts/hello.sh` becomes `sv hello`.
111
123
  echo "Hello from $SV_NAME"
112
124
  ```
113
125
 
126
+ File-script metadata can be defined without `cmd`:
127
+
128
+ ```toml
129
+ [scripts.hello]
130
+ description = "Print a greeting"
131
+ ```
132
+
133
+ This requires a same-name script file in `.sv/scripts/`, such as `hello` or
134
+ `hello.sh`, with a shebang. Without a matching file, `cmd` is required.
135
+
136
+ Scripts and orchestrations accept either `desc` or `description`. If both are
137
+ set, `description` takes precedence. Descriptions are shown beside names in
138
+ `sv list`.
139
+
140
+ Listings use colors on supported terminals. Piped output, JSON, `TERM=dumb`,
141
+ and environments with `NO_COLOR` set remain plain.
142
+
114
143
  ### Inline scripts
115
144
 
116
145
  Define a command in `vault.toml`:
@@ -127,6 +156,49 @@ sv add hello
127
156
  sv add hello --in < script.sh
128
157
  ```
129
158
 
159
+ ### Local And Hidden Scripts
160
+
161
+ ```sh
162
+ sv add personal --local
163
+ sv add personal --local --in < script.sh
164
+ sv run personal
165
+ sv list --all
166
+ ```
167
+
168
+ Local scripts live in `.sv/local/scripts/`. `sv init` and `sv add --local`
169
+ ensure `.sv/.gitignore` ignores `/local/`, preserving existing ignore rules.
170
+ Local scripts are hidden from `sv list` by default but remain callable by
171
+ name, including from orchestration steps. Local and shared names must not
172
+ conflict. Gitignore rules do not untrack files already committed.
173
+
174
+ Shared helpers can also be hidden:
175
+
176
+ ```toml
177
+ [scripts.helper]
178
+ hidden = true
179
+ cmd = "echo helper"
180
+ ```
181
+
182
+ `hidden = true` also works for file-script metadata and orchestrations.
183
+ `sv list --all` reveals hidden targets, including with `--json` or `--nested`.
184
+ Hiding is a listing preference, not access control or secret protection.
185
+
186
+ ### Source-Only Helpers
187
+
188
+ Put reusable shell helpers in `.sv/lib/`, outside the runnable script directory:
189
+
190
+ ```bash
191
+ source "$SV_LIB/helper.sh"
192
+ source "$SV_TOP_LIB/git-version.sh"
193
+ ```
194
+
195
+ `SV_LIB` points to the owning vault's library directory. `SV_TOP_LIB` points
196
+ to the outermost vault's library directory in the current execution chain.
197
+ If a nested vault is invoked on its own, both point to that nested vault's
198
+ library. These paths are injected even when the directories do not yet exist.
199
+ Helpers are not runnable targets and never appear in `sv list`, even with
200
+ `--all`. Sourcing keeps their functions and variables in the calling shell.
201
+
130
202
  ## Running targets
131
203
 
132
204
  ```sh
@@ -187,8 +259,11 @@ Precedence, from lowest to highest:
187
259
 
188
260
  Injected variables:
189
261
 
190
- - `SV_ROOT`: project root
191
- - `SV_DIR`: `.sv` directory
262
+ - `SV_TOP_ROOT`: outermost vault's root directory in the execution chain
263
+ - `SV_TOP_LIB`: that outermost vault's `.sv/lib` directory
264
+ - `SV_ROOT`: root directory of the vault owning the current script or orchestration
265
+ - `SV_DIR`: that owning vault's `.sv` directory
266
+ - `SV_LIB`: that owning vault's `.sv/lib` directory
192
267
  - `SV_CWD`: current working directory at invocation
193
268
  - `SV_NAME`: target name, when running a named script
194
269
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "scriptvault"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  description = "Store and run project commands in a hidden vault directory"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -3,6 +3,6 @@
3
3
  from importlib.metadata import PackageNotFoundError
4
4
 
5
5
  try:
6
- __version__ = "0.3.0"
6
+ __version__ = "0.4.0"
7
7
  except PackageNotFoundError:
8
- __version__ = "0.3.0"
8
+ __version__ = "0.4.0"
@@ -13,6 +13,7 @@ from pathlib import Path
13
13
 
14
14
  from . import __version__, templates
15
15
  from .run import run_target
16
+ from .term import CYAN, GREEN, MAGENTA, Palette
16
17
  from .vault import (
17
18
  Vault,
18
19
  NAME_RE,
@@ -23,6 +24,7 @@ from .vault import (
23
24
  find_root,
24
25
  hidden_dir_name,
25
26
  load_vault,
27
+ split_qualified,
26
28
  )
27
29
 
28
30
  COMMANDS = (
@@ -56,6 +58,14 @@ def _toml_str(value: str) -> str:
56
58
  return json.dumps(value)[1:-1]
57
59
 
58
60
 
61
+ def _ignore_local_scripts(hidden: Path) -> None:
62
+ path = hidden / ".gitignore"
63
+ content = path.read_text(encoding="utf-8") if path.exists() else ""
64
+ if "/local/" not in content.splitlines():
65
+ separator = "\n" if content and not content.endswith("\n") else ""
66
+ path.write_text(content + separator + "/local/\n", encoding="utf-8")
67
+
68
+
59
69
  def cmd_init(args: argparse.Namespace) -> int:
60
70
  """Initialize a vault in a project directory."""
61
71
  path = Path(args.path)
@@ -75,6 +85,7 @@ def cmd_init(args: argparse.Namespace) -> int:
75
85
  raise CLIError("cannot derive a vault name from path; pass --name")
76
86
 
77
87
  (hidden / "scripts").mkdir(parents=True, exist_ok=True)
88
+ _ignore_local_scripts(hidden)
78
89
  vault_toml.write_text(
79
90
  templates.VAULT_TOML.format(name=_toml_str(name)), encoding="utf-8"
80
91
  )
@@ -393,16 +404,20 @@ def _load_vault(path: str | None = None):
393
404
  def cmd_list(args: argparse.Namespace) -> int:
394
405
  """List scripts and orchestrations in the vault."""
395
406
  vault = _load_vault(args.path)
407
+ show_hidden = getattr(args, "all", False)
396
408
 
397
409
  if args.json:
398
410
  json.dump(
399
411
  {
400
412
  "vault": vault.name,
401
- "scripts": [_target_json(target) for target in vault.targets.values()],
413
+ "scripts": [_target_json(target) for target in vault.targets.values() if show_hidden or not target.hidden],
402
414
  "includes": {
403
415
  name: {
404
416
  "path": str(vault._nested_vaults[name].root),
405
- "scripts": list(vault._nested_vaults[name].scripts.keys()),
417
+ "scripts": [
418
+ script.name for script in vault._nested_vaults[name].scripts.values()
419
+ if show_hidden or not script.hidden
420
+ ],
406
421
  }
407
422
  for name in vault._nested_vaults
408
423
  },
@@ -413,35 +428,52 @@ def cmd_list(args: argparse.Namespace) -> int:
413
428
  sys.stdout.write("\n")
414
429
  return 0
415
430
 
416
- # Show nested structure
417
- print(f"Root vault: {vault.name}")
418
-
419
- # Root targets only (exclude nested vault names)
420
- root_scripts = [name for name in vault.scripts.keys() if name not in vault._nested_vaults]
421
- if root_scripts:
422
- print(f" Scripts: {', '.join(root_scripts)}")
423
- root_orchestrations = [
424
- name for name in vault.orchestrations if name not in vault._nested_vaults
425
- ]
426
- if root_orchestrations:
427
- print(f" Orchestrations: {', '.join(root_orchestrations)}")
431
+ palette = Palette(sys.stdout)
432
+ print(palette.paint(f"Root vault: {vault.name}", bold=True, fg=CYAN))
433
+
434
+ for label, targets in (("Scripts", vault.scripts), ("Orchestrations", vault.orchestrations)):
435
+ names = [
436
+ name for name, target in targets.items()
437
+ if name not in vault._nested_vaults and (show_hidden or not target.hidden)
438
+ ]
439
+ if names:
440
+ print(palette.paint(f" {label}:", bold=True))
441
+ width = max(len(name) for name in names)
442
+ for name in names:
443
+ description = targets[name].description
444
+ color = MAGENTA if isinstance(targets[name], Orchestration) else GREEN
445
+ title = palette.paint(name, fg=color)
446
+ suffix = " " * (width - len(name) + 2) + palette.paint(description, dim=True) if description else ""
447
+ print(f" {title}{suffix}")
428
448
 
429
449
  if vault._nested_vaults:
430
- print("\nIncluded vaults:")
450
+ print("\n" + palette.paint("Included vaults:", bold=True, fg=CYAN))
431
451
  for include_name, nested_vault in vault._nested_vaults.items():
432
452
  names = [
433
453
  name
434
454
  for name in list(nested_vault.scripts) + list(nested_vault.orchestrations)
435
- if name not in vault._nested_vaults
455
+ if name not in vault._nested_vaults and (show_hidden or not nested_vault.get(name).hidden)
436
456
  ]
437
457
  if names:
438
- print(f" {include_name}: {', '.join(names)}")
458
+ print(palette.paint(f" {include_name}:", bold=True, fg=CYAN))
459
+ width = max(len(name) for name in names)
460
+ for name in names:
461
+ target = nested_vault.get(name)
462
+ description = target.description
463
+ color = MAGENTA if isinstance(target, Orchestration) else GREEN
464
+ title = palette.paint(name, fg=color)
465
+ suffix = " " * (width - len(name) + 2) + palette.paint(description, dim=True) if description else ""
466
+ print(f" {title}{suffix}")
439
467
 
440
468
  # If --nested flag is set, show more details
441
469
  if args.nested:
442
- print("\nAll targets (including nested):")
470
+ print("\n" + palette.paint("All targets (including nested):", bold=True, fg=CYAN))
443
471
  for name, target in vault.targets.items():
444
- print(f" {name}: {target.description}")
472
+ if target.hidden and not show_hidden:
473
+ continue
474
+ color = MAGENTA if isinstance(target, Orchestration) else GREEN
475
+ title = palette.paint(name, fg=color)
476
+ print(f" {title}: {palette.paint(target.description, dim=True)}")
445
477
 
446
478
  return 0
447
479
 
@@ -521,9 +553,21 @@ def cmd_run(args: argparse.Namespace) -> int:
521
553
  source_vault=vault._nested_vaults[name],
522
554
  )
523
555
 
524
- # Root vault: single arg only
556
+ # Root vault: a plain name or an `include:target` reference
557
+ parts = split_qualified(name)
558
+ if parts is not None and parts[0] not in vault._nested_vaults:
559
+ available = ", ".join(vault._nested_vaults) or "none"
560
+ raise CLIError(
561
+ f"unknown include {parts[0]!r} (available: {available})", 127
562
+ )
525
563
  target = vault.get(name)
526
564
  if target is None:
565
+ if parts is not None:
566
+ available = ", ".join(vault._nested_vaults[parts[0]].targets) or "none"
567
+ raise CLIError(
568
+ f"unknown target {parts[1]!r} in include {parts[0]!r} "
569
+ f"(available: {available})", 127
570
+ )
527
571
  available = ", ".join(vault.targets) or "none"
528
572
  raise CLIError(
529
573
  f"unknown target {name!r} (available: {available})", 127
@@ -570,8 +614,11 @@ def cmd_add(args: argparse.Namespace) -> int:
570
614
  if not body.endswith("\n"):
571
615
  body += "\n"
572
616
 
573
- vault.scripts_dir.mkdir(parents=True, exist_ok=True)
574
- path = vault.scripts_dir / f"{name}.sh"
617
+ scripts_dir = vault.local_scripts_dir if args.local else vault.scripts_dir
618
+ scripts_dir.mkdir(parents=True, exist_ok=True)
619
+ if args.local:
620
+ _ignore_local_scripts(vault.hidden_dir)
621
+ path = scripts_dir / f"{name}.sh"
575
622
  if path.exists():
576
623
  raise CLIError(f"'{path}' already exists")
577
624
  path.write_text(body, encoding="utf-8")
@@ -751,52 +798,50 @@ def cmd_activate(args: argparse.Namespace) -> int:
751
798
  print("Deactivated. Use this command or pipe to your shell.", file=sys.stderr)
752
799
  return 0
753
800
 
754
- # Determine which vault to activate
801
+ current = Path.cwd()
802
+ hidden = hidden_dir_name()
755
803
  if args.name is None:
756
- # Activate current .sv directory (if we're in one)
757
- current = Path.cwd()
758
- # Check if current directory IS the .sv directory
759
- hidden = hidden_dir_name()
760
804
  if current.name == hidden and (current / "vault.toml").is_file():
761
- # We're already in a .sv directory, use it
762
- vault_name = current.parent.name
763
- print(f"export SV_ACTIVE_VAULT=\"{vault_name}\"", file=sys.stderr)
764
- print(f"Activated: {vault_name}", file=sys.stderr)
805
+ vault_root = current.parent
806
+ elif (current / hidden / "vault.toml").is_file():
807
+ vault_root = current
765
808
  else:
766
809
  print(f"Error: No vault found in {current}", file=sys.stderr)
767
810
  return 1
768
811
  else:
769
- # Activate named vault
770
812
  if args.name in RESERVED_NAMES:
771
813
  print(f"Error: '{args.name}' is a reserved name", file=sys.stderr)
772
814
  return 1
773
815
 
774
- current = Path.cwd()
775
- # Try: current/VAULT/.sv/vault.toml
776
- vault_path = current / args.name / hidden_dir_name() / "vault.toml"
777
- if not vault_path.is_file():
816
+ vault_root = current / args.name
817
+ if not (vault_root / hidden / "vault.toml").is_file():
778
818
  print(f"Error: Vault '{args.name}' not found", file=sys.stderr)
779
819
  return 1
780
820
 
781
- print(f"export SV_ACTIVE_VAULT=\"{args.name}\"", file=sys.stderr)
782
- print(f"Activated: {args.name}", file=sys.stderr)
783
-
784
- # Print the active vault info
785
821
  try:
786
- vault = _load_vault(None)
787
- print(f"Active vault: {vault.name}", file=sys.stderr)
822
+ vault = load_vault(vault_root)
788
823
  except Exception as e:
789
824
  print(f"Error loading vault: {e}", file=sys.stderr)
790
825
  return 1
791
826
 
827
+ active_path = shlex.quote(str(vault_root.resolve()))
828
+ print(f"export SV_ACTIVE_VAULT={active_path}", file=sys.stderr)
829
+ print(f"Activated: {vault_root.name}", file=sys.stderr)
830
+ print(f"Active vault: {vault.name}", file=sys.stderr)
792
831
  return 0
793
832
 
794
833
 
795
834
  def cmd_names(_args: argparse.Namespace | None = None) -> int:
796
- """Print target names, one per line (used by shell completions)."""
835
+ """Print target names, one per line (used by shell completions).
836
+
837
+ Included targets appear both bare and as `include:target` references.
838
+ """
797
839
  vault = _load_vault(None)
798
840
  for name in vault.targets:
799
841
  print(name)
842
+ for include, nested in vault._nested_vaults.items():
843
+ for name in nested.targets:
844
+ print(f"{include}:{name}")
800
845
  return 0
801
846
 
802
847
 
@@ -880,6 +925,7 @@ def build_parser() -> argparse.ArgumentParser:
880
925
  lst.add_argument(
881
926
  "--json", action="store_true", help="output as a JSON object with include info"
882
927
  )
928
+ lst.add_argument("--all", action="store_true", help="include hidden and local targets")
883
929
  lst.add_argument(
884
930
  "--nested", action="store_true",
885
931
  help="show all nested vault scripts (default: only root scripts)"
@@ -939,6 +985,7 @@ def build_parser() -> argparse.ArgumentParser:
939
985
  help="read the script body from stdin instead of the template",
940
986
  )
941
987
  add.set_defaults(func=cmd_add)
988
+ add.add_argument("--local", action="store_true", help="create a gitignored, hidden local script")
942
989
 
943
990
  edit = sub.add_parser(
944
991
  "edit", help="edit a script, its env, or the vault configuration"
@@ -981,7 +1028,7 @@ def build_parser() -> argparse.ArgumentParser:
981
1028
  nargs="?",
982
1029
  default=None,
983
1030
  metavar="VAULT",
984
- help="vault name to activate (default: use current .sv directory)",
1031
+ help="vault name to activate (default: use current project root or .sv directory)",
985
1032
  )
986
1033
  activate.add_argument(
987
1034
  "--deactivate",
@@ -230,7 +230,9 @@ def build_env(
230
230
  """Build the environment for a script: global .env, script .env, real env, injected vars."""
231
231
  ctx = source_vault or vault
232
232
  env: dict[str, str] = {}
233
- if ctx.global_env.is_file():
233
+ if vault.global_env.is_file():
234
+ env.update(parse_env_file(vault.global_env))
235
+ if ctx is not vault and ctx.global_env.is_file():
234
236
  env.update(parse_env_file(ctx.global_env))
235
237
 
236
238
  # Load environment files from project root recursively matching environment
@@ -244,8 +246,11 @@ def build_env(
244
246
  env.update(parse_env_file(script_env))
245
247
 
246
248
  env.update(dict(os.environ))
249
+ env["SV_TOP_ROOT"] = str(vault.root)
250
+ env["SV_TOP_LIB"] = str(vault.hidden_dir / "lib")
247
251
  env["SV_ROOT"] = str(ctx.root)
248
252
  env["SV_DIR"] = str(ctx.hidden_dir)
253
+ env["SV_LIB"] = str(ctx.hidden_dir / "lib")
249
254
  env["SV_CWD"] = os.getcwd()
250
255
  if name is not None:
251
256
  env["SV_NAME"] = name
@@ -314,13 +319,14 @@ def run_script(
314
319
  progress=None,
315
320
  source_vault: Vault | None = None,
316
321
  ) -> int:
322
+ source_vault = source_vault or vault.owner_of(script.name)
317
323
  env = build_env(vault, script.name, source_vault=source_vault)
318
324
  argv = _script_argv(vault, script, args)
319
325
  if global_flags is not None:
320
326
  argv = global_flags + argv
321
- if progress is not None:
322
- return _run_child(argv, env, vault.root, out, progress)
323
327
  cwd = source_vault.root if source_vault else vault.root
328
+ if progress is not None:
329
+ return _run_child(argv, env, cwd, out, progress)
324
330
  proc = subprocess.Popen(
325
331
  argv,
326
332
  cwd=str(cwd),
@@ -439,12 +445,13 @@ def run_parallel(
439
445
  jobs: list[tuple[threading.Thread, list[int]]] = []
440
446
  for name in names:
441
447
  target = vault.get(name)
448
+ target_vault = vault.owner_of(name)
442
449
  if isinstance(target, Script):
443
- env = build_env(vault, target.name, source_vault=source_vault)
450
+ env = build_env(vault, target.name, source_vault=target_vault)
444
451
  argv = _script_argv(vault, target, [])
445
452
  if global_flags is not None:
446
453
  argv = global_flags + argv
447
- cwd = source_vault.root if source_vault else vault.root
454
+ cwd = target_vault.root if target_vault else vault.root
448
455
  proc = subprocess.Popen(
449
456
  argv,
450
457
  cwd=str(cwd),
@@ -464,7 +471,7 @@ def run_parallel(
464
471
  job_out = os.fdopen(wfd, "w", encoding="utf-8", errors="replace")
465
472
  codes = []
466
473
 
467
- def job(n=name, o=job_out, c=codes, p=progress, g=global_flags, v=vault, s=source_vault) -> None:
474
+ def job(n=name, o=job_out, c=codes, p=progress, g=global_flags, v=vault, s=target_vault) -> None:
468
475
  try:
469
476
  c.append(_run_job(vault, n, out=o, progress=p, global_flags=g, source_vault=s))
470
477
  except Exception as exc:
@@ -531,6 +538,7 @@ def run_orchestration(
531
538
  try:
532
539
  if step.kind == "run":
533
540
  target = vault.get(step.run_name)
541
+ target_vault = vault.owner_of(step.run_name)
534
542
  if isinstance(target, Orchestration):
535
543
  code = run_orchestration(
536
544
  vault,
@@ -539,7 +547,7 @@ def run_orchestration(
539
547
  progress=progress,
540
548
  show_progress=False,
541
549
  global_flags=global_flags,
542
- source_vault=source_vault,
550
+ source_vault=target_vault,
543
551
  )
544
552
  else:
545
553
  code = run_script(
@@ -549,7 +557,7 @@ def run_orchestration(
549
557
  global_flags=global_flags,
550
558
  out=out,
551
559
  progress=progress,
552
- source_vault=source_vault,
560
+ source_vault=target_vault,
553
561
  )
554
562
  elif step.kind == "sh":
555
563
  code = _run_sh_step(