base-cli 0.1.0__tar.gz → 0.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.
Files changed (59) hide show
  1. {base_cli-0.1.0/lib/python/base_cli.egg-info → base_cli-0.2.0}/PKG-INFO +151 -139
  2. {base_cli-0.1.0 → base_cli-0.2.0}/README.md +149 -137
  3. base_cli-0.2.0/VERSION +1 -0
  4. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/__init__.py +32 -10
  5. base_cli-0.2.0/lib/python/base_cli/_dependencies.py +15 -0
  6. base_cli-0.2.0/lib/python/base_cli/_private_files.py +38 -0
  7. base_cli-0.2.0/lib/python/base_cli/_runtime.py +130 -0
  8. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/app.py +74 -87
  9. base_cli-0.2.0/lib/python/base_cli/command_filters.py +70 -0
  10. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/command_protocol.py +60 -61
  11. base_cli-0.2.0/lib/python/base_cli/config.py +28 -0
  12. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/context.py +7 -8
  13. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/exit_codes.py +1 -1
  14. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/history.py +41 -133
  15. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/logging.py +14 -6
  16. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/output.py +5 -9
  17. base_cli-0.2.0/lib/python/base_cli/paths.py +56 -0
  18. base_cli-0.2.0/lib/python/base_cli/profile.py +159 -0
  19. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/testing.py +18 -25
  20. {base_cli-0.1.0 → base_cli-0.2.0/lib/python/base_cli.egg-info}/PKG-INFO +151 -139
  21. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli.egg-info/SOURCES.txt +7 -7
  22. {base_cli-0.1.0 → base_cli-0.2.0}/pyproject.toml +1 -1
  23. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_app_log_retention.py +84 -19
  24. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_app_run.py +45 -11
  25. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_app_runtime_boundary.py +32 -15
  26. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_app_runtime_errors.py +8 -5
  27. base_cli-0.2.0/tests/test_command_filters.py +36 -0
  28. base_cli-0.2.0/tests/test_command_protocol.py +202 -0
  29. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_context_workspace.py +25 -14
  30. base_cli-0.2.0/tests/test_generic_core.py +80 -0
  31. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_logging.py +12 -3
  32. base_cli-0.2.0/tests/test_profile.py +119 -0
  33. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_public_api.py +29 -13
  34. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_testing.py +83 -17
  35. base_cli-0.1.0/VERSION +0 -1
  36. base_cli-0.1.0/lib/python/base_cli/_runtime.py +0 -89
  37. base_cli-0.1.0/lib/python/base_cli/command_filters.py +0 -37
  38. base_cli-0.1.0/lib/python/base_cli/config.py +0 -270
  39. base_cli-0.1.0/lib/python/base_cli/ide_schema.py +0 -74
  40. base_cli-0.1.0/lib/python/base_cli/paths.py +0 -136
  41. base_cli-0.1.0/tests/test_base_cli.py +0 -1015
  42. base_cli-0.1.0/tests/test_command_protocol.py +0 -147
  43. base_cli-0.1.0/tests/test_history.py +0 -398
  44. base_cli-0.1.0/tests/test_ide_schema.py +0 -48
  45. base_cli-0.1.0/tests/test_user_config_github.py +0 -95
  46. base_cli-0.1.0/tests/test_user_config_workspace.py +0 -24
  47. {base_cli-0.1.0 → base_cli-0.2.0}/LICENSE +0 -0
  48. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/inspection.py +0 -0
  49. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/py.typed +0 -0
  50. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli/redaction.py +0 -0
  51. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli.egg-info/dependency_links.txt +0 -0
  52. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli.egg-info/requires.txt +0 -0
  53. {base_cli-0.1.0 → base_cli-0.2.0}/lib/python/base_cli.egg-info/top_level.txt +0 -0
  54. {base_cli-0.1.0 → base_cli-0.2.0}/setup.cfg +0 -0
  55. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_app_dry_run.py +0 -0
  56. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_app_quiet.py +0 -0
  57. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_app_subcommands.py +0 -0
  58. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_inspection.py +0 -0
  59. {base_cli-0.1.0 → base_cli-0.2.0}/tests/test_output.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: base-cli
