lore-agent-task-manager 0.1.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.
- lore/__init__.py +5 -0
- lore/__main__.py +5 -0
- lore/artifact.py +50 -0
- lore/cli.py +2786 -0
- lore/codex.py +316 -0
- lore/db.py +1320 -0
- lore/defaults/GETTING-STARTED.md +38 -0
- lore/defaults/LORE-AGENT.md +32 -0
- lore/defaults/artifacts/codex/CODEX.md +143 -0
- lore/defaults/artifacts/codex/conceptual/entities/task.md +51 -0
- lore/defaults/artifacts/codex/conceptual/entities/user.md +47 -0
- lore/defaults/artifacts/codex/conceptual/relationships/user--task.md +58 -0
- lore/defaults/artifacts/codex/conceptual/workflows/complete-task.md +47 -0
- lore/defaults/artifacts/codex/conceptual/workflows/create-and-assign-entity.md +68 -0
- lore/defaults/artifacts/codex/constraints/constraints.md +59 -0
- lore/defaults/artifacts/codex/decisions/001-sqlite-storage.md +64 -0
- lore/defaults/artifacts/codex/decisions/adr-no-default-content-tests.md +33 -0
- lore/defaults/artifacts/codex/glossary/glossary.md +40 -0
- lore/defaults/artifacts/codex/integrations/integrations.md +47 -0
- lore/defaults/artifacts/codex/operations/deployment/development.md +105 -0
- lore/defaults/artifacts/codex/operations/deployment/overview.md +57 -0
- lore/defaults/artifacts/codex/operations/deployment/production.md +88 -0
- lore/defaults/artifacts/codex/operations/deployment/staging.md +57 -0
- lore/defaults/artifacts/codex/operations/git.md +95 -0
- lore/defaults/artifacts/codex/operations/runbooks/runbook-template.md +75 -0
- lore/defaults/artifacts/codex/personas/persona.md +48 -0
- lore/defaults/artifacts/codex/security/security-model.md +62 -0
- lore/defaults/artifacts/codex/standards/code-conventions.md +61 -0
- lore/defaults/artifacts/codex/standards/design-principles.md +67 -0
- lore/defaults/artifacts/codex/standards/testing.md +71 -0
- lore/defaults/artifacts/codex/technical/backend/api/tasks.md +81 -0
- lore/defaults/artifacts/codex/technical/backend/overview.md +58 -0
- lore/defaults/artifacts/codex/technical/database/overview.md +45 -0
- lore/defaults/artifacts/codex/technical/database/schemas/tasks.md +49 -0
- lore/defaults/artifacts/codex/technical/database/schemas/users.md +38 -0
- lore/defaults/artifacts/codex/technical/frontend/overview.md +41 -0
- lore/defaults/artifacts/codex/technical/overview.md +59 -0
- lore/defaults/artifacts/feature-implementation/codex-change-proposal.md +91 -0
- lore/defaults/artifacts/feature-implementation/context-map.md +44 -0
- lore/defaults/artifacts/feature-implementation/crazy-prd.md +88 -0
- lore/defaults/artifacts/feature-implementation/crazy-tech-spec.md +79 -0
- lore/defaults/artifacts/feature-implementation/prd-draft.md +128 -0
- lore/defaults/artifacts/feature-implementation/prd.md +125 -0
- lore/defaults/artifacts/feature-implementation/tech-spec-draft.md +134 -0
- lore/defaults/artifacts/feature-implementation/tech-spec.md +138 -0
- lore/defaults/artifacts/feature-implementation/user-story-index.md +59 -0
- lore/defaults/artifacts/feature-implementation/user-story.md +126 -0
- lore/defaults/doctrines/feature-implementation/feature-implementation.yaml +387 -0
- lore/defaults/doctrines/feature-implementation/quick-feature-implementation.yaml +206 -0
- lore/defaults/doctrines/feature-implementation/tdd-implementation.yaml +51 -0
- lore/defaults/doctrines/update-changelog.yaml +24 -0
- lore/defaults/gitignore +20 -0
- lore/defaults/knights/changelog-scribe.md +105 -0
- lore/defaults/knights/feature-implementation/architect.md +65 -0
- lore/defaults/knights/feature-implementation/ba.md +73 -0
- lore/defaults/knights/feature-implementation/crazy-architect.md +41 -0
- lore/defaults/knights/feature-implementation/crazy-pm.md +39 -0
- lore/defaults/knights/feature-implementation/pm.md +61 -0
- lore/defaults/knights/feature-implementation/scout.md +67 -0
- lore/defaults/knights/feature-implementation/tdd-green.md +32 -0
- lore/defaults/knights/feature-implementation/tdd-red.md +31 -0
- lore/defaults/knights/feature-implementation/tdd-refactor.md +40 -0
- lore/defaults/knights/feature-implementation/tech-lead.md +73 -0
- lore/defaults/knights/feature-implementation/tech-writer.md +68 -0
- lore/defaults/schema.sql +60 -0
- lore/defaults/skills/explore-codex/SKILL.md +60 -0
- lore/defaults/skills/new-artifact/SKILL.md +73 -0
- lore/defaults/skills/new-doctrine/SKILL.md +79 -0
- lore/defaults/skills/new-knight/SKILL.md +72 -0
- lore/defaults/skills/new-watcher/SKILL.md +45 -0
- lore/defaults/skills/start-quest/SKILL.md +100 -0
- lore/defaults/watchers/change-log-updates.yaml +16 -0
- lore/doctrine.py +271 -0
- lore/frontmatter.py +96 -0
- lore/graph.py +73 -0
- lore/ids.py +16 -0
- lore/init.py +137 -0
- lore/knight.py +97 -0
- lore/migrations/__init__.py +1 -0
- lore/migrations/v1_to_v2.py +10 -0
- lore/migrations/v2_to_v3.py +24 -0
- lore/migrations/v3_to_v4.py +19 -0
- lore/migrations/v4_to_v5.py +41 -0
- lore/migrations/v5_to_v6.py +18 -0
- lore/models.py +323 -0
- lore/oracle.py +204 -0
- lore/paths.py +56 -0
- lore/priority.py +36 -0
- lore/py.typed +0 -0
- lore/root.py +27 -0
- lore/validators.py +149 -0
- lore/watcher.py +158 -0
- lore_agent_task_manager-0.1.0.dist-info/METADATA +194 -0
- lore_agent_task_manager-0.1.0.dist-info/RECORD +97 -0
- lore_agent_task_manager-0.1.0.dist-info/WHEEL +4 -0
- lore_agent_task_manager-0.1.0.dist-info/entry_points.txt +2 -0
- lore_agent_task_manager-0.1.0.dist-info/licenses/LICENSE +21 -0
lore/codex.py
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"""Codex scanning and document listing."""
|
|
2
|
+
|
|
3
|
+
import collections
|
|
4
|
+
import random as _random
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import yaml
|
|
8
|
+
|
|
9
|
+
from lore import frontmatter
|
|
10
|
+
|
|
11
|
+
def _parse_doc_robust(
|
|
12
|
+
filepath: Path,
|
|
13
|
+
*,
|
|
14
|
+
extra_fields: tuple[str, ...] = (),
|
|
15
|
+
include_body: bool = False,
|
|
16
|
+
) -> dict | None:
|
|
17
|
+
"""Parse a codex markdown file tolerantly.
|
|
18
|
+
|
|
19
|
+
Unlike ``frontmatter.parse_frontmatter_doc_full``, this function strips
|
|
20
|
+
leading/trailing whitespace from each line of the frontmatter block before
|
|
21
|
+
YAML parsing. This makes it resilient to frontmatter that has been
|
|
22
|
+
inadvertently indented (e.g. in test fixtures produced by ``textwrap.dedent``
|
|
23
|
+
on a string with inconsistent indentation).
|
|
24
|
+
|
|
25
|
+
Returns a dict with keys for each required field plus ``path`` (and
|
|
26
|
+
optionally ``body`` and each name in ``extra_fields``), or ``None`` if
|
|
27
|
+
parsing fails.
|
|
28
|
+
"""
|
|
29
|
+
try:
|
|
30
|
+
text = filepath.read_text()
|
|
31
|
+
parts = text.split("---", 2)
|
|
32
|
+
if len(parts) < 3:
|
|
33
|
+
return None
|
|
34
|
+
# Normalise each line of the frontmatter block so that indented
|
|
35
|
+
# frontmatter (a common test-fixture artefact) is still parseable.
|
|
36
|
+
fm_lines = parts[1].split("\n")
|
|
37
|
+
fm_normalised = "\n".join(line.strip() for line in fm_lines)
|
|
38
|
+
fm = yaml.safe_load(fm_normalised)
|
|
39
|
+
except Exception:
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
if not isinstance(fm, dict):
|
|
43
|
+
return None
|
|
44
|
+
if any(field not in fm or fm[field] is None for field in frontmatter._REQUIRED_FIELDS):
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
result: dict = {field: str(fm[field]) for field in frontmatter._REQUIRED_FIELDS}
|
|
48
|
+
result["path"] = filepath
|
|
49
|
+
for field in extra_fields:
|
|
50
|
+
if field in fm:
|
|
51
|
+
result[field] = fm[field]
|
|
52
|
+
if include_body:
|
|
53
|
+
result["body"] = parts[2].lstrip("\n")
|
|
54
|
+
return result
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def scan_codex(codex_dir: Path) -> list[dict]:
|
|
58
|
+
"""Walk codex_dir recursively, parse frontmatter, return document records.
|
|
59
|
+
|
|
60
|
+
Returns a list of dicts with keys: id, title, summary, group, path.
|
|
61
|
+
Files without valid frontmatter or missing required fields are skipped.
|
|
62
|
+
Results are sorted alphabetically by id.
|
|
63
|
+
"""
|
|
64
|
+
if not codex_dir.exists():
|
|
65
|
+
return []
|
|
66
|
+
|
|
67
|
+
results = []
|
|
68
|
+
for filepath in codex_dir.rglob("*.md"):
|
|
69
|
+
record = frontmatter.parse_frontmatter_doc(filepath, required_fields=("id", "title", "summary"))
|
|
70
|
+
if record is not None:
|
|
71
|
+
results.append(record)
|
|
72
|
+
|
|
73
|
+
return sorted(results, key=lambda d: d["id"])
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def search_documents(codex_dir: Path, keyword: str) -> list[dict]:
|
|
77
|
+
"""Return documents whose title or summary contains the keyword (case-insensitive).
|
|
78
|
+
|
|
79
|
+
Returns a list of dicts with keys: id, title, summary (no path).
|
|
80
|
+
Results are sorted alphabetically by id.
|
|
81
|
+
"""
|
|
82
|
+
docs = scan_codex(codex_dir)
|
|
83
|
+
kw = keyword.lower()
|
|
84
|
+
results = []
|
|
85
|
+
for doc in docs:
|
|
86
|
+
title_match = kw in doc["title"].lower()
|
|
87
|
+
summary_match = kw in doc["summary"].lower()
|
|
88
|
+
if title_match or summary_match:
|
|
89
|
+
results.append({
|
|
90
|
+
"id": doc["id"],
|
|
91
|
+
"title": doc["title"],
|
|
92
|
+
"summary": doc["summary"],
|
|
93
|
+
})
|
|
94
|
+
return results
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def read_document(codex_dir: Path, doc_id: str) -> dict | None:
|
|
98
|
+
"""Return a full document record for the given ID, or None if not found.
|
|
99
|
+
|
|
100
|
+
The returned dict has keys: id, title, summary, body.
|
|
101
|
+
The body is the content below the YAML frontmatter block, with leading
|
|
102
|
+
newlines stripped.
|
|
103
|
+
"""
|
|
104
|
+
docs = scan_codex(codex_dir)
|
|
105
|
+
for doc in docs:
|
|
106
|
+
if doc["id"] == doc_id:
|
|
107
|
+
filepath = doc["path"]
|
|
108
|
+
record = frontmatter.parse_frontmatter_doc_full(filepath, required_fields=("id", "title", "summary"))
|
|
109
|
+
if record is None:
|
|
110
|
+
return None
|
|
111
|
+
return {
|
|
112
|
+
"id": record["id"],
|
|
113
|
+
"title": record["title"],
|
|
114
|
+
"summary": record["summary"],
|
|
115
|
+
"body": record["body"],
|
|
116
|
+
}
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _read_related(filepath: Path, index: dict) -> list[str]:
|
|
121
|
+
"""Return sorted list of related IDs present in the index.
|
|
122
|
+
|
|
123
|
+
Reads the ``related`` field from the document frontmatter at ``filepath``,
|
|
124
|
+
filters to only IDs present in ``index``, casts non-string entries to str,
|
|
125
|
+
strips whitespace, drops null entries, and returns a sorted list for
|
|
126
|
+
determinism.
|
|
127
|
+
"""
|
|
128
|
+
record = _parse_doc_robust(filepath, extra_fields=("related",))
|
|
129
|
+
if record is None:
|
|
130
|
+
return []
|
|
131
|
+
|
|
132
|
+
raw = record.get("related")
|
|
133
|
+
if not raw:
|
|
134
|
+
return []
|
|
135
|
+
|
|
136
|
+
result = []
|
|
137
|
+
for entry in raw:
|
|
138
|
+
if entry is None:
|
|
139
|
+
continue
|
|
140
|
+
candidate = str(entry).strip()
|
|
141
|
+
if candidate in index:
|
|
142
|
+
result.append(candidate)
|
|
143
|
+
|
|
144
|
+
return sorted(result)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _scan_codex_robust(codex_dir: Path) -> list[dict]:
|
|
148
|
+
"""Like ``scan_codex`` but uses ``_parse_doc_robust`` for tolerant parsing.
|
|
149
|
+
|
|
150
|
+
Used internally by ``map_documents`` so that test fixtures with indented
|
|
151
|
+
frontmatter are still discovered.
|
|
152
|
+
"""
|
|
153
|
+
if not codex_dir.exists():
|
|
154
|
+
return []
|
|
155
|
+
|
|
156
|
+
results = []
|
|
157
|
+
for filepath in codex_dir.rglob("*.md"):
|
|
158
|
+
record = _parse_doc_robust(filepath)
|
|
159
|
+
if record is not None:
|
|
160
|
+
results.append(record)
|
|
161
|
+
|
|
162
|
+
return sorted(results, key=lambda d: d["id"])
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def map_documents(codex_dir: Path, start_id: str, depth: int) -> list[dict] | None:
|
|
166
|
+
"""BFS traversal of the codex document graph starting from ``start_id``.
|
|
167
|
+
|
|
168
|
+
Returns a list of full document dicts (id, title, summary, body) in
|
|
169
|
+
BFS order up to ``depth`` hops from the root. Each document appears at most
|
|
170
|
+
once. Returns ``None`` if ``start_id`` is not in the codex index.
|
|
171
|
+
|
|
172
|
+
Broken ``related`` links (IDs not in the index) are silently skipped.
|
|
173
|
+
"""
|
|
174
|
+
docs = _scan_codex_robust(codex_dir)
|
|
175
|
+
index = {doc["id"]: doc for doc in docs}
|
|
176
|
+
|
|
177
|
+
if start_id not in index:
|
|
178
|
+
return None
|
|
179
|
+
|
|
180
|
+
visited: set[str] = set()
|
|
181
|
+
result: list[dict] = []
|
|
182
|
+
|
|
183
|
+
# Queue items: (doc_id, current_depth)
|
|
184
|
+
queue: collections.deque = collections.deque()
|
|
185
|
+
queue.append((start_id, 0))
|
|
186
|
+
visited.add(start_id)
|
|
187
|
+
|
|
188
|
+
while queue:
|
|
189
|
+
current_id, current_depth = queue.popleft()
|
|
190
|
+
doc_meta = index[current_id]
|
|
191
|
+
full_record = _parse_doc_robust(
|
|
192
|
+
doc_meta["path"],
|
|
193
|
+
include_body=True,
|
|
194
|
+
)
|
|
195
|
+
if full_record is None:
|
|
196
|
+
continue
|
|
197
|
+
|
|
198
|
+
result.append({
|
|
199
|
+
"id": full_record["id"],
|
|
200
|
+
"title": full_record["title"],
|
|
201
|
+
"summary": full_record["summary"],
|
|
202
|
+
"body": full_record["body"],
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
if current_depth < depth:
|
|
206
|
+
neighbours = _read_related(doc_meta["path"], index)
|
|
207
|
+
for neighbour_id in neighbours:
|
|
208
|
+
if neighbour_id not in visited:
|
|
209
|
+
visited.add(neighbour_id)
|
|
210
|
+
queue.append((neighbour_id, current_depth + 1))
|
|
211
|
+
|
|
212
|
+
return result
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def chaos_documents(
|
|
216
|
+
project_root: Path,
|
|
217
|
+
start_id: str,
|
|
218
|
+
threshold: int,
|
|
219
|
+
*,
|
|
220
|
+
rng: _random.Random | None = None,
|
|
221
|
+
) -> list[dict] | None:
|
|
222
|
+
"""Random-walk traversal of the codex document graph from ``start_id``.
|
|
223
|
+
|
|
224
|
+
Steps:
|
|
225
|
+
1. Validate threshold (raises ValueError if < 30 or > 100).
|
|
226
|
+
2. Build index and bidirectional adjacency map.
|
|
227
|
+
3. BFS from start_id to compute the full reachable subgraph.
|
|
228
|
+
4. Random walk: pick random unvisited reachable nodes.
|
|
229
|
+
Stop when discovered / reachable_others >= threshold / 100 or no unvisited remain.
|
|
230
|
+
|
|
231
|
+
Returns None if start_id is not in the index.
|
|
232
|
+
The seed document is always the first entry.
|
|
233
|
+
"""
|
|
234
|
+
from lore.validators import validate_chaos_threshold
|
|
235
|
+
|
|
236
|
+
valid, err = validate_chaos_threshold(threshold)
|
|
237
|
+
if not valid:
|
|
238
|
+
raise ValueError(err)
|
|
239
|
+
|
|
240
|
+
codex_dir = project_root / ".lore" / "codex"
|
|
241
|
+
docs = _scan_codex_robust(codex_dir)
|
|
242
|
+
index = {doc["id"]: doc for doc in docs}
|
|
243
|
+
|
|
244
|
+
if start_id not in index:
|
|
245
|
+
return None
|
|
246
|
+
|
|
247
|
+
if rng is None:
|
|
248
|
+
rng = _random.Random()
|
|
249
|
+
|
|
250
|
+
# Build bidirectional adjacency from related links
|
|
251
|
+
adjacency: dict[str, set[str]] = {doc_id: set() for doc_id in index}
|
|
252
|
+
for doc in docs:
|
|
253
|
+
neighbours = _read_related(doc["path"], index)
|
|
254
|
+
for neighbour_id in neighbours:
|
|
255
|
+
adjacency[doc["id"]].add(neighbour_id)
|
|
256
|
+
adjacency[neighbour_id].add(doc["id"])
|
|
257
|
+
|
|
258
|
+
# BFS to find all reachable nodes from start_id
|
|
259
|
+
reachable: set[str] = set()
|
|
260
|
+
bfs_queue: collections.deque = collections.deque([start_id])
|
|
261
|
+
reachable.add(start_id)
|
|
262
|
+
while bfs_queue:
|
|
263
|
+
current = bfs_queue.popleft()
|
|
264
|
+
for nb in adjacency[current]:
|
|
265
|
+
if nb not in reachable:
|
|
266
|
+
reachable.add(nb)
|
|
267
|
+
bfs_queue.append(nb)
|
|
268
|
+
|
|
269
|
+
# reachable_others excludes the seed for threshold ratio calculation
|
|
270
|
+
reachable_others = reachable - {start_id}
|
|
271
|
+
total_reachable = len(reachable_others)
|
|
272
|
+
|
|
273
|
+
# Start result with seed document
|
|
274
|
+
result: list[dict] = []
|
|
275
|
+
visited: set[str] = {start_id}
|
|
276
|
+
|
|
277
|
+
seed_doc = index[start_id]
|
|
278
|
+
seed_record = _parse_doc_robust(seed_doc["path"])
|
|
279
|
+
if seed_record is not None:
|
|
280
|
+
result.append({
|
|
281
|
+
"id": seed_record["id"],
|
|
282
|
+
"title": seed_record["title"],
|
|
283
|
+
"summary": seed_record["summary"],
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
# If no reachable others, return immediately
|
|
287
|
+
if total_reachable == 0:
|
|
288
|
+
return result
|
|
289
|
+
|
|
290
|
+
# Random walk
|
|
291
|
+
while True:
|
|
292
|
+
# Check stopping condition
|
|
293
|
+
discovered = len(visited) - 1 # exclude seed
|
|
294
|
+
if discovered >= total_reachable:
|
|
295
|
+
break
|
|
296
|
+
if discovered > 0 and (discovered / total_reachable) >= (threshold / 100):
|
|
297
|
+
break
|
|
298
|
+
|
|
299
|
+
# Pick a random unvisited reachable node
|
|
300
|
+
candidates = list(reachable_others - visited)
|
|
301
|
+
if not candidates:
|
|
302
|
+
break
|
|
303
|
+
|
|
304
|
+
next_id = rng.choice(candidates)
|
|
305
|
+
visited.add(next_id)
|
|
306
|
+
|
|
307
|
+
doc_meta = index[next_id]
|
|
308
|
+
record = _parse_doc_robust(doc_meta["path"])
|
|
309
|
+
if record is not None:
|
|
310
|
+
result.append({
|
|
311
|
+
"id": record["id"],
|
|
312
|
+
"title": record["title"],
|
|
313
|
+
"summary": record["summary"],
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
return result
|