ticket-docket 1.3.0__tar.gz → 1.5.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 (58) hide show
  1. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/PKG-INFO +23 -1
  2. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/README.md +21 -0
  3. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/pyproject.toml +1 -0
  4. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/__init__.py +1 -1
  5. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/cli/__init__.py +18 -2
  6. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/cli/commands.py +127 -25
  7. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/cli/grammar.py +55 -8
  8. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/config.py +8 -0
  9. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/deploy.py +5 -2
  10. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/graph.py +95 -1
  11. ticket_docket-1.5.0/src/docket/core/handoff.py +106 -0
  12. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/inputs.py +2 -2
  13. ticket_docket-1.5.0/src/docket/core/resources.py +33 -0
  14. ticket_docket-1.5.0/src/docket/core/roadmap.py +87 -0
  15. ticket_docket-1.5.0/src/docket/core/templating.py +61 -0
  16. ticket_docket-1.5.0/src/docket/docs/roadmap.md.jinja +22 -0
  17. ticket_docket-1.5.0/src/docket/docs/writingTicketsOffsite.md.jinja +139 -0
  18. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/server.py +4 -11
  19. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/templates/CLAUDE.md +12 -0
  20. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/templates/docket.toml +4 -0
  21. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_cli.py +249 -4
  22. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_config.py +35 -1
  23. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_graph.py +169 -2
  24. ticket_docket-1.5.0/tests/test_handoff.py +146 -0
  25. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_inputs.py +5 -5
  26. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_packaging.py +2 -0
  27. ticket_docket-1.5.0/tests/test_roadmap.py +173 -0
  28. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/.gitignore +0 -0
  29. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/LICENSE +0 -0
  30. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/scripts/bumpVersion.py +0 -0
  31. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/cli/__main__.py +0 -0
  32. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/cli/output.py +0 -0
  33. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/__init__.py +0 -0
  34. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/atomic.py +0 -0
  35. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/errors.py +0 -0
  36. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/fields.py +0 -0
  37. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/ids.py +0 -0
  38. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/lock.py +0 -0
  39. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/mermaid.py +0 -0
  40. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/store.py +0 -0
  41. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/ticket.py +0 -0
  42. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/titles.py +0 -0
  43. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/core/validate.py +0 -0
  44. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/src/docket/py.typed +0 -0
  45. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/concurrencyWorker.py +0 -0
  46. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/conftest.py +0 -0
  47. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_atomic.py +0 -0
  48. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_bumpVersion.py +0 -0
  49. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_concurrency.py +0 -0
  50. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_deploy.py +0 -0
  51. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_ids.py +0 -0
  52. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_lock.py +0 -0
  53. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_mermaid.py +0 -0
  54. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_server.py +0 -0
  55. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_store.py +0 -0
  56. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_ticket.py +0 -0
  57. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_titles.py +0 -0
  58. {ticket_docket-1.3.0 → ticket_docket-1.5.0}/tests/test_validate.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ticket-docket
3
- Version: 1.3.0
3
+ Version: 1.5.0
4
4
  Summary: A per-repo ticketing system that is plain markdown for humans and structured MCP for agents
5
5
  Project-URL: Homepage, https://github.com/Sorcerio/Docket
6
6
  Project-URL: Repository, https://github.com/Sorcerio/Docket
@@ -21,6 +21,7 @@ Classifier: Topic :: Utilities
21
21
  Classifier: Typing :: Typed
22
22
  Requires-Python: >=3.12
23
23
  Requires-Dist: filelock>=3.32.2
24
+ Requires-Dist: jinja2>=3.1.6
24
25
  Requires-Dist: mcp<3,>=2
25
26
  Requires-Dist: pyyaml>=6.0.3
26
27
  Requires-Dist: rich-argparse>=1.8.0
@@ -132,8 +133,14 @@ docket list [-s todo] [-k CORE] [-m 2] [-r]
132
133
  docket graph [-i CORE-14 | -k GEN | -s todo] [-o FILE]
133
134
  docket key list | add KEY "desc" [-r TEXT] | remove KEY
134
135
  docket validate | deploy PATH | upgrade PATH