3
- Version: 0.1.0
4
- Summary: A small, consistent Python CLI framework for Base and Base-supported projects
3
+ Version: 0.2.0
4
+ Summary: A small, consumer-neutral Python CLI framework
5
5
  Author: Base Foundry
6
6
  License: Apache-2.0
7
7
  Project-URL: Homepage, https://github.com/basefoundry/base-cli
@@ -44,18 +44,18 @@ documented in [`docs/releasing.md`](docs/releasing.md). The package exposes
44
44
  The package is distributed under the Apache License 2.0. Base itself remains
45
45
  licensed separately under AGPL-3.0-or-later.
46
46
 
47
- `base_cli` is Base's small Python framework for writing command-line tools that
48
- feel consistent across Base and Base-supported projects.
47
+ `base_cli` is a small Python framework for writing command-line tools with
48
+ a consistent lifecycle. It is designed to be embedded by applications rather
49
+ than to define an application's project model. Base is one consumer of the
50
+ library, not part of its generic contract.
49
51
 
50
52
  It is intentionally thin. Click still owns argument parsing and command
51
- execution, while `base_cli` adds the Base-specific behavior every project CLI
52
- should get by default:
53
+ execution, while `base_cli` provides reusable lifecycle behavior:
53
54
 
54
55
  - standard command options such as `--debug`, `--quiet`, `--environment`,
55
56
  `--config`, `--keep-temp`, and `--log-file`
56
57
  - structured logging to stderr and, by default, to a persistent per-run log file
57
- - Base project discovery through `base_manifest.yaml`
58
- - config loading with predictable precedence
58
+ - optional project discovery and configuration policies supplied by the consumer
59
59
  - per-run temp directories, persistent cache directories, and cleanup hooks
60
60
  - sensitive argument redaction in debug invocation logs
61
61
  - a command context object shared by command code and helper functions
@@ -63,7 +63,7 @@ should get by default:
63
63
 
64
64
  ## Design Goals
65
65
 
66
- Base CLI tools should be easy to write, but not magical. A command should be
66
+ CLI tools should be easy to write, but not magical. A command should be
67
67
  explicitly registered, receive an explicit `Context`, and use standard Python
68
68
  functions instead of import-time side effects.
69
69
 
@@ -73,22 +73,59 @@ The package follows these rules:
73
73
  decorating a function.
74
74
  - **Logs go to stderr**: user-facing program output can stay on stdout, while
75
75
  logs remain redirectable and skippable.
76
- - **Every run has a context**: logs, paths, config, environment, manifest, and
77
- cleanup are available through one object.
76
+ - **Every run has a context**: logs, paths, configuration, environment, and
77
+ cleanup are available through one object. Project metadata is available when
78
+ the selected consumer profile supplies it.
78
79
  - **No import-time filesystem writes**: state directories are created only when
79
80
  a command runs.
80
- - **Base-aware, Click-compatible**: command authors keep using familiar Click
81
- concepts such as options and arguments.
81
+ - **Consumer-neutral, Click-compatible**: command authors keep using familiar
82
+ Click concepts such as options and arguments.
83
+
84
+ ## Consumer Profiles
85
+
86
+ `App` accepts a `CliProfile` that supplies the policies which vary
87
+ between applications: project discovery, configuration, runtime placement, and
88
+ optional history persistence.
89
+
90
+ Standalone consumers use the generic profile by default. It can also be passed
91
+ explicitly when making the policy boundary visible:
92
+
93
+ ```python
94
+ app = base_cli.App(
95
+ name="hello",
96
+ version="0.1.0",
97
+ profile=base_cli.CliProfile.generic(),
98
+ )
99
+ ```
100
+
101
+ The generic profile has no manifest filename convention, no product-owned
102
+ configuration directory, and no implicit history writer. Applications can
103
+ provide those policies through callbacks or build their own profile. The
104
+ consumer-owned adapters should supply any product-specific policies. See
105
+ [`docs/consumer-profiles.md`](docs/consumer-profiles.md) for the boundary and
106
+ migration guidance.
82
107
 
