sinapsis_cli 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sinapsis_cli/__init__.py +13 -0
- sinapsis_cli/commands/__init__.py +0 -0
- sinapsis_cli/commands/cloud/__init__.py +0 -0
- sinapsis_cli/commands/cloud/_agent_selection.py +112 -0
- sinapsis_cli/commands/cloud/_secrets_render.py +15 -0
- sinapsis_cli/commands/cloud/_webhook_render.py +19 -0
- sinapsis_cli/commands/cloud/agents.py +137 -0
- sinapsis_cli/commands/cloud/api_keys.py +155 -0
- sinapsis_cli/commands/cloud/files.py +135 -0
- sinapsis_cli/commands/cloud/jobs.py +532 -0
- sinapsis_cli/commands/cloud/packages.py +164 -0
- sinapsis_cli/commands/cloud/schedules.py +392 -0
- sinapsis_cli/commands/cloud/secrets.py +96 -0
- sinapsis_cli/commands/cloud/templates.py +95 -0
- sinapsis_cli/commands/cloud/webhooks.py +156 -0
- sinapsis_cli/commands/common/__init__.py +0 -0
- sinapsis_cli/commands/common/auth.py +219 -0
- sinapsis_cli/commands/common/profiles.py +156 -0
- sinapsis_cli/commands/common/telemetry.py +150 -0
- sinapsis_cli/commands/local_api/__init__.py +0 -0
- sinapsis_cli/commands/local_api/jobs.py +284 -0
- sinapsis_cli/commands/local_venv/__init__.py +0 -0
- sinapsis_cli/commands/local_venv/_templates_render.py +56 -0
- sinapsis_cli/commands/local_venv/jobs.py +76 -0
- sinapsis_cli/commands/local_venv/templates.py +47 -0
- sinapsis_cli/composition.py +215 -0
- sinapsis_cli/config.py +446 -0
- sinapsis_cli/execution.py +77 -0
- sinapsis_cli/main.py +185 -0
- sinapsis_cli/main_multi.py +152 -0
- sinapsis_cli/shared/__init__.py +3 -0
- sinapsis_cli/shared/jobs.py +134 -0
- sinapsis_cli/shared/terminal.py +8 -0
- sinapsis_cli/shared/writer.py +427 -0
- sinapsis_cli/state.py +310 -0
- sinapsis_cli/telemetry/__init__.py +7 -0
- sinapsis_cli/telemetry/collector.py +84 -0
- sinapsis_cli/telemetry/core.py +331 -0
- sinapsis_cli/telemetry/scheduler.py +234 -0
- sinapsis_cli/telemetry/transport.py +150 -0
- sinapsis_cli-1.0.0.dist-info/METADATA +386 -0
- sinapsis_cli-1.0.0.dist-info/RECORD +46 -0
- sinapsis_cli-1.0.0.dist-info/WHEEL +4 -0
- sinapsis_cli-1.0.0.dist-info/entry_points.txt +5 -0
- sinapsis_cli-1.0.0.dist-info/licenses/LICENSE-APACHE +202 -0
- sinapsis_cli-1.0.0.dist-info/licenses/LICENSE-MIT +21 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""Webhook commands for the Sinapsis CLI."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import json
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
from sinapsis_contracts.cloud_api.models.webhooks.payloads import RegisterWebhookRequest
|
|
9
|
+
from sinapsis_contracts.cloud_api.models.webhooks.responses import RegisteredWebhookItem
|
|
10
|
+
|
|
11
|
+
from sinapsis_cli.execution import ExecutionContext, create_api_client, get_execution_context
|
|
12
|
+
|
|
13
|
+
from ._webhook_render import print_webhooks
|
|
14
|
+
|
|
15
|
+
app = typer.Typer(name="webhooks", help="Manage webhook integrations.", no_args_is_help=True)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@app.command()
|
|
19
|
+
def register(
|
|
20
|
+
ctx: typer.Context,
|
|
21
|
+
integration_name: str = typer.Argument(..., help="Name for the webhook integration."),
|
|
22
|
+
provider: str = typer.Option(..., "--provider", "-p", help="Webhook provider."),
|
|
23
|
+
credential_id: UUID | None = typer.Option(None, "--credential-id", help="Credential ID used by the provider."),
|
|
24
|
+
enforce_schema: bool = typer.Option(
|
|
25
|
+
False, "--enforce-schema", help="Require incoming payloads to match the expected schema."
|
|
26
|
+
),
|
|
27
|
+
expected_schema: str | None = typer.Option(
|
|
28
|
+
None, "--expected-schema", help="JSON schema used to validate incoming payloads."
|
|
29
|
+
),
|
|
30
|
+
) -> None:
|
|
31
|
+
"""Register a webhook integration."""
|
|
32
|
+
asyncio.run(
|
|
33
|
+
_register(
|
|
34
|
+
execution=get_execution_context(ctx),
|
|
35
|
+
integration_name=integration_name,
|
|
36
|
+
provider=provider,
|
|
37
|
+
credential_id=credential_id,
|
|
38
|
+
enforce_schema=enforce_schema,
|
|
39
|
+
expected_schema=expected_schema,
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def _register(
|
|
45
|
+
*,
|
|
46
|
+
execution: ExecutionContext,
|
|
47
|
+
integration_name: str,
|
|
48
|
+
provider: str,
|
|
49
|
+
credential_id: UUID | None,
|
|
50
|
+
enforce_schema: bool,
|
|
51
|
+
expected_schema: str | None,
|
|
52
|
+
) -> None:
|
|
53
|
+
payload_data: dict[str, object] = {
|
|
54
|
+
"integration_name": integration_name,
|
|
55
|
+
"provider": provider,
|
|
56
|
+
"credential_id": credential_id,
|
|
57
|
+
"enforce_schema": enforce_schema,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if expected_schema is not None:
|
|
61
|
+
payload_data["expected_schema"] = json.loads(expected_schema)
|
|
62
|
+
|
|
63
|
+
payload = RegisterWebhookRequest.model_validate(payload_data)
|
|
64
|
+
|
|
65
|
+
async with create_api_client(execution) as client:
|
|
66
|
+
webhook: RegisteredWebhookItem = await client.webhooks.register(payload)
|
|
67
|
+
|
|
68
|
+
typer.echo(f"Created webhook: {webhook.webhook_id}")
|
|
69
|
+
typer.echo(f"Name: {webhook.integration_name}")
|
|
70
|
+
typer.echo(f"Provider: {webhook.provider}")
|
|
71
|
+
typer.echo(f"Active: {webhook.is_active}")
|
|
72
|
+
typer.echo(f"Public URL: {webhook.webhook_url}")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@app.command("list")
|
|
76
|
+
def list_webhooks(ctx: typer.Context) -> None:
|
|
77
|
+
"""List registered webhook integrations."""
|
|
78
|
+
asyncio.run(_list_webhooks(get_execution_context(ctx)))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
async def _list_webhooks(execution: ExecutionContext) -> None:
|
|
82
|
+
async with create_api_client(execution) as client:
|
|
83
|
+
webhooks = await client.webhooks.list_user_webhooks()
|
|
84
|
+
|
|
85
|
+
if not webhooks:
|
|
86
|
+
typer.echo("No webhook integrations found.")
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
print_webhooks(webhooks)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@app.command("show")
|
|
93
|
+
def show_webhook(
|
|
94
|
+
ctx: typer.Context,
|
|
95
|
+
webhook_id: UUID = typer.Argument(..., help="ID of the webhook integration."),
|
|
96
|
+
) -> None:
|
|
97
|
+
"""Show one webhook integration's configuration and public URL."""
|
|
98
|
+
asyncio.run(_show_webhook(get_execution_context(ctx), webhook_id))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
async def _show_webhook(execution: ExecutionContext, webhook_id: UUID) -> None:
|
|
102
|
+
async with create_api_client(execution) as client:
|
|
103
|
+
webhook = await client.webhooks.get(webhook_id)
|
|
104
|
+
typer.echo(webhook.model_dump_json(indent=2))
|
|
105
|
+
typer.echo(f"Public URL: {webhook.webhook_url}")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@app.command()
|
|
109
|
+
def delete(
|
|
110
|
+
ctx: typer.Context,
|
|
111
|
+
webhook_id: UUID = typer.Argument(..., help="ID of the webhook integration."),
|
|
112
|
+
) -> None:
|
|
113
|
+
"""Delete a webhook integration."""
|
|
114
|
+
if not typer.confirm(f"Delete webhook {webhook_id!r}?"):
|
|
115
|
+
raise typer.Abort()
|
|
116
|
+
|
|
117
|
+
asyncio.run(_delete(get_execution_context(ctx), webhook_id))
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
async def _delete(execution: ExecutionContext, webhook_id: UUID) -> None:
|
|
121
|
+
async with create_api_client(execution) as client:
|
|
122
|
+
result = await client.webhooks.delete(str(webhook_id))
|
|
123
|
+
|
|
124
|
+
typer.echo(result.message)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@app.command()
|
|
128
|
+
def toggle(
|
|
129
|
+
ctx: typer.Context,
|
|
130
|
+
webhook_id: UUID = typer.Argument(..., help="ID of the webhook integration."),
|
|
131
|
+
active: bool = typer.Option(..., "--active/--inactive", help="Enable or disable the webhook integration."),
|
|
132
|
+
) -> None:
|
|
133
|
+
"""Enable or disable a webhook integration."""
|
|
134
|
+
asyncio.run(_toggle(get_execution_context(ctx), webhook_id, active))
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
async def _toggle(execution: ExecutionContext, webhook_id: UUID, active: bool) -> None:
|
|
138
|
+
async with create_api_client(execution) as client:
|
|
139
|
+
webhook = await client.webhooks.toggle(str(webhook_id), is_active=active)
|
|
140
|
+
|
|
141
|
+
state = "active" if webhook.is_active else "inactive"
|
|
142
|
+
typer.echo(f"Webhook {webhook_id!r} is now {state}.")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@app.command("public-url")
|
|
146
|
+
def public_url(
|
|
147
|
+
ctx: typer.Context,
|
|
148
|
+
webhook_id: UUID = typer.Argument(..., help="ID of the webhook integration."),
|
|
149
|
+
) -> None:
|
|
150
|
+
"""Print the public URL for a webhook integration."""
|
|
151
|
+
asyncio.run(_public_url(get_execution_context(ctx), webhook_id))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
async def _public_url(execution: ExecutionContext, webhook_id: UUID) -> None:
|
|
155
|
+
async with create_api_client(execution) as client:
|
|
156
|
+
typer.echo(client.webhooks.public_url(webhook_id))
|
|
File without changes
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""Authentication and interactive profile configuration commands."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
import typer
|
|
7
|
+
from sinapsis.logging import sinapsis_logger
|
|
8
|
+
from sinapsis_sdk.cloud_api._auth import AuthManager
|
|
9
|
+
from sinapsis_sdk.cloud_api._config import ConfigStore
|
|
10
|
+
from sinapsis_sdk.cloud_api._credentials import create_credential_store
|
|
11
|
+
from sinapsis_sdk.cloud_api.cloud_config import CloudAPIConfig
|
|
12
|
+
|
|
13
|
+
from sinapsis_cli.config import (
|
|
14
|
+
DEFAULT_CLOUD_URL,
|
|
15
|
+
DEFAULT_LOCAL_URL,
|
|
16
|
+
DEFAULT_VENV,
|
|
17
|
+
CLIConfig,
|
|
18
|
+
ExecutionBackend,
|
|
19
|
+
Profile,
|
|
20
|
+
load_config,
|
|
21
|
+
save_config,
|
|
22
|
+
)
|
|
23
|
+
from sinapsis_cli.execution import ExecutionContext, get_execution_context
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def configure(
|
|
27
|
+
ctx: typer.Context,
|
|
28
|
+
profile: str | None = typer.Option(None, "--profile", "-p", help="Configure a specific profile."),
|
|
29
|
+
all_profiles: bool = typer.Option(False, "--all-profiles", help="Configure every defined profile."),
|
|
30
|
+
) -> None:
|
|
31
|
+
"""Configure Sinapsis execution profiles.
|
|
32
|
+
|
|
33
|
+
With an explicitly selected positional profile, that profile is configured.
|
|
34
|
+
Without one, the command preserves the previous behavior and configures all
|
|
35
|
+
profiles unless ``--profile`` chooses a specific profile.
|
|
36
|
+
"""
|
|
37
|
+
execution = get_execution_context(ctx)
|
|
38
|
+
|
|
39
|
+
if profile is not None and all_profiles:
|
|
40
|
+
raise typer.BadParameter("--profile and --all-profiles are mutually exclusive.")
|
|
41
|
+
|
|
42
|
+
asyncio.run(_configure(execution=execution, profile_name=profile, all_profiles=all_profiles))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def _configure(*, execution: ExecutionContext, profile_name: str | None, all_profiles: bool) -> None:
|
|
46
|
+
"""Configure one or more Sinapsis execution profiles."""
|
|
47
|
+
cli_config = load_config()
|
|
48
|
+
assert cli_config.profiles is not None
|
|
49
|
+
|
|
50
|
+
if profile_name is not None:
|
|
51
|
+
names = [cli_config.get_profile(profile_name).name]
|
|
52
|
+
elif execution.explicit_profile and not all_profiles:
|
|
53
|
+
names = [execution.profile_name]
|
|
54
|
+
else:
|
|
55
|
+
names = list(cli_config.profiles)
|
|
56
|
+
|
|
57
|
+
typer.echo("Sinapsis configuration")
|
|
58
|
+
typer.echo()
|
|
59
|
+
|
|
60
|
+
for name in names:
|
|
61
|
+
await _configure_profile(cli_config, name)
|
|
62
|
+
|
|
63
|
+
if len(names) > 1:
|
|
64
|
+
_configure_default(cli_config)
|
|
65
|
+
|
|
66
|
+
save_config(cli_config)
|
|
67
|
+
|
|
68
|
+
typer.echo()
|
|
69
|
+
typer.echo("Configuration complete.")
|
|
70
|
+
typer.echo(f"Default profile: {cli_config.default_profile}")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
async def _configure_profile(cli_config: CLIConfig, profile_name: str) -> None:
|
|
74
|
+
"""Configure one profile according to its execution backend."""
|
|
75
|
+
profile = cli_config.get_profile(profile_name)
|
|
76
|
+
|
|
77
|
+
if profile.backend is ExecutionBackend.LOCAL_VENV:
|
|
78
|
+
_configure_local_venv(cli_config, profile)
|
|
79
|
+
return
|
|
80
|
+
|
|
81
|
+
if profile.backend is ExecutionBackend.LOCAL_API:
|
|
82
|
+
_configure_local_api(cli_config, profile)
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
if profile.backend is ExecutionBackend.CLOUD:
|
|
86
|
+
await _configure_cloud(cli_config, profile)
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
raise RuntimeError(f"No profile configurator for backend {profile.backend.value!r}.")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _configure_local_venv(cli_config: CLIConfig, profile: Profile) -> None:
|
|
93
|
+
"""Configure local virtual-environment execution."""
|
|
94
|
+
assert cli_config.profiles is not None
|
|
95
|
+
|
|
96
|
+
typer.echo(f"Local execution [{profile.name}]")
|
|
97
|
+
typer.echo("-" * (18 + len(profile.name)))
|
|
98
|
+
|
|
99
|
+
venv = typer.prompt("Virtual environment", default=profile.venv or DEFAULT_VENV)
|
|
100
|
+
|
|
101
|
+
cli_config.profiles[profile.name] = Profile(
|
|
102
|
+
name=profile.name,
|
|
103
|
+
backend=profile.backend,
|
|
104
|
+
venv=venv,
|
|
105
|
+
authenticated=False,
|
|
106
|
+
command_sets=profile.command_sets,
|
|
107
|
+
)
|
|
108
|
+
typer.echo()
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
async def _configure_cloud(cli_config: CLIConfig, profile: Profile) -> None:
|
|
112
|
+
"""Configure cloud execution and authenticate the user."""
|
|
113
|
+
assert cli_config.profiles is not None
|
|
114
|
+
|
|
115
|
+
typer.echo(f"Cloud API [{profile.name}]")
|
|
116
|
+
typer.echo("-" * (12 + len(profile.name)))
|
|
117
|
+
|
|
118
|
+
api_url = typer.prompt("Cloud API URL", default=profile.api_url or DEFAULT_CLOUD_URL).rstrip("/")
|
|
119
|
+
|
|
120
|
+
cli_config.profiles[profile.name] = Profile(
|
|
121
|
+
name=profile.name,
|
|
122
|
+
backend=profile.backend,
|
|
123
|
+
api_url=api_url,
|
|
124
|
+
authenticated=True,
|
|
125
|
+
command_sets=profile.command_sets,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
current_api_config = ConfigStore().load()
|
|
129
|
+
api_config = CloudAPIConfig(api_url=api_url, timeout=current_api_config.timeout)
|
|
130
|
+
|
|
131
|
+
typer.echo()
|
|
132
|
+
typer.echo("Cloud authentication")
|
|
133
|
+
typer.echo()
|
|
134
|
+
|
|
135
|
+
credential_store = create_credential_store()
|
|
136
|
+
auth = AuthManager(api_config, credential_store)
|
|
137
|
+
|
|
138
|
+
try:
|
|
139
|
+
await _configure_supabase(auth)
|
|
140
|
+
finally:
|
|
141
|
+
await auth.aclose()
|
|
142
|
+
|
|
143
|
+
typer.echo()
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _configure_local_api(cli_config: CLIConfig, profile: Profile) -> None:
|
|
147
|
+
"""Configure local API execution."""
|
|
148
|
+
assert cli_config.profiles is not None
|
|
149
|
+
|
|
150
|
+
typer.echo(f"Local API [{profile.name}]")
|
|
151
|
+
typer.echo("-" * (12 + len(profile.name)))
|
|
152
|
+
|
|
153
|
+
api_url = typer.prompt("Local API URL", default=profile.api_url or DEFAULT_LOCAL_URL).rstrip("/")
|
|
154
|
+
|
|
155
|
+
cli_config.profiles[profile.name] = Profile(
|
|
156
|
+
name=profile.name,
|
|
157
|
+
backend=profile.backend,
|
|
158
|
+
api_url=api_url,
|
|
159
|
+
authenticated=False,
|
|
160
|
+
command_sets=profile.command_sets,
|
|
161
|
+
)
|
|
162
|
+
typer.echo()
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _configure_default(cli_config: CLIConfig) -> None:
|
|
166
|
+
"""Configure the default execution profile."""
|
|
167
|
+
assert cli_config.profiles is not None
|
|
168
|
+
|
|
169
|
+
names = list(cli_config.profiles)
|
|
170
|
+
typer.echo("Default execution profile")
|
|
171
|
+
typer.echo("-------------------------")
|
|
172
|
+
typer.echo()
|
|
173
|
+
|
|
174
|
+
for index, name in enumerate(names, start=1):
|
|
175
|
+
profile = cli_config.profiles[name]
|
|
176
|
+
typer.echo(f"{index}. {name} ({profile.backend.value})")
|
|
177
|
+
|
|
178
|
+
current_index = names.index(cli_config.default_profile) + 1 if cli_config.default_profile in names else 1
|
|
179
|
+
|
|
180
|
+
choice = typer.prompt("Choose default profile", default=current_index, type=click.IntRange(min=1, max=len(names)))
|
|
181
|
+
|
|
182
|
+
cli_config.default_profile = names[choice - 1]
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
async def _configure_supabase(auth: AuthManager, *, max_attempts: int = 3) -> None:
|
|
186
|
+
"""Authenticate the cloud profile through the Cloud API.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
auth: Authentication manager used to perform the login.
|
|
190
|
+
max_attempts: Maximum number of authentication attempts.
|
|
191
|
+
|
|
192
|
+
Raises:
|
|
193
|
+
typer.Exit: If authentication fails after all attempts.
|
|
194
|
+
ValueError: If ``max_attempts`` is less than one.
|
|
195
|
+
"""
|
|
196
|
+
if max_attempts < 1:
|
|
197
|
+
raise ValueError("max_attempts must be greater than zero.")
|
|
198
|
+
|
|
199
|
+
for attempt in range(1, max_attempts + 1):
|
|
200
|
+
email = typer.prompt("Email")
|
|
201
|
+
password = typer.prompt("Password", hide_input=True)
|
|
202
|
+
|
|
203
|
+
try:
|
|
204
|
+
await auth.login(email, password)
|
|
205
|
+
return
|
|
206
|
+
except Exception as exception:
|
|
207
|
+
sinapsis_logger.warning("Cloud authentication attempt {}/{} failed: {}", attempt, max_attempts, exception)
|
|
208
|
+
|
|
209
|
+
attempts_remaining = max_attempts - attempt
|
|
210
|
+
|
|
211
|
+
if attempts_remaining:
|
|
212
|
+
typer.echo(
|
|
213
|
+
f"Login failed. {attempts_remaining} attempt{'s' if attempts_remaining != 1 else ''} remaining.",
|
|
214
|
+
err=True,
|
|
215
|
+
)
|
|
216
|
+
continue
|
|
217
|
+
|
|
218
|
+
typer.echo(f"Login failed after {max_attempts} attempts.", err=True)
|
|
219
|
+
raise typer.Exit(code=1) from exception
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""Execution profile management commands."""
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from sinapsis_cli.config import (
|
|
6
|
+
DEFAULT_CLOUD_URL,
|
|
7
|
+
DEFAULT_LOCAL_URL,
|
|
8
|
+
DEFAULT_VENV,
|
|
9
|
+
ExecutionBackend,
|
|
10
|
+
Profile,
|
|
11
|
+
delete_profile,
|
|
12
|
+
load_config,
|
|
13
|
+
set_default_profile,
|
|
14
|
+
set_profile,
|
|
15
|
+
validate_backend,
|
|
16
|
+
validate_profile_name,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
app = typer.Typer(name="profiles", help="Manage Sinapsis execution profiles.", no_args_is_help=True)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
_RESERVED_PROFILE_NAMES = {
|
|
23
|
+
"configure",
|
|
24
|
+
"profiles",
|
|
25
|
+
"jobs",
|
|
26
|
+
"templates",
|
|
27
|
+
"files",
|
|
28
|
+
"webhooks",
|
|
29
|
+
"api-keys",
|
|
30
|
+
"secrets",
|
|
31
|
+
"api",
|
|
32
|
+
"version",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _validate_new_profile_name(name: str) -> str:
|
|
37
|
+
normalized = validate_profile_name(name)
|
|
38
|
+
|
|
39
|
+
if normalized in _RESERVED_PROFILE_NAMES:
|
|
40
|
+
raise typer.BadParameter(f"Profile name {normalized!r} is reserved by the CLI.")
|
|
41
|
+
|
|
42
|
+
return normalized
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@app.command("list")
|
|
46
|
+
def list_profiles() -> None:
|
|
47
|
+
"""List configured execution profiles."""
|
|
48
|
+
config = load_config()
|
|
49
|
+
assert config.profiles is not None
|
|
50
|
+
|
|
51
|
+
for name in sorted(config.profiles):
|
|
52
|
+
profile = config.profiles[name]
|
|
53
|
+
marker = "*" if name == config.default_profile else " "
|
|
54
|
+
target = profile.api_url or profile.venv or "-"
|
|
55
|
+
extras = ",".join(profile.command_sets) or "-"
|
|
56
|
+
typer.echo(f"{marker} {name:16} {profile.backend.value:12} {target} extras={extras}")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@app.command()
|
|
60
|
+
def show(name: str = typer.Argument(..., help="Profile name.")) -> None:
|
|
61
|
+
"""Show one execution profile."""
|
|
62
|
+
profile = load_config().get_profile(name)
|
|
63
|
+
|
|
64
|
+
typer.echo(f"Name: {profile.name}")
|
|
65
|
+
typer.echo(f"Backend: {profile.backend.value}")
|
|
66
|
+
typer.echo(f"API URL: {profile.api_url or '-'}")
|
|
67
|
+
typer.echo(f"Virtual env: {profile.venv or '-'}")
|
|
68
|
+
typer.echo(f"Authenticated: {profile.authenticated}")
|
|
69
|
+
typer.echo("Command sets: " + (", ".join(profile.command_sets) or "-"))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@app.command()
|
|
73
|
+
def create(
|
|
74
|
+
name: str = typer.Argument(..., help="Profile name."),
|
|
75
|
+
backend: str = typer.Option(..., "--backend", "-b", help="Execution backend: local-venv, local-api, or cloud."),
|
|
76
|
+
api_url: str | None = typer.Option(None, "--api-url", help="API URL for API-backed profiles."),
|
|
77
|
+
venv: str | None = typer.Option(None, "--venv", help="Virtual environment for local-venv profiles."),
|
|
78
|
+
command_set: list[str] | None = typer.Option(
|
|
79
|
+
None,
|
|
80
|
+
"--command-set",
|
|
81
|
+
help="Additional command-set provider. Repeat for multiple providers.",
|
|
82
|
+
),
|
|
83
|
+
) -> None:
|
|
84
|
+
"""Create or replace an execution profile."""
|
|
85
|
+
normalized_name = _validate_new_profile_name(name)
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
resolved_backend = validate_backend(backend)
|
|
89
|
+
except ValueError as exception:
|
|
90
|
+
raise typer.BadParameter(str(exception), param_hint="--backend") from exception
|
|
91
|
+
|
|
92
|
+
if resolved_backend is ExecutionBackend.CLOUD:
|
|
93
|
+
resolved_api_url = (api_url or DEFAULT_CLOUD_URL).rstrip("/")
|
|
94
|
+
resolved_venv = None
|
|
95
|
+
authenticated = True
|
|
96
|
+
elif resolved_backend is ExecutionBackend.LOCAL_API:
|
|
97
|
+
resolved_api_url = (api_url or DEFAULT_LOCAL_URL).rstrip("/")
|
|
98
|
+
resolved_venv = None
|
|
99
|
+
authenticated = False
|
|
100
|
+
else:
|
|
101
|
+
resolved_api_url = None
|
|
102
|
+
resolved_venv = venv or DEFAULT_VENV
|
|
103
|
+
authenticated = False
|
|
104
|
+
|
|
105
|
+
requested_command_sets = tuple(command_set or ())
|
|
106
|
+
if requested_command_sets:
|
|
107
|
+
from sinapsis_cli.composition import command_provider_names
|
|
108
|
+
|
|
109
|
+
available = set(command_provider_names())
|
|
110
|
+
unknown = [name for name in requested_command_sets if name not in available]
|
|
111
|
+
if unknown:
|
|
112
|
+
raise typer.BadParameter(
|
|
113
|
+
"Unknown command set(s): " + ", ".join(sorted(unknown)), param_hint="--command-set"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
profile = Profile(
|
|
117
|
+
name=normalized_name,
|
|
118
|
+
backend=resolved_backend,
|
|
119
|
+
api_url=resolved_api_url,
|
|
120
|
+
venv=resolved_venv,
|
|
121
|
+
authenticated=authenticated,
|
|
122
|
+
command_sets=requested_command_sets,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
set_profile(profile)
|
|
126
|
+
typer.echo(f"Profile {normalized_name!r} saved.")
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@app.command("default")
|
|
130
|
+
def set_default(
|
|
131
|
+
name: str = typer.Argument(..., help="Profile to use when none is specified."),
|
|
132
|
+
) -> None:
|
|
133
|
+
"""Set the default execution profile."""
|
|
134
|
+
try:
|
|
135
|
+
set_default_profile(name)
|
|
136
|
+
except ValueError as exception:
|
|
137
|
+
raise typer.BadParameter(str(exception), param_hint="name") from exception
|
|
138
|
+
|
|
139
|
+
typer.echo(f"Default profile changed to {name!r}.")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@app.command()
|
|
143
|
+
def delete(
|
|
144
|
+
name: str = typer.Argument(..., help="Profile name."),
|
|
145
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Delete without prompting for confirmation."),
|
|
146
|
+
) -> None:
|
|
147
|
+
"""Delete an execution profile."""
|
|
148
|
+
if not yes and not typer.confirm(f"Delete profile {name!r}?"):
|
|
149
|
+
raise typer.Abort()
|
|
150
|
+
|
|
151
|
+
try:
|
|
152
|
+
delete_profile(name)
|
|
153
|
+
except ValueError as exception:
|
|
154
|
+
raise typer.BadParameter(str(exception), param_hint="name") from exception
|
|
155
|
+
|
|
156
|
+
typer.echo(f"Deleted profile {name!r}.")
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Transparent, opt-in Sinapsis CLI telemetry controls."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from sinapsis_cli.config import ExecutionBackend
|
|
9
|
+
from sinapsis_cli.execution import get_execution_context
|
|
10
|
+
from sinapsis_cli.telemetry.core import (
|
|
11
|
+
clear_events,
|
|
12
|
+
collection_enabled,
|
|
13
|
+
data_fields,
|
|
14
|
+
inventory_snapshot,
|
|
15
|
+
override_state,
|
|
16
|
+
recent_events,
|
|
17
|
+
record_inventory_if_due,
|
|
18
|
+
set_consent,
|
|
19
|
+
stored_consent,
|
|
20
|
+
)
|
|
21
|
+
from sinapsis_cli.telemetry.transport import publish_pending, queue_status
|
|
22
|
+
from sinapsis_cli.telemetry.scheduler import install_scheduler, remove_scheduler, scheduler_status
|
|
23
|
+
|
|
24
|
+
app = typer.Typer(name="telemetry", no_args_is_help=True, help="Control and inspect optional CLI telemetry.")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _selected_venv(ctx: typer.Context) -> Path | None:
|
|
28
|
+
"""Use the selected invocation profile, never the host of a local API."""
|
|
29
|
+
profile = get_execution_context(ctx).profile
|
|
30
|
+
if profile.backend is ExecutionBackend.LOCAL_VENV and profile.venv:
|
|
31
|
+
return Path(profile.venv).expanduser().resolve()
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _print_json(value: object) -> None:
|
|
36
|
+
typer.echo(json.dumps(value, indent=2, sort_keys=True))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@app.command()
|
|
40
|
+
def status() -> None:
|
|
41
|
+
"""Show effective consent, overrides, local history, and delivery status."""
|
|
42
|
+
typer.echo(f"Collection: {'enabled' if collection_enabled() else 'disabled'}")
|
|
43
|
+
typer.echo(f"Stored consent: {'enabled' if stored_consent() else 'disabled'}")
|
|
44
|
+
typer.echo(f"SINAPSIS_TELEMETRY override: {override_state() if override_state() is not None else 'unset'}")
|
|
45
|
+
typer.echo(f"Local events retained: {len(recent_events(200))}")
|
|
46
|
+
delivery = queue_status()
|
|
47
|
+
schedule = scheduler_status()
|
|
48
|
+
typer.echo(f"Hourly background publisher: {schedule['status']} ({schedule['provider']})")
|
|
49
|
+
typer.echo(f"Pending events: {delivery['pending']}")
|
|
50
|
+
typer.echo(f"Acknowledged events: {delivery['sent']}")
|
|
51
|
+
typer.echo(f"Last transmission: {delivery['last_sent']['acknowledged_at'] if delivery['last_sent'] else 'none'}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@app.command()
|
|
55
|
+
def enable(ctx: typer.Context) -> None:
|
|
56
|
+
"""Opt in and install an independent hourly OS-level telemetry publisher."""
|
|
57
|
+
try:
|
|
58
|
+
install_scheduler()
|
|
59
|
+
except (OSError, RuntimeError, ValueError) as error:
|
|
60
|
+
# Never claim consent/publishing is enabled when scheduling failed.
|
|
61
|
+
set_consent(False)
|
|
62
|
+
typer.secho(f"Unable to enable automatic telemetry: {error}", err=True, fg=typer.colors.RED)
|
|
63
|
+
raise typer.Exit(1) from error
|
|
64
|
+
set_consent(True)
|
|
65
|
+
# An initial inventory is explicitly requested here (not a normal job).
|
|
66
|
+
recorded = record_inventory_if_due(venv=_selected_venv(ctx), force=True)
|
|
67
|
+
typer.echo("Telemetry enabled. Automatic publishing scheduled hourly.")
|
|
68
|
+
typer.echo("Environment inventory recorded." if recorded else "Inventory will be collected by the scheduler.")
|
|
69
|
+
if override_state() == "0":
|
|
70
|
+
typer.echo("SINAPSIS_TELEMETRY=0 currently suppresses collection in this process.")
|
|
71
|
+
typer.echo("Use `sinx config telemetry info` to inspect the exact payloads.")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@app.command()
|
|
75
|
+
def disable(
|
|
76
|
+
clear: bool = typer.Option(False, "--clear", help="Also delete locally retained events."),
|
|
77
|
+
) -> None:
|
|
78
|
+
"""Opt out; optionally delete locally collected event history."""
|
|
79
|
+
set_consent(False)
|
|
80
|
+
try:
|
|
81
|
+
remove_scheduler()
|
|
82
|
+
except (OSError, RuntimeError) as error:
|
|
83
|
+
typer.secho(f"WARNING: Could not remove OS scheduler: {error}", fg=typer.colors.YELLOW, err=True)
|
|
84
|
+
deleted = clear_events() if clear else None
|
|
85
|
+
typer.echo("Stored telemetry consent disabled.")
|
|
86
|
+
if override_state() == "1":
|
|
87
|
+
typer.echo("WARNING: SINAPSIS_TELEMETRY=1 currently overrides this setting.")
|
|
88
|
+
if deleted is not None:
|
|
89
|
+
typer.echo(f"Deleted {deleted} local events.")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@app.command()
|
|
93
|
+
def info() -> None:
|
|
94
|
+
"""List all collected fields and display the most recent actual event."""
|
|
95
|
+
status()
|
|
96
|
+
typer.echo("\nFields collected (never raw CLI arguments or files):")
|
|
97
|
+
for field, meaning in data_fields().items():
|
|
98
|
+
typer.echo(f" {field}: {meaning}")
|
|
99
|
+
events = recent_events(1)
|
|
100
|
+
typer.echo("\nLast locally collected event:")
|
|
101
|
+
if events:
|
|
102
|
+
_print_json(events[0])
|
|
103
|
+
else:
|
|
104
|
+
typer.echo("None. Run `sinx config telemetry preview` for an unsaved example.")
|
|
105
|
+
typer.echo("\nLast successfully transmitted payload:")
|
|
106
|
+
_print_json(queue_status()['last_sent'])
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@app.command()
|
|
110
|
+
def preview(ctx: typer.Context) -> None:
|
|
111
|
+
"""Show an inventory example without collecting or persisting an event."""
|
|
112
|
+
typer.echo("Environment inventory preview (NOT stored or transmitted):")
|
|
113
|
+
_print_json(inventory_snapshot(venv=_selected_venv(ctx)))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@app.command()
|
|
117
|
+
def inventory(ctx: typer.Context) -> None:
|
|
118
|
+
"""Record a current environment snapshot when telemetry consent is enabled."""
|
|
119
|
+
if not collection_enabled():
|
|
120
|
+
typer.echo("Telemetry is disabled. Use `sinx config telemetry preview` without opting in.")
|
|
121
|
+
return
|
|
122
|
+
recorded = record_inventory_if_due(venv=_selected_venv(ctx), force=True)
|
|
123
|
+
typer.echo("Environment inventory recorded." if recorded else "Could not record environment inventory.")
|
|
124
|
+
typer.echo("Queued events are sent automatically by the hourly background publisher.")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@app.command()
|
|
128
|
+
def history(limit: int = typer.Option(10, "--limit", min=1, max=200)) -> None:
|
|
129
|
+
"""Inspect recent locally collected telemetry payloads, newest first."""
|
|
130
|
+
_print_json(recent_events(limit))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@app.command()
|
|
134
|
+
def clear(yes: bool = typer.Option(False, "--yes", "-y")) -> None:
|
|
135
|
+
"""Delete all local telemetry events (does not change consent)."""
|
|
136
|
+
if not yes and not typer.confirm("Delete all locally retained telemetry events?"):
|
|
137
|
+
raise typer.Abort()
|
|
138
|
+
typer.echo(f"Deleted {clear_events()} local events.")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@app.command('last-sent')
|
|
142
|
+
def last_sent() -> None:
|
|
143
|
+
"""Display the actual acknowledged payload and server-acceptance timestamp."""
|
|
144
|
+
_print_json(queue_status()['last_sent'])
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@app.command('send')
|
|
148
|
+
def send() -> None:
|
|
149
|
+
"""Diagnostic only: the OS scheduler publishes hourly without CLI use."""
|
|
150
|
+
typer.echo(f"Acknowledged {publish_pending()} events.")
|
|
File without changes
|