@techwavedev/agi-agent-kit 1.1.7 → 1.2.1

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.

Potentially problematic release.


This version of @techwavedev/agi-agent-kit might be problematic. Click here for more details.

Files changed (111) hide show
  1. package/CHANGELOG.md +82 -1
  2. package/README.md +190 -12
  3. package/bin/init.js +30 -2
  4. package/package.json +6 -3
  5. package/templates/base/AGENTS.md +54 -23
  6. package/templates/base/README.md +325 -0
  7. package/templates/base/directives/memory_integration.md +95 -0
  8. package/templates/base/execution/memory_manager.py +309 -0
  9. package/templates/base/execution/session_boot.py +218 -0
  10. package/templates/base/execution/session_init.py +320 -0
  11. package/templates/base/skill-creator/SKILL_skillcreator.md +23 -36
  12. package/templates/base/skill-creator/scripts/init_skill.py +18 -135
  13. package/templates/skills/ec/README.md +31 -0
  14. package/templates/skills/ec/aws/SKILL.md +1020 -0
  15. package/templates/skills/ec/aws/defaults.yaml +13 -0
  16. package/templates/skills/ec/aws/references/common_patterns.md +80 -0
  17. package/templates/skills/ec/aws/references/mcp_servers.md +98 -0
  18. package/templates/skills/ec/aws-terraform/SKILL.md +349 -0
  19. package/templates/skills/ec/aws-terraform/references/best_practices.md +394 -0
  20. package/templates/skills/ec/aws-terraform/references/checkov_reference.md +337 -0
  21. package/templates/skills/ec/aws-terraform/scripts/configure_mcp.py +150 -0
  22. package/templates/skills/ec/confluent-kafka/SKILL.md +655 -0
  23. package/templates/skills/ec/confluent-kafka/references/ansible_playbooks.md +792 -0
  24. package/templates/skills/ec/confluent-kafka/references/ec_deployment.md +579 -0
  25. package/templates/skills/ec/confluent-kafka/references/kraft_migration.md +490 -0
  26. package/templates/skills/ec/confluent-kafka/references/troubleshooting.md +778 -0
  27. package/templates/skills/ec/confluent-kafka/references/upgrade_7x_to_8x.md +488 -0
  28. package/templates/skills/ec/confluent-kafka/scripts/kafka_health_check.py +435 -0
  29. package/templates/skills/ec/confluent-kafka/scripts/upgrade_preflight.py +568 -0
  30. package/templates/skills/ec/confluent-kafka/scripts/validate_config.py +455 -0
  31. package/templates/skills/ec/consul/SKILL.md +427 -0
  32. package/templates/skills/ec/consul/references/acl_setup.md +168 -0
  33. package/templates/skills/ec/consul/references/ha_config.md +196 -0
  34. package/templates/skills/ec/consul/references/troubleshooting.md +267 -0
  35. package/templates/skills/ec/consul/references/upgrades.md +213 -0
  36. package/templates/skills/ec/consul/scripts/consul_health_report.py +530 -0
  37. package/templates/skills/ec/consul/scripts/consul_status.py +264 -0
  38. package/templates/skills/ec/consul/scripts/generate_values.py +170 -0
  39. package/templates/skills/ec/documentation/SKILL.md +351 -0
  40. package/templates/skills/ec/documentation/references/best_practices.md +201 -0
  41. package/templates/skills/ec/documentation/scripts/analyze_code.py +307 -0
  42. package/templates/skills/ec/documentation/scripts/detect_changes.py +460 -0
  43. package/templates/skills/ec/documentation/scripts/generate_changelog.py +312 -0
  44. package/templates/skills/ec/documentation/scripts/sync_docs.py +272 -0
  45. package/templates/skills/ec/documentation/scripts/update_skill_docs.py +366 -0
  46. package/templates/skills/ec/gitlab/SKILL.md +529 -0
  47. package/templates/skills/ec/gitlab/references/agent_installation.md +416 -0
  48. package/templates/skills/ec/gitlab/references/api_reference.md +508 -0
  49. package/templates/skills/ec/gitlab/references/gitops_flux.md +465 -0
  50. package/templates/skills/ec/gitlab/references/troubleshooting.md +518 -0
  51. package/templates/skills/ec/gitlab/scripts/generate_agent_values.py +329 -0
  52. package/templates/skills/ec/gitlab/scripts/gitlab_agent_status.py +414 -0
  53. package/templates/skills/ec/jira/SKILL.md +484 -0
  54. package/templates/skills/ec/jira/references/jql_reference.md +148 -0
  55. package/templates/skills/ec/jira/scripts/add_comment.py +91 -0
  56. package/templates/skills/ec/jira/scripts/bulk_log_work.py +124 -0
  57. package/templates/skills/ec/jira/scripts/create_ticket.py +162 -0
  58. package/templates/skills/ec/jira/scripts/get_ticket.py +191 -0
  59. package/templates/skills/ec/jira/scripts/jira_client.py +383 -0
  60. package/templates/skills/ec/jira/scripts/log_work.py +154 -0
  61. package/templates/skills/ec/jira/scripts/search_tickets.py +104 -0
  62. package/templates/skills/ec/jira/scripts/update_comment.py +67 -0
  63. package/templates/skills/ec/jira/scripts/update_ticket.py +161 -0
  64. package/templates/skills/ec/karpenter/SKILL.md +301 -0
  65. package/templates/skills/ec/karpenter/references/ec2nodeclasses.md +421 -0
  66. package/templates/skills/ec/karpenter/references/migration.md +396 -0
  67. package/templates/skills/ec/karpenter/references/nodepools.md +400 -0
  68. package/templates/skills/ec/karpenter/references/troubleshooting.md +359 -0
  69. package/templates/skills/ec/karpenter/scripts/generate_ec2nodeclass.py +187 -0
  70. package/templates/skills/ec/karpenter/scripts/generate_nodepool.py +245 -0
  71. package/templates/skills/ec/karpenter/scripts/karpenter_status.py +359 -0
  72. package/templates/skills/ec/opensearch/SKILL.md +720 -0
  73. package/templates/skills/ec/opensearch/references/ml_neural_search.md +576 -0
  74. package/templates/skills/ec/opensearch/references/operator.md +532 -0
  75. package/templates/skills/ec/opensearch/references/query_dsl.md +532 -0
  76. package/templates/skills/ec/opensearch/scripts/configure_mcp.py +148 -0
  77. package/templates/skills/ec/victoriametrics/SKILL.md +598 -0
  78. package/templates/skills/ec/victoriametrics/references/kubernetes.md +531 -0
  79. package/templates/skills/ec/victoriametrics/references/prometheus_migration.md +333 -0
  80. package/templates/skills/ec/victoriametrics/references/troubleshooting.md +442 -0
  81. package/templates/skills/knowledge/SKILLS_CATALOG.md +274 -4
  82. package/templates/skills/knowledge/intelligent-routing/SKILL.md +237 -164
  83. package/templates/skills/knowledge/parallel-agents/SKILL.md +345 -73
  84. package/templates/skills/knowledge/plugin-discovery/SKILL.md +582 -0
  85. package/templates/skills/knowledge/plugin-discovery/scripts/platform_setup.py +1083 -0
  86. package/templates/skills/knowledge/design-md/README.md +0 -34
  87. package/templates/skills/knowledge/design-md/SKILL.md +0 -193
  88. package/templates/skills/knowledge/design-md/examples/DESIGN.md +0 -154
  89. package/templates/skills/knowledge/notebooklm-mcp/SKILL.md +0 -71
  90. package/templates/skills/knowledge/notebooklm-mcp/assets/example_asset.txt +0 -24
  91. package/templates/skills/knowledge/notebooklm-mcp/references/api_reference.md +0 -34
  92. package/templates/skills/knowledge/notebooklm-mcp/scripts/example.py +0 -19
  93. package/templates/skills/knowledge/react-components/README.md +0 -36
  94. package/templates/skills/knowledge/react-components/SKILL.md +0 -53
  95. package/templates/skills/knowledge/react-components/examples/gold-standard-card.tsx +0 -80
  96. package/templates/skills/knowledge/react-components/package-lock.json +0 -231
  97. package/templates/skills/knowledge/react-components/package.json +0 -16
  98. package/templates/skills/knowledge/react-components/resources/architecture-checklist.md +0 -15
  99. package/templates/skills/knowledge/react-components/resources/component-template.tsx +0 -37
  100. package/templates/skills/knowledge/react-components/resources/stitch-api-reference.md +0 -14
  101. package/templates/skills/knowledge/react-components/resources/style-guide.json +0 -27
  102. package/templates/skills/knowledge/react-components/scripts/fetch-stitch.sh +0 -30
  103. package/templates/skills/knowledge/react-components/scripts/validate.js +0 -68
  104. package/templates/skills/knowledge/self-update/SKILL.md +0 -60
  105. package/templates/skills/knowledge/self-update/scripts/update_kit.py +0 -103
  106. package/templates/skills/knowledge/stitch-loop/README.md +0 -54
  107. package/templates/skills/knowledge/stitch-loop/SKILL.md +0 -235
  108. package/templates/skills/knowledge/stitch-loop/examples/SITE.md +0 -73
  109. package/templates/skills/knowledge/stitch-loop/examples/next-prompt.md +0 -25
  110. package/templates/skills/knowledge/stitch-loop/resources/baton-schema.md +0 -61
  111. package/templates/skills/knowledge/stitch-loop/resources/site-template.md +0 -104