136
+ docket docs handoff [-p] [-o FILE]
137
+ docket docs roadmap [CORE-14 | GEN | todo] [-m N] [-p] [-o FILE]
135
138
  ```
136
139
 
140
+ `docs` writes a file: `handoff.md` and `roadmap.md` at the repo root. `-p/--print` sends it to stdout instead, `-o` picks another path, and passing both writes the file and prints it. `graph` is the exception, printing unless you ask for a file, because its output is usually piped.
141
+
142
+ `docket docs roadmap` is the committable picture of the graph: a markdown file wrapping a mermaid diagram, plus the legend a renderer that ignores styling would otherwise leave you without. Past `maxRoadmapNodes` it drops the completed tickets furthest from the work still open, and never drops an open ticket, so the diagram stays readable without losing what is ahead.
143
+
137
144
  `-r` replaces the dependency list. `-ra` and `-rr` edit the one already there. Both in one call is refused.
138
145
 
139
146
  A ticket is ready when every id in its `requires` names a ticket that is `done`. A missing dependency blocks, and a `done` ticket is never ready, so `docket list -r` is the set you can pick up right now.
@@ -158,6 +165,18 @@ Every short flag has a long form (`-k/--key`, `-p/--priority`, `-m/--priority-ma
158
165
  | `validate()` | Structured findings. |
159
166
  | `set_metadata(id, key, value?)` | One entry at a time, leaving every other key alone. |
160
167
 
168
+ ## Writing Tickets Elsewhere
169
+
170
+ ```bash
171
+ docket docs handoff > brief.md
172
+ ```
173
+
174
+ Prints a brief written for a chat system that has no access to your repository. Paste it in, describe the project, and it writes ticket files by hand.
175
+
176
+ The brief is rendered against this repository, so it names your registered keys, the first free number under each, your priority band, and the directory the files belong in. Nothing is left for it to guess.
177
+
178
+ Save what comes back into your todo directory and run `docket validate`. That is the whole import step, because every rule an importer would need already lives there. Tickets written somewhere else are checked by the same code as the ones written here.
179
+
161
180
  ## Key Ticket Rules
162
181
 
163
182
  1. **Dependencies point one way.** A ticket declares `requires` and nothing else. Reverse edges are derived, so a one-sided edge is impossible rather than merely detectable.
@@ -175,6 +194,7 @@ doneDir = "done"
175
194
  defaultPriority = 2
176
195
  maxPriority = 4
177
196
  lockTimeout = 5.0
197
+ maxRoadmapNodes = 200
178
198
 
179
199
  [keys]
180
200
  # Primary arch
@@ -185,6 +205,8 @@ META = "campaign and progression"
185
205
 
186
206
  A key's rationale becomes the comment above it, and removing the key takes the comment with it. The status vocabulary is deliberately not configurable.
187
207
 
208
+ `maxRoadmapNodes` is how many nodes `docket docs roadmap` aims to draw, and `0` turns the ceiling off.
209
+
188
210
  `docket deploy` never rewrites an existing `.docket.toml`. Run `docket upgrade .` later to refresh the template and repair the server entry without touching your config or tickets.
189
211
 
190
212
  ## Concurrent Access
@@ -101,8 +101,14 @@ docket list [-s todo] [-k CORE] [-m 2] [-r]
101
101
  docket graph [-i CORE-14 | -k GEN | -s todo] [-o FILE]
102
102
  docket key list | add KEY "desc" [-r TEXT] | remove KEY
103
103
  docket validate | deploy PATH | upgrade PATH
104
+ docket docs handoff [-p] [-o FILE]
105
+ docket docs roadmap [CORE-14 | GEN | todo] [-m N] [-p] [-o FILE]
104
106
  ```
105
107
 
108
+ `docs` writes a file: `handoff.md` and `roadmap.md` at the repo root. `-p/--print` sends it to stdout instead, `-o` picks another path, and passing both writes the file and prints it. `graph` is the exception, printing unless you ask for a file, because its output is usually piped.
109
+
110
+ `docket docs roadmap` is the committable picture of the graph: a markdown file wrapping a mermaid diagram, plus the legend a renderer that ignores styling would otherwise leave you without. Past `maxRoadmapNodes` it drops the completed tickets furthest from the work still open, and never drops an open ticket, so the diagram stays readable without losing what is ahead.
111
+
106
112
  `-r` replaces the dependency list. `-ra` and `-rr` edit the one already there. Both in one call is refused.
107
113
 
108
114
  A ticket is ready when every id in its `requires` names a ticket that is `done`. A missing dependency blocks, and a `done` ticket is never ready, so `docket list -r` is the set you can pick up right now.
@@ -127,6 +133,18 @@ Every short flag has a long form (`-k/--key`, `-p/--priority`, `-m/--priority-ma
127
133
  | `validate()` | Structured findings. |
128
134
  | `set_metadata(id, key, value?)` | One entry at a time, leaving every other key alone. |
129
135
 
