lmgcp guide
Overview
lmgcp is a single-binary Google Cloud Platform host for LMScript built on lmcode-go and official Google Cloud Go SDKs (cloud.google.com/go and google.golang.org/api). It provides two execution surfaces in one executable: the native 16-service Gcp schema (default lmgcp command) and the provider-neutral lmcloud schema (lmgcp cloud subcommand).
Dual schema architecture: native Gcp and shared lmcloud
Understanding the two CLI modes lets you pick the right abstraction for your script:
- Native GCP mode (lmgcp --lmcode FILE): binds schema/lmgcp.dsl.json with context gcp: Gcp. It exposes 299 host-specific signatures across 16 GCP service families and 20 typed handles, plus 226 standard lmcode_std_v3 signatures (525 total signatures). Use this mode for the 40 visual GCP cloud stories, multi-VPC topology analysis, GKE/Cloud SQL/KMS/IAM security audits, BigQuery/Firestore data workflows, and Cloud Logging/Monitoring pipelines.
- Shared lmcloud mode (lmgcp cloud --lmcode FILE): delegates to cloudhost.Program from github.com/lmctl-ai/lmcloud/hostkit/cloudhost and binds schema/lmcloud.dsl.json with context cloud: Cloud. In this mode, bucket_* and object_* map to Cloud Storage (GCS), queue_* maps to Pub/Sub topic-and-subscription pairs, and table_*/item_* map to Firestore.
In-process fakegcp server versus local gcpsim emulator
lmgcp supports three transport backends without code changes:
- In-process fakegcp server (default): starts an ephemeral loopback HTTP server inside the lmgcp process pre-seeded with 43 realistic GCP resources across all 16 domains. Every example runs deterministically offline at $0.00 actual cloud cost.
- Local gcpsim emulator: set LMGCP_ENDPOINT=http://127.0.0.1:4588 (or cloud.set_endpoint("all", "http://127.0.0.1:4588") in lmgcp cloud mode) to target a standalone gcpsim process for GCS and Pub/Sub testing. Set LMGCP_ACCESS_TOKEN when testing against gcpsim --auth enforce with OAuth bearer token and IAM binding rules.
- Live Google Cloud (LMGCP_LIVE=1): authenticates with Google Application Default Credentials in LMGCP_PROJECT, LMGCP_REGION (default us-central1), and LMGCP_ZONE (default us-central1-a). LMGCP_ENDPOINT and LMGCP_LIVE=1 are mutually exclusive.
Cloud safety guardrails and RunLedger cost model
Every mutating operation in lmgcp passes through internal/safety guardrails:
- Mandatory prefixes and labels: created resources are automatically prefixed with lmgcp_<runId>_ or lmgcp-<runId>- and labeled with lmgcp_test=<runId>. Resources lacking ownership metadata are never modified or deleted.
- Shape allowlists: Compute Engine instances are restricted to e2-micro and e2-small with boot disks ≤20 GB; Cloud SQL instances are restricted to db-f1-micro and db-g1-small; GKE cluster creation is read-only in live mode to prevent high-cost control-plane charges.
- Pre-dispatch cost cap: RunLedger estimates cost using us-central1 list prices before each mutating request. The default cap is $0.05 per run with a hard ceiling of $0.25. Any operation that would push cumulative cost above the cap is refused before contacting the transport.
- Durable recovery journal and LIFO teardown: every creation appends an entry to an fsynced journal in LMGCP_STATE_DIR (or LMGCP_LEDGER). On normal exit, error, or memory watchdog trigger (LMGCP_MAX_MEMORY_MB, default 4096 MiB), CleanupLedger deletes owned resources in reverse order. Interrupted runs can be replayed with lmgcp --sweep --run-id ID --delete.
Standard lmcode_std_v3 REST and CLI interfaces
Both native lmgcp and lmgcp cloud register the 226-signature lmcode_std_v3 standard library, including all 10 standard REST and CLI SAM interfaces (RestGet, RestPost, RestPut, RestDelete, RestPatch, RestHead, RestOptions, RestHandler, CliCommand, CliOption) and the 5 dispatcher functions (rest_config, rest_route, rest_serve, rest_stop, rest_cli).
p = _lmcode_ cli="lmgcp" install="github:lmctl-ai/lmgcp@latest";
@"/projects/inventory/:service"
fn get_inv(x: RestExchange) -> void implements RestGet {
let svc = x.param("service");
if (svc == "vms") {
x.json("{\"vms\":" + str(gcp.compute_list_instances(gcp.zone()).len()) + "}");
return;
}
x.json("{\"buckets\":" + str(gcp.storage_list_buckets().len()) + "}");
}
@"--format"
fn opt_fmt(x: RestExchange) -> void implements CliOption {
x.set("fmt", x.query("format"));
}
@"audit"
fn cmd_audit(x: RestExchange) -> void implements CliCommand {
x.send(x.get("fmt") + ":vms=" + str(gcp.compute_list_instances(gcp.zone()).len()));
}
rest_config("prefix", "/v1");
let a = rest_cli(str_split("--format text audit", " "));
let b = rest_cli(str_split("/v1/projects/inventory/vms", " "));
print(a + " | " + b);
end _lmcode_