@@ -0,0 +1,508 @@
1
+ # GitLab API Reference
2
+
3
+ API endpoints for managing GitLab Kubernetes agents, tokens, and projects. All operations can be performed by project owners/maintainers — no GitLab admin access required.
4
+
5
+ ---
6
+
7
+ ## Authentication
8
+
9
+ All API requests require a Personal Access Token or Project Access Token:
10
+
11
+ ```bash
12
+ export GITLAB_HOST="gitlab.example.com"
13
+ export GITLAB_TOKEN="glpat-xxxxxxxxxxxxxxxxxxxx"
14
+
15
+ # Include in requests
16
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
17
+ "https://${GITLAB_HOST}/api/v4/..."
18
+ ```
19
+
20
+ ### Required Token Scopes
21
+
22
+ | Operation | Required Scopes |
23
+ | ---------------------- | ------------------- |
24
+ | List/view agents | `api` or `read_api` |
25
+ | Register/delete agents | `api` |
26
+ | Manage tokens | `api` |
27
+ | Project management | `api` |
28
+ | GitOps (Flux access) | `read_repository` |
29
+
30
+ ---
31
+
32
+ ## Kubernetes Agent API
33
+
34
+ ### List Agents for a Project
35
+
36
+ List all agents registered in a project.
37
+
38
+ **Minimum Role:** Developer
39
+
40
+ ```bash
41
+ GET /projects/:id/cluster_agents
42
+ ```
43
+
44
+ **Example:**
45
+
46
+ ```bash
47
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
48
+ "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/cluster_agents" | jq
49
+ ```
50
+
51
+ **Response:**
52
+
53
+ ```json
54
+ [
55
+ {
56
+ "id": 1,
57
+ "name": "eks-nonprod-agent",
58
+ "config_project": {
59
+ "id": 20,
60
+ "name": "kubernetes-agents",
61
+ "path_with_namespace": "infrastructure/kubernetes-agents"
62
+ },
63
+ "created_at": "2026-01-15T10:00:00.000Z",
64
+ "created_by_user_id": 42
65
+ }
66
+ ]
67
+ ```
68
+
69
+ ---
70
+
71
+ ### Get Agent Details
72
+
73
+ Get details of a specific agent.
74
+
75
+ **Minimum Role:** Developer
76
+
77
+ ```bash
78
+ GET /projects/:id/cluster_agents/:agent_id
79
+ ```
80
+
81
+ **Example:**
82
+
83
+ ```bash
84
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
85
+ "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}" | jq
86
+ ```
87
+
88
+ ---
89
+
90
+ ### Register an Agent
91
+
92
+ Register a new agent with the project.
93
+
94
+ **Minimum Role:** Maintainer
95
+
96
+ ```bash
97
+ POST /projects/:id/cluster_agents
98
+ ```
99
+
100
+ **Body:**
101
+
102
+ ```json
103
+ {
104
+ "name": "eks-nonprod-agent"
105
+ }
106
+ ```
107
+
108
+ **Example:**
109
+
110
+ ```bash
111
+ curl --request POST \
112
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
113
+ --header "Content-Type: application/json" \
114
+ --url "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/cluster_agents" \
115
+ --data '{"name":"eks-nonprod-agent"}' | jq
116
+ ```
117
+
118
+ **Response:**
119
+
120
+ ```json
121
+ {
122
+ "id": 1,
123
+ "name": "eks-nonprod-agent",
124
+ "config_project": {
125
+ "id": 20,
126
+ "name": "kubernetes-agents",
127
+ "path_with_namespace": "infrastructure/kubernetes-agents"
128
+ },
129
+ "created_at": "2026-01-21T12:00:00.000Z",
130
+ "created_by_user_id": 42
131
+ }
132
+ ```
133
+
134
+ **Next Step:** Create a token for the agent to actually connect.
135
+
136
+ ---
137
+
138
+ ### Delete an Agent
139
+
140
+ Delete an agent registration. This does NOT uninstall the agent from the cluster.
141
+
142
+ **Minimum Role:** Maintainer
143
+
144
+ ```bash
145
+ DELETE /projects/:id/cluster_agents/:agent_id
146
+ ```
147
+
148
+ **Example:**
149
+
150
+ ```bash
151
+ curl --request DELETE \
152
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
153
+ "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}"
154
+ ```
155
+
156
+ **Important:** After deleting from GitLab, also uninstall from cluster:
157
+
158
+ ```bash
159
+ helm uninstall gitlab-agent --namespace gitlab-agent
160
+ ```
161
+
162
+ ---
163
+
164
+ ## Agent Token API
165
+
166
+ ### List Tokens for an Agent
167
+
168
+ List all active tokens for an agent. Maximum 2 active tokens allowed.
169
+
170
+ **Minimum Role:** Developer
171
+
172
+ ```bash
173
+ GET /projects/:id/cluster_agents/:agent_id/tokens
174
+ ```
175
+
176
+ **Example:**
177
+
178
+ ```bash
179
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
180
+ "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}/tokens" | jq
181
+ ```
182
+
183
+ **Response:**
184
+
185
+ ```json
186
+ [
187
+ {
188
+ "id": 1,
189
+ "name": "initial-token",
190
+ "description": "Initial installation token",
191
+ "agent_id": 1,
192
+ "status": "active",
193
+ "created_at": "2026-01-21T12:00:00.000Z",
194
+ "created_by_user_id": 42
195
+ }
196
+ ]
197
+ ```
198
+
199
+ ---
200
+
201
+ ### Get Single Token
202
+
203
+ Get details of a specific token, including last used time.
204
+
205
+ **Minimum Role:** Developer
206
+
207
+ ```bash
208
+ GET /projects/:id/cluster_agents/:agent_id/tokens/:token_id
209
+ ```
210
+
211
+ **Example:**
212
+
213
+ ```bash
214
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
215
+ "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}/tokens/1" | jq
216
+ ```
217
+
218
+ **Response includes `last_used_at`:**
219
+
220
+ ```json
221
+ {
222
+ "id": 1,
223
+ "name": "initial-token",
224
+ "status": "active",
225
+ "last_used_at": "2026-01-21T12:30:00.000Z",
226
+ "created_at": "2026-01-21T12:00:00.000Z"
227
+ }
228
+ ```
229
+
230
+ ---
231
+
232
+ ### Create Agent Token
233
+
234
+ Create a new token for agent authentication. **The token value is only returned once — save it immediately!**
235
+
236
+ **Minimum Role:** Maintainer
237
+
238
+ **Limit:** Maximum 2 active tokens per agent.
239
+
240
+ ```bash
241
+ POST /projects/:id/cluster_agents/:agent_id/tokens
242
+ ```
243
+
244
+ **Body:**
245
+
246
+ ```json
247
+ {
248
+ "name": "token-name",
249
+ "description": "optional description"
250
+ }
251
+ ```
252
+
253
+ **Example:**
254
+
255
+ ```bash
256
+ TOKEN_RESPONSE=$(curl --silent --request POST \
257
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
258
+ --header "Content-Type: application/json" \
259
+ --url "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}/tokens" \
260
+ --data '{"name":"install-token","description":"EKS installation"}')
261
+
262
+ echo $TOKEN_RESPONSE | jq
263
+
264
+ # Extract token value (SAVE THIS!)
265
+ AGENT_TOKEN=$(echo $TOKEN_RESPONSE | jq -r '.token')
266
+ echo "Agent Token: ${AGENT_TOKEN}"
267
+ ```
268
+
269
+ **Response:**
270
+
271
+ ```json
272
+ {
273
+ "id": 2,
274
+ "name": "install-token",
275
+ "description": "EKS installation",
276
+ "agent_id": 1,
277
+ "status": "active",
278
+ "created_at": "2026-01-21T12:00:00.000Z",
279
+ "created_by_user_id": 42,
280
+ "last_used_at": null,
281
+ "token": "glagent-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
282
+ }
283
+ ```
284
+
285
+ ---
286
+
287
+ ### Revoke Token
288
+
289
+ Revoke (delete) a token. The agent will disconnect if this was its active token.
290
+
291
+ **Minimum Role:** Maintainer
292
+
293
+ ```bash
294
+ DELETE /projects/:id/cluster_agents/:agent_id/tokens/:token_id
295
+ ```
296
+
297
+ **Example:**
298
+
299
+ ```bash
300
+ curl --request DELETE \
301
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
302
+ "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}/tokens/1"
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Project API
308
+
309
+ ### Get Project ID
310
+
311
+ Find project ID by path.
312
+
313
+ ```bash
314
+ # URL-encode the path (replace / with %2F)
315
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
316
+ "https://${GITLAB_HOST}/api/v4/projects/infrastructure%2Fkubernetes-agents" | jq '.id'
317
+ ```
318
+
319
+ Or search by name:
320
+
321
+ ```bash
322
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
323
+ "https://${GITLAB_HOST}/api/v4/projects?search=kubernetes-agents" | jq '.[].id'
324
+ ```
325
+
326
+ ---
327
+
328
+ ### List Projects
329
+
330
+ List projects you have access to.
331
+
332
+ ```bash
333
+ GET /projects
334
+ ```
335
+
336
+ **Useful parameters:**
337
+
338
+ | Parameter | Description |
339
+ | ------------ | -------------------------------------- |
340
+ | `search` | Search by name |
341
+ | `owned` | Only your projects |
342
+ | `membership` | Projects you're a member of |
343
+ | `per_page` | Results per page (default 20, max 100) |
344
+
345
+ **Example:**
346
+
347
+ ```bash
348
+ # List projects you own
349
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
350
+ "https://${GITLAB_HOST}/api/v4/projects?owned=true" | jq '.[].path_with_namespace'
351
+ ```
352
+
353
+ ---
354
+
355
+ ### Get Project Details
356
+
357
+ ```bash
358
+ GET /projects/:id
359
+ ```
360
+
361
+ **Example:**
362
+
363
+ ```bash
364
+ curl --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
365
+ "https://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}" | jq
366
+ ```
367
+
368
+ ---
369
+
370
+ ## Helper Scripts
371
+
372
+ ### Full Agent Setup Script
373
+
374
+ Complete script based on API (project owner perspective):
375
+
376
+ ```bash
377
+ #!/bin/bash
378
+ # gitlab-agent-setup.sh - Register agent and create token via API
379
+
380
+ set -e
381
+
382
+ # Configuration
383
+ GITLAB_HOST="${GITLAB_HOST:-gitlab.example.com}"
384
+ PROJECT_ID="${PROJECT_ID:-}"
385
+ AGENT_NAME="${AGENT_NAME:-eks-agent}"
386
+
387
+ # Validate inputs
388
+ if [ -z "$GITLAB_TOKEN" ]; then
389
+ echo "Error: GITLAB_TOKEN must be set"
390
+ exit 1
391
+ fi
392
+
393
+ if [ -z "$PROJECT_ID" ]; then
394
+ echo "Error: PROJECT_ID must be set"
395
+ exit 1
396
+ fi
397
+
398
+ API_URL="https://${GITLAB_HOST}/api/v4"
399
+
400
+ echo "=== Registering agent '${AGENT_NAME}' ==="
401
+
402
+ # Register agent
403
+ AGENT_RESPONSE=$(curl --silent --fail \
404
+ --request POST \
405
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
406
+ --header "Content-Type: application/json" \
407
+ --url "${API_URL}/projects/${PROJECT_ID}/cluster_agents" \
408
+ --data "{\"name\":\"${AGENT_NAME}\"}")
409
+
410
+ AGENT_ID=$(echo $AGENT_RESPONSE | jq -r '.id')
411
+ echo "Agent ID: ${AGENT_ID}"
412
+
413
+ echo "=== Creating agent token ==="
414
+
415
+ # Create token
416
+ TOKEN_RESPONSE=$(curl --silent --fail \
417
+ --request POST \
418
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
419
+ --header "Content-Type: application/json" \
420
+ --url "${API_URL}/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}/tokens" \
421
+ --data '{"name":"install-token","description":"Installation token"}')
422
+
423
+ AGENT_TOKEN=$(echo $TOKEN_RESPONSE | jq -r '.token')
424
+ echo "Agent Token: ${AGENT_TOKEN}"
425
+
426
+ echo ""
427
+ echo "=== Next Steps ==="
428
+ echo "1. Save this token securely (it cannot be retrieved again)"
429
+ echo "2. Install agent on EKS cluster:"
430
+ echo ""
431
+ echo "helm repo add gitlab https://charts.gitlab.io"
432
+ echo "helm repo update"
433
+ echo "helm upgrade --install gitlab-agent gitlab/gitlab-agent \\"
434
+ echo " --namespace gitlab-agent \\"
435
+ echo " --create-namespace \\"
436
+ echo " --set config.token=\"${AGENT_TOKEN}\" \\"
437
+ echo " --set config.kasAddress=\"wss://${GITLAB_HOST}/-/kubernetes-agent/\""
438
+ ```
439
+
440
+ ### Token Rotation Script
441
+
442
+ ```bash
443
+ #!/bin/bash
444
+ # rotate-agent-token.sh - Rotate agent token with zero downtime
445
+
446
+ set -e
447
+
448
+ # Configuration
449
+ GITLAB_HOST="${GITLAB_HOST:-gitlab.example.com}"
450
+ PROJECT_ID="${PROJECT_ID:-}"
451
+ AGENT_ID="${AGENT_ID:-}"
452
+
453
+ API_URL="https://${GITLAB_HOST}/api/v4"
454
+
455
+ echo "=== Creating new token ==="
456
+ TOKEN_RESPONSE=$(curl --silent --fail \
457
+ --request POST \
458
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
459
+ --header "Content-Type: application/json" \
460
+ --url "${API_URL}/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}/tokens" \
461
+ --data "{\"name\":\"rotation-$(date +%Y%m%d)\",\"description\":\"Token rotation\"}")
462
+
463
+ NEW_TOKEN=$(echo $TOKEN_RESPONSE | jq -r '.token')
464
+ echo "New token created"
465
+
466
+ echo "=== Updating agent deployment ==="
467
+ helm upgrade gitlab-agent gitlab/gitlab-agent \
468
+ --namespace gitlab-agent \
469
+ --reuse-values \
470
+ --set config.token="${NEW_TOKEN}"
471
+
472
+ echo "=== Waiting for rollout ==="
473
+ kubectl rollout status deployment/gitlab-agent -n gitlab-agent
474
+
475
+ echo "=== Listing old tokens ==="
476
+ curl --silent \
477
+ --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" \
478
+ "${API_URL}/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}/tokens" | \
479
+ jq '.[] | select(.name != "rotation-'$(date +%Y%m%d)'") | {id, name}'
480
+
481
+ echo ""
482
+ echo "Manually revoke old tokens with:"
483
+ echo "curl --request DELETE --header \"PRIVATE-TOKEN: \${GITLAB_TOKEN}\" \\"
484
+ echo " \"${API_URL}/projects/${PROJECT_ID}/cluster_agents/${AGENT_ID}/tokens/OLD_TOKEN_ID\""
485
+ ```
486
+
487
+ ---
488
+
489
+ ## Error Handling
490
+
491
+ ### Common API Errors
492
+
493
+ | HTTP Code | Meaning | Solution |
494
+ | --------- | ----------------- | -------------------------------------- |
495
+ | 401 | Unauthorized | Check token is valid and not expired |
496
+ | 403 | Forbidden | Need higher role (e.g., Maintainer) |
497
+ | 404 | Not found | Check project/agent ID exists |
498
+ | 422 | Validation failed | Check request body (e.g., token limit) |
499
+
500
+ ### Token Limit Error
501
+
502
+ ```json
503
+ {
504
+ "message": "An agent can have at most 2 active tokens"
505
+ }
506
+ ```
507
+
508
+ **Solution:** Revoke an existing token before creating a new one.