cloud/provision script recorded. Once a project saves its first revision, its machine profiles' checks and setup replace checks and machine/prepare, the other phases no longer run, and the revision supplies the browser origins, command environment and signed-caller routes. Service declarations in .gitspace/services.json, signed callers and service tokens apply to every project..gitspace/bundle.json version 1 and scripts under .gitspace/lifecycle. There is no second lifecycle manifest. For the human approval flow, see Workspace lifecycle.123456789101112131415161718192021222324252627282930313233{ "version": 1, "defaultProfile": "base", "profiles": { "base": { "checks": ["bun"], "secrets": [], "values": ["APP_MODE"], "notes": "Local development" }, "preview": { "checks": ["github"], "secrets": ["GH_TOKEN"], "values": ["PREVIEW_REPOSITORY"] } }, "checks": { "bun": { "kind": "built-in", "check": "bun" }, "github": { "kind": "command", "label": "GitHub CLI version", "command": "gh --version" } }, "values": { "APP_MODE": { "default": "development", "description": "Application mode" }, "PREVIEW_REPOSITORY": { "description": "Existing GitHub owner/repository to adopt" } }, "terminal": { "path": ["node_modules/.bin", ".gitspace/bin", "~/.cargo/bin"], "env": { "NODE_ENV": "development" } } }
| Field | Rules |
version | Must be 1 |
defaultProfile | Existing profile name; defaults to base |
profiles | Must include base |
Profile checks, secrets, values | Arrays; default to empty. A selected profile adds to base rather than replacing it |
Profile notes | Optional text, up to 2,000 characters |
checks | Named built-in or command checks. Referenced check IDs must exist |
values | Named non-secret values with optional default and description. Referenced value names must exist |
terminal | Optional. path and env for agent bash commands, declared services, and workspace terminals. See Terminal environment |
bun, gh, git, postgres, vercel, and node. They run bun --version, gh --version, git --version, pg_isready, vercel whoami, and node --version, respectively. A check name is not an installer. Optional built-in requirement text does not enforce a version constraint by itself. Use a command check when you need an exact assertion.kind: "command", a label, and a command. Checks need execution approval too; read their commands before running them.terminal section makes project tools available to the commands that run in a checkout: agent bash commands, services from .gitspace/services.json, and workspace terminals. Lifecycle scripts are unaffected. Once a project has an Environment revision, its Command environment replaces this section, even when the revision declares none.| Field | Rules |
path | Up to 64 directories. Each entry is checkout-relative, such as node_modules/.bin, or starts with ~/ for the machine user's home. Absolute paths, . or .. segments, empty segments, and : reject. Entries lead PATH in listed order, ahead of the inherited PATH; duplicates keep their first position |
env | Plain, non-secret string values. Names contain letters, digits, or underscores and do not start with a digit. PATH (use path), GITSPACE_* names, secret-like names, credential-looking values, and names declared in values or as profile secrets reject |
"path": ["node_modules/.bin"], a service can declare "command": "vite", and a bash command can run vite build without npx. Service env entries override terminal.env. Secrets keep using profiles and grants. If bundle.json is missing or invalid, commands still run with no additions.1234567891011121314151617.gitspace/ bundle.json lifecycle/ cloud/ provision/ 10-adopt.preview.sh destroy/ 10-delete.preview.sh machine/ prepare/ 10-tools.sh workspace/ materialize/ 10-dependencies.sh 20-config.preview.sh dematerialize/ 10-flush.sh
.profile suffix, and .sh. Examples: 10-tools.sh, 20-config.preview.sh..base.sh scripts run for every profile. A script suffixed with another declared profile runs only when that profile is selected. Unknown profiles and malformed filenames reject. Scripts sort by filename, not by numeric value: use equal-width prefixes such as 10, 20, and 30. Selected-profile scripts add to base scripts; they do not override a base file.| Phase | Successful-run identity |
cloud/provision | Durable workspace identity. A prior success skips later requests unless the user explicitly requests a rerun, even if the profile or script hashes changed |
machine/prepare | Account, project, verified machine, profile, and approved script hashes |
workspace/materialize | Workspace checkout generation and phase. Profile or script changes do not repeat a completed phase without an explicit rerun |
workspace/dematerialize | Workspace checkout generation and phase. Profile or script changes do not repeat a completed phase without an explicit rerun |
cloud/destroy | Explicit destruction request for the durable workspace's recorded resources |
checks is a run phase for bundle checks, not a script directory. setup, select, remove, and pre are not executable lifecycle aliases.machine/prepare, checks, and workspace/materialize scripts in that order, each step within 30 minutes. A step whose content isn't approved waits for approval. A failure is recorded and leaves the workspace accessible; inspect the step results.cloud/provision request runs approved machine/prepare, checks, cloud/provision, and workspace/materialize in that order, including for a local-only repository with no provisioning script. A failure stops later phases. An empty provisioning phase still records successful local-only setup. Creating or selecting a workspace runs nothing.cloud/destroy for its own workspace, non-interactively and with approved content only. It deletes only the resources that workspace recorded as its own. GitSpace refuses an agent's cloud/destroy on the project's base workspace. Every ended cloud/destroy run adds an entry to the workspace journal that names the recorded resources and the outcome.123456789#!/bin/bash # gitspace: interactive set -euo pipefail set +x aws configure mfa-login \ --profile staging-source \ --update-profile staging-session \ --duration-seconds 43200
AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE to protected, ignored workspace-local paths if credentials should not use the machine's default AWS files. Add the ignore rule before writing credentials.skipped: <script> needs a terminal; run setup from a terminal to execute it in the run output. Skipped scripts are not part of the run's claimed executions. Choose Run in terminal in Environment and confirm the approved effects to execute them. The entire phase then uses a protected terminal, including any unmarked scripts in that phase. An explicit phase request can also set interactive: true; retries with the same run ID must preserve that choice..env or provider credential file. Use restrictive permissions and ignored paths. Protected terminal handling is not a sandbox and does not make arbitrary secret output safe.cloud/destroy. The request requires its machineId; the cloud refuses a missing or unattached machine instead of choosing another runner.cloud/destroy clears the workspace's bindings, including each copy's: the next cloud/provision starts from none. The journal entry of that run keeps the list of what it deleted, and run logs remain available. A failed, cancelled, or interrupted destruction keeps the bindings needed to recover. To run cloud/destroy again after it succeeded, request it with rerun: true; without it the request is skipped.| Variable | Value |
GITSPACE_PROJECT_ID | Durable project ID |
GITSPACE_WORKSPACE_ID | Durable workspace ID; use this for resource identity rather than a machine path |
GITSPACE_MACHINE_ID | Authorized runner machine ID |
GITSPACE_WORKSPACE_GENERATION | Current checkout generation |
GITSPACE_ENVIRONMENT_PROFILE | Selected profile name |
GITSPACE_MACHINE_TOOLS | Private, stable machine tool directory; its bin directory takes precedence over tools on the inherited PATH in lifecycle scripts only. Agent commands, processes, services and terminals get neither the variable nor its bin |
GITSPACE_PLATFORM | The machine's operating system: linux or darwin |
GITSPACE_ARCH | The machine's architecture: x64 or arm64 |
GITSPACE_MACHINE_PLATFORM | The two joined, as the machine reports itself: linux-x64, linux-arm64, darwin-x64 or darwin-arm64. Agent commands, processes, services and terminals get the three platform variables too |
GITSPACE_SERVICE_URL_<NAME> | Workspace URL (https://…) of each http port of each service in .gitspace/services.json. <NAME> is the port's URL name upper-cased, other characters as _: GITSPACE_SERVICE_URL_WEB for service web's first http port, GITSPACE_SERVICE_URL_WEB_ADMIN for its port admin |
GITSPACE_SERVICE_URLS_JSON | The same URLs as a JSON object keyed by URL name ({"web":"https://…","web-admin":"https://…"}); {} without declared http ports |
GITSPACE_LIFECYCLE_INGRESS | cloud/provision and workspace/materialize only: where to write ingress.json (see Signed callers) |
.gitspace/services.json receive the same two URL variables, with GITSPACE_SERVICE_NAME, PORT, GITSPACE_PORTS_JSON, and GITSPACE_PORT_<NAME>. A URL is not a secret: only an approved browser or a signed caller gets through it.GITSPACE_LIFECYCLE_BINDINGS contains a JSON object of durable, non-secret resource bindings. Parse it as JSON; do not source or evaluate it as shell code.GITSPACE_LIFECYCLE_OUTPUT is a file path supplied by the runner. Write JSON in this form:123456{ "bindings": { "previewRepository": "example/preview-workspace", "previewRepositoryId": "123456789" } }
null, for example {"bindings": {"sourcePin": null}}. Keep the output file within 64 KiB. A resource created before its ID reaches the cloud still needs provider-side reconciliation after interruption.secret:NAME references. They are not a credential store. A secret reference names a secret; it does not turn the binding into the secret's plaintext value. Store it as a project secret or grant an account secret to the project, then declare the required name in the profile.secret:NAME reference. Private keys and URLs with embedded credentials reject. These checks catch common mistakes, not every possible secret.HOME, PATH, and ordinary environment. GitSpace prepends GITSPACE_MACHINE_TOOLS/bin to PATH; declared values and granted secrets override inherited values. Internal GITSPACE_* daemon bootstrap variables are excluded, and the runner supplies its own workspace metadata. Git uses the user's normal configuration; unattended runs disable its interactive prompting.PATH, HOME, USER, LOGNAME, SHELL, TMPDIR, TMP, TEMP, LANG, LC_ALL, TERM, TZ and XDG_* directories, GITSPACE_PROJECT_ID, GITSPACE_WORKSPACE_ID, the platform variables, and the project's Environment command path and variables. Services and terminals get the same over the machine's ordinary environment. None of them sees GITSPACE_MACHINE_TOOLS or has its bin on PATH: a tool a script installs there is for later lifecycle scripts.machine/prepare to install missing tools. Inheritance uses the daemon's environment; it does not search for tools outside its PATH or source login dotfiles. A cloud machine uses its own home, not a copy of your personal machine..sh files execute their approved bytes with /bin/bash, without login startup files. Command checks use /bin/sh. The working directory is the checkout root; $0 is the script's path in that checkout. Use $0, not BASH_SOURCE, when locating helpers beside an entry script.<service>--<workspace>--<account>-srv) only; machine URLs never admit them..gitspace/services.json routes are no longer read. A project without one declares them in .gitspace/services.json.ingress:123456789101112{ "services": [{ "name": "api", "command": "bun", "args": ["run", "start"], "ports": [{ "name": "http" }, { "name": "admin" }], "ingress": [ { "method": "POST", "path": "/webhooks/*" }, { "method": "GET", "path": "/status", "port": "admin" } ] }] }
| Field | Rules |
method | GET, POST, PUT, PATCH, DELETE, or * for any method. A WebSocket upgrade is a GET |
path | An exact path (/status) or a prefix ending in /* (/webhooks/* matches /webhooks/ and every path below it, not /webhooks; /* matches every path). No .., ., empty segments, other wildcards, query, or /__gitspace paths |
port | An http port of the service; defaults to its first. Each port is its own workspace URL |
tokens | true also admits the service's GitSpace-signed tokens on the route |
401 with {"error":"INGRESS_UNAUTHORIZED","reason":"…"}. A valid credential's header is removed and everything else (body, headers, query, WebSocket upgrades) reaches the service unchanged. Other paths on the same URL keep the browser sign-in.cloud/provision or workspace/materialize script registers credentials, by writing JSON to the path in GITSPACE_LIFECYCLE_INGRESS (ingress.json in the run's output directory):1234567{ "credentials": [ { "kind": "oidc", "service": "api", "issuer": "https://broker.example.com", "subjects": ["webhooks/stripe", "webhooks/*"] }, { "kind": "jwt", "service": "api", "port": "admin", "issuer": "status-poller", "keys": { "keys": [{ "kty": "OKP", "crv": "Ed25519", "x": "…" }] }, "subjects": ["poller"] }, { "kind": "bearer", "service": "api", "secret": "STRIPE_FORWARD_TOKEN" } ] }
http port with declared routes; the routes are approved) and replaces the workspace's registrations with it. A phase that writes no file leaves the credentials unchanged; when an approved route sets tokens: true, it still registers the routes. An invalid file or unapproved routes fail the run. GitSpace keeps registrations with the workspace URL, apart from the machine serving it, and ends them when the workspace is archived or deleted. Agents cannot register: the account accepts a registration only from the machine running that approved phase, for approved routes.| Kind | Checked |
oidc | A JWT signed by the issuer's keys. GitSpace reads <issuer>/.well-known/openid-configuration (its issuer must equal the registered one) and its jwks_uri, over HTTPS on a public DNS name (no IP addresses, localhost, or GitSpace hosts), within 5 seconds and 64 KiB, cached about 10 minutes and refetched for an unknown kid at most every 30 seconds |
jwt | The same JWT checks with the public keys given in keys (a JWKS; private key members reject) |
bearer | A static token equal to the named secret, which must be one of the profile's secrets. Only its SHA-256 leaves the machine. Rotating the secret and running the phase again keeps the previous token valid too, until the next rotation |
iss equal to the issuer, aud equal to the workspace URL (https://<service>--<workspace>--<account>-srv.gssh.dev), exp, iat at most 5 minutes old, and a sub matching one of subjects (* matches any characters). When present, htm must equal the request method and htu the request URL without query.Authorization: Bearer <token> or GitSpace-Ingress: <token>. Set "forwardAuthorization": true on an oidc or jwt credential when the service checks its own Authorization header; the caller then uses GitSpace-Ingress, and Authorization reaches the service. GitSpace counts admissions and refusals per workspace URL and keeps the last refusal's reason."tokens": true on the routes they may call. Once those routes are approved and a cloud/provision or workspace/materialize run registers them, GitSpace keeps a P-256 signing key for the workspace and service. The private key never leaves GitSpace's credential vault; a key signs for 7 days and the tokens it signed stay valid 8 hours more. Scripts' credentials never replace it.environment tool (token), from gitspace service token <service> --sub <subject> [--ttl 30m] [--refresh] [--port <name>] in a workspace terminal or agent command (prints JSON), or from Copy app token in Environment (with a QR code). A token is an ES256 JWT whose sub names the caller, valid 8 hours unless a shorter ttl is given. Send it as GitSpace-Ingress: <token>; the app's own Authorization reaches the service. It is accepted only on routes that set tokens: true, and refused once it expires, once it is revoked, or once its key is rotated out (Environment's Rotate now ends every earlier key at once).123curl -X POST https://api--<workspace>--<account>-srv.gssh.dev/__gitspace/token \ -H 'content-type: application/json' -d '{"refresh_token":"…"}' # {"access_token":"…","token_type":"Bearer","expires_in":28800,"refresh_token":"…"}
400 {"error":"invalid_grant"}. Environment lists the tokens issued for each service with their subject, expiry and last use; Revoke ends a token and its refresh chain.environment tool directly:1{ "args": { "method": "get" } }
get, setProfile, putValue, deleteValue, runChecks, runPhase, cancelRun, runLog, and token. Arguments go inside args; all operations target the current workspace. A run request supplies runId, optional deadlineAt, and a phase for runPhase. A log request supplies runId and optional offset. A token request supplies service, subject, and optional port, ttlSeconds, and refresh (see Service tokens). Agent calls cannot request protected interactive execution.rerun: true only for an explicitly authorized rerun. The agent surface runs noninteractively only, and refuses cloud/destroy on the project's base workspace. Content approval governs the runs GitSpace starts; an agent asked by the user to set up a workspace may run its scripts directly with bash.environment.runChecks({ spaceId, machineId, runId }) and environment.runPhase({ spaceId, machineId, runId, phase, rerun }) require an explicit attached machine ID. They accept the request in the cloud and dispatch only to the named ready or resumable cache. Keep the same machine ID and inputs when reconciling an existing run ID; attach a machine before requesting execution if none is available.lifecycle, the cloud-owned record of profile, values, approvals, automatic policy, execution definitions and content, bindings, last successful provision, destruction time, and phase runs. Saved script content lets the human inspect what a closed workspace would execute; do not embed secrets in it. Run status is accepted, running, cancelling, succeeded, failed, cancelled, timed-out, or interrupted. The run stores its machine, profile, hashes, interaction mode, timestamps, results, and safe output preview.exitCode: zero means success, a nonzero value means failure, and null means no exit was recorded. A started script with no exit is running while the phase is active and interrupted after the phase ends. A script with no result has not started. Available startedAt and finishedAt timestamps describe that script, not the whole phase.environment tool's runLog method accepts runId and optional offset. It returns output, nextOffset, and cursor. Follow nextOffset while more stored chunks are available. A null nextOffset means caught up for now, not necessarily that a running script has finished; retain cursor, the first unread stored row, and use it as the next request's offset after a run update. Read subsequent chunks rather than treating the preview as the full log..gitspace/bundle.json:123456{ "version": 1, "defaultProfile": "base", "profiles": { "base": { "checks": ["bun"] } }, "checks": { "bun": { "kind": "built-in", "check": "bun" } } }
.gitspace/lifecycle/workspace/materialize/10-dependencies.sh:123#!/usr/bin/env bash set -euo pipefail bun install --frozen-lockfile
machine/prepare script based on its existing CI installation method.preview profile that names GH_TOKEN in secrets and PREVIEW_REPOSITORY in values. Add the value definition under top-level values:123456789101112131415{ "version": 1, "defaultProfile": "preview", "profiles": { "base": { "checks": ["bun"] }, "preview": { "secrets": ["GH_TOKEN"], "values": ["PREVIEW_REPOSITORY"] } }, "checks": { "bun": { "kind": "built-in", "check": "bun" } }, "values": { "PREVIEW_REPOSITORY": { "description": "Existing GitHub owner/repository" } } }
PREVIEW_REPOSITORY to the existing owner/repository in Environment. Store a GitHub token with access to read that repository as the project secret GH_TOKEN. Do not paste the token into a value, binding, or script..gitspace/lifecycle/cloud/provision/10-adopt.preview.sh:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647#!/usr/bin/env bash set -euo pipefail bun - <<'JS' import { rename } from 'node:fs/promises'; const output = process.env.GITSPACE_LIFECYCLE_OUTPUT; const token = process.env.GH_TOKEN; if (!token || !output) throw new Error('Run through the approved lifecycle runner'); const previous = await Bun.file(output).json(); const bindings = { ...JSON.parse(process.env.GITSPACE_LIFECYCLE_BINDINGS || '{}'), ...previous.bindings, }; const configured = process.env.PREVIEW_REPOSITORY; const repository = bindings.previewRepository || configured; if (!repository || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository)) { throw new Error('Set PREVIEW_REPOSITORY to an existing owner/repository'); } if (bindings.previewRepository && configured && configured !== repository) { throw new Error('Configured repository differs from the recorded binding'); } const response = await fetch(`https://api.github.com/repos/${repository}`, { headers: { Accept: 'application/vnd.github+json', Authorization: `Bearer ${token}`, 'X-GitHub-Api-Version': '2022-11-28', 'User-Agent': 'gitspace-workspace-lifecycle', }, }); if (!response.ok) throw new Error(`Repository lookup failed: HTTP ${response.status}`); const resource = await response.json(); if (!Number.isSafeInteger(resource.id) || typeof resource.full_name !== 'string') { throw new Error('GitHub returned an invalid repository identity'); } if (bindings.previewRepositoryId && bindings.previewRepositoryId !== String(resource.id)) { throw new Error('Repository identity changed; inspect before recovery'); } const pendingOutput = `${output}.${crypto.randomUUID()}.tmp`; await Bun.write(pendingOutput, JSON.stringify({ bindings: { ...bindings, previewRepository: resource.full_name, previewRepositoryId: String(resource.id), }, })); await rename(pendingOutput, output); console.log(`Adopted repository ${resource.full_name} (${resource.id})`); JS
preview, approve the final script content, and separately authorize setup. Later materialization reads the saved bindings rather than adopting or creating resources again.cloud/destroy script here. Adoption records a resource reference, not permission to delete a shared resource. For a dedicated workspace-owned resource, write a separately reviewed destroy script that verifies the provider resource ID against the recorded binding and deletes only that resource. Never search by a broad name prefix and delete every match. Content approval of a destroy script lets the workspace's agent run it, so approve it only for resources the workspace owns.