83
108
  ## Public API
84
109
 
85
110
  The supported facade is `import base_cli`. It exports the command lifecycle
86
111
  (`App`, `Context`, `run_app`, decorators, and logging helpers), command filters,
87
- the structured command protocol helpers, and the user configuration types used
88
- by `Context.user_config`. The corresponding modules are also available as
112
+ and the structured command protocol helpers. Consumer-owned user configuration
113
+ is passed through `Context.user_config`; the library does not impose a schema.
114
+ The corresponding modules are also available as
89
115
  `base_cli.command_filters`, `base_cli.command_protocol`, and
90
116
  `base_cli.history`.
91
117
 
118
+ The command protocol owns only generic framing, field validation, and schema
119
+ registration. It ships with no application record types and uses
120
+ `COMMAND_PROTOCOL_V1` by default. A consumer can register its own schemas and
121
+ pass a compatibility `protocol_header` when it must interoperate with an
122
+ existing peer protocol.
123
+
124
+ Command filters use consumer-neutral name normalization by default. Consumers
125
+ with legacy command names can pass a `normalizer` callback to
126
+ `normalize_command_filter`, `normalize_command_filters`, and
127
+ `command_matches` to define compatibility aliases or prefixes.
128
+
92
129
  Low-level implementation helpers are intentionally not included in the
93
130
  module `__all__` surfaces. Downstream code should use the documented facade or
94
131
  the explicitly supported symbols from those modules.
@@ -101,7 +138,11 @@ from __future__ import annotations
101
138
  import base_cli
102
139
 
103
140
 
104
- app = base_cli.App(name="hello", version="0.1.0")
141
+ app = base_cli.App(
142
+ name="hello",
143
+ version="0.1.0",
144
+ profile=base_cli.CliProfile.generic(),
145
+ )
105
146
 
106
147
 
107
148
  @app.command()
@@ -116,7 +157,7 @@ if __name__ == "__main__":
116
157
  ```
117
158
 
118
159
  Running this command directly as a Python package automatically adds the
119
- standard Base options:
160
+ standard options:
120
161
 
121
162
  ```bash
122
163
  hello --name Ada
@@ -129,19 +170,16 @@ hello --log-file /tmp/hello.log --name Ada
129
170
 
130
171
  Long options with values use space-separated syntax. `base_cli.run_app()` rejects
131
172
  equals-form values such as `--name=Ada` before Click parses arguments.
132
- These are direct package options. Public `basectl` launchers expose `-v` for
133
- command-level debug logs and command-specific flags from
134
- `basectl <command> --help`; they do not expose `--debug`, `--quiet`,
135
- `--log-file`, `--config`, or `--environment` as public `basectl` options.
136
- The wrapper-level `basectl --keep-temp <command>` option preserves the
137
- complete temporary tree for that run.
173
+ These options belong to the application-level lifecycle. A consumer may expose
174
+ them through its own launcher or compose them with a higher-level command
175
+ wrapper.
138
176
 
139
177
  ## Command Registration
140
178
 
141
179
  Use `App` when you want a named command:
142
180
 
143
181
  ```python
144
- app = base_cli.App(name="base-projects", version="0.1.0")
182
+ app = base_cli.App(name="workspace-tools", version="0.1.0")
145
183
  ```
146
184
 
147
185
  Register the command function explicitly:
