fogies 0.0.0.dev12__tar.gz → 0.0.0.dev14__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.
Files changed (56) hide show
  1. fogies-0.0.0.dev14/PKG-INFO +22 -0
  2. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/pyproject.toml +23 -20
  3. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/aws_access_key.py +0 -2
  4. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/boto_clients.py +1 -3
  5. fogies-0.0.0.dev14/src/fogies/config.py +97 -0
  6. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/includes/templates/claude_sync.toml.template +4 -2
  7. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/pyfogies.py +2 -2
  8. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/retry.py +2 -5
  9. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tasks/access_key.py +0 -2
  10. fogies-0.0.0.dev14/src/fogies/tasks/claude_code.py +70 -0
  11. fogies-0.0.0.dev14/src/fogies/tasks/claude_desktop.py +140 -0
  12. fogies-0.0.0.dev14/src/fogies/tasks/claude_sync.py +345 -0
  13. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tasks/format.py +2 -1
  14. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tasks/lint.py +2 -1
  15. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tasks/poetry.py +21 -13
  16. fogies-0.0.0.dev14/src/fogies/tasks/terminal.py +172 -0
  17. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tasks/terraform.py +2 -1
  18. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tasks/terraform_backend.py +2 -2
  19. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tasks/test.py +2 -1
  20. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/terraform/backend.py +1 -1
  21. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/aws_environ.py +30 -29
  22. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/boto.py +73 -3
  23. fogies-0.0.0.dev14/src/fogies/tools/claude_code.py +152 -0
  24. fogies-0.0.0.dev14/src/fogies/tools/claude_desktop.py +198 -0
  25. fogies-0.0.0.dev14/src/fogies/tools/claude_sessions.py +53 -0
  26. fogies-0.0.0.dev14/src/fogies/tools/claude_sync.py +879 -0
  27. fogies-0.0.0.dev14/src/fogies/tools/claude_sync_deletions.py +292 -0
  28. fogies-0.0.0.dev14/src/fogies/tools/claude_sync_watch.py +179 -0
  29. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/command.py +2 -4
  30. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/environ.py +0 -2
  31. fogies-0.0.0.dev12/PKG-INFO +0 -21
  32. fogies-0.0.0.dev12/src/fogies/tasks/claude_sync.py +0 -145
  33. fogies-0.0.0.dev12/src/fogies/tools/claude_sync.py +0 -302
  34. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/README.md +0 -0
  35. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/__init__.py +0 -0
  36. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/age_key.py +0 -0
  37. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/download_verified.py +0 -0
  38. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/includes/templates/aws.toml.template +0 -0
  39. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/includes/templates/backend_status.toml.template +0 -0
  40. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/includes/templates/poetry.toml.template +0 -0
  41. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/py.typed +0 -0
  42. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/ready_poll.py +0 -0
  43. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tasks/__init__.py +0 -0
  44. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/templates.py +0 -0
  45. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/terraform/__init__.py +0 -0
  46. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/terraform/alb.py +0 -0
  47. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/terraform/cloudwatch.py +0 -0
  48. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/terraform/ecr.py +0 -0
  49. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/terraform/ecs.py +0 -0
  50. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/terraform/hosted_zone.py +0 -0
  51. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/terraform/network.py +0 -0
  52. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/__init__.py +0 -0
  53. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/go.py +0 -0
  54. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/ollama.py +0 -0
  55. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/terraform.py +0 -0
  56. {fogies-0.0.0.dev12 → fogies-0.0.0.dev14}/src/fogies/tools/terraform_backend.py +0 -0
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: fogies
3
+ Version: 0.0.0.dev14
4
+ Summary:
5
+ Author: James Fogarty
6
+ Author-email: jayfo@users.noreply.github.com
7
+ Requires-Python: >=3.15,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.15
10
+ Requires-Dist: boto3 (>=1.44.13,<2.0.0)
11
+ Requires-Dist: claude-agent-sdk (>=0.2.189,<0.3.0)
12
+ Requires-Dist: filelock (>=4.3.2,<5.0.0)
13
+ Requires-Dist: ollama (>=0.6.3,<0.7.0)
14
+ Requires-Dist: psutil (>=7.2.2,<8.0.0)
15
+ Requires-Dist: pydantic (>=2.14.4,<3.0.0)
16
+ Requires-Dist: pyrage (>=1.4.0,<2.0.0)
17
+ Requires-Dist: requests (>=2.33.0,<2.34.0)
18
+ Requires-Dist: tenacity (>=9.2.1,<10.0.0)
19
+ Requires-Dist: tomlkit (>=0.15.3,<0.16.0)
20
+ Description-Content-Type: text/markdown
21
+
22
+ # pyfogies
@@ -1,13 +1,14 @@
1
1
  [project]
