openforma 0.4.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.
- forma_cli/__init__.py +5 -0
- forma_cli/app.py +1139 -0
- forma_cli/config.py +112 -0
- forma_cli/credentials.py +141 -0
- forma_cli/local.py +562 -0
- forma_cli/metadata_api.py +138 -0
- forma_cli/project_artifacts.py +182 -0
- forma_cli/sdk.py +571 -0
- forma_core/__init__.py +9 -0
- forma_core/__main__.py +4 -0
- forma_core/_version.py +3 -0
- forma_core/agents/__init__.py +50 -0
- forma_core/agents/clarification.py +194 -0
- forma_core/agents/component_reconciliation.py +99 -0
- forma_core/agents/context_gathering.py +115 -0
- forma_core/agents/continuous.py +537 -0
- forma_core/agents/contracts.py +247 -0
- forma_core/agents/firecrawl_mcp.py +484 -0
- forma_core/agents/lattice.py +239 -0
- forma_core/agents/orchestrator.py +3724 -0
- forma_core/agents/pipeline.py +843 -0
- forma_core/agents/project_correction.py +83 -0
- forma_core/agents/prompt_compaction.py +428 -0
- forma_core/agents/system_architecture.py +345 -0
- forma_core/agents/video_correction.py +119 -0
- forma_core/agents/web_research_workflow.py +1256 -0
- forma_core/agents/workflows.py +176 -0
- forma_core/assets/__init__.py +1 -0
- forma_core/assets/models.py +156 -0
- forma_core/assets/project.py +17 -0
- forma_core/assets/repository.py +48 -0
- forma_core/assets/service.py +142 -0
- forma_core/assets/validation.py +35 -0
- forma_core/benchmarks/__init__.py +5 -0
- forma_core/benchmarks/ir_triad_v1.py +477 -0
- forma_core/biology/__init__.py +28 -0
- forma_core/biology/benchmark.py +80 -0
- forma_core/biology/ewart_liverchip.py +279 -0
- forma_core/biology/ir.py +25 -0
- forma_core/biology/liverbench.py +416 -0
- forma_core/biology/liverbench_assay.py +251 -0
- forma_core/biology/liverbench_baselines.py +133 -0
- forma_core/biology/liverbench_independent.py +229 -0
- forma_core/biology/liverchip_demo.py +154 -0
- forma_core/biology/liverchip_evidence.py +149 -0
- forma_core/biology/models.py +247 -0
- forma_core/biology/validation.py +72 -0
- forma_core/cad_migrations/__init__.py +6 -0
- forma_core/cad_migrations/cli.py +101 -0
- forma_core/cad_migrations/emitters.py +227 -0
- forma_core/cad_migrations/models.py +121 -0
- forma_core/cad_migrations/planner.py +68 -0
- forma_core/chemistry/__init__.py +5 -0
- forma_core/chemistry/models.py +215 -0
- forma_core/chemistry/stoichiometry.py +272 -0
- forma_core/chemistry/validation.py +179 -0
- forma_core/cli/__init__.py +1 -0
- forma_core/cli/__main__.py +4 -0
- forma_core/cli/main.py +370 -0
- forma_core/config/__init__.py +28 -0
- forma_core/config/compatibility.py +282 -0
- forma_core/config/contract.py +184 -0
- forma_core/config/environment.py +129 -0
- forma_core/config/parti.py +34 -0
- forma_core/config/runtime.py +303 -0
- forma_core/control/__init__.py +10 -0
- forma_core/control/actions.py +136 -0
- forma_core/control/adapters.py +36 -0
- forma_core/control/cli.py +49 -0
- forma_core/control/client.py +124 -0
- forma_core/control/models.py +168 -0
- forma_core/control/opencode_worker.py +80 -0
- forma_core/control/package.py +318 -0
- forma_core/control/rover_scene/__init__.py +1 -0
- forma_core/control/rover_scene/__main__.py +34 -0
- forma_core/control/rover_scene/assets.py +65 -0
- forma_core/control/rover_scene/fleet.py +214 -0
- forma_core/control/rover_scene/host.py +258 -0
- forma_core/control/rover_scene/kinematics.py +35 -0
- forma_core/control/rover_scene/machine.py +347 -0
- forma_core/control/rover_scene/robot.py +166 -0
- forma_core/control/rover_scene/scene.py +206 -0
- forma_core/control/rover_scene/view.py +80 -0
- forma_core/control/rover_scene/web/index.html +25 -0
- forma_core/control/rover_scene/web/viewer.js +148 -0
- forma_core/control/runtime.py +356 -0
- forma_core/control/so101.py +235 -0
- forma_core/control/tasks.py +287 -0
- forma_core/database.py +2362 -0
- forma_core/debug.py +314 -0
- forma_core/domains/__init__.py +7 -0
- forma_core/domains/agents.py +85 -0
- forma_core/domains/base.py +69 -0
- forma_core/domains/benchmark.py +87 -0
- forma_core/domains/cli.py +48 -0
- forma_core/domains/compatibility.py +234 -0
- forma_core/domains/composition.py +372 -0
- forma_core/domains/diagnostics.py +15 -0
- forma_core/domains/generation.py +479 -0
- forma_core/domains/interaction.py +301 -0
- forma_core/domains/planning.py +140 -0
- forma_core/domains/providers.py +214 -0
- forma_core/domains/registry.py +267 -0
- forma_core/domains/selection.py +75 -0
- forma_core/domains/storage.py +60 -0
- forma_core/domains/tools.py +180 -0
- forma_core/electronics/__init__.py +1 -0
- forma_core/electronics/models.py +84 -0
- forma_core/electronics/primitives.py +43 -0
- forma_core/electronics/rules.py +340 -0
- forma_core/external_sources.py +497 -0
- forma_core/fabricator/__init__.py +33 -0
- forma_core/fabricator/__main__.py +7 -0
- forma_core/fabricator/main.py +578 -0
- forma_core/firmware/__init__.py +60 -0
- forma_core/firmware/drivers.py +140 -0
- forma_core/firmware/examples.py +503 -0
- forma_core/firmware/generate.py +520 -0
- forma_core/firmware/models.py +34 -0
- forma_core/firmware/sil/__init__.py +5 -0
- forma_core/firmware/sil/adapter.py +71 -0
- forma_core/firmware/sil/build.py +49 -0
- forma_core/firmware/sil/native/CMakeLists.txt +9 -0
- forma_core/firmware/sil/native/bridge.cpp +112 -0
- forma_core/firmware/sil/native/controller.cpp +123 -0
- forma_core/firmware/sil/native/controller.h +49 -0
- forma_core/firmware/sil/simulator.py +139 -0
- forma_core/firmware/targets.py +111 -0
- forma_core/firmware/validation.py +130 -0
- forma_core/fluidics/__init__.py +6 -0
- forma_core/fluidics/benchmark.py +217 -0
- forma_core/fluidics/calculations.py +79 -0
- forma_core/fluidics/examples.py +54 -0
- forma_core/fluidics/ir.py +25 -0
- forma_core/fluidics/models.py +132 -0
- forma_core/fluidics/topology.py +47 -0
- forma_core/fluidics/validation.py +134 -0
- forma_core/generation.py +32 -0
- forma_core/geometry_bindings/__init__.py +20 -0
- forma_core/geometry_bindings/cad_adapter.py +80 -0
- forma_core/geometry_bindings/models.py +163 -0
- forma_core/geometry_bindings/resolution.py +340 -0
- forma_core/geometry_bindings/tools.py +125 -0
- forma_core/image_providers.py +3049 -0
- forma_core/images.py +3 -0
- forma_core/integrations/__init__.py +1 -0
- forma_core/integrations/huggingface/__init__.py +29 -0
- forma_core/integrations/huggingface/huggingface_artifacts.py +272 -0
- forma_core/jobs/__init__.py +1 -0
- forma_core/jobs/context.py +277 -0
- forma_core/jobs/continuous.py +719 -0
- forma_core/jobs/metrics.py +124 -0
- forma_core/jobs/migrations.py +161 -0
- forma_core/jobs/persistence.py +28 -0
- forma_core/jobs/repositories.py +422 -0
- forma_core/jobs/schema.py +28 -0
- forma_core/jobs/source_usage.py +230 -0
- forma_core/jobs/store.py +476 -0
- forma_core/llm.py +3 -0
- forma_core/llm_providers.py +2682 -0
- forma_core/logs.py +107 -0
- forma_core/mechanics/__init__.py +1 -0
- forma_core/mechanics/gear_benchmark.py +85 -0
- forma_core/mechanics/mechanism_benchmarks.py +345 -0
- forma_core/mechanics/models.py +72 -0
- forma_core/mechanics/primitives.py +109 -0
- forma_core/mechanics/solid_cad.py +83 -0
- forma_core/observability.py +237 -0
- forma_core/openai_streams.py +780 -0
- forma_core/opencode/__init__.py +25 -0
- forma_core/opencode/architecture.py +82 -0
- forma_core/opencode/capabilities.py +130 -0
- forma_core/opencode/models.py +419 -0
- forma_core/opencode/persistence.py +62 -0
- forma_core/opencode/public_events.py +91 -0
- forma_core/opencode/schema.py +28 -0
- forma_core/opencode/store.py +874 -0
- forma_core/persistence/__init__.py +16 -0
- forma_core/persistence/base.py +38 -0
- forma_core/persistence/images.py +598 -0
- forma_core/persistence/migrations.py +200 -0
- forma_core/persistence/models.py +439 -0
- forma_core/persistence/project_artifacts.py +341 -0
- forma_core/persistence/project_reconciliation.py +1094 -0
- forma_core/persistence/providers/__init__.py +4 -0
- forma_core/persistence/providers/sqlite.py +114 -0
- forma_core/persistence/providers/supabase.py +31 -0
- forma_core/persistence/repositories/__init__.py +9 -0
- forma_core/persistence/repositories/base.py +335 -0
- forma_core/persistence/repositories/sqlite.py +1571 -0
- forma_core/persistence/repositories/supabase.py +1576 -0
- forma_core/persistence/schema.py +176 -0
- forma_core/processes/__init__.py +5 -0
- forma_core/processes/models.py +338 -0
- forma_core/processes/validation.py +141 -0
- forma_core/project_list_cache.py +316 -0
- forma_core/prompt_continuity.py +387 -0
- forma_core/providers/__init__.py +39 -0
- forma_core/providers/base.py +28 -0
- forma_core/providers/models.py +138 -0
- forma_core/providers/openai.py +92 -0
- forma_core/providers/openai_compatible.py +190 -0
- forma_core/providers/registry.py +68 -0
- forma_core/providers/registry_utils.py +46 -0
- forma_core/py.typed +1 -0
- forma_core/runtime.py +3 -0
- forma_core/selectors.py +36 -0
- forma_core/signups/__init__.py +5 -0
- forma_core/signups/models.py +49 -0
- forma_core/terminal/__init__.py +1 -0
- forma_core/terminal/dashboard.py +475 -0
- forma_core/terminal/images.py +156 -0
- forma_core/thermal/__init__.py +5 -0
- forma_core/thermal/models.py +361 -0
- forma_core/thermal/validation.py +175 -0
- forma_core/user_integrations.py +2069 -0
- forma_core/utils.py +291 -0
- forma_core/validation.py +83 -0
- forma_core/vertex_auth.py +92 -0
- forma_core/video_prompts.py +193 -0
- forma_core/video_review.py +1006 -0
- forma_core/wiring.py +356 -0
- forma_core/workers/__init__.py +120 -0
- forma_core/workers/contracts.py +183 -0
- forma_core/workers/generation.py +753 -0
- forma_core/workers/orchestration.py +805 -0
- forma_core/workers/registry.py +222 -0
- forma_core/workers/reverse_engineering.py +272 -0
- forma_core/workers/validation.py +291 -0
- forma_core/workspaces/__init__.py +5 -0
- forma_core/workspaces/chats/__init__.py +11 -0
- forma_core/workspaces/chats/models.py +48 -0
- forma_core/workspaces/context/__init__.py +15 -0
- forma_core/workspaces/context/agent.py +260 -0
- forma_core/workspaces/context/models.py +117 -0
- forma_core/workspaces/context/pdf.py +418 -0
- forma_core/workspaces/design_briefs/__init__.py +25 -0
- forma_core/workspaces/design_briefs/models.py +85 -0
- forma_core/workspaces/design_briefs/references.py +56 -0
- forma_core/workspaces/models.py +41 -0
- forma_core/workspaces/projects/__init__.py +88 -0
- forma_core/workspaces/projects/cad_generation.py +1016 -0
- forma_core/workspaces/projects/context_governance.py +365 -0
- forma_core/workspaces/projects/design_lifecycle.py +668 -0
- forma_core/workspaces/projects/fabrication/__init__.py +54 -0
- forma_core/workspaces/projects/fabrication/demo_printers.py +236 -0
- forma_core/workspaces/projects/fabrication/models.py +120 -0
- forma_core/workspaces/projects/fabrication/printer_config.py +205 -0
- forma_core/workspaces/projects/fabrication/slicers/__init__.py +7 -0
- forma_core/workspaces/projects/fabrication/slicers/base.py +25 -0
- forma_core/workspaces/projects/fabrication/slicers/cura.py +125 -0
- forma_core/workspaces/projects/fabrication/slicers/orca.py +208 -0
- forma_core/workspaces/projects/fabrication/slicing.py +202 -0
- forma_core/workspaces/projects/fabrication/validation.py +103 -0
- forma_core/workspaces/projects/gear_benchmark.py +6 -0
- forma_core/workspaces/projects/generation_mode.py +70 -0
- forma_core/workspaces/projects/identity.py +28 -0
- forma_core/workspaces/projects/iteration.py +680 -0
- forma_core/workspaces/projects/manifest.py +362 -0
- forma_core/workspaces/projects/mechanism_benchmarks.py +12 -0
- forma_core/workspaces/projects/models.py +913 -0
- forma_core/workspaces/projects/objects.py +731 -0
- forma_core/workspaces/projects/outcomes.py +47 -0
- forma_core/workspaces/projects/output.py +735 -0
- forma_core/workspaces/projects/resolver.py +397 -0
- forma_core/workspaces/projects/solid_cad.py +8 -0
- forma_core/workspaces/projects/state.py +622 -0
- forma_core/workspaces/readiness/__init__.py +28 -0
- forma_core/workspaces/readiness/evaluator.py +103 -0
- forma_core/workspaces/readiness/models.py +97 -0
- forma_core/workspaces/readiness/service.py +225 -0
- forma_core/workspaces/reverse_engineering/__init__.py +37 -0
- forma_core/workspaces/reverse_engineering/analyzer.py +246 -0
- forma_core/workspaces/reverse_engineering/models.py +128 -0
- forma_core/workspaces/validation/__init__.py +37 -0
- forma_core/workspaces/validation/evaluator.py +327 -0
- forma_core/workspaces/validation/models.py +146 -0
- forma_core/workspaces/validation/service.py +212 -0
- forma_core/workspaces/workflow/__init__.py +29 -0
- forma_core/workspaces/workflow/guard.py +33 -0
- forma_core/workspaces/workflow/models.py +77 -0
- forma_core/workspaces/workflow/service.py +287 -0
- openforma-0.4.0.dist-info/METADATA +247 -0
- openforma-0.4.0.dist-info/RECORD +288 -0
- openforma-0.4.0.dist-info/WHEEL +5 -0
- openforma-0.4.0.dist-info/entry_points.txt +4 -0
- openforma-0.4.0.dist-info/licenses/LICENSE +373 -0
- openforma-0.4.0.dist-info/top_level.txt +2 -0
forma_cli/app.py
ADDED
|
@@ -0,0 +1,1139 @@
|
|
|
1
|
+
"""The first-party ``forma-oss`` command line application."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import getpass
|
|
7
|
+
import hashlib
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
import sys
|
|
12
|
+
import tempfile
|
|
13
|
+
import time
|
|
14
|
+
from urllib.parse import quote
|
|
15
|
+
import webbrowser
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from forma_core import __version__
|
|
19
|
+
from forma_cli.config import api_url, load_linkage
|
|
20
|
+
from forma_cli.credentials import CredentialStore, CredentialStoreError
|
|
21
|
+
from forma_cli.local import (
|
|
22
|
+
LOCAL_PROVIDER_ENVIRONMENT,
|
|
23
|
+
LocalProjectError,
|
|
24
|
+
build_project,
|
|
25
|
+
import_project,
|
|
26
|
+
init_project,
|
|
27
|
+
project_root,
|
|
28
|
+
read_project,
|
|
29
|
+
slice_local_project,
|
|
30
|
+
status_project,
|
|
31
|
+
update_linkage,
|
|
32
|
+
)
|
|
33
|
+
from forma_cli.metadata_api import project_metadata, serve_metadata_api
|
|
34
|
+
from forma_cli.project_artifacts import (
|
|
35
|
+
artifact_target,
|
|
36
|
+
canonical_project_upload_payload,
|
|
37
|
+
file_digest,
|
|
38
|
+
prepare_project_upload,
|
|
39
|
+
)
|
|
40
|
+
from forma_cli.sdk import FormaAPIClient, FormaAPIError, ProjectArtifactDownload
|
|
41
|
+
from forma_core.config.compatibility import CompatibilityStatus
|
|
42
|
+
from forma_core.workspaces.projects.manifest import (
|
|
43
|
+
ProjectManifest,
|
|
44
|
+
normalize_artifact_media_type,
|
|
45
|
+
validate_artifact_references,
|
|
46
|
+
write_project_manifest,
|
|
47
|
+
rewrite_artifact_paths,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _print_json(value: Any) -> None:
|
|
52
|
+
print(json.dumps(value, indent=2, sort_keys=True, default=str))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _client(args: argparse.Namespace) -> FormaAPIClient:
|
|
56
|
+
client = FormaAPIClient(base_url=args.api_url if getattr(args, "api_url", None) else None)
|
|
57
|
+
notice = client.compatibility_notice()
|
|
58
|
+
if notice:
|
|
59
|
+
print(notice, file=sys.stderr)
|
|
60
|
+
return client
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def cmd_version(args: argparse.Namespace) -> int:
|
|
64
|
+
result = _client(args).check_compatibility()
|
|
65
|
+
payload = {
|
|
66
|
+
"cli_version": __version__,
|
|
67
|
+
"status": result.status.value,
|
|
68
|
+
"latest_version": result.latest_version,
|
|
69
|
+
"minimum_supported_version": result.minimum_supported_version,
|
|
70
|
+
"protocol_version": result.protocol_version,
|
|
71
|
+
"hardware_ir_version": result.hardware_ir_version,
|
|
72
|
+
"message": result.message,
|
|
73
|
+
"upgrade_command": result.upgrade_command,
|
|
74
|
+
}
|
|
75
|
+
if args.json:
|
|
76
|
+
_print_json(payload)
|
|
77
|
+
else:
|
|
78
|
+
print("Forma-OSS")
|
|
79
|
+
print(f"CLI: {payload['cli_version']}")
|
|
80
|
+
print(f"Latest: {payload['latest_version'] or 'unavailable'}")
|
|
81
|
+
print(f"Minimum: {payload['minimum_supported_version'] or 'unavailable'}")
|
|
82
|
+
print(f"Protocol: {payload['protocol_version'] or 'unavailable'}")
|
|
83
|
+
print(f"Hardware Intermediate Representation: {payload['hardware_ir_version'] or 'unavailable'}")
|
|
84
|
+
print(f"Status: {payload['status']}")
|
|
85
|
+
if result.status == CompatibilityStatus.UPDATE_AVAILABLE:
|
|
86
|
+
print(f"Upgrade: {result.upgrade_command}")
|
|
87
|
+
elif result.status == CompatibilityStatus.REMOTE_VERSION_UNAVAILABLE:
|
|
88
|
+
print(result.message)
|
|
89
|
+
return 0
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def cmd_doctor(args: argparse.Namespace) -> int:
|
|
93
|
+
client = _client(args)
|
|
94
|
+
compatibility = client.check_compatibility()
|
|
95
|
+
checks: list[dict[str, str]] = [
|
|
96
|
+
{
|
|
97
|
+
"name": "Forma version",
|
|
98
|
+
"status": "ok" if not compatibility.is_blocking else "fail",
|
|
99
|
+
"message": compatibility.message,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "Hosted compatibility endpoint",
|
|
103
|
+
"status": "ok" if compatibility.status != CompatibilityStatus.REMOTE_VERSION_UNAVAILABLE else "unavailable",
|
|
104
|
+
"message": compatibility.status.value,
|
|
105
|
+
},
|
|
106
|
+
]
|
|
107
|
+
if client._saved_tokens():
|
|
108
|
+
try:
|
|
109
|
+
identity = client.whoami()
|
|
110
|
+
except FormaAPIError as exc:
|
|
111
|
+
checks.append({"name": "Authentication", "status": "fail", "message": str(exc)})
|
|
112
|
+
else:
|
|
113
|
+
checks.append({"name": "Authentication", "status": "ok", "message": identity.subject})
|
|
114
|
+
else:
|
|
115
|
+
checks.append({"name": "Authentication", "status": "not configured", "message": "Run `forma-oss login`."})
|
|
116
|
+
if args.json:
|
|
117
|
+
_print_json({"cli_version": __version__, "checks": checks})
|
|
118
|
+
else:
|
|
119
|
+
print("Forma-OSS doctor")
|
|
120
|
+
for check in checks:
|
|
121
|
+
print(f"{check['status'].upper():14} {check['name']}: {check['message']}")
|
|
122
|
+
return 1 if any(check["status"] == "fail" for check in checks) else 0
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def cmd_login(args: argparse.Namespace) -> int:
|
|
126
|
+
client = _client(args)
|
|
127
|
+
authorization = client.request_device_authorization()
|
|
128
|
+
print("Opening Forma in your browser...")
|
|
129
|
+
print(f"If the browser does not open, visit: {authorization.verification_uri}")
|
|
130
|
+
if not args.no_browser:
|
|
131
|
+
webbrowser.open(authorization.verification_uri)
|
|
132
|
+
print("Waiting for authorization...")
|
|
133
|
+
deadline = time.monotonic() + authorization.expires_in
|
|
134
|
+
while time.monotonic() < deadline:
|
|
135
|
+
result = client.poll_device_authorization(authorization.device_code)
|
|
136
|
+
if result.status == "approved":
|
|
137
|
+
client.exchange_device_code(authorization.device_code)
|
|
138
|
+
identity = client.whoami()
|
|
139
|
+
account = identity.email or identity.display_name or identity.subject
|
|
140
|
+
print(f"Logged in as {account}")
|
|
141
|
+
if client._store.using_plaintext_fallback:
|
|
142
|
+
print("WARNING: credentials stored in plaintext because the explicit fallback is enabled.")
|
|
143
|
+
else:
|
|
144
|
+
print("Credentials stored securely")
|
|
145
|
+
return 0
|
|
146
|
+
if result.status in {"expired", "denied"}:
|
|
147
|
+
raise FormaAPIError(result.message or f"Device authorization {result.status}.")
|
|
148
|
+
time.sleep(authorization.interval)
|
|
149
|
+
raise FormaAPIError("Device authorization expired before it was approved.")
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def cmd_logout(args: argparse.Namespace) -> int:
|
|
153
|
+
_client(args).revoke()
|
|
154
|
+
print("Logged out")
|
|
155
|
+
return 0
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def cmd_whoami(args: argparse.Namespace) -> int:
|
|
159
|
+
identity = _client(args).whoami()
|
|
160
|
+
if args.json:
|
|
161
|
+
_print_json(identity.model_dump(mode="json"))
|
|
162
|
+
else:
|
|
163
|
+
print(identity.email or identity.display_name or identity.subject)
|
|
164
|
+
print(f"Provider: {identity.provider}")
|
|
165
|
+
print(f"API endpoint: {identity.api_url}")
|
|
166
|
+
return 0
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def cmd_init(args: argparse.Namespace) -> int:
|
|
170
|
+
manifest = init_project(args.path, title=args.title or "")
|
|
171
|
+
print(f"Initialized Forma project {manifest.project_id}")
|
|
172
|
+
return 0
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def cmd_build(args: argparse.Namespace) -> int:
|
|
176
|
+
manifest = build_project(
|
|
177
|
+
args.path,
|
|
178
|
+
prompt=args.prompt,
|
|
179
|
+
workflow=args.workflow,
|
|
180
|
+
provider=args.provider,
|
|
181
|
+
model=args.model,
|
|
182
|
+
simulation=args.simulation,
|
|
183
|
+
assembly_step=args.assembly_step,
|
|
184
|
+
)
|
|
185
|
+
print(
|
|
186
|
+
f"Built {manifest.title or manifest.project_id}, persisted {manifest.project_id} to Forma DB, "
|
|
187
|
+
f"at {project_root(args.path) / 'forma-project.json'}"
|
|
188
|
+
)
|
|
189
|
+
return 0
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def cmd_import(args: argparse.Namespace) -> int:
|
|
193
|
+
source_path = Path(args.source).expanduser()
|
|
194
|
+
destination = Path(args.path).expanduser() if args.path else (
|
|
195
|
+
source_path if source_path.is_dir() else source_path.parent
|
|
196
|
+
)
|
|
197
|
+
manifest = import_project(
|
|
198
|
+
args.source,
|
|
199
|
+
destination=destination,
|
|
200
|
+
assembly_step=args.assembly_step,
|
|
201
|
+
preview_stl=args.preview_stl,
|
|
202
|
+
)
|
|
203
|
+
print(
|
|
204
|
+
f"Imported {manifest.title or manifest.project_id}, persisted {manifest.project_id} to Forma DB, "
|
|
205
|
+
f"at {destination / 'forma-project.json'}"
|
|
206
|
+
)
|
|
207
|
+
return 0
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def cmd_metadata(args: argparse.Namespace) -> int:
|
|
211
|
+
payload = project_metadata(args.path)
|
|
212
|
+
if args.json:
|
|
213
|
+
_print_json(payload)
|
|
214
|
+
else:
|
|
215
|
+
print(f"Project: {payload['title'] or payload['project_id']}")
|
|
216
|
+
print(f"Project ID: {payload['project_id']}")
|
|
217
|
+
print(f"Database: {'present' if payload['database']['present'] else 'missing'}")
|
|
218
|
+
print(f"CAD: {payload['cad']['meshes']} mesh(es), {payload['cad']['mesh_vertices']} vertices")
|
|
219
|
+
print(f"Components: {payload['hardware']['components']}")
|
|
220
|
+
print(f"Placements: {payload['hardware']['placements']}")
|
|
221
|
+
print(f"Valid: {'yes' if payload['valid'] else 'no'}")
|
|
222
|
+
return 0
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def cmd_metadata_api(args: argparse.Namespace) -> int:
|
|
226
|
+
print(f"Serving project metadata at http://{args.host}:{args.port}/metadata")
|
|
227
|
+
serve_metadata_api(args.path, args.host, args.port)
|
|
228
|
+
return 0
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def cmd_status(args: argparse.Namespace) -> int:
|
|
232
|
+
payload = status_project(args.path)
|
|
233
|
+
if args.json:
|
|
234
|
+
_print_json(payload)
|
|
235
|
+
else:
|
|
236
|
+
print(f"Project: {payload['title'] or payload['project_id']}")
|
|
237
|
+
print(f"Path: {payload['path']}")
|
|
238
|
+
print(f"Validation: {'ok' if payload['valid'] else 'failed'}")
|
|
239
|
+
if payload.get("remote"):
|
|
240
|
+
print(f"Remote: {payload['remote']}")
|
|
241
|
+
print(f"Revision: {payload.get('revision_id') or 'none'}")
|
|
242
|
+
return 0 if payload["valid"] else 1
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def cmd_render(args: argparse.Namespace) -> int:
|
|
246
|
+
from forma_core.terminal.dashboard import DashboardRenderConfig, render_dashboard_image
|
|
247
|
+
|
|
248
|
+
root = project_root(args.path)
|
|
249
|
+
manifest = read_project(root)
|
|
250
|
+
output = Path(args.output).expanduser()
|
|
251
|
+
if not output.is_absolute():
|
|
252
|
+
output = root / output
|
|
253
|
+
render_dashboard_image(
|
|
254
|
+
manifest.project_ir,
|
|
255
|
+
output,
|
|
256
|
+
config=DashboardRenderConfig(
|
|
257
|
+
width=args.width,
|
|
258
|
+
height=args.height,
|
|
259
|
+
scene_yaw_degrees=args.yaw,
|
|
260
|
+
scene_label="FORMA OSS / CLI RENDER",
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
print(f"Rendered {manifest.title or manifest.project_id} at {output}")
|
|
264
|
+
return 0
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _printer_registry():
|
|
268
|
+
from forma_core.workspaces.projects.fabrication import load_printer_registry
|
|
269
|
+
|
|
270
|
+
return load_printer_registry()
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def cmd_printer_list(args: argparse.Namespace) -> int:
|
|
274
|
+
registry = _printer_registry()
|
|
275
|
+
rows = [
|
|
276
|
+
{
|
|
277
|
+
"printer_id": printer.printer_id,
|
|
278
|
+
"display_name": printer.display_name,
|
|
279
|
+
"backend": printer.backend,
|
|
280
|
+
"default_profile": printer.default_profile,
|
|
281
|
+
"default": registry.default_printer == printer.printer_id,
|
|
282
|
+
"profiles": sorted(printer.profiles),
|
|
283
|
+
}
|
|
284
|
+
for printer in sorted(registry.printers.values(), key=lambda item: item.printer_id)
|
|
285
|
+
]
|
|
286
|
+
if args.json:
|
|
287
|
+
_print_json(rows)
|
|
288
|
+
else:
|
|
289
|
+
for row in rows:
|
|
290
|
+
marker = "*" if row["default"] else " "
|
|
291
|
+
print(f"{marker} {row['printer_id']}\t{row['backend']}\t{row['default_profile']}\t{row['display_name']}")
|
|
292
|
+
return 0
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def cmd_printer_show(args: argparse.Namespace) -> int:
|
|
296
|
+
registry = _printer_registry()
|
|
297
|
+
printer = registry.printers.get(args.printer_id)
|
|
298
|
+
if printer is None:
|
|
299
|
+
raise ValueError(f"Printer configuration not found: {args.printer_id}")
|
|
300
|
+
payload = printer.model_dump(mode="json")
|
|
301
|
+
payload["default"] = registry.default_printer == printer.printer_id
|
|
302
|
+
if args.json:
|
|
303
|
+
_print_json(payload)
|
|
304
|
+
else:
|
|
305
|
+
print(f"{printer.display_name} ({printer.printer_id})")
|
|
306
|
+
print(f"Backend: {printer.backend}")
|
|
307
|
+
print(f"Default profile: {printer.default_profile}")
|
|
308
|
+
for name, profile in sorted(printer.profiles.items()):
|
|
309
|
+
print(f"Profile {name}: {profile.native_config}")
|
|
310
|
+
return 0
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def cmd_printer_add(args: argparse.Namespace) -> int:
|
|
314
|
+
from forma_core.workspaces.projects.fabrication import (
|
|
315
|
+
PrinterProfileReference,
|
|
316
|
+
UserPrinterConfig,
|
|
317
|
+
save_printer_registry,
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
registry = _printer_registry()
|
|
321
|
+
if args.printer_id in registry.printers:
|
|
322
|
+
raise ValueError(f"Printer configuration already exists: {args.printer_id}")
|
|
323
|
+
if not args.profiles:
|
|
324
|
+
raise ValueError("At least one --profile NAME=PATH is required.")
|
|
325
|
+
profiles = {}
|
|
326
|
+
for value in args.profiles:
|
|
327
|
+
name, separator, native_config = value.partition("=")
|
|
328
|
+
if not separator or not name.strip() or not native_config.strip():
|
|
329
|
+
raise ValueError("Profiles must use NAME=PATH format.")
|
|
330
|
+
profiles[name.strip()] = PrinterProfileReference(native_config=native_config.strip())
|
|
331
|
+
printer = UserPrinterConfig(
|
|
332
|
+
printer_id=args.printer_id,
|
|
333
|
+
display_name=args.display_name or args.printer_id,
|
|
334
|
+
backend=args.backend,
|
|
335
|
+
default_profile=args.default_profile or next(iter(profiles)),
|
|
336
|
+
profiles=profiles,
|
|
337
|
+
)
|
|
338
|
+
registry.printers[printer.printer_id] = printer
|
|
339
|
+
if args.set_default or registry.default_printer is None:
|
|
340
|
+
registry.default_printer = printer.printer_id
|
|
341
|
+
save_printer_registry(registry)
|
|
342
|
+
print(f"Added printer {printer.printer_id}")
|
|
343
|
+
return 0
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def cmd_printer_set_default(args: argparse.Namespace) -> int:
|
|
347
|
+
from forma_core.workspaces.projects.fabrication import save_printer_registry
|
|
348
|
+
|
|
349
|
+
registry = _printer_registry()
|
|
350
|
+
if args.printer_id not in registry.printers:
|
|
351
|
+
raise ValueError(f"Printer configuration not found: {args.printer_id}")
|
|
352
|
+
registry.default_printer = args.printer_id
|
|
353
|
+
save_printer_registry(registry)
|
|
354
|
+
print(f"Default printer: {args.printer_id}")
|
|
355
|
+
return 0
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def cmd_printer_remove(args: argparse.Namespace) -> int:
|
|
359
|
+
from forma_core.workspaces.projects.fabrication import save_printer_registry
|
|
360
|
+
|
|
361
|
+
registry = _printer_registry()
|
|
362
|
+
if args.printer_id not in registry.printers:
|
|
363
|
+
raise ValueError(f"Printer configuration not found: {args.printer_id}")
|
|
364
|
+
del registry.printers[args.printer_id]
|
|
365
|
+
if registry.default_printer == args.printer_id:
|
|
366
|
+
registry.default_printer = next(iter(sorted(registry.printers)), None)
|
|
367
|
+
save_printer_registry(registry)
|
|
368
|
+
print(f"Removed printer {args.printer_id}")
|
|
369
|
+
return 0
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def cmd_project_slice(args: argparse.Namespace) -> int:
|
|
373
|
+
if args.project_id:
|
|
374
|
+
project_id = read_project(args.path).project_id
|
|
375
|
+
if args.project_id != project_id:
|
|
376
|
+
raise ValueError(f"Project ID mismatch: manifest contains {project_id}, requested {args.project_id}.")
|
|
377
|
+
manifest = slice_local_project(
|
|
378
|
+
args.path,
|
|
379
|
+
printer_id=args.printer,
|
|
380
|
+
backend=args.backend,
|
|
381
|
+
profile=args.profile,
|
|
382
|
+
profile_name=args.profile_name,
|
|
383
|
+
output_name=args.output_name,
|
|
384
|
+
)
|
|
385
|
+
result = {
|
|
386
|
+
"project_id": manifest.project_id,
|
|
387
|
+
"operation": "slice",
|
|
388
|
+
"artifacts": [artifact.model_dump(mode="json") for artifact in manifest.artifacts if artifact.path.startswith("fabrication/")],
|
|
389
|
+
}
|
|
390
|
+
if args.json:
|
|
391
|
+
_print_json(result)
|
|
392
|
+
else:
|
|
393
|
+
print(f"Sliced project {manifest.project_id}")
|
|
394
|
+
for artifact in result["artifacts"]:
|
|
395
|
+
print(f"Wrote {artifact['path']}")
|
|
396
|
+
return 0
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def cmd_projects_list(args: argparse.Namespace) -> int:
|
|
400
|
+
projects = _client(args).list_projects()
|
|
401
|
+
if args.json:
|
|
402
|
+
_print_json([project.model_dump(mode="json") for project in projects])
|
|
403
|
+
else:
|
|
404
|
+
for project in projects:
|
|
405
|
+
revision = project.revision_id or "no revisions"
|
|
406
|
+
print(f"{project.project_id}\t{project.title or 'Untitled'}\t{revision}")
|
|
407
|
+
return 0
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def _confirm_push(args: argparse.Namespace, manifest: Any) -> bool:
|
|
411
|
+
output = sys.stderr if args.json else sys.stdout
|
|
412
|
+
artifacts = list(getattr(manifest, "artifacts", []) or [])
|
|
413
|
+
print(f"This will upload the private project manifest and {len(artifacts)} referenced artifact(s).", file=output)
|
|
414
|
+
for artifact in artifacts:
|
|
415
|
+
print(f" - {artifact.path}", file=output)
|
|
416
|
+
print("Provider credentials and authentication tokens are excluded.", file=output)
|
|
417
|
+
if args.yes:
|
|
418
|
+
return True
|
|
419
|
+
if args.json:
|
|
420
|
+
print("Continue? [y/N] ", end="", file=output, flush=True)
|
|
421
|
+
answer = input().strip().lower()
|
|
422
|
+
else:
|
|
423
|
+
answer = input("Continue? [y/N] ").strip().lower()
|
|
424
|
+
return answer in {"y", "yes"}
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def _artifact_summary(statuses: list[dict[str, Any]]) -> dict[str, Any]:
|
|
428
|
+
counts: dict[str, int] = {}
|
|
429
|
+
for item in statuses:
|
|
430
|
+
status = str(item.get("status") or "unknown")
|
|
431
|
+
counts[status] = counts.get(status, 0) + 1
|
|
432
|
+
return {
|
|
433
|
+
"total": len(statuses),
|
|
434
|
+
"succeeded": sum(value for key, value in counts.items() if key in {"uploaded", "restored", "already_present"}),
|
|
435
|
+
"failed": sum(value for key, value in counts.items() if key not in {"uploaded", "restored", "already_present"}),
|
|
436
|
+
"by_status": counts,
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def _linkage_artifact_digests(linkage: dict[str, Any]) -> dict[str, str]:
|
|
441
|
+
value = linkage.get("artifact_digests")
|
|
442
|
+
if isinstance(value, str):
|
|
443
|
+
try:
|
|
444
|
+
value = json.loads(value)
|
|
445
|
+
except ValueError:
|
|
446
|
+
return {}
|
|
447
|
+
if not isinstance(value, dict):
|
|
448
|
+
return {}
|
|
449
|
+
return {
|
|
450
|
+
str(path): str(digest).strip().lower()
|
|
451
|
+
for path, digest in value.items()
|
|
452
|
+
if str(path).strip() and isinstance(digest, str) and digest.strip()
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def _ensure_pull_is_safe(
|
|
457
|
+
root: Path,
|
|
458
|
+
linkage: dict[str, Any],
|
|
459
|
+
local_manifest: ProjectManifest,
|
|
460
|
+
remote_artifacts: list[dict[str, Any]],
|
|
461
|
+
) -> None:
|
|
462
|
+
"""Reject dirty working trees before any remote bytes can replace files."""
|
|
463
|
+
current_revision = linkage.get("revision_id")
|
|
464
|
+
if current_revision:
|
|
465
|
+
expected_digest = linkage.get("manifest_digest")
|
|
466
|
+
if not expected_digest:
|
|
467
|
+
raise LocalProjectError(
|
|
468
|
+
"The linked project lacks a working-tree integrity record; refusing to overwrite local changes."
|
|
469
|
+
)
|
|
470
|
+
try:
|
|
471
|
+
current_digest = _manifest_digest(canonical_project_upload_payload(root, local_manifest))
|
|
472
|
+
except (LocalProjectError, ValueError) as exc:
|
|
473
|
+
raise LocalProjectError(
|
|
474
|
+
"Local project references cannot be verified; refusing to overwrite local changes."
|
|
475
|
+
) from exc
|
|
476
|
+
if current_digest != expected_digest:
|
|
477
|
+
raise LocalProjectError(
|
|
478
|
+
"Local project changes diverge from the linked cloud revision; refusing to overwrite them."
|
|
479
|
+
)
|
|
480
|
+
elif (
|
|
481
|
+
local_manifest.project_ir
|
|
482
|
+
or local_manifest.artifacts
|
|
483
|
+
or local_manifest.prompt
|
|
484
|
+
or local_manifest.title not in {"", "Untitled Forma Project"}
|
|
485
|
+
):
|
|
486
|
+
raise LocalProjectError(
|
|
487
|
+
"The local project is not pristine and has no linked revision; refusing to overwrite local changes."
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
baseline_digests = _linkage_artifact_digests(linkage)
|
|
491
|
+
local_digests = {
|
|
492
|
+
artifact.path: artifact.sha256.strip().lower()
|
|
493
|
+
for artifact in local_manifest.artifacts
|
|
494
|
+
if artifact.sha256 and artifact.sha256.strip()
|
|
495
|
+
}
|
|
496
|
+
for artifact in remote_artifacts:
|
|
497
|
+
target = artifact_target(root, artifact["path"])
|
|
498
|
+
if not target.exists() and not target.is_symlink():
|
|
499
|
+
continue
|
|
500
|
+
if target.is_symlink() or target.is_dir():
|
|
501
|
+
raise LocalProjectError(
|
|
502
|
+
f"Local artifact target is not a regular file: {artifact['path']}; refusing to overwrite it."
|
|
503
|
+
)
|
|
504
|
+
actual_digest = file_digest(target)
|
|
505
|
+
if actual_digest == artifact["sha256"]:
|
|
506
|
+
continue
|
|
507
|
+
baseline = baseline_digests.get(artifact["path"]) or local_digests.get(artifact["path"])
|
|
508
|
+
if not baseline or actual_digest != baseline:
|
|
509
|
+
raise LocalProjectError(
|
|
510
|
+
f"Local artifact {artifact['path']} has changed; refusing to overwrite local changes."
|
|
511
|
+
)
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def _restored_manifest(
|
|
515
|
+
root: Path,
|
|
516
|
+
manifest: ProjectManifest,
|
|
517
|
+
artifacts: list[dict[str, Any]],
|
|
518
|
+
) -> ProjectManifest:
|
|
519
|
+
replacements = {
|
|
520
|
+
artifact["path"]: str(artifact_target(root, artifact["path"]).resolve())
|
|
521
|
+
for artifact in artifacts
|
|
522
|
+
}
|
|
523
|
+
payload = manifest.model_dump(mode="json")
|
|
524
|
+
payload["artifacts"] = artifacts
|
|
525
|
+
payload["project_ir"] = rewrite_artifact_paths(payload.get("project_ir", {}), replacements)
|
|
526
|
+
return ProjectManifest.model_validate(payload)
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
def _download_parts(download: Any) -> tuple[bytes, str | None, str | None, int | None]:
|
|
530
|
+
if isinstance(download, ProjectArtifactDownload):
|
|
531
|
+
return download.content, download.content_type, download.sha256, download.size_bytes
|
|
532
|
+
if isinstance(download, (bytes, bytearray)):
|
|
533
|
+
return bytes(download), None, None, None
|
|
534
|
+
if isinstance(download, tuple):
|
|
535
|
+
content = bytes(download[0])
|
|
536
|
+
content_type = download[1] if len(download) > 1 else None
|
|
537
|
+
sha256 = download[2] if len(download) > 2 else None
|
|
538
|
+
size_bytes = download[3] if len(download) > 3 else None
|
|
539
|
+
return content, content_type, sha256, size_bytes
|
|
540
|
+
if isinstance(download, dict):
|
|
541
|
+
content = download.get("content", b"")
|
|
542
|
+
return (
|
|
543
|
+
bytes(content),
|
|
544
|
+
download.get("content_type") or download.get("media_type"),
|
|
545
|
+
download.get("sha256"),
|
|
546
|
+
download.get("size_bytes"),
|
|
547
|
+
)
|
|
548
|
+
content = getattr(download, "content", b"")
|
|
549
|
+
return (
|
|
550
|
+
bytes(content),
|
|
551
|
+
getattr(download, "content_type", None),
|
|
552
|
+
getattr(download, "sha256", None),
|
|
553
|
+
getattr(download, "size_bytes", None),
|
|
554
|
+
)
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def _push_idempotency_key(upload_payload: dict[str, Any]) -> str:
|
|
558
|
+
return f"push:{_manifest_digest(upload_payload)}"
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def cmd_projects_push(args: argparse.Namespace) -> int:
|
|
562
|
+
root = project_root(args.path)
|
|
563
|
+
manifest = read_project(root)
|
|
564
|
+
upload_payload, local_artifacts = prepare_project_upload(root, manifest)
|
|
565
|
+
if not _confirm_push(args, manifest):
|
|
566
|
+
if args.json:
|
|
567
|
+
_print_json({"ok": False, "operation": "push", "status": "cancelled"})
|
|
568
|
+
else:
|
|
569
|
+
print("Upload cancelled.")
|
|
570
|
+
return 1
|
|
571
|
+
linkage = load_linkage(root)
|
|
572
|
+
idempotency_key = args.key or _push_idempotency_key(upload_payload)
|
|
573
|
+
client = _client(args)
|
|
574
|
+
delivery = client.push_project(
|
|
575
|
+
upload_payload,
|
|
576
|
+
idempotency_key=idempotency_key,
|
|
577
|
+
parent_revision_id=linkage.get("revision_id"),
|
|
578
|
+
visibility=args.visibility,
|
|
579
|
+
)
|
|
580
|
+
if delivery.project.project_id != manifest.project_id:
|
|
581
|
+
raise LocalProjectError("Cloud push returned a different project identity; refusing to update local linkage.")
|
|
582
|
+
artifact_statuses: list[dict[str, Any]] = []
|
|
583
|
+
for artifact in local_artifacts:
|
|
584
|
+
try:
|
|
585
|
+
content = artifact.source_path.read_bytes()
|
|
586
|
+
except OSError as exc:
|
|
587
|
+
raise LocalProjectError(f"Could not read project artifact {artifact.path}: {exc}") from exc
|
|
588
|
+
if hashlib.sha256(content).hexdigest() != artifact.sha256:
|
|
589
|
+
raise LocalProjectError(
|
|
590
|
+
f"Project artifact {artifact.path} changed after validation; refusing to upload it."
|
|
591
|
+
)
|
|
592
|
+
try:
|
|
593
|
+
response = client.upload_project_artifact(
|
|
594
|
+
delivery.project.project_id,
|
|
595
|
+
delivery.project.revision_id,
|
|
596
|
+
artifact.sha256,
|
|
597
|
+
content,
|
|
598
|
+
artifact.media_type,
|
|
599
|
+
)
|
|
600
|
+
except FormaAPIError as exc:
|
|
601
|
+
raise LocalProjectError(f"Could not upload project artifact {artifact.path}: {exc}") from exc
|
|
602
|
+
response_sha256 = str(response.get("sha256") or artifact.sha256).strip().lower()
|
|
603
|
+
response_media_type = str(response.get("media_type") or artifact.media_type)
|
|
604
|
+
try:
|
|
605
|
+
response_media_type = normalize_artifact_media_type(response_media_type)
|
|
606
|
+
except ValueError as exc:
|
|
607
|
+
raise LocalProjectError(f"Cloud artifact validation failed for {artifact.path}.") from exc
|
|
608
|
+
if response_sha256 != artifact.sha256 or response_media_type != artifact.media_type:
|
|
609
|
+
raise LocalProjectError(f"Cloud artifact validation failed for {artifact.path}.")
|
|
610
|
+
response_size = response.get("size_bytes")
|
|
611
|
+
if response_size is not None:
|
|
612
|
+
try:
|
|
613
|
+
if int(response_size) != artifact.size_bytes:
|
|
614
|
+
raise LocalProjectError(f"Cloud artifact validation failed for {artifact.path}.")
|
|
615
|
+
except (TypeError, ValueError) as exc:
|
|
616
|
+
raise LocalProjectError(f"Cloud artifact validation failed for {artifact.path}.") from exc
|
|
617
|
+
artifact_statuses.append(
|
|
618
|
+
{
|
|
619
|
+
"path": artifact.path,
|
|
620
|
+
"status": str(response.get("status") or "uploaded"),
|
|
621
|
+
"sha256": artifact.sha256,
|
|
622
|
+
"media_type": artifact.media_type,
|
|
623
|
+
"size_bytes": artifact.size_bytes,
|
|
624
|
+
}
|
|
625
|
+
)
|
|
626
|
+
try:
|
|
627
|
+
completed = client.complete_delivery(delivery.delivery_id)
|
|
628
|
+
except FormaAPIError as exc:
|
|
629
|
+
raise LocalProjectError(
|
|
630
|
+
f"Delivery session {delivery.delivery_id} could not be completed: {exc}"
|
|
631
|
+
) from exc
|
|
632
|
+
if local_artifacts:
|
|
633
|
+
# Persist the same portable, secret-free shape that was committed remotely.
|
|
634
|
+
write_project_manifest(root / "forma-project.json", ProjectManifest.model_validate(upload_payload))
|
|
635
|
+
update_linkage(
|
|
636
|
+
root,
|
|
637
|
+
version=1,
|
|
638
|
+
remote=args.api_url.rstrip("/") if args.api_url else api_url(),
|
|
639
|
+
remote_project_id=completed.project.project_id,
|
|
640
|
+
project_id=manifest.project_id,
|
|
641
|
+
revision_id=completed.project.revision_id,
|
|
642
|
+
parent_revision_id=completed.project.parent_revision_id,
|
|
643
|
+
manifest_digest=_manifest_digest(upload_payload),
|
|
644
|
+
artifact_digests=json.dumps(
|
|
645
|
+
{artifact.path: artifact.sha256 for artifact in local_artifacts},
|
|
646
|
+
sort_keys=True,
|
|
647
|
+
),
|
|
648
|
+
)
|
|
649
|
+
payload = completed.model_dump(mode="json")
|
|
650
|
+
payload["operation"] = "push"
|
|
651
|
+
payload["idempotency_key"] = idempotency_key
|
|
652
|
+
payload["artifacts"] = artifact_statuses
|
|
653
|
+
payload["artifact_summary"] = _artifact_summary(artifact_statuses)
|
|
654
|
+
payload["project_url"] = _project_url(client.base_url or api_url(), completed.project.project_id)
|
|
655
|
+
if args.json:
|
|
656
|
+
_print_json(payload)
|
|
657
|
+
else:
|
|
658
|
+
print(f"Delivered project {completed.project.project_id} revision {completed.project.revision_id}")
|
|
659
|
+
print(f"Visibility: {completed.project.visibility}")
|
|
660
|
+
print(f"Project URL: {payload['project_url']}")
|
|
661
|
+
return 0
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
def cmd_projects_pull(args: argparse.Namespace) -> int:
|
|
665
|
+
root = project_root(args.path)
|
|
666
|
+
linkage = load_linkage(root)
|
|
667
|
+
remote_project_id = args.project_id or linkage.get("remote_project_id") or linkage.get("project_id")
|
|
668
|
+
if not remote_project_id:
|
|
669
|
+
raise LocalProjectError("No remote project is linked. Push this project first or pass --project-id.")
|
|
670
|
+
client = _client(args)
|
|
671
|
+
revision = client.pull_project(remote_project_id, args.revision_id)
|
|
672
|
+
if revision.project_id != remote_project_id:
|
|
673
|
+
raise LocalProjectError("Cloud pull returned a different project identity; refusing to update local files.")
|
|
674
|
+
current_revision = linkage.get("revision_id")
|
|
675
|
+
if current_revision and current_revision != revision.revision_id:
|
|
676
|
+
if revision.parent_revision_id not in {current_revision, None}:
|
|
677
|
+
raise LocalProjectError(
|
|
678
|
+
"Cloud revision ancestry diverges from the linked local revision; refusing to overwrite it."
|
|
679
|
+
)
|
|
680
|
+
manifest = ProjectManifest.from_document(revision.manifest)
|
|
681
|
+
if manifest.project_id != revision.project_id:
|
|
682
|
+
raise LocalProjectError("Cloud revision manifest identity does not match the revision; refusing to pull it.")
|
|
683
|
+
remote_artifacts = validate_artifact_references(manifest.artifacts, require_integrity=True)
|
|
684
|
+
local_manifest = read_project(root)
|
|
685
|
+
_ensure_pull_is_safe(root, linkage, local_manifest, remote_artifacts)
|
|
686
|
+
|
|
687
|
+
artifact_statuses: list[dict[str, Any]] = []
|
|
688
|
+
restored_manifest: ProjectManifest
|
|
689
|
+
with tempfile.TemporaryDirectory(prefix="forma-pull-", dir=root) as temporary_dir:
|
|
690
|
+
stage_root = Path(temporary_dir)
|
|
691
|
+
for artifact in remote_artifacts:
|
|
692
|
+
try:
|
|
693
|
+
downloaded = client.download_project_artifact(
|
|
694
|
+
revision.project_id,
|
|
695
|
+
revision.revision_id,
|
|
696
|
+
artifact["sha256"],
|
|
697
|
+
)
|
|
698
|
+
except (FormaAPIError, OSError) as exc:
|
|
699
|
+
raise LocalProjectError(f"Could not restore project artifact {artifact['path']}: {exc}") from exc
|
|
700
|
+
content, response_media_type, response_sha256, response_size = _download_parts(downloaded)
|
|
701
|
+
actual_sha256 = hashlib.sha256(content).hexdigest()
|
|
702
|
+
if actual_sha256 != artifact["sha256"] or (
|
|
703
|
+
response_sha256 and str(response_sha256).lower() != artifact["sha256"]
|
|
704
|
+
):
|
|
705
|
+
raise LocalProjectError(f"Downloaded project artifact {artifact['path']} failed its hash check.")
|
|
706
|
+
if response_media_type:
|
|
707
|
+
try:
|
|
708
|
+
normalized_media_type = normalize_artifact_media_type(response_media_type)
|
|
709
|
+
except ValueError as exc:
|
|
710
|
+
raise LocalProjectError(f"Downloaded project artifact {artifact['path']} has an invalid media type.") from exc
|
|
711
|
+
if normalized_media_type != artifact["media_type"]:
|
|
712
|
+
raise LocalProjectError(f"Downloaded project artifact {artifact['path']} failed its media type check.")
|
|
713
|
+
if artifact.get("size_bytes") is not None and len(content) != artifact["size_bytes"]:
|
|
714
|
+
raise LocalProjectError(f"Downloaded project artifact {artifact['path']} failed its size check.")
|
|
715
|
+
if response_size is not None and int(response_size) != len(content):
|
|
716
|
+
raise LocalProjectError(f"Downloaded project artifact {artifact['path']} returned an invalid size.")
|
|
717
|
+
staged = stage_root / Path(*artifact["path"].split("/"))
|
|
718
|
+
staged.parent.mkdir(parents=True, exist_ok=True)
|
|
719
|
+
staged.write_bytes(content)
|
|
720
|
+
target = artifact_target(root, artifact["path"])
|
|
721
|
+
artifact_statuses.append(
|
|
722
|
+
{
|
|
723
|
+
"path": artifact["path"],
|
|
724
|
+
"status": "already_present" if target.is_file() and file_digest(target) == artifact["sha256"] else "restored",
|
|
725
|
+
"sha256": artifact["sha256"],
|
|
726
|
+
"media_type": artifact["media_type"],
|
|
727
|
+
"size_bytes": len(content),
|
|
728
|
+
}
|
|
729
|
+
)
|
|
730
|
+
|
|
731
|
+
restored_manifest = _restored_manifest(root, manifest, remote_artifacts)
|
|
732
|
+
for artifact in remote_artifacts:
|
|
733
|
+
target = artifact_target(root, artifact["path"])
|
|
734
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
735
|
+
(stage_root / Path(*artifact["path"].split("/"))).replace(target)
|
|
736
|
+
write_project_manifest(root / "forma-project.json", restored_manifest)
|
|
737
|
+
update_linkage(
|
|
738
|
+
root,
|
|
739
|
+
remote=args.api_url.rstrip("/") if args.api_url else api_url(),
|
|
740
|
+
remote_project_id=revision.project_id,
|
|
741
|
+
project_id=manifest.project_id,
|
|
742
|
+
revision_id=revision.revision_id,
|
|
743
|
+
parent_revision_id=revision.parent_revision_id,
|
|
744
|
+
manifest_digest=_manifest_digest(canonical_project_upload_payload(root, restored_manifest)),
|
|
745
|
+
artifact_digests=json.dumps(
|
|
746
|
+
{artifact["path"]: artifact["sha256"] for artifact in remote_artifacts},
|
|
747
|
+
sort_keys=True,
|
|
748
|
+
),
|
|
749
|
+
)
|
|
750
|
+
if args.json:
|
|
751
|
+
payload = revision.model_dump(mode="json")
|
|
752
|
+
payload["operation"] = "pull"
|
|
753
|
+
payload["artifacts"] = artifact_statuses
|
|
754
|
+
payload["artifact_summary"] = _artifact_summary(artifact_statuses)
|
|
755
|
+
_print_json(payload)
|
|
756
|
+
else:
|
|
757
|
+
print(f"Pulled private project {revision.project_id} revision {revision.revision_id}")
|
|
758
|
+
print(f"Restored {len(artifact_statuses)} project artifact(s)")
|
|
759
|
+
return 0
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
def _delivery_idempotency_key(upload_payload: dict[str, Any]) -> str:
|
|
763
|
+
return f"deliver:{_manifest_digest(upload_payload)}"
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
def cmd_projects_deliver(args: argparse.Namespace) -> int:
|
|
767
|
+
root = project_root(args.path)
|
|
768
|
+
manifest = read_project(root)
|
|
769
|
+
upload_payload, local_artifacts = prepare_project_upload(root, manifest)
|
|
770
|
+
if not _confirm_push(args, manifest):
|
|
771
|
+
if args.json:
|
|
772
|
+
_print_json({"ok": False, "operation": "deliver", "status": "cancelled"})
|
|
773
|
+
else:
|
|
774
|
+
print("Deliver cancelled.")
|
|
775
|
+
return 1
|
|
776
|
+
linkage = load_linkage(root)
|
|
777
|
+
idempotency_key = args.key or _delivery_idempotency_key(upload_payload)
|
|
778
|
+
client = _client(args)
|
|
779
|
+
delivery = client.deliver_project(
|
|
780
|
+
upload_payload,
|
|
781
|
+
idempotency_key=idempotency_key,
|
|
782
|
+
parent_revision_id=linkage.get("revision_id"),
|
|
783
|
+
visibility=args.visibility,
|
|
784
|
+
)
|
|
785
|
+
if delivery.project.project_id != manifest.project_id:
|
|
786
|
+
raise LocalProjectError("Cloud delivery returned a different project identity; refusing to update local linkage.")
|
|
787
|
+
artifact_statuses: list[dict[str, Any]] = []
|
|
788
|
+
for artifact in local_artifacts:
|
|
789
|
+
try:
|
|
790
|
+
content = artifact.source_path.read_bytes()
|
|
791
|
+
except OSError as exc:
|
|
792
|
+
raise LocalProjectError(f"Could not read project artifact {artifact.path}: {exc}") from exc
|
|
793
|
+
if hashlib.sha256(content).hexdigest() != artifact.sha256:
|
|
794
|
+
raise LocalProjectError(
|
|
795
|
+
f"Project artifact {artifact.path} changed after validation; refusing to upload it."
|
|
796
|
+
)
|
|
797
|
+
try:
|
|
798
|
+
response = client.upload_project_artifact(
|
|
799
|
+
delivery.project.project_id,
|
|
800
|
+
delivery.project.revision_id,
|
|
801
|
+
artifact.sha256,
|
|
802
|
+
content,
|
|
803
|
+
artifact.media_type,
|
|
804
|
+
)
|
|
805
|
+
except FormaAPIError as exc:
|
|
806
|
+
raise LocalProjectError(f"Could not upload project artifact {artifact.path}: {exc}") from exc
|
|
807
|
+
response_sha256 = str(response.get("sha256") or artifact.sha256).strip().lower()
|
|
808
|
+
response_media_type = str(response.get("media_type") or artifact.media_type)
|
|
809
|
+
try:
|
|
810
|
+
response_media_type = normalize_artifact_media_type(response_media_type)
|
|
811
|
+
except ValueError as exc:
|
|
812
|
+
raise LocalProjectError(f"Cloud artifact validation failed for {artifact.path}.") from exc
|
|
813
|
+
if response_sha256 != artifact.sha256 or response_media_type != artifact.media_type:
|
|
814
|
+
raise LocalProjectError(f"Cloud artifact validation failed for {artifact.path}.")
|
|
815
|
+
response_size = response.get("size_bytes")
|
|
816
|
+
if response_size is not None:
|
|
817
|
+
try:
|
|
818
|
+
if int(response_size) != artifact.size_bytes:
|
|
819
|
+
raise LocalProjectError(f"Cloud artifact validation failed for {artifact.path}.")
|
|
820
|
+
except (TypeError, ValueError) as exc:
|
|
821
|
+
raise LocalProjectError(f"Cloud artifact validation failed for {artifact.path}.") from exc
|
|
822
|
+
artifact_statuses.append(
|
|
823
|
+
{
|
|
824
|
+
"path": artifact.path,
|
|
825
|
+
"status": str(response.get("status") or "uploaded"),
|
|
826
|
+
"sha256": artifact.sha256,
|
|
827
|
+
"media_type": artifact.media_type,
|
|
828
|
+
"size_bytes": artifact.size_bytes,
|
|
829
|
+
}
|
|
830
|
+
)
|
|
831
|
+
try:
|
|
832
|
+
completed = client.complete_delivery(delivery.delivery_id)
|
|
833
|
+
except FormaAPIError as exc:
|
|
834
|
+
raise LocalProjectError(
|
|
835
|
+
f"Delivery session {delivery.delivery_id} could not be completed: {exc}"
|
|
836
|
+
) from exc
|
|
837
|
+
if local_artifacts:
|
|
838
|
+
write_project_manifest(root / "forma-project.json", ProjectManifest.model_validate(upload_payload))
|
|
839
|
+
update_linkage(
|
|
840
|
+
root,
|
|
841
|
+
remote=args.api_url.rstrip("/") if args.api_url else api_url(),
|
|
842
|
+
remote_project_id=completed.project.project_id,
|
|
843
|
+
project_id=manifest.project_id,
|
|
844
|
+
revision_id=completed.project.revision_id,
|
|
845
|
+
parent_revision_id=completed.project.parent_revision_id,
|
|
846
|
+
manifest_digest=_manifest_digest(upload_payload),
|
|
847
|
+
artifact_digests=json.dumps(
|
|
848
|
+
{artifact.path: artifact.sha256 for artifact in local_artifacts},
|
|
849
|
+
sort_keys=True,
|
|
850
|
+
),
|
|
851
|
+
)
|
|
852
|
+
payload = completed.model_dump(mode="json")
|
|
853
|
+
payload["operation"] = "deliver"
|
|
854
|
+
payload["idempotency_key"] = idempotency_key
|
|
855
|
+
payload["artifacts"] = artifact_statuses
|
|
856
|
+
payload["project_url"] = _project_url(client.base_url or api_url(), completed.project.project_id)
|
|
857
|
+
if args.json:
|
|
858
|
+
_print_json(payload)
|
|
859
|
+
else:
|
|
860
|
+
print(f"Delivered project {completed.project.project_id} revision {completed.project.revision_id}")
|
|
861
|
+
print(f"Visibility: {completed.project.visibility}")
|
|
862
|
+
print(f"Project URL: {payload['project_url']}")
|
|
863
|
+
return 0
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
def cmd_projects_publish(args: argparse.Namespace) -> int:
|
|
867
|
+
root = project_root(args.path)
|
|
868
|
+
linkage = load_linkage(root)
|
|
869
|
+
project_id = args.project_id or linkage.get("remote_project_id") or linkage.get("project_id")
|
|
870
|
+
if not project_id:
|
|
871
|
+
raise LocalProjectError("No remote project is linked. Deliver or push it first, or pass --project-id.")
|
|
872
|
+
result = _client(args).publish_project(project_id)
|
|
873
|
+
payload = dict(result)
|
|
874
|
+
payload["operation"] = "publish"
|
|
875
|
+
if args.json:
|
|
876
|
+
_print_json(payload)
|
|
877
|
+
else:
|
|
878
|
+
print(f"Project {project_id} is now {result.get('visibility', 'public')}")
|
|
879
|
+
if result.get("published"):
|
|
880
|
+
print(f"Published from {result.get('visibility_before')} by explicit action ({result.get('published_at')}).")
|
|
881
|
+
else:
|
|
882
|
+
print("Project was already public; no change was recorded.")
|
|
883
|
+
return 0
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
def _manifest_digest(value: Any) -> str:
|
|
887
|
+
canonical = json.dumps(value, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
|
888
|
+
return hashlib.sha256(canonical).hexdigest()
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
def _project_url(api_endpoint: str, project_id: str) -> str:
|
|
892
|
+
"""Build the browser URL without coupling the CLI to the web client."""
|
|
893
|
+
web_endpoint = (
|
|
894
|
+
os.environ.get("FORMA_WEB_URL")
|
|
895
|
+
or os.environ.get("NEXT_PUBLIC_APP_URL")
|
|
896
|
+
or api_endpoint.rstrip("/")
|
|
897
|
+
).rstrip("/")
|
|
898
|
+
if web_endpoint.endswith("/api"):
|
|
899
|
+
web_endpoint = web_endpoint[:-4].rstrip("/")
|
|
900
|
+
return f"{web_endpoint}/project/{quote(project_id, safe='')}"
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
def _local_key_rows(store: CredentialStore) -> list[dict[str, Any]]:
|
|
904
|
+
rows = []
|
|
905
|
+
for provider in sorted(LOCAL_PROVIDER_ENVIRONMENT):
|
|
906
|
+
try:
|
|
907
|
+
configured = bool(store.get(f"provider:{provider}"))
|
|
908
|
+
except CredentialStoreError:
|
|
909
|
+
configured = False
|
|
910
|
+
rows.append({"provider": provider, "scope": "local", "configured": configured})
|
|
911
|
+
return rows
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
def cmd_keys_list(args: argparse.Namespace) -> int:
|
|
915
|
+
rows: list[dict[str, Any]] = []
|
|
916
|
+
if args.scope in {"local", "both"}:
|
|
917
|
+
rows.extend(_local_key_rows(CredentialStore()))
|
|
918
|
+
if args.scope in {"cloud", "both"}:
|
|
919
|
+
rows.extend(
|
|
920
|
+
{**key.model_dump(mode="json"), "scope": "cloud"}
|
|
921
|
+
for key in _client(args).list_keys()
|
|
922
|
+
)
|
|
923
|
+
if args.json:
|
|
924
|
+
_print_json(rows)
|
|
925
|
+
else:
|
|
926
|
+
for row in rows:
|
|
927
|
+
masked = row.get("masked_value") or ("configured" if row.get("configured") else "not configured")
|
|
928
|
+
print(f"{row['scope']}\t{row['provider']}\t{masked}")
|
|
929
|
+
return 0
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
def cmd_keys_set(args: argparse.Namespace) -> int:
|
|
933
|
+
if args.scope == "local" and args.provider not in LOCAL_PROVIDER_ENVIRONMENT:
|
|
934
|
+
raise ValueError(
|
|
935
|
+
f"Unknown local provider {args.provider!r}. Supported providers: "
|
|
936
|
+
+ ", ".join(sorted(LOCAL_PROVIDER_ENVIRONMENT))
|
|
937
|
+
)
|
|
938
|
+
value = args.value or getpass.getpass("Provider key (input hidden): ")
|
|
939
|
+
if args.scope == "local":
|
|
940
|
+
CredentialStore().set(f"provider:{args.provider}", value)
|
|
941
|
+
print(f"Stored {args.provider} in the OS credential store for local generation.")
|
|
942
|
+
else:
|
|
943
|
+
result = _client(args).set_key(args.provider, value, label=args.label)
|
|
944
|
+
print(f"Stored managed {result.provider} credential {result.credential_id or result.label or ''}".rstrip())
|
|
945
|
+
return 0
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
def cmd_keys_remove(args: argparse.Namespace) -> int:
|
|
949
|
+
if args.scope == "local" and args.provider not in LOCAL_PROVIDER_ENVIRONMENT:
|
|
950
|
+
raise ValueError(
|
|
951
|
+
f"Unknown local provider {args.provider!r}. Supported providers: "
|
|
952
|
+
+ ", ".join(sorted(LOCAL_PROVIDER_ENVIRONMENT))
|
|
953
|
+
)
|
|
954
|
+
if args.scope == "local":
|
|
955
|
+
CredentialStore().delete(f"provider:{args.provider}")
|
|
956
|
+
print(f"Removed local {args.provider} credential.")
|
|
957
|
+
else:
|
|
958
|
+
_client(args).remove_key(args.provider)
|
|
959
|
+
print(f"Removed managed {args.provider} credential.")
|
|
960
|
+
return 0
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
964
|
+
parser = argparse.ArgumentParser(prog="forma-oss", description="Local-first Forma project CLI.")
|
|
965
|
+
parser.add_argument("--api-url", default=None, help="Forma API endpoint; defaults to local config or FORMA_API_URL.")
|
|
966
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
967
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
968
|
+
|
|
969
|
+
version = subparsers.add_parser("version", help="Show local and hosted compatibility information.")
|
|
970
|
+
version.add_argument("--json", action="store_true")
|
|
971
|
+
version.set_defaults(func=cmd_version)
|
|
972
|
+
doctor = subparsers.add_parser("doctor", help="Check local, hosted, and authentication compatibility.")
|
|
973
|
+
doctor.add_argument("--json", action="store_true")
|
|
974
|
+
doctor.set_defaults(func=cmd_doctor)
|
|
975
|
+
|
|
976
|
+
login = subparsers.add_parser("login", help="Authenticate with browser/device authorization.")
|
|
977
|
+
login.add_argument("--no-browser", action="store_true", help="Print the approval URL without opening a browser.")
|
|
978
|
+
login.set_defaults(func=cmd_login)
|
|
979
|
+
logout = subparsers.add_parser("logout", help="Revoke the CLI session and remove local credentials.")
|
|
980
|
+
logout.set_defaults(func=cmd_logout)
|
|
981
|
+
whoami = subparsers.add_parser("whoami", help="Show the signed-in account and API endpoint.")
|
|
982
|
+
whoami.add_argument("--json", action="store_true")
|
|
983
|
+
whoami.set_defaults(func=cmd_whoami)
|
|
984
|
+
|
|
985
|
+
init = subparsers.add_parser("init", help="Create a local forma-project.json.")
|
|
986
|
+
init.add_argument("path", nargs="?", default=".")
|
|
987
|
+
init.add_argument("--title", default="")
|
|
988
|
+
init.set_defaults(func=cmd_init)
|
|
989
|
+
build = subparsers.add_parser("build", help="Generate or rebuild a project locally.")
|
|
990
|
+
build.add_argument("prompt", nargs="?")
|
|
991
|
+
build.add_argument("--path", default=".")
|
|
992
|
+
build.add_argument("--workflow", default="default")
|
|
993
|
+
build.add_argument("--provider")
|
|
994
|
+
build.add_argument("--model")
|
|
995
|
+
build.add_argument("--simulation", action="store_true")
|
|
996
|
+
build.add_argument(
|
|
997
|
+
"--assembly-step",
|
|
998
|
+
help="Optional native STEP file to attach to the project.",
|
|
999
|
+
)
|
|
1000
|
+
build.set_defaults(func=cmd_build)
|
|
1001
|
+
imported = subparsers.add_parser(
|
|
1002
|
+
"import",
|
|
1003
|
+
help="Import an existing generated Hardware Intermediate Representation project and its native CAD artifacts.",
|
|
1004
|
+
)
|
|
1005
|
+
imported.add_argument("source", help="Existing forma-project.json or its containing directory.")
|
|
1006
|
+
imported.add_argument("--path", default=None, help="Destination project directory; defaults to the source directory.")
|
|
1007
|
+
imported.add_argument("--assembly-step", help="Override the STEP artifact discovered from the source project.")
|
|
1008
|
+
imported.add_argument("--preview-stl", help="Override the STL preview discovered from the source project.")
|
|
1009
|
+
imported.set_defaults(func=cmd_import)
|
|
1010
|
+
metadata = subparsers.add_parser("metadata", help="Read local project and artifact metadata without the Forma API.")
|
|
1011
|
+
metadata.add_argument("--path", default=".")
|
|
1012
|
+
metadata.add_argument("--json", action="store_true")
|
|
1013
|
+
metadata.set_defaults(func=cmd_metadata)
|
|
1014
|
+
metadata_api = subparsers.add_parser("metadata-api", help="Serve local project metadata over a read-only HTTP API.")
|
|
1015
|
+
metadata_api.add_argument("--path", default=".")
|
|
1016
|
+
metadata_api.add_argument("--host", default="127.0.0.1")
|
|
1017
|
+
metadata_api.add_argument("--port", type=int, default=8765)
|
|
1018
|
+
metadata_api.set_defaults(func=cmd_metadata_api)
|
|
1019
|
+
status = subparsers.add_parser("status", help="Validate and show local/remote project state.")
|
|
1020
|
+
status.add_argument("--path", default=".")
|
|
1021
|
+
status.add_argument("--json", action="store_true")
|
|
1022
|
+
status.set_defaults(func=cmd_status)
|
|
1023
|
+
|
|
1024
|
+
render = subparsers.add_parser("render", help="Render the local mechanical project layout to a PNG.")
|
|
1025
|
+
render.add_argument("--path", default=None)
|
|
1026
|
+
render.add_argument("--output", default="forma-render.png")
|
|
1027
|
+
render.add_argument("--width", type=int, default=1280)
|
|
1028
|
+
render.add_argument("--height", type=int, default=900)
|
|
1029
|
+
render.add_argument("--yaw", type=float, default=0.0)
|
|
1030
|
+
render.set_defaults(func=cmd_render)
|
|
1031
|
+
|
|
1032
|
+
printer = subparsers.add_parser("printer", help="Manage the local user printer registry.")
|
|
1033
|
+
printer_commands = printer.add_subparsers(dest="printer_command", required=True)
|
|
1034
|
+
printer_add = printer_commands.add_parser("add", help="Register a printer and native slicing profile.")
|
|
1035
|
+
printer_add.add_argument("printer_id")
|
|
1036
|
+
printer_add.add_argument("--backend", required=True)
|
|
1037
|
+
printer_add.add_argument("--profile", dest="profiles", action="append", required=True, metavar="NAME=PATH")
|
|
1038
|
+
printer_add.add_argument("--display-name")
|
|
1039
|
+
printer_add.add_argument("--default-profile")
|
|
1040
|
+
printer_add.add_argument("--set-default", action="store_true")
|
|
1041
|
+
printer_add.set_defaults(func=cmd_printer_add)
|
|
1042
|
+
printer_list = printer_commands.add_parser("list", help="List registered printers.")
|
|
1043
|
+
printer_list.add_argument("--json", action="store_true")
|
|
1044
|
+
printer_list.set_defaults(func=cmd_printer_list)
|
|
1045
|
+
printer_show = printer_commands.add_parser("show", help="Show a registered printer.")
|
|
1046
|
+
printer_show.add_argument("printer_id")
|
|
1047
|
+
printer_show.add_argument("--json", action="store_true")
|
|
1048
|
+
printer_show.set_defaults(func=cmd_printer_show)
|
|
1049
|
+
printer_default = printer_commands.add_parser("set-default", help="Select the default printer.")
|
|
1050
|
+
printer_default.add_argument("printer_id")
|
|
1051
|
+
printer_default.set_defaults(func=cmd_printer_set_default)
|
|
1052
|
+
printer_remove = printer_commands.add_parser("remove", help="Remove a registered printer.")
|
|
1053
|
+
printer_remove.add_argument("printer_id")
|
|
1054
|
+
printer_remove.set_defaults(func=cmd_printer_remove)
|
|
1055
|
+
|
|
1056
|
+
project = subparsers.add_parser("project", help="Run operations on a local Forma project.")
|
|
1057
|
+
project_commands = project.add_subparsers(dest="project_command", required=True)
|
|
1058
|
+
project_slice = project_commands.add_parser("slice", help="Slice an existing project mesh into validated G-code.")
|
|
1059
|
+
project_slice.add_argument("project_id", nargs="?")
|
|
1060
|
+
project_slice.add_argument("--path", default=".")
|
|
1061
|
+
project_slice.add_argument("--printer")
|
|
1062
|
+
project_slice.add_argument("--backend")
|
|
1063
|
+
project_slice.add_argument("--profile", help="Native slicer profile/config path.")
|
|
1064
|
+
project_slice.add_argument("--profile-name")
|
|
1065
|
+
project_slice.add_argument("--output-name")
|
|
1066
|
+
project_slice.add_argument("--json", action="store_true")
|
|
1067
|
+
project_slice.set_defaults(func=cmd_project_slice)
|
|
1068
|
+
|
|
1069
|
+
projects = subparsers.add_parser("projects", help="Manage explicit cloud project synchronization.")
|
|
1070
|
+
project_commands = projects.add_subparsers(dest="projects_command", required=True)
|
|
1071
|
+
projects_list = project_commands.add_parser("list", help="List private cloud projects.")
|
|
1072
|
+
projects_list.add_argument("--json", action="store_true")
|
|
1073
|
+
projects_list.set_defaults(func=cmd_projects_list)
|
|
1074
|
+
push = project_commands.add_parser("push", help="Upload the canonical manifest and referenced artifacts explicitly.")
|
|
1075
|
+
push.add_argument("--path", default=".")
|
|
1076
|
+
push.add_argument("--key", help="Idempotency key; defaults to a digest of the pushed manifest.")
|
|
1077
|
+
push.add_argument("--visibility", choices=("public", "private"), default=None)
|
|
1078
|
+
push.add_argument("--yes", action="store_true", help="Confirm upload without prompting.")
|
|
1079
|
+
push.add_argument("--json", action="store_true")
|
|
1080
|
+
push.set_defaults(func=cmd_projects_push)
|
|
1081
|
+
pull = project_commands.add_parser("pull", help="Download an exact or latest linked revision.")
|
|
1082
|
+
pull.add_argument("--path", default=".")
|
|
1083
|
+
pull.add_argument("--project-id")
|
|
1084
|
+
pull.add_argument("--revision-id")
|
|
1085
|
+
pull.add_argument("--json", action="store_true")
|
|
1086
|
+
pull.set_defaults(func=cmd_projects_pull)
|
|
1087
|
+
deliver = project_commands.add_parser(
|
|
1088
|
+
"deliver",
|
|
1089
|
+
help="Deliver a private snapshot with an idempotent receipt accepted only after artifacts are verified.",
|
|
1090
|
+
)
|
|
1091
|
+
deliver.add_argument("--path", default=".")
|
|
1092
|
+
deliver.add_argument("--key", help="Idempotency key; defaults to a digest of the delivered manifest.")
|
|
1093
|
+
deliver.add_argument("--visibility", choices=("public", "private"), default=None)
|
|
1094
|
+
deliver.add_argument("--yes", action="store_true", help="Confirm delivery without prompting.")
|
|
1095
|
+
deliver.add_argument("--json", action="store_true")
|
|
1096
|
+
deliver.set_defaults(func=cmd_projects_deliver)
|
|
1097
|
+
publish = project_commands.add_parser("publish", help="Explicitly publish an owned private project.")
|
|
1098
|
+
publish.add_argument("--path", default=".")
|
|
1099
|
+
publish.add_argument("--project-id")
|
|
1100
|
+
publish.add_argument("--json", action="store_true")
|
|
1101
|
+
publish.set_defaults(func=cmd_projects_publish)
|
|
1102
|
+
|
|
1103
|
+
keys = subparsers.add_parser("keys", help="Manage local or hosted provider credentials.")
|
|
1104
|
+
key_commands = keys.add_subparsers(dest="keys_command", required=True)
|
|
1105
|
+
keys_list = key_commands.add_parser("list", help="List credential metadata only.")
|
|
1106
|
+
keys_list.add_argument("--scope", choices=("local", "cloud", "both"), default="local")
|
|
1107
|
+
keys_list.add_argument("--json", action="store_true")
|
|
1108
|
+
keys_list.set_defaults(func=cmd_keys_list)
|
|
1109
|
+
keys_set = key_commands.add_parser("set", help="Store a provider credential.")
|
|
1110
|
+
keys_set.add_argument("provider")
|
|
1111
|
+
keys_set.add_argument("--scope", choices=("local", "cloud"), default="local")
|
|
1112
|
+
keys_set.add_argument("--value", help=argparse.SUPPRESS)
|
|
1113
|
+
keys_set.add_argument("--label")
|
|
1114
|
+
keys_set.set_defaults(func=cmd_keys_set)
|
|
1115
|
+
keys_remove = key_commands.add_parser("remove", help="Remove a provider credential.")
|
|
1116
|
+
keys_remove.add_argument("provider")
|
|
1117
|
+
keys_remove.add_argument("--scope", choices=("local", "cloud"), default="local")
|
|
1118
|
+
keys_remove.set_defaults(func=cmd_keys_remove)
|
|
1119
|
+
return parser
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
def app(argv: list[str] | None = None) -> int:
|
|
1123
|
+
parser = build_parser()
|
|
1124
|
+
args = parser.parse_args(argv)
|
|
1125
|
+
try:
|
|
1126
|
+
return args.func(args)
|
|
1127
|
+
except (CredentialStoreError, FormaAPIError, LocalProjectError, OSError, ValueError, RuntimeError) as exc:
|
|
1128
|
+
if getattr(args, "json", False):
|
|
1129
|
+
_print_json({"ok": False, "error": str(exc), "error_type": exc.__class__.__name__})
|
|
1130
|
+
else:
|
|
1131
|
+
print(f"{parser.prog}: {exc}", file=sys.stderr)
|
|
1132
|
+
return 2
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
main = app
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
if __name__ == "__main__":
|
|
1139
|
+
raise SystemExit(app())
|