@@ -153,7 +191,7 @@ def main(ctx: base_cli.Context) -> None:
153
191
  ```
154
192
 
155
193
  The command function always receives `ctx` as its first argument. User-defined
156
- options and arguments are passed after the Base standard options have been
194
+ options and arguments are passed after the standard lifecycle options have been
157
195
  removed from Click's keyword arguments.
158
196
 
159
197
  For small scripts, the module-level decorators are available:
@@ -164,10 +202,10 @@ def main(ctx: base_cli.Context) -> None:
164
202
  ...
165
203
  ```
166
204
 
167
- In Base itself, prefer an explicit `App` so command names and versions are
168
- obvious at the top of the module.
205
+ Prefer an explicit `App` when command names, versions, or consumer
206
+ policies should be visible at the top of the module.
169
207
 
170
- Use `@app.subcommand()` when one CLI needs multiple verbs while keeping Base's
208
+ Use `@app.subcommand()` when one CLI needs multiple verbs while keeping the
171
209
  standard context, logging, redaction, and cleanup lifecycle for each invocation:
172
210
 
173
211
  ```python
@@ -193,7 +231,7 @@ def sync_project(ctx: base_cli.Context, dry_run: bool) -> None:
193
231
 
194
232
  Subcommands use the same `base_cli.option()` and `base_cli.argument()` metadata
195
233
  as single commands. `App(help=...)` appears in the command group's `--help`
196
- output. For subcommand apps, prefer standard Base options before the subcommand
234
+ output. For subcommand apps, prefer standard options before the subcommand
197
235
  name, for example `workspace-tools --debug status demo`. The post-subcommand
198
236
  form, such as `workspace-tools status --debug demo`, remains accepted for
199
237
  compatibility. Use either `@app.command()` for a single-command CLI or
@@ -222,11 +260,11 @@ def main(ctx: base_cli.Context, token: str) -> None:
222
260
  ```
223
261
 
224
262
  Both `--token secret` and an externally supplied `--token=secret` token are
225
- redacted in debug logs, even though Base command invocation rejects equals-form
226
- option values before Click parses them.
263
+ redacted in debug logs. The lifecycle rejects equals-form option values before
264
+ Click parses them.
227
265
 
228
266
  Use `dry_run=True` when a nonstandard option should drive `ctx.dry_run` and
229
- Base's default durable-write suppression:
267
+ the lifecycle's default durable-write suppression:
230
268
 
231
269
  ```python
232
270
  @base_cli.option("--preview", is_flag=True, dry_run=True)
@@ -258,7 +296,7 @@ are consumed before the command function is called.
258
296
 
259
297
  ## Exit Codes
260
298
 
261
- Use `base_cli.ExitCode` when command code or tests need to name Base's standard
299
+ Use `base_cli.ExitCode` when command code or tests need to name standard
262
300
  command result meanings:
263
301
 
264
302
  - `ExitCode.SUCCESS` (`0`): the command completed successfully.
@@ -272,28 +310,30 @@ constants when it makes intent clearer:
272
310
 
273
311
  ```python
274
312
  if ctx.project_root is None:
275
- ctx.log.error("run this command from a Base project")
313
+ ctx.log.error("run this command from a project recognized by the consumer")
276
314
  return base_cli.ExitCode.USAGE_ERROR
