@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,324 @@
1
+ # Agent orchestration implementation blueprint
2
+
3
+ ## Purpose
4
+
5
+ This document converts the agent orchestration specs into a concrete Krate implementation plan. It is intentionally docs-only: it names the files, resources, controllers, API routes, UI routes, chart surfaces, tests, and rollout order that should be touched when implementation starts.
6
+
7
+ The target experience is repository-native and GitHub-like: agents appear inside Code, Issues, Pull Requests, Actions/Runs, Workspaces, Inbox, and Settings. Agent Mux provides adapter/session/chat/runtime primitives; Krate owns the resource graph, repository context, trigger policy, runner placement, approvals, audit, and UI projections.
8
+
9
+ ## Implementation boundaries
10
+
11
+ | Layer | Krate owns | Agent Mux owns |
12
+ | --- | --- | --- |
13
+ | Product graph | repositories, issues, PRs, pipelines, jobs, workspaces, approvals, artifacts, audit | adapter-specific session/run internals |
14
+ | Declarative config | `AgentStack`, tools, MCP servers, skills, subagents, trigger rules, context labels, workspace policy | adapter capability manifests and launch option validation |
15
+ | Execution records | `AgentDispatchRun`, attempts, context bundle snapshots, approval state, write-back state | transcript, runtime events, tool activity, continuation/cancel/fork/resume primitives |
16
+ | UI frame | GitHub-like Krate navigation, route hierarchy, resource forms, policy explanations | chat transcript, event timeline, runtime panels that can be embedded |
17
+ | Security | repository trust, runner class, native Kubernetes RBAC, service account admission, secret/config admission, write-back approval, audit | adapter/tool execution according to admitted launch options |
18
+
19
+ ## Existing Krate files to extend
20
+
21
+ ### Resource model
22
+
23
+ - `src/resource-model.js`
24
+ - Add config kinds to `CONFIG_KINDS`: `AgentStack`, `AgentSubagent`, `AgentToolProfile`, `AgentMcpServer`, `AgentSkill`, `AgentTriggerRule`, `AgentContextLabel`, `AgentWorkspacePolicy`, `AgentServiceAccount`, `AgentRoleBinding`, `AgentSecretGrant`, `AgentConfigGrant`.
25
+ - Add execution kinds to `AGGREGATED_KINDS`: `AgentDispatchRun`, `AgentDispatchAttempt`, `AgentSession`, `AgentWorkspace`, `AgentApproval`, `AgentContextBundle`, `AgentReviewArtifact`, `AgentArtifact`, `AgentTriggerExecution`, `AgentCapabilityRequirement`.
26
+ - Keep `status.conditions` in every schema so disabled UI states can be explained from resources.
27
+
28
+ ### Controllers and services
29
+
30
+ - `src/kubernetes-controller.js`
31
+ - Reconcile declarative agent config resources and expose them through the existing Krate resource gateway.
32
+ - Watch CRD-backed config changes and trigger validation refreshes.
33
+ - `src/api-controller.js`
34
+ - Add agent API routes through the existing controller boundary; do not bypass the Krate gateway from UI components.
35
+ - `src/controller-ui.js`
36
+ - Add agent dashboard cards, repository route view models, operational counters, and validation checks.
37
+ - Project dispatches beside existing `Pipeline` and `Job` resources.
38
+ - New `src/agent-stack-controller.js`
39
+ - Resolve Agent Mux capabilities, MCP health, skill validation, subagent compatibility, and policy admission.
40
+ - New `src/agent-trigger-controller.js`
41
+ - Normalize events, evaluate trigger rules, dry-run payloads, dedupe, coalesce, and create dispatch runs.
42
+ - New `src/agent-dispatch-controller.js`
43
+ - Create attempts, call Agent Mux, bind session/run IDs, reconcile event streams, artifacts, and final status.
44
+ - New `src/agent-workspace-controller.js`
45
+ - Provision/link/recover/archive/cleanup/rebase workspaces and maintain issue/session/workspace associations.
46
+ - New `src/agent-approval-controller.js`
47
+ - Gate shell/tool/network/secret/write-back/rebase/release operations and audit decisions.
48
+ - New `src/agent-rbac-controller.js`
49
+ - Sync Krate role/service-account intent to native Kubernetes ServiceAccounts, Roles, ClusterRoles, RoleBindings, and ClusterRoleBindings.
50
+ - New `src/agent-secret-config-controller.js`
51
+ - Validate Secret/ConfigMap grants, tool-secret and skill-secret requirements, ConfigMap injection, rotation impact, and missing-permission warnings.
52
+ - New `src/agent-permission-review.js`
53
+ - Produce a deterministic permission review for stack save, trigger dry-run, dispatch creation, and launch attempts.
54
+ - New `src/agent-mux-client.js`
55
+ - Thin adapter around Agent Mux gateway/client for capability lookup, launch, stream, continue, cancel, retry, fork, resume, and approval forwarding.
56
+
57
+ ### UI app routes
58
+
59
+ - `apps/web/app/agents/page.jsx`
60
+ - Global operations overview: active dispatches, pending approvals, trigger health, workspace attention, stack readiness.
61
+ - `apps/web/app/agents/stacks/page.jsx`
62
+ - Stack registry and builder for agent, model, prompt, approval mode, tools, MCP, skills, subagents, runner/workspace/write-back policy.
63
+ - `apps/web/app/agents/runs/page.jsx`
64
+ - Cross-repository CI-like dispatch queue.
65
+ - `apps/web/app/agents/runs/[run]/page.jsx`
66
+ - Dispatch detail with Agent Mux chat/session and observability panels.
67
+ - `apps/web/app/agents/rules/page.jsx`
68
+ - Trigger rule lifecycle, dry-run, delivery replay, execution summaries.
69
+ - `apps/web/app/agents/workspaces/page.jsx`
70
+ - Workspace inventory and attention mode.
71
+ - `apps/web/app/agents/approvals/page.jsx`
72
+ - Approval inbox and action-required queue.
73
+ - `apps/web/app/agents/identities/page.jsx`
74
+ - Users, teams, agent ServiceAccounts, runner ServiceAccounts, and native RBAC projection.
75
+ - `apps/web/app/agents/secrets/page.jsx`
76
+ - Secret/ConfigMap inventory, grants, consumers, rotation state, and missing-permission warnings without exposing Secret values.
77
+ - `apps/web/app/agents/permissions/page.jsx`
78
+ - Role templates, RoleBindings, ClusterRoleBindings, grant graph, drift, and escalation warnings.
79
+ - `apps/web/app/orgs/[org]/repositories/[repo]/settings/agents/page.jsx`
80
+ - Repository-scoped stack permissions, triggers, MCP/skill/tool allow-lists, runner policy, and secrets policy.
81
+ - Existing repository routes
82
+ - `code`: add path-aware manual dispatch and active workspace/session chips.
83
+ - `issues`: add board/list associations, context labels, dispatch readiness, linked sessions/workspaces/runs.
84
+ - `pull-requests`: add check diagnosis, review artifacts, patch proposals, and write-back approvals.
85
+ - `pipelines`: add agent dispatch rows beside pipeline/job rows.
86
+ - `hooks`: show trigger deliveries, replay, and rule matches.
87
+
88
+ ### API routes
89
+
90
+ - `GET/POST /api/agents/stacks`
91
+ - `GET/PATCH/DELETE /api/agents/stacks/:name`
92
+ - `GET /api/agents/capabilities`
93
+ - `GET /api/agents/identities`
94
+ - `POST /api/agents/identities/service-accounts`
95
+ - `GET /api/agents/permissions`
96
+ - `POST /api/agents/permissions/role-bindings`
97
+ - `POST /api/agents/permissions/review`
98
+ - `GET /api/agents/secrets`
99
+ - `POST /api/agents/secrets/grants`
100
+ - `POST /api/agents/config/grants`
101
+ - `GET/POST /api/agents/runs`
102
+ - `GET /api/agents/runs/:run`
103
+ - `GET /api/agents/runs/:run/events`
104
+ - `POST /api/agents/runs/:run/cancel`
105
+ - `POST /api/agents/runs/:run/continue`
106
+ - `POST /api/agents/runs/:run/retry`
107
+ - `POST /api/agents/runs/:run/fork`
108
+ - `GET/POST /api/agents/rules`
109
+ - `POST /api/agents/rules/:rule/dry-run`
110
+ - `POST /api/agents/rules/:rule/lifecycle`
111
+ - `GET/POST /api/agents/workspaces`
112
+ - `POST /api/agents/workspaces/:workspace/action`
113
+ - `GET /api/agents/approvals`
114
+ - `POST /api/agents/approvals/:approval/decision`
115
+ - `GET /api/watch/orgs/[org]/agentdispatchruns`
116
+ - `GET /api/watch/orgs/[org]/agentapprovals`
117
+ - `GET /api/watch/orgs/[org]/agentworkspaces`
118
+
119
+ API handlers should delegate to controller modules. They should not mutate hidden UI-only state.
120
+
121
+ ### Helm/chart/package surfaces
122
+
123
+ - `charts/krate/templates/crds.yaml`
124
+ - Add CRDs for low-cardinality config resources first, including `AgentServiceAccount`, `AgentRoleBinding`, `AgentSecretGrant`, and `AgentConfigGrant`.
125
+ - `charts/krate/values.yaml`
126
+ - Add Agent Mux gateway URL, execution mode, default runner pool, default agent ServiceAccount, Secret/ConfigMap grant feature gates, retention, and feature gates.
127
+ - `charts/krate/templates/deployment.yaml`
128
+ - Add environment for Agent Mux gateway, secrets policy, stream retention, and runner integration.
129
+ - `examples/`
130
+ - Add minimal `AgentStack`, `AgentTriggerRule`, `AgentContextLabel`, and manual dispatch examples.
131
+ - `dist/`
132
+ - Regenerate only through `npm run build` after implementation.
133
+
134
+ ## Detailed implementation specs
135
+
136
+ Start with:
137
+
138
+ - [Agent system overview](./system-overview.md) for the architecture summary and invariants.
139
+ - [Agent glossary](./glossary.md) for shared terminology.
140
+ - [Agent traceability matrix](./traceability-matrix.md) for requirement-to-file/test mapping.
141
+
142
+ Use these companion docs before writing code:
143
+
144
+ - [Agent CRD schema spec](./crd-schema-spec.md) for exact resource classification, required fields, conditions, labels, and storage classes.
145
+ - [Controller reconciliation spec](./controller-reconciliation-spec.md) for watches, outputs, idempotency keys, and failure handling.
146
+ - [API contract spec](./api-contract-spec.md) for typed endpoint contracts and compatibility with the existing controller/resource/watch routes.
147
+ - [UI flow and state spec](./ui-flow-spec.md) for repository-native UX flows and denied/missing-grant states.
148
+ - [Security threat model](./security-threat-model.md) for required mitigations.
149
+ - [Acceptance test matrix](./acceptance-test-matrix.md) for implementation gates.
150
+ - [Storage and migration spec](./storage-migration-spec.md) for persistence, indexing, snapshots, retention, and migrations.
151
+ - [Chart and packaging spec](./chart-packaging-spec.md) for Helm values, CRDs, RBAC, deployments, examples, and package validation.
152
+ - [Agent Mux adapter contract](./agent-mux-adapter-contract.md) for capability discovery, launch, event normalization, and UI embedding.
153
+ - [Implementation rollout slices](./implementation-rollout-slices.md) for incremental delivery order.
154
+ - [Context assembly and prompt safety spec](./context-assembly-spec.md) for prompt/source/redaction/digest handling.
155
+ - [Observability and audit spec](./observability-audit-spec.md) for events, metrics, traces, audit records, and alerts.
156
+ - [Repository page integration spec](./repository-page-integration-spec.md) for adding agent affordances to existing repository pages.
157
+ - [Tools, MCP, and skills spec](./tools-mcp-skills-spec.md) for capability dependencies and launch policy.
158
+ - [Subagent orchestration spec](./subagent-orchestration-spec.md) for parent/child execution and telemetry.
159
+ - [Artifacts and write-back spec](./artifacts-writeback-spec.md) for durable outputs and gated mutations.
160
+ - [Workspace lifecycle spec](./workspace-lifecycle-spec.md) for workspace/session/work item associations and recovery.
161
+ - [Resource relationship map](./resource-relationship-map.md) for cross-resource dependencies and deletion impact.
162
+ - [Operator runbook](./operator-runbook.md) for safe enablement, troubleshooting, and rollback.
163
+ - [Developer implementation checklist](./developer-implementation-checklist.md) for file-by-file rollout execution.
164
+ - [MVP vertical slice spec](./mvp-vertical-slice-spec.md) for the first coherent build target and non-negotiables.
165
+ - [Decision log and open questions](./decision-log-open-questions.md) for accepted decisions and unresolved choices.
166
+ ## Custom resources by storage class
167
+
168
+ ### CRD-backed configuration resources
169
+
170
+ | Kind | Storage | Why declarative |
171
+ | --- | --- | --- |
172
+ | `AgentStack` | etcd | reusable agent launch definition and policy envelope |
173
+ | `AgentSubagent` | etcd | reusable child-agent role definition |
174
+ | `AgentToolProfile` | etcd | audited native tool and command policy |
175
+ | `AgentMcpServer` | etcd | managed server endpoint, secret refs, and health status |
176
+ | `AgentSkill` | etcd | reusable runbook/prompt/tool dependency bundle |
177
+ | `AgentTriggerRule` | etcd | reviewable event-to-agent routing policy |
178
+ | `AgentContextLabel` | etcd | reviewed prompt fragment and provenance metadata |
179
+ | `AgentWorkspacePolicy` | etcd | workspace provisioning, cleanup, retention, and trust policy |
180
+ | `AgentServiceAccount` | etcd | native Kubernetes ServiceAccount identity for agents and runner pools |
181
+ | `AgentRoleBinding` | etcd | native Role/ClusterRole and RoleBinding/ClusterRoleBinding intent |
182
+ | `AgentSecretGrant` | etcd | explicit Secret key access for users, teams, agents, tools, skills, MCP servers, and runners |
183
+ | `AgentConfigGrant` | etcd | explicit ConfigMap key access for users, teams, agents, tools, skills, MCP servers, and runners |
184
+
185
+ ### Aggregated execution resources
186
+
187
+ | Kind | Storage | Why aggregated |
188
+ | --- | --- | --- |
189
+ | `AgentDispatchRun` | postgres | high-cardinality run state, source refs, artifacts, approvals, event cursor |
190
+ | `AgentDispatchAttempt` | postgres | retry/resume/fork attempts and Agent Mux session/run binding |
191
+ | `AgentSession` | postgres projection | durable session metadata linked to Agent Mux session IDs |
192
+ | `AgentWorkspace` | postgres projection | git worktree/runtime inventory and lifecycle state |
193
+ | `AgentApproval` | postgres | human-gate decisions and audit trail |
194
+ | `AgentContextBundle` | postgres/object storage | immutable context snapshot, prompt hash, attachment manifest |
195
+ | `AgentArtifact` | postgres/object storage | patches, logs, review artifacts, reports, subagent outputs |
196
+ | `AgentTriggerExecution` | postgres | webhook/rule evaluation, coalescing, rejection, and created-run links |
197
+ | `AgentCapabilityRequirement` | postgres projection | computed tool/MCP/skill/model/subagent requirements and missing grant warnings |
198
+
199
+ ## Controller graph
200
+
201
+ ```text
202
+ WebhookDelivery / CI event / issue or PR event / manual UI action
203
+ -> agent-trigger-controller
204
+ -> AgentTriggerExecution
205
+ -> AgentContextBundle
206
+ -> native RBAC + SecretGrant + ConfigGrant admission
207
+ -> AgentDispatchRun
208
+ -> AgentDispatchAttempt
209
+ -> agent-mux-client
210
+ -> Agent Mux run/session
211
+ -> stream/event reconciliation
212
+ -> AgentApproval / AgentArtifact / AgentWorkspace / WorkItem links
213
+ -> repository UI projections and write-back actions
214
+ ```
215
+
216
+ Controllers should be restart-safe. Every external side effect needs an idempotency key derived from source event, trigger rule, stack snapshot, context digest, and attempt number.
217
+
218
+ ## User-flow acceptance contracts
219
+
220
+ ### Manual code dispatch
221
+
222
+ 1. User opens `/orgs/[org]/repositories/[repo]/code`.
223
+ 2. User selects files/folder/ref and clicks `Dispatch agent`.
224
+ 3. UI shows stack, context labels, workspace policy, prompt preview, and write-back policy.
225
+ 4. Krate creates `AgentDispatchRun` and `AgentDispatchAttempt` before Agent Mux launch.
226
+ 5. Run appears in repository pipelines and `/agents/runs`.
227
+ 6. Detail page shows pending handoff, then chat/session once bound.
228
+
229
+ ### Failed CI repair
230
+
231
+ 1. Pipeline/job fails and creates/updates a durable CI event.
232
+ 2. `AgentTriggerRule` matches workflow/job/step/failure signature.
233
+ 3. Trigger controller creates `AgentTriggerExecution`; dedupe may coalesce into an existing run.
234
+ 4. Dispatch uses untrusted runner policy for forked refs and privileged runner policy only for trusted refs.
235
+ 5. Agent output becomes artifacts and approval requests.
236
+ 6. PR comments, branch pushes, check reruns, and review submissions happen only after allowed write-back approval.
237
+
238
+ ### Issue or PR mention dispatch
239
+
240
+ 1. User mentions an agent or applies a dispatch label.
241
+ 2. Krate records source actor, comment/label payload, repository trust, and context label set.
242
+ 3. Rule dry-run preview shows task kind, prompt fragments, attachments, and dedupe key.
243
+ 4. Dispatch links back to the issue/PR and optional workspace.
244
+ 5. Chat/session stays reachable from the issue/PR, workspace, run, and global session list.
245
+
246
+ ### Subagent orchestration
247
+
248
+ 1. Parent `AgentStack` declares allowed subagents and concurrency limits.
249
+ 2. Agent Mux reports whether adapter supports subagent dispatch or Krate emulates it as child dispatch attempts.
250
+ 3. UI shows subagent lanes with status, context slice, output contract, artifacts, and parent decision impact.
251
+ 4. Child output is immutable and linked to the parent attempt.
252
+
253
+ ### Tool, MCP, and skill management
254
+
255
+ 1. Stack builder validates tools, MCP servers, skills, and subagents before dispatch.
256
+ 2. Execution context panel shows exactly what was injected into the prompt and launch options.
257
+ 3. Tool/MCP/skill errors surface as `status.conditions`, not only toast notifications.
258
+ 4. Disabling a tool/MCP/skill invalidates dependent stacks and rules until remediated.
259
+
260
+ ## Rollout order
261
+
262
+ 1. Add resource definitions, schemas, examples, and chart CRDs for config resources, including native RBAC/service-account/secret/config grant resources.
263
+ 2. Add read-only UI projections and empty states in repository routes.
264
+ 3. Add stack registry with Agent Mux capability validation and native RBAC/Secret/ConfigMap readiness checks.
265
+ 4. Add manual dispatch from repository code page and dispatch run list/detail.
266
+ 5. Add Agent Mux session binding, chat, event stream, and observability panel.
267
+ 6. Add approvals, write-back gates, service-account binding, Secret grants, ConfigMap grants, and role-binding management.
268
+ 7. Add trigger rules, dry-run, webhook deliveries, CI failure matching, and dedupe/coalescing.
269
+ 8. Add workspace provisioning/recovery/rebase lifecycle and issue/session/workspace association graph.
270
+ 9. Add subagent lanes, MCP health, skill validation, cost/usage, retention, and audit hardening.
271
+
272
+ ## Test and validation plan
273
+
274
+ - Unit tests for resource schemas, status conditions, trigger matchers, context bundle assembly, native RBAC admission, SecretGrant/ConfigGrant admission, and policy admission.
275
+ - Controller tests for idempotent dispatch creation, retry/resume/fork, workspace lifecycle, and approval decisions.
276
+ - API tests for every route listed above with denied/allowed policy cases, including missing Secret/ConfigMap/Role access.
277
+ - UI validation for GitHub-like route hierarchy, empty states, disabled actions, permission review explanations, missing-grant warnings, reconnect states, pending handoff, and approval-blocked runs.
278
+ - E2E tests for manual dispatch, failed CI dispatch, issue mention dispatch, workspace recovery, and write-back approval.
279
+ - Package/chart validation to ensure CRDs, examples, and Helm values stay in sync.
280
+
281
+ ## Done criteria for the first production-ready slice
282
+
283
+ - A repository admin can create a Claude Code `AgentStack` with tools, MCP servers, skills, subagents, runtime ServiceAccount, runner ServiceAccount, Secret grants, ConfigMap grants, runner policy, and approval mode.
284
+ - A user can manually dispatch it from a repository page and see a CI-like run.
285
+ - The run binds to Agent Mux chat/session and streams events without losing source breadcrumbs.
286
+ - Pending approvals block privileged actions and can be decided from the run page or approval inbox.
287
+ - Workspace/session/run associations are visible from the source issue/PR/code/pipeline page and from global agent pages.
288
+ - Every UI action maps to a resource/action/controller/watch path documented in these specs.
289
+ - A stack that enables a tool/skill/MCP server requiring a Secret or ConfigMap shows a blocking warning until the selected agent identity has the matching grant.
290
+
291
+ ## Company brain memory implementation slice
292
+
293
+ When implementation begins, add memory after the basic dispatch/context slice but before broad trigger automation:
294
+
295
+ 1. Add `AgentMemoryRepository`, `AgentMemorySource`, `AgentMemoryOntology`, and `AgentMemoryAssociation` to `src/resource-model.js` and CRDs.
296
+ 2. Add aggregated `AgentMemorySnapshot`, `AgentMemoryQuery`, and `AgentMemoryUpdate` storage.
297
+ 3. Add memory ref resolution and query actions to `src/api-controller.js`.
298
+ 4. Extend context assembly to add memory source manifests to `AgentContextBundle`.
299
+ 5. Expose `/agents/memory` and repository settings associations in `src/controller-ui.js`.
300
+ 6. Gate Agent Mux memory tools through stack capability and permission review.
301
+ 7. Add validators for graph YAML, Markdown frontmatter, free-form path policy, ontology, indexes, and secret scans.
302
+
303
+ ## Org-scoped resource implementation prerequisites
304
+
305
+ Before implementing company brain memory, Krate should add org scoping foundations:
306
+
307
+ 1. Add `Organization`, `OrgNamespaceBinding`, and org labels to the resource model.
308
+ 2. Make repository, deployment, agent, runner, memory, secret, config, session, workspace, and audit resources resolve `organizationRef`.
309
+ 3. Keep API routes org-addressed and return not found for non-org repository paths.
310
+ 4. Update controllers to reject cross-org references and use org namespace ServiceAccounts.
311
+ 5. Add `AgentRunMemoryImport` for curated `MEMORY.md`, session, journal, task, and artifact-manifest imports into the org memory repo.
312
+
313
+ ## Current app org-route alignment
314
+
315
+ The current app already exposes an org-scoped route tree under `apps/web/app/orgs/[org]` and org-scoped resource APIs under `apps/web/app/api/orgs/[org]`. Agent implementation should extend this tree instead of introducing global agent pages first.
316
+
317
+ Implementation deltas:
318
+
319
+ 1. Add `Agents` to `orgNavigation` in `apps/web/app/ui-shell.jsx`.
320
+ 2. Add routes under `apps/web/app/orgs/[org]/agents/*`.
321
+ 3. Add repository page links from existing Code, Issues, Pull Requests, Runs, Hooks, and Settings pages into org-scoped agent routes.
322
+ 4. Add org-scoped memory APIs under `apps/web/app/api/orgs/[org]/agents/memory/*`.
323
+ 5. Preserve existing generic `/api/orgs/[org]/resources` behavior for YAML/resource views.
324
+ 6. Keep advanced resource panels as escape hatches, but make normal memory/agent flows task-led.
@@ -0,0 +1,251 @@
1
+ # Agent implementation rollout slices
2
+
3
+ ## Purpose
4
+
5
+ This document turns the specs into incremental implementation slices. Each slice must leave Krate usable, respect the current app architecture, and keep tests/package validation green.
6
+
7
+ ## Slice 0: docs and resource alignment
8
+
9
+ Status: current docs-only work.
10
+
11
+ Deliverables:
12
+
13
+ - agent docs indexed in `docs/agents/README.md`;
14
+ - CRD schema, controller, API, UI, security, storage, chart, adapter, and acceptance specs;
15
+ - no runtime behavior changes.
16
+
17
+ Validation:
18
+
19
+ - `npm run validate:docs`;
20
+ - `npm run package:check`.
21
+
22
+ ## Slice 1: resource definitions and chart CRDs
23
+
24
+ Deliverables:
25
+
26
+ - add agent config kinds to `src/resource-model.js`;
27
+ - add agent resource entries to `src/kubernetes-controller.js` `KRATE_RESOURCES`;
28
+ - add chart CRDs for config resources;
29
+ - add examples under `examples/agents/`;
30
+ - update package validator required terms/kinds when appropriate.
31
+
32
+ UI impact:
33
+
34
+ - generic advanced resource tables can list/apply agent resources.
35
+ - no typed agent pages yet.
36
+
37
+ Tests:
38
+
39
+ - resource schema tests;
40
+ - package/chart validation;
41
+ - existing UI validation.
42
+
43
+ ## Slice 2: read-only UI projection
44
+
45
+ Deliverables:
46
+
47
+ - extend `src/controller-ui.js` with `views.agents` summary;
48
+ - add `/agents` overview page;
49
+ - add repository route affordance slots for Code, Issues, PRs, Pipelines, Hooks, Settings;
50
+ - show empty states and disabled actions backed by missing resources.
51
+
52
+ UI impact:
53
+
54
+ - users can see where agent features will appear without mock data.
55
+
56
+ Tests:
57
+
58
+ - `npm run ui:validate`;
59
+ - route render tests if available;
60
+ - no Agent Mux dependency.
61
+
62
+ ## Slice 3: RBAC and permission review MVP
63
+
64
+ Deliverables:
65
+
66
+ - add `AgentServiceAccount`, `AgentRoleBinding`, `AgentSecretGrant`, `AgentConfigGrant` support;
67
+ - add `src/agent-permission-review.js`;
68
+ - add `POST /api/agents/permissions/review`;
69
+ - add stack builder warning model for missing grants.
70
+
71
+ UI impact:
72
+
73
+ - `/agents/identities`, `/agents/secrets`, `/agents/permissions` can start as read-only + review panels.
74
+ - repository settings can show ServiceAccount/grant requirements.
75
+
76
+ Tests:
77
+
78
+ - missing Secret grant denied;
79
+ - role escalation denied;
80
+ - no Secret values in responses.
81
+
82
+ ## Slice 4: stack registry MVP
83
+
84
+ Deliverables:
85
+
86
+ - implement stack CRUD through typed routes or generic apply wrappers;
87
+ - query Agent Mux capabilities if configured;
88
+ - compute `AgentCapabilityRequirement`;
89
+ - update stack readiness conditions.
90
+
91
+ UI impact:
92
+
93
+ - `/agents/stacks` builder can create a usable stack.
94
+
95
+ Tests:
96
+
97
+ - ready stack;
98
+ - missing MCP/skill/tool/permission blocks readiness;
99
+ - YAML preview matches applied resources.
100
+
101
+ ## Slice 5: manual dispatch MVP
102
+
103
+ Deliverables:
104
+
105
+ - add `AgentDispatchRun`, `AgentDispatchAttempt`, `AgentContextBundle` creation;
106
+ - add manual dispatch API;
107
+ - add dispatch composer in repository Code page;
108
+ - create runs before Agent Mux launch.
109
+
110
+ UI impact:
111
+
112
+ - run appears in `/agents/runs` and repository Runs page.
113
+ - run detail can show queued/pending state.
114
+
115
+ Tests:
116
+
117
+ - manual dispatch creates run/attempt/context/permission snapshot;
118
+ - denied permission blocks run creation or creates rejected execution as designed.
119
+
120
+ ## Slice 6: Agent Mux session binding
121
+
122
+ Deliverables:
123
+
124
+ - add `src/agent-mux-client.js`;
125
+ - launch Agent Mux run/session;
126
+ - bind IDs to attempts;
127
+ - stream events into run detail;
128
+ - embed transcript/observability panels.
129
+
130
+ UI impact:
131
+
132
+ - run detail becomes CI check page + Agent Mux chat.
133
+
134
+ Tests:
135
+
136
+ - gateway unavailable fallback;
137
+ - pending session handoff;
138
+ - stream reconnect state;
139
+ - launch rejected state.
140
+
141
+ ## Slice 7: approvals and write-back
142
+
143
+ Deliverables:
144
+
145
+ - add `AgentApproval` action flow;
146
+ - implement approval inbox;
147
+ - gate PR comments, branch pushes, check reruns, review submissions;
148
+ - audit decisions and idempotency.
149
+
150
+ UI impact:
151
+
152
+ - pending approvals appear globally and in run detail.
153
+
154
+ Tests:
155
+
156
+ - approval required;
157
+ - wrong approver denied;
158
+ - artifact digest mismatch denied;
159
+ - idempotent write-back.
160
+
161
+ ## Slice 8: trigger rules and CI integration
162
+
163
+ Deliverables:
164
+
165
+ - add `AgentTriggerRule` evaluation;
166
+ - add dry-run/replay;
167
+ - connect failed `Pipeline`/`Job`, issue/PR comments, labels, schedules, webhooks;
168
+ - create `AgentTriggerExecution` records.
169
+
170
+ UI impact:
171
+
172
+ - `/agents/rules` and repo hooks/settings show trigger health.
173
+ - agent runs appear beside CI runs.
174
+
175
+ Tests:
176
+
177
+ - failed CI dispatch;
178
+ - duplicate failure coalesced;
179
+ - fork PR forced untrusted;
180
+ - trigger dry-run output.
181
+
182
+ ## Slice 9: workspace/session/work item graph
183
+
184
+ Deliverables:
185
+
186
+ - implement `AgentWorkspace`, `WorkItemSessionLink`, `WorkItemWorkspaceLink`;
187
+ - add workspace provisioning/recovery/rebase actions;
188
+ - link issue/PR/run/session/workspace views.
189
+
190
+ UI impact:
191
+
192
+ - issue/session/workspace associations behave like Agent Mux kanban, but inside Krate repository hierarchy.
193
+
194
+ Tests:
195
+
196
+ - create issue workspace;
197
+ - link session to issue;
198
+ - missing workspace recovery;
199
+ - rebase conflict state.
200
+
201
+ ## Slice 10: production hardening
202
+
203
+ Deliverables:
204
+
205
+ - retention jobs;
206
+ - metrics;
207
+ - audit exports;
208
+ - chart values finalized;
209
+ - network policy for Agent Mux/MCP;
210
+ - scale/performance tuning;
211
+ - e2e suite in CI.
212
+
213
+ Done gate:
214
+
215
+ - `npm run check` green;
216
+ - chart package validation includes agent CRDs/examples;
217
+ - documented threat model mitigations covered by tests.
218
+
219
+ ## Company brain memory slice
220
+
221
+ - Add memory resources and read-only UI first: repository health, ontology status, graph browse, and grep search.
222
+ - Add context integration next: `AgentMemorySnapshot`, `AgentMemoryQuery`, context preview, and run detail provenance.
223
+ - Add historical refs: explicit ref, snapshot tag, and `refAt` timestamp resolution.
224
+ - Add tool exposure: graph search, record read, docs grep, snapshot diff, update propose, ontology validate.
225
+ - Add write-back last: proposed PRs, validation reports, approval, merge, rollback, and audit.
226
+
227
+ ## Org-scoped foundation slice
228
+
229
+ This slice must land before memory write-back and broad automation:
230
+
231
+ 1. Introduce `Organization` and `OrgNamespaceBinding` resources.
232
+ 2. Add org-aware routes and compatibility redirects.
233
+ 3. Add `organizationRef` and org labels to repository, deployment, agent, runner, memory, session, workspace, secret, and config resources.
234
+ 4. Add admission checks for same-org references.
235
+ 5. Add org-scoped watch filters and audit fields.
236
+ 6. Add `AgentRunMemoryImport` only after namespace enforcement is in place.
237
+
238
+ ## Org memory vertical slice rollout
239
+
240
+ The first implementation slice should prove one org, one repo, one company brain, one manual dispatch, one memory snapshot, and one summary-only run-memory import:
241
+
242
+ 1. enable org/resource model additions and CRD examples;
243
+ 2. create org memory dashboard empty state;
244
+ 3. configure `AgentMemoryRepository` and `AgentMemorySource` for one repo;
245
+ 4. dispatch manually from repository Code page with memory preview;
246
+ 5. show memory snapshot on run detail;
247
+ 6. import summary-only `MEMORY.md`/session/run metadata through `AgentRunMemoryImport`;
248
+ 7. query imported run memory in a later dispatch;
249
+ 8. prove cross-org memory access is denied.
250
+
251
+ Do not implement broad trigger automation, raw artifact retention, or cross-org sharing in this slice.