sessionmemory 0.15.0__tar.gz → 0.17.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.15.0 → sessionmemory-0.17.0}/PKG-INFO +1 -1
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/pyproject.toml +2 -2
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/pyproject.toml.orig +2 -2
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/cli.py +2 -2
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/_common.py +198 -46
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/delete.py +9 -4
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/doctor.py +2 -5
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/export.py +6 -7
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/init.py +14 -13
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/inject.py +7 -5
- sessionmemory-0.17.0/src/sessionmemory/commands/local.py +942 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/new.py +59 -63
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/path.py +8 -19
- sessionmemory-0.17.0/src/sessionmemory/commands/project.py +279 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/reconcile.py +13 -16
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/reindex.py +3 -7
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/search.py +7 -17
- sessionmemory-0.17.0/src/sessionmemory/entry.py +21 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/doctor.py +48 -11
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/export.py +9 -4
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/fieldindex.py +35 -8
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/frontmatter.py +5 -1
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/gitinfo.py +20 -13
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/inject.py +8 -2
- sessionmemory-0.17.0/src/sessionmemory/lib/localdeclined.py +146 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/localmanifest.py +2 -2
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/localmd.py +338 -31
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/log.py +7 -7
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/paths.py +25 -14
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/reconcile.py +41 -1
- sessionmemory-0.17.0/src/sessionmemory/lib/registration.py +221 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/resolve.py +6 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/settingsdiff.py +27 -17
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/specs.py +48 -0
- sessionmemory-0.15.0/src/sessionmemory/commands/local.py +0 -604
- sessionmemory-0.15.0/src/sessionmemory/commands/project.py +0 -404
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/README.md +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/__init__.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/__init__.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/commands/log.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/__init__.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/atomic.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/backlog.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/bootstrap.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/changes.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/commits.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/config.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/embed.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/field.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/ids.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/localtree.py +0 -0
- {sessionmemory-0.15.0 → sessionmemory-0.17.0}/src/sessionmemory/lib/registry.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.17.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.17.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
|
|
@@ -18,7 +17,7 @@ from typer._click import core as click_core
|
|
|
18
17
|
from typer._click import exceptions as click_exceptions
|
|
19
18
|
|
|
20
19
|
from sessionmemory.lib import embed, registry
|
|
21
|
-
from sessionmemory.lib.bootstrap import is_empty
|
|
20
|
+
from sessionmemory.lib.bootstrap import InitResult, initialize, is_empty
|
|
22
21
|
from sessionmemory.lib.config import (
|
|
23
22
|
CONFIG_FILE,
|
|
24
23
|
VaultNotConfiguredError,
|
|
@@ -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:
|
|
@@ -164,6 +167,114 @@ def emit_json(payload: object) -> None:
|
|
|
164
167
|
emit_value(json.dumps(payload, indent=2))
|
|
165
168
|
|
|
166
169
|
|
|
170
|
+
def interactive() -> bool:
|
|
171
|
+
"""Report whether a person can answer a prompt, so an agent's call never blocks.
|
|
172
|
+
|
|
173
|
+
Returns:
|
|
174
|
+
bool: True when both stdin and stdout are terminals.
|
|
175
|
+
"""
|
|
176
|
+
return sys.stdin.isatty() and sys.stdout.isatty()
|
|
177
|
+
|
|
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
|
+
|
|
199
|
+
def confirm(question: str, yes: str) -> bool:
|
|
200
|
+
"""Ask one yes-or-no question whose answers say what each choice does.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
question (str): The question.
|
|
204
|
+
yes (str): The yes answer, naming what it does.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
bool: True only when the person chose yes; cancelling counts as no.
|
|
208
|
+
"""
|
|
209
|
+
return answer(question=question, yes=yes) is True
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def init_question(vault: Path, *, force: bool) -> tuple[str, str]:
|
|
213
|
+
"""Word the question that offers to initialize a vault, and its yes answer.
|
|
214
|
+
|
|
215
|
+
Args:
|
|
216
|
+
vault (Path): The directory to initialize.
|
|
217
|
+
force (bool): Whether the directory holds files but no vault marker.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
tuple[str, str]: The question and the yes answer.
|
|
221
|
+
"""
|
|
222
|
+
if force:
|
|
223
|
+
return (
|
|
224
|
+
f"{vault} holds files but no vault marker. Initialize a vault there anyway?",
|
|
225
|
+
"Yes, initialize it (its files are kept)",
|
|
226
|
+
)
|
|
227
|
+
return f"{vault} is not a vault yet. Initialize one there?", "Yes, initialize it"
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def offer_init(vault: Path) -> InitResult | None:
|
|
231
|
+
"""Ask a person at a terminal whether to initialize `vault`, and do it on a yes.
|
|
232
|
+
|
|
233
|
+
Args:
|
|
234
|
+
vault (Path): The uninitialized directory.
|
|
235
|
+
|
|
236
|
+
Returns:
|
|
237
|
+
InitResult | None: What was created, or None when the person declined.
|
|
238
|
+
"""
|
|
239
|
+
force = not is_empty(vault)
|
|
240
|
+
question, yes = init_question(vault, force=force)
|
|
241
|
+
if not confirm(question=question, yes=yes):
|
|
242
|
+
return None
|
|
243
|
+
return initialize(vault, force=force)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def ask_text(message: str) -> str | None:
|
|
247
|
+
"""Ask a person at a terminal to type an answer.
|
|
248
|
+
|
|
249
|
+
Args:
|
|
250
|
+
message (str): The prompt.
|
|
251
|
+
|
|
252
|
+
Returns:
|
|
253
|
+
str | None: The answer, or None when the person cancelled.
|
|
254
|
+
"""
|
|
255
|
+
try:
|
|
256
|
+
return str(typer.prompt(message)).strip() or None
|
|
257
|
+
except typer.Abort:
|
|
258
|
+
return None
|
|
259
|
+
|
|
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
|
+
|
|
167
278
|
def require_vault() -> Path:
|
|
168
279
|
"""Return an initialized vault root, or exit with the command that fixes it.
|
|
169
280
|
|
|
@@ -178,35 +289,35 @@ def require_vault() -> Path:
|
|
|
178
289
|
Exit: When the variable is unset, names a missing directory, or names a
|
|
179
290
|
directory that `sessionmemory init` has never touched.
|
|
180
291
|
"""
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
292
|
+
vault = configured_vault()
|
|
293
|
+
if is_initialized(vault):
|
|
294
|
+
return vault
|
|
295
|
+
|
|
296
|
+
if interactive():
|
|
297
|
+
if offer_init(vault) is None:
|
|
298
|
+
fail(f"{vault} is not a vault")
|
|
299
|
+
pp.success(f"initialized {vault}")
|
|
300
|
+
return vault
|
|
301
|
+
|
|
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)
|
|
210
321
|
|
|
211
322
|
|
|
212
323
|
def fail(message: str, details: list[str] | None = None) -> NoReturn:
|
|
@@ -219,7 +330,7 @@ def fail(message: str, details: list[str] | None = None) -> NoReturn:
|
|
|
219
330
|
Raises:
|
|
220
331
|
Exit: Always, with code 1.
|
|
221
332
|
"""
|
|
222
|
-
pp.error(message, details=details
|
|
333
|
+
pp.error(message, details=details or [])
|
|
223
334
|
raise typer.Exit(1)
|
|
224
335
|
|
|
225
336
|
|
|
@@ -238,28 +349,69 @@ def report_malformed_registry(vault: Path, error: registry.RegistryError) -> NoR
|
|
|
238
349
|
raise typer.Exit(1) from error
|
|
239
350
|
|
|
240
351
|
|
|
241
|
-
def
|
|
242
|
-
"""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.
|
|
243
382
|
|
|
244
383
|
Args:
|
|
245
384
|
vault (Path): The vault root.
|
|
246
385
|
cwd (Path | None): The directory to resolve, or None for the shell's.
|
|
247
386
|
|
|
248
387
|
Returns:
|
|
249
|
-
str: The resolved project slug.
|
|
388
|
+
tuple[str, Resolution]: The resolved project slug, and the resolution it came from.
|
|
250
389
|
|
|
251
390
|
Raises:
|
|
252
391
|
Exit: When the working directory is not a registered project.
|
|
253
392
|
"""
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
|
258
401
|
|
|
259
|
-
if
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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)])
|
|
@@ -9,9 +9,9 @@ from pathlib import Path # noqa: TC003
|
|
|
9
9
|
import typer
|
|
10
10
|
from nclutils import pp
|
|
11
11
|
|
|
12
|
-
from sessionmemory.commands
|
|
12
|
+
from sessionmemory.commands import _common
|
|
13
|
+
from sessionmemory.commands._common import JSON_OPTION, configured_vault, emit_json, fail
|
|
13
14
|
from sessionmemory.lib.bootstrap import InitResult, NotAVaultError, initialize
|
|
14
|
-
from sessionmemory.lib.config import VaultNotConfiguredError, vault_root
|
|
15
15
|
|
|
16
16
|
DIRECTORY_ARGUMENT = typer.Argument(
|
|
17
17
|
None, help="Where to create the vault. Defaults to the configured vault root."
|
|
@@ -21,7 +21,6 @@ FORCE_OPTION = typer.Option(
|
|
|
21
21
|
"--force",
|
|
22
22
|
help="Initialize a directory that already has contents. Nothing existing is overwritten.",
|
|
23
23
|
)
|
|
24
|
-
JSON_OPTION = typer.Option(False, "--json", help="Emit JSON instead of prose.") # noqa: FBT003
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
def _report(result: InitResult, *, as_json: bool) -> None:
|
|
@@ -58,9 +57,10 @@ def init(
|
|
|
58
57
|
) -> None:
|
|
59
58
|
"""Create the files a new vault needs.
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
Off a terminal, `require_vault` refuses an uninitialized directory, and this command is
|
|
61
|
+
what fixes that. When no directory is given, the configured root is read directly
|
|
62
|
+
instead. On a terminal, a directory holding unrelated files is initialized once the
|
|
63
|
+
person agrees, as if `--force` were given.
|
|
64
64
|
|
|
65
65
|
Raises:
|
|
66
66
|
Exit: When no directory is given and no vault root is configured or the
|
|
@@ -73,16 +73,17 @@ def init(
|
|
|
73
73
|
vault = directory.expanduser().resolve()
|
|
74
74
|
vault.mkdir(parents=True, exist_ok=True)
|
|
75
75
|
else:
|
|
76
|
-
|
|
77
|
-
vault = vault_root()
|
|
78
|
-
except VaultNotConfiguredError as error:
|
|
79
|
-
pp.error(str(error), details=VAULT_FIX)
|
|
80
|
-
raise typer.Exit(1) from error
|
|
76
|
+
vault = configured_vault()
|
|
81
77
|
|
|
82
78
|
try:
|
|
83
79
|
result = initialize(vault, force=force)
|
|
84
80
|
except NotAVaultError as error:
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
if not _common.interactive():
|
|
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
|
|
87
88
|
|
|
88
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
|