ticket-docket 1.0.0__py3-none-any.whl

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.
docket/server.py ADDED
@@ -0,0 +1,330 @@
1
+ """
2
+ Docket MCP Server
3
+
4
+ A stdio MCP server, a thin shell over `docket.core`.
5
+
6
+ Nothing here may write to stdout, because the MCP stdio transport owns it and one stray byte corrupts the protocol.
7
+ Diagnostics go to stderr. `rich` must never be imported in this module for the same reason.
8
+
9
+ Naming across the two surfaces:
10
+ MCP tool names and their parameters are snake_case, because that is the MCP ecosystem convention and it is what the model sees.
11
+ This repository's Python is camelCase. The two meet here and nowhere else.
12
+ Each handler is a camelCase Python function carrying an explicit snake_case `name`, its parameters are snake_case because they are the wire format, and the first thing every body does is hand those values to camelCase core calls.
13
+ Neither convention leaks into the other.
14
+
15
+ Every handler is `async` on purpose. `MCPServer` runs a synchronous handler on a worker thread, which would let two tool calls into `docket.core` at once.
16
+ Declaring the handlers `async` keeps them on the event loop, serialized, which is what this server has always done. Nothing here awaits, so this costs an event loop hop and buys back that guarantee.
17
+
18
+ That only covers this process. A CLI command, a second server, or a script driving `docket.core` is a separate process the event loop knows nothing about, so `docket.core` holds a lock file across every read and every read-modify-write of its own.
19
+ The two guarantees are independent and both are needed. Neither replaces the other, and the lock is where the real one lives.
20
+
21
+ A handler that meets a lock held by another process blocks the event loop until it is released or `lockTimeout` elapses. That is deliberate. Moving the wait off the loop would un-serialize the handlers, which is the guarantee the paragraph above exists to keep.
22
+ A timeout surfaces as `LockTimeoutError`, which leaves this module through the same path as every other `DocketError` and reaches the model as a tool error rather than a protocol one.
23
+ """
24
+
25
+ # MARK: Imports
26
+
27
+ import json
28
+ import sys
29
+ from typing import Any, Optional
30
+
31
+ from mcp.server import MCPServer
32
+
33
+ from docket import __version__
34
+ from docket.core.config import Config, discoverConfig
35
+ from docket.core.graph import ResolvedGraph, dependencyContext, resolveGraph, subgraphForId, subgraphForKey
36
+ from docket.core.mermaid import renderGraph
37
+ from docket.core.store import Store, TicketResult, TicketSet
38
+ from docket.core.ticket import Ticket
39
+ from docket.core.validate import ValidationReport, validate
40
+
41
+ # MARK: Constants
42
+
43
+ # The server name the client sees.
44
+ SERVER_NAME: str = "docket"
45
+
46
+ # Shown to the model when the server connects, so an agent knows the shape of the system before calling anything.
47
+ SERVER_INSTRUCTIONS: str = """\
48
+ Docket is this repository's ticket system. Tickets are markdown files with YAML frontmatter.
49
+
50
+ A ticket file has two halves with different rules. The body, everything below the closing frontmatter delimiter, is prose you may edit directly and freely. No tool parses it, and there is deliberately no tool for editing it. The frontmatter fields, and where the file lives, belong to these tools.
51
+
52
+ So: use `update_ticket` for title, priority, and dependencies, `set_metadata` for one metadata entry at a time, and `set_status` for status. Never move a file between the todo and done directories by hand, because `set_status` writes the frontmatter and performs the move together. Never rename a ticket file, because filenames are frozen at creation and other tickets reference them.
53
+
54
+ `metadata` is a free-form map any tool or skill can attach entries to. Namespace your key so two consumers never collide, for example `video` rather than `covered`. `set_metadata` touches only the key you name, leaving every other consumer's entries alone.
55
+
56
+ Dependencies are stored in one direction only. A ticket declares `requires`, and never declares what it blocks. `read_ticket` returns both directions, deriving the reverse side for you.
57
+
58
+ Keys are closed. Call `list_keys` before `create_ticket`. When no existing key fits, ask the user with `AskUserQuestion` whether to add one, and call `add_key` only once they agree.
59
+ """
60
+
61
+ # MARK: Server
62
+
63
+ # An unversioned server reports an empty version, so the real one is passed here and reaches the handshake through the constructor.
64
+ mcp: MCPServer = MCPServer(name=SERVER_NAME, instructions=SERVER_INSTRUCTIONS, version=__version__)
65
+
66
+ # MARK: Functions
67
+
68
+
69
+ @mcp.tool(name="list_tickets")
70
+ async def listTickets(status: Optional[str] = None, key: Optional[str] = None, priority_max: Optional[int] = None) -> str:
71
+ """
72
+ List ticket summaries, ordered by priority and then by id.
73
+
74
+ Returns id, title, status, priority, and key for each match. Never returns bodies, so listing many tickets stays cheap. Call `read_ticket` for the body of one.
75
+
76
+ status: Keep only tickets with this status. One of todo, wip, done.
77
+ key: Keep only tickets carrying this key.
78
+ priority_max: Keep only tickets at or below this priority number. 0 is most urgent.
79
+ """
80
+
81
+ store: Store = _store()
82
+ tickets: list[Ticket] = store.loadAll().filtered(status=status, key=key, priorityMax=priority_max)
83
+
84
+ return _json({"count": len(tickets), "tickets": [ticket.summary() for ticket in tickets]})
85
+
86
+
87
+ @mcp.tool(name="read_ticket")
88
+ async def readTicket(id: str) -> str:
89
+ """
90
+ Read one ticket in full, with its dependency context resolved.
91
+
92
+ The raw file stores bare ids in one direction only, so this adds what the file deliberately does not duplicate: the title and status of everything this ticket requires, and the whole reverse direction of everything that requires it. A dependency naming a ticket that does not exist is returned with `exists` false rather than being hidden.
93
+
94
+ id: The ticket id, for example CORE-14.
95
+ """
96
+
97
+ store: Store = _store()
98
+ loaded: TicketSet = store.loadAll()
99
+ ticket: Ticket = loaded.get(id)
100
+ context = dependencyContext(loaded, id)
101
+
102
+ payload: dict[str, Any] = dict(ticket.summary())
103
+ payload["body"] = ticket.body
104
+ payload["requires"] = context["requires"]
105
+ payload["requiredBy"] = context["requiredBy"]
106
+ payload["metadata"] = ticket.metadata
107
+ payload["extra"] = ticket.extra
108
+
109
+ return _json(payload)
110
+
111
+
112
+ @mcp.tool(name="create_ticket")
113
+ async def createTicket(
114
+ key: str,
115
+ title: str,
116
+ body: Optional[str] = None,
117
+ requires: Optional[list[str]] = None,
118
+ priority: Optional[int] = None,
119
+ ) -> str:
120
+ """
121
+ Create a ticket, allocating its id and writing the file.
122
+
123
+ The key must already be registered. Call `list_keys` first rather than guessing. When nothing fits, ask the user with `AskUserQuestion` and call `add_key` once they agree. An unregistered key is refused.
124
+
125
+ Write the body so a reader with no other context can act on it. Include the architecture discussed, the assumptions made, and the questions already answered, stated plainly in the ticket itself.
126
+
127
+ A `requires` entry naming a ticket that does not exist yet is a warning rather than a failure, so a batch written out of order still completes. Call `validate` once the batch is done.
128
+
129
+ key: The key to mint under, for example CORE.
130
+ title: The ticket title, which cannot be empty. The filename derives from this once, at creation, and never changes afterwards.
131
+ body: Markdown prose for the body, placed under a heading built from the title.
132
+ requires: Ids this ticket depends on.
133
+ priority: 0 is most urgent. Defaults to the repository's configured default.
134
+ """
135
+
136
+ result: TicketResult = _store().create(key=key, title=title, body=body, requires=requires, priority=priority)
137
+
138
+ return _json({"id": result.ticket.id, "path": str(result.ticket.path), "warnings": result.warnings})
139
+
140
+
141
+ @mcp.tool(name="update_ticket")
142
+ async def updateTicket(
143
+ id: str,
144
+ title: Optional[str] = None,
145
+ priority: Optional[int] = None,
146
+ requires: Optional[list[str]] = None,
147
+ requires_add: Optional[list[str]] = None,
148
+ requires_remove: Optional[list[str]] = None,
149
+ ) -> str:
150
+ """
151
+ Change a ticket's title, priority, or dependencies.
152
+
153
+ Only the fields supplied are touched. Status is not changeable here, because changing it moves the file, which is `set_status`. The filename never changes, even when the title does, so prose cross-references elsewhere stay intact.
154
+
155
+ The dependency list is edited either wholesale or in place, never both in one call. Passing `requires` alongside `requires_add` or `requires_remove` is refused, since it asks for two contradictory things at once.
156
+
157
+ id: The ticket id.
158
+ title: A new title, which cannot be empty.
159
+ priority: A new priority. 0 is most urgent.
160
+ requires: A replacement dependency list. Pass an empty list to clear it.
161
+ requires_add: Ids to append to the existing list. One already there is not duplicated.
162
+ requires_remove: Ids to drop from the existing list. One that is not there is ignored.
163
+ """
164
+
165
+ result: TicketResult = _store().update(ticketId=id, title=title, priority=priority, requires=requires, requiresAdd=requires_add, requiresRemove=requires_remove)
166
+
167
+ # The summary carries no dependency list, and an in-place edit is worth nothing if the caller cannot see what it landed on.
168
+ return _json({"id": result.ticket.id, "warnings": result.warnings, "ticket": result.ticket.summary(), "requires": result.ticket.requires})
169
+
170
+
171
+ @mcp.tool(name="set_metadata")
172
+ async def setMetadata(id: str, key: str, value: Optional[Any] = None) -> str:
173
+ """
174
+ Set or clear one entry in a ticket's `metadata` map.
175
+
176
+ `metadata` is free-form, shared by whatever tools or skills want to attach data to a ticket. Namespace your key, for example `video`, so your entries never collide with another consumer's. Only the named key is touched, every other entry is left as it was.
177
+
178
+ id: The ticket id.
179
+ key: The metadata key, which cannot be empty.
180
+ value: The value to store, any JSON-compatible type. Omit or pass null to remove the key instead.
181
+ """
182
+
183
+ result: TicketResult = _store().setMetadata(ticketId=id, key=key, value=value)
184
+
185
+ return _json({"id": result.ticket.id, "warnings": result.warnings, "metadata": result.ticket.metadata})
186
+
187
+
188
+ @mcp.tool(name="set_status")
189
+ async def setStatus(id: str, status: str) -> str:
190
+ """
191
+ Change a ticket's status, updating the frontmatter and moving the file in one operation.
192
+
193
+ Never move a ticket file by hand. The status field is the truth and the directory is a projection of it, and only this tool keeps the two in step.
194
+
195
+ id: The ticket id.
196
+ status: One of todo, wip, done. Only done moves the file into the done directory.
197
+ """
198
+
199
+ ticket: Ticket = _store().setStatus(id, status)
200
+
201
+ return _json({"id": ticket.id, "status": ticket.status, "path": str(ticket.path)})
202
+
203
+
204
+ @mcp.tool(name="graph")
205
+ async def graphTool(id: Optional[str] = None, key: Optional[str] = None) -> str:
206
+ """
207
+ Render the dependency graph as mermaid source.
208
+
209
+ Arrows point from a dependency to what depends on it, so an arrow reads as "must happen before". With no argument the whole set is rendered.
210
+
211
+ id: Scope to one ticket's transitive ancestors and descendants.
212
+ key: Scope to one key, plus its immediate cross-key neighbors, which are marked so the boundary is visible.
213
+ """
214
+
215
+ store: Store = _store()
216
+ graph: ResolvedGraph = resolveGraph(store.loadAll())
217
+
218
+ # Scope when asked, preferring an id since it is the narrower request.
219
+ if id is not None:
220
+ graph = subgraphForId(graph, id)
221
+ elif key is not None:
222
+ graph = subgraphForKey(graph, key)
223
+
224
+ return _json({"scope": graph.scope, "nodeCount": len(graph), "mermaid": renderGraph(graph)})
225
+
226
+
227
+ @mcp.tool(name="list_keys")
228
+ async def listKeys() -> str:
229
+ """
230
+ List the keys tickets may be created under.
231
+
232
+ A key not listed here will be refused by `create_ticket`.
233
+ """
234
+
235
+ registered: list[dict[str, str]] = [{"key": key, "description": description} for key, description in sorted(_config().registeredKeys.items())]
236
+
237
+ return _json({"registered": registered})
238
+
239
+
240
+ @mcp.tool(name="add_key")
241
+ async def addKey(key: str, description: str, rationale: str) -> str:
242
+ """
243
+ Register a new key, so tickets can be created under it.
244
+
245
+ Adding a key changes how this repository is organized, which is the user's call and not yours. Before calling this, ask the user with `AskUserQuestion` whether they want the new key, naming the key you propose and why the existing ones do not fit. Offer using an existing key as an option. Call this only once they have agreed, and never as a reflex because you cannot remember which key to use. Call `list_keys` first.
246
+
247
+ The key is written into the repository's configuration, where it shows up in the git diff.
248
+
249
+ key: The new key. Uppercase alphanumeric, starting with a letter, for example META.
250
+ description: What this key groups, shown alongside the other keys. It cannot be empty.
251
+ rationale: Why a new key is needed. This is written as a comment above the key, so a later reader sees the reasoning.
252
+ """
253
+
254
+ _config().addKey(key=key, description=description, rationale=rationale)
255
+
256
+ return _json({"key": key, "description": description, "rationale": rationale})
257
+
258
+
259
+ @mcp.tool(name="validate")
260
+ async def validateTool() -> str:
261
+ """
262
+ Run every integrity rule over the ticket set and return structured findings.
263
+
264
+ Errors block. Warnings inform. Call this after writing a batch of tickets, since a dependency naming a ticket that did not exist yet is only a warning at creation time and becomes an error here.
265
+ """
266
+
267
+ store: Store = _store()
268
+ report: ValidationReport = validate(store)
269
+
270
+ return _json(report.toDict())
271
+
272
+
273
+ def main(argv: Optional[list[str]] = None) -> int:
274
+ """
275
+ Entry point for the `docket-mcp` console script.
276
+
277
+ argv: Argument list, accepted for symmetry with the CLI and currently unused.
278
+
279
+ Returns the process exit code.
280
+ """
281
+
282
+ # `MCPServer.run` owns the event loop, so no async runtime is imported here.
283
+ try:
284
+ mcp.run(transport="stdio")
285
+ except KeyboardInterrupt:
286
+ return 0
287
+
288
+ return 0
289
+
290
+
291
+ def _config() -> Config:
292
+ """
293
+ Find the configuration governing the working directory.
294
+
295
+ This resolves per call rather than once at startup, so a key approved while the server is running is picked up without a restart.
296
+
297
+ Returns the loaded `Config`.
298
+ """
299
+
300
+ return discoverConfig()
301
+
302
+
303
+ def _store() -> Store:
304
+ """
305
+ Build a store over the configuration governing the working directory.
306
+
307
+ Returns the store.
308
+ """
309
+
310
+ return Store(_config())
311
+
312
+
313
+ def _json(payload: Any) -> str:
314
+ """
315
+ Encode a payload for return across the MCP boundary.
316
+
317
+ Every tool returns JSON as text, which is unambiguous for the model to parse and stable to assert on in tests. It is written compactly, since an agent pays for every token of it.
318
+
319
+ payload: The data to encode.
320
+
321
+ Returns the encoded text.
322
+ """
323
+
324
+ return json.dumps(payload, ensure_ascii=False, separators=(",", ":"))
325
+
326
+
327
+ # MARK: Main
328
+
329
+ if __name__ == "__main__":
330
+ sys.exit(main())
@@ -0,0 +1,108 @@
1
+ # Tickets
2
+
3
+ This directory is managed by `docket`. Read this before touching anything in it.
4
+
5
+ ## What a ticket is
6
+
7
+ A markdown file with a YAML frontmatter block.
8
+
9
+ ```markdown
10
+ ---
11
+ id: CORE-14
12
+ title: Skirmish setup
13
+ status: todo
14
+ priority: 1
15
+ requires: [CORE-9, GEN-3]
16
+ ---
17
+
18
+ # Skirmish setup
19
+
20
+ Prose, unparsed and unconstrained.
21
+ ```
22
+
23
+ | Field | Meaning |
24
+ |---|---|
25
+ | `id` | `<KEY>-<NUM>`. Allocated at creation. Never change it. |
26
+ | `title` | Free text. May change. The filename does not follow it. |
27
+ | `status` | `todo`, `wip`, or `done`. Nothing else is valid. |
28
+ | `priority` | Integer, `0` most urgent. |
29
+ | `requires` | Ids this ticket depends on. May be empty. |
30
+ | `metadata` | Free-form `{key: value}` map for any tool or skill to attach data to. Namespace your key so it cannot collide with another consumer's. |
31
+
32
+ Any other field is preserved untouched, so this repository may add its own.
33
+
34
+ Everything below the frontmatter is yours. No tool parses it.
35
+
36
+ ## The body is yours. The frontmatter is not.
37
+
38
+ A ticket file has two halves, and they have different rules.
39
+
40
+ **The body, everything below the closing `---`, is yours to edit directly.** Rewrite it, extend it, restructure it, correct it. No tool parses it and no tool will overwrite it. There is no MCP tool for editing a body, because editing it in place is the intended way. Do that freely and often, especially to record something you just worked out.
41
+
42
+ **The frontmatter block, and where the file lives, belong to the tool.** Do not hand-edit those fields, and do not create, move, rename, or delete ticket files yourself.
43
+
44
+ | Want to change | Do this |
45
+ |---|---|
46
+ | The prose in the body | Edit the file directly |
47
+ | `title`, `priority`, `requires` | `update_ticket` |
48
+ | one `metadata` entry | `set_metadata` |
49
+ | `status` | `set_status` |
50
+ | Nothing, you just want to read it | `read_ticket` |
51
+
52
+ Never move a file between `todo/` and `done/` yourself. The `status` field is the truth and the directory is a projection of it. `set_status` writes both together, and it is the only thing that does. A file moved by hand leaves the two disagreeing, and `validate` will report it as an error.
53
+
54
+ Filenames are frozen at creation. Retitling a ticket deliberately does not rename its file, because renaming would break every prose cross-reference pointing at it from other tickets. Do not rename one to "fix" a stale slug. It is stale on purpose.
55
+
56
+ ## The rest of the tools
57
+
58
+ | To do this | Call this |
59
+ |---|---|
60
+ | See what exists | `list_tickets` |
61
+ | Read one ticket in full | `read_ticket` |
62
+ | Create a ticket | `create_ticket` |
63
+ | See the dependency graph | `graph` |
64
+ | See valid keys | `list_keys` |
65
+ | Add a new key | `add_key`, after asking the user |
66
+ | Check the set is sound | `validate` |
67
+
68
+ ## Dependencies point one way
69
+
70
+ A ticket declares what it `requires`. It never declares what it blocks.
71
+
72
+ The reverse direction is derived, not stored. `read_ticket` returns both, so to find out what a ticket is blocking, read it and look at `requiredBy`. Do not add a "blocks" field. Storing both directions guarantees they eventually disagree, which is exactly what this design exists to prevent.
73
+
74
+ To change one edge, use `update_ticket` with `requires_add` or `requires_remove` rather than reading the list and passing it back with one entry different. Those edit the list in place, so nothing you did not name is at risk. Reserve `requires` for when you genuinely mean to replace the whole list, and never pass it in the same call as an edit, which is refused.
75
+
76
+ ## Keys are closed
77
+
78
+ A ticket's key is the part before the hyphen. It groups related work.
79
+
80
+ Keys must be registered before use. `create_ticket` refuses an unregistered one, which is what stops a typo silently spawning an orphan group.
81
+
82
+ Call `list_keys` before creating a ticket rather than guessing.
83
+
84
+ **When no existing key fits, ask the user before adding one.** Use `AskUserQuestion`. Name the key you have in mind, say what it would group, and say why the existing keys do not cover the work. Offer the closest existing key as an alternative option, because most of the time that is the right answer.
85
+
86
+ Only once the user has agreed, call `add_key` with the key, a description, and the rationale they just gave you. Never call it on your own judgement. How this repository is carved up is the user's decision, and a key added without asking is a structural change nobody signed off on.
87
+
88
+ If you are mid-batch and the user is not there to answer, use the closest existing key and say so in the ticket body. Do not stall the batch, and do not invent a key.
89
+
90
+ ## Write tickets for a reader who was not there
91
+
92
+ This is the part that matters most.
93
+
94
+ A ticket is read weeks later by someone, or something, with none of the context you have right now. Put that context in the ticket.
95
+
96
+ Include the architecture that was discussed, the assumptions being made, and the questions that were already asked and answered. State them plainly in the body, where a new reader will see them. A ticket that only makes sense to whoever was in the conversation is a ticket that will be redone from scratch.
97
+
98
+ ## If a call reports the repository is locked
99
+
100
+ Another process was writing to this repository and did not finish in time.
101
+
102
+ Nothing was changed when that error is raised, so retry the same call once. If it happens repeatedly, tell the user rather than retrying in a loop, because something is holding the repository open.
103
+
104
+ ## After writing a batch
105
+
106
+ Call `validate`.
107
+
108
+ A `requires` entry naming a ticket that does not exist yet is only a warning at creation time, so that writing a batch out of order does not strand you halfway. It becomes an error in `validate`. Run it when the batch is done and resolve what it reports.
@@ -0,0 +1,22 @@
1
+ # Docket configuration.
2
+ # This file is hand-maintained. Comments and key order survive every write the tool makes.
3
+
4
+ # Where tickets live, relative to this file.
5
+ root = "docs/tickets"
6
+
7
+ # Tickets with status todo or wip live here. Only done moves a file.
8
+ todoDir = "todo"
9
+ doneDir = "done"
10
+
11
+ # Priority is an integer with 0 most urgent. New tickets get defaultPriority, and validate enforces the ceiling.
12
+ defaultPriority = 2
13
+ maxPriority = 4
14
+
15
+ # How long, in seconds, one docket process waits for another to finish writing before giving up.
16
+ # Writes are serialized across processes, so a CLI command and a running MCP server never overwrite each other.
17
+ lockTimeout = 5.0
18
+
19
+ # Keys group related work. A ticket id is <KEY>-<NUM>.
20
+ # Add a key here with a short description of what it covers, or run `docket key add <KEY> "<DESCRIPTION>"`. A key must exist before tickets can use it.
21
+ # An agent adds one through add_key, which it is told to do only after asking you first.
22
+ [keys]
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.4
2
+ Name: ticket-docket
3
+ Version: 1.0.0
4
+ Summary: A per-repo ticketing system that is plain markdown for humans and structured MCP for agents
5
+ Project-URL: Homepage, https://github.com/Sorcerio/Docket
6
+ Project-URL: Repository, https://github.com/Sorcerio/Docket
7
+ Project-URL: Issues, https://github.com/Sorcerio/Docket/issues
8
+ Author: Sorcerio
9
+ License-Expression: GPL-3.0-or-later
10
+ License-File: LICENSE
11
+ Keywords: agents,cli,issue-tracker,markdown,mcp,project-management,tickets
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Bug Tracking
20
+ Classifier: Topic :: Utilities
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: filelock>=3.32.2
24
+ Requires-Dist: mcp<3,>=2
25
+ Requires-Dist: pyyaml>=6.0.3
26
+ Requires-Dist: rich-argparse>=1.8.0
27
+ Requires-Dist: rich>=15.0.0
28
+ Requires-Dist: tomlkit>=0.15.1
29
+ Description-Content-Type: text/markdown
30
+
31
+ # docket
32
+
33
+ Markdown tickets that live in your repo. You read them in a text editor or CLI. Your agent reads them over MCP.
34
+
35
+ ![Docket demo](https://raw.githubusercontent.com/Sorcerio/Docket/master/docs/demo/docket.gif)
36
+
37
+ * [docket](#docket)
38
+ * [Start Here](#start-here)
39
+ * [A Ticket](#a-ticket)
40
+ * [CLI](#cli)
41
+ * [MCP](#mcp)
42
+ * [Key Ticket Rules](#key-ticket-rules)
43
+ * [Configuration](#configuration)
44
+ * [Concurrent Access](#concurrent-access)
45
+ * [Validation](#validation)
46
+ * [Docket Runs on Docket](#docket-runs-on-docket)
47
+ * [Development](#development)
48
+ * [License](#license)
49
+
50
+ ---
51
+
52
+ ## Start Here
53
+
54
+ ```bash
55
+ uv tool install ticket-docket # or: pipx install ticket-docket
56
+ cd my-project
57
+ docket deploy .
58
+ ```
59
+
60
+ This installs two commands: `docket` for you and `docket-mcp` for your agent.
61
+
62
+ Then add at least one project key to `.docket.toml` for your future tickets:
63
+
64
+ ```bash
65
+ docket key add "CORE" "tactical-sim core"
66
+ ```
67
+
68
+ Make your first ticket:
69
+
70
+ ```bash
71
+ docket new CORE "Skirmish setup"
72
+ ```
73
+
74
+ ## A Ticket
75
+
76
+ File: `docs/tickets/todo/CORE-14_skirmishSetup.md`
77
+
78
+ ```markdown
79
+ ---
80
+ id: CORE-14
81
+ title: Skirmish setup
82
+ status: todo
83
+ priority: 1
84
+ requires: [CORE-9, GEN-3]
85
+ metadata: {}
86
+ ---
87
+
88
+ Goal: a screen where the player sets up one battle and plays it.
89
+ ```
90
+
91
+ | Field | Notes |
92
+ |---|---|
93
+ | `id` | `<KEY>-<NUM>`. Must match the filename prefix. |
94
+ | `title` | Free text. Changing it does not rename the file. |
95
+ | `status` | `todo`, `wip`, or `done`. Fixed vocabulary. |
96
+ | `priority` | Integer, `0` most urgent. Ceiling configurable. |
97
+ | `requires` | Ids this depends on. Never lists what it blocks. |
98
+ | `metadata` | Additional freeform key:value pairs handled first-party. |
99
+
100
+ Unknown fields are round-tripped untouched. Filenames are frozen at creation so prose cross-references never break.
101
+
102
+ ## CLI
103
+
104
+ > [!IMPORTANT]
105
+ > In Windows PowerShell, the \` character can be treated as an escape character. Typing "Use \`argparse\` instead" produces `\x07`. For code blocks in a body, use the MCP surface or a text editor.
106
+
107
+ A ticket id is the command:
108
+
109
+ ```bash
110
+ docket CORE-14 # show it, dependency context and all
111
+ docket CORE-14 status # bare word, for a pipe
112
+ docket CORE-14 done # todo, wip, or done. The file follows
113
+ docket CORE-14 set [-t TEXT] [-p N] [-r A,B|none] [-ra A,B] [-rr A,B]
114
+ docket CORE-14 meta [KEY [VALUE]] [-c]
115
+ ```
116
+
117
+ Everything else works on the set:
118
+
119
+ ```bash
120
+ docket new CORE "Skirmish setup" [-r CORE-9,GEN-3] [-p 1] [-b TEXT]
121
+ docket list [-s todo] [-k CORE] [-m 2]
122
+ docket graph [-i CORE-14 | -k GEN] [-o FILE]
123
+ docket key list | add KEY "desc" [-r TEXT] | remove KEY
124
+ docket validate | deploy PATH | upgrade PATH
125
+ ```
126
+
127
+ `-r` replaces the dependency list. `-ra` and `-rr` edit the one already there. Both in one call is refused.
128
+
129
+ Every short flag has a long form (`-k/--key`, `-p/--priority`, `-m/--priority-max`, and so on). `--help` lists your actual keys and priority range.
130
+
131
+ ## MCP
132
+
133
+ `docket-mcp` is a stdio server. Ten tools, each returning JSON as text.
134
+
135
+ | Tool | Purpose |
136
+ |---|---|
137
+ | `list_tickets(status?, key?, priority_max?)` | Summaries only, never bodies. |
138
+ | `read_ticket(id)` | Full body plus both dependency directions. |
139
+ | `create_ticket(key, title, body?, requires?, priority?)` | Allocates the id, writes the file. |
140
+ | `update_ticket(id, title?, priority?, requires?, requires_add?, requires_remove?)` | Those three fields only. |
141
+ | `set_status(id, status)` | Writes frontmatter and moves the file together. |
142
+ | `graph(id?, key?)` | Mermaid source. |
143
+ | `list_keys()` | The registered keys. |
144
+ | `add_key(key, description, rationale)` | After the agent has asked the user. |
145
+ | `validate()` | Structured findings. |
146
+ | `set_metadata(id, key, value?)` | One entry at a time, leaving every other key alone. |
147
+
148
+ ## Key Ticket Rules
149
+
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.
151
+ 2. **Status is the truth, the directory follows.** Only `done` moves a file, and nothing writes one without the other. `validate` catches a file moved by hand.
152
+ 3. **Keys are a whitelist.** An unregistered key is refused, so a typo cannot spawn an orphan group. A key must be added explicitly before it can be used.
153
+
154
+ ## Configuration
155
+
156
+ `.docket.toml` at the repo root. Read and written with `tomlkit`, so comments, spacing, and key order survive every write like:
157
+
158
+ ```toml
159
+ root = "docs/tickets"
160
+ todoDir = "todo"
161
+ doneDir = "done"
162
+ defaultPriority = 2
163
+ maxPriority = 4
164
+ lockTimeout = 5.0
165
+
166
+ [keys]
167
+ # Primary arch
168
+ CORE = "tactical-sim core"
169
+ # The strategic layer is a distinct area.
170
+ META = "campaign and progression"
171
+ ```
172
+
173
+ 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.
174
+
175
+ `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.
176
+
177
+ ## Concurrent Access
178
+
179
+ Writes are serialized across processes through `.docket.lock` at the repo root, which `deploy` adds to your `.gitignore`.
180
+
181
+ - Readers share the lock, writers take it exclusively.
182
+ - The whole read-modify-write is held, not just the write. Two processes cannot mint the same id.
183
+ - Files are replaced atomically.
184
+
185
+ Config value `lockTimeout` is how long a process waits before giving up. Hitting it raises an error that changed nothing, so the call is always safe to retry.
186
+
187
+ ## Validation
188
+
189
+ `docket validate` errors on:
190
+
191
+ - A `requires` entry naming an id that does not exist, or a dependency cycle
192
+ - Two tickets sharing an id, or an unregistered key
193
+ - An id disagreeing with its filename prefix, or a status disagreeing with its directory
194
+ - A priority outside the band, or a status outside the vocabulary
195
+ - A file under a status directory that cannot be read as a ticket
196
+
197
+ `validate` has no warnings of its own. That severity exists for `create_ticket`, which downgrades a dangling `requires` entry so a batch written out of order is not stranded halfway.
198
+
199
+ ## Docket Runs on Docket
200
+
201
+ This repo is its own first consumer. Every feature above arrived as a ticket, committed in `docs/tickets/`. `done/` is the history of how the tool got built, `todo/` is what is next.
202
+
203
+ ## Development
204
+
205
+ ```bash
206
+ uv sync
207
+ uv run pytest
208
+ uv run docket --help
209
+ uv tool install --editable --force . # install your working copy
210
+ ```
211
+
212
+ The core library holds every rule. The CLI and MCP server are thin shells with no logic of their own, which is what keeps the two surfaces from disagreeing.
213
+
214
+ The version lives in exactly one place, `src/docket/__init__.py`. Bump it with the script, never by hand, then run `uv sync`:
215
+
216
+ ```bash
217
+ python scripts/bumpVersion.py patch
218
+ python scripts/bumpVersion.py 0.2.0
219
+ python scripts/bumpVersion.py minor --dry-run
220
+ ```
221
+
222
+ ## License
223
+
224
+ [GNU GPL v3.0 or later](https://github.com/Sorcerio/Docket/blob/master/LICENSE), with an output exception.
225
+
226
+ Anything Docket writes into your repository is yours under whatever terms you choose: deployed templates, ticket files, generated artifacts. Running Docket against a repository places no license obligation on that repository. The exception reaches only what Docket produces, never Docket's own source.