promptverse-py 0.1.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 (94) hide show
  1. promptverse_py-0.1.0/.gitignore +13 -0
  2. promptverse_py-0.1.0/LICENSE +21 -0
  3. promptverse_py-0.1.0/PKG-INFO +587 -0
  4. promptverse_py-0.1.0/README.md +563 -0
  5. promptverse_py-0.1.0/pyproject.toml +70 -0
  6. promptverse_py-0.1.0/src/promptverse/__init__.py +1 -0
  7. promptverse_py-0.1.0/src/promptverse/activation.py +343 -0
  8. promptverse_py-0.1.0/src/promptverse/apply.py +365 -0
  9. promptverse_py-0.1.0/src/promptverse/authoring.py +373 -0
  10. promptverse_py-0.1.0/src/promptverse/changelog.py +94 -0
  11. promptverse_py-0.1.0/src/promptverse/cli/__init__.py +50 -0
  12. promptverse_py-0.1.0/src/promptverse/cli/activate.py +178 -0
  13. promptverse_py-0.1.0/src/promptverse/cli/add.py +304 -0
  14. promptverse_py-0.1.0/src/promptverse/cli/delete.py +69 -0
  15. promptverse_py-0.1.0/src/promptverse/cli/env.py +89 -0
  16. promptverse_py-0.1.0/src/promptverse/cli/group.py +37 -0
  17. promptverse_py-0.1.0/src/promptverse/cli/housekeeping.py +101 -0
  18. promptverse_py-0.1.0/src/promptverse/cli/init.py +104 -0
  19. promptverse_py-0.1.0/src/promptverse/cli/options.py +138 -0
  20. promptverse_py-0.1.0/src/promptverse/cli/project.py +259 -0
  21. promptverse_py-0.1.0/src/promptverse/cli/reading.py +239 -0
  22. promptverse_py-0.1.0/src/promptverse/cli/seal.py +46 -0
  23. promptverse_py-0.1.0/src/promptverse/cli/tag.py +90 -0
  24. promptverse_py-0.1.0/src/promptverse/cli/update.py +68 -0
  25. promptverse_py-0.1.0/src/promptverse/cli/validating.py +54 -0
  26. promptverse_py-0.1.0/src/promptverse/config.py +441 -0
  27. promptverse_py-0.1.0/src/promptverse/deletion.py +256 -0
  28. promptverse_py-0.1.0/src/promptverse/errors.py +136 -0
  29. promptverse_py-0.1.0/src/promptverse/frontmatter.py +171 -0
  30. promptverse_py-0.1.0/src/promptverse/graph.py +309 -0
  31. promptverse_py-0.1.0/src/promptverse/graphlog.py +201 -0
  32. promptverse_py-0.1.0/src/promptverse/hashing.py +110 -0
  33. promptverse_py-0.1.0/src/promptverse/housekeeping.py +144 -0
  34. promptverse_py-0.1.0/src/promptverse/ids.py +179 -0
  35. promptverse_py-0.1.0/src/promptverse/model.py +323 -0
  36. promptverse_py-0.1.0/src/promptverse/moves.py +205 -0
  37. promptverse_py-0.1.0/src/promptverse/placeholders.py +26 -0
  38. promptverse_py-0.1.0/src/promptverse/plan.py +210 -0
  39. promptverse_py-0.1.0/src/promptverse/pointers.py +118 -0
  40. promptverse_py-0.1.0/src/promptverse/promptdoc.py +213 -0
  41. promptverse_py-0.1.0/src/promptverse/py.typed +0 -0
  42. promptverse_py-0.1.0/src/promptverse/render.py +747 -0
  43. promptverse_py-0.1.0/src/promptverse/resolve.py +210 -0
  44. promptverse_py-0.1.0/src/promptverse/store.py +392 -0
  45. promptverse_py-0.1.0/src/promptverse/tagging.py +112 -0
  46. promptverse_py-0.1.0/src/promptverse/template.py +3 -0
  47. promptverse_py-0.1.0/src/promptverse/validate.py +629 -0
  48. promptverse_py-0.1.0/tests/builders.py +153 -0
  49. promptverse_py-0.1.0/tests/test_acceptance.py +251 -0
  50. promptverse_py-0.1.0/tests/test_activation.py +233 -0
  51. promptverse_py-0.1.0/tests/test_activation_plan.py +260 -0
  52. promptverse_py-0.1.0/tests/test_apply.py +390 -0
  53. promptverse_py-0.1.0/tests/test_authoring.py +422 -0
  54. promptverse_py-0.1.0/tests/test_changelog.py +190 -0
  55. promptverse_py-0.1.0/tests/test_cli.py +89 -0
  56. promptverse_py-0.1.0/tests/test_cli_add.py +440 -0
  57. promptverse_py-0.1.0/tests/test_cli_delete.py +249 -0
  58. promptverse_py-0.1.0/tests/test_cli_destroy.py +166 -0
  59. promptverse_py-0.1.0/tests/test_cli_downgrade.py +157 -0
  60. promptverse_py-0.1.0/tests/test_cli_env.py +71 -0
  61. promptverse_py-0.1.0/tests/test_cli_housekeeping.py +216 -0
  62. promptverse_py-0.1.0/tests/test_cli_init.py +194 -0
  63. promptverse_py-0.1.0/tests/test_cli_options.py +123 -0
  64. promptverse_py-0.1.0/tests/test_cli_project.py +361 -0
  65. promptverse_py-0.1.0/tests/test_cli_reading.py +466 -0
  66. promptverse_py-0.1.0/tests/test_cli_seal.py +157 -0
  67. promptverse_py-0.1.0/tests/test_cli_tag.py +197 -0
  68. promptverse_py-0.1.0/tests/test_cli_update.py +261 -0
  69. promptverse_py-0.1.0/tests/test_cli_upgrade.py +308 -0
  70. promptverse_py-0.1.0/tests/test_cli_validate.py +230 -0
  71. promptverse_py-0.1.0/tests/test_config.py +516 -0
  72. promptverse_py-0.1.0/tests/test_deletion.py +256 -0
  73. promptverse_py-0.1.0/tests/test_errors.py +74 -0
  74. promptverse_py-0.1.0/tests/test_frontmatter.py +285 -0
  75. promptverse_py-0.1.0/tests/test_graph.py +292 -0
  76. promptverse_py-0.1.0/tests/test_graphlog.py +214 -0
  77. promptverse_py-0.1.0/tests/test_hashing.py +142 -0
  78. promptverse_py-0.1.0/tests/test_housekeeping.py +221 -0
  79. promptverse_py-0.1.0/tests/test_ids.py +180 -0
  80. promptverse_py-0.1.0/tests/test_model.py +404 -0
  81. promptverse_py-0.1.0/tests/test_moves.py +269 -0
  82. promptverse_py-0.1.0/tests/test_placeholders.py +59 -0
  83. promptverse_py-0.1.0/tests/test_plan.py +180 -0
  84. promptverse_py-0.1.0/tests/test_pointers.py +123 -0
  85. promptverse_py-0.1.0/tests/test_promptdoc.py +224 -0
  86. promptverse_py-0.1.0/tests/test_render.py +823 -0
  87. promptverse_py-0.1.0/tests/test_render_graph.py +104 -0
  88. promptverse_py-0.1.0/tests/test_resolve.py +296 -0
  89. promptverse_py-0.1.0/tests/test_seal_plan.py +122 -0
  90. promptverse_py-0.1.0/tests/test_store.py +501 -0
  91. promptverse_py-0.1.0/tests/test_tagging.py +159 -0
  92. promptverse_py-0.1.0/tests/test_update_plan.py +218 -0
  93. promptverse_py-0.1.0/tests/test_validate.py +751 -0
  94. promptverse_py-0.1.0/tests/test_validate_disk.py +115 -0
