@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,88 @@
1
+ # Agent system overview
2
+
3
+ ## Purpose
4
+
5
+ This document is the short entry point for the full agent orchestration spec set. It explains the product shape, implementation boundaries, and first build target without requiring readers to open every detailed spec first.
6
+
7
+ ## Product thesis
8
+
9
+ Krate agents are repository-native work executors. They should feel like a CI run plus a durable chat/session: queued on runner capacity, scoped to a repository/ref/source object, governed by Kubernetes-native RBAC and grants, observable in real time, artifact-producing, approval-gated, and linked back to Code, Issues, Pull Requests, Runs, Hooks, Workspaces, Inbox, and Settings.
10
+
11
+ Agent Mux provides adapter/session/chat/runtime capabilities. Krate owns the repository graph, resource model, policy, triggers, RBAC, secret/config grants, context assembly, dispatch run state, approvals, artifacts, audit, and UI hierarchy.
12
+
13
+ ## Big picture flow
14
+
15
+ ```text
16
+ Repository/PR/Issue/Pipeline/Webhook/manual action
17
+ -> trigger or manual dispatch request
18
+ -> context assembly and redaction
19
+ -> permission review
20
+ -> AgentDispatchRun and AgentDispatchAttempt
21
+ -> Agent Mux launch/session binding
22
+ -> event/transcript/artifact reconciliation
23
+ -> approvals and optional write-back
24
+ -> repository page projections and audit
25
+ ```
26
+
27
+ ## Main resource families
28
+
29
+ | Family | Resources | Why it exists |
30
+ | --- | --- | --- |
31
+ | Stack config | `AgentStack`, `AgentToolProfile`, `AgentMcpServer`, `AgentSkill`, `AgentSubagent` | defines what can run. |
32
+ | Permission config | `AgentServiceAccount`, `AgentRoleBinding`, `AgentSecretGrant`, `AgentConfigGrant` | defines who/what can access roles, secrets, config, and runners. |
33
+ | Trigger config | `AgentTriggerRule`, `AgentContextLabel`, `AgentWorkspacePolicy` | defines when/how context and workspace are selected. |
34
+ | Execution records | `AgentDispatchRun`, `AgentDispatchAttempt`, `AgentSession`, `AgentTriggerExecution` | tracks work like CI runs. |
35
+ | Context/artifacts | `AgentContextBundle`, `AgentArtifact`, `AgentReviewArtifact` | makes prompts and outputs durable/auditable. |
36
+ | Human gates | `AgentApproval` | gates tools, secrets, write-back, release actions, and risky operations. |
37
+ | Work graph links | `AgentWorkspace`, `WorkItemSessionLink`, `WorkItemWorkspaceLink` | connects sessions/workspaces/runs to issues, PRs, and repository pages. |
38
+
39
+ ## First build target
40
+
41
+ The MVP is intentionally narrow:
42
+
43
+ 1. Define one read-only/diagnostic stack.
44
+ 2. Validate Kubernetes-native ServiceAccount/RBAC/Secret/Config access.
45
+ 3. Dispatch manually from Code or Runs.
46
+ 4. Create `AgentDispatchRun`, `AgentDispatchAttempt`, context bundle, and permission snapshot before Agent Mux launch.
47
+ 5. Show the run beside CI runs and in `/agents/runs`.
48
+ 6. Bind Agent Mux session if configured; otherwise show a clear degraded state.
49
+
50
+ Deferred from MVP: auto triggers, write-back, branch pushes, full workspace lifecycle, subagent execution, retention jobs, and production MCP management.
51
+
52
+ ## Existing Krate seams to preserve
53
+
54
+ - `src/resource-model.js` remains the kind/schema source of truth.
55
+ - `src/kubernetes-controller.js` remains the Kubernetes-style resource gateway.
56
+ - `src/api-controller.js` remains the HTTP/application facade.
57
+ - `src/controller-ui.js` remains the server-projected UI model.
58
+ - `/api/controller/resources` remains the generic list/apply path.
59
+ - `/api/watch/orgs/[org]/*` is the watch/SSE pattern.
60
+ - Repository routes stay under `/orgs/[org]/repositories/[repo]/...`.
61
+
62
+ Typed agent APIs and pages should wrap these seams, not bypass them.
63
+
64
+ ## Safety invariants
65
+
66
+ - No Secret values in browser, prompt preview, status, logs, audit, or docs examples.
67
+ - Kubernetes RBAC remains authoritative.
68
+ - Labels/comments/context labels cannot grant permissions.
69
+ - Untrusted/forked refs cannot use privileged ServiceAccounts or secrets.
70
+ - Agent output cannot write back without policy and approval.
71
+ - Agent Mux is not source of truth for Krate repository objects.
72
+ - Every visible UI action maps to resource/action/controller/watch state.
73
+
74
+ ## Where to read next
75
+
76
+ - Start implementation with [MVP vertical slice spec](./mvp-vertical-slice-spec.md).
77
+ - Add kinds from [Agent CRD schema spec](./crd-schema-spec.md).
78
+ - Add controllers from [Controller reconciliation spec](./controller-reconciliation-spec.md).
79
+ - Use [API contract spec](./api-contract-spec.md) for route bodies.
80
+ - Use [UI flow and state spec](./ui-flow-spec.md) for screens.
81
+ - Use [Security threat model](./security-threat-model.md) before enabling write-back or secrets.
82
+ - Use [Developer implementation checklist](./developer-implementation-checklist.md) as the execution checklist.
83
+
84
+ ## Company brain memory layer
85
+
86
+ Krate should include an org-level company brain as a first-class context source. The company brain is a managed internal Git repository containing Atlas-style YAML graph records, Markdown files with YAML frontmatter, ontology definitions, and free-form Markdown notes searchable with grep. Dispatches can read current memory or a historical memory ref, and every selected memory item is captured in `AgentContextBundle` through `AgentMemorySnapshot` and `AgentMemoryQuery` records.
87
+
88
+ This layer belongs to Krate's repository and policy plane: Krate owns memory repository configuration, RBAC, path/kind grants, ref resolution, context digests, update approvals, validation, and audit. Agent Mux may execute memory tools inside a session only after Krate admits those capabilities.
@@ -0,0 +1,189 @@
1
+ # Agent tools, MCP, and skills spec
2
+
3
+ ## Purpose
4
+
5
+ This document defines how Krate should manage native tools, MCP servers, and skills as first-class system capabilities. Tools, MCP servers, and skills are not just UI settings; they affect launch options, permission review, Secret/ConfigMap requirements, audit, and dispatch readiness.
6
+
7
+ ## Resource ownership
8
+
9
+ | Capability | Resource | Scope |
10
+ | --- | --- | --- |
11
+ | Native tools and shell/filesystem/network policy | `AgentToolProfile` | stack/repository/org |
12
+ | MCP server endpoint and discovered tools | `AgentMcpServer` | global/org/repository/stack |
13
+ | Reusable runbook or prompt/tool bundle | `AgentSkill` | global/org/repository/stack |
14
+ | Required roles/secrets/configs | `AgentCapabilityRequirement` | computed per stack/capability |
15
+ | Secret access | `AgentSecretGrant` | subject + purpose + source scope |
16
+ | Config access | `AgentConfigGrant` | subject + purpose + source scope |
17
+
18
+ ## `AgentToolProfile`
19
+
20
+ Tool profiles should describe categories, not raw prompt text.
21
+
22
+ Required concerns:
23
+
24
+ - native tool enablement: shell, filesystem, browser, code search, git, test runner, package manager;
25
+ - filesystem scope: no-fs, read-only, repo-write, workspace-write;
26
+ - network scope: deny, allowlist, repository-host-only, unrestricted-with-approval;
27
+ - command allow/deny lists;
28
+ - approval policy by tool class;
29
+ - required roles;
30
+ - required Secret/ConfigMap refs;
31
+ - audit level.
32
+
33
+ Readiness checks:
34
+
35
+ - command deny patterns compile;
36
+ - filesystem policy compatible with runner trust tier;
37
+ - network policy compatible with repository policy;
38
+ - required roles admitted;
39
+ - required Secret/ConfigMap grants admitted;
40
+ - adapter supports requested native tools.
41
+
42
+ ## `AgentMcpServer`
43
+
44
+ MCP servers should be managed as runtime dependencies with health and permission state.
45
+
46
+ Required concerns:
47
+
48
+ - transport: stdio, SSE, streamable HTTP;
49
+ - command/args or URL;
50
+ - env refs and header refs;
51
+ - Secret/ConfigMap refs;
52
+ - discovered tools and schemas;
53
+ - allowed stacks/orgs/[org]/repositories;
54
+ - network policy;
55
+ - approval policy;
56
+ - health and last probe.
57
+
58
+ MCP health states:
59
+
60
+ - `Unknown`: not probed yet;
61
+ - `Ready`: reachable and schema discovered;
62
+ - `Degraded`: reachable but some tools unavailable;
63
+ - `Denied`: policy/RBAC/grant blocked;
64
+ - `Failed`: probe failed;
65
+ - `Disabled`: lifecycle disabled.
66
+
67
+ ## `AgentSkill`
68
+
69
+ Skills should behave like reusable capability bundles.
70
+
71
+ Skill fields:
72
+
73
+ - description and owner;
74
+ - source format: file, directory, package, inline;
75
+ - source ref and version;
76
+ - prompt fragment;
77
+ - required tools;
78
+ - required MCP servers;
79
+ - required Secret/ConfigMap refs;
80
+ - compatible base agents/adapters;
81
+ - task kinds;
82
+ - output contract;
83
+ - validation status.
84
+
85
+ Skill validation:
86
+
87
+ 1. Source exists and version resolves.
88
+ 2. Prompt fragment passes policy checks.
89
+ 3. Required tools/MCP servers exist and are admitted.
90
+ 4. Required Secret/ConfigMap grants exist for selected stack identity.
91
+ 5. Output contract is compatible with task kind and UI projection.
92
+
93
+ ## Capability requirement graph
94
+
95
+ Every stack should have a computed dependency graph:
96
+
97
+ ```text
98
+ AgentStack
99
+ -> AgentToolProfile
100
+ -> required roles/secrets/configs
101
+ -> AgentMcpServer
102
+ -> transport/network/secrets/configs/discovered tools
103
+ -> AgentSkill
104
+ -> prompt fragment/tools/MCP/secrets/configs/output contract
105
+ -> AgentSubagent
106
+ -> tool subset/skill subset/MCP subset
107
+ ```
108
+
109
+ The graph should produce `AgentCapabilityRequirement` records and UI warnings.
110
+
111
+ ## UI requirements
112
+
113
+ ### Tools page
114
+
115
+ - list tool profiles;
116
+ - show allowed/denied commands;
117
+ - show filesystem/network policy;
118
+ - show consuming stacks;
119
+ - show required grants and missing grants;
120
+ - preview launch impact.
121
+
122
+ ### MCP page
123
+
124
+ - list servers and health;
125
+ - show discovered tools;
126
+ - show Secret/ConfigMap refs without values;
127
+ - show allowed stacks and denied stacks;
128
+ - run probe/dry-run when authorized.
129
+
130
+ ### Skills page
131
+
132
+ - list skills by task kind;
133
+ - show prompt fragment preview;
134
+ - show required tools/MCP/secrets/configs;
135
+ - show consuming stacks;
136
+ - show validation errors and output contract.
137
+
138
+ ### Stack builder integration
139
+
140
+ The stack builder must show tools/MCP/skills as dependency cards with:
141
+
142
+ - readiness;
143
+ - missing roles/secrets/configs;
144
+ - adapter support;
145
+ - approval requirements;
146
+ - launch option preview;
147
+ - audit level.
148
+
149
+ ## Dispatch-time behavior
150
+
151
+ At dispatch launch:
152
+
153
+ 1. Expand selected tools, MCP servers, and skills.
154
+ 2. Re-run permission review.
155
+ 3. Materialize only admitted launch options.
156
+ 4. Snapshot dependency graph digest.
157
+ 5. Send admitted tool/MCP/skill configuration to Agent Mux.
158
+ 6. Record tool/MCP/skill versions in attempt status.
159
+
160
+ ## Security rules
161
+
162
+ - A skill cannot grant tools, roles, secrets, configs, or approval mode by prompt text.
163
+ - MCP server command/env/header refs must use grants and policy.
164
+ - Shell tools default to approval for privileged commands.
165
+ - Network access defaults to deny or allowlist.
166
+ - Tool output containing suspected secrets must be redacted before transcript/artifact persistence.
167
+
168
+ ## Acceptance criteria
169
+
170
+ - A stack cannot dispatch with a tool requiring an ungranted Secret.
171
+ - MCP health and discovered tools are visible before dispatch.
172
+ - Skills show required tools/MCP/secrets/configs and output contract.
173
+ - Tool/MCP/skill launch options are snapshotted into dispatch attempts.
174
+ - UI can explain exactly why a capability is disabled or approval-gated.
175
+
176
+ ## Company brain memory tools
177
+
178
+ Memory tools are normal tool capabilities and require the same stack admission, permission review, audit, and Agent Mux launch gating as other tools.
179
+
180
+ | Tool | Purpose | Required grant |
181
+ | --- | --- | --- |
182
+ | `memory.graph.search` | search graph records by text, kind, edge, owner, repo, stack, or association | memory query grant for allowed kinds/paths. |
183
+ | `memory.record.read` | read a graph or Markdown record by ID/path at the dispatch memory ref | memory read grant. |
184
+ | `memory.docs.grep` | grep allowed free-form Markdown paths at the pinned commit | memory grep grant. |
185
+ | `memory.snapshot.diff` | compare pinned memory with current or another ref | memory diff grant. |
186
+ | `memory.update.propose` | create a proposed memory patch artifact | memory propose-update grant. |
187
+ | `memory.ontology.validate` | validate proposed graph/frontmatter changes | memory validation grant. |
188
+
189
+ Tools default to the dispatch `AgentMemorySnapshot`. Accessing current memory from a historical-memory run requires explicit refresh or approval so agents cannot silently escape the pinned context.
@@ -0,0 +1,79 @@
1
+ # Agent traceability matrix
2
+
3
+ ## Purpose
4
+
5
+ This matrix maps product requirements to resources, controllers, UI surfaces, docs, and validation gates. It is intended for implementation reviews and PR checklists.
6
+
7
+ ## Requirement traceability
8
+
9
+ | Requirement | Resources | Controllers/APIs | UI surfaces | Primary docs | Validation |
10
+ | --- | --- | --- | --- | --- | --- |
11
+ | Define an agent stack | `AgentStack`, tools, MCP, skills, subagents | stack controller, resource API | `/agents/stacks` | stack, CRD, tools, subagent specs | schema + UI validation |
12
+ | Validate ServiceAccount/RBAC | `AgentServiceAccount`, `AgentRoleBinding` | RBAC controller, permission review API | `/agents/permissions`, stack builder | RBAC spec | permission tests |
13
+ | Grant Secret/Config access | `AgentSecretGrant`, `AgentConfigGrant` | secret/config controller | `/agents/secrets`, grant wizards | RBAC spec, tools spec | no-secret-value tests |
14
+ | Assemble prompt/context | `AgentContextBundle`, context labels | context bundle service | dispatch composer, run detail | context spec | redaction tests |
15
+ | Dispatch manually from repo | `AgentDispatchRun`, `AgentDispatchAttempt` | dispatch API/controller | Code/Runs pages | MVP, API, repo integration | API + UI tests |
16
+ | Show CI-like run | dispatch run/attempt/session | dispatch controller, watch API | `/agents/runs`, repo Runs | UI flow, repository integration | UI validation |
17
+ | Bind Agent Mux session | attempt/session | Agent Mux client | run detail chat panel | adapter contract | gateway fallback tests |
18
+ | Manage tools/MCP/skills | tool/MCP/skill resources | stack/capability controllers | `/agents/tools`, `/mcp`, `/skills` | tools spec | capability tests |
19
+ | Run subagents | `AgentSubagent`, attempts/artifacts | dispatch/subagent controller | run detail subagent tree | subagent spec | child permission tests |
20
+ | Produce artifacts | artifacts/review artifacts | artifact service | run/PR/issue/pipeline pages | artifacts spec | digest tests |
21
+ | Gate write-back | approvals/artifacts | approval controller | inbox/run detail | artifacts, security specs | idempotency tests |
22
+ | Trigger from CI/webhook | trigger rules/executions | trigger controller | rules/hooks/pipelines | CI, trigger, API specs | dry-run/dedupe tests |
23
+ | Manage workspace lifecycle | workspace/link resources | workspace controller | workspaces/issues/PR/run | workspace spec | lifecycle tests |
24
+ | Observe and audit | audit/events/metrics | all controllers | run detail/insights | observability spec | audit/no-secret tests |
25
+ | Package/deploy agents | CRDs/chart values/templates | chart/package validation | operations install | chart spec | package check |
26
+
27
+ ## File traceability
28
+
29
+ | Future implementation file | Governing docs |
30
+ | --- | --- |
31
+ | `src/resource-model.js` | CRD schema, MVP, developer checklist |
32
+ | `src/kubernetes-controller.js` | CRD schema, controller reconciliation, chart spec |
33
+ | `src/controller-ui.js` | UI flow, repository integration, observability |
34
+ | `src/api-controller.js` | API contract, controller reconciliation |
35
+ | `src/agent-permission-review.js` | RBAC spec, API contract, MVP |
36
+ | `src/agent-stack-controller.js` | stack spec, tools spec, RBAC spec |
37
+ | `src/agent-context-bundles.js` | context assembly spec |
38
+ | `src/agent-dispatch-controller.js` | controller reconciliation, adapter contract, MVP |
39
+ | `src/agent-mux-client.js` | Agent Mux adapter contract |
40
+ | `src/agent-trigger-controller.js` | CI spec, controller reconciliation |
41
+ | `src/agent-workspace-controller.js` | workspace lifecycle spec |
42
+ | `src/agent-approval-controller.js` | artifacts/write-back spec |
43
+ | `apps/web/app/agents/*` | UI flow, repository integration |
44
+ | `charts/krate/*` | chart packaging, storage migration |
45
+ | `examples/agents/*` | resource examples, package validation |
46
+ | `tests/*` | acceptance test matrix |
47
+
48
+ ## Review checklist
49
+
50
+ Before merging implementation work, reviewers should ask:
51
+
52
+ - Which requirement row does this change satisfy?
53
+ - Which resource/controller/UI path backs the user action?
54
+ - Does the change preserve current generic resource/watch APIs?
55
+ - Are Secret values excluded from responses/status/logs/tests?
56
+ - Are denied states explainable from server-side conditions?
57
+ - Did package/docs/UI validation run?
58
+ - Did the PR update the affected docs and examples?
59
+
60
+ ## Org memory traceability
61
+
62
+ | Requirement | Resources | Controllers | UI | Docs | Validation |
63
+ | --- | --- | --- | --- | --- | --- |
64
+ | Org namespace isolation | `Organization`, `OrgNamespaceBinding` | org controller, admission | org switcher, YAML panels | org scoping spec | cross-org rejection tests |
65
+ | Company brain per org | `AgentMemoryRepository`, `AgentMemorySource` | memory controller | `/orgs/[org]/agents/memory` | memory specs | memory query permission tests |
66
+ | Babysitter run memory import | `AgentRunMemoryImport`, `AgentRunJournalEvent` | memory import controller | memory imports panel | memory runbook | redaction/import validation |
67
+ | Historical memory dispatch | `AgentMemorySnapshot`, `AgentMemoryQuery` | context assembler | dispatch memory advanced panel | context integration | refAt resolution tests |
68
+
69
+ ## Current app seam traceability
70
+
71
+ | Seam | Current file | Agent/memory use |
72
+ | --- | --- | --- |
73
+ | Org shell/navigation | `apps/web/app/ui-shell.jsx` | add Agents nav, memory attention counters, org breadcrumbs. |
74
+ | Org routes | `apps/web/app/orgs/[org]/*` | add `/agents/*` and `/agents/memory/*`. |
75
+ | Repo tabs | `apps/web/app/orgs/[org]/repositories/[repo]/*` | add dispatch actions, linked sessions/workspaces, memory associations. |
76
+ | Org resource API | `apps/web/app/api/orgs/[org]/resources/*` | list/apply agent and memory resources. |
77
+ | Watch API | `apps/web/app/api/watch/[[...resource]]/route.js` | stream org-scoped agent runs/imports after resource support. |
78
+ | Resource model | `src/resource-model.js` | add agent/memory kinds with `organizationRef`. |
79
+ | API controller | `src/api-controller.js` | add typed dispatch, memory query, import, approve, merge actions. |
@@ -0,0 +1,211 @@
1
+ # Agent UI flow and state spec
2
+
3
+ ## Purpose
4
+
5
+ This document translates the agent specs into concrete UI flows that fit the existing Krate app. Current UI facts:
6
+
7
+ - Repository routes are already organized under `/orgs/[org]/repositories/[repo]/code`, `/issues`, `/pull-requests`, `/runs`, `/hooks`, and `/settings`.
8
+ - `apps/web/app/ui-shell.jsx` centralizes most page rendering and favors GitHub-like repository pages with advanced YAML panels.
9
+ - `LiveWatchPanel` already consumes `/api/watch/orgs/[org]/*` streams.
10
+ - Existing pages emphasize disabled states backed by access checks and advanced plans hidden behind expandable panels.
11
+
12
+ Agent UI should extend this style instead of becoming a separate chat-only dashboard.
13
+
14
+ ## Navigation additions
15
+
16
+ Global routes:
17
+
18
+ - `/agents`: operational overview.
19
+ - `/agents/stacks`: stack registry and builder.
20
+ - `/agents/runs`: dispatch queue.
21
+ - `/agents/runs/[run]`: run/session detail.
22
+ - `/agents/rules`: trigger rules and dry-run.
23
+ - `/agents/workspaces`: workspace inventory.
24
+ - `/agents/approvals`: approval inbox.
25
+ - `/agents/identities`: ServiceAccounts, users, teams, native RBAC projections.
26
+ - `/agents/secrets`: Secret/ConfigMap grants and consumers.
27
+ - `/agents/permissions`: role templates, RoleBindings, drift, and permission review.
28
+
29
+ Repository route extensions:
30
+
31
+ - `/orgs/[org]/repositories/[repo]/code`: add `Dispatch agent` button, selected paths, branch/ref, active workspace/session chips.
32
+ - `/orgs/[org]/repositories/[repo]/issues`: add agent-ready board/list, context labels, linked workspaces/sessions/runs.
33
+ - `/orgs/[org]/repositories/[repo]/pull-requests`: add diagnose/repair/review agents, patch artifacts, write-back approvals.
34
+ - `/orgs/[org]/repositories/[repo]/runs`: show `AgentDispatchRun` rows beside `Pipeline` and `Job` rows.
35
+ - `/orgs/[org]/repositories/[repo]/hooks`: show trigger matches, delivery replay, and rule evaluation.
36
+ - `/orgs/[org]/repositories/[repo]/settings/agents`: stack permissions, triggers, ServiceAccounts, grants, runner policy.
37
+
38
+ ## Stack builder flow
39
+
40
+ 1. Choose base agent and adapter.
41
+ 2. Choose model/provider and prompt.
42
+ 3. Select runtime ServiceAccount.
43
+ 4. Select tool profile, MCP servers, skills, subagents, context labels.
44
+ 5. Choose runner pool and workspace policy.
45
+ 6. UI calls permission review.
46
+ 7. UI shows capability requirements matrix.
47
+ 8. User fixes missing RBAC/Secret/Config grants or removes capabilities.
48
+ 9. UI previews resource YAML.
49
+ 10. Save applies resources through controller API.
50
+
51
+ Required states:
52
+
53
+ - no adapters configured;
54
+ - adapter capability unavailable;
55
+ - ServiceAccount missing;
56
+ - role escalation denied;
57
+ - missing Secret grant;
58
+ - missing ConfigMap grant;
59
+ - Secret key missing;
60
+ - ConfigMap key sensitive/hidden;
61
+ - stack ready;
62
+ - stack ready but requires approval for selected sources.
63
+
64
+ ## Secret grant wizard
65
+
66
+ Entry points:
67
+
68
+ - stack builder warning;
69
+ - tool profile page;
70
+ - skill detail page;
71
+ - MCP server page;
72
+ - `/agents/secrets`;
73
+ - denied dispatch explanation.
74
+
75
+ Flow:
76
+
77
+ 1. Show requesting capability and why it needs the Secret.
78
+ 2. Show selected runtime ServiceAccount and repository/ref scope.
79
+ 3. Let authorized user select Secret/key metadata or create write-only key.
80
+ 4. Select purpose, mount policy, trigger/ref scope, and approval requirement.
81
+ 5. Preview `AgentSecretGrant` YAML and permission review result.
82
+ 6. Apply grant and recompute stack readiness.
83
+
84
+ UI must never show Secret values after write.
85
+
86
+ ## Config grant wizard
87
+
88
+ Flow mirrors Secret grant wizard, but ConfigMap values can be shown only when native RBAC permits and Krate sensitivity policy allows it. Otherwise show key names and metadata only.
89
+
90
+ ## Permission review panel
91
+
92
+ Reusable panel for stack builder, trigger dry-run, dispatch composer, and denied run states.
93
+
94
+ Sections:
95
+
96
+ - actor and Kubernetes identity;
97
+ - runtime ServiceAccount and runner ServiceAccount;
98
+ - role checks;
99
+ - required Secrets and grants;
100
+ - required ConfigMaps and grants;
101
+ - trust-tier constraints;
102
+ - approval requirements;
103
+ - least-privilege suggested fixes;
104
+ - YAML preview for permitted fixes.
105
+
106
+ ## Dispatch composer flow
107
+
108
+ On Code/Issue/PR/Pipeline pages:
109
+
110
+ 1. User opens dispatch composer.
111
+ 2. Source refs are prefilled from route context.
112
+ 3. User chooses stack, task kind, context labels, paths/artifacts/logs, workspace mode.
113
+ 4. UI calls permission review and context preview.
114
+ 5. User confirms.
115
+ 6. API creates `AgentDispatchRun` and `AgentDispatchAttempt` before Agent Mux launch.
116
+ 7. UI navigates to run detail or keeps an inline status chip.
117
+
118
+ ## Run detail flow
119
+
120
+ Layout should feel like a CI check page plus Agent Mux chat:
121
+
122
+ - Header: repository, source object, branch/SHA, stack, runner, ServiceAccounts, phase, approvals.
123
+ - Left: source context, logs/artifacts/files/context labels.
124
+ - Center: Agent Mux transcript and continuation composer.
125
+ - Right: attempts, event timeline, tools, MCP, skills, subagents, Secret/Config grants, approvals, artifacts.
126
+ - Footer: cancel/retry/resume/fork/continue controls when admitted.
127
+
128
+ States:
129
+
130
+ - queued;
131
+ - runner waiting;
132
+ - permission snapshot pending;
133
+ - Agent Mux session binding pending;
134
+ - stream disconnected/reconnecting;
135
+ - waiting for approval;
136
+ - workspace missing/rebase conflict;
137
+ - adapter launch rejected;
138
+ - succeeded/failed/cancelled.
139
+
140
+ ## Repository settings agents tab
141
+
142
+ This page is the GitHub-like management hub for a repository:
143
+
144
+ - enabled stacks;
145
+ - allowed triggers;
146
+ - allowed runner pools;
147
+ - runtime ServiceAccounts;
148
+ - runner ServiceAccounts;
149
+ - Secret grants;
150
+ - ConfigMap grants;
151
+ - role bindings;
152
+ - dry-run permission review.
153
+
154
+ The page should show safe defaults first and advanced YAML only in expandable panels, matching current Krate UI conventions.
155
+
156
+ ## Empty and denied states
157
+
158
+ Every action-disabled state must include:
159
+
160
+ - action attempted;
161
+ - resource involved;
162
+ - Kubernetes identity used;
163
+ - missing permission or policy reason;
164
+ - whether the user can fix it;
165
+ - link to permission review or relevant settings page.
166
+
167
+ ## Integration with current app
168
+
169
+ Initial implementation can reuse:
170
+
171
+ - `apps/web/app/ui-shell.jsx` page patterns;
172
+ - `ResourceTable` for generic resource visibility;
173
+ - `PlanCard` for YAML previews;
174
+ - `LiveWatchPanel` for dispatch/watch streams;
175
+ - existing repository route wrappers in `apps/web/app/orgs/[org]/repositories/[repo]/*/page.jsx`.
176
+
177
+ Typed components should be introduced once the resource/controller contracts exist.
178
+
179
+ ## Memory user flows
180
+
181
+ ### Configure company brain
182
+
183
+ 1. Admin opens `/agents/memory` and creates or adopts `AgentMemoryRepository`.
184
+ 2. Krate validates layout and ontology.
185
+ 3. Admin creates `AgentMemorySource` policies for repositories, teams, stacks, and triggers.
186
+ 4. UI shows generated YAML, RBAC implications, and validation status.
187
+
188
+ ### Dispatch with memory
189
+
190
+ 1. User opens repository Code, Issue, PR, or Pipeline page.
191
+ 2. User opens dispatch composer and expands Memory.
192
+ 3. UI shows default memory source, current commit, query preview, and selected records/excerpts.
193
+ 4. User optionally chooses explicit ref, snapshot tag, or `refAt` timestamp.
194
+ 5. Krate resolves commit and creates `AgentMemorySnapshot` before launch.
195
+
196
+ ### Review memory update
197
+
198
+ 1. Agent proposes memory update from run detail.
199
+ 2. UI shows diff, source run, evidence, ontology validation, secret scan, and owners.
200
+ 3. Reviewer approves, requests changes, rejects, or merges.
201
+ 4. Merge updates memory repo and links new commit to the source run.
202
+
203
+ ## Org-scoped route migration flow
204
+
205
+ 1. User opens `/orgs/[org]/repositories/[repo]/code`.
206
+ 2. Server resolves visible repositories matching `[repo]`.
207
+ 3. Krate stays within the explicit `/orgs/[org]` route and never resolves a repository without org context.
208
+ 4. If multiple matches exist, show an org picker with visible org names only.
209
+ 5. If no match exists, show a normal not-found state without leaking private orgs.
210
+
211
+ All dispatch composers, memory pages, deployment pages, and settings pages should use org-aware routes directly.