lithora-cli 0.2.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lithora
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,9 @@
1
+ include LICENSE
2
+ prune tests
3
+ global-exclude *.py[cod]
4
+ global-exclude __pycache__
5
+
6
+ # Ship ONLY the README among markdown — keep internal docs (EXPANSION_PLAN.md,
7
+ # roadmaps, plans, in-progress changelogs) out of the public PyPI distribution.
8
+ global-exclude *.md
9
+ include README.md
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: lithora-cli
3
+ Version: 0.2.0
4
+ Summary: Command-line interface for the Lithora REST API (the agent-grade control plane)
5
+ Author-email: Lithora <support@lithora.io>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://lithora.io
8
+ Project-URL: Documentation, https://github.com/AADI0009/SaaS-App/tree/main/cli
9
+ Project-URL: Repository, https://github.com/AADI0009/SaaS-App
10
+ Project-URL: Issues, https://github.com/AADI0009/SaaS-App/issues
11
+ Project-URL: API, https://api.lithora.io
12
+ Keywords: lithora,cli,project-management,api,agent
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: Utilities
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: typer>=0.12
29
+ Requires-Dist: rich>=13
30
+ Requires-Dist: keyring>=24
31
+ Requires-Dist: lithora>=0.1
32
+ Provides-Extra: yaml
33
+ Requires-Dist: pyyaml>=6; extra == "yaml"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7; extra == "dev"
36
+ Requires-Dist: responses>=0.23; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # lithora — the Lithora CLI
40
+
41
+ The terminal-native, agent-grade control plane for [Lithora](https://lithora.io).
42
+ Manage teams, projects, issues, automations — and drive the **confirmation-gated AI
43
+ agent** — without leaving your shell or your CI pipeline.
44
+
45
+ Built on the official [`lithora`](../sdk/python) Python SDK (one shared HTTP core,
46
+ nothing vendored). `v0.2` — **beta**.
47
+
48
+ ## Install
49
+
50
+ ```bash
51
+ pipx install lithora-cli # recommended (isolated)
52
+ # or
53
+ pip install lithora-cli
54
+ ```
55
+
56
+ This installs the `lithora` command. Requires Python 3.9+. Optional: `keyring`
57
+ (used automatically for OS-keychain token storage; falls back to a 600-mode file).
58
+
59
+ ## Quickstart (every command here is real)
60
+
61
+ ```bash
62
+ # 1. Point at your API (defaults to https://api.lithora.io)
63
+ export LITHORA_BASE_URL=http://localhost:8000 # optional, local dev
64
+
65
+ # 2. Log in (password is prompted securely; token → OS keychain or 600-mode file)
66
+ lithora login --email you@example.com
67
+ lithora whoami
68
+ lithora doctor # diagnose auth/connectivity
69
+
70
+ # 3. Projects & issues
71
+ lithora teams list
72
+ lithora projects create --name "Q3 Launch" --team <team_id>
73
+ lithora tasks create --title "Wire up billing" --project <project_id> --priority high
74
+ lithora tasks list --project <project_id> --status todo
75
+ lithora tasks status <task_id> in_progress
76
+
77
+ # 4. The AI agent — propose → approve in the terminal → apply
78
+ lithora ai "break the autosave issue into a parent task and subtasks"
79
+ # → renders the plan, asks "Approve? [y]es / [n]o", then applies on approval.
80
+
81
+ # 5. Automations, GitHub, the work graph
82
+ lithora automations list
83
+ lithora automations execute <automation_id>
84
+ lithora work-items graph --team <team_id>
85
+ lithora work-items pr-status <task_id>
86
+ ```
87
+
88
+ ## The confirmation gate (the keystone)
89
+
90
+ The agent **never writes without your approval**. `lithora ai "<prompt>"` shows the
91
+ proposed plan and waits:
92
+
93
+ ```
94
+ ACTION PLAN (requires confirmation)
95
+ 1. + task: Add autosave to the editor [acme/web#418]
96
+ - subtask: Persist drafts to localStorage
97
+ - subtask: Debounced autosave on change
98
+ Summary: Agent will create 1 task + 3 subtasks
99
+ Approve? [y]es / [n]o:
100
+ ```
101
+
102
+ - **Interactive:** `y` applies it, `n` discards it.
103
+ - **CI / non-interactive:** add `--yes` to auto-approve, e.g.
104
+ `lithora ai chat "<prompt>" --yes` (the plan is still printed first). `lithora ai
105
+ "<prompt>"` is shorthand for `lithora ai chat`, so the flag works on both forms.
106
+ Without a TTY and without `--yes`, the CLI **refuses to write** and exits `2` —
107
+ so an unattended run can never silently mutate your workspace.
108
+ - **Overnight digests:** `lithora ai pending` lists plans the scheduled triage agent
109
+ staged; approve one with `lithora ai confirm <action_id> --session <sid>`.
110
+
111
+ ## Output & scripting
112
+
113
+ ```bash
114
+ lithora tasks list --project P -o json | jq '.tasks[].title' # stable JSON
115
+ lithora -o json automations list # machine-readable
116
+ ```
117
+
118
+ - `--output table` (default, colorized on a TTY) · `--output json` (stable, for CI) · `--output yaml`.
119
+ - **Exit codes:** `0` ok · `2` usage / confirmation-needed · `3` auth · `4` not-found ·
120
+ `5` conflict · `22` invalid input · `130` interrupted.
121
+
122
+ ## Profiles, config & tokens
123
+
124
+ ```bash
125
+ lithora profile list
126
+ lithora --profile work whoami # target a different account/org
127
+ lithora token create --name "GitHub CI" --scope tasks:write --expires-in-days 90
128
+ lithora token list
129
+ lithora token revoke <token_id>
130
+ ```
131
+
132
+ - Config lives in `~/.lithora/config.json` (dir `700` / file `600`). The bearer token
133
+ is stored in your **OS keychain** when available, else the 600-mode file.
134
+ - Precedence: **flag > env (`LITHORA_TOKEN`/`LITHORA_BASE_URL`/`LITHORA_PROFILE`) > profile > default**.
135
+ - The password is never accepted as a flag value (argv/history leak). Use the prompt
136
+ or `--password-stdin` in CI.
137
+
138
+ ## CI example (GitHub Actions)
139
+
140
+ ```yaml
141
+ - name: Create a Lithora issue from a failing build
142
+ if: failure()
143
+ env:
144
+ LITHORA_TOKEN: ${{ secrets.LITHORA_PAT }} # a scoped PAT (lithora token create)
145
+ run: |
146
+ pipx install lithora-cli
147
+ lithora tasks create --title "CI failed on ${{ github.sha }}" \
148
+ --project "$LITHORA_PROJECT" --priority high -o json
149
+ ```
150
+
151
+ ## Command map
152
+
153
+ `login` · `logout` · `whoami` · `doctor` · `--version`
154
+ `teams` · `projects` · `tasks` · `work-items` · `automations` · `github` · `search`
155
+ `ai` (chat / pending / confirm / sessions) · `token` · `profile`
156
+
157
+ Run `lithora <group> --help` for the full surface. See
158
+ [`EXPANSION_PLAN.md`](EXPANSION_PLAN.md) for the roadmap.
159
+
160
+ ## License
161
+
162
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,124 @@
1
+ # lithora — the Lithora CLI
2
+
3
+ The terminal-native, agent-grade control plane for [Lithora](https://lithora.io).
4
+ Manage teams, projects, issues, automations — and drive the **confirmation-gated AI
5
+ agent** — without leaving your shell or your CI pipeline.
6
+
7
+ Built on the official [`lithora`](../sdk/python) Python SDK (one shared HTTP core,
8
+ nothing vendored). `v0.2` — **beta**.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pipx install lithora-cli # recommended (isolated)
14
+ # or
15
+ pip install lithora-cli
16
+ ```
17
+
18
+ This installs the `lithora` command. Requires Python 3.9+. Optional: `keyring`
19
+ (used automatically for OS-keychain token storage; falls back to a 600-mode file).
20
+
21
+ ## Quickstart (every command here is real)
22
+
23
+ ```bash
24
+ # 1. Point at your API (defaults to https://api.lithora.io)
25
+ export LITHORA_BASE_URL=http://localhost:8000 # optional, local dev
26
+
27
+ # 2. Log in (password is prompted securely; token → OS keychain or 600-mode file)
28
+ lithora login --email you@example.com
29
+ lithora whoami
30
+ lithora doctor # diagnose auth/connectivity
31
+
32
+ # 3. Projects & issues
33
+ lithora teams list
34
+ lithora projects create --name "Q3 Launch" --team <team_id>
35
+ lithora tasks create --title "Wire up billing" --project <project_id> --priority high
36
+ lithora tasks list --project <project_id> --status todo
37
+ lithora tasks status <task_id> in_progress
38
+
39
+ # 4. The AI agent — propose → approve in the terminal → apply
40
+ lithora ai "break the autosave issue into a parent task and subtasks"
41
+ # → renders the plan, asks "Approve? [y]es / [n]o", then applies on approval.
42
+
43
+ # 5. Automations, GitHub, the work graph
44
+ lithora automations list
45
+ lithora automations execute <automation_id>
46
+ lithora work-items graph --team <team_id>
47
+ lithora work-items pr-status <task_id>
48
+ ```
49
+
50
+ ## The confirmation gate (the keystone)
51
+
52
+ The agent **never writes without your approval**. `lithora ai "<prompt>"` shows the
53
+ proposed plan and waits:
54
+
55
+ ```
56
+ ACTION PLAN (requires confirmation)
57
+ 1. + task: Add autosave to the editor [acme/web#418]
58
+ - subtask: Persist drafts to localStorage
59
+ - subtask: Debounced autosave on change
60
+ Summary: Agent will create 1 task + 3 subtasks
61
+ Approve? [y]es / [n]o:
62
+ ```
63
+
64
+ - **Interactive:** `y` applies it, `n` discards it.
65
+ - **CI / non-interactive:** add `--yes` to auto-approve, e.g.
66
+ `lithora ai chat "<prompt>" --yes` (the plan is still printed first). `lithora ai
67
+ "<prompt>"` is shorthand for `lithora ai chat`, so the flag works on both forms.
68
+ Without a TTY and without `--yes`, the CLI **refuses to write** and exits `2` —
69
+ so an unattended run can never silently mutate your workspace.
70
+ - **Overnight digests:** `lithora ai pending` lists plans the scheduled triage agent
71
+ staged; approve one with `lithora ai confirm <action_id> --session <sid>`.
72
+
73
+ ## Output & scripting
74
+
75
+ ```bash
76
+ lithora tasks list --project P -o json | jq '.tasks[].title' # stable JSON
77
+ lithora -o json automations list # machine-readable
78
+ ```
79
+
80
+ - `--output table` (default, colorized on a TTY) · `--output json` (stable, for CI) · `--output yaml`.
81
+ - **Exit codes:** `0` ok · `2` usage / confirmation-needed · `3` auth · `4` not-found ·
82
+ `5` conflict · `22` invalid input · `130` interrupted.
83
+
84
+ ## Profiles, config & tokens
85
+
86
+ ```bash
87
+ lithora profile list
88
+ lithora --profile work whoami # target a different account/org
89
+ lithora token create --name "GitHub CI" --scope tasks:write --expires-in-days 90
90
+ lithora token list
91
+ lithora token revoke <token_id>
92
+ ```
93
+
94
+ - Config lives in `~/.lithora/config.json` (dir `700` / file `600`). The bearer token
95
+ is stored in your **OS keychain** when available, else the 600-mode file.
96
+ - Precedence: **flag > env (`LITHORA_TOKEN`/`LITHORA_BASE_URL`/`LITHORA_PROFILE`) > profile > default**.
97
+ - The password is never accepted as a flag value (argv/history leak). Use the prompt
98
+ or `--password-stdin` in CI.
99
+
100
+ ## CI example (GitHub Actions)
101
+
102
+ ```yaml
103
+ - name: Create a Lithora issue from a failing build
104
+ if: failure()
105
+ env:
106
+ LITHORA_TOKEN: ${{ secrets.LITHORA_PAT }} # a scoped PAT (lithora token create)
107
+ run: |
108
+ pipx install lithora-cli
109
+ lithora tasks create --title "CI failed on ${{ github.sha }}" \
110
+ --project "$LITHORA_PROJECT" --priority high -o json
111
+ ```
112
+
113
+ ## Command map
114
+
115
+ `login` · `logout` · `whoami` · `doctor` · `--version`
116
+ `teams` · `projects` · `tasks` · `work-items` · `automations` · `github` · `search`
117
+ `ai` (chat / pending / confirm / sessions) · `token` · `profile`
118
+
119
+ Run `lithora <group> --help` for the full surface. See
120
+ [`EXPANSION_PLAN.md`](EXPANSION_PLAN.md) for the roadmap.
121
+
122
+ ## License
123
+
124
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,3 @@
1
+ """lithora-cli — the terminal-native, agent-grade control plane for Lithora."""
2
+
3
+ __version__ = "0.2.0"
File without changes
@@ -0,0 +1,41 @@
1
+ """Shared command helpers: client access + clean SDK-error → exit-code mapping."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from contextlib import contextmanager
6
+
7
+ import typer
8
+
9
+ from lithora import ApiError, AuthError, LithoraError
10
+ from ..output import error, exit_code_for, render
11
+
12
+
13
+ def client(ctx: typer.Context):
14
+ """The authenticated Lithora client built by the global callback."""
15
+ return ctx.obj["client"]
16
+
17
+
18
+ def out(ctx: typer.Context) -> str:
19
+ return ctx.obj.get("output", "table")
20
+
21
+
22
+ @contextmanager
23
+ def errors():
24
+ """Map SDK exceptions to a friendly stderr message + the right exit code."""
25
+ try:
26
+ yield
27
+ except AuthError as e:
28
+ detail = getattr(e, "detail", None) or str(e)
29
+ error("{} (run 'lithora login')".format(detail))
30
+ raise typer.Exit(exit_code_for(getattr(e, "status_code", 401)))
31
+ except ApiError as e:
32
+ error(str(getattr(e, "detail", None) or e))
33
+ raise typer.Exit(exit_code_for(getattr(e, "status_code", None)))
34
+ except LithoraError as e:
35
+ error(str(e))
36
+ raise typer.Exit(1)
37
+
38
+
39
+ def show(ctx: typer.Context, data, *, columns=None, title=None) -> None:
40
+ """Render a payload in the invocation's output mode."""
41
+ render(data, out(ctx), columns=columns, title=title)
@@ -0,0 +1,70 @@
1
+ """`lithora token` (PATs) and `lithora profile` (contexts)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import List, Optional
6
+
7
+ import typer
8
+
9
+ from .. import config
10
+ from ._common import client, errors, show
11
+ from ..output import success
12
+
13
+ # ---- token group (Personal Access Tokens) ---------------------------------
14
+ token_app = typer.Typer(no_args_is_help=True, help="Personal access tokens (scoped API keys).")
15
+
16
+
17
+ @token_app.command("create")
18
+ def token_create(
19
+ ctx: typer.Context,
20
+ name: str = typer.Option(..., "--name", "-n", help="Label for the token"),
21
+ scopes: Optional[List[str]] = typer.Option(None, "--scope", help="Repeatable, e.g. tasks:write"),
22
+ expires_in_days: Optional[int] = typer.Option(None, "--expires-in-days"),
23
+ ):
24
+ """Mint a scoped PAT (the secret is shown ONCE — store it securely)."""
25
+ with errors():
26
+ show(ctx, client(ctx).tokens.create(name, scopes=scopes or None, expires_in_days=expires_in_days))
27
+
28
+
29
+ @token_app.command("list")
30
+ def token_list(ctx: typer.Context):
31
+ """List your PATs (masked)."""
32
+ with errors():
33
+ show(ctx, client(ctx).tokens.list(),
34
+ columns=["token_id", "name", "scopes", "expires_at", "last_used_at"])
35
+
36
+
37
+ @token_app.command("revoke")
38
+ def token_revoke(ctx: typer.Context, token_id: str = typer.Argument(...)):
39
+ """Revoke a PAT immediately."""
40
+ with errors():
41
+ client(ctx).tokens.revoke(token_id)
42
+ success("Revoked {}".format(token_id))
43
+
44
+
45
+ # ---- profile group (contexts) ---------------------------------------------
46
+ profile_app = typer.Typer(no_args_is_help=True, help="Switch between accounts/orgs (contexts).")
47
+
48
+
49
+ @profile_app.command("list")
50
+ def profile_list(ctx: typer.Context):
51
+ """List configured profiles."""
52
+ cur = config.current_profile()
53
+ rows = [{"profile": ("* " + n) if n == cur else n, "base_url": p.get("base_url", "")}
54
+ for n, p in config.list_profiles().items()]
55
+ show(ctx, {"profiles": rows or [{"profile": "default", "base_url": config.DEFAULT_BASE_URL}]},
56
+ columns=["profile", "base_url"])
57
+
58
+
59
+ @profile_app.command("use")
60
+ def profile_use(name: str = typer.Argument(..., help="Profile name to switch to")):
61
+ """Set the active profile."""
62
+ config.use_profile(name)
63
+ success("Now using profile '{}'".format(name))
64
+
65
+
66
+ @profile_app.command("show")
67
+ def profile_show(ctx: typer.Context):
68
+ """Show the active profile + base URL (token not printed)."""
69
+ cfg = ctx.obj["config"]
70
+ show(ctx, {"profile": cfg.profile, "base_url": cfg.base_url, "authenticated": bool(cfg.token)})
@@ -0,0 +1,192 @@
1
+ """`lithora ai` — the confirmation-gated agent, in your terminal.
2
+
3
+ lithora ai "plan the Q3 launch into tasks" # propose → approve → apply
4
+ lithora ai pending # staged overnight-triage plans
5
+ lithora ai confirm <action_id> --session <sid> # approve a staged plan
6
+ lithora ai sessions # your AI sessions
7
+
8
+ The agent NEVER writes without approval: chat returns a PLAN; you approve it here.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from typing import Optional
14
+
15
+ import typer
16
+ from typer.core import TyperGroup
17
+
18
+ try: # standard Typer depends on the real click…
19
+ import click # type: ignore
20
+ except ImportError: # …typer-slim vendors it as typer._click
21
+ from typer import _click as click # type: ignore
22
+
23
+ from ._common import client, errors, out, show
24
+ from ..output import error, is_tty, print_json, success, EXIT_USAGE
25
+
26
+
27
+ class _AiGroup(TyperGroup):
28
+ """Route a bare prompt to ``chat`` so ``lithora ai "plan the launch"`` works.
29
+
30
+ Real subcommands (chat/pending/confirm/sessions) still resolve normally; only
31
+ when the first token isn't one of them do we treat the whole arg list as a
32
+ chat message — so the natural-language shortcut and the structured commands
33
+ coexist without one stealing the other.
34
+ """
35
+
36
+ def resolve_command(self, ctx, args):
37
+ try:
38
+ return super().resolve_command(ctx, args)
39
+ except click.exceptions.UsageError:
40
+ chat_cmd = self.get_command(ctx, "chat")
41
+ if chat_cmd is None: # pragma: no cover - chat is always registered
42
+ raise
43
+ return chat_cmd.name, chat_cmd, args
44
+
45
+
46
+ app = typer.Typer(
47
+ cls=_AiGroup,
48
+ no_args_is_help=False,
49
+ invoke_without_command=True,
50
+ # Tolerate a leading flag before the prompt (e.g. `ai --yes "do it"`); the
51
+ # bare prompt itself is rerouted to `chat` by _AiGroup.resolve_command.
52
+ context_settings={"allow_extra_args": True, "ignore_unknown_options": True},
53
+ help="Talk to the confirmation-gated Lithora agent.",
54
+ )
55
+
56
+
57
+ def _render_plan(plan: dict) -> None:
58
+ """Pretty-print a staged plan (summary + planned actions)."""
59
+ typer.secho("\nACTION PLAN (requires confirmation)", fg=typer.colors.YELLOW, bold=True)
60
+ typer.echo(" Action: {} Status: {}".format(
61
+ plan.get("action_id", "?"), plan.get("state", "waiting_confirmation")))
62
+ for i, a in enumerate((plan.get("planned_actions") or []), 1):
63
+ kind = a.get("type", "action")
64
+ if kind == "task":
65
+ gh = ""
66
+ if a.get("github_repo"):
67
+ gh = " [{}{}]".format(a["github_repo"],
68
+ "#{}".format(a["github_issue_number"]) if a.get("github_issue_number") else "")
69
+ typer.echo(" {}. + task: {}{}".format(i, a.get("title", "?"), gh))
70
+ for s in (a.get("subtasks") or []):
71
+ typer.echo(" - subtask: {}".format(s.get("title", "?")))
72
+ elif kind in ("subtask", "note"):
73
+ typer.echo(" {}. + {}: {}".format(i, kind, a.get("title", "?")))
74
+ else:
75
+ typer.echo(" {}. {}".format(i, a.get("label") or a.get("tool") or kind))
76
+ typer.echo(" Summary: {}".format(plan.get("summary", "")))
77
+
78
+
79
+ def _apply(ctx, session_id: str, action_id: str, confirmed: bool) -> None:
80
+ res = client(ctx).ai.confirm_agent_action(session_id, action_id, confirmed)
81
+ if out(ctx) == "json":
82
+ print_json(res)
83
+ return
84
+ if not confirmed:
85
+ success("Discarded — nothing was written.")
86
+ return
87
+ success(res.get("response", "Applied."))
88
+ for inv in (res.get("action_plan", {}) or {}).get("tool_invocations", []):
89
+ ok = "✓" if inv.get("success") else "✗"
90
+ typer.echo(" {} {}".format(ok, inv.get("function")))
91
+
92
+
93
+ @app.callback(invoke_without_command=True)
94
+ def ai_main(ctx: typer.Context):
95
+ """Send a message; if the agent proposes changes, approve them in the terminal.
96
+
97
+ `lithora ai "<prompt>"` is a shortcut for `lithora ai chat "<prompt>"` —
98
+ a bare prompt is routed to the chat subcommand (see _AiGroup), so flags like
99
+ --yes / --session work the same either way.
100
+ """
101
+ if ctx.invoked_subcommand is None:
102
+ typer.echo(ctx.get_help())
103
+ raise typer.Exit(0)
104
+
105
+
106
+ @app.command("chat")
107
+ def chat(
108
+ ctx: typer.Context,
109
+ prompt: str = typer.Argument(..., help="Your message to the agent"),
110
+ session: Optional[str] = typer.Option(None, "--session", "-s", help="Existing session id"),
111
+ yes: bool = typer.Option(False, "--yes", "-y", help="Auto-approve the plan (CI)"),
112
+ ):
113
+ """Chat with the agent (full form, with --yes / --session)."""
114
+ _do_chat(ctx, prompt, session=session, yes=yes)
115
+
116
+
117
+ def _do_chat(ctx: typer.Context, prompt: str, session: Optional[str], yes: bool) -> None:
118
+ with errors():
119
+ c = client(ctx)
120
+ sid = session or c.ai.create_session().get("session_id")
121
+ resp = c.ai.chat(sid, prompt)
122
+
123
+ if out(ctx) == "json":
124
+ print_json(resp)
125
+ # In JSON mode, still honor --yes so CI can one-shot.
126
+ plan = resp.get("action_plan") or {}
127
+ if resp.get("requires_confirmation") and plan.get("action_id") and yes:
128
+ _apply(ctx, sid, plan["action_id"], True)
129
+ return
130
+
131
+ plan = resp.get("action_plan") or {}
132
+ if not (resp.get("requires_confirmation") and plan.get("action_id")):
133
+ # plain answer (no mutations proposed)
134
+ typer.echo(resp.get("response", ""))
135
+ if not session:
136
+ typer.secho("\n(session: {})".format(sid), dim=True)
137
+ return
138
+
139
+ _render_plan(plan)
140
+ action_id = plan["action_id"]
141
+
142
+ if yes:
143
+ typer.echo("\n--yes → approving.")
144
+ _apply(ctx, sid, action_id, True)
145
+ return
146
+ if not is_tty():
147
+ error("This plan requires confirmation but stdin is not a TTY. "
148
+ "Re-run with --yes, or: lithora ai confirm {} --session {}".format(action_id, sid))
149
+ raise typer.Exit(EXIT_USAGE)
150
+
151
+ choice = typer.prompt("\nApprove? [y]es / [n]o", default="n").strip().lower()
152
+ _apply(ctx, sid, action_id, choice in ("y", "yes"))
153
+ if not session:
154
+ typer.secho("(session: {})".format(sid), dim=True)
155
+
156
+
157
+ @app.command("pending")
158
+ def pending(ctx: typer.Context):
159
+ """List staged-but-unapproved agent plans (e.g. overnight triage)."""
160
+ with errors():
161
+ data = client(ctx).ai.list_pending_actions()
162
+ if out(ctx) == "json":
163
+ print_json(data)
164
+ return
165
+ items = data.get("pending", []) if isinstance(data, dict) else (data or [])
166
+ if not items:
167
+ typer.echo("No staged plans awaiting approval.")
168
+ return
169
+ for p in items:
170
+ _render_plan(p)
171
+ typer.echo(" approve: lithora ai confirm {} --session {}\n".format(
172
+ p.get("action_id"), p.get("session_id")))
173
+
174
+
175
+ @app.command("confirm")
176
+ def confirm(
177
+ ctx: typer.Context,
178
+ action_id: str = typer.Argument(...),
179
+ session: str = typer.Option(..., "--session", "-s"),
180
+ reject: bool = typer.Option(False, "--reject", help="Reject instead of approve"),
181
+ ):
182
+ """Approve (or --reject) a staged agent plan by id."""
183
+ with errors():
184
+ _apply(ctx, session, action_id, not reject)
185
+
186
+
187
+ @app.command("sessions")
188
+ def sessions(ctx: typer.Context):
189
+ """List your AI sessions."""
190
+ with errors():
191
+ show(ctx, client(ctx).ai.list_sessions(),
192
+ columns=["session_id", "title", "updated_at"])