136
+ ## Writing Tickets Elsewhere
137
+
138
+ ```bash
139
+ docket docs handoff > brief.md
140
+ ```
141
+
142
+ Prints a brief written for a chat system that has no access to your repository. Paste it in, describe the project, and it writes ticket files by hand.
143
+
144
+ The brief is rendered against this repository, so it names your registered keys, the first free number under each, your priority band, and the directory the files belong in. Nothing is left for it to guess.
145
+
146
+ Save what comes back into your todo directory and run `docket validate`. That is the whole import step, because every rule an importer would need already lives there. Tickets written somewhere else are checked by the same code as the ones written here.
147
+
130
148
  ## Key Ticket Rules
131
149
 
132
150
  1. **Dependencies point one way.** A ticket declares `requires` and nothing else. Reverse edges are derived, so a one-sided edge is impossible rather than merely detectable.
@@ -144,6 +162,7 @@ doneDir = "done"
144
162
  defaultPriority = 2
145
163
  maxPriority = 4
146
164
  lockTimeout = 5.0
165
+ maxRoadmapNodes = 200
147
166
 
148
167
  [keys]
149
168
  # Primary arch
@@ -154,6 +173,8 @@ META = "campaign and progression"
154
173
 
155
174
  A key's rationale becomes the comment above it, and removing the key takes the comment with it. The status vocabulary is deliberately not configurable.
156
175
 
176
+ `maxRoadmapNodes` is how many nodes `docket docs roadmap` aims to draw, and `0` turns the ceiling off.
177
+
157
178
  `docket deploy` never rewrites an existing `.docket.toml`. Run `docket upgrade .` later to refresh the template and repair the server entry without touching your config or tickets.
158
179
 
159
180
  ## Concurrent Access
@@ -30,6 +30,7 @@ classifiers = [
30
30
  ]