277
315
  ```
278
316
 
279
317
  ## Context
280
318
 
281
319
  `Context` is the object command code should pass around instead of rediscovering
282
- Base paths or global settings.
320
+ runtime paths or global settings.
283
321
 
284
322
  Important fields include:
285
323
 
286
324
  - `ctx.cli_name`: normalized CLI name used for state paths and logger names.
287
325
  - `ctx.run_id`: timestamp plus short random suffix for this invocation.
288
- - `ctx.base_home`: resolved `BASE_HOME`, when available.
289
- - `ctx.project_root`: directory containing the nearest `base_manifest.yaml`.
290
- - `ctx.workspace_root`: configured workspace root from `~/.base.d/config.yaml`.
291
- - `ctx.manifest_path`: nearest discovered Base manifest.
292
- - `ctx.history_scope`: compatibility scope marker; delegated children are not
293
- written as separate history events.
294
- - `ctx.history_parent_run_id`: shared parent `basectl` invocation ID, when delegated.
295
- - `ctx.runtime_owner`: `base` or `project`.
296
- - `ctx.owner_root`: owner namespace root under the Base cache root.
326
+ - `ctx.application_home`: optional application home supplied by the profile.
327
+ - `ctx.project_root`: project root returned by the profile, when any.
328
+ - `ctx.workspace_root`: optional workspace root supplied by user configuration.
329
+ - `ctx.manifest_path`: project metadata path returned by the profile, when any.
330
+ - `ctx.history_scope`: history scope supplied by the profile or its
331
+ compatibility adapter.
332
+ - `ctx.history_parent_run_id`: optional parent invocation ID supplied by
333
+ the consumer.
334
+ - `ctx.runtime_owner`: consumer-defined runtime owner; the generic
335
+ profile uses `default`.
336
+ - `ctx.owner_root`: application namespace root under the configured cache root.
297
337
  - `ctx.run_root`: this invocation's run bundle.
298
338
  - `ctx.state_dir`: owner root (compatibility alias).
299
339
  - `ctx.log_dir`: run-bundle log directory.
@@ -302,13 +342,14 @@ Important fields include:
302
342
  - `ctx.log_file`: the run's shared `logs/primary.log`, or `None` when persistent
303
343
  logging is disabled.
304
344
  - `ctx.config`: merged configuration dictionary.
305
- - `ctx.user_config`: typed user configuration from `~/.base.d/config.yaml`.
345
+ - `ctx.user_config`: opaque consumer-owned user configuration returned by the
346
+ profile, or `None` for the generic default.
306
347
  - `ctx.environment`: active environment, defaulting to `dev`.
307
348
  - `ctx.debug`: whether debug logging is enabled for the stderr stream.
308
349
  - `ctx.quiet`: whether INFO logs are suppressed on the stderr stream.
309
350
  - `ctx.dry_run`: whether the command is running in a no-durable-write mode.
310
351
  - `ctx.keep_temp`: whether `ctx.temp_dir` should survive cleanup.
311
- - `ctx.log`: standard Python logger configured by Base.
352
+ - `ctx.log`: standard Python logger configured by `base_cli`.
312
353
 
313
354
  Helpers can retrieve the active context without threading it through every call:
314
355
 
@@ -335,37 +376,39 @@ def helper() -> None:
335
376
  `--quiet` suppresses INFO output on the user-facing stream but still shows
336
377
  warnings and errors. `--debug` and `--quiet` cannot be used together. Persistent
337
378
  log files still receive DEBUG-level detail, including INFO messages suppressed
338
- from stderr. When `basectl --color` is used on a terminal, the user-facing
339
- Python logs use the same level colors as Bash logs; persistent log files remain
340
- plain text. `NO_COLOR` disables colors.
379
+ from stderr. User-facing logs use colors automatically on interactive terminals;
380
+ persistent log files remain plain text. Set `NO_COLOR=1` or
381
+ `BASE_CLI_COLOR=0` to disable colors. A consumer wrapper may add its own color
382
+ option and map it to the environment variable.
383
+
384
+ Click also provides shell completion. For an app named `hello`, request a
385
+ completion script with `_HELLO_COMPLETE=bash_source hello`, replacing `bash`
386
+ with `zsh` or `fish` as needed. `base_cli` leaves installation to the caller so
387
+ shell startup files remain under user control.
341
388
 
342
389
  Advanced tests and CI wrappers can call `base_cli.configure_logger(...,
343
390
  stream=..., formatter=...)` to capture user-facing logs or apply a custom
344
- formatter without replacing Base's logger setup. Leave those arguments as
345
- `None` to keep the default stderr stream and `BaseCliFormatter`. Base CLI log
346
- timestamps use the host's local timezone and include its numeric offset by
347
- default. When the wrapper sets `LOG_UTC=1` (for example via
348
- `basectl --utc-wrapper`), they use UTC and include an explicit `UTC` marker.
391
+ formatter. Leave those arguments as `None` to keep the default stderr stream
392
+ and formatter. Log timestamps use the host's local timezone and include its
393
+ numeric offset by default. A consumer can set `LOG_UTC=1` to use UTC and
394
+ include an explicit `UTC` marker.
349
395
 
350
396
  This setting affects log presentation only. Run metadata, history records, and
351
397
  run IDs retain their canonical UTC representation.
352
398
 
353
399
  Commands that inspect runtime artifacts can use `base_cli.App(log_to_file=False)`
354
400
  to keep the standard context, `--debug`, and `--quiet` behavior without creating
355
- default `logs/`, `cache/`, or `tmp/<run-id>/` directories. `base_logs` uses this
356
- mode so `basectl logs` does not appear in its own output; `base_history` does
357
- the same for `basectl history`. An explicit `--log-file <path>` still enables
358
- file logging for that invocation.
401
+ default `logs/`, `cache/`, or `tmp/<run-id>/` directories. An explicit
402
+ `--log-file <path>` still enables file logging for that invocation.
359
403
 
360
404
  Commands running with `ctx.dry_run` also skip default `logs/`, `cache/`, and
361
405
  `tmp/<run-id>/` creation. Passing `--log-file <path>` still writes to that
362
406
  explicit file so tests and diagnostics can inspect dry-run logs when needed.
363
407
 
364
- For Python-backed commands with persistent logs, `base_cli.App` also writes a
365
- best-effort final history record to `<base-cache-root>/base/history/runs.jsonl`.
366
- History records contain redacted command metadata, timing, exit status, project
367
- context when known, and a pointer to the raw log file. History writes are local
368
- only and do not fail the user command when the index cannot be updated.
408
+ The generic profile does not write command history. A profile may provide a
409
+ history writer to persist redacted command metadata, timing, exit status,
410
+ project context, and a pointer to the raw log file. History writes should be
411
+ best-effort and should not fail the user command when an index cannot be updated.
369
412
 
370
413
  High-frequency tools can set `base_cli.App(max_log_files=<count>)` to keep at
371
414
  most that many default persistent log files across the owner's run bundles.
@@ -374,10 +417,10 @@ resolved, and the current run's log file is never pruned. The policy is skipped
374
417
  for `ctx.dry_run`,
375
418
  `log_to_file=False`, and explicit `--log-file` paths so no-durable-write modes
376
419
  and caller-selected log locations stay under caller control. Use this as a
377
- small guardrail for busy local tools; `basectl clean` remains the broader
378
- maintenance command for caches, logs, and retained temp files.
420
+ small guardrail for busy local tools; an application can provide broader
421
+ maintenance commands for caches, logs, and retained temp files.
379
422
 
380
- Logs use the same general shape as Base Bash logs:
423
+ Logs use a stable, human-readable shape:
381
424
 
382
425
  ```text
