# Gravity Keep — AI Reference

> **Status:** Draft 0.2, 2026-11-23. The condensed method for describing and changing AWS infrastructure with Gravity Keep. Read it with the [Gravity Standard AI Reference](https://gravitystandard.com/gravity-standard.md), which it builds on and never overrides. Where this summary and the full documents differ, the full documents win.

## 0. How to use this reference

You are helping a person describe AWS infrastructure as a Gravity Keep tree, or change it through commits.

- Follow every CTL rule below and every rule in the Gravity Standard reference. If they appear to conflict, the Standard wins and you raise the conflict with a person.
- You may write candidate configuration, run `commit check`, and explain plans. A person (or a pipeline loading a Git source) commits.
- Before proposing a change, check the namespace's source (`show sources`). Beneath a Git source, write the change as an edit to its file for a pull request, never as session commands (CTL-052).
- **Never** propose an expression, loop, or conditional in configuration (CTL-018). Use a template parameter, a second template, or an explicit namespace.
- **Never** suggest weakening a guardrail beneath it, acknowledging a destructive change the person hasn't seen, or using a hold to make a permanent change. A hold is for emergencies, and the change it allows is reverted when it ends unless committed.
- When a plan contains `replace` or `delete` of a stateful or identity-bearing resource, say so first, in plain words, before anything else, including that holders outside the tree can't be found.
- **Never** write a secret value into configuration. Prefer AWS-managed secrets (`manage-master-user-password`), else a secret reference.
- Bring existing resources in with `adopt` or a narrowed `explore`; take them out with `evict` (never by deleting from the tree unless deletion is meant).
- Mark properties AWS owns after creation (desired counts, scaled capacity) with `create { }`, preferably in the template.
- Roll out a new guardrail as `guardrails audit` first, and take a high-tree default to dev first, then `promote` it.

## 1. What it is

An AWS-native control plane configured like a Junos device: edit a candidate, `commit check`, `commit`, and reactors keep AWS matching the committed tree. A proposed alternative to Terraform for Gravity Standard companies.

**Central idea:** the committed configuration is the mass; anything that strays from it is pulled back. The commit is atomic; convergence is eventual and recorded. Events are hints; state is compared.

**What it is not:** multi-cloud; a programming environment; a deployment pipeline; a substitute for SCPs; a backup system.

## 2. Glossary

| Term | Meaning |
|---|---|
| Tree | The whole configuration: namespaces (branches) holding resources (leaves) and statements |
| Namespace | Company-named branch; path `/tidewater/lending/prod`; no dots in names |
| Resource | `resource <type> <name> { ... }`; path `<namespace>/<type>/<name>` |
| Type | CloudFormation registry type by derived alias: `AWS::EC2::SecurityGroup` → `ec2.security-group`; properties in kebab-case |
| Placement | `organization`, `account`, `region`, `zone` (AZ ID), inherited |
| Scope | global, regional, zonal, or organization: what placement a type needs |
| Defaults / guardrails | Overridable fill-ins / non-weakenable requirements, per type or for tags and placement |
| Lifecycle phases | `create { }`: applied at creation or replacement only; ordinary statements: maintained and held; `destroy { }`: `deletion retain|snapshot|delete` and the type's destroy values, used only at deletion. Separate from where a value comes from |
| Audit guardrail | `guardrails audit { }`: same forms, never fails or changes anything; violations are findings; made real by a commit |
| Reach | The namespaces whose resolved configuration a commit changes, counted by environment; review and confirmation follow reach |
| Template / apply | Versioned parameterized bundle / its use at a namespace |
| Reference | `@<path>:<attribute>`, or `:<list>[<key>].<field>`; the only dependency mechanism; waits for the target to be stable unless the attribute is early |
| Type table | Per type: scope, stateful, runner (Cloud Control or hand-written), converging limit, typical duration, early attributes, list keys |
| Source | Where a namespace is written: the control plane (default) or one Git file on one branch; declared by the parent; covers the subtree |
| Binding | Ties a namespace to an application and environment; adds tags; production is reviewed by default. Not a permit check |
| Policy | `ownership` (owned/learning/observed), `learn` (area filters), `drift` (remediate/report), `commit mode` (direct/reviewed), `commit confirmed required [types] minutes n` (automatic for session commits and requests), `protect`, `deletion` (retain/snapshot/delete), `ownership` (owned/observed) |
| Candidate | A session's private edits against a base commit |
| Commit | Atomic, numbered, immutable change to the active configuration |
| Convergence | Making AWS match the active configuration, asynchronously after the commit |
| State | `stable`, `converging`, `drifted` (won't be corrected without a person), `failed`, `unknown`, with a reason; namespaces show the worst beneath |
| Drift | A managed property whose observed value differs from its resolved value |
| Hold | Time-limited, recorded suspension of remediation beneath a path; warns before ending; `extend` within `policy hold maximum/total`; `capture` turns held changes into a commit by the namespace's route |
| Adoption | Bringing an existing resource into the tree without changing it |

## 3. Value resolution (CTL-013)

Template body → defaults from root down (nearest wins) → the resource's own statements → fixed-value guardrails (conflict is an error). Then every guardrail is checked. Tags merge key by key. Always added: `managed-by gravity-keep`, `gravity-path <namespace path>`, plus binding tags `application`, `environment`, `data-classification`. Only stated (or defaulted, guarded, templated) properties are managed (CTL-011).

## 4. The rules

### Tree
- **CTL-001:** Namespace names: lower-case letters, digits, hyphens; start with a letter; ≤ 40 characters; never a dot.
- **CTL-002:** One tree per control plane; every managed resource has exactly one path.
- **CTL-003:** The company names the top; fixed vocabulary only inside a namespace.
- **CTL-004:** Behavior comes from statements, never from names.
- **CTL-005:** Namespaces hold only namespaces, resources, and the fixed vocabulary; empty ones are removed.
- **CTL-006:** Moving or renaming a namespace never replaces a resource.

### Placement
- **CTL-007:** Placement is inherited until set again.
- **CTL-008:** Placement resolves to what the type's scope needs, or commit check fails.
- **CTL-009:** Zones are AZ IDs, never names.

### Resources and types
- **CTL-010:** Types are registry types by derived alias; names are derived from the schema.
- **CTL-011:** Only managed properties can drift, down to nested sub-properties.
- **CTL-066:** Statements are create (`create { }`, applied at create or replace only), maintain (ordinary, held), or destroy (`destroy { }`, used only at deletion); `create` never in or under guardrails.
- **CTL-070:** Destroy values are never compared; `destroy` overrides `policy deletion`; guardrails may restrict it; deletion follows the last commit that held the resource.
- **CTL-071:** Inherited create-only values apply only to new resources; never replace existing ones.
- **CTL-067:** Compare only after the type table's normaliser (`json`, `set`, `arn-or-name`, `version-prefix`, `case-insensitive`, `numeric`).
- **CTL-068:** Secrets only by reference, read at call time; never in tree, store, Git, plans, or logs.
- **CTL-069:** Write-only properties are compared with a hash of what was last sent.

### Defaults and guardrails
- **CTL-012:** A default applies only where nothing nearer set the property.
- **CTL-013:** Resolution order as in section 3, and every value's source can be shown.
- **CTL-014:** Nothing beneath a guardrail may weaken it.
- **CTL-015:** `managed-by` and `gravity-path` tags are always present.
- **CTL-016:** Boundaries that must hold outside Gravity Keep are also SCPs in the tree.
- **CTL-072:** Audit guardrails never block or change; violations are findings; made real only by commit.

### Templates and references
- **CTL-017:** Templates are referenced by Terraform-syntax version constraint (`"1.2.3"`, `"~> 1.0"`, `"~> 1.2.0"`, `">= 1.2, < 1.5"`), never copied.
- **CTL-065:** Ranges resolve to the newest match only at a commit that changes the applying namespace, or `update templates`; versions and digests are recorded; rollback and revert restore them; a changed digest fails.
- **CTL-018:** Templates substitute typed parameters only; no loops, conditionals, functions.
- **CTL-019:** Template resources appear at ordinary paths, and their origin can be shown.
- **CTL-020:** References resolve within the tree, are the only dependencies, and can't cycle.
- **CTL-063:** A reference waits for its target to be `stable`, except early attributes (type table), which wait only until known; list entries by key, never position.

### Candidate and commit
- **CTL-021:** Conflicts with newer commits are named, never overwritten.
- **CTL-022:** A commit runs all of commit check; failing configuration is never committed.
- **CTL-023:** The active configuration changes only by commit.
- **CTL-024:** Commits are atomic, numbered, immutable, and fully recorded.
- **CTL-027:** Session commits and commit requests are `commit confirmed` when asked or when policy lists a type in the plan; Git loads never are. Unconfirmed or failed ones are reverted by a new commit.
- **CTL-028:** Destructive changes need an acknowledgment matching the plan, and never go under `commit confirmed`.
- **CTL-074:** Destructive = deleting or replacing a stateful type (data, or hosted zones and Elastic IPs) or an identity-bearing type (IAM role unique ID, security group ID, generated domain names).
- **CTL-058:** `request revert` restores the configuration before one commit beneath its paths, refused if a later commit touched them; granted as `revert`; alarmed.

### Convergence
- **CTL-025:** Converge toward the latest active configuration; recompute each action from current state.
- **CTL-026:** Retries are bounded; then failed, with an alarm.
- **CTL-059:** One AWS request in flight per resource; newer actions wait, then recompute.
- **CTL-060:** Five resource states with reasons; namespaces roll up worst-first: unknown, failed, drifted, converging, stable.
- **CTL-062:** A wait succeeds only on `stable`; `drifted` and `unknown` never count.
- **CTL-064:** Each type has a converging limit; past it, the resource is `failed`.

### Drift
- **CTL-030:** Events say where to look; reactors read state; a sweep reads every managed resource.
- **CTL-031:** A missing stateful resource is reported, never recreated automatically.
- **CTL-032:** More than three corrections in an hour stops remediation on that resource and alarms.
- **CTL-033:** Holds are scoped, reasoned, warned before ending, extended only within policy totals, and recorded; expiry pulls back only what wasn't committed.
- **CTL-075:** A held change stays only by committing it (capture or by hand) through the namespace's route; a hold with nothing left ends itself.
- **CTL-061:** Every drift is recorded; drift being corrected shows `converging`; `drifted` means it won't be corrected without a person.

### Ownership and deletion
- **CTL-029:** Rollback is a new commit that names any data it can't restore.
- **CTL-034:** Every resource of an inventoried type is in the tree or listed unmanaged; uncovered types are listed.
- **CTL-076:** What exists comes from an inventory source (Resource Explorer by default), at least daily; managed reads stay with Cloud Control.
- **CTL-077:** `ownership learning` writes outside-commit creates, changes, and deletes into the tree, crediting CloudTrail's identity; areas never overlap; never beneath a Git source.
- **CTL-078:** `evict` removes resources from the tree and untags them; it never deletes.
- **CTL-079:** Adopt and explore only fill a candidate; explore needs a narrowing filter or `all`.
- **CTL-035:** Unmanaged resources are never changed; adopting commits change only tags.
- **CTL-047:** Stateful resources are retained when removed unless policy says otherwise; KMS key deletion is always scheduled.
- **CTL-048:** Protected namespaces and resources can't be deleted, moved, or renamed until a separate commit unprotects them.
- **CTL-049:** Observed-ownership resources are compared and reported, never changed.

### Access, governance, audit
- **CTL-036:** Rights go to directory groups, enforced by Verified Permissions.
- **CTL-037:** *Retired.* Gravity Keep doesn't check development permits; pipelines that use them check them before committing.
- **CTL-073:** Review and confirmation follow reach: every namespace whose resolved configuration changes; reaching a reviewed namespace from above needs a second person.
- **CTL-038:** Reviewed namespaces accept only their Git source or, when sourced in the control plane, a second person's approval; never self-approval.
- **CTL-039:** Every change has exactly one author, and names whom it acts for.
- **CTL-040:** History is kept at least as long as the longest bound retention, and never edited.

### Sources
- **CTL-050:** One source per namespace, control plane or one Git file, covering its subtree.
- **CTL-051:** The parent declares a source; a source file never contains `source`.
- **CTL-052:** Beneath a Git source only `load source` changes configuration; session edits, other loads, commit requests, rollback, and `ownership learning` are refused.
- **CTL-053:** Loads only move forward: on the declared branch, descending from the last commit loaded or written.
- **CTL-054:** The control plane writes to Git only to record a `request revert`; a failed write leaves the namespace out of step until a person loads with acknowledgment.
- **CTL-057:** The control plane's own namespace (pipeline roles, source connector) is always sourced in the control plane.
- **CTL-055:** Declaring or removing a source is a commit at the parent; declaring needs a file that matches; removing alarms.
- **CTL-056:** Every commit is copied outside the control plane, and an export is never loaded.

### Sessions and the control plane
- **CTL-041:** Candidates are stored server-side and survive disconnection.
- **CTL-042:** The CLI uses the same API as pipelines; there is no bypass.
- **CTL-043:** Operational commands change nothing except recorded `request`s.
- **CTL-044:** The control plane's own namespace is protected, reviewed, and commit-confirmed.
- **CTL-045:** Per-account roles, assumed per action, generated least privilege; no long-lived credentials.
- **CTL-046:** Unreadable accounts are `unknown`, never assumed stable, and alarm.

## 5. Commands

**Operational (`user@cp>`):** `configure [exclusive <path>]`, `show configuration|commits|commit <n>|status|resource|observed|drift|unmanaged|retained|findings|sources|holds|requests|sessions|events|templates|types|type`, `monitor commit|drift`, `wait commit <n>|<path> [timeout]`, `request reconcile|hold|hold extend|hold capture|hold release|remediation resume|revert commit|commit approve|commit reject`.

**Configuration (`user@cp#`, with `[edit <level>]`):** `edit`, `up`, `top`, `exit`, `set`, `delete`, `deactivate`, `activate`, `rename`, `move`, `copy`, `annotate`, `protect`, `unprotect`, `apply`, `adopt`, `explore`, `evict`, `set source|delete source`, `load source|merge|replace|set|candidate`, `update`, `update templates`, `promote`, `show`, `commit check`, `commit [comment]`, `commit confirmed <m>`, `commit acknowledge destructive <n>`, `commit request [confirmed <m>]`, `commit and-quit`, `commit and-wait`, `rollback <n>|commit <n>`, `status`, `run <op>`.

**Pipes:** `| compare [rollback n | commit n]`, `| display set|status|inheritance|templates|json|cloudformation`, `| match`, `| except`, `| count`, `| last`, `| no-more`, `| save`.

## 6. Syntax

```
namespace tidewater {
    placement { organization o-tw7exampl3; region us-east-2; }
    guardrails { s3.bucket { bucket-encryption required; } tags { owner required; } }
    defaults { tags { cost-center 4100; } }
    namespace lending {
        binding { application lending; data-classification restricted; }
        namespace prod {
            placement { account 111100000021; }
            binding { environment production; }
            policy { commit mode reviewed; }
            resource s3.bucket documents {
                bucket-name tidewater-lending-prod-documents;
                versioning-configuration { status Enabled; }
            }
            namespace intake {
                apply gs-lambda { version "~> 1.3.0"; memory 1024; log-key @/tidewater/foundation/prod/kms.key/logs; ... }
            }
        }
    }
}
```

Set form: `set /tidewater/lending/prod resource s3.bucket documents versioning-configuration status Enabled`. Repeated blocks are lists of objects; `[ a b ]` is a list of scalars.

## 7. How an AI assistant works with Gravity Keep

1. **Find the right level.** Put a setting at the highest namespace where it is true for everything beneath. Don't repeat what a default or guardrail already supplies; check with `| display inheritance`.
2. **Prefer templates** from the published library over hand-written resources for anything the Standard has a module for.
3. **Write references, not literals,** for anything in the tree (ARNs, IDs, account IDs).
4. **Run `commit check`** and read the plan to the person: destructive lines first, then reach, creates, updates, retains, drift, and review requirements.
5. **Choose the route:** a pull request to the file beneath a Git source; otherwise direct commit in direct namespaces, or `commit request` beneath `commit mode reviewed`; `commit confirmed` (or `commit request confirmed`) for access-affecting types, which policy usually applies automatically. Never for Git loads: a bad Git change is undone with `request revert`.
6. **Adopt before changing.** An existing resource is adopted as it is, then changed in a separate commit.
7. **Never restate the Standard's platform rules** in a namespace that already inherits them.

## 8. Relationship to the Gravity Standard

- Gravity Keep is itself a Standard application (`keep`) with its own permits to run. It doesn't check other applications' permits; their pipelines do, before committing.
- Its templates mirror, and for a company that adopts it replace, the Standard's Terraform modules (`gs-lambda`, `gs-application-stack`, `gs-process`, `gs-observability`, `gs-database-role`).
- The dependency runs one way: Gravity Keep refers to the Standard; the Standard never refers to Gravity Keep. **Never** propose changing the Standard for Gravity Keep's sake.
- The Standard specifies Terraform. Adoption runs Observe (report only, `ownership observed`) → Own (per-application `DESIGN-nnn`, production via a Git source or approved commit requests, every commit copied outside the control plane) → Replace (a company-wide `DESIGN-nnn`; the Standard is unchanged).

## 9. Reference company: Tidewater

Accounts: management 111100000001, gravity-keep 111100000002, foundation-prod 111100000010, lending-dev 111100000020, lending-prod 111100000021, payments-prod 111100000031, support-prod 111100000041, sandbox 111100000090. Regions us-east-2 (primary) and us-west-2 (recovery). Full tree and eight worked sessions in `samples/`. All numbers and names are invented.
