sessionmemory 0.16.0__tar.gz → 0.18.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.
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/PKG-INFO +1 -1
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/pyproject.toml +2 -2
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/pyproject.toml.orig +2 -2
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/cli.py +2 -2
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/_common.py +123 -59
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/delete.py +9 -4
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/doctor.py +2 -5
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/export.py +6 -7
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/init.py +8 -15
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/inject.py +7 -5
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/local.py +244 -116
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/new.py +59 -63
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/path.py +8 -19
- sessionmemory-0.18.0/src/sessionmemory/commands/project.py +279 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/reconcile.py +13 -16
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/reindex.py +3 -7
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/search.py +7 -17
- sessionmemory-0.18.0/src/sessionmemory/entry.py +21 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/doctor.py +56 -17
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/export.py +9 -4
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/fieldindex.py +35 -8
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/frontmatter.py +5 -1
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/gitinfo.py +22 -15
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/inject.py +8 -2
- sessionmemory-0.18.0/src/sessionmemory/lib/localdeclined.py +146 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/localmd.py +387 -61
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/log.py +7 -7
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/paths.py +25 -14
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/reconcile.py +41 -1
- sessionmemory-0.18.0/src/sessionmemory/lib/registration.py +221 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/registry.py +23 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/resolve.py +15 -2
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/specs.py +48 -0
- sessionmemory-0.16.0/src/sessionmemory/commands/project.py +0 -484
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/README.md +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/__init__.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/__init__.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/commands/log.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/__init__.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/atomic.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/backlog.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/bootstrap.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/changes.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/commits.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/config.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/embed.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/field.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/ids.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/localmanifest.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/localtree.py +0 -0
- {sessionmemory-0.16.0 → sessionmemory-0.18.0}/src/sessionmemory/lib/settingsdiff.py +0 -0
|
@@ -11,14 +11,14 @@ description = "Durable memory for coding agents, one folder of searchable pages
|
|
|
11
11
|
name = "sessionmemory"
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
requires-python = ">=3.13,<3.15"
|
|
14
|
-
version = "0.
|
|
14
|
+
version = "0.18.0"
|
|
15
15
|
|
|
16
16
|
[[project.authors]]
|
|
17
17
|
name = "Nathaniel Landau"
|
|
18
18
|
email = "github@natelandau.com"
|
|
19
19
|
|
|
20
20
|
[project.scripts]
|
|
21
|
-
sessionmemory = "sessionmemory.
|
|
21
|
+
sessionmemory = "sessionmemory.entry:main"
|
|
22
22
|
|
|
23
23
|
[dependency-groups]
|
|
24
24
|
dev = [
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
name = "sessionmemory"
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
requires-python = ">=3.13,<3.15"
|
|
15
|
-
version = "0.
|
|
15
|
+
version = "0.18.0"
|
|
16
16
|
|
|
17
17
|
[project.scripts]
|
|
18
|
-
sessionmemory = "sessionmemory.
|
|
18
|
+
sessionmemory = "sessionmemory.entry:main"
|
|
19
19
|
|
|
20
20
|
[dependency-groups]
|
|
21
21
|
dev = [
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import importlib.metadata
|
|
6
|
-
|
|
7
5
|
import typer
|
|
8
6
|
|
|
9
7
|
from sessionmemory.commands import delete as delete_commands
|
|
@@ -38,6 +36,8 @@ PLUGIN = "Plugin internals"
|
|
|
38
36
|
def _print_version(value: bool) -> None: # noqa: FBT001
|
|
39
37
|
"""Print the installed version bare and exit, for a caller that compares it."""
|
|
40
38
|
if value:
|
|
39
|
+
import importlib.metadata
|
|
40
|
+
|
|
41
41
|
emit_value(importlib.metadata.version("sessionmemory"))
|
|
42
42
|
raise typer.Exit
|
|
43
43
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import importlib.metadata
|
|
6
5
|
import json
|
|
7
6
|
import os
|
|
8
7
|
import sys
|
|
@@ -11,7 +10,7 @@ from typing import TYPE_CHECKING, NoReturn
|
|
|
11
10
|
|
|
12
11
|
import typer
|
|
13
12
|
import typer.core
|
|
14
|
-
from nclutils import
|
|
13
|
+
from nclutils import pp
|
|
15
14
|
|
|
16
15
|
# Typer vendors Click, so the `click` package's classes never match its errors.
|
|
17
16
|
from typer._click import core as click_core
|
|
@@ -30,10 +29,12 @@ from sessionmemory.lib.resolve import resolve as resolve_project
|
|
|
30
29
|
|
|
31
30
|
if TYPE_CHECKING:
|
|
32
31
|
from sessionmemory.lib.embed import Embedder
|
|
32
|
+
from sessionmemory.lib.resolve import Resolution
|
|
33
33
|
|
|
34
34
|
EMBEDDER_ENV_VAR = "SESSIONMEMORY_EMBEDDER"
|
|
35
35
|
|
|
36
36
|
CWD_OPTION = typer.Option(None, "--cwd", "-C", help="Directory to resolve the project from.")
|
|
37
|
+
JSON_OPTION = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
|
|
37
38
|
|
|
38
39
|
|
|
39
40
|
# The two ways to name the vault, offered together whenever neither is set.
|
|
@@ -65,6 +66,8 @@ def _unknown_command_hint(message: str) -> str:
|
|
|
65
66
|
A miss Typer can correct is a typo, so a newer release is only offered as the cause
|
|
66
67
|
when no close match was suggested.
|
|
67
68
|
"""
|
|
69
|
+
import importlib.metadata
|
|
70
|
+
|
|
68
71
|
try:
|
|
69
72
|
version = importlib.metadata.version("sessionmemory")
|
|
70
73
|
except importlib.metadata.PackageNotFoundError:
|
|
@@ -173,6 +176,26 @@ def interactive() -> bool:
|
|
|
173
176
|
return sys.stdin.isatty() and sys.stdout.isatty()
|
|
174
177
|
|
|
175
178
|
|
|
179
|
+
def answer(question: str, yes: str, no: str = "No, leave it alone") -> bool | None:
|
|
180
|
+
"""Ask one yes-or-no question, telling a no apart from a cancelled question.
|
|
181
|
+
|
|
182
|
+
Use it where a no is remembered, so walking away from the prompt is not taken as one.
|
|
183
|
+
|
|
184
|
+
Args:
|
|
185
|
+
question (str): The question.
|
|
186
|
+
yes (str): The yes answer, naming what it does.
|
|
187
|
+
no (str): The no answer, naming what it does.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
bool | None: True for yes, False for no, None when the person cancelled.
|
|
191
|
+
"""
|
|
192
|
+
# Imported here, since the prompt library costs every command tens of milliseconds to load.
|
|
193
|
+
from nclutils import ask
|
|
194
|
+
|
|
195
|
+
picked = ask.choose_one_from_list(choices=[(yes, "yes"), (no, "no")], message=question)
|
|
196
|
+
return None if picked is None else picked == "yes"
|
|
197
|
+
|
|
198
|
+
|
|
176
199
|
def confirm(question: str, yes: str) -> bool:
|
|
177
200
|
"""Ask one yes-or-no question whose answers say what each choice does.
|
|
178
201
|
|
|
@@ -183,8 +206,7 @@ def confirm(question: str, yes: str) -> bool:
|
|
|
183
206
|
Returns:
|
|
184
207
|
bool: True only when the person chose yes; cancelling counts as no.
|
|
185
208
|
"""
|
|
186
|
-
|
|
187
|
-
return ask.choose_one_from_list(choices=choices, message=question) == "yes"
|
|
209
|
+
return answer(question=question, yes=yes) is True
|
|
188
210
|
|
|
189
211
|
|
|
190
212
|
def init_question(vault: Path, *, force: bool) -> tuple[str, str]:
|
|
@@ -236,6 +258,23 @@ def ask_text(message: str) -> str | None:
|
|
|
236
258
|
return None
|
|
237
259
|
|
|
238
260
|
|
|
261
|
+
def configured_vault() -> Path:
|
|
262
|
+
"""Return the configured vault root, initialized or not, or exit naming how to set it.
|
|
263
|
+
|
|
264
|
+
Returns:
|
|
265
|
+
Path: The resolved vault directory.
|
|
266
|
+
|
|
267
|
+
Raises:
|
|
268
|
+
Exit: When no vault root is configured or the configured one names a missing
|
|
269
|
+
directory.
|
|
270
|
+
"""
|
|
271
|
+
try:
|
|
272
|
+
return vault_root()
|
|
273
|
+
except VaultNotConfiguredError as error:
|
|
274
|
+
pp.error(str(error), details=VAULT_FIX)
|
|
275
|
+
raise typer.Exit(1) from error
|
|
276
|
+
|
|
277
|
+
|
|
239
278
|
def require_vault() -> Path:
|
|
240
279
|
"""Return an initialized vault root, or exit with the command that fixes it.
|
|
241
280
|
|
|
@@ -250,42 +289,35 @@ def require_vault() -> Path:
|
|
|
250
289
|
Exit: When the variable is unset, names a missing directory, or names a
|
|
251
290
|
directory that `sessionmemory init` has never touched.
|
|
252
291
|
"""
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
pp.error(str(error), details=VAULT_FIX)
|
|
257
|
-
raise typer.Exit(1) from error
|
|
292
|
+
vault = configured_vault()
|
|
293
|
+
if is_initialized(vault):
|
|
294
|
+
return vault
|
|
258
295
|
|
|
259
|
-
if
|
|
296
|
+
if interactive():
|
|
260
297
|
if offer_init(vault) is None:
|
|
261
|
-
|
|
262
|
-
raise typer.Exit(1)
|
|
298
|
+
fail(f"{vault} is not a vault")
|
|
263
299
|
pp.success(f"initialized {vault}")
|
|
264
300
|
return vault
|
|
265
301
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
"
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
)
|
|
286
|
-
raise typer.Exit(1)
|
|
287
|
-
|
|
288
|
-
return vault
|
|
302
|
+
# An empty directory is the ordinary bootstrap case, and `sessionmemory init` is safe
|
|
303
|
+
# for a caller, human or agent, to run there. A non-empty directory holding no
|
|
304
|
+
# marker is different: initializing it is a one-time human decision about a
|
|
305
|
+
# specific path, never something to hand an agent as its next action, so that
|
|
306
|
+
# case is described rather than phrased as a `run:` instruction to follow.
|
|
307
|
+
if is_empty(vault):
|
|
308
|
+
fail(f"{vault} is not a vault", ["run: sessionmemory init"])
|
|
309
|
+
|
|
310
|
+
pp.error(
|
|
311
|
+
f"{vault} is not an initialized vault",
|
|
312
|
+
details=[
|
|
313
|
+
"it holds files but no _system/vault.toml marker",
|
|
314
|
+
(
|
|
315
|
+
"if this is an existing vault, a human can initialize it once by "
|
|
316
|
+
"hand with: sessionmemory init --force"
|
|
317
|
+
),
|
|
318
|
+
],
|
|
319
|
+
)
|
|
320
|
+
raise typer.Exit(1)
|
|
289
321
|
|
|
290
322
|
|
|
291
323
|
def fail(message: str, details: list[str] | None = None) -> NoReturn:
|
|
@@ -298,7 +330,7 @@ def fail(message: str, details: list[str] | None = None) -> NoReturn:
|
|
|
298
330
|
Raises:
|
|
299
331
|
Exit: Always, with code 1.
|
|
300
332
|
"""
|
|
301
|
-
pp.error(message, details=details
|
|
333
|
+
pp.error(message, details=details or [])
|
|
302
334
|
raise typer.Exit(1)
|
|
303
335
|
|
|
304
336
|
|
|
@@ -317,37 +349,69 @@ def report_malformed_registry(vault: Path, error: registry.RegistryError) -> NoR
|
|
|
317
349
|
raise typer.Exit(1) from error
|
|
318
350
|
|
|
319
351
|
|
|
320
|
-
def
|
|
321
|
-
"""Return the
|
|
352
|
+
def target_dir(cwd: Path | None) -> Path:
|
|
353
|
+
"""Return the directory a `--cwd` option names, or the shell's, resolved.
|
|
354
|
+
|
|
355
|
+
Args:
|
|
356
|
+
cwd (Path | None): The `--cwd` value.
|
|
357
|
+
|
|
358
|
+
Returns:
|
|
359
|
+
Path: The resolved directory.
|
|
360
|
+
"""
|
|
361
|
+
return (cwd or Path.cwd()).resolve()
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def resolve_or_exit(vault: Path, target: Path) -> Resolution:
|
|
365
|
+
"""Resolve which project `target` belongs to, exiting on a malformed registry.
|
|
366
|
+
|
|
367
|
+
Args:
|
|
368
|
+
vault (Path): The vault root.
|
|
369
|
+
target (Path): The directory to resolve.
|
|
370
|
+
|
|
371
|
+
Returns:
|
|
372
|
+
Resolution: The match, or an unregistered result.
|
|
373
|
+
"""
|
|
374
|
+
try:
|
|
375
|
+
return resolve_project(vault, target)
|
|
376
|
+
except registry.RegistryError as error:
|
|
377
|
+
report_malformed_registry(vault, error)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def require_registered(vault: Path, cwd: Path | None = None) -> tuple[str, Resolution]:
|
|
381
|
+
"""Return the current project's slug and what git said resolving it, or exit.
|
|
322
382
|
|
|
323
383
|
Args:
|
|
324
384
|
vault (Path): The vault root.
|
|
325
385
|
cwd (Path | None): The directory to resolve, or None for the shell's.
|
|
326
386
|
|
|
327
387
|
Returns:
|
|
328
|
-
str: The resolved project slug.
|
|
388
|
+
tuple[str, Resolution]: The resolved project slug, and the resolution it came from.
|
|
329
389
|
|
|
330
390
|
Raises:
|
|
331
391
|
Exit: When the working directory is not a registered project.
|
|
332
392
|
"""
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
393
|
+
target = target_dir(cwd)
|
|
394
|
+
resolved = resolve_or_exit(vault, target)
|
|
395
|
+
if resolved.slug is not None:
|
|
396
|
+
return resolved.slug, resolved
|
|
397
|
+
if not interactive():
|
|
398
|
+
fail("this directory is not a registered project", ["run: sessionmemory project register"])
|
|
399
|
+
# Imported here, since the project command imports this module.
|
|
400
|
+
from sessionmemory.commands.project import offer_registration
|
|
337
401
|
|
|
338
|
-
if
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return
|
|
402
|
+
if offer_registration(vault, target):
|
|
403
|
+
return require_registered(vault, target)
|
|
404
|
+
fail("this directory is not a registered project")
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def require_project(vault: Path, cwd: Path | None = None) -> str:
|
|
408
|
+
"""Return the current project's slug, or exit with instructions.
|
|
409
|
+
|
|
410
|
+
Args:
|
|
411
|
+
vault (Path): The vault root.
|
|
412
|
+
cwd (Path | None): The directory to resolve, or None for the shell's.
|
|
413
|
+
|
|
414
|
+
Returns:
|
|
415
|
+
str: The resolved project slug.
|
|
416
|
+
"""
|
|
417
|
+
return require_registered(vault, cwd)[0]
|
|
@@ -12,14 +12,19 @@ from typing import TYPE_CHECKING
|
|
|
12
12
|
import typer
|
|
13
13
|
from nclutils import pp
|
|
14
14
|
|
|
15
|
-
from sessionmemory.commands._common import
|
|
15
|
+
from sessionmemory.commands._common import (
|
|
16
|
+
JSON_OPTION,
|
|
17
|
+
build_embedder,
|
|
18
|
+
emit_json,
|
|
19
|
+
fail,
|
|
20
|
+
require_vault,
|
|
21
|
+
)
|
|
16
22
|
from sessionmemory.lib import fieldindex, paths
|
|
17
23
|
|
|
18
24
|
if TYPE_CHECKING:
|
|
19
25
|
from sessionmemory.lib.embed import Embedder
|
|
20
26
|
|
|
21
27
|
PATHS = typer.Argument(..., help="Files to delete.")
|
|
22
|
-
JSON = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
|
|
23
28
|
|
|
24
29
|
|
|
25
30
|
def _check_vault_boundary(targets: list[Path], vault: Path) -> None:
|
|
@@ -41,14 +46,14 @@ def _delete_targets(targets: list[Path]) -> list[dict[str, object]]:
|
|
|
41
46
|
deleted = absolute.is_file()
|
|
42
47
|
if deleted:
|
|
43
48
|
absolute.unlink()
|
|
44
|
-
if absolute.parent.name in paths.
|
|
49
|
+
if absolute.parent.name in paths.INDEX_DIRS:
|
|
45
50
|
embedder = embedder or build_embedder()
|
|
46
51
|
fieldindex.forget(absolute.parent, embedder, absolute.name)
|
|
47
52
|
records.append({"path": str(target), "deleted": deleted})
|
|
48
53
|
return records
|
|
49
54
|
|
|
50
55
|
|
|
51
|
-
def delete_command(targets: list[Path] = PATHS, *, as_json: bool =
|
|
56
|
+
def delete_command(targets: list[Path] = PATHS, *, as_json: bool = JSON_OPTION) -> None:
|
|
52
57
|
"""Delete files from the vault, dropping a page's index row with it.
|
|
53
58
|
|
|
54
59
|
Raises:
|
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import typer
|
|
6
5
|
from nclutils import pp
|
|
7
6
|
|
|
8
|
-
from sessionmemory.commands._common import build_embedder, emit_json, require_vault
|
|
7
|
+
from sessionmemory.commands._common import JSON_OPTION, build_embedder, emit_json, require_vault
|
|
9
8
|
from sessionmemory.lib import doctor
|
|
10
9
|
|
|
11
|
-
JSON = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
def doctor_command(*, as_json: bool = JSON) -> None:
|
|
11
|
+
def doctor_command(*, as_json: bool = JSON_OPTION) -> None:
|
|
15
12
|
"""Report pages, projects, and indexes worth a look. Always exits 0."""
|
|
16
13
|
vault = require_vault()
|
|
17
14
|
findings = doctor.run(vault, build_embedder())
|
|
@@ -9,13 +9,14 @@ from nclutils import pp
|
|
|
9
9
|
|
|
10
10
|
from sessionmemory.commands._common import (
|
|
11
11
|
CWD_OPTION,
|
|
12
|
+
JSON_OPTION,
|
|
12
13
|
build_embedder,
|
|
13
14
|
emit_json,
|
|
14
15
|
fail,
|
|
15
16
|
require_project,
|
|
16
17
|
require_vault,
|
|
17
18
|
)
|
|
18
|
-
from sessionmemory.lib import export,
|
|
19
|
+
from sessionmemory.lib import export, paths
|
|
19
20
|
|
|
20
21
|
LOGS = typer.Option(False, "--logs", help="Export the logs field instead of learnings.") # noqa: FBT003
|
|
21
22
|
OUTPUT = typer.Option(
|
|
@@ -27,7 +28,6 @@ OUTPUT = typer.Option(
|
|
|
27
28
|
"directory, which is usually the checkout."
|
|
28
29
|
),
|
|
29
30
|
)
|
|
30
|
-
JSON = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
def export_command(
|
|
@@ -35,7 +35,7 @@ def export_command(
|
|
|
35
35
|
*,
|
|
36
36
|
logs: bool = LOGS,
|
|
37
37
|
output: Path | None = OUTPUT,
|
|
38
|
-
as_json: bool =
|
|
38
|
+
as_json: bool = JSON_OPTION,
|
|
39
39
|
) -> None:
|
|
40
40
|
"""Write this project's learnings, or its logs, as a .memoryfield.zip."""
|
|
41
41
|
vault = require_vault()
|
|
@@ -52,14 +52,13 @@ def export_command(
|
|
|
52
52
|
pp.warning(f"{field_directory} does not exist; the archive holds no pages")
|
|
53
53
|
|
|
54
54
|
try:
|
|
55
|
-
|
|
55
|
+
pages = export.export_field(field_directory, embedder, output)
|
|
56
56
|
except OSError as error:
|
|
57
57
|
fail(f"cannot write {output}: {error}")
|
|
58
|
-
pages = len(field.iter_pages(field_directory))
|
|
59
58
|
|
|
60
59
|
if as_json:
|
|
61
|
-
emit_json({"path": str(
|
|
60
|
+
emit_json({"path": str(output), "pages": pages})
|
|
62
61
|
return
|
|
63
62
|
|
|
64
63
|
label = "page" if pages == 1 else "pages"
|
|
65
|
-
pp.success(f"exported {pages} {label}", details=[str(
|
|
64
|
+
pp.success(f"exported {pages} {label}", details=[str(output)])
|
|
@@ -10,9 +10,8 @@ import typer
|
|
|
10
10
|
from nclutils import pp
|
|
11
11
|
|
|
12
12
|
from sessionmemory.commands import _common
|
|
13
|
-
from sessionmemory.commands._common import
|
|
13
|
+
from sessionmemory.commands._common import JSON_OPTION, configured_vault, emit_json, fail
|
|
14
14
|
from sessionmemory.lib.bootstrap import InitResult, NotAVaultError, initialize
|
|
15
|
-
from sessionmemory.lib.config import VaultNotConfiguredError, vault_root
|
|
16
15
|
|
|
17
16
|
DIRECTORY_ARGUMENT = typer.Argument(
|
|
18
17
|
None, help="Where to create the vault. Defaults to the configured vault root."
|
|
@@ -22,7 +21,6 @@ FORCE_OPTION = typer.Option(
|
|
|
22
21
|
"--force",
|
|
23
22
|
help="Initialize a directory that already has contents. Nothing existing is overwritten.",
|
|
24
23
|
)
|
|
25
|
-
JSON_OPTION = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
|
|
26
24
|
|
|
27
25
|
|
|
28
26
|
def _report(result: InitResult, *, as_json: bool) -> None:
|
|
@@ -75,22 +73,17 @@ def init(
|
|
|
75
73
|
vault = directory.expanduser().resolve()
|
|
76
74
|
vault.mkdir(parents=True, exist_ok=True)
|
|
77
75
|
else:
|
|
78
|
-
|
|
79
|
-
vault = vault_root()
|
|
80
|
-
except VaultNotConfiguredError as error:
|
|
81
|
-
pp.error(str(error), details=VAULT_FIX)
|
|
82
|
-
raise typer.Exit(1) from error
|
|
76
|
+
vault = configured_vault()
|
|
83
77
|
|
|
84
78
|
try:
|
|
85
79
|
result = initialize(vault, force=force)
|
|
86
80
|
except NotAVaultError as error:
|
|
87
81
|
if not _common.interactive():
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
result = initialize(vault, force=True)
|
|
82
|
+
fail(str(error))
|
|
83
|
+
# Only a directory holding files raises this, so the offer is the forced one.
|
|
84
|
+
offered = _common.offer_init(vault)
|
|
85
|
+
if offered is None:
|
|
86
|
+
fail(f"{vault} was not initialized")
|
|
87
|
+
result = offered
|
|
95
88
|
|
|
96
89
|
_report(result, as_json=as_json)
|
|
@@ -8,24 +8,26 @@ import typer
|
|
|
8
8
|
|
|
9
9
|
from sessionmemory.commands._common import (
|
|
10
10
|
CWD_OPTION,
|
|
11
|
+
JSON_OPTION,
|
|
11
12
|
emit_json,
|
|
12
13
|
emit_value,
|
|
13
|
-
|
|
14
|
+
require_registered,
|
|
14
15
|
require_vault,
|
|
15
16
|
)
|
|
16
17
|
from sessionmemory.lib import inject
|
|
17
18
|
|
|
18
19
|
COMMAND = typer.Option("sessionmemory", "--command", help="How the guidance names this CLI.")
|
|
19
|
-
JSON = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def inject_command(
|
|
23
|
-
cwd: Path | None = CWD_OPTION, command: str = COMMAND, *, as_json: bool =
|
|
23
|
+
cwd: Path | None = CWD_OPTION, command: str = COMMAND, *, as_json: bool = JSON_OPTION
|
|
24
24
|
) -> None:
|
|
25
25
|
"""Print what this project's session should start with."""
|
|
26
26
|
vault = require_vault()
|
|
27
|
-
slug =
|
|
28
|
-
injection = inject.build(
|
|
27
|
+
slug, resolved = require_registered(vault, cwd)
|
|
28
|
+
injection = inject.build(
|
|
29
|
+
vault, slug, reviewed=resolved.project.reviewed if resolved.project else None
|
|
30
|
+
)
|
|
29
31
|
if as_json:
|
|
30
32
|
emit_json(inject.payload(injection, command=command))
|
|
31
33
|
return
|