@a5c-ai/krate 5.0.1-staging.660d2b90f → 5.0.1-staging.69cb593ea
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.
- package/Dockerfile +31 -29
- package/bin/krate-demo.mjs +0 -0
- package/bin/krate-server.mjs +0 -0
- package/dist/krate-controller-ui.json +808 -10
- package/dist/krate-lifecycle.json +1 -1
- package/dist/krate-runtime-snapshot.json +223 -53
- package/dist/krate-summary.json +40 -3
- package/docs/agents/gaps-agent-mux-to-krate-crds.md +298 -0
- package/docs/architecture-v2.md +431 -0
- package/docs/openapi.yaml +1275 -0
- package/docs/requirements-v2.md +238 -0
- package/docs/sdk-api-reference.md +782 -0
- package/docs/system-spec-v2.md +352 -0
- package/docs/todos.md +4 -0
- package/docs/web-console-spec.md +433 -0
- package/package.json +1 -1
- package/scripts/validate-ui.mjs +305 -207
- package/src/agent-adapter-controller.js +169 -0
- package/src/agent-approval-controller.js +47 -0
- package/src/agent-dispatch-controller.js +130 -7
- package/src/agent-gateway-config-controller.js +147 -0
- package/src/agent-memory-controller.js +357 -0
- package/src/agent-memory-import.js +327 -0
- package/src/agent-memory-query.js +292 -0
- package/src/agent-memory-repository-source-controller.js +255 -0
- package/src/agent-mux-client.js +1 -1
- package/src/agent-permission-review.js +102 -14
- package/src/agent-project-controller.js +117 -0
- package/src/agent-provider-config-controller.js +150 -0
- package/src/agent-secret-config-grant-controller.js +282 -0
- package/src/agent-session-transcript-controller.js +189 -0
- package/src/agent-stack-controller.js +52 -1
- package/src/agent-subagent-controller.js +160 -0
- package/src/agent-transport-binding-controller.js +121 -0
- package/src/agent-trigger-controller.js +273 -0
- package/src/agent-workspace-controller.js +702 -0
- package/src/agent-writeback-controller.js +302 -0
- package/src/api-controller.js +338 -3
- package/src/async-controller.js +207 -0
- package/src/audit-controller.js +191 -0
- package/src/auth.js +48 -6
- package/src/controller-client.js +112 -38
- package/src/controller-ui.js +96 -16
- package/src/data-plane.js +3 -2
- package/src/event-bus.js +61 -0
- package/src/external/conflict-controller.js +225 -0
- package/src/external/github/auth.js +96 -0
- package/src/external/github/cicd.js +180 -0
- package/src/external/github/git-forge.js +240 -0
- package/src/external/github/index.js +144 -0
- package/src/external/github/issue-tracking.js +163 -0
- package/src/external/provider-adapter.js +161 -0
- package/src/external/provider-resource-factory.js +161 -0
- package/src/external/sync-controller.js +235 -0
- package/src/external/webhook-controller.js +144 -0
- package/src/external/write-controller.js +283 -0
- package/src/gitea-backend.js +36 -0
- package/src/gitea-service.js +173 -0
- package/src/http-server.js +226 -0
- package/src/index.js +27 -0
- package/src/kubernetes-controller-async.js +531 -0
- package/src/kubernetes-controller.js +156 -84
- package/src/notification-controller.js +178 -0
- package/src/org-scoping.js +5 -0
- package/src/resource-model.js +26 -8
- package/src/runner-controller.js +272 -0
- package/src/snapshot-cache.js +157 -0
- package/tests/agent-adapter-controller.test.js +361 -0
- package/tests/agent-dispatch-controller.test.js +139 -0
- package/tests/agent-gateway-config-controller.test.js +386 -0
- package/tests/agent-memory-controller.test.js +308 -0
- package/tests/agent-memory-import-snapshot.test.js +477 -0
- package/tests/agent-memory-query.test.js +404 -0
- package/tests/agent-memory-repository-source.test.js +514 -0
- package/tests/agent-permission-review-v2.test.js +317 -0
- package/tests/agent-project-controller.test.js +302 -0
- package/tests/agent-provider-config-controller.test.js +376 -0
- package/tests/agent-resources.test.js +35 -19
- package/tests/agent-secret-config-grant.test.js +231 -0
- package/tests/agent-session-transcript-controller.test.js +499 -0
- package/tests/agent-subagent-controller.test.js +201 -0
- package/tests/agent-transport-binding-controller.test.js +294 -0
- package/tests/agent-trigger-routes.test.js +190 -0
- package/tests/agent-trigger-sources.test.js +245 -0
- package/tests/agent-workspace-controller.test.js +181 -0
- package/tests/agent-writeback.test.js +292 -0
- package/tests/approval-persistence.test.js +171 -0
- package/tests/async-controller.test.js +252 -0
- package/tests/audit-controller.test.js +227 -0
- package/tests/codespace-controller.test.js +318 -0
- package/tests/controller-client.test.js +133 -0
- package/tests/deployment.test.js +43 -29
- package/tests/e2e/lifecycle.test.js +5 -2
- package/tests/event-bus-integration.test.js +190 -0
- package/tests/external-github-forge.test.js +560 -0
- package/tests/external-github-issues-cicd.test.js +520 -0
- package/tests/external-integration.test.js +470 -0
- package/tests/external-persistence.test.js +340 -0
- package/tests/external-provider-adapter.test.js +365 -0
- package/tests/external-resource-model.test.js +215 -0
- package/tests/external-webhook-sync.test.js +287 -0
- package/tests/external-write-conflict.test.js +353 -0
- package/tests/gitea-service.test.js +253 -0
- package/tests/health-check-real.test.js +165 -0
- package/tests/integration/full-flow.test.js +266 -0
- package/tests/krate.test.js +58 -6
- package/tests/memory-search-wiring.test.js +270 -0
- package/tests/notification-controller.test.js +196 -0
- package/tests/notification-integration.test.js +179 -0
- package/tests/org-scoping.test.js +687 -0
- package/tests/runner-controller.test.js +327 -0
- package/tests/runner-integration.test.js +231 -0
- package/tests/session-cookie-hmac.test.js +151 -0
- package/tests/snapshot-performance.test.js +315 -0
- package/tests/sse-events.test.js +107 -0
- package/tests/webhook-trigger.test.js +198 -0
- package/tests/workspace-volumes.test.js +312 -0
- package/tests/writeback-persistence.test.js +207 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Memory Query Engine
|
|
3
|
+
*
|
|
4
|
+
* Standalone query engine for in-memory graph traversal and document grep.
|
|
5
|
+
* No external dependencies — operates purely on plain JS data structures.
|
|
6
|
+
*
|
|
7
|
+
* Boundary: agent-memory-query
|
|
8
|
+
* - owns: graph traversal, relevance scoring, text grep, context extraction, combined query execution
|
|
9
|
+
* - delegatesTo: (none — pure data transformation)
|
|
10
|
+
* - mustNotOwn: persistence, HTTP routing, Kubernetes resources, secret handling
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const AGENT_MEMORY_QUERY_BOUNDARY = {
|
|
14
|
+
role: 'agent-memory-query',
|
|
15
|
+
scope: 'In-memory graph traversal and full-text grep query execution for agent memory documents',
|
|
16
|
+
owns: ['graph traversal', 'nodeKind filtering', 'edge following', 'relevance scoring', 'full-text grep', 'context extraction', 'combined query execution'],
|
|
17
|
+
delegatesTo: [],
|
|
18
|
+
mustNotOwn: ['persistence', 'HTTP routing', 'Kubernetes resources', 'secret handling'],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const VALID_MODES = ['graph-only', 'grep-only', 'graph-and-grep'];
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Graph query
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Execute a graph query over a set of records.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} params
|
|
31
|
+
* @param {Array} params.records - Array of graph records. Each record has { id, nodeKind, attributes, edges }.
|
|
32
|
+
* @param {Array} [params.edges] - Optional flat edges array { source, target, kind }. If provided these
|
|
33
|
+
* supplement per-record edges during traversal.
|
|
34
|
+
* @param {string} params.query - Search text (required, must be non-empty).
|
|
35
|
+
* @param {Array} [params.kinds] - nodeKind filter. Empty array means "no filter".
|
|
36
|
+
* @param {number} [params.depth] - Edge-follow depth (default 1).
|
|
37
|
+
* @returns {{ matches: Array, totalMatches: number }}
|
|
38
|
+
*/
|
|
39
|
+
export function queryGraph({ records = [], edges = [], query, kinds = [], depth = 1 }) {
|
|
40
|
+
if (query === undefined || query === null) {
|
|
41
|
+
throw new Error('queryGraph: query text is required');
|
|
42
|
+
}
|
|
43
|
+
if (typeof query !== 'string' || query.trim() === '') {
|
|
44
|
+
throw new Error('queryGraph: query text must be a non-empty string');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Build adjacency index from flat edges + per-record edges
|
|
48
|
+
const adjacency = buildAdjacency(records, edges);
|
|
49
|
+
|
|
50
|
+
// Filter by nodeKind
|
|
51
|
+
let candidates = records;
|
|
52
|
+
if (kinds.length > 0) {
|
|
53
|
+
candidates = candidates.filter(r => kinds.includes(r.nodeKind));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const lowerQuery = query.toLowerCase();
|
|
57
|
+
const matches = [];
|
|
58
|
+
|
|
59
|
+
for (const record of candidates) {
|
|
60
|
+
const score = scoreRecord(record, lowerQuery);
|
|
61
|
+
if (score === 0) continue;
|
|
62
|
+
|
|
63
|
+
const followedEdges = followEdges(record.id, adjacency, depth);
|
|
64
|
+
|
|
65
|
+
matches.push({
|
|
66
|
+
record: shallowClone(record),
|
|
67
|
+
score,
|
|
68
|
+
edges: followedEdges,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Sort by descending score for deterministic output
|
|
73
|
+
matches.sort((a, b) => b.score - a.score);
|
|
74
|
+
|
|
75
|
+
return { matches, totalMatches: matches.length };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Execute a grep query over a set of documents.
|
|
80
|
+
*
|
|
81
|
+
* @param {object} params
|
|
82
|
+
* @param {Array} params.documents - Array of { path: string, content: string }.
|
|
83
|
+
* @param {string} params.query - Search text (required, must be non-empty).
|
|
84
|
+
* @param {Array} [params.paths] - Optional glob-style path filters.
|
|
85
|
+
* @param {number} [params.context] - Number of context lines above/below each match (default 1).
|
|
86
|
+
* @param {number} [params.maxMatches] - Maximum number of excerpts to return (default 25).
|
|
87
|
+
* @returns {{ excerpts: Array, totalMatches: number }}
|
|
88
|
+
*/
|
|
89
|
+
export function queryGrep({ documents = [], query, paths = [], context = 1, maxMatches = 25 }) {
|
|
90
|
+
if (query === undefined || query === null) {
|
|
91
|
+
throw new Error('queryGrep: query text is required');
|
|
92
|
+
}
|
|
93
|
+
if (typeof query !== 'string' || query.trim() === '') {
|
|
94
|
+
throw new Error('queryGrep: query text must be a non-empty string');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Filter by path globs
|
|
98
|
+
let filtered = documents;
|
|
99
|
+
if (paths.length > 0) {
|
|
100
|
+
filtered = documents.filter(doc => paths.some(p => globMatch(p, doc.path)));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const lowerQuery = query.toLowerCase();
|
|
104
|
+
const excerpts = [];
|
|
105
|
+
|
|
106
|
+
for (const doc of filtered) {
|
|
107
|
+
if (excerpts.length >= maxMatches) break;
|
|
108
|
+
|
|
109
|
+
const lines = String(doc.content || '').split('\n');
|
|
110
|
+
for (let i = 0; i < lines.length; i++) {
|
|
111
|
+
if (excerpts.length >= maxMatches) break;
|
|
112
|
+
|
|
113
|
+
const lowerLine = lines[i].toLowerCase();
|
|
114
|
+
if (!lowerLine.includes(lowerQuery)) continue;
|
|
115
|
+
|
|
116
|
+
// Build highlighted line: mark matched span
|
|
117
|
+
const matchStart = lowerLine.indexOf(lowerQuery);
|
|
118
|
+
const matchEnd = matchStart + query.length;
|
|
119
|
+
const highlighted =
|
|
120
|
+
lines[i].slice(0, matchStart) +
|
|
121
|
+
'**' + lines[i].slice(matchStart, matchEnd) + '**' +
|
|
122
|
+
lines[i].slice(matchEnd);
|
|
123
|
+
|
|
124
|
+
// Context lines
|
|
125
|
+
const ctxStart = Math.max(0, i - context);
|
|
126
|
+
const ctxEnd = Math.min(lines.length - 1, i + context);
|
|
127
|
+
const contextLines = lines.slice(ctxStart, ctxEnd + 1);
|
|
128
|
+
|
|
129
|
+
excerpts.push({
|
|
130
|
+
path: doc.path,
|
|
131
|
+
lineNumber: i + 1,
|
|
132
|
+
line: lines[i],
|
|
133
|
+
highlighted,
|
|
134
|
+
context: contextLines.join('\n'),
|
|
135
|
+
contextStart: ctxStart + 1,
|
|
136
|
+
contextEnd: ctxEnd + 1,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return { excerpts, totalMatches: excerpts.length };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Execute a combined query (graph + grep or either alone).
|
|
146
|
+
*
|
|
147
|
+
* @param {object} params
|
|
148
|
+
* @param {string} params.query - Search text (required).
|
|
149
|
+
* @param {string} [params.mode] - 'graph-and-grep' | 'graph-only' | 'grep-only' (default 'graph-and-grep').
|
|
150
|
+
* @param {Array} [params.records] - Graph records.
|
|
151
|
+
* @param {Array} [params.edges] - Flat edge list.
|
|
152
|
+
* @param {Array} [params.documents] - Grep documents.
|
|
153
|
+
* @param {object} [params.graphOptions] - Passed to queryGraph: { kinds, depth }.
|
|
154
|
+
* @param {object} [params.grepOptions] - Passed to queryGrep: { paths, context, maxMatches }.
|
|
155
|
+
* @returns {{ graph: object|null, grep: object|null, stats: object }}
|
|
156
|
+
*/
|
|
157
|
+
export function queryMemory({
|
|
158
|
+
query,
|
|
159
|
+
mode = 'graph-and-grep',
|
|
160
|
+
records = [],
|
|
161
|
+
edges = [],
|
|
162
|
+
documents = [],
|
|
163
|
+
graphOptions = {},
|
|
164
|
+
grepOptions = {},
|
|
165
|
+
}) {
|
|
166
|
+
if (!VALID_MODES.includes(mode)) {
|
|
167
|
+
throw new Error(`queryMemory: invalid mode "${mode}". Must be one of: ${VALID_MODES.join(', ')}`);
|
|
168
|
+
}
|
|
169
|
+
if (query === undefined || query === null) {
|
|
170
|
+
throw new Error('queryMemory: query text is required');
|
|
171
|
+
}
|
|
172
|
+
if (typeof query !== 'string' || query.trim() === '') {
|
|
173
|
+
throw new Error('queryMemory: query text must be a non-empty string');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let graphResult = null;
|
|
177
|
+
let grepResult = null;
|
|
178
|
+
|
|
179
|
+
if (mode === 'graph-only' || mode === 'graph-and-grep') {
|
|
180
|
+
graphResult = queryGraph({
|
|
181
|
+
records,
|
|
182
|
+
edges,
|
|
183
|
+
query,
|
|
184
|
+
kinds: graphOptions.kinds || [],
|
|
185
|
+
depth: graphOptions.depth ?? 1,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (mode === 'grep-only' || mode === 'graph-and-grep') {
|
|
190
|
+
grepResult = queryGrep({
|
|
191
|
+
documents,
|
|
192
|
+
query,
|
|
193
|
+
paths: grepOptions.paths || [],
|
|
194
|
+
context: grepOptions.context ?? 1,
|
|
195
|
+
maxMatches: grepOptions.maxMatches ?? 25,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const graphCount = graphResult ? graphResult.totalMatches : 0;
|
|
200
|
+
const grepCount = grepResult ? grepResult.totalMatches : 0;
|
|
201
|
+
const totalMatches = graphCount + grepCount;
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
graph: graphResult,
|
|
205
|
+
grep: grepResult,
|
|
206
|
+
stats: {
|
|
207
|
+
mode,
|
|
208
|
+
totalMatches,
|
|
209
|
+
graphCount,
|
|
210
|
+
grepCount,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
// Internal helpers
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Build adjacency map: nodeId -> [{ target, kind, source }]
|
|
221
|
+
* Merges per-record edges with a flat edge list.
|
|
222
|
+
*/
|
|
223
|
+
function buildAdjacency(records, flatEdges) {
|
|
224
|
+
const adj = new Map();
|
|
225
|
+
|
|
226
|
+
for (const record of records) {
|
|
227
|
+
if (!adj.has(record.id)) adj.set(record.id, []);
|
|
228
|
+
for (const edge of record.edges || []) {
|
|
229
|
+
adj.get(record.id).push({ ...edge, source: record.id });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
for (const edge of flatEdges) {
|
|
234
|
+
const src = edge.source;
|
|
235
|
+
if (!adj.has(src)) adj.set(src, []);
|
|
236
|
+
adj.get(src).push({ ...edge });
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return adj;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Follow edges from a start node up to `maxDepth` hops.
|
|
244
|
+
* Returns a flat array of edge objects encountered.
|
|
245
|
+
*/
|
|
246
|
+
function followEdges(startId, adjacency, maxDepth) {
|
|
247
|
+
if (maxDepth <= 0) return [];
|
|
248
|
+
|
|
249
|
+
const visited = new Set([startId]);
|
|
250
|
+
const collected = [];
|
|
251
|
+
let frontier = [startId];
|
|
252
|
+
|
|
253
|
+
for (let d = 0; d < maxDepth; d++) {
|
|
254
|
+
const nextFrontier = [];
|
|
255
|
+
for (const nodeId of frontier) {
|
|
256
|
+
for (const edge of adjacency.get(nodeId) || []) {
|
|
257
|
+
if (visited.has(edge.target)) continue;
|
|
258
|
+
visited.add(edge.target);
|
|
259
|
+
collected.push({ ...edge });
|
|
260
|
+
nextFrontier.push(edge.target);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
frontier = nextFrontier;
|
|
264
|
+
if (frontier.length === 0) break;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return collected;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Score a record against a lowercase query string.
|
|
272
|
+
* Returns 0 (no match), 1 (attribute match), or 2 (id match).
|
|
273
|
+
*/
|
|
274
|
+
function scoreRecord(record, lowerQuery) {
|
|
275
|
+
const id = String(record.id || '').toLowerCase();
|
|
276
|
+
const attrs = JSON.stringify(record.attributes || {}).toLowerCase();
|
|
277
|
+
|
|
278
|
+
if (id.includes(lowerQuery)) return 2;
|
|
279
|
+
if (attrs.includes(lowerQuery)) return 1;
|
|
280
|
+
return 0;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** Minimal shallow clone to avoid mutation of inputs */
|
|
284
|
+
function shallowClone(obj) {
|
|
285
|
+
return Object.assign(Object.create(null), obj);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Simple glob match: * matches any sequence of characters */
|
|
289
|
+
function globMatch(pattern, path) {
|
|
290
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
291
|
+
return new RegExp(`^${escaped}$`).test(path);
|
|
292
|
+
}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// Agent Memory Repository & Source Controller — Slice 2.3a
|
|
2
|
+
//
|
|
3
|
+
// AgentMemoryRepository: org-level memory storage pointer, git repo ref validation.
|
|
4
|
+
// AgentMemorySource: read policies for memory paths, access control.
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Boundaries
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
export const AGENT_MEMORY_REPOSITORY_CONTROLLER_BOUNDARY = {
|
|
11
|
+
role: 'agent-memory-repository-controller',
|
|
12
|
+
scope: 'AgentMemoryRepository lifecycle: validation, repo URL resolution, retention policy defaults',
|
|
13
|
+
owns: ['memory repository validation', 'repo URL', 'retention policy defaults'],
|
|
14
|
+
delegatesTo: ['resource-model'],
|
|
15
|
+
mustNotOwn: ['git operations', 'secret values', 'Agent Mux sessions', 'memory search']
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const AGENT_MEMORY_SOURCE_CONTROLLER_BOUNDARY = {
|
|
19
|
+
role: 'agent-memory-source-controller',
|
|
20
|
+
scope: 'AgentMemorySource lifecycle: validation, read policy, included/excluded paths, access control',
|
|
21
|
+
owns: ['memory source validation', 'read policy defaults', 'included paths', 'excluded paths'],
|
|
22
|
+
delegatesTo: ['resource-model'],
|
|
23
|
+
mustNotOwn: ['git operations', 'secret values', 'Agent Mux sessions', 'memory search']
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Constants — defaults
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
const DEFAULT_RETENTION_POLICY = Object.freeze({
|
|
31
|
+
maxAgeDays: 90,
|
|
32
|
+
maxSizeMb: 500,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const DEFAULT_READ_POLICY = Object.freeze({
|
|
36
|
+
mode: 'allow-all',
|
|
37
|
+
maxDepth: 5,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Valid git/http/ssh URL schemes
|
|
41
|
+
// Accepted forms:
|
|
42
|
+
// https://... http://... ssh://... git://... git@host:path (SCP-style)
|
|
43
|
+
const VALID_REPO_URL_PATTERNS = [
|
|
44
|
+
/^https?:\/\//,
|
|
45
|
+
/^ssh:\/\//,
|
|
46
|
+
/^git:\/\//,
|
|
47
|
+
/^git@[^:]+:.+/,
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Standalone validateMemoryRepository
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Validate an AgentMemoryRepository resource. Returns { valid, errors }.
|
|
56
|
+
* @param {object} resource
|
|
57
|
+
* @returns {{ valid: boolean, errors: string[] }}
|
|
58
|
+
*/
|
|
59
|
+
export function validateMemoryRepository(resource) {
|
|
60
|
+
const errors = [];
|
|
61
|
+
|
|
62
|
+
// Guard against null/undefined
|
|
63
|
+
if (resource == null) {
|
|
64
|
+
errors.push('resource must not be null or undefined');
|
|
65
|
+
return { valid: false, errors };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Validate metadata.name
|
|
69
|
+
if (!resource.metadata?.name) {
|
|
70
|
+
errors.push('metadata.name is required');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const spec = resource.spec || {};
|
|
74
|
+
|
|
75
|
+
// Validate organizationRef
|
|
76
|
+
if (!spec.organizationRef) {
|
|
77
|
+
errors.push('spec.organizationRef is required');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Validate repoUrl — presence
|
|
81
|
+
if (!spec.repoUrl) {
|
|
82
|
+
errors.push('spec.repoUrl is required; provide a git/http/ssh repository URL');
|
|
83
|
+
} else {
|
|
84
|
+
// Validate repoUrl — format (git/http/ssh/scp-style)
|
|
85
|
+
const isValid = VALID_REPO_URL_PATTERNS.some((re) => re.test(spec.repoUrl));
|
|
86
|
+
if (!isValid) {
|
|
87
|
+
errors.push(
|
|
88
|
+
'spec.repoUrl must be a valid git repository URL (https://, http://, ssh://, git://, or git@host:path format)'
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { valid: errors.length === 0, errors };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// AgentMemoryRepository controller factory
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Factory that returns an AgentMemoryRepository controller instance.
|
|
102
|
+
*/
|
|
103
|
+
export function createAgentMemoryRepositoryController() {
|
|
104
|
+
return {
|
|
105
|
+
role: 'agent-memory-repository-controller',
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Validate an AgentMemoryRepository resource.
|
|
109
|
+
* @param {object} resource
|
|
110
|
+
* @returns {{ valid: boolean, errors: string[] }}
|
|
111
|
+
*/
|
|
112
|
+
validateMemoryRepository(resource) {
|
|
113
|
+
return validateMemoryRepository(resource);
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Return the repository URL configured in spec.repoUrl.
|
|
118
|
+
* @param {object} resource
|
|
119
|
+
* @returns {string}
|
|
120
|
+
*/
|
|
121
|
+
getRepositoryUrl(resource) {
|
|
122
|
+
if (resource == null) {
|
|
123
|
+
throw new Error('resource must not be null or undefined');
|
|
124
|
+
}
|
|
125
|
+
return resource.spec?.repoUrl ?? null;
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Return the effective retention policy for the memory repository.
|
|
130
|
+
* Merges spec.retentionPolicy with defaults; spec values take precedence.
|
|
131
|
+
* Defaults: maxAgeDays = 90, maxSizeMb = 500.
|
|
132
|
+
* @param {object} resource
|
|
133
|
+
* @returns {{ maxAgeDays: number, maxSizeMb: number }}
|
|
134
|
+
*/
|
|
135
|
+
getRetentionPolicy(resource) {
|
|
136
|
+
if (resource == null) {
|
|
137
|
+
throw new Error('resource must not be null or undefined');
|
|
138
|
+
}
|
|
139
|
+
const specPolicy = resource.spec?.retentionPolicy ?? {};
|
|
140
|
+
return {
|
|
141
|
+
maxAgeDays: specPolicy.maxAgeDays ?? DEFAULT_RETENTION_POLICY.maxAgeDays,
|
|
142
|
+
maxSizeMb: specPolicy.maxSizeMb ?? DEFAULT_RETENTION_POLICY.maxSizeMb,
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
// Standalone validateMemorySource
|
|
150
|
+
// ---------------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Validate an AgentMemorySource resource. Returns { valid, errors }.
|
|
154
|
+
* @param {object} resource
|
|
155
|
+
* @returns {{ valid: boolean, errors: string[] }}
|
|
156
|
+
*/
|
|
157
|
+
export function validateMemorySource(resource) {
|
|
158
|
+
const errors = [];
|
|
159
|
+
|
|
160
|
+
// Guard against null/undefined
|
|
161
|
+
if (resource == null) {
|
|
162
|
+
errors.push('resource must not be null or undefined');
|
|
163
|
+
return { valid: false, errors };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Validate metadata.name
|
|
167
|
+
if (!resource.metadata?.name) {
|
|
168
|
+
errors.push('metadata.name is required');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const spec = resource.spec || {};
|
|
172
|
+
|
|
173
|
+
// Validate organizationRef
|
|
174
|
+
if (!spec.organizationRef) {
|
|
175
|
+
errors.push('spec.organizationRef is required');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Validate repositoryRef
|
|
179
|
+
if (!spec.repositoryRef) {
|
|
180
|
+
errors.push('spec.repositoryRef is required; provide a reference to the AgentMemoryRepository');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Validate paths — must be present and non-empty
|
|
184
|
+
const paths = spec.paths;
|
|
185
|
+
if (!Array.isArray(paths) || paths.length === 0) {
|
|
186
|
+
errors.push('spec.paths must be a non-empty array of memory path patterns');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return { valid: errors.length === 0, errors };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ---------------------------------------------------------------------------
|
|
193
|
+
// AgentMemorySource controller factory
|
|
194
|
+
// ---------------------------------------------------------------------------
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Factory that returns an AgentMemorySource controller instance.
|
|
198
|
+
*/
|
|
199
|
+
export function createAgentMemorySourceController() {
|
|
200
|
+
return {
|
|
201
|
+
role: 'agent-memory-source-controller',
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Validate an AgentMemorySource resource.
|
|
205
|
+
* @param {object} resource
|
|
206
|
+
* @returns {{ valid: boolean, errors: string[] }}
|
|
207
|
+
*/
|
|
208
|
+
validateMemorySource(resource) {
|
|
209
|
+
return validateMemorySource(resource);
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Return the effective read policy for the memory source.
|
|
214
|
+
* Merges spec.readPolicy with defaults; spec values take precedence.
|
|
215
|
+
* Defaults: mode = 'allow-all', maxDepth = 5.
|
|
216
|
+
* @param {object} resource
|
|
217
|
+
* @returns {{ mode: string, maxDepth: number }}
|
|
218
|
+
*/
|
|
219
|
+
getReadPolicy(resource) {
|
|
220
|
+
if (resource == null) {
|
|
221
|
+
throw new Error('resource must not be null or undefined');
|
|
222
|
+
}
|
|
223
|
+
const specPolicy = resource.spec?.readPolicy ?? {};
|
|
224
|
+
return {
|
|
225
|
+
mode: specPolicy.mode ?? DEFAULT_READ_POLICY.mode,
|
|
226
|
+
maxDepth: specPolicy.maxDepth ?? DEFAULT_READ_POLICY.maxDepth,
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Return the included memory path patterns from spec.paths.
|
|
232
|
+
* @param {object} resource
|
|
233
|
+
* @returns {string[]}
|
|
234
|
+
*/
|
|
235
|
+
getIncludedPaths(resource) {
|
|
236
|
+
if (resource == null) {
|
|
237
|
+
throw new Error('resource must not be null or undefined');
|
|
238
|
+
}
|
|
239
|
+
return Array.isArray(resource.spec?.paths) ? [...resource.spec.paths] : [];
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Return the excluded memory path patterns from spec.excludedPaths.
|
|
244
|
+
* Returns an empty array when not set.
|
|
245
|
+
* @param {object} resource
|
|
246
|
+
* @returns {string[]}
|
|
247
|
+
*/
|
|
248
|
+
getExcludedPaths(resource) {
|
|
249
|
+
if (resource == null) {
|
|
250
|
+
throw new Error('resource must not be null or undefined');
|
|
251
|
+
}
|
|
252
|
+
return Array.isArray(resource.spec?.excludedPaths) ? [...resource.spec.excludedPaths] : [];
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
package/src/agent-mux-client.js
CHANGED
|
@@ -116,7 +116,7 @@ export function createAgentMuxClient(options = {}) {
|
|
|
116
116
|
prompt: contextBundle?.prompt,
|
|
117
117
|
systemPrompt: contextBundle?.systemPrompt,
|
|
118
118
|
attachments: contextBundle?.attachments,
|
|
119
|
-
workspace: workspace?.
|
|
119
|
+
workspace: workspace?.mountPath || '/workspace',
|
|
120
120
|
};
|
|
121
121
|
const { status, body } = await httpRequest(`${gateway}/api/v1/sessions`, { method: 'POST', body: payload });
|
|
122
122
|
if (status >= 200 && status < 300 && body?.runId && body?.sessionId) {
|