2
2
  name = "fogies"
3
3
  # Version follows semantic versioning <https://semver.org/>.
4
- version = "0.0.0-dev.12"
4
+ version = "0.0.0-dev.14"
5
5
  description = ""
6
6
  authors = [
7
7
  {name = "James Fogarty",email = "jayfo@users.noreply.github.com"}
8
8
  ]
9
9
  readme = "README.md"
10
- requires-python = ">=3.14,<4.0"
10
+ requires-python = ">=3.15,<4.0"
11
+ dynamic = ["dependencies"]
11
12
 
12
13
  [tool.poetry]
13
14
  packages = [
@@ -26,39 +27,41 @@ include = [
26
27
  # Example: ^1.2.3 will match 1.x.x versions >=1.2.3 and <2.0.0.
27
28
  # ~ allows only patch releases.
28
29
  # Example: ~1.2.3 will match versions >=1.2.3 and <1.3.0.
29
- boto3 = "^1.42.68"
30
- filelock = "^3.25.2"
31
- ollama = "^0.6.2"
30
+ boto3 = "^1.44.13"
31
+ claude-agent-sdk = "^0.2.189"
32
+ filelock = "^4.3.2"
33
+ ollama = "^0.6.3"
32
34
  psutil = "^7.2.2"
33
- pydantic = "^2.12.5"
34
- requests = "~2.33.0"
35
- tenacity = "^9.1.4"
36
- tomlkit = "^0.15.1"
35
+ pydantic = "^2.14.4"
37
36
  pyrage = "^1.4.0"
37
+ requests = "~2.33.0" # Keep with types-requests.
38
+ tenacity = "^9.2.1"
39
+ tomlkit = "^0.15.3"
38
40
 
39
41
  [tool.poetry.group.dev.dependencies]
40
42
  # ^ allows all minor and patch releases.
41
43
  # Example: ^1.2.3 will match 1.x.x versions >=1.2.3 and <2.0.0.
42
44
  # ~ allows only patch releases.
43
45
  # Example: ~1.2.3 will match versions >=1.2.3 and <1.3.0.
44
- basedpyright = "^1.36.1"
45
- black = "~26.5.1" # Black does not semver.
46
- boto3-stubs = {extras = ["logs", "s3"], version = "^1.43.70"}
47
- invoke = "^2.2.1"
48
- isort = "^8.0.1"
49
- poetry = "^2.2.1"
50
- pytest = "^9.0.2"
51
- semver = "^3.0.4"
52
- types-requests = "~2.33.0.20260712"
46
+ basedpyright = "^1.40.2"
47
+ black = "~26.10.1" # Black does not semver.
48
+ boto3-stubs = {extras = ["ec2", "ecs", "elbv2", "iam", "logs", "s3", "sts"], version = "^1.44.13"}
49
+ colorama = "^0.4.6"
50
+ invoke = "^3.0.3"
51
+ isort = "^9.0.2"
52
+ poetry = "^2.5.2"
53
+ pytest = "^9.2.0"
54
+ semver = "^3.2.0"
55
+ types-requests = "~2.33.0.20261030" # Keep with requests.
53
56
 
54
57
  [tool.basedpyright]
55
58
  typeCheckingMode = "recommended"
56
- pythonVersion = "3.14"
59
+ pythonVersion = "3.15"
57
60
  include = ["src", "tasks", "tests"]
58
61
  allowedUntypedLibraries = ["invoke"]
59
62
 
60
63
  [tool.black]
61
- target-version = ["py314"]
64
+ target-version = ["py315"]
62
65
 
63
66
  [build-system]
64
67
  requires = ["poetry-core>=2.0.0,<3.0.0"]
@@ -1,7 +1,5 @@
1
1
  """IAM user and access key management, independent of invoke."""
2
2
 
3
- from __future__ import annotations
4
-
5
3
  import datetime
6
4
  from typing import TYPE_CHECKING
7
5
 
@@ -1,10 +1,8 @@
1
1
  """Typed factories for boto3 clients."""
2
2
 
3
- from __future__ import annotations
4
-
5
3
  from typing import TYPE_CHECKING
6
4
 
7
- import boto3
5
+ lazy import boto3
8
6
 
9
7
  if TYPE_CHECKING:
10
8
  from mypy_boto3_ec2.client import EC2Client
@@ -0,0 +1,97 @@
1
+ """Loading config files, in one place.
2
+
3
+ A config file is TOML at a path that a project chooses, and is loaded into a
4
+ pydantic model. The file at that path may instead be a redirect, so that
5
+ projects can share one config rather than each repeating it:
6
+
7
+ redirect = "../shared/aws.toml"
8
+
9
+ The path is relative to the file that has the redirect, and the file has
10
+ nothing else in it. Anything that is common to loading every config, such as
11
+ redirects, belongs here rather than in each loader.
12
+ """
13
+
14
+ import pathlib
15
+ import tomllib
16
+ from collections.abc import Callable
17
+
18
+ from pydantic import BaseModel
19
+
20
+ from fogies.templates import ensure_from_template
21
+
22
+ _REDIRECT_KEY = "redirect"
23
+
24
+
25
+ def _read_toml(*, path: pathlib.Path) -> dict[str, object]:
26
+ with path.open("rb") as f:
27
+ return tomllib.load(f)
28
+
29
+
30
+ def _require_toml(*, path: pathlib.Path) -> None:
31
+ if path.suffix != ".toml":
32
+ raise ValueError("Config file '{}' must have a .toml extension.".format(path))
33
+
34
+
35
+ def _redirect_target(
36
+ *, path: pathlib.Path, data: dict[str, object]
37
+ ) -> pathlib.Path | None:
38
+ """Return where data, read from path, redirects to, or None if it doesn't."""
39
+ if _REDIRECT_KEY not in data:
40
+ return None
41
+ target = data[_REDIRECT_KEY]
42
+ if len(data) != 1 or not isinstance(target, str):
43
+ raise ValueError(
44
+ "'{}' has a '{}', so it must contain only that, as a path.".format(
45
+ path, _REDIRECT_KEY
46
+ )
47
+ )
48
+ return path.parent / target
49
+
50
+
51
+ def resolve_config_path(*, path: pathlib.Path) -> pathlib.Path:
52
+ """Return the file that holds the config at path.
53
+
54
+ That is path itself, or the file that it redirects to. Use this to write to
55
+ a config, so that the write goes to the shared file and not the redirect.
56
+
57
+ Raises ValueError if path, or the file it redirects to, is not a .toml file.
58
+ """
59
+ _require_toml(path=path)
60
+ if not path.exists():
61
+ return path
62
+
63
+ target = _redirect_target(path=path, data=_read_toml(path=path))
64
+ if target is None:
65
+ return path
66
+
67
+ _require_toml(path=target)
68
+ if not target.exists():
69
+ raise FileNotFoundError(
70
+ "'{}' redirects to '{}', which was not found.".format(path, target)
71
+ )
72
+ if _redirect_target(path=target, data=_read_toml(path=target)) is not None:
73
+ raise ValueError(
74
+ "'{}' redirects to '{}', which is itself a redirect.".format(path, target)
75
+ )
76
+ return target
77
+
78
+
79
+ def load_config[ConfigModel: BaseModel](
80
+ *,
81
+ path: pathlib.Path,
82
+ model: type[ConfigModel],
83
+ template_factory: Callable[[], str],
84
+ ) -> ConfigModel:
85
+ """Load the config at path as a model.
86
+
87
+ If path doesn't exist, it is created from template_factory and
88
+ FileNotFoundError is raised, so that it is filled in before it is used; see
89
+ ensure_from_template(). If path redirects, the config is the file it
90
+ redirects to. Raises ValueError if path, or the file it redirects to, is not
91
+ a .toml file, and a pydantic ValidationError if the config does not match
92
+ model.
93
+ """
94
+ # Before the template, so that a file with the wrong name is never created.
95
+ _require_toml(path=path)
96
+ ensure_from_template(path=path, template_factory=template_factory)
97
+ return model.model_validate(_read_toml(path=resolve_config_path(path=path)))
@@ -1,11 +1,13 @@
1
1
  # Config for claude-sync tasks.
2
2
  # See https://github.com/tawanorg/claude-sync
3
3
 
4
- # Profile in the AWS config, for an IAM user that can use the bucket.
4
+ # Profile in the AWS config, for an IAM user that can use the buckets.
5
5
  aws_profile = "..."
6
6
 
7
- # S3 bucket.
7
+ # S3 bucket that claude-sync syncs to.
8
8
  bucket = "..."
9
+ # S3 bucket for the record of deleted sessions, which claude-sync does not use.
10
+ deletions_bucket = "..."
9
11
  region = "..."
10
12
 
11
13
  # What to sync: "sessions" or "full".
@@ -31,7 +31,7 @@ def _pep440_version() -> str:
31
31
  """
32
32
  installed_version = importlib.metadata.version("fogies")
33
33
 
34
- if _FINAL_RELEASE_RE.match(installed_version) or _DEV_RELEASE_RE.match(
34
+ if _FINAL_RELEASE_RE.fullmatch(installed_version) or _DEV_RELEASE_RE.fullmatch(
35
35
  installed_version
36
36
  ):
37
37
  return installed_version
@@ -47,7 +47,7 @@ def _semver_version() -> str:
47
47
  """The installed pyfogies version, as SemVer (e.g. "0.0.0-dev.6")."""
48
48
  pep440_version = _pep440_version()
49
49
 
50
- dev_release_match = _DEV_RELEASE_RE.match(pep440_version)
50
+ dev_release_match = _DEV_RELEASE_RE.fullmatch(pep440_version)
51
51
  if dev_release_match:
52
52
  return "{}-dev.{}".format(
53
53
  dev_release_match.group("base"), dev_release_match.group("dev")
@@ -9,12 +9,9 @@ created, unless a retry actually happens.
9
9
  import pathlib
10
10
  from collections.abc import Callable
11
11
  from datetime import datetime
12
- from typing import TypeVar
13
12
 
14
13
  import tenacity
15
14
 
16
- _T = TypeVar("_T")
17
-
18
15
 
19
16
  def _log_retry(log_path: pathlib.Path) -> Callable[[tenacity.RetryCallState], None]:
20
17
  def log_it(retry_state: tenacity.RetryCallState) -> None:
@@ -34,11 +31,11 @@ def _log_retry(log_path: pathlib.Path) -> Callable[[tenacity.RetryCallState], No
34
31
  return log_it
35
32
 
36
33
 
37
- def retry_transient(
34
+ def retry_transient[T](
38
35
  *,
39
36
  exceptions: type[BaseException] | tuple[type[BaseException], ...],
40
37
  log_path: pathlib.Path | None = None,
41
- ) -> Callable[[Callable[[], _T]], Callable[[], _T]]:
38
+ ) -> Callable[[Callable[[], T]], Callable[[], T]]:
42
39
  """Retry profile for a flaky one-off operation, with no backoff."""
43
40
  return tenacity.retry(
44
41
  retry=tenacity.retry_if_exception_type(exceptions),
@@ -1,7 +1,5 @@
1
1
  """Tasks for managing IAM users and access keys."""
2
2
 
3
- from __future__ import annotations
4
-
5
3
  import contextlib
6
4
  import getpass
7
5
  from collections.abc import Callable, Generator
@@ -0,0 +1,70 @@
1
+ """Tasks for signing in to Claude Code."""
2
+
3
+ import pathlib
4
+ from collections.abc import Callable
5
+ from typing import cast
6
+
7
+ from invoke.collection import Collection
8
+ from invoke.context import Context
9
+ from invoke.tasks import Task, task
10
+
11
+ from fogies.tools.claude_code import claude_code
12
+
13
+
14
+ def get_task_login(*, binary_cache_path: pathlib.Path) -> Task[Callable[..., None]]:
15
+ @task(
16
+ name="login", auto_shortflags=False
17
+ ) # pyright: ignore[reportUntypedFunctionDecorator]
18
+ def task_login(context: Context) -> None:
19
+ """
20
+ Login to Claude Code.
21
+ """
22
+ _ = context
23
+ with claude_code(binary_cache_path=binary_cache_path) as cc:
24
+ cc.auth_login()
25
+
26
+ return cast(Task[Callable[..., None]], task_login)
27
+
28
+
29
+ def get_task_logout(*, binary_cache_path: pathlib.Path) -> Task[Callable[..., None]]:
30
+ @task(
31
+ name="logout", auto_shortflags=False
32
+ ) # pyright: ignore[reportUntypedFunctionDecorator]
33
+ def task_logout(context: Context) -> None:
34
+ """
35
+ Logout of Claude Code.
36
+ """
37
+ _ = context
38
+ with claude_code(binary_cache_path=binary_cache_path) as cc:
39
+ cc.auth_logout()
40
+
41
+ return cast(Task[Callable[..., None]], task_logout)
42
+
43
+
44
+ def get_task_status(*, binary_cache_path: pathlib.Path) -> Task[Callable[..., None]]:
45
+ @task(
46
+ name="status", auto_shortflags=False
47
+ ) # pyright: ignore[reportUntypedFunctionDecorator]
48
+ def task_status(context: Context) -> None:
49
+ """
50
+ Show login status of Claude Code.
51
+ """
52
+ _ = context
53
+ with claude_code(binary_cache_path=binary_cache_path) as cc:
54
+ if not cc.auth_status():
55
+ print("Not signed in. Sign in with the login task.")
56
+
57
+ return cast(Task[Callable[..., None]], task_status)
58
+
59
+
60
+ def get_collection(
61
+ *,
62
+ collection_name: str,
63
+ binary_cache_path: pathlib.Path,
64
+ ) -> Collection:
65
+ """Get a collection of tasks for signing in to Claude Code."""
66
+ collection = Collection(collection_name)
67
+ collection.add_task(get_task_login(binary_cache_path=binary_cache_path))
68
+ collection.add_task(get_task_logout(binary_cache_path=binary_cache_path))
69
+ collection.add_task(get_task_status(binary_cache_path=binary_cache_path))
70
+ return collection
@@ -0,0 +1,140 @@
1
+ """Tasks for the sessions that the Claude desktop app lists, and opening others in it.
2
+
3
+ The app lists only sessions it has a record of on this machine, as read by
4
+ fogies.tools.claude_desktop. A session synced here from another machine (e.g.,
5
+ by claude-sync) has a transcript but no record, so is not in the sidebar until it
6
+ is resumed in the app.
7
+ """
8
+
9
+ import pathlib
10
+ from collections.abc import Callable
11
+ from typing import cast
12
+
13
+ from invoke.collection import Collection
14
+ from invoke.context import Context
15
+ from invoke.tasks import Task, task
16
+ lazy from claude_agent_sdk import list_sessions
17
+
18
+ from fogies.tools.claude_code import claude_code
19
+ from fogies.tools.claude_desktop import (
20
+ desktop_sessions,
21
+ desktop_sessions_directory,
22
+ desktop_statuses,
23
+ plan_resume,
24
+ resume_each,
25
+ )
26
+ from fogies.tools.claude_sessions import describe_session, find_session_id
27
+
28
+ _NOT_FOUND = "The Claude desktop app's sessions were not found here ({}).".format
29
+
30
+
31
+ def get_task_sessions() -> Task[Callable[..., None]]:
32
+ @task(
33
+ name="sessions", auto_shortflags=False
34
+ ) # pyright: ignore[reportUntypedFunctionDecorator]
35
+ def task_sessions(context: Context) -> None:
36
+ """
37
+ List sessions on this machine, and whether the Claude desktop app lists them.
38
+ """
39
+ _ = context
40
+ recorded = desktop_sessions()
41
+ if recorded is None:
42
+ raise ValueError(_NOT_FOUND(desktop_sessions_directory()))
43
+
44
+ sessions = {session.session_id: session for session in list_sessions()}
45
+ statuses = desktop_statuses(transcripts=sessions, recorded=recorded)
46
+ for session_id, status in statuses.items():
47
+ if session_id in sessions:
48
+ print(
49
+ "{:<10} {}".format(status, describe_session(sessions[session_id]))
50
+ )
51
+ else:
52
+ print(
53
+ "{:<10} {} {}".format(
54
+ status, session_id, recorded[session_id].title or ""
55
+ )
56
+ )
57
+
58
+ return cast(Task[Callable[..., None]], task_sessions)
59
+
60
+
61
+ def get_task_resume(*, binary_cache_path: pathlib.Path) -> Task[Callable[..., None]]:
62
+ @task(
63
+ name="resume",
64
+ auto_shortflags=False,
65
+ help={
66
+ "session_id": "Session to resume, from any part of its ID that is only in that one.",
67
+ "all": "Resume every session that the app does not list, except those that ran in a directory that is not here.",
68
+ },
69
+ ) # pyright: ignore[reportUntypedFunctionDecorator]
70
+ def task_resume(
71
+ context: Context, session_id: str | None = None, all_: bool = False
72
+ ) -> None:
73
+ """
74
+ Resume a session, or all that are not listed, in Claude desktop.
75
+ """
76
+ _ = context
77
+ if (session_id is not None) == all_:
78
+ raise ValueError("Give a session ID, or --all, and not both.")
79
+
80
+ sessions = {session.session_id: session for session in list_sessions()}
81
+ if all_:
82
+ recorded = desktop_sessions()
83
+ if recorded is None:
84
+ # Without knowing what is listed, all would be every session.
85
+ raise ValueError(_NOT_FOUND(desktop_sessions_directory()))
86
+ directories = {i: session.cwd for i, session in sessions.items()}
87
+ # Archived sessions are recorded, so are not resumed.
88
+ listed = recorded.keys()
89
+ else:
90
+ assert session_id is not None
91
+ resume_id = find_session_id(list(sessions), session_id)
92
+ directories = {resume_id: sessions[resume_id].cwd}
93
+ listed = ()
94
+ resumable, skipped = plan_resume(directories=directories, listed=listed)
95
+
96
+ # One session that is asked for is an error. Skipping a session is for
97
+ # when all of them are.
98
+ if skipped and not all_:
99
+ ((skipped_id, problem),) = skipped.items()
100
+ raise ValueError("Session '{}' {}".format(skipped_id, problem))
101
+ for skipped_id, problem in skipped.items():
102
+ print("Skipping {}, as it {}.".format(skipped_id, problem))
103
+
104
+ with claude_code(binary_cache_path=binary_cache_path) as cc:
105
+
106
+ def resume(resume_id: str, cwd: pathlib.Path) -> None:
107
+ print("Resuming {}.".format(resume_id))
108
+ cc.resume_in_desktop(session_id=resume_id, cwd=cwd)
109
+
110
+ if not all_:
111
+ # One session that is asked for is an error, if it fails.
112
+ for resume_id, cwd in resumable.items():
113
+ resume(resume_id, cwd)
114
+ return
115
+ resumed, failed = resume_each(resumable=resumable, resume=resume)
116
+
117
+ for failed_id, reason in failed.items():
118
+ print("Could not resume {}: {}".format(failed_id, reason))
119
+ print(
120
+ "Resumed {} of {} sessions not listed.".format(
121
+ len(resumed), len(resumable) + len(skipped)
122
+ )
123
+ )
124
+ # Skipping is not a failure, but a session that was tried is.
125
+ if failed:
126
+ raise SystemExit(1)
127
+
128
+ return cast(Task[Callable[..., None]], task_resume)
129
+
130
+
131
+ def get_collection(
132
+ *,
133
+ collection_name: str,
134
+ binary_cache_path: pathlib.Path,
135
+ ) -> Collection:
136
+ """Get a collection of tasks for the sessions that the Claude desktop app lists."""
137
+ collection = Collection(collection_name)
138
+ collection.add_task(get_task_resume(binary_cache_path=binary_cache_path))
139
+ collection.add_task(get_task_sessions())
140
+ return collection