@@ -0,0 +1,13 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ # Coverage data
13
+ .coverage
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Shyam Santoki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,587 @@
1
+ Metadata-Version: 2.5
2
+ Name: promptverse-py
3
+ Version: 0.1.0
4
+ Summary: Version control system for LLM prompts
5
+ Project-URL: Homepage, https://github.com/shyamsantoki/promptverse
6
+ Project-URL: Source, https://github.com/shyamsantoki/promptverse
7
+ Project-URL: Issues, https://github.com/shyamsantoki/promptverse/issues
8
+ Author: Shyam Santoki
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: llm,prompt,prompt-engineering,prompts,version-control
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Version Control
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: click<9,>=8.2.0
22
+ Requires-Dist: pyyaml>=6.0.1
23
+ Description-Content-Type: text/markdown
24
+
25
+ # promptverse
26
+
27
+ Version control for LLM prompts, kept as plain files in your git repository.
28
+
29
+ Each prompt is a folder of full-text versions. One version is marked as active, and
30
+ named tags such as `prod` can point at others. All state lives in committed files, so
31
+ there is no database, no server and no lock file. `git clone` plus `pip install` is a
32
+ complete setup.
33
+
34
+ The command is called `prompt`. It works like database migrations, except that people
35
+ write the versions by hand.
36
+
37
+ promptverse manages the files. Loading a prompt into your application at run time is
38
+ not part of this release.
39
+
40
+ ## Install
41
+
42
+ promptverse needs Python 3.12 or newer. It depends on `click` and `pyyaml`.
43
+
44
+ ```console
45
+ pip install promptverse-py
46
+ ```
47
+
48
+ For a command line tool, an isolated install keeps it out of your projects:
49
+
50
+ ```console
51
+ uv tool install promptverse-py
52
+ pipx install promptverse-py
53
+ ```
54
+
55
+ The package installs one command, `prompt`. Check it with `prompt --version`. The name on PyPI
56
+ is `promptverse-py`, and the Python package inside it is `promptverse`.
57
+
58
+ ## Concepts
59
+
60
+ **Prompt.** A folder under the prompts directory. Its folder name is its identity. A name is
61
+ 1 to 64 characters of lower case letters, digits, `_` and `-`, and starts with a letter or
62
+ digit. Names with dots, slashes or capitals are rejected before any path is built.
63
+
64
+ **Version.** One file holding the full text of the prompt at one point in its history. A
65
+ version never stores a diff, so every file can be read and reviewed on its own.
66
+
67
+ **Version ID.** A UTC timestamp, `YYYYMMDDTHHMMSSZ`. IDs sort by time as plain strings and
68
+ contain no characters that file systems dislike. The ID is also the file name.
69
+
70
+ **Parent and tree.** Every version except the first names one parent. The first version of a
71
+ prompt is the root and has no parent. The history is therefore a tree, not a line.
72
+
73
+ **Head.** A version with no children, the tip of a branch.
74
+
75
+ **Draft and sealed.** A new version is a draft that you can edit freely. Activating or sealing
76
+ it records a `sha256` of its body and config and the time. After that the file is sealed, and
77
+ `validate` reports any change to it.
78
+
79
+ **Active version.** The sealed version that the prompt currently serves. It is the single ID in
80
+ the `VERSION` file, and it is empty until the first activation. Only `upgrade` and `downgrade`
81
+ move it on purpose.
82
+
83
+ **Tag.** A name for a version, such as `prod`. A tag matches a lower case letter followed by up
84
+ to 31 letters, digits, `_` or `-`, and cannot be `head`, `base`, `current`, `latest` or `root`.
85
+ Tags are accepted wherever a version is expected.
86
+
87
+ **Placeholder.** A variable in the prompt text written `${name}`, where the name is letters,
88
+ digits and underscores and does not start with a digit. A doubled dollar sign is a literal one,
89
+ so `$${name}` is plain text, and a bare `$name` is plain text too.
90
+
91
+ **Type.** The kind of change a version makes, such as `fix` or `feature`. The root has the
92
+ type `initial`. The other types come from the configuration.
93
+
94
+ ## Files on disk
95
+
96
+ ```text
97
+ prompts.toml project configuration, found by walking up from the current folder
98
+ <prompts dir>/
99
+ <name>/
100
+ PROMPT.md description, inputs, outputs and the changelog
101
+ VERSION the ID of the active version, empty when none is active
102
+ TAGS one "<tag> <version-id>" line per tag, sorted by tag (optional)
103
+ <version-id>.md one file per version
104
+ ```
105
+
106
+ Text files are UTF-8 with `\n` line endings. A file written with `\r\n` or a byte order mark is
107
+ read correctly and is not rewritten unless a command changes it.
108
+
109
+ ### Version file
110
+
111
+ YAML front matter between two `---` lines, one blank line, then the prompt text.
112
+
113
+ | Key | Required | Meaning |
114
+ | --- | --- | --- |
115
+ | `type` | yes | `initial` for the root, otherwise one of the configured types. |
116
+ | `message` | yes | One line of 1 to 200 characters saying what the version changes. |
117
+ | `parent` | yes | The parent's ID, or `ROOT` for the root. |
118
+ | `config` | no | A mapping of settings that travel with the prompt, such as a model name. Values must be JSON compatible. It is copied into every new draft. |
119
+ | `sha256` | when sealed | Hash of the body and the config. |
120
+ | `sealed_at` | when sealed | When the version was sealed, as an ID-format timestamp. |
121
+
122
+ The hash covers only the body and the config. Changing `parent` or `type`, which delete does when
123
+ it reparents or promotes a version, therefore does not break a seal. A sealed version needs both
124
+ `sha256` and `sealed_at`, and one without the other is an error. Unknown keys are kept and
125
+ reported as a warning.
126
+
127
+ ### PROMPT.md
128
+
129
+ YAML front matter, then a changelog between two marker lines.
130
+
131
+ | Key | Meaning |
132
+ | --- | --- |
133
+ | `name` | Display name. It may differ from the folder name and is not changed by `rename`. |
134
+ | `purpose` | What the prompt is for (optional). |
135
+ | `inputs` | The placeholders the text expects, each with a `name` and an optional `description`. |
136
+ | `outputs` | A list of what the prompt produces (optional). |
137
+
138
+ The changelog sits between `<!-- changelog:start -->` and `<!-- changelog:end -->`, with one line
139
+ per version in ID order: `<parent or ROOT> -> <id> (<time>) [<type>]: <message>`. The tool
140
+ regenerates only that region and never adds markers to a file that lacks them.
141
+
142
+ ### VERSION and TAGS
143
+
144
+ `VERSION` holds one ID and a newline, or nothing. `TAGS` holds one `<tag> <version-id>` line per
145
+ tag, sorted by tag. The file is removed when the last tag is removed.
146
+
147
+ ## Using the command line
148
+
149
+ ### Shared options
150
+
151
+ Options go after the subcommand name, as in `prompt delete --yes`.
152
+
153
+ | Option | Commands | Meaning |
154
+ | --- | --- | --- |
155
+ | `--name NAME` | all but `init`, `list` | The prompt to act on. `validate` checks every prompt without it. |
156
+ | `--config FILE` | all | Use this config file instead of searching for one. |
157
+ | `--no-input` | all | Never ask a question. A missing value is an error. |
158
+ | `--no-color` | all | Do not color output. The `NO_COLOR` variable does the same. |
159
+ | `--dry-run` | commands that write | Print what would change, as a plan, and write nothing. A summary line is marked `(dry run)`. |
160
+ | `-q`, `--quiet` | commands that write | Do not print informational lines. |
161
+ | `-y`, `--yes` | `update`, `delete`, `destroy` | Skip the confirmation. |
162
+ | `--json` | `list`, `current`, `heads`, `log`, `validate` | Print JSON and nothing else on stdout. |
163
+ | `--local` | `list`, `log` | Show times in the local time zone. The default is UTC. |
164
+
165
+ `prompt --version` prints the version of the tool. It is unrelated to the per-command
166
+ `--version TARGET` option, which names a prompt version.
167
+
168
+ ### Choosing the prompt
169
+
170
+ With `--name`, that prompt is used, and a missing one is `E_PROMPT_NOT_FOUND` with the names
171
+ that exist. Without it, a terminal and exactly one prompt means that prompt is used, and a note
172
+ `Using prompt 'x'` goes to stderr. Anything else is `E_NAME_REQUIRED`, listing the prompts.
173
+ `destroy` never guesses: it always needs `--name`.
174
+
175
+ ### Version targets
176
+
177
+ Wherever a command takes a version, it resolves the text in this order and stops at the first
178
+ match:
179
+
180
+ 1. A relative token, only where the command allows it. `upgrade` takes `head` and `+N`.
181
+ `downgrade` takes `base` and `-N`. N is a positive integer.
182
+ 2. An exact version ID. A trailing `.md` is dropped, so a pasted file name works.
183
+ 3. A tag.
184
+ 4. A unique prefix of one version ID. A prefix that matches several is `E_AMBIGUOUS_TARGET`
185
+ with the candidates listed. Prefixes usually need 9 or more characters.
186
+ 5. Otherwise `E_VERSION_NOT_FOUND`.
187
+
188
+ On `upgrade` and `downgrade`, an argument that starts with a dash and is not `-N` is reported
189
+ as an unknown option.
190
+
191
+ ### Questions and confirmations
192
+
193
+ A run is interactive when stdin is a terminal and neither `--no-input` nor
194
+ `PROMPTVERSE_NO_INPUT=1` is set. Then missing values are asked for, and commands that remove
195
+ things show their plan and ask `Proceed? [y/N]`. Otherwise nothing is asked: a missing value is
196
+ `E_MISSING_OPTION` and a needed confirmation is `E_CONFIRMATION_REQUIRED`, unless `--yes` is
197
+ given. Declining or interrupting a question aborts with exit status 1.
198
+
199
+ ### Output and exit status
200
+
201
+ Results go to stdout. Errors and warnings go to stderr as `error[E_CODE]: message`, with
202
+ indented `hint:` lines, or `warning: ...`. With `--json`, stdout holds only JSON. `validate`
203
+ prints its findings on stdout.
204
+
205
+ | Status | Meaning |
206
+ | --- | --- |
207
+ | 0 | Success, including a command that had nothing to do and a `validate` with only warnings. |
208
+ | 1 | A domain error: a refused operation, an invalid state, `validate` errors, or `current` with no active version. |
209
+ | 2 | Bad usage: an unknown command or option, or a missing argument. |
210
+
211
+ Only `diff` uses color, and only when stdout is a terminal.
212
+
213
+ ## Commands
214
+
215
+ | Command | What it does |
216
+ | --- | --- |
217
+ | [`init`](#prompt-init) | Create `prompts.toml` and the prompts directory. |
218
+ | [`add`](#prompt-add) | Create a prompt with a draft first version. |
219
+ | [`update`](#prompt-update) | Create a draft version derived from another one. |
220
+ | [`delete`](#prompt-delete) | Delete a version, or a version and everything below it. |
221
+ | [`destroy`](#prompt-destroy) | Remove a whole prompt. |
222
+ | [`upgrade`](#prompt-upgrade-and-prompt-downgrade) | Activate a newer version. |
223
+ | [`downgrade`](#prompt-upgrade-and-prompt-downgrade) | Activate an older version. |
224
+ | [`seal`](#prompt-seal) | Lock a version without activating it. |
225
+ | [`list`](#prompt-list) | List the prompts with their counts. |
226
+ | [`current`](#prompt-current) | Print the active version ID. |
227
+ | [`heads`](#prompt-heads) | List the tip of every branch. |
228
+ | [`log`](#prompt-log) | Draw the version graph. |
229
+ | [`diff`](#prompt-diff) | Compare two versions. |
230
+ | [`tag`](#prompt-tag) | Name versions: `set`, `rm` and `list`. |
231
+ | [`rename`](#prompt-rename) | Rename a prompt's folder. |
232
+ | [`sync`](#prompt-sync) | Regenerate the changelog in `PROMPT.md`. |
233
+ | [`validate`](#prompt-validate) | Check the configuration and every prompt. |
234
+
235
+ ### prompt init
236
+
237
+ `prompt init [--dir PATH] [--force]`
238
+
239
+ Creates `prompts.toml` in the current folder and the prompts directory it names, and prints the
240
+ two `.gitignore` lines to add for the tool's temporary files. The command never edits
241
+ `.gitignore`. An existing prompts directory and the files in it are left alone.
242
+
243
+ - `--dir PATH` is the prompts directory, relative to the current folder. It defaults to
244
+ `prompts`, and an interactive run asks for it. It must be a folder inside the project: an
245
+ absolute path, a path that climbs out with `..` and the project folder itself are refused.
246
+ `./prompts/` and `a/../b` are stored as `prompts` and `b`.
247
+ - `--force` overwrites an existing `prompts.toml`. Without it an existing file is
248
+ `E_CONFIG_EXISTS`.
249
+ - If a parent folder already has a config, the command still creates a new project and says so
250
+ on stderr.
251
+
252
+ ### prompt add
253
+
254
+ `prompt add [--name NAME] [--title TEXT] [--description TEXT] [--input NAME[:DESC]]...
255
+ [--output TEXT]... [-m MESSAGE] [--from-file FILE | --text TEXT] [--activate]`
256
+
257
+ Creates a prompt: its folder, a `PROMPT.md`, an empty `VERSION` and a draft root version of type
258
+ `initial`. An interactive run asks for whatever was not given: the name, the title (default: the
259
+ name with `_` and `-` replaced by spaces), the description, each input, each output and the
260
+ message. A script has to give `--name`; the title defaults to the name and the rest are empty.
261
+
262
+ - `--input NAME[:DESC]` declares a placeholder. `--input` and `--output` can be repeated.
263
+ - `-m` is the message of the root version, one line of 1 to 200 characters. The default is
264
+ `Initial version`.
265
+ - `--text` or `--from-file` gives the prompt text, and giving both is a usage error.
266
+ `--from-file -` reads standard input, and either source must be valid UTF-8. A missing final
267
+ newline is added. With neither, the root holds a template line that has to be replaced.
268
+ - `--activate` seals the root and makes it active in the same step. It runs the checks of
269
+ `upgrade`, so the template text and an empty body are refused. Placeholders in the text that are
270
+ not declared as inputs are a warning.
271
+ - A prompt that already exists is `E_PROMPT_EXISTS`.
272
+
273
+ ### prompt update
274
+
275
+ `prompt update [--name NAME] -m MESSAGE [--type TYPE] [--version PARENT] [-y]`
276
+
277
+ Creates a draft version that starts as a copy of another version, body and config. The parent is
278
+ the active version, or `--version PARENT`, which can be any version of the prompt, a draft or one
279
+ on another branch. The active version does not change. Without an active version, `--version` is
280
+ required.
281
+
282
+ - `-m MESSAGE` is required, one line of 1 to 200 characters. An interactive run asks for it.
283
+ - `--type TYPE` must be one of the configured types and cannot be `initial`. The default is
284
+ `default_type` from the configuration.
285
+ - If the prompt already has drafts, the command lists them and asks for confirmation, because a
286
+ new draft starts another line of work. A script needs `-y`.
287
+ - The changelog in `PROMPT.md` gets a line for the new version.
288
+
289
+ ### prompt delete
290
+
291
+ `prompt delete [--name NAME] --version TARGET [--cascade] [-y]`
292
+
293
+ Deletes one version file and repairs everything that pointed at it, in one atomic step. The plan
294
+ is shown first and confirmed unless `-y` is given. Git is the only way back.
295
+
296
+ - The children of the deleted version are given its parent, and their seals stay valid.
297
+ - If the active version is deleted, `VERSION` moves to the nearest sealed ancestor that survives,
298
+ or becomes empty when there is none.
299
+ - Tags that pointed at deleted versions are removed.
300
+ - The changelog is regenerated.
301
+ - `--cascade` deletes the version and everything derived from it, and reparents nothing.
302
+ - A root with exactly one child can be deleted. The child becomes the new root and gets the type
303
+ `initial`. A root with several children is `E_ROOT_HAS_BRANCHES`, a root with `--cascade` is
304
+ `E_ROOT_CASCADE`, and the only version of a prompt is `E_LAST_VERSION`. The last two point
305
+ to `destroy`.
306
+
307
+ ### prompt destroy
308
+
309
+ `prompt destroy --name NAME [-y]`
310
+
311
+ Removes the whole prompt folder, with its versions, tags and `PROMPT.md`. `--name` is always
312
+ required, even when only one prompt exists. The plan lists every file in the folder and marks the
313
+ ones the tool does not manage. An interactive run asks you to type the exact prompt name, and a
314
+ script needs `-y`. Other prompts are untouched, and a damaged prompt can be destroyed.
315
+
316
+ ### prompt upgrade and prompt downgrade
317
+
318
+ `prompt upgrade [TARGET] [--name NAME] [--force]`
319
+ `prompt downgrade [TARGET] [--name NAME] [--force]`
320
+
321
+ These two move the `VERSION` pointer and are the only commands that choose what is live.
322
+ `upgrade` goes to a newer version, meaning a descendant of the active one. `downgrade` goes to
323
+ an older one, meaning an ancestor. A target on another branch is `E_NOT_RELATED`, and a
324
+ target in the wrong direction is `E_WRONG_DIRECTION`. To switch branches, downgrade to the common
325
+ parent and upgrade from there.
326
+
327
+ | Command | Default | Relative targets |
328
+ | --- | --- | --- |
329
+ | `upgrade` | `head` | `head` is the single branch tip reachable from the active version. `+N` follows N child links. |
330
+ | `downgrade` | `-1` | `-N` follows N parent links. `base` is the root. |
331
+
332
+ A relative target that cannot be followed is an error: `E_AT_ROOT` past the root, `E_NO_CHILD` at
333
+ a tip, and `E_MULTIPLE_HEADS` or `E_MULTIPLE_CHILDREN` when there is more than one way to go.
334
+ Their hints list the candidates, and an explicit ID or tag always works. Moving to the version
335
+ that is already active changes nothing.
336
+
337
+ Activating a draft seals it first, and the seal and the new `VERSION` are written together.
338
+ Ancestors of the target are not sealed. Before a draft is activated the command refuses:
339
+
340
+ - text that is still the template, with `E_UNEDITED_TEMPLATE`, which `--force` does not override;
341
+ - an empty body, with `E_EMPTY_BODY`;
342
+ - a body and config identical to the parent's, with `E_UNEDITED_COPY`, which `--force` allows.
343
+
344
+ A sealed target whose text no longer matches its hash is refused with `E_SEAL_MISMATCH`.
345
+ Placeholders in the text that are not declared as inputs are a warning.
346
+
347
+ ### prompt seal
348
+
349
+ `prompt seal --version TARGET [--name NAME] [--force]`
350
+
351
+ Seals a version without touching `VERSION`, so CI or an author can lock a version without making
352
+ it live. The target is a plain target, and an interactive run asks for it. Sealing a sealed
353
+ version says so and changes nothing. `--force` seals an unedited copy of its parent, and it
354
+ re-seals a version whose text was edited after sealing, which is the repair for
355
+ `E_SEAL_MISMATCH`. Repairing the active version prints a warning, because the live text changed.
356
+
357
+ ### prompt list
358
+
359
+ `prompt list [--json] [--local]`
360
+
361
+ One row per prompt, sorted by name: the active version, the number of versions, drafts and heads,
362
+ and the time of the latest version. A prompt with no versions shows `0` and a dash. `--json`
363
+ prints an array of objects.
364
+
365
+ ### prompt current
366
+
367
+ `prompt current [--name NAME] [--json]`
368
+
369
+ Prints the active version ID and nothing else, so it can be used in scripts. With no active
370
+ version it prints `no active version` on stderr and exits 1. `--json` prints the prompt name and
371
+ the version.
372
+
373
+ ### prompt heads
374
+
375
+ `prompt heads [--name NAME] [--json]`
376
+
377
+ Lists the tip of every branch, ordered by ID: the ID, the type and message, whether it is a draft
378
+ or sealed, and `(active)` where it applies. `--json` prints an array of `id`, `type`, `message`,
379
+ `sealed`, `sealed_at` and `active`.
380
+
381
+ ### prompt log
382
+
383
+ `prompt log [--name NAME] [--long] [--tree] [--ascii] [--json] [--local]`
384
+
385
+ Draws the versions as a graph in the style of `git log --graph`: newest first, every version
386
+ above its parent, with one column for each branch that is still open. A fork opens a second
387
+ column and a join line closes it, so a long chain stays in one column. The first line is the
388
+ prompt name and its active ID, then a blank line, then one row per version:
389
+
390
+ ```text
391
+ <graph> <id> (<markers>) [<type>] <message>
392
+ ```
393
+
394
+ The markers are `active`, `head` and `tag: <name>` for each tag, in that order, and the
395
+ brackets are left out when none apply.
396
+
397
+ - `--long` adds `sealed <time>` or `draft`, the creation time taken from the ID, and the file
398
+ path to each version row. `--local` shows those times in the local zone.
399
+ - `--tree` draws the tree from the root instead, with children in ID order, the status column and
400
+ the markers at the end of the row. `--ascii` replaces its box characters with `+--` and `<-`,
401
+ and it is chosen by itself when stdout cannot show UTF-8. The graph is plain ASCII already.
402
+ - `--json` prints the same document for both views: the name, the active ID and every version
403
+ with its parent, children, type, message, seal, tags, `is_head` and `is_active`.
404
+
405
+ ### prompt diff
406
+
407
+ `prompt diff [--name NAME] [--from A] [--to B] [--exit-code]`
408
+
409
+ Shows how the body and the config of two versions differ, as a unified diff with a header that
410
+ names both versions. `--to` defaults to the active version and `--from` to the parent of `--to`.
411
+ Any two versions can be compared, whatever branch they are on. Equal versions print
412
+ `No differences.` With `--exit-code` the status is 1 when they differ and 0 when they do not.
413
+ Without an active version and without `--to`, or with the root as `--to` and no `--from`, the
414
+ command asks for more information. Color is used only on a terminal.
415
+
416
+ ### prompt tag
417
+
418
+ `prompt tag set TAG [--version TARGET] [--name NAME]`
419
+ `prompt tag rm TAG [--name NAME]`
420
+ `prompt tag list [--name NAME] [--json]`
421
+
422
+ Tags are stored in the `TAGS` file of the prompt.
423
+
424
+ - `set` points TAG at a version, creating the tag or moving it. `--version` defaults to the
425
+ active version, and it takes any plain target, including another tag. Setting a tag where it
426
+ already points changes nothing.
427
+ - `rm` removes a tag and says where it pointed. An unknown tag is `E_TAG_NOT_FOUND`, and the
428
+ hint lists the tags that exist.
429
+ - `list` prints each tag, sorted, with the version it points at. `--json` prints an array.
430
+ - A bad or reserved tag name is `E_TAGS_FORMAT`. Tagging a draft is allowed, and `validate` warns
431
+ about it.
432
+
433
+ ### prompt rename
434
+
435
+ `prompt rename --name OLD --to NEW`
436
+
437
+ Renames the prompt's folder and nothing else. No file inside mentions the folder name, so
438
+ versions, tags and `VERSION` stay as they are, and so does the display name in `PROMPT.md`. A
439
+ warning reminds you to update the code and config that refer to the old name. A name that is
440
+ taken is `E_PROMPT_EXISTS`.
441
+
442
+ ### prompt sync
443
+
444
+ `prompt sync [--name NAME]`
445
+
446
+ Regenerates the changelog region of `PROMPT.md` from the version files. Use it after a git merge
447
+ or after editing a version header by hand. Only the region between the markers changes, and
448
+ text around it is kept. With nothing to change it prints `changelog up to date`. Without markers
449
+ nothing is written and a warning says so. A missing `PROMPT.md` or broken front matter is an
450
+ error.
451
+
452
+ ### prompt validate
453
+
454
+ `prompt validate [--name NAME] [--strict] [--json]`
455
+
456
+ Checks the configuration and every prompt, or one with `--name`, without changing anything. Every
457
+ finding is one line on stdout, `error[CODE] <path>: message` or `warning[CODE] <path>: message`,
458
+ or `No problems found.` The status is 1 if there is any error, and with `--strict` also if there
459
+ is any warning. `--json` prints `{"ok": bool, "problems": [...]}`, where each problem has
460
+ `prompt`, `code`, `severity`, `path` and `message`.
461
+
462
+ A file is checked until its first fault, so a version with two problems shows one at a time.
463
+ These errors make the status 1:
464
+
465
+ | Code | Meaning |
466
+ | --- | --- |
467
+ | `E_FRONTMATTER`, `E_FIELD` | A file has broken front matter, or a missing or wrongly typed field. |
468
+ | `E_BAD_VERSION_ID` | A file is named like a version but not a real UTC date and time. |
469
+ | `E_ROOT_COUNT`, `E_PARENT_MISSING`, `E_CYCLE` | The tree does not have exactly one root, a parent does not exist, or parents form a loop. |
470
+ | `E_ACTIVE_MISSING`, `E_ACTIVE_UNSEALED` | `VERSION` names a missing version or a draft. |
471
+ | `E_SEAL_PARTIAL`, `E_SEAL_MISMATCH` | Only one of the two seal fields is present, or a sealed version's text no longer matches its hash. |
472
+ | `E_CONFIG_VALUE` | A `config:` value is not JSON compatible, such as a YAML date. |
473
+ | `E_TAGS_FORMAT`, `E_TAG_MISSING` | `TAGS` is malformed, or a tag points at a version that does not exist. |
474
+ | `E_PROMPT_MD_MISSING` | A prompt has no `PROMPT.md`. |
475
+
476
+ These are warnings, which only fail the run with `--strict`:
477
+
478
+ | Code | Meaning |
479
+ | --- | --- |
480
+ | `W_NO_ACTIVE` | Nothing is active yet. |
481
+ | `W_UNEDITED_COPY` | A draft is identical to its parent. |
482
+ | `W_ID_ORDER` | A version's ID is not later than its parent's, usually a wrong clock. |
483
+ | `W_UNDECLARED_INPUT`, `W_UNUSED_INPUT` | The active text uses a placeholder that is not declared, or a declared input is not used. |
484
+ | `W_CHANGELOG_MARKERS`, `W_CHANGELOG_STALE` | The changelog markers are missing, or the region differs from what `sync` would write. |
485
+ | `W_TAG_DRAFT` | A tag points at a draft. |
486
+ | `W_UNKNOWN_KEY` | A key the tool does not know in a config or front matter. |
487
+ | `W_STRAY_FILE`, `W_STALE_TEMP` | A file in a prompt folder the tool does not use, or a temporary file left by an interrupted write. |
488
+
489
+ ## Configuration
490
+
491
+ The project is configured by a `prompts.toml` file, which `prompt init` writes. The same keys
492
+ can instead sit under a `[tool.promptverse]` table in `pyproject.toml`.
493
+
494
+ | Key | Required | Meaning |
495
+ | --- | --- | --- |
496
+ | `format_version` | yes | The file format version. This release reads and writes `1`. A larger number stops every command with `E_FORMAT_TOO_NEW` and asks you to upgrade promptverse-py. |
497
+ | `dir` | yes | The prompts directory, relative to the folder that holds the config file. It must stay inside that folder. A folder that does not exist yet is fine, and one that is a file is an error. |
498
+ | `types` | no | The values `--type` accepts. Each is a lower case letter followed by up to 23 letters, digits, `_` or `-`, and `initial` is reserved for roots. The default is `fix`, `feature`, `refactor` and `chore`. |
499
+ | `default_type` | no | The type `update` uses when `--type` is left out. It must be one of `types`. The default is `fix`. |
500
+
501
+ Unknown keys are kept and reported by `validate` as a warning.
502
+
503
+ **Finding the config.** The first match wins:
504
+
505
+ 1. the file given with `--config`;
506
+ 2. the file named by the `PROMPTVERSE_CONFIG` environment variable;
507
+ 3. a search from the current folder up to the root of the file system, where each folder is
508
+ checked for `prompts.toml` first, then for a `pyproject.toml` that has a `[tool.promptverse]`
509
+ table.
510
+
511
+ A relative path from 1 or 2 is taken from the current folder. Because `dir` is relative to the
512
+ config file, every command works the same from any subfolder of the project. If nothing is found
513
+ the error is `E_NO_CONFIG` with a hint to run `prompt init`.
514
+
515
+ ### Environment variables
516
+
517
+ | Variable | Effect |
518
+ | --- | --- |
519
+ | `PROMPTVERSE_CONFIG` | The config file to use, as with `--config`. The option wins over the variable. |
520
+ | `PROMPTVERSE_NO_INPUT` | Set to `1` to never ask a question, as with `--no-input`. |
521
+ | `NO_COLOR` | Set to anything to turn color off. |
522
+ | `PROMPTVERSE_FAKE_NOW` | A fixed time in version ID format. It exists for tests. |
523
+
524
+ ## Working with git
525
+
526
+ Commit `prompts.toml` and the prompts directory like any other source. Add the two lines that
527
+ `prompt init` prints to `.gitignore`, so the temporary files of an interrupted write are never
528
+ committed:
529
+
530
+ ```text
531
+ .promptverse-tmp-*
532
+ .promptverse-bak-*
533
+ ```
534
+
535
+ A fresh clone is a complete setup. Nothing has to be initialized, because every command reads
536
+ only these files.
537
+
538
+ A new version is a new file with a unique name, so two branches that each add a version do not
539
+ conflict on it. A merge can conflict in two files that both branches changed: the changelog
540
+ region of `PROMPT.md` and `VERSION`. To resolve it, take the changelog from either side and run
541
+ `prompt sync`, which rebuilds it from the version files. Then keep one version ID in `VERSION`
542
+ and remove the conflict markers. `prompt validate` reports a `VERSION` that still holds markers.
543
+
544
+ Deleting a version cannot be undone by the tool. Git is the way back.
545
+
546
+ ## Safety
547
+
548
+ - **Atomic writes.** A command that changes several files, such as an upgrade that seals a draft
549
+ and moves `VERSION`, writes them as one operation. New content goes to temporary files, the
550
+ originals are moved aside, and everything is moved into place. If any step fails, the steps
551
+ are undone and the command reports `E_WRITE_FAILED`. A process killed in between can leave
552
+ `.promptverse-tmp-*` or `.promptverse-bak-*` files. `validate` warns about them and nothing
553
+ deletes them for you.
554
+ - **Refusals change nothing.** A command that is refused leaves the files as they were, and a
555
+ dry run prints its plan and writes nothing.
556
+ - **Seals.** The `sha256` covers the body and the config, so an edit to a version that is live is
557
+ found by `validate` and refused by `upgrade`, `downgrade` and `seal` until you repair it
558
+ deliberately with `seal --force`.
559
+ - **Paths.** Prompt names, tag names and version targets are checked against their patterns
560
+ before any path is built, so `../x` and `a/b` never reach the file system. A prompt folder that
561
+ is a link leading outside the prompts directory is refused with `E_PATH_ESCAPE`.
562
+ - **Read-only commands.** `list`, `current`, `heads`, `log`, `diff` and `validate` never write.
563
+ A file that cannot be read is reported as a warning and the rest is still shown.
564
+
565
+ ## Development
566
+
567
+ The project uses [uv](https://docs.astral.sh/uv/) and needs Python 3.12 or newer.
568
+
569
+ ```console
570
+ uv sync
571
+ uv run pytest
572
+ uv run ruff check .
573
+ uv run ruff format --check .
574
+ uv run mypy
575
+ ```
576
+
577
+ The tests need 80% coverage, which `pytest` enforces. `mypy` runs in strict mode. A
578
+ `pre-commit` configuration runs the formatter and the checks before each commit.
579
+
580
+ The package is in `src/promptverse`. The modules that decide things, such as `graph`, `graphlog`,
581
+ `resolve`, `frontmatter`, `hashing`, `changelog` and `validate`, take data in and return data
582
+ out. Files are read and written in a few places only (`store`, `apply` and `config`), and the
583
+ commands in `cli` are thin layers over them.
584
+
585
+ ## License
586
+
587
+ promptverse is released under the MIT license. See the `LICENSE` file.