Skip to content

Commit 322444f

Browse files
committed
Address review feedback on token CLI docs
1 parent 8ae3b0a commit 322444f

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

docs/authentication.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ uv run agent-memory token remove abc12345
8686
# Remove a token without confirmation
8787
uv run agent-memory token remove abc12345 --force
8888
```
89-
### CI / Terraform token bootstrapping
89+
### CI/Terraform token bootstrapping
9090

9191
You can use the token CLI to bootstrap authentication tokens in CI pipelines and infrastructure-as-code tools like Terraform.
9292

@@ -110,6 +110,21 @@ The example below generates a short-lived token during a workflow run and expose
110110
```
111111
112112
Later steps can use `AGENT_MEMORY_TOKEN` as the bearer token when calling the API.
113+
**JSON output format for `token add`**
114+
115+
When you use `--format json`, `agent-memory token add` returns a JSON object with fields like:
116+
117+
```json
118+
{
119+
"token": "the-plaintext-token",
120+
"hash": "abc12345def67890...",
121+
"description": "CI bootstrap token",
122+
"created_at": "2025-07-10T18:30:00.000000+00:00",
123+
"expires_at": "2025-08-09T18:30:00.000000+00:00"
124+
}
125+
```
126+
127+
You can extract any of these fields in your scripts (for example, `.token` or `.hash` with `jq`).
113128

114129
#### Terraform example (register a pre-generated token)
115130

@@ -121,22 +136,26 @@ variable "agent_memory_token" {
121136
sensitive = true
122137
}
123138
124-
resource "null_resource" "agent_memory_token" {
139+
resource "terraform_data" "agent_memory_token" {
125140
provisioner "local-exec" {
141+
environment = {
142+
AGENT_MEMORY_TOKEN = var.agent_memory_token
143+
}
144+
126145
command = <<EOT
127146
TOKEN_JSON=$(agent-memory token add \
128147
--description "Terraform bootstrap" \
129-
--token "${var.agent_memory_token}" \
148+
--token "$AGENT_MEMORY_TOKEN" \
130149
--format json)
131150
echo "$TOKEN_JSON" > agent-memory-token.json
132151
EOT
133152
}
134153
}
135154
```
136155

137-
In both cases, store the plaintext token in a secure secret store (GitHub Actions secrets, Terraform variables, Vault, etc.). The server will hash it before storing, and the CLI will only ever print the plaintext once.
138-
156+
For Terraform versions earlier than 1.4, you can use a `null_resource` instead of `terraform_data`.
139157

158+
In both cases, store the plaintext token in a secure secret store (GitHub Actions secrets, Terraform variables, Vault, etc.). The server will hash it before storing. When the CLI generates a token (without `--token`), it displays the plaintext only once; when using `--token` with a pre-generated value, ensure you've already stored it securely.
140159

141160
**Security Features:**
142161
- Tokens are hashed using bcrypt before storage

docs/cli.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ agent-memory token add --description "DESCRIPTION" [--expires-days DAYS] [--form
142142
- `--description TEXT` / `-d TEXT`: **Required**. Description for the token (e.g., "API access for service X")
143143
- `--expires-days INTEGER` / `-e INTEGER`: **Optional**. Number of days until token expires. If not specified, token never expires.
144144
- `--format [text|json]`: **Optional**. Output format. `text` (default) is human-readable; `json` is machine-readable and recommended for CI or scripting.
145-
- `--token TEXT`: **Optional**. Use a pre-generated token value instead of having the CLI generate one. The CLI will hash and store the token but only prints the plaintext once.
145+
- `--token TEXT`: **Optional**. Use a pre-generated token value instead of having the CLI generate one. The CLI will hash and store the provided token; make sure you've stored the plaintext securely in your secrets manager or CI system.
146146

147147
**Examples:**
148148

@@ -171,6 +171,25 @@ agent-memory token list [--format text|json]
171171
```
172172

173173
When `--format json` is used, the command prints a JSON array of token summaries suitable for scripting and CI pipelines. The default `text` format produces human-readable output like the example below.
174+
**JSON Output Example:**
175+
```json
176+
[
177+
{
178+
"hash": "abc12345def67890xyz",
179+
"description": "API access token",
180+
"created_at": "2025-07-10T18:30:00.000000+00:00",
181+
"expires_at": "2025-08-09T18:30:00.000000+00:00",
182+
"status": "Active"
183+
},
184+
{
185+
"hash": "def09876uvw54321...",
186+
"description": "Service account token",
187+
"created_at": "2025-07-10T19:00:00.000000+00:00",
188+
"expires_at": null,
189+
"status": "Never Expires"
190+
}
191+
]
192+
```
174193

175194
**Example Output:**
176195
```
@@ -197,6 +216,16 @@ agent-memory token show TOKEN_HASH [--format text|json]
197216
```
198217

199218
When `--format json` is used, the command prints a JSON object with token details (including status) suitable for scripting and CI pipelines. The default `text` format produces human-readable output.
219+
**JSON Output Example:**
220+
```json
221+
{
222+
"hash": "abc12345def67890xyz",
223+
"description": "API access token",
224+
"created_at": "2025-07-10T18:30:00.000000+00:00",
225+
"expires_at": "2025-08-09T18:30:00.000000+00:00",
226+
"status": "Active"
227+
}
228+
```
200229

201230
**Arguments:**
202231

0 commit comments

Comments
 (0)