383
426
  2026-05-26 12:34:56 INFO path/to/file.py:42 message
@@ -404,65 +447,42 @@ the real command output.
404
447
 
405
448
  ## Config Precedence
406
449
 
407
- Configuration is loaded from YAML files and environment variables in this order:
408
-
409
- 1. user config: `~/.base.d/config.yaml`
410
- 2. project config: `<project>/.base/config.yaml`
411
- 3. explicit config from `--config`
412
- 4. environment variables
413
- 5. direct command-line standard options
414
-
415
- Environment variables currently recognized by the config layer:
416
-
417
- - `BASE_CLI_ENVIRONMENT`
418
- - `BASE_CLI_LOG_LEVEL`
419
- - `BASE_CLI_KEEP_TEMP`
450
+ The generic profile has no implicit configuration files. It loads the file
451
+ passed through `--config`, when present, and otherwise starts with an empty
452
+ configuration dictionary. Standard command-line options are applied by the
453
+ lifecycle after the profile's configuration is loaded; for example,
454
+ `--environment prod` overrides `environment: dev` from an explicit
455
+ configuration file.
420
456
 
421
- `LOG_DEBUG=1` or `LOG_DEBUG=true` is also accepted as an internal compatibility
422
- fallback for wrapper/debug paths when `BASE_CLI_LOG_LEVEL` is unset. Prefer
423
- `BASE_CLI_LOG_LEVEL=debug` for user-facing Python CLI debug logging.
424
457
 
