@a5c-ai/krate 5.0.1-staging.f672fe79b

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.
Files changed (174) hide show
  1. package/Dockerfile +29 -0
  2. package/README.md +183 -0
  3. package/bin/krate-demo.mjs +23 -0
  4. package/bin/krate-server.mjs +14 -0
  5. package/dist/krate-controller-ui.json +2407 -0
  6. package/dist/krate-lifecycle.json +201 -0
  7. package/dist/krate-runtime-snapshot.json +2955 -0
  8. package/dist/krate-summary.json +687 -0
  9. package/docs/README.md +61 -0
  10. package/docs/agents/README.md +83 -0
  11. package/docs/agents/acceptance-test-matrix.md +193 -0
  12. package/docs/agents/agent-mux-adapter-contract.md +167 -0
  13. package/docs/agents/agent-mux-source-map.md +310 -0
  14. package/docs/agents/agent-run-memory-import-spec.md +256 -0
  15. package/docs/agents/agent-stack-management-spec.md +421 -0
  16. package/docs/agents/api-contract-spec.md +309 -0
  17. package/docs/agents/artifacts-writeback-spec.md +145 -0
  18. package/docs/agents/chart-packaging-spec.md +128 -0
  19. package/docs/agents/ci-orchestration-spec.md +140 -0
  20. package/docs/agents/context-assembly-spec.md +219 -0
  21. package/docs/agents/controller-reconciliation-spec.md +255 -0
  22. package/docs/agents/crd-schema-spec.md +315 -0
  23. package/docs/agents/decision-log-open-questions.md +169 -0
  24. package/docs/agents/developer-implementation-checklist.md +329 -0
  25. package/docs/agents/dispatching-design.md +262 -0
  26. package/docs/agents/glossary.md +66 -0
  27. package/docs/agents/implementation-blueprint.md +324 -0
  28. package/docs/agents/implementation-rollout-slices.md +251 -0
  29. package/docs/agents/memory-context-integration-spec.md +194 -0
  30. package/docs/agents/memory-ontology-schema-spec.md +253 -0
  31. package/docs/agents/memory-operations-runbook.md +121 -0
  32. package/docs/agents/mvp-vertical-slice-spec.md +146 -0
  33. package/docs/agents/observability-audit-spec.md +265 -0
  34. package/docs/agents/operator-runbook.md +174 -0
  35. package/docs/agents/org-memory-api-payload-examples.md +333 -0
  36. package/docs/agents/org-memory-controller-sequence-spec.md +181 -0
  37. package/docs/agents/org-memory-e2e-fixture-plan.md +161 -0
  38. package/docs/agents/org-memory-ui-implementation-map.md +114 -0
  39. package/docs/agents/org-memory-vertical-slice-spec.md +168 -0
  40. package/docs/agents/org-resource-model-delta-spec.md +111 -0
  41. package/docs/agents/org-route-resource-model-spec.md +183 -0
  42. package/docs/agents/org-scoping-namespace-spec.md +114 -0
  43. package/docs/agents/rbac-secrets-management-spec.md +406 -0
  44. package/docs/agents/repository-page-integration-spec.md +255 -0
  45. package/docs/agents/resource-contract-examples.md +808 -0
  46. package/docs/agents/resource-relationship-map.md +190 -0
  47. package/docs/agents/security-threat-model.md +188 -0
  48. package/docs/agents/shared-memory-company-brain-spec.md +358 -0
  49. package/docs/agents/storage-migration-spec.md +168 -0
  50. package/docs/agents/subagent-orchestration-spec.md +152 -0
  51. package/docs/agents/system-overview.md +88 -0
  52. package/docs/agents/tools-mcp-skills-spec.md +189 -0
  53. package/docs/agents/traceability-matrix.md +79 -0
  54. package/docs/agents/ui-flow-spec.md +211 -0
  55. package/docs/agents/ui-ux-system-spec.md +426 -0
  56. package/docs/agents/workspace-lifecycle-spec.md +166 -0
  57. package/docs/architecture-spec.md +78 -0
  58. package/docs/components/control-plane.md +78 -0
  59. package/docs/components/data-plane.md +69 -0
  60. package/docs/components/hooks-events.md +67 -0
  61. package/docs/components/identity-rbac-policy.md +73 -0
  62. package/docs/components/kubevela-oam.md +70 -0
  63. package/docs/components/operations-publishing.md +81 -0
  64. package/docs/components/runners-ci.md +66 -0
  65. package/docs/components/web-ui.md +94 -0
  66. package/docs/external/README.md +47 -0
  67. package/docs/external/bidirectional-sync-design.md +134 -0
  68. package/docs/external/cicd-interface.md +64 -0
  69. package/docs/external/external-backend-controllers.md +170 -0
  70. package/docs/external/external-backend-crds.md +234 -0
  71. package/docs/external/external-backend-ui-spec.md +151 -0
  72. package/docs/external/external-backend-ux-flows.md +115 -0
  73. package/docs/external/external-object-mapping.md +125 -0
  74. package/docs/external/git-forge-interface.md +68 -0
  75. package/docs/external/github-integration-design.md +151 -0
  76. package/docs/external/issue-tracking-interface.md +66 -0
  77. package/docs/external/provider-capability-manifests.md +204 -0
  78. package/docs/external/provider-catalog.md +139 -0
  79. package/docs/external/provider-rollout-testing.md +78 -0
  80. package/docs/external/research-results.md +48 -0
  81. package/docs/external/security-auth-permissions.md +81 -0
  82. package/docs/external/sync-state-machines.md +108 -0
  83. package/docs/external/unified-external-backend-model.md +107 -0
  84. package/docs/external/user-facing-changes.md +67 -0
  85. package/docs/gaps.md +161 -0
  86. package/docs/install.md +94 -0
  87. package/docs/krate-design.md +334 -0
  88. package/docs/local-minikube.md +55 -0
  89. package/docs/ontology/README.md +32 -0
  90. package/docs/ontology/bounded-contexts.md +29 -0
  91. package/docs/ontology/events-and-hooks.md +32 -0
  92. package/docs/ontology/oam-kubevela.md +32 -0
  93. package/docs/ontology/operations-and-release.md +25 -0
  94. package/docs/ontology/personas-and-actors.md +32 -0
  95. package/docs/ontology/policies-and-invariants.md +33 -0
  96. package/docs/ontology/problem-space.md +30 -0
  97. package/docs/ontology/resource-contracts.md +40 -0
  98. package/docs/ontology/resource-taxonomy.md +42 -0
  99. package/docs/ontology/runners-and-ci.md +29 -0
  100. package/docs/ontology/solution-space.md +24 -0
  101. package/docs/ontology/storage-and-data-boundaries.md +29 -0
  102. package/docs/ontology/validation-matrix.md +24 -0
  103. package/docs/ontology/web-ui-excellent-flows.md +32 -0
  104. package/docs/ontology/workflows.md +39 -0
  105. package/docs/ontology/world.md +35 -0
  106. package/docs/product-requirements.md +62 -0
  107. package/docs/roadmap-mvp.md +87 -0
  108. package/docs/system-requirements.md +90 -0
  109. package/docs/tests/README.md +53 -0
  110. package/docs/tests/agent-qa-plan.md +63 -0
  111. package/docs/tests/browser-ui-tests.md +62 -0
  112. package/docs/tests/ci-quality-gates.md +48 -0
  113. package/docs/tests/coverage-model.md +64 -0
  114. package/docs/tests/e2e-scenario-tests.md +53 -0
  115. package/docs/tests/fixtures-test-data.md +63 -0
  116. package/docs/tests/observability-reliability-tests.md +54 -0
  117. package/docs/tests/product-test-matrix.md +145 -0
  118. package/docs/tests/qa-adoption-roadmap.md +130 -0
  119. package/docs/tests/qa-automation-plan.md +101 -0
  120. package/docs/tests/security-compliance-tests.md +57 -0
  121. package/docs/tests/test-framework-tools.md +88 -0
  122. package/docs/tests/test-suite-layout.md +121 -0
  123. package/docs/tests/unit-integration-tests.md +48 -0
  124. package/docs/todo-kyverno +714 -0
  125. package/docs/user-stories.md +78 -0
  126. package/examples/minikube-demo.yaml +190 -0
  127. package/examples/oam-application.yaml +23 -0
  128. package/examples/policy-kyverno-pr-title.yaml +18 -0
  129. package/package.json +63 -0
  130. package/scripts/build.mjs +29 -0
  131. package/scripts/setup-minikube.mjs +65 -0
  132. package/scripts/smoke.mjs +37 -0
  133. package/scripts/validate-doc-coverage.mjs +152 -0
  134. package/scripts/validate-package.mjs +93 -0
  135. package/scripts/validate-ui.mjs +207 -0
  136. package/src/agent-approval-controller.js +123 -0
  137. package/src/agent-context-bundles.js +242 -0
  138. package/src/agent-dispatch-controller.js +86 -0
  139. package/src/agent-mux-client.js +280 -0
  140. package/src/agent-permission-review.js +162 -0
  141. package/src/agent-stack-controller.js +296 -0
  142. package/src/agent-trigger-controller.js +108 -0
  143. package/src/api-controller.js +206 -0
  144. package/src/argocd-gitops.js +43 -0
  145. package/src/auth.js +265 -0
  146. package/src/component-catalog.js +41 -0
  147. package/src/control-plane.js +136 -0
  148. package/src/controller-client.js +38 -0
  149. package/src/controller-ui.js +538 -0
  150. package/src/data-plane.js +178 -0
  151. package/src/gitea-backend.js +95 -0
  152. package/src/handoff.js +98 -0
  153. package/src/hooks-events.js +63 -0
  154. package/src/http-server.js +151 -0
  155. package/src/identity-policy.js +86 -0
  156. package/src/index.js +30 -0
  157. package/src/kubernetes-controller.js +812 -0
  158. package/src/kubernetes-resource-gateway.js +48 -0
  159. package/src/operations.js +112 -0
  160. package/src/resource-model.js +203 -0
  161. package/src/runners-ci.js +48 -0
  162. package/src/runtime.js +196 -0
  163. package/src/web-ui.js +40 -0
  164. package/tests/agent-approval-controller.test.js +173 -0
  165. package/tests/agent-context-bundles.test.js +278 -0
  166. package/tests/agent-dispatch-controller.test.js +176 -0
  167. package/tests/agent-mux-client.test.js +204 -0
  168. package/tests/agent-permission-review.test.js +209 -0
  169. package/tests/agent-resources.test.js +212 -0
  170. package/tests/agent-stack-controller.test.js +221 -0
  171. package/tests/agent-trigger-controller.test.js +211 -0
  172. package/tests/deployment.test.js +395 -0
  173. package/tests/e2e/lifecycle.test.js +117 -0
  174. package/tests/krate.test.js +727 -0
