clinotes 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.
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ *.egg-info/
6
+ build/
7
+ dist/
8
+ .venv/
9
+ venv/
10
+ .coverage
11
+ htmlcov/
12
+ .clinotes/
clinotes-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Karthick Raja M
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,100 @@
1
+ Metadata-Version: 2.4
2
+ Name: clinotes
3
+ Version: 0.1.0
4
+ Summary: Pyramid memory for LLM-driven CLIs. Git-native, MCP-ready.
5
+ Project-URL: Homepage, https://github.com/karthyick/clinotes
6
+ Project-URL: Repository, https://github.com/karthyick/clinotes
7
+ Author-email: Karthick Raja M <Karthickrajam18@gmail.com>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: agent,cli,llm,mcp,memory
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: fastmcp>=3.0
20
+ Requires-Dist: pydantic>=2
21
+ Requires-Dist: python-frontmatter>=1.0
22
+ Requires-Dist: pyyaml>=6.0
23
+ Requires-Dist: typer>=0.12
24
+ Provides-Extra: dev
25
+ Requires-Dist: black; extra == 'dev'
26
+ Requires-Dist: build; extra == 'dev'
27
+ Requires-Dist: pytest; extra == 'dev'
28
+ Requires-Dist: ruff; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # clinotes
32
+
33
+ > Pyramid memory for LLM-driven CLIs. Git-native, MCP-ready.
34
+ >
35
+ > [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
36
+
37
+ ## What it is
38
+
39
+ clinotes is project memory that lives in your repo. It stores decisions and learnings as plain Markdown with YAML frontmatter inside a `.clinotes/` directory. Because the format is text-first and git-native, any LLM can recall it cheaply without hallucinating your stack.
40
+
41
+ ## Why
42
+
43
+ LLMs forget between sessions. Inline code comments rot. Wikis live outside the repo. clinotes gives your agent a structured, versioned memory layer it can read in ~200 tokens and expand only when needed.
44
+
45
+ ## Install
46
+
47
+ ```bash
48
+ pip install clinotes
49
+ ```
50
+
51
+ ## Quickstart
52
+
53
+ ```bash
54
+ clinotes init # scaffold .clinotes/
55
+ clinotes ls # show the index (L0)
56
+ clinotes show d1 # show a detail (L2)
57
+ ```
58
+
59
+ ## MCP Setup
60
+
61
+ Add clinotes to your editor so the LLM can recall and record project memory.
62
+
63
+ **Claude Code:**
64
+ ```bash
65
+ claude mcp add clinotes -- uvx clinotes-mcp
66
+ ```
67
+
68
+ **Cursor** (`.cursor/mcp.json`):
69
+ ```json
70
+ {
71
+ "mcpServers": {
72
+ "clinotes": {
73
+ "command": "uvx",
74
+ "args": ["clinotes-mcp"]
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Python API
81
+
82
+ ```python
83
+ from clinotes import note_decision, recall_index, recall_detail
84
+
85
+ # Record a decision
86
+ note_decision(
87
+ title="postgres over mysql",
88
+ why="client DBA only supports pg",
89
+ alternatives=["mysql", "sqlite"],
90
+ refs=["infra/db.py"]
91
+ )
92
+
93
+ # Recall
94
+ print(recall_index()) # L0 — cheap survey
95
+ print(recall_detail("d1")) # L2 — full detail
96
+ ```
97
+
98
+ ## Format
99
+
100
+ The on-disk layout, ID scheme, and frontmatter specification are defined in [SPEC.md](SPEC.md).
@@ -0,0 +1,70 @@
1
+ # clinotes
2
+
3
+ > Pyramid memory for LLM-driven CLIs. Git-native, MCP-ready.
4
+ >
5
+ > [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ ## What it is
8
+
9
+ clinotes is project memory that lives in your repo. It stores decisions and learnings as plain Markdown with YAML frontmatter inside a `.clinotes/` directory. Because the format is text-first and git-native, any LLM can recall it cheaply without hallucinating your stack.
10
+
11
+ ## Why
12
+
13
+ LLMs forget between sessions. Inline code comments rot. Wikis live outside the repo. clinotes gives your agent a structured, versioned memory layer it can read in ~200 tokens and expand only when needed.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install clinotes
19
+ ```
20
+
21
+ ## Quickstart
22
+
23
+ ```bash
24
+ clinotes init # scaffold .clinotes/
25
+ clinotes ls # show the index (L0)
26
+ clinotes show d1 # show a detail (L2)
27
+ ```
28
+
29
+ ## MCP Setup
30
+
31
+ Add clinotes to your editor so the LLM can recall and record project memory.
32
+
33
+ **Claude Code:**
34
+ ```bash
35
+ claude mcp add clinotes -- uvx clinotes-mcp
36
+ ```
37
+
38
+ **Cursor** (`.cursor/mcp.json`):
39
+ ```json
40
+ {
41
+ "mcpServers": {
42
+ "clinotes": {
43
+ "command": "uvx",
44
+ "args": ["clinotes-mcp"]
45
+ }
46
+ }
47
+ }
48
+ ```
49
+
50
+ ## Python API
51
+
52
+ ```python
53
+ from clinotes import note_decision, recall_index, recall_detail
54
+
55
+ # Record a decision
56
+ note_decision(
57
+ title="postgres over mysql",
58
+ why="client DBA only supports pg",
59
+ alternatives=["mysql", "sqlite"],
60
+ refs=["infra/db.py"]
61
+ )
62
+
63
+ # Recall
64
+ print(recall_index()) # L0 — cheap survey
65
+ print(recall_detail("d1")) # L2 — full detail
66
+ ```
67
+
68
+ ## Format
69
+
70
+ The on-disk layout, ID scheme, and frontmatter specification are defined in [SPEC.md](SPEC.md).
clinotes-0.1.0/SPEC.md ADDED
@@ -0,0 +1,111 @@
1
+ # clinotes Memory Format Specification v0.1
2
+
3
+ ## Overview
4
+
5
+ The clinotes memory format is a plain-text, git-native project knowledge base. It lives in a `.clinotes/` directory at the project root and is designed for cheap LLM recall through a two-level pyramid model.
6
+
7
+ ## Directory Layout
8
+
9
+ ```
10
+ .clinotes/
11
+ ├── INDEX.md # L0 — compact index of all memory IDs
12
+ └── detail/
13
+ ├── d1.md # L2 — full detail, one file per memory
14
+ ├── d2.md
15
+ ├── l1.md
16
+ └── ...
17
+ ```
18
+
19
+ ## ID Scheme
20
+
21
+ - **Decisions**: `d{n}` (e.g., `d1`, `d2`)
22
+ - **Learnings**: `l{n}` (e.g., `l1`, `l2`)
23
+ - `n` starts at 1 and is monotonic per prefix.
24
+
25
+ ## INDEX.md Format
26
+
27
+ ```markdown
28
+ # Project Memory Index
29
+
30
+ ## Decisions
31
+
32
+ - d1: postgres over mysql
33
+
34
+ ## Learned
35
+
36
+ - l1: asyncpg caches prepared statements
37
+
38
+ ## Rejected
39
+
40
+ ## Open
41
+ ```
42
+
43
+ Rules:
44
+ - The first line is always `# Project Memory Index`.
45
+ - The four section headers (`## Decisions`, `## Learned`, `## Rejected`, `## Open`) always exist, in that order, even when empty.
46
+ - Each entry line is exactly `- {id}: {title}`.
47
+ - `Rejected` and `Open` are reserved for forward compatibility.
48
+
49
+ ## detail/{id}.md Format
50
+
51
+ Every detail file uses YAML frontmatter followed by a markdown body.
52
+
53
+ ### Decision
54
+
55
+ ```markdown
56
+ ---
57
+ id: d1
58
+ type: decision
59
+ title: postgres over mysql
60
+ created: 2026-05-30T14:23:01+00:00
61
+ refs:
62
+ - infra/db.py
63
+ ---
64
+
65
+ ## Why
66
+
67
+ client DBA only supports pg
68
+
69
+ ## Alternatives
70
+
71
+ - mysql
72
+ - sqlite
73
+ ```
74
+
75
+ ### Learned
76
+
77
+ ```markdown
78
+ ---
79
+ id: l1
80
+ type: learned
81
+ title: asyncpg caches prepared statements
82
+ created: 2026-05-30T14:25:10+00:00
83
+ refs: []
84
+ ---
85
+
86
+ ## Notes
87
+
88
+ Neon's pgbouncer breaks asyncpg statement cache; set statement_cache_size=0.
89
+ ```
90
+
91
+ Rules:
92
+ - `created` is ISO-8601 with timezone.
93
+ - `refs` is always a YAML list; may be empty (`[]`).
94
+ - Decision body: `## Why` followed by the rationale. If alternatives are provided, `## Alternatives` follows with a `- {item}` list.
95
+ - Learned body: `## Notes` followed by the note text.
96
+
97
+ ## The L0 / L2 Pyramid Recall Model
98
+
99
+ LLM context is expensive and finite. clinotes uses a two-tier pyramid to minimize token spend during project recall:
100
+
101
+ - **L0 (INDEX.md)**: ~200 tokens. A dense, structured list of every decision and learning. This is the "table of contents" for project memory. An LLM should read this first to locate relevant IDs.
102
+ - **L2 (detail/{id}.md)**: ~400 tokens per file. The full rationale, alternatives, and references for a single memory. An LLM reads only the specific IDs it needs after scanning L0.
103
+
104
+ Why this saves context:
105
+ - A project with 20 memories costs ~200 tokens to survey at L0, versus ~8,000 tokens if every detail were inlined.
106
+ - The index gives the LLM a searchable map; details give precision without noise.
107
+ - Because the format is plain Markdown with YAML frontmatter, it diffs cleanly in git and merges predictably.
108
+
109
+ ---
110
+
111
+ This specification is implementation-neutral. Any tool that reads and writes this exact on-disk layout is compatible.
@@ -0,0 +1,2 @@
1
+ import sys, pathlib
2
+ sys.path.insert(0, str(pathlib.Path(__file__).parent / "src"))
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "clinotes"
7
+ version = "0.1.0"
8
+ description = "Pyramid memory for LLM-driven CLIs. Git-native, MCP-ready."
9
+ authors = [
10
+ { name = "Karthick Raja M", email = "Karthickrajam18@gmail.com" },
11
+ ]
12
+ requires-python = ">=3.10"
13
+ readme = "README.md"
14
+ license = { text = "MIT" }
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Software Development :: Libraries",
23
+ ]
24
+ keywords = ["mcp", "memory", "llm", "cli", "agent"]
25
+ dependencies = [
26
+ "pydantic>=2",
27
+ "typer>=0.12",
28
+ "python-frontmatter>=1.0",
29
+ "pyyaml>=6.0",
30
+ "fastmcp>=3.0",
31
+ ]
32
+
33
+ [project.optional-dependencies]
34
+ dev = ["pytest", "ruff", "black", "build"]
35
+
36
+ [project.scripts]
37
+ clinotes = "clinotes.cli:app"
38
+ clinotes-mcp = "clinotes.server:main"
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/karthyick/clinotes"
42
+ Repository = "https://github.com/karthyick/clinotes"
43
+
44
+ [tool.hatch.build.targets.wheel]
45
+ packages = ["src/clinotes"]
46
+
47
+ [tool.pytest.ini_options]
48
+ pythonpath = ["src"]
@@ -0,0 +1,15 @@
1
+ """Clinotes - CLI-driven memory for AI-assisted development.
2
+
3
+ A simple system for capturing and retrieving decisions and learnings
4
+ during development, optimized for LLM-driven workflows.
5
+ """
6
+ from .api import recall_index, recall_detail, note_decision, note_learned
7
+
8
+ __version__ = "0.1.0"
9
+ __all__ = [
10
+ "recall_index",
11
+ "recall_detail",
12
+ "note_decision",
13
+ "note_learned",
14
+ "__version__",
15
+ ]
@@ -0,0 +1,211 @@
1
+ """Public API for clinotes memory management.
2
+
3
+ Provides functions to record and recall decisions and learnings. Frontmatter is
4
+ serialized with a real YAML dumper so titles/refs containing colons, quotes,
5
+ brackets, unicode, or trailing spaces round-trip losslessly.
6
+ """
7
+ from datetime import datetime, timezone
8
+ import os
9
+ import re
10
+ from pathlib import Path
11
+
12
+ import yaml
13
+
14
+ from . import storage, ids, index, schema
15
+
16
+ # A valid memory id is a letter-prefix followed by digits (e.g. "d1", "l12").
17
+ # Anything else is rejected so recall_detail cannot be coerced into a path
18
+ # traversal (e.g. "../../secret").
19
+ _ID_RE = re.compile(r"^[A-Za-z]+[0-9]+$")
20
+
21
+
22
+ def _root() -> Path:
23
+ """Return the clinotes memory root directory.
24
+
25
+ Resolves from the ``CLINOTES_ROOT`` environment variable, defaulting to
26
+ ``.clinotes`` in the current working directory.
27
+ """
28
+ return Path(os.environ.get("CLINOTES_ROOT", ".clinotes"))
29
+
30
+
31
+ def _validate_title(title: str) -> str:
32
+ """Validate a memory title.
33
+
34
+ Args:
35
+ title: The proposed title.
36
+
37
+ Returns:
38
+ The title unchanged.
39
+
40
+ Raises:
41
+ ValueError: If the title is empty/blank or contains a line break
42
+ (titles are single-line labels — a newline would corrupt the
43
+ single-line INDEX.md entry).
44
+ """
45
+ if not title or not title.strip():
46
+ raise ValueError("title must not be empty or blank")
47
+ if "\n" in title or "\r" in title:
48
+ raise ValueError("title must be a single line (no line breaks)")
49
+ return title
50
+
51
+
52
+ def recall_index() -> str:
53
+ """L0: return INDEX.md text.
54
+
55
+ Calls :func:`index.ensure_index` first so a fresh project returns the empty
56
+ scaffold rather than raising.
57
+
58
+ Returns:
59
+ The full text of the INDEX.md file.
60
+ """
61
+ root = _root()
62
+ index.ensure_index(root)
63
+ return storage.read_file(root / "INDEX.md")
64
+
65
+
66
+ def recall_detail(id: str) -> str:
67
+ """L2: return full text of ``_root()/detail/{id}.md``.
68
+
69
+ Args:
70
+ id: The memory identifier (e.g., ``"d1"``, ``"l3"``).
71
+
72
+ Returns:
73
+ The full markdown text of the detail file.
74
+
75
+ Raises:
76
+ ValueError: If ``id`` is malformed or no memory exists with that id.
77
+ """
78
+ if not isinstance(id, str) or not _ID_RE.match(id):
79
+ raise ValueError(f"No memory with id={id}")
80
+ detail_path = _root() / "detail" / f"{id}.md"
81
+ if not detail_path.exists():
82
+ raise ValueError(f"No memory with id={id}")
83
+ return storage.read_file(detail_path)
84
+
85
+
86
+ def _render_detail(
87
+ id: str,
88
+ type: str,
89
+ title: str,
90
+ body: str,
91
+ alternatives: list[str],
92
+ refs: list[str],
93
+ ) -> str:
94
+ """Render the full markdown document (YAML frontmatter + body).
95
+
96
+ The frontmatter is produced with :func:`yaml.safe_dump` so any special
97
+ characters (``:``, quotes, ``[``/``{``, ``#``, unicode, trailing spaces)
98
+ are correctly escaped and round-trip via ``frontmatter.loads``.
99
+
100
+ Args:
101
+ id: Unique identifier (e.g., ``"d1"``).
102
+ type: Either ``"decision"`` or ``"learned"``.
103
+ title: Human-readable single-line title.
104
+ body: The "why" for decisions, the "notes" text for learnings.
105
+ alternatives: Alternatives (decisions only; emitted only if non-empty).
106
+ refs: File/URL references (emitted as a YAML list).
107
+
108
+ Returns:
109
+ The complete markdown document.
110
+
111
+ Raises:
112
+ ValueError: If ``type`` is not a known memory type.
113
+ """
114
+ if type not in schema.ALLOWED_TYPES:
115
+ raise ValueError(f"Unknown type: {type}")
116
+
117
+ meta = {
118
+ "id": id,
119
+ "type": type,
120
+ "title": title,
121
+ "created": datetime.now(timezone.utc).isoformat(),
122
+ "refs": list(refs),
123
+ }
124
+ fm = yaml.safe_dump(
125
+ meta, sort_keys=False, allow_unicode=True, default_flow_style=False
126
+ ).strip()
127
+ frontmatter_block = f"---\n{fm}\n---"
128
+
129
+ if type == "decision":
130
+ parts = [frontmatter_block, "", "## Why", "", body]
131
+ if alternatives:
132
+ alt_lines = "\n".join(f"- {alt}" for alt in alternatives)
133
+ parts.extend(["", "## Alternatives", "", alt_lines])
134
+ return "\n".join(parts)
135
+
136
+ # learned
137
+ return "\n".join([frontmatter_block, "", "## Notes", "", body])
138
+
139
+
140
+ def note_decision(
141
+ title: str,
142
+ why: str,
143
+ alternatives: list[str] | None = None,
144
+ refs: list[str] | None = None,
145
+ ) -> str:
146
+ """Record a decision.
147
+
148
+ Args:
149
+ title: Single-line title (must not be empty/blank or contain newlines).
150
+ why: Explanation of the decision.
151
+ alternatives: Optional alternatives considered.
152
+ refs: Optional file/URL references.
153
+
154
+ Returns:
155
+ The new id (e.g., ``"d3"``).
156
+
157
+ Raises:
158
+ ValueError: If the title is invalid.
159
+ """
160
+ _validate_title(title)
161
+ root = _root()
162
+ # Serialize id-assignment + detail-write + index-update so concurrent
163
+ # writers in the same .clinotes dir can't collide on ids or lose entries.
164
+ with storage.lock(root):
165
+ new_id = ids.next_id(root, "d")
166
+ content = _render_detail(
167
+ id=new_id,
168
+ type="decision",
169
+ title=title,
170
+ body=why,
171
+ alternatives=alternatives or [],
172
+ refs=refs or [],
173
+ )
174
+ storage.write_file_atomic(root / "detail" / f"{new_id}.md", content)
175
+ index.update_index(root, "Decisions", new_id, title)
176
+ return new_id
177
+
178
+
179
+ def note_learned(
180
+ title: str,
181
+ body: str,
182
+ refs: list[str] | None = None,
183
+ ) -> str:
184
+ """Record a learning.
185
+
186
+ Args:
187
+ title: Single-line title (must not be empty/blank or contain newlines).
188
+ body: The notes/learning content.
189
+ refs: Optional file/URL references.
190
+
191
+ Returns:
192
+ The new id (e.g., ``"l3"``).
193
+
194
+ Raises:
195
+ ValueError: If the title is invalid.
196
+ """
197
+ _validate_title(title)
198
+ root = _root()
199
+ with storage.lock(root):
200
+ new_id = ids.next_id(root, "l")
201
+ content = _render_detail(
202
+ id=new_id,
203
+ type="learned",
204
+ title=title,
205
+ body=body,
206
+ alternatives=[],
207
+ refs=refs or [],
208
+ )
209
+ storage.write_file_atomic(root / "detail" / f"{new_id}.md", content)
210
+ index.update_index(root, "Learned", new_id, title)
211
+ return new_id
@@ -0,0 +1,41 @@
1
+ """Typer CLI for clinotes memory management.
2
+
3
+ Provides commands to initialize, list, and show project memory entries.
4
+ """
5
+ from pathlib import Path
6
+
7
+ import typer
8
+
9
+ from . import api, index
10
+
11
+ app = typer.Typer(
12
+ no_args_is_help=True,
13
+ help="Pyramid memory for LLM-driven CLIs.",
14
+ )
15
+
16
+
17
+ @app.command()
18
+ def init() -> None:
19
+ """Create .clinotes/ in the current directory (idempotent)."""
20
+ root = api._root()
21
+ root.mkdir(parents=True, exist_ok=True)
22
+ (root / "detail").mkdir(parents=True, exist_ok=True)
23
+ index.ensure_index(root)
24
+ typer.echo(f"initialized .clinotes/ at {root.resolve()}")
25
+
26
+
27
+ @app.command()
28
+ def show(id: str) -> None:
29
+ """Print the full detail for a memory id (e.g. clinotes show d2)."""
30
+ try:
31
+ detail = api.recall_detail(id)
32
+ except ValueError:
33
+ typer.echo(f"No memory with id={id}", err=True)
34
+ raise typer.Exit(1)
35
+ typer.echo(detail)
36
+
37
+
38
+ @app.command()
39
+ def ls() -> None:
40
+ """Print the INDEX (all ids grouped by section)."""
41
+ typer.echo(api.recall_index())
@@ -0,0 +1,37 @@
1
+ from pathlib import Path
2
+
3
+
4
+ def next_id(root: Path, prefix: str) -> str:
5
+ """Return the next id for a prefix, e.g. 'd3' or 'l7'.
6
+
7
+ Scans root/'detail' for files named '{prefix}{n}.md', finds the max n,
8
+ returns f'{prefix}{max_n + 1}'. Returns f'{prefix}1' when none exist.
9
+ Only counts files whose stem is prefix followed by digits (ignore others).
10
+
11
+ Args:
12
+ root: The project root directory containing the ``.clinotes`` tree.
13
+ prefix: The id prefix character(s), e.g. ``"d"`` or ``"l"``.
14
+
15
+ Returns:
16
+ The next monotonic id string for the given prefix.
17
+ """
18
+ detail = root / "detail"
19
+ max_n = 0
20
+ if detail.exists() and detail.is_dir():
21
+ for item in detail.iterdir():
22
+ if not item.is_file():
23
+ continue
24
+ if item.suffix != ".md":
25
+ continue
26
+ stem = item.stem
27
+ if not stem.startswith(prefix):
28
+ continue
29
+ suffix = stem[len(prefix) :]
30
+ if not suffix.isdigit():
31
+ continue
32
+ n = int(suffix)
33
+ if n > max_n:
34
+ max_n = n
35
+ if max_n == 0:
36
+ return f"{prefix}1"
37
+ return f"{prefix}{max_n + 1}"