425
- Command-line standard options are applied after config is loaded. For example,
426
- `--environment prod` overrides `environment: dev` from config.
427
-
428
- `ctx.config` exposes the merged raw configuration after user, project,
429
- explicit, and environment layers are applied. `ctx.user_config` exposes only the
430
- typed machine-local user config, including `workspace.root`,
431
- `workspace.manifest`, and IDE
432
- preferences, so command code does not need to re-read `~/.base.d/config.yaml`
433
- for those structured values.
434
-
435
- The user config file is machine-local by default. Base owns the semantics of
436
- `~/.base.d/config.yaml`, while users own backup and sync choices such as iCloud,
437
- chezmoi, dotfiles repositories, Time Machine, or manual copy. See
438
- `docs/local-config.md` for the product-level boundary.
458
+ `ctx.config` exposes the dictionary returned by the profile. `ctx.user_config`
459
+ exposes the opaque user-configuration value returned by the profile. Consumers
460
+ that need user files, project files, environment variables, or a merge
461
+ precedence must implement those policies in `CliProfile.load_config` and
462
+ `CliProfile.load_user_config`; `base_cli` does not define the value's fields.
439
463
 
440
464
  ## Project Discovery
441
465
 
442
- When a command runs, `base_cli` walks upward from the current working directory
443
- looking for `base_manifest.yaml`.
444
-
445
- If found:
466
+ The generic profile does not discover projects or assume a manifest filename.
467
+ Its `ctx.project_root` and `ctx.manifest_path` fields are `None` unless the
468
+ consumer supplies a `discover_project` policy. A profile can discover projects
469
+ from a manifest, workspace, repository metadata, or any other application-owned
470
+ source and return a `ProjectInfo` value.
446
471
 
447
- - `ctx.manifest_path` points to the manifest
448
- - `ctx.project_root` points to the manifest's parent directory
449
-
450
- If no manifest is found, both fields are `None`. Commands that require a Base
451
- project should validate this explicitly and return a clear usage error or
452
- actionable message.
472
+ Commands that require a project should validate the profile-provided value
473
+ explicitly and return a clear usage error or actionable message.
453
474
 
454
475
  ## Runtime Directories
455
476
 
456
- Runtime state is rooted at `~/Library/Caches/base` on macOS and `~/.cache/base`
457
- elsewhere. `BASE_CACHE_DIR` overrides the root. See
458
- [`docs/cache-ownership-and-layout.md`](../../../docs/cache-ownership-and-layout.md)
459
- for the owner-aware layout. Base control-plane commands use `base/`; a
460
- Base-compliant project's own commands use `projects/<project>/<checkout-id>/`.
477
+ The generic profile uses the configured cache root and an application namespace
478
+ to create per-run logs, caches, and temporary directories. Pass
479
+ `cache_root` to `CliProfile.generic()` for deterministic placement in tests or
480
+ applications; otherwise the platform cache directory is used. The generic
481
+ profile does not prescribe a product-wide cache name or cleanup command.
482
+
461
483
  Each invocation is a run bundle containing private (`0600`) `run.json`,
462
- `logs/`, and `tmp/`,
463
- while persistent component caches live in the owner's `cache/components/`.
464
- `basectl clean --older-than <age>` removes old bundles and component caches;
465
- `--keep-last <count>` retains the newest completed bundles per owner.
484
+ `logs/`, and `tmp/`, while persistent component caches live in the
485
+ bundle's cache directory.
466
486
 
467
487
  Use `ctx.on_cleanup()` for cleanup work that should happen even when helper code
468
488
  does not own the main command wrapper:
@@ -497,39 +517,31 @@ def test_command(tmp_path: Path) -> None:
497
517
  ["--name", "Ada"],
498
518
  home=tmp_path,
499
519
  cwd=project,
500
- manifest={"project": {"name": "demo"}, "artifacts": []},
501
520
  )
502
521
 
503
522
  assert result.exit_code == 0
504
523
  assert "hello Ada" in result.stdout
505
524
  ```
506
525
 
507
- The helper wraps Click's `CliRunner`, sets `HOME` when requested, supplies
508
- `cwd` to Base's context discovery without mutating process-global cwd, and keeps
509
- stderr separate on Click versions that support it. Use `cwd` for commands whose
510
- behavior depends on project discovery, including tests that intentionally run
511
- outside a Base project. Pass
512
- `manifest={...}` with `cwd` to write a temporary `base_manifest.yaml` before
513
- the command runs.
526
+ The helper wraps Click's `CliRunner`, sets `HOME` when requested, and supplies
527
+ `cwd` to the invocation for the duration of the test. Calls that use
528
+ `cwd` are serialized and the caller's cwd is restored afterward, but this
529
+ remains process-global: do not use it concurrently with code that changes cwd
530
+ outside `invoke()` or from threads spawned by the invoked command. A
531
+ generic profile should receive project fixtures through its
532
+ `discover_project` callback. The helper does not create or interpret any
533
+ product-specific manifest fixture.
514
534
 
515
- When `home` is supplied, `invoke()` also defaults `BASE_CACHE_DIR` to
516
- `<home>/.cache/base` so helper-based tests do not inherit a developer's real
517
- cache root. Pass `env={"BASE_CACHE_DIR": str(path)}` when a test needs an
518
- explicit cache location.
535
+ When `home` is supplied, `invoke()` provides an isolated default cache
536
+ environment for tests. Pass `env={"BASE_CLI_CACHE_DIR": str(path)}` when a test
537
+ needs an explicit cache location.
519
538
 
520
539
  ## When To Use `base_cli`
521
540
 
522
- Use `base_cli` for Python commands that are part of Base or a Base-supported
523
- project and need standard Base behavior.
524
-
525
- Base public command engines under `cli/python/base_*/engine.py` should
526
- instantiate `base_cli.App` so standard options, logging, redaction, runtime
527
- state, and local command history stay consistent. If a future public Python
528
- engine intentionally bypasses this lifecycle, document the reason in code and
529
- in this guide, then add it as an explicit lifecycle-audit exemption. Shell-only
530
- helpers that avoid Python startup, such as `basectl config path`, do not create
531
- Python logs or history records; once a `basectl` path enters a Python command
532
- package, it should participate in `base_cli.App`.
541
+ Use `base_cli` for Python commands that need a predictable command
542
+ lifecycle: standard options, logging, redaction, runtime state, cleanup, and
543
+ test helpers. Standalone consumers should use `CliProfile.generic()` or
544
+ provide an explicit profile with their own project and configuration policies.
533
545
 
534
546
  It is a good fit for:
535
547
 
@@ -539,5 +551,5 @@ It is a good fit for:
539
551
  - CLIs that need predictable logs, temp directories, and config precedence
540
552
 
541
553
  It is not meant to replace Click, Typer, argparse, or rich terminal UI
542
- frameworks. It is the Base layer around command lifecycle, context, logging,
554
+ frameworks. It is the reusable layer around command lifecycle, context, logging,
543
555
  configuration, and state.