@@ -0,0 +1,808 @@
1
+ # Agent resource contract examples
2
+
3
+ ## Purpose
4
+
5
+ This document gives concrete examples for the resource model described in the agent specs. The examples are intentionally implementation-ready but still docs-only. Field names may be refined during implementation, but the relationships should remain stable: stacks define launch capability, trigger rules decide when to dispatch, context labels explain prompt injection, dispatch runs track execution, and approvals gate privileged actions.
6
+
7
+ ## Example: Claude Code repair stack
8
+
9
+ ```yaml
10
+ apiVersion: krate.a5c.ai/v1alpha1
11
+ kind: AgentStack
12
+ metadata:
13
+ name: claude-code-ci-repair
14
+ namespace: krate-system
15
+ labels:
16
+ a5c.ai/owner: platform
17
+ spec:
18
+ displayName: Claude Code CI Repair
19
+ baseAgent: claude-code
20
+ adapter: agent-mux.claude-code
21
+ provider: anthropic
22
+ model: claude-sonnet-4-5
23
+ approvalMode: prompt
24
+ prompt:
25
+ system: >-
26
+ You are a repository repair agent. Diagnose the failing CI signal, make the
27
+ smallest safe change, and request approval before privileged write-back.
28
+ developer: >-
29
+ Preserve unrelated worktree changes. Prefer focused tests before broad gates.
30
+ agentsDocRef:
31
+ source: repository
32
+ path: AGENTS.md
33
+ toolProfileRef: repo-write-safe
34
+ mcpServerRefs:
35
+ - github-readonly
36
+ - krate-controller
37
+ skillRefs:
38
+ - ci-diagnosis
39
+ - focused-test-selection
40
+ subagentRefs:
41
+ - ci-log-researcher
42
+ - patch-reviewer
43
+ contextLabelRefs:
44
+ - ci-failure-summary
45
+ workspacePolicyRef: isolated-worktree-default
46
+ runnerPool: untrusted-linux
47
+ runtimeIdentity:
48
+ serviceAccountRef: agent-claude-code-ci-repair
49
+ permissionRefs:
50
+ roleBindings:
51
+ - claude-code-ci-repair-repo-read-write
52
+ secretGrants:
53
+ - claude-code-github-comment-token
54
+ - claude-code-anthropic-api-key
55
+ configGrants:
56
+ - claude-code-npm-config
57
+ secretPolicy:
58
+ allowOnForks: false
59
+ allowedSecretRefs:
60
+ - github-comment-token
61
+ writeBackPolicy:
62
+ requireApproval: true
63
+ allowedTargets:
64
+ - pull-request-comment
65
+ - check-rerun
66
+ - branch-push
67
+ status:
68
+ phase: Ready
69
+ conditions:
70
+ - type: CapabilitiesResolved
71
+ status: "True"
72
+ reason: AdapterManifestLoaded
73
+ - type: McpHealthy
74
+ status: "True"
75
+ reason: AllRequiredServersReady
76
+ - type: Ready
77
+ status: "True"
78
+ reason: PolicyAdmitted
79
+ ```
80
+
81
+ ## Example: subagents
82
+
83
+ ```yaml
84
+ apiVersion: krate.a5c.ai/v1alpha1
85
+ kind: AgentSubagent
86
+ metadata:
87
+ name: ci-log-researcher
88
+ spec:
89
+ description: Reads CI logs and finds the smallest likely root cause.
90
+ taskKinds:
91
+ - research
92
+ - triage
93
+ rolePrompt: >-
94
+ Inspect failing jobs, summarize root cause candidates, and do not edit files.
95
+ workspaceScope: read-only
96
+ maxParallelTasks: 2
97
+ outputContract:
98
+ format: markdown-summary
99
+ requiredSections:
100
+ - failing-signal
101
+ - likely-root-cause
102
+ - recommended-next-test
103
+ ---
104
+ apiVersion: krate.a5c.ai/v1alpha1
105
+ kind: AgentSubagent
106
+ metadata:
107
+ name: patch-reviewer
108
+ spec:
109
+ description: Reviews a proposed patch before write-back.
110
+ taskKinds:
111
+ - review
112
+ rolePrompt: >-
113
+ Review the diff for scope, safety, tests, and repository conventions.
114
+ workspaceScope: branch-local
115
+ maxParallelTasks: 1
116
+ outputContract:
117
+ format: checklist
118
+ ```
119
+
120
+ ## Example: tools, MCP, skills, and context labels
121
+
122
+ ```yaml
123
+ apiVersion: krate.a5c.ai/v1alpha1
124
+ kind: AgentToolProfile
125
+ metadata:
126
+ name: repo-write-safe
127
+ spec:
128
+ nativeTools:
129
+ shell: true
130
+ filesystem: true
131
+ browser: false
132
+ filesystemPolicy: workspace-write
133
+ networkPolicy:
134
+ default: deny
135
+ allowHosts:
136
+ - api.github.com
137
+ allowedCommands:
138
+ - git
139
+ - npm
140
+ - node
141
+ - npx
142
+ deniedCommands:
143
+ - rm -rf /
144
+ - git push --force
145
+ approvalPolicyByTool:
146
+ shell: prompt-on-denied-or-privileged
147
+ filesystem: allow-workspace
148
+ network: prompt
149
+ auditLevel: full-redacted-transcript
150
+ ---
151
+ apiVersion: krate.a5c.ai/v1alpha1
152
+ kind: AgentMcpServer
153
+ metadata:
154
+ name: krate-controller
155
+ spec:
156
+ transport: streamable-http
157
+ url: http://krate-controller.krate-system.svc.cluster.local/mcp
158
+ scope: repository
159
+ allowedAgentStacks:
160
+ - claude-code-ci-repair
161
+ approvalPolicy: readonly-auto-write-prompt
162
+ status:
163
+ health: Ready
164
+ discoveredTools:
165
+ - list_resources
166
+ - get_resource
167
+ - watch_resource
168
+ ---
169
+ apiVersion: krate.a5c.ai/v1alpha1
170
+ kind: AgentSkill
171
+ metadata:
172
+ name: ci-diagnosis
173
+ spec:
174
+ description: Standard Krate CI failure diagnosis runbook.
175
+ format: directory
176
+ sourceRef:
177
+ repository: krate
178
+ path: .agents/skills/ci-diagnosis
179
+ requiredTools:
180
+ - shell
181
+ requiredMcpServers:
182
+ - krate-controller
183
+ promptFragment: >-
184
+ Start by identifying the exact failed job, command, and first actionable error.
185
+ ---
186
+ apiVersion: krate.a5c.ai/v1alpha1
187
+ kind: AgentContextLabel
188
+ metadata:
189
+ name: ci-failure-summary
190
+ spec:
191
+ displayName: CI failure summary
192
+ promptFragment: >-
193
+ Include failed workflow, job, step, command, exit code, first error block,
194
+ changed files, branch, PR number, and rerun history.
195
+ allowedSources:
196
+ - pipeline
197
+ - job
198
+ - pull-request
199
+ requiresReview: true
200
+ ```
201
+
202
+ ## Example: native ServiceAccount, roles, Secrets, and ConfigMaps
203
+
204
+ ```yaml
205
+ apiVersion: krate.a5c.ai/v1alpha1
206
+ kind: AgentServiceAccount
207
+ metadata:
208
+ name: agent-claude-code-ci-repair
209
+ namespace: krate-system
210
+ spec:
211
+ namespace: krate-runners
212
+ serviceAccountName: agent-claude-code-ci-repair
213
+ owner:
214
+ kind: AgentStack
215
+ name: claude-code-ci-repair
216
+ allowedRepositories:
217
+ - krate
218
+ allowedRunnerPools:
219
+ - untrusted-linux
220
+ tokenAudience: krate-agent-dispatch
221
+ tokenExpirationSeconds: 3600
222
+ automountServiceAccountToken: false
223
+ status:
224
+ conditions:
225
+ - type: ServiceAccountSynced
226
+ status: "True"
227
+ reason: NativeObjectReady
228
+ - type: Ready
229
+ status: "True"
230
+ reason: TokenProjectionAllowed
231
+ ---
232
+ apiVersion: krate.a5c.ai/v1alpha1
233
+ kind: AgentRoleBinding
234
+ metadata:
235
+ name: claude-code-ci-repair-repo-read-write
236
+ spec:
237
+ subject:
238
+ kind: agent-stack
239
+ name: claude-code-ci-repair
240
+ serviceAccountRef: agent-claude-code-ci-repair
241
+ scope:
242
+ kind: repository
243
+ name: krate
244
+ roleRef:
245
+ kind: ClusterRole
246
+ name: krate-agent-repository-repair
247
+ resourceRules:
248
+ - apiGroups: ["krate.a5c.ai"]
249
+ resources: ["repositories", "pullrequests", "pipelines", "jobs", "agentdispatchruns"]
250
+ verbs: ["get", "list", "watch", "patch"]
251
+ escalationPolicy: deny
252
+ status:
253
+ conditions:
254
+ - type: NativeBindingSynced
255
+ status: "True"
256
+ reason: RoleBindingReady
257
+ ---
258
+ apiVersion: krate.a5c.ai/v1alpha1
259
+ kind: AgentSecretGrant
260
+ metadata:
261
+ name: claude-code-anthropic-api-key
262
+ spec:
263
+ subject:
264
+ kind: agent-stack
265
+ name: claude-code-ci-repair
266
+ serviceAccountRef: agent-claude-code-ci-repair
267
+ secretRef:
268
+ namespace: krate-secrets
269
+ name: anthropic-provider
270
+ keys:
271
+ - api-key
272
+ purpose: model-provider-token
273
+ allowedRepositories:
274
+ - krate
275
+ allowedRefs:
276
+ include:
277
+ - refs/heads/staging
278
+ - refs/heads/main
279
+ exclude:
280
+ - refs/pull/*/head
281
+ mountPolicy: env
282
+ requiredApproval: on-untrusted-ref
283
+ status:
284
+ conditions:
285
+ - type: SecretExists
286
+ status: "True"
287
+ reason: SecretFound
288
+ - type: SubjectAuthorized
289
+ status: "True"
290
+ reason: GrantMatchesServiceAccount
291
+ ---
292
+ apiVersion: krate.a5c.ai/v1alpha1
293
+ kind: AgentSecretGrant
294
+ metadata:
295
+ name: claude-code-github-comment-token
296
+ spec:
297
+ subject:
298
+ kind: tool
299
+ name: github-commenter
300
+ stackRef: claude-code-ci-repair
301
+ serviceAccountRef: agent-claude-code-ci-repair
302
+ secretRef:
303
+ namespace: krate-secrets
304
+ name: github-writeback
305
+ keys:
306
+ - token
307
+ purpose: tool
308
+ allowedRepositories:
309
+ - krate
310
+ allowedTriggerSources:
311
+ - pull-request
312
+ - ci
313
+ mountPolicy: never-mount-pass-by-reference
314
+ requiredApproval: always
315
+ ---
316
+ apiVersion: krate.a5c.ai/v1alpha1
317
+ kind: AgentConfigGrant
318
+ metadata:
319
+ name: claude-code-npm-config
320
+ spec:
321
+ subject:
322
+ kind: skill
323
+ name: focused-test-selection
324
+ stackRef: claude-code-ci-repair
325
+ serviceAccountRef: agent-claude-code-ci-repair
326
+ configMapRef:
327
+ namespace: krate-config
328
+ name: npm-test-policy
329
+ keys:
330
+ - allowed-scripts.json
331
+ purpose: skill-config
332
+ allowedRepositories:
333
+ - krate
334
+ mountPolicy: file
335
+ ```
336
+
337
+ ## Example: capability requirement warning
338
+
339
+ ```yaml
340
+ apiVersion: krate.a5c.ai/v1alpha1
341
+ kind: AgentCapabilityRequirement
342
+ metadata:
343
+ name: claude-code-ci-repair-requirements
344
+ spec:
345
+ ownerRef:
346
+ kind: AgentStack
347
+ name: claude-code-ci-repair
348
+ requiredSecretRefs:
349
+ - reason: model-provider-token
350
+ namespace: krate-secrets
351
+ name: anthropic-provider
352
+ key: api-key
353
+ - reason: tool
354
+ toolRef: github-commenter
355
+ namespace: krate-secrets
356
+ name: github-writeback
357
+ key: token
358
+ requiredConfigRefs:
359
+ - reason: skill-config
360
+ skillRef: focused-test-selection
361
+ namespace: krate-config
362
+ name: npm-test-policy
363
+ key: allowed-scripts.json
364
+ requiredRoles:
365
+ - krate-agent-repository-repair
366
+ status:
367
+ missingGrants:
368
+ - kind: AgentSecretGrant
369
+ reason: ToolSecretNotGranted
370
+ message: github-commenter requires Secret krate-secrets/github-writeback:token for stack claude-code-ci-repair.
371
+ conditions:
372
+ - type: GrantsResolved
373
+ status: "False"
374
+ reason: MissingSecretGrant
375
+ `
376
+
377
+ ## Example: permission review response
378
+
379
+ Request:
380
+
381
+ ```json
382
+ {
383
+ "repository": "krate",
384
+ "ref": "refs/pull/42/head",
385
+ "actor": "tmusk",
386
+ "agentStack": "claude-code-ci-repair",
387
+ "triggerSource": "pull-request-comment",
388
+ "taskKind": "ci-repair",
389
+ "runnerPool": "untrusted-linux"
390
+ }
391
+ ```
392
+
393
+ Response when a tool secret is missing:
394
+
395
+ ```json
396
+ {
397
+ "decision": "denied",
398
+ "runtimeIdentity": {
399
+ "serviceAccountRef": "agent-claude-code-ci-repair",
400
+ "ready": true
401
+ },
402
+ "runnerIdentity": {
403
+ "runnerPool": "untrusted-linux",
404
+ "serviceAccountRef": "runner-untrusted-linux",
405
+ "ready": true
406
+ },
407
+ "requiredRoles": [
408
+ {
409
+ "roleRef": "krate-agent-repository-repair",
410
+ "allowed": true,
411
+ "nativeReview": "allowed"
412
+ }
413
+ ],
414
+ "requiredSecrets": [
415
+ {
416
+ "owner": { "kind": "tool", "name": "github-commenter" },
417
+ "secretRef": "krate-secrets/github-writeback",
418
+ "keys": ["token"],
419
+ "grant": null,
420
+ "decision": "missing-grant"
421
+ }
422
+ ],
423
+ "requiredConfigs": [
424
+ {
425
+ "owner": { "kind": "skill", "name": "focused-test-selection" },
426
+ "configMapRef": "krate-config/npm-test-policy",
427
+ "keys": ["allowed-scripts.json"],
428
+ "grant": "claude-code-npm-config",
429
+ "decision": "allowed"
430
+ }
431
+ ],
432
+ "missingGrants": [
433
+ {
434
+ "kind": "AgentSecretGrant",
435
+ "suggestedName": "claude-code-github-comment-token",
436
+ "reason": "ToolSecretNotGranted",
437
+ "blocking": true
438
+ }
439
+ ],
440
+ "reasons": [
441
+ "github-commenter requires Secret krate-secrets/github-writeback:token, but no AgentSecretGrant matches stack claude-code-ci-repair on refs/pull/42/head."
442
+ ]
443
+ }
444
+ ```
445
+
446
+ ## Example: stack status after missing grant
447
+
448
+ ```yaml
449
+ apiVersion: krate.a5c.ai/v1alpha1
450
+ kind: AgentStack
451
+ metadata:
452
+ name: claude-code-ci-repair
453
+ status:
454
+ phase: Blocked
455
+ conditions:
456
+ - type: CapabilitiesResolved
457
+ status: "True"
458
+ reason: AdapterManifestLoaded
459
+ - type: RuntimeIdentityReady
460
+ status: "True"
461
+ reason: ServiceAccountReady
462
+ - type: RolesAdmitted
463
+ status: "True"
464
+ reason: RequiredRolesAllowed
465
+ - type: SecretsAdmitted
466
+ status: "False"
467
+ reason: MissingSecretGrant
468
+ message: github-commenter requires Secret krate-secrets/github-writeback:token.
469
+ - type: Ready
470
+ status: "False"
471
+ reason: PermissionRequirementsBlocked
472
+ ```
473
+
474
+ ## Example: audit event for grant creation
475
+
476
+ ```yaml
477
+ apiVersion: krate.a5c.ai/v1alpha1
478
+ kind: AuditEvent
479
+ metadata:
480
+ name: audit-agent-secret-grant-01hx
481
+ spec:
482
+ type: AgentSecretGrantApplied
483
+ actor:
484
+ kind: User
485
+ name: tmusk
486
+ kubernetesUser: tmusk@example.com
487
+ target:
488
+ kind: AgentSecretGrant
489
+ name: claude-code-github-comment-token
490
+ decision:
491
+ nativeReview: allowed
492
+ escalationReview: not-escalating
493
+ details:
494
+ subject:
495
+ kind: tool
496
+ name: github-commenter
497
+ stackRef: claude-code-ci-repair
498
+ secretRef:
499
+ namespace: krate-secrets
500
+ name: github-writeback
501
+ keys:
502
+ - token
503
+ purpose: tool
504
+ allowedRepositories:
505
+ - krate
506
+ allowedTriggerSources:
507
+ - pull-request
508
+ - ci
509
+ ```
510
+ ## Example: trigger rule for failed PR checks
511
+
512
+ ```yaml
513
+ apiVersion: krate.a5c.ai/v1alpha1
514
+ kind: AgentTriggerRule
515
+ metadata:
516
+ name: failed-pr-check-repair
517
+ namespace: krate-system
518
+ spec:
519
+ lifecycleState: active
520
+ sources:
521
+ - ci
522
+ - check-suite
523
+ match:
524
+ repository: krate
525
+ eventTypes:
526
+ - check_run.completed
527
+ - workflow_job.completed
528
+ conclusion:
529
+ - failure
530
+ - timed_out
531
+ pullRequestRequired: true
532
+ branches:
533
+ include:
534
+ - main
535
+ - staging
536
+ paths:
537
+ include:
538
+ - src/**
539
+ - apps/web/**
540
+ - tests/**
541
+ agentStack: claude-code-ci-repair
542
+ taskKind: ci-repair
543
+ promptTemplate: >-
544
+ Diagnose and repair the failed CI signal for {{ repository }} at {{ sha }}.
545
+ Preserve unrelated changes and ask before write-back.
546
+ contextLabels:
547
+ - ci-failure-summary
548
+ contextBundleTemplate:
549
+ include:
550
+ - changed-files
551
+ - failing-job-log
552
+ - pull-request-summary
553
+ - recent-commits
554
+ - repository-instructions
555
+ maxBytes: 750000
556
+ redactSecrets: true
557
+ runnerPool: untrusted-linux
558
+ approvalPolicy:
559
+ requireFor:
560
+ - write-back
561
+ - secret-access
562
+ - network-expanded
563
+ - branch-push
564
+ dedupePolicy:
565
+ key: "{{ repository }}:{{ pullRequest.number }}:{{ check.name }}:{{ sha }}"
566
+ window: 30m
567
+ concurrencyPolicy:
568
+ mode: coalesce
569
+ maxActivePerPullRequest: 1
570
+ writeBackPolicy:
571
+ allowedTargets:
572
+ - pull-request-comment
573
+ - check-rerun
574
+ - branch-push
575
+ status:
576
+ lastTriggeredAt: "2026-05-10T00:00:00Z"
577
+ executionSummary:
578
+ created: 14
579
+ coalesced: 3
580
+ rejected: 2
581
+ ```
582
+
583
+ ## Example: dispatch run and attempt projection
584
+
585
+ ```yaml
586
+ apiVersion: krate.a5c.ai/v1alpha1
587
+ kind: AgentDispatchRun
588
+ metadata:
589
+ name: adr-01hx-ci-repair
590
+ namespace: krate-system
591
+ spec:
592
+ repository: krate
593
+ ref: refs/pull/42/head
594
+ branch: user/fix-ci
595
+ sha: abcdef1234567890
596
+ sourceEvent:
597
+ kind: WebhookDelivery
598
+ name: delivery-01hx
599
+ sourceRefs:
600
+ pullRequest: krate/42
601
+ pipeline: pipeline-01hx
602
+ job: job-01hx-test
603
+ triggerRule: failed-pr-check-repair
604
+ agentStack: claude-code-ci-repair
605
+ taskKind: ci-repair
606
+ contextBundleRef: acb-01hx
607
+ workspaceRef: workspace-krate-pr-42
608
+ runnerPool: untrusted-linux
609
+ approvalPolicy:
610
+ requireWriteBackApproval: true
611
+ status:
612
+ phase: waiting-for-approval
613
+ agentMuxRunId: run_01hx
614
+ agentMuxSessionId: ses_01hx
615
+ childSubagentRuns:
616
+ - ci-log-researcher/run_01hx_child_1
617
+ - patch-reviewer/run_01hx_child_2
618
+ artifacts:
619
+ - kind: patch
620
+ name: artifact-01hx-patch
621
+ - kind: diagnosis
622
+ name: artifact-01hx-diagnosis
623
+ approvals:
624
+ - approval-01hx-writeback
625
+ eventCursor: "0000000000000104"
626
+ conditions:
627
+ - type: AgentMuxSessionBound
628
+ status: "True"
629
+ reason: SessionReady
630
+ - type: ApprovalSatisfied
631
+ status: "False"
632
+ reason: WaitingForWriteBackApproval
633
+ ---
634
+ apiVersion: krate.a5c.ai/v1alpha1
635
+ kind: AgentDispatchAttempt
636
+ metadata:
637
+ name: ada-01hx-ci-repair-1
638
+ spec:
639
+ agentDispatchRun: adr-01hx-ci-repair
640
+ attemptReason: initial
641
+ agentStackSnapshot:
642
+ name: claude-code-ci-repair
643
+ generation: 7
644
+ contextBundleDigest: sha256:9f5b...
645
+ workspaceRef: workspace-krate-pr-42
646
+ runnerPool: untrusted-linux
647
+ status:
648
+ agentMuxRunId: run_01hx
649
+ agentMuxSessionId: ses_01hx
650
+ queueEnteredAt: "2026-05-10T10:10:00Z"
651
+ startedAt: "2026-05-10T10:10:24Z"
652
+ exitReason: waiting-for-approval
653
+ ```
654
+
655
+ ## Example: approval request
656
+
657
+ ```yaml
658
+ apiVersion: krate.a5c.ai/v1alpha1
659
+ kind: AgentApproval
660
+ metadata:
661
+ name: approval-01hx-writeback
662
+ spec:
663
+ dispatchRun: adr-01hx-ci-repair
664
+ attempt: ada-01hx-ci-repair-1
665
+ requestedBy:
666
+ kind: agent
667
+ name: claude-code-ci-repair
668
+ action:
669
+ type: pull-request-comment
670
+ target: krate/42
671
+ summary: Post diagnosis and attach proposed patch.
672
+ policyReasons:
673
+ - writeBackPolicy.requireApproval
674
+ - pullRequest.fromFork
675
+ artifactRefs:
676
+ - artifact-01hx-diagnosis
677
+ - artifact-01hx-patch
678
+ status:
679
+ phase: pending
680
+ createdAt: "2026-05-10T10:14:00Z"
681
+ ```
682
+
683
+ ## Example: issue, workspace, and session association
684
+
685
+ ```yaml
686
+ apiVersion: krate.a5c.ai/v1alpha1
687
+ kind: WorkItemSessionLink
688
+ metadata:
689
+ name: issue-91-session-01hx
690
+ spec:
691
+ issue: krate/91
692
+ agentSession: ses_01hx
693
+ dispatchRun: adr-01hx-ci-repair
694
+ relation: active-agent-chat
695
+ ---
696
+ apiVersion: krate.a5c.ai/v1alpha1
697
+ kind: WorkItemWorkspaceLink
698
+ metadata:
699
+ name: issue-91-workspace-01hx
700
+ spec:
701
+ issue: krate/91
702
+ workspace: workspace-krate-pr-42
703
+ relation: implementation-workspace
704
+ ```
705
+
706
+ ## API payload example: manual dispatch
707
+
708
+ ```json
709
+ {
710
+ "repository": "krate",
711
+ "ref": "refs/heads/staging",
712
+ "agentStack": "claude-code-ci-repair",
713
+ "taskKind": "manual-repair",
714
+ "prompt": "Investigate the failing docs validation and propose the smallest fix.",
715
+ "contextLabels": ["ci-failure-summary"],
716
+ "runtimeIdentity": {
717
+ "serviceAccountRef": "agent-claude-code-ci-repair"
718
+ },
719
+ "secretGrants": ["claude-code-anthropic-api-key"],
720
+ "configGrants": ["claude-code-npm-config"],
721
+ "sourceRefs": {
722
+ "path": "docs/agents",
723
+ "actor": "tmusk"
724
+ },
725
+ "workspacePolicy": {
726
+ "mode": "isolated-worktree",
727
+ "baseBranch": "staging"
728
+ },
729
+ "writeBackPolicy": {
730
+ "requireApproval": true
731
+ }
732
+ }
733
+ ```
734
+
735
+ Expected response:
736
+
737
+ ```json
738
+ {
739
+ "run": {
740
+ "kind": "AgentDispatchRun",
741
+ "metadata": { "name": "adr-01hx-manual" },
742
+ "status": { "phase": "queued" }
743
+ },
744
+ "links": {
745
+ "detail": "/agents/runs/adr-01hx-manual",
746
+ "repository": "/orgs/[org]/repositories/krate/runs?agentRun=adr-01hx-manual"
747
+ }
748
+ }
749
+ ```
750
+
751
+ ## Org-scoped memory examples
752
+
753
+ ```yaml
754
+ apiVersion: krate.a5c.ai/v1alpha1
755
+ kind: Organization
756
+ metadata:
757
+ name: a5c
758
+ spec:
759
+ namespaceName: krate-org-a5c
760
+ slug: a5c
761
+ memoryRepositoryRef: org-company-brain
762
+ ```
763
+
764
+ ```yaml
765
+ apiVersion: krate.a5c.ai/v1alpha1
766
+ kind: AgentRunMemoryImport
767
+ metadata:
768
+ name: import-01kr
769
+ namespace: krate-org-a5c
770
+ labels:
771
+ krate.a5c.ai/org: a5c
772
+ spec:
773
+ organizationRef: a5c
774
+ memoryRepository: org-company-brain
775
+ source:
776
+ kind: babysitter-run
777
+ runId: 01KR1ZCPQVVPJAJDNBQHGPWZZY
778
+ a5cRunPath: .a5c/runs/01KR1ZCPQVVPJAJDNBQHGPWZZY
779
+ include:
780
+ memoryMd: true
781
+ sessionSummary: true
782
+ journal: curated
783
+ taskResults: true
784
+ artifactManifests: true
785
+ targetPath: babysitter/runs/01KR1ZCPQVVPJAJDNBQHGPWZZY
786
+ validationPolicy:
787
+ redactSecrets: true
788
+ requireReview: true
789
+ ```
790
+
791
+ ```yaml
792
+ apiVersion: krate.a5c.ai/v1alpha1
793
+ kind: AgentMemorySource
794
+ metadata:
795
+ name: krate-ci-memory
796
+ namespace: krate-org-a5c
797
+ spec:
798
+ organizationRef: a5c
799
+ repositoryRef: org-company-brain
800
+ appliesTo:
801
+ repositories: [krate]
802
+ include:
803
+ paths:
804
+ - babysitter/MEMORY.md
805
+ - babysitter/runs/**
806
+ - runbooks/ci/**
807
+ graphKinds: [BabysitterRun, Runbook, AgentPractice, RunRetrospective]
808
+ ```