31
31
  dependencies = [
32
32
  "filelock>=3.32.2",
33
+ "jinja2>=3.1.6",
33
34
  "mcp>=2,<3",
34
35
  "pyyaml>=6.0.3",
35
36
  "rich>=15.0.0",
@@ -8,4 +8,4 @@ A per-repo ticketing system that is plain markdown for humans and structured MCP
8
8
 
9
9
  # No type check to comply with hatch's requirements.
10
10
  # Do not re-add.
11
- __version__ = "1.3.0"
11
+ __version__ = "1.5.0"
@@ -14,30 +14,36 @@ from typing import Optional
14
14
 
15
15
  from docket.cli.commands import (
16
16
  commandDeploy,
17
+ commandDocs,
17
18
  commandGraph,
18
19
  commandKey,
19
20
  commandList,
20
21
  commandMeta,
21
22
  commandNew,
23
+ commandRoadmap,
22
24
  commandSet,
23
25
  commandShow,
24
26
  commandStatus,
25
27
  commandStatusRead,
26
28
  commandTicket,
27
29
  commandValidate,
30
+ documentPath,
31
+ emitDocument,
32
+ requireScopeKey,
28
33
  )
29
34
  from docket.cli.grammar import (
30
35
  CLEAR_SENTINEL,
31
36
  EXIT_INVALID,
32
37
  EXIT_OK,
33
38
  EXIT_USAGE,
34
- OUT_ARGUMENT,
39
+ OUTPUT_ARGUMENT,
35
40
  PROGRAM_NAME,
36
41
  TICKET_COMMAND,
37
42
  TOKEN_ID,
38
43
  TOKEN_KEY,
39
44
  TOKEN_PRIORITY,
40
45
  TOKEN_STATUS,
46
+ addScopeArguments,
41
47
  buildParser,
42
48
  classifyToken,
43
49
  describeKeys,
@@ -62,7 +68,7 @@ __all__: list[str] = [
62
68
  "EXIT_INVALID",
63
69
  "EXIT_OK",
64
70
  "EXIT_USAGE",
65
- "OUT_ARGUMENT",
71
+ "OUTPUT_ARGUMENT",
66
72
  "PROGRAM_NAME",
67
73
  "STATUS_STYLES",
68
74
  "TICKET_COMMAND",
@@ -71,15 +77,18 @@ __all__: list[str] = [
71
77
  "TOKEN_PRIORITY",
72
78
  "TOKEN_STATUS",
73
79
  "Output",
80
+ "addScopeArguments",
74
81
  "buildContextTable",
75
82
  "buildParser",
76
83
  "classifyToken",
77
84
  "commandDeploy",
85
+ "commandDocs",
78
86
  "commandGraph",
79
87
  "commandKey",
80
88
  "commandList",
81
89
  "commandMeta",
82
90
  "commandNew",
91
+ "commandRoadmap",
83
92
  "commandSet",
84
93
  "commandShow",
85
94
  "commandStatus",
@@ -89,10 +98,13 @@ __all__: list[str] = [
89
98
  "describeKeys",
90
99
  "describePriorities",
91
100
  "dispatch",
101
+ "documentPath",
102
+ "emitDocument",
92
103
  "main",
93
104
  "parseEditIdList",
94
105
  "parseIdList",
95
106
  "relativeToRoot",
107
+ "requireScopeKey",
96
108
  "resolveGraphScope",
97
109
  "resolveListFilters",
98
110
  "rewriteIdFirst",
@@ -150,6 +162,10 @@ def dispatch(args: argparse.Namespace, config: Optional[Config], output: Output)
150
162
  if args.command in ("deploy", "upgrade"):
151
163
  return commandDeploy(args, output)
152
164
 
165
+ # A shipped document renders with or without a configuration, so it must not be gated behind discovering one either.
166
+ if args.command == "docs":
167
+ return commandDocs(args, config, output)
168
+
153
169
  # Every other command works against the configuration governing the current directory. Discovery is repeated when the parser was built without one, so the reason it could not be found is reported by the code that knows it.
154
170
  store: Store = Store(config if config is not None else discoverConfig())
155
171
 
@@ -10,17 +10,20 @@ No rules live here either. A handler decides what to say, never what is true.
10
10
 
11
11
  import argparse
12
12
  from pathlib import Path
13
+ from typing import Optional
13
14
 
14
15
  from rich.table import Table
15
16
  from rich.text import Text
16
17
 
17
- from docket.cli.grammar import EXIT_INVALID, EXIT_OK, EXIT_USAGE, OUT_ARGUMENT, parseEditIdList, parseIdList, resolveGraphScope, resolveListFilters
18
+ from docket.cli.grammar import EXIT_INVALID, EXIT_OK, EXIT_USAGE, OUTPUT_ARGUMENT, parseEditIdList, parseIdList, resolveGraphScope, resolveListFilters
18
19
  from docket.cli.output import STATUS_STYLES, Output, buildContextTable, relativeToRoot
19
- from docket.core.config import Config
20
+ from docket.core.config import Config, discoverConfig
20
21
  from docket.core.deploy import DeployReport, deploy, upgrade
21
- from docket.core.graph import Readiness, ResolvedGraph, dependencyContext, readyTickets, resolveGraph, subgraphForId, subgraphForKey, subgraphForStatus, ticketReadiness
22
+ from docket.core.handoff import HANDOFF_FILENAME, renderHandoff
23
+ from docket.core.graph import Readiness, ResolvedGraph, dependencyContext, readyTickets, resolveGraph, scopeGraph, ticketReadiness
22
24
  from docket.core.inputs import requireWritableFile, writeFile
23
25
  from docket.core.mermaid import renderGraph
26
+ from docket.core.roadmap import ROADMAP_FILENAME, Roadmap, buildRoadmap
24
27
  from docket.core.store import Store, TicketResult, TicketSet
25
28
  from docket.core.ticket import STATUSES, Ticket
26
29
  from docket.core.validate import SEVERITY_ERROR, ValidationReport, validate
@@ -327,32 +330,13 @@ def commandGraph(args: argparse.Namespace, store: Store, output: Output) -> int:
327
330
 
328
331
  ticketId, key, status = resolveGraphScope(args.scope, args.id, args.key, args.status)
329
332
 
330
- graph: ResolvedGraph = resolveGraph(store.loadAll())
333
+ requireScopeKey(store, key)
331
334
 
332
- # Scope the graph when asked. At most one of the three survives resolution.
333
- if ticketId is not None:
334
- graph = subgraphForId(graph, ticketId)
335
- elif key is not None:
336
- # For the same reason as `list`, an unregistered key here would render an empty graph rather than admitting the key does not exist.
337
- store.config.requireKnownKey(key)
338
- graph = subgraphForKey(graph, key)
339
- elif status is not None:
340
- # No equivalent check, because the vocabulary is fixed and both spellings are checked against it before they arrive. An empty result here is a true answer rather than a typo.
341
- graph = subgraphForStatus(graph, status)
335
+ graph: ResolvedGraph = scopeGraph(resolveGraph(store.loadAll()), ticketId, key, status)
342
336
 
343
337
  source: str = renderGraph(graph)
344
338
 
345
- if args.out is not None:
346
- # Check the destination before rendering work is spent on it, and translate whatever the filesystem still refuses, so no write failure reaches the user as a traceback.
347
- outPath: Path = writeFile(requireWritableFile(args.out, OUT_ARGUMENT), source, OUT_ARGUMENT)
348
- output.print(f"Wrote {outPath}")
349
-
350
- return EXIT_OK
351
-
352
- # Straight to stdout with no styling, so a redirect captures exactly the mermaid source.
353
- output.raw(source)
354
-
355
- return EXIT_OK
339
+ return emitDocument(source, args.output, OUTPUT_ARGUMENT, output)
356
340
 
357
341
 
358
342
  def commandKey(args: argparse.Namespace, store: Store, output: Output) -> int:
@@ -429,6 +413,124 @@ def commandValidate(args: argparse.Namespace, store: Store, output: Output) -> i
429
413
  return EXIT_INVALID if report.errors else EXIT_OK
430
414
 
431
415
 
416
+ def requireScopeKey(store: Store, key: Optional[str]) -> None:
417
+ """
418
+ Refuse a scope naming a key the repository has not registered.
419
+
420
+ Scoping to an unknown key would draw an empty graph, which reads as an answer rather than as the typo it is. `list` refuses one for the same reason. A status needs no equivalent check, since the vocabulary is fixed and both spellings are checked against it before they arrive here, so an empty result there is a true answer.
421
+
422
+ store: The store holding the registry.
423
+ key: The key the scope named, or `None` when it named something else.
424
+ """
425
+
426
+ if key is not None:
427
+ store.config.requireKnownKey(key)
428
+
429
+
430
+ def documentPath(config: Optional[Config], filename: str) -> Path:
431
+ """
432
+ Place a shipped document's prescribed destination.
433
+
434
+ A document belongs to the repository it describes, so it lands beside the configuration that governs it. Run outside a repository there is no such place, and the working directory is the only honest fallback, which is the same reasoning that lets the brief render without a configuration at all.
435
+
436
+ config: The configuration governing the document, or `None` when none was found.
437
+ filename: What the document is called.
438
+
439
+ Returns the path to write to unless the caller names another.
440
+ """
441
+
442
+ return (config.repoRoot if config is not None else Path.cwd()) / filename
443
+
444
+
445
+ def emitDocument(text: str, destination: Optional[str], name: str, output: Output, defaultPath: Optional[Path] = None, toPrint: bool = False, note: str = "") -> int:
446
+ """
447
+ Send rendered text to the file it belongs in, to stdout, or to both.
448
+
449
+ Every command that renders text leaves through here rather than each growing its own copy of the rule. What differs between them is only whether they have a file to fall back on: a document does and so writes one unasked, while `graph` does not and so stays a pipe.
450
+
451
+ A named destination always wins. Without one, the prescribed path is written unless printing was asked for instead, and asking for both does both.
452
+
453
+ text: The rendered text to emit.
454
+ destination: The path the caller named, or `None` when none was named.
455
+ name: What to name the destination in an error message, for example `--output path`.
456
+ output: Where to write.
457
+ defaultPath: The path to write when none was named, or `None` to leave stdout as the only destination.
458
+ toPrint: Whether to print the text to stdout.
459
+ note: Anything to append to the confirmation line, already spaced and parenthesized.
460
+
461
+ Returns the process exit code.
462
+ """
463
+
464
+ chosen: Optional[str] = destination
465
+
466
+ # Fall back to the prescribed path, which printing replaces rather than adds to, so a bare print stays clean enough to pipe.
467
+ if chosen is None and defaultPath is not None and not toPrint:
468
+ chosen = str(defaultPath)
469
+
470
+ if chosen is not None:
471
+ # Check the destination before the filesystem is touched, and translate whatever it still refuses, so no write failure reaches the user as a traceback.
472
+ outPath: Path = writeFile(requireWritableFile(chosen, name), text, name)
473
+ output.print(f"Wrote {outPath}{note}")
474
+
475
+ # Straight to stdout with no styling, so a redirect captures exactly what was rendered and nothing else. With nothing written this is the whole of the command's output.
476
+ if toPrint or chosen is None:
477
+ output.raw(text)
478
+
479
+ return EXIT_OK
480
+
481
+
482
+ def commandDocs(args: argparse.Namespace, config: Optional[Config], output: Output) -> int:
483
+ """
484
+ Write a document docket ships, rendered for this repository.
485
+
486
+ args: The parsed arguments.
487
+ config: The configuration governing the current directory, or `None` when none was found.
488
+ output: Where to write.
489
+
490
+ Returns the process exit code.
491
+ """
492
+
493
+ if args.docsCommand == "handoff":
494
+ # A configuration is what lets the brief name real keys and real numbering, but its absence is a state the document handles rather than an error, since a person may be anywhere when they go to fetch it.
495
+ store: Optional[Store] = Store(config) if config is not None else None
496
+
497
+ return emitDocument(renderHandoff(store), args.output, OUTPUT_ARGUMENT, output, documentPath(config, HANDOFF_FILENAME), args.toPrint)
498
+
499
+ if args.docsCommand == "roadmap":
500
+ # The roadmap is nothing but this repository's own tickets, so unlike the brief it cannot be rendered without one. Discovery is repeated here so the reason a configuration could not be found is reported by the code that knows it.
501
+ return commandRoadmap(args, Store(config if config is not None else discoverConfig()), output)
502
+
503
+ output.error("Expected one of: handoff, roadmap.")
504
+
505
+ return EXIT_USAGE
506
+
507
+
508
+ def commandRoadmap(args: argparse.Namespace, store: Store, output: Output) -> int:
509
+ """
510
+ Write the dependency graph as a markdown document with an embedded mermaid diagram.
511
+
512
+ args: The parsed arguments.
513
+ store: The store to read from.
514
+ output: Where to write.
515
+
516
+ Returns the process exit code.
517
+ """
518
+
519
+ ticketId, key, status = resolveGraphScope(args.scope, args.id, args.key, args.status)
520
+
521
+ requireScopeKey(store, key)
522
+
523
+ # The flag overrides the configured ceiling for one run, which is what lets a repository render a bigger diagram once without editing its configuration.
524
+ maxNodes: int = store.config.maxRoadmapNodes if args.maxNodes is None else args.maxNodes
525
+
526
+ roadmap: Roadmap = buildRoadmap(store, ticketId=ticketId, key=key, status=status, maxNodes=maxNodes)
527
+
528
+ # The document says nothing about what the ceiling dropped, so the person who ran the command is told here instead. Otherwise a diagram that quietly stopped showing its history gives no hint of why.
529
+ note: str = f" ({roadmap.dropped} completed ticket(s) omitted)" if roadmap.dropped else ""
530
+
531
+ return emitDocument(roadmap.document, args.output, OUTPUT_ARGUMENT, output, documentPath(store.config, ROADMAP_FILENAME), args.toPrint, note)
532
+
533
+
432
534
  def commandDeploy(args: argparse.Namespace, output: Output) -> int:
433
535
  """
434
536
  Install docket into a repository, or refresh what is already deployed there.
@@ -16,7 +16,9 @@ from rich_argparse import RichHelpFormatter
16
16
  from docket import __version__
17
17
  from docket.core.config import Config, discoverConfig
18
18
  from docket.core.errors import ConflictingArgumentsError, DocketError, InvalidArgumentError, InvalidIdError
19
+ from docket.core.handoff import HANDOFF_FILENAME
19
20
  from docket.core.ids import isValidId, isValidKey
21
+ from docket.core.roadmap import ROADMAP_FILENAME
20
22
  from docket.core.ticket import STATUSES
21
23
 
22
24
  # MARK: Constants
@@ -41,8 +43,8 @@ TOKEN_PRIORITY: str = "priority"
41
43
  # The word that clears a comma-separated list argument. An id can never collide with it, since every id is an uppercase key followed by a hyphen and a number.
42
44
  CLEAR_SENTINEL: str = "none"
43
45
 
44
- # How the graph destination is named when a message has to talk about it.
45
- OUT_ARGUMENT: str = "--out path"
46
+ # How a destination is named when a message has to talk about it. The graph and the shipped documents share the flag, so they share its name too.
47
+ OUTPUT_ARGUMENT: str = "--output path"
46
48
 
47
49
  # MARK: Functions
48
50
 
@@ -260,12 +262,8 @@ def buildParser(config: Optional[Config] = None) -> argparse.ArgumentParser:
260
262
  listParser.add_argument("-r", "--ready", action="store_true", help="Keep only tickets whose dependencies are all done. A done ticket is never ready, so this never shows one.")
261
263
 
262
264
  graphParser: argparse.ArgumentParser = commands.add_parser("graph", help="Render the dependency graph as mermaid source.", formatter_class=RichHelpFormatter)
263
- graphParser.add_argument("scope", nargs="?", metavar="SCOPE", help=f"What to scope to, read from its own shape: a ticket id, a key, or a status ({', '.join(STATUSES)}). The flags below are the same three, named explicitly.")
264
- graphScope = graphParser.add_mutually_exclusive_group()
265
- graphScope.add_argument("-i", "--id", help="Scope to one ticket's ancestors and descendants.")
266
- graphScope.add_argument("-k", "--key", help=f"Scope to one key, plus its immediate cross-key neighbors. {keyOptions}")
267
- graphScope.add_argument("-s", "--status", choices=STATUSES, help="Scope to the tickets with this status alone. Nothing outside it is borrowed, so an edge survives only when both of its ends carry the status.")
268
- graphParser.add_argument("-o", "--out", help="Write to a file rather than to stdout.")
265
+ addScopeArguments(graphParser, keyOptions)
266
+ graphParser.add_argument("-o", "--output", help="Write to a file rather than to stdout.")
269
267
 
270
268
  keyParser: argparse.ArgumentParser = commands.add_parser("key", help="Inspect and manage the key registry.", formatter_class=RichHelpFormatter)
271
269
  keyCommands = keyParser.add_subparsers(dest="keyCommand", metavar="SUBCOMMAND")
@@ -280,6 +278,37 @@ def buildParser(config: Optional[Config] = None) -> argparse.ArgumentParser:
280
278
  keyRemoveParser: argparse.ArgumentParser = keyCommands.add_parser("remove", help="Remove a key no ticket uses.", formatter_class=RichHelpFormatter)
281
279
  keyRemoveParser.add_argument("key", help=f"The key to remove. {keyOptions}")
282
280
 
281
+ # Documents docket ships, rendered against this repository. This is a group rather than a bare command because each one is read somewhere else, and more than one such document was always plausible.
282
+ docsParser: argparse.ArgumentParser = commands.add_parser("docs", help="Write a document docket ships, rendered for this repository.", formatter_class=RichHelpFormatter)
283
+ docsCommands = docsParser.add_subparsers(dest="docsCommand", metavar="SUBCOMMAND")
284
+
285
+ # Every document reaches its reader the same way, so the destination is declared once here and inherited by each one rather than repeated per document. A document is a file by default, unlike `graph`, because it is written to be kept and read later rather than piped into something else.
286
+ docsOutput: argparse.ArgumentParser = argparse.ArgumentParser(add_help=False)
287
+ docsOutput.add_argument("-o", "--output", help="Write to this file instead of the one the document is named for.")
288
+ docsOutput.add_argument("-p", "--print", dest="toPrint", action="store_true", help="Print to stdout instead of writing the file. Combined with -o/--output it does both, writing the file and printing it.")
289
+
290
+ docsCommands.add_parser(
291
+ "handoff",
292
+ help=f"Write the brief that teaches a chat system with no access to this repository how to write tickets for it by hand. Lands in {HANDOFF_FILENAME}.",
293
+ parents=[docsOutput],
294
+ formatter_class=RichHelpFormatter,
295
+ )
296
+
297
+ roadmapParser: argparse.ArgumentParser = docsCommands.add_parser(
298
+ "roadmap",
299
+ help=f"Write the dependency graph as a markdown document with an embedded mermaid diagram, for committing alongside the tickets. Lands in {ROADMAP_FILENAME}.",
300
+ parents=[docsOutput],
301
+ formatter_class=RichHelpFormatter,
302
+ )
303
+ addScopeArguments(roadmapParser, keyOptions)
304
+ roadmapParser.add_argument(
305
+ "-m",
306
+ "--max-nodes",
307
+ type=int,
308
+ dest="maxNodes",
309
+ help="How many nodes to aim for, overriding the configured maxRoadmapNodes. Past it the completed tickets furthest from the work still open are dropped, and open tickets are never dropped. Pass 0 for no ceiling.",
310
+ )
311
+
283
312
  commands.add_parser("validate", help="Run every integrity rule.", formatter_class=RichHelpFormatter)
284
313
 
285
314
  deployParser: argparse.ArgumentParser = commands.add_parser("deploy", help="Install docket into a repository.", formatter_class=RichHelpFormatter)
@@ -291,6 +320,24 @@ def buildParser(config: Optional[Config] = None) -> argparse.ArgumentParser:
291
320
  return parser
292
321
 
293
322
 
323
+ def addScopeArguments(parser: argparse.ArgumentParser, keyOptions: str) -> None:
324
+ """
325
+ Add the three ways of scoping a graph to a parser, in both their bare and their explicit spelling.
326
+
327
+ Both commands that draw a graph offer the same scopes, read by the same rules, and resolved by the same `resolveGraphScope`. Declaring them once is what keeps the two from drifting into disagreeing about what a bare token means.
328
+
329
+ parser: The parser to add the arguments to.
330
+ keyOptions: The sentence describing the registered keys, already built.
331
+ """
332
+
333
+ parser.add_argument("scope", nargs="?", metavar="SCOPE", help=f"What to scope to, read from its own shape: a ticket id, a key, or a status ({', '.join(STATUSES)}). The flags below are the same three, named explicitly.")
334
+
335
+ scopeGroup = parser.add_mutually_exclusive_group()
336
+ scopeGroup.add_argument("-i", "--id", help="Scope to one ticket's ancestors and descendants.")
337
+ scopeGroup.add_argument("-k", "--key", help=f"Scope to one key, plus its immediate cross-key neighbors. {keyOptions}")
338
+ scopeGroup.add_argument("-s", "--status", choices=STATUSES, help="Scope to the tickets with this status alone. Nothing outside it is borrowed, so an edge survives only when both of its ends carry the status.")
339
+
340
+
294
341
  def buildTicketParser(commands: argparse._SubParsersAction, priorityOptions: str) -> argparse.ArgumentParser:
295
342
  """
296
343
  Build the branch that works with one ticket, named by its id.
@@ -36,6 +36,9 @@ DEFAULT_PRIORITY: int = 2
36
36
  DEFAULT_MAX_PRIORITY: int = 4
37
37
  DEFAULT_LOCK_TIMEOUT: float = 5.0
38
38
 
39
+ # How many nodes a rendered roadmap aims to hold. Mermaid lays out a few hundred before a diagram stops being readable at any zoom, and a repository with more history than that would rather lose the history than the shape of what is ahead.
40
+ DEFAULT_MAX_ROADMAP_NODES: int = 200
41
+
39
42
  # MARK: Classes
40
43
 
41
44
 
@@ -69,6 +72,7 @@ class Config:
69
72
  self.defaultPriority: int = readInt(document, "defaultPriority", ConfigError, source, DEFAULT_PRIORITY)
70
73
  self.maxPriority: int = readInt(document, "maxPriority", ConfigError, source, DEFAULT_MAX_PRIORITY)
71
74
  self.lockTimeout: float = readFloat(document, "lockTimeout", ConfigError, source, DEFAULT_LOCK_TIMEOUT)
75
+ self.maxRoadmapNodes: int = readInt(document, "maxRoadmapNodes", ConfigError, source, DEFAULT_MAX_ROADMAP_NODES)
72
76
 
73
77
  # A default outside the allowed band would make every created ticket invalid, so catch it at load.
74
78
  if not 0 <= self.defaultPriority <= self.maxPriority:
@@ -78,6 +82,10 @@ class Config:
78
82
  if self.lockTimeout <= 0:
79
83
  raise ConfigError(f"lockTimeout {self.lockTimeout} in {self.path} must be greater than 0. It is a wait in seconds.")
80
84
 
85
+ # Zero is the documented way to ask for no ceiling at all, so only a negative number is meaningless here.
86
+ if self.maxRoadmapNodes < 0:
87
+ raise ConfigError(f"maxRoadmapNodes {self.maxRoadmapNodes} in {self.path} cannot be negative. It is a node count, and 0 means no ceiling.")
88
+
81
89
  # MARK: Properties
82
90
 
83
91
  @property
@@ -10,7 +10,6 @@ The consumer receives ticket directories, a `CLAUDE.md`, a `.docket.toml`, one e
10
10
 
11
11
  import json
12
12
  from dataclasses import dataclass, field
13
- from importlib.resources import files
14
13
  from pathlib import Path
15
14
  from typing import Any
16
15
 
@@ -18,9 +17,13 @@ from docket.core.atomic import writeTextAtomic
18
17
  from docket.core.config import CONFIG_FILENAME, Config, loadConfig
19
18
  from docket.core.errors import DeployError
20
19
  from docket.core.lock import LOCK_FILENAME
20
+ from docket.core.resources import readPackageText
21
21
 
22
22
  # MARK: Constants
23
23
 
24
+ # The directory inside the package holding the files a repository receives.
25
+ TEMPLATES_DIRECTORY: str = "templates"
26
+
24
27
  # The template files shipped inside the package.
25
28
  TEMPLATE_CLAUDE: str = "CLAUDE.md"
26
29
  TEMPLATE_CONFIG: str = "docket.toml"
@@ -164,7 +167,7 @@ def readTemplate(name: str) -> str:
164
167
  Returns the template text.
165
168
  """
166
169
 
167
- return files("docket").joinpath("templates", name).read_text(encoding="utf-8")
170
+ return readPackageText(TEMPLATES_DIRECTORY, name)
168
171
 
169
172
 
170
173
  def _writeClaudeTemplate(config: Config, report: DeployReport) -> None: