@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,421 @@
1
+ # Agent stack management spec
2
+
3
+ ## Purpose
4
+
5
+ Krate needs a general agent orchestration layer, not only a UI integration. Users should be able to define a reusable agent stack such as "Claude Code reviewer with filesystem tools, repo MCP tools, two subagents, release-runbook skills, prompt context labels, and strict approval policy", then connect it to CI failures, issue/PR triggers, incoming webhooks, schedules, or manual repository actions.
6
+
7
+ The result should look and behave like a CI run in Krate: queued on runner capacity, tied to repo/ref/source event, visible beside pipelines/jobs, streamable in real time, artifact-producing, cancellable, approval-gated, and auditable. It should also expose the Agent Mux chat/session so humans can continue the run, inspect transcript/tool activity, manage subagents, and recover the workspace.
8
+
9
+ ## Core user flows
10
+
11
+ ### Define an agent stack
12
+
13
+ 1. Platform admin or repo maintainer creates an `AgentStack`.
14
+ 2. They select a base runtime: `claude-code`, `codex`, `gemini`, `opencode`, `babysitter`, or an external Agent Mux adapter.
15
+ 3. They configure model/provider, approval mode, allowed/denied tools, sandbox, workspace policy, secrets policy, MCP servers, skills, subagents, and default prompt.
16
+ 4. Krate validates the definition against adapter capabilities from Agent Mux.
17
+ 5. The stack becomes selectable by dispatch rules and manual repository actions.
18
+
19
+ ### Define Claude Code subagents
20
+
21
+ 1. User adds subagent definitions under an `AgentStack`.
22
+ 2. Each subagent gets a name, description, role prompt, optional model override, allowed tools, MCP access, workspace scope, and concurrency limit.
23
+ 3. The parent stack can dispatch to these subagents for research, implementation, review, validation, or release checks.
24
+ 4. Subagent activity is surfaced as child attempts/events under the main dispatch run.
25
+
26
+ ### Manage tools, MCP servers, and skills
27
+
28
+ 1. User registers tools as managed capabilities, not ad-hoc prompt text.
29
+ 2. MCP servers define transport, command/URL, args, env refs, headers refs, scope, and approval policy.
30
+ 3. Skills define reusable procedures/runbooks that can be loaded into an agent stack.
31
+ 4. Krate checks repository policy before a tool/skill/MCP server is attached to a stack or dispatch.
32
+ 5. Dispatch context shows exactly which tools, skills, and MCP servers were made available.
33
+
34
+ ### Connect triggers to an agent stack
35
+
36
+ 1. User creates an `AgentTriggerRule`.
37
+ 2. The rule selects source events: failed check, pipeline/job event, incoming webhook, issue/PR mention, label, push, tag, schedule, manual action, or repository dispatch.
38
+ 3. The rule matches workflow/job/step/path/branch/label/comment/body/failure signature/webhook payload fields.
39
+ 4. The rule selects an agent stack, task kind, context labels, runner pool, approval policy, dedupe policy, and write-back policy.
40
+ 5. When an event matches, Krate creates a dispatch run and links it to the source object.
41
+
42
+ ### Dispatch appears as a CI-like run
43
+
44
+ 1. Krate creates an `AgentDispatchRun` and one `AgentDispatchAttempt`.
45
+ 2. The run appears next to `Pipeline` and `Job` records for the repo/ref/PR.
46
+ 3. The run shows queue state, runner pool, workspace, source trigger, agent stack, task kind, phase, cost/tokens, artifacts, approvals, and linked Agent Mux session.
47
+ 4. Opening the run shows CI-style metadata plus the live Agent Mux chat/transcript.
48
+ 5. Agent output can produce artifacts: diagnosis, patch, branch proposal, review comments, subagent reports, release report, or rerun request.
49
+ 6. Privileged write-back requires approval before comments, PR updates, pushes, review submissions, check reruns, or release actions.
50
+
51
+ ### Manage work item, workspace, and session lifecycle
52
+
53
+ 1. A trigger can create or link a work item/card/issue.
54
+ 2. The work item can own or link a workspace.
55
+ 3. The workspace can own or link active sessions and dispatch runs.
56
+ 4. Users can pin, archive, cleanup, recover, rebase, annotate, and inspect runtime surfaces for the workspace.
57
+ 5. The issue/PR/pipeline/workspace/session views are projections of the same linked orchestration graph.
58
+
59
+ ## Proposed resource model
60
+
61
+ Names are planning names only.
62
+
63
+ ### `AgentStack`
64
+
65
+ Reusable definition of a runnable agent configuration.
66
+
67
+ Important fields:
68
+
69
+ - `spec.displayName`;
70
+ - `spec.baseAgent`: `claude-code`, `codex`, `gemini`, `opencode`, `babysitter`, `agent-mux-remote`, external;
71
+ - `spec.adapter`: Agent Mux adapter ID or gateway route;
72
+ - `spec.model` and `spec.provider`;
73
+ - `spec.prompt`: default system/developer/task framing;
74
+ - `spec.agentsDocRef`: `AGENTS.md` or equivalent instruction source;
75
+ - `spec.approvalMode`: prompt, deny, yolo, or policy-derived;
76
+ - `spec.allowedCommands` / `spec.deniedCommands`;
77
+ - `spec.toolPolicy`;
78
+ - `spec.mcpServerRefs`;
79
+ - `spec.skillRefs`;
80
+ - `spec.subagentRefs`;
81
+ - `spec.contextLabelRefs`;
82
+ - `spec.workspacePolicy`;
83
+ - `spec.runnerPool`;
84
+ - `spec.secretPolicy`;
85
+ - `spec.runtimeIdentity.serviceAccountRef`;
86
+ - `spec.permissionRefs.roleBindings`;
87
+ - `spec.permissionRefs.secretGrants`;
88
+ - `spec.permissionRefs.configGrants`;
89
+ - `spec.writeBackPolicy`;
90
+ - `status.capabilities`: adapter-reported normalized capabilities;
91
+ - `status.validation`: valid, warning, invalid.
92
+
93
+ ### `AgentSubagent`
94
+
95
+ A named child-agent definition available to an `AgentStack`.
96
+
97
+ Important fields:
98
+
99
+ - `spec.name`;
100
+ - `spec.description`;
101
+ - `spec.rolePrompt`;
102
+ - `spec.taskKinds`: research, implementation, validation, review, triage, release-check;
103
+ - `spec.modelOverride`;
104
+ - `spec.toolRefs`;
105
+ - `spec.mcpServerRefs`;
106
+ - `spec.skillRefs`;
107
+ - `spec.workspaceScope`: read-only, branch-local, isolated-worktree, no-workspace;
108
+ - `spec.maxParallelTasks`;
109
+ - `spec.outputContract`: summary, patch, checklist, JSON, review comments.
110
+
111
+ Subagents must be visible in run telemetry. A parent dispatch should show which subagents were invoked, what context they received, and what they returned.
112
+
113
+ ### `AgentToolProfile`
114
+
115
+ Policy bundle for native tools and shell access.
116
+
117
+ Important fields:
118
+
119
+ - `spec.nativeTools`: enabled/disabled native tool categories;
120
+ - `spec.allowedCommands`;
121
+ - `spec.deniedCommands`;
122
+ - `spec.filesystemPolicy`: read-only, repo-write, workspace-write, no-fs;
123
+ - `spec.networkPolicy`;
124
+ - `spec.approvalPolicyByTool`;
125
+ - `spec.requiredSecretRefs` for tools that need credentials;
126
+ - `spec.requiredConfigRefs` for tools that need non-secret config;
127
+ - `spec.auditLevel`: metadata, inputs, outputs, full redacted transcript.
128
+
129
+ ### `AgentMcpServer`
130
+
131
+ Managed MCP server definition.
132
+
133
+ Important fields:
134
+
135
+ - `spec.name`;
136
+ - `spec.transport`: stdio, sse, streamable-http;
137
+ - `spec.command` / `spec.args` for stdio;
138
+ - `spec.url` for network transports;
139
+ - `spec.envFrom` and `spec.secretRefs`;
140
+ - `spec.configMapRefs`;
141
+ - `spec.headersFrom`;
142
+ - `spec.scope`: global, org, repository, stack, dispatch;
143
+ - `spec.allowedAgentStacks`;
144
+ - `spec.approvalPolicy`;
145
+ - `status.health`;
146
+ - `status.discoveredTools`.
147
+
148
+ ### `AgentSkill`
149
+
150
+ Reusable runbook/procedure available to agent stacks.
151
+
152
+ Important fields:
153
+
154
+ - `spec.name`;
155
+ - `spec.description`;
156
+ - `spec.format`: file, directory, package, inline;
157
+ - `spec.sourceRef`;
158
+ - `spec.allowedAgentStacks`;
159
+ - `spec.requiredTools`;
160
+ - `spec.requiredMcpServers`;
161
+ - `spec.requiredSecretRefs`;
162
+ - `spec.requiredConfigRefs`;
163
+ - `spec.promptFragment`;
164
+ - `spec.version`;
165
+ - `status.validation`.
166
+
167
+ ### `AgentServiceAccount`
168
+
169
+ Krate-managed wrapper around native Kubernetes `ServiceAccount` identity for agent stacks and runner pools.
170
+
171
+ Important fields:
172
+
173
+ - `spec.namespace`;
174
+ - `spec.serviceAccountName`;
175
+ - `spec.owner`: agent-stack, runner-pool, repository, organization;
176
+ - `spec.allowedRepositories`;
177
+ - `spec.allowedRunnerPools`;
178
+ - `spec.tokenAudience` and `spec.tokenExpirationSeconds`;
179
+ - `spec.imagePullSecretRefs`;
180
+ - `status.syncedServiceAccount`;
181
+ - `status.conditions`: ServiceAccountSynced, TokenProjectionAllowed, Ready.
182
+
183
+ ### `AgentRoleBinding`
184
+
185
+ Krate-managed intent that syncs to native Kubernetes `Role`, `ClusterRole`, `RoleBinding`, or `ClusterRoleBinding` resources.
186
+
187
+ Important fields:
188
+
189
+ - `spec.subject`: user, group, team, agent-stack, runner-pool, service-account;
190
+ - `spec.scope`: namespace, repository, organization, cluster;
191
+ - `spec.roleRef`: native role or Krate role template;
192
+ - `spec.resourceRules`;
193
+ - `spec.nativeRoleBindingName`;
194
+ - `spec.escalationPolicy`;
195
+ - `status.syncedRoleRefs`;
196
+ - `status.conditions`: RoleResolved, SubjectsResolved, NativeBindingSynced, EscalationAdmitted, Ready.
197
+
198
+ ### `AgentSecretGrant`
199
+
200
+ Permission for an actor to consume selected Kubernetes Secret keys for an explicit purpose.
201
+
202
+ Important fields:
203
+
204
+ - `spec.subject`: agent-stack, service-account, runner-pool, user, team, tool, skill, MCP server;
205
+ - `spec.secretRef`: namespace/name and allowed keys;
206
+ - `spec.purpose`: model-provider-token, git-credential, mcp-server, tool, skill, webhook-signing, image-pull, cache, deployment;
207
+ - `spec.allowedRepositories`, `spec.allowedRefs`, and `spec.allowedTriggerSources`;
208
+ - `spec.mountPolicy`: env, file, projected-volume, never-mount-pass-by-reference;
209
+ - `spec.requiredApproval`;
210
+ - `status.conditions`: SecretExists, KeysExist, SubjectAuthorized, PolicyAdmitted, Ready.
211
+
212
+ ### `AgentConfigGrant`
213
+
214
+ Permission for an actor to consume selected Kubernetes ConfigMap keys.
215
+
216
+ Important fields:
217
+
218
+ - `spec.subject`;
219
+ - `spec.configMapRef`: namespace/name and allowed keys;
220
+ - `spec.purpose`: tool-config, skill-config, mcp-config, runner-config, prompt-template, repository-policy;
221
+ - `spec.allowedRepositories`;
222
+ - `spec.mountPolicy`: env, file, projected-volume, api-read;
223
+ - `status.conditions`: ConfigMapExists, KeysExist, SubjectAuthorized, PolicyAdmitted, Ready.
224
+
225
+ ### `AgentCapabilityRequirement`
226
+
227
+ Computed requirement record for tools, MCP servers, skills, subagents, model providers, and stack launch options.
228
+
229
+ Important fields:
230
+
231
+ - `spec.ownerRef`;
232
+ - `spec.requiredSecretRefs`;
233
+ - `spec.requiredConfigRefs`;
234
+ - `spec.requiredRoles`;
235
+ - `spec.requiredServiceAccountCapabilities`;
236
+ - `status.missingGrants`;
237
+ - `status.invalidGrants`;
238
+ - `status.conditions`: RequirementsDiscovered, GrantsResolved, Ready.
239
+
240
+ ### `AgentTriggerRule`
241
+
242
+ Connects incoming events to agent stacks.
243
+
244
+ Important fields:
245
+
246
+ - `spec.sources`: ci, webhook, issue-comment, pr-comment, label, push, tag, schedule, manual, repository-dispatch;
247
+ - `spec.match`: workflow, job, step, check, branch, path, label, actor, mention, payload JSONPath, failure signature;
248
+ - `spec.agentStack`;
249
+ - `spec.taskKind`;
250
+ - `spec.promptTemplate`;
251
+ - `spec.contextLabels`;
252
+ - `spec.contextBundleTemplate`;
253
+ - `spec.runnerPool`;
254
+ - `spec.approvalPolicy`;
255
+ - `spec.dedupePolicy`;
256
+ - `spec.concurrencyPolicy`;
257
+ - `spec.writeBackPolicy`;
258
+ - `status.lastTriggeredAt`;
259
+ - `status.executionSummary`.
260
+
261
+ ### `AgentDispatchRun`
262
+
263
+ Logical agent run that appears like a pipeline run.
264
+
265
+ Important fields:
266
+
267
+ - `spec.repository`;
268
+ - `spec.ref`, `spec.branch`, `spec.sha`;
269
+ - `spec.sourceEvent`;
270
+ - `spec.sourceRefs`: PR, issue, check, pipeline, job, webhook delivery, schedule, work item;
271
+ - `spec.agentStack`;
272
+ - `spec.taskKind`;
273
+ - `spec.contextBundleRef`;
274
+ - `spec.workspaceRef`;
275
+ - `spec.runnerPool`;
276
+ - `spec.approvalPolicy`;
277
+ - `status.phase`: pending, queued, running, waiting-for-approval, succeeded, failed, cancelled;
278
+ - `status.agentMuxRunId`;
279
+ - `status.agentMuxSessionId`;
280
+ - `status.childSubagentRuns`;
281
+ - `status.artifacts`;
282
+ - `status.approvals`;
283
+ - `status.cost`;
284
+ - `status.eventCursor`.
285
+
286
+ ### `AgentDispatchAttempt`
287
+
288
+ Concrete execution attempt under one logical dispatch run.
289
+
290
+ Important fields:
291
+
292
+ - `spec.agentDispatchRun`;
293
+ - `spec.attemptReason`: initial, retry, resume, repair, rerun-after-fix, continuation;
294
+ - `spec.agentStackSnapshot`;
295
+ - `spec.contextBundleDigest`;
296
+ - `spec.workspaceRef`;
297
+ - `spec.runnerPool`;
298
+ - `status.agentMuxRunId`;
299
+ - `status.agentMuxSessionId`;
300
+ - `status.queueEnteredAt`, `status.startedAt`, `status.completedAt`;
301
+ - `status.exitReason`;
302
+ - `status.producedArtifacts`;
303
+ - `status.subagentEvents`.
304
+
305
+ ### `WorkItemSessionLink` and `WorkItemWorkspaceLink`
306
+
307
+ Generalized links from Agent Mux kanban issue/session/workspace associations.
308
+
309
+ Important fields:
310
+
311
+ - `spec.workItemRef`: issue, PR, check failure, release task, or internal card;
312
+ - `spec.workspaceRef` or `spec.sessionRef`;
313
+ - `spec.runRefs`;
314
+ - `spec.linkSource`: created-from-work-item, linked-existing-workspace, linked-session, automation-derived;
315
+ - `spec.branchName`;
316
+ - `spec.createdBy`;
317
+ - `status.lastActivityAt`.
318
+
319
+ ## Status conditions and admission contract
320
+
321
+ Every declarative agent resource needs `status.conditions` so the UI and controllers can explain why an action is enabled or disabled. Conditions should use stable reason codes; free-form messages are for humans only.
322
+
323
+ ### `AgentStack.status.conditions`
324
+
325
+ | Condition | True means | False examples |
326
+ | --- | --- | --- |
327
+ | `CapabilitiesResolved` | Agent Mux adapter capabilities were fetched and normalized. | adapter unavailable, unsupported base agent, stale capability schema. |
328
+ | `ToolsAdmitted` | Native tool profile is compatible with repo/org policy. | denied shell command, filesystem scope too broad, network policy missing. |
329
+ | `McpHealthy` | Referenced MCP servers are reachable or explicitly allowed to be lazy. | failed probe, secret ref missing, server not allowed for repo. |
330
+ | `SkillsValidated` | Skill sources were found, compatible, and prompt fragments passed policy. | missing skill, invalid package, required tool not admitted. |
331
+ | `SubagentsValid` | Subagent definitions are compatible with adapter and stack policy. | adapter lacks subagent dispatch, parallelism exceeds limit, output contract unsupported. |
332
+ | `ContextLabelsValid` | Default labels exist and have approved prompt fragments. | label deleted, stale version, unsafe injection token. |
333
+ | `PolicyAdmitted` | Repository/org/cluster policy allows this stack to dispatch. | untrusted repo, forbidden approval mode, privileged secrets on fork. |
334
+ | `RuntimeIdentityReady` | Selected agent ServiceAccount exists and can receive projected tokens. | ServiceAccount missing, token projection forbidden, runner pool cannot use identity. |
335
+ | `RolesAdmitted` | Required native Roles/RoleBindings are present and non-escalating. | missing RoleBinding, ClusterRole denied, binding drifted from native state. |
336
+ | `SecretsAdmitted` | Required Secret keys have matching `AgentSecretGrant` records. | missing secret grant, key missing, secret not allowed for repo/ref/trigger. |
337
+ | `ConfigAdmitted` | Required ConfigMap keys have matching `AgentConfigGrant` records. | missing config grant, key missing, config denied for stack. |
338
+ | `Ready` | All required conditions for dispatch are true. | any required condition false or unknown. |
339
+
340
+ ### `AgentTriggerRule.status.conditions`
341
+
342
+ | Condition | True means | False examples |
343
+ | --- | --- | --- |
344
+ | `SourceConfigured` | Event source and delivery endpoint are valid. | webhook missing secret, unknown CI workflow, invalid schedule. |
345
+ | `MatcherValid` | Match expression compiles and can be dry-run. | invalid JSONPath, unknown label matcher, unsupported failure signature. |
346
+ | `TargetStackReady` | Referenced `AgentStack` is `Ready`. | stack not admitted, capability resolution unknown. |
347
+ | `ContextTemplateValid` | Prompt/context template can render with sample payload. | missing payload field, unsafe raw payload injection, attachment too large. |
348
+ | `DedupePolicyValid` | Dedupe/concurrency keys are stable and bounded. | unbounded key, missing coalescing target, conflicting concurrency policy. |
349
+ | `LifecycleActive` | Rule can dispatch new runs. | draft, paused, disabled, archived. |
350
+
351
+ ### `AgentDispatchRun.status.conditions`
352
+
353
+ | Condition | True means | False examples |
354
+ | --- | --- | --- |
355
+ | `ContextAssembled` | Context bundle snapshot exists with digest and provenance. | source object missing, artifact fetch failed, redaction error. |
356
+ | `WorkspaceResolved` | Workspace was selected/provisioned and policy-admitted. | workspace missing, rebase blocked, untrusted ref requires isolated workspace. |
357
+ | `RunnerAssigned` | Execution host/pool accepted the attempt. | no capacity, forbidden runner, queue timeout. |
358
+ | `AgentMuxSessionBound` | Agent Mux run/session IDs are attached. | gateway unavailable, pending handoff, launch failed. |
359
+ | `ApprovalSatisfied` | Required human gates are resolved for current phase. | waiting on tool/write-back/secret/network/release approval. |
360
+ | `ArtifactsIndexed` | Produced outputs are durable and linked. | missing patch, review artifact parse failed, upload failed. |
361
+
362
+ ## Controller admission sequence
363
+
364
+ 1. Resolve actor, source repository, trust boundary, and event source.
365
+ 2. Load `AgentTriggerRule` or manual dispatch request.
366
+ 3. Snapshot `AgentStack` and referenced tool/MCP/skill/subagent/context-label resources.
367
+ 4. Validate adapter capabilities, native Kubernetes RBAC, runtime ServiceAccount, Secret grants, and ConfigMap grants.
368
+ 5. Assemble bounded context bundle and record digest before launch.
369
+ 6. Select or provision workspace using `AgentWorkspacePolicy`.
370
+ 7. Select runner/execution host, verify runner ServiceAccount, and enforce untrusted/fork isolation.
371
+ 8. Create `AgentDispatchRun` and initial `AgentDispatchAttempt`.
372
+ 9. Launch through Agent Mux and bind run/session IDs when available.
373
+ 10. Stream events into status, artifacts, approvals, and work item/session/workspace links.
374
+
375
+ ## Trigger management requirements
376
+
377
+ - Trigger rules are managed resources, not hidden UI settings.
378
+ - Incoming webhooks must create durable delivery records before rule evaluation.
379
+ - Trigger rules must support dry-run/testing against a sample event.
380
+ - Every trigger execution must record matched rule, source event, context bundle digest, agent stack snapshot, dedupe decision, approval decision, and created dispatch run.
381
+ - Disabled, paused, archived, and draft trigger states must be explicit.
382
+ - Rule actions should include enable, pause, resume, disable, archive/delete, replay delivery, and materialize work item without dispatch.
383
+
384
+ ## Tool and capability validation
385
+
386
+ Before dispatch, Krate must validate:
387
+
388
+ 1. Selected `AgentStack` is valid for the adapter capabilities.
389
+ 2. Required MCP servers are available and allowed for repository/ref/trust tier.
390
+ 3. Skills are compatible with the base agent and task kind.
391
+ 4. Subagents do not exceed adapter/runtime concurrency limits.
392
+ 5. Tool profile is compatible with runner trust tier and fork/untrusted status.
393
+ 6. Runtime ServiceAccount and runner ServiceAccount are admitted by native Kubernetes RBAC.
394
+ 7. Required Secret keys have matching `AgentSecretGrant` records for the selected subject, repository, ref, and trigger source.
395
+ 8. Required ConfigMap keys have matching `AgentConfigGrant` records for the selected subject, repository, ref, and trigger source.
396
+ 9. Secrets and environment refs are allowed by policy.
397
+ 10. Approval mode is allowed for the source trigger and actor.
398
+
399
+ ## CI-like run projection
400
+
401
+ `AgentDispatchRun` should share the mental model of `Pipeline` and `Job`:
402
+
403
+ - listable in repository pipeline/check views;
404
+ - filterable by status, source, agent stack, task kind, runner pool, branch, PR, issue, and trigger rule;
405
+ - streamable through watch/SSE;
406
+ - has attempts, artifacts, logs/events, queue timing, runner placement, and status;
407
+ - can be cancelled, retried, resumed, or continued when the adapter supports it;
408
+ - links to Agent Mux chat/session for transcript and continuation;
409
+ - posts back to checks/PR/issues only through explicit write-back policy.
410
+
411
+ ## Agent Mux boundary
412
+
413
+ Krate should not reimplement adapter internals. It should:
414
+
415
+ - store desired stack/tool/trigger policy;
416
+ - validate against Agent Mux adapter capabilities;
417
+ - launch through Agent Mux gateway/client;
418
+ - subscribe to Agent Mux run/session events;
419
+ - link Agent Mux session IDs to Krate work items and dispatch attempts;
420
+ - surface Agent Mux chat and runtime state inside Krate pages;
421
+ - keep repository, trigger, approval, runner, and audit state in Krate.