@akanjs/cli 3.1.2-rc.2 → 3.1.2-rc.3

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 (47) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-nkk70v5h.js → CodeAgent-n2tkg59z.js} +2 -2
  3. package/{CodeTui-sdqz2gxb.js → CodeTui-9wsdx7ap.js} +1 -1
  4. package/{TunnelShare-hdq9h1hr.js → TunnelShare-6d7z36sr.js} +1 -1
  5. package/{agent.command-5gfrfh8d.js → agent.command-tffz6wdn.js} +7 -7
  6. package/akanCode.js +2 -2
  7. package/{application.command-nd0fshsk.js → application.command-7bkxbrsp.js} +17 -2
  8. package/{cloud.command-8kbddsz9.js → cloud.command-a792bc10.js} +3 -3
  9. package/{cloud.script-hgvvajm3.js → cloud.script-t2n13gv6.js} +3 -3
  10. package/{code.command-5djp5c0n.js → code.command-ma8dtzww.js} +4 -4
  11. package/commandManifest.json +1 -1
  12. package/{context.command-5d0bscv6.js → context.command-80a1qhps.js} +11 -10
  13. package/{context.runner-2v5pq18d.js → context.runner-wxqb3qcy.js} +10 -9
  14. package/incrementalBuilder.proc.js +22 -2
  15. package/{index-pqdyyxz0.js → index-361ex3rb.js} +2 -2
  16. package/{index-mzjwq4dd.js → index-9z3egsmg.js} +6 -6
  17. package/{index-tyt7cw99.js → index-aayg4dqf.js} +4 -4
  18. package/{index-ewbmfarf.js → index-db2nqrad.js} +20 -2
  19. package/{index-tw27n941.js → index-eft5c2mp.js} +1 -1
  20. package/{index-19cspack.js → index-gbp1q1b5.js} +1 -1
  21. package/{index-pnk67cqd.js → index-hapx5myy.js} +1 -1
  22. package/{index-gf4fcw1n.js → index-j2dgmzbj.js} +389 -6
  23. package/{index-dbxac7mz.js → index-j9d3mjx1.js} +1 -1
  24. package/{index-f6zrhcnk.js → index-jb2sreps.js} +17 -4
  25. package/{index-1404hqcj.js → index-m02tdq8a.js} +1 -1
  26. package/{index-2mwjshz5.js → index-ppvqy5bc.js} +8 -5
  27. package/{index-q9q6jjk1.js → index-scck6h6d.js} +3 -3
  28. package/{index-chjaw222.js → index-sjabnf7j.js} +1 -1
  29. package/{index-00a7j05x.js → index-sx91nf4z.js} +1 -1
  30. package/{index-ms1am2wr.js → index-tns543wd.js} +2 -2
  31. package/index-vzpnr12w.js +65 -0
  32. package/{index-yep9xcz0.js → index-wrmq92vk.js} +1 -1
  33. package/{index-3q4kkyd4.js → index-z7kbxdqg.js} +3 -3
  34. package/{index-t78230d7.js → index-zdpte1pj.js} +2 -1
  35. package/index.js +16 -16
  36. package/{localRegistry.command-g3f8k25t.js → localRegistry.command-343ksmn9.js} +2 -2
  37. package/{module.command-myykfb6s.js → module.command-2hce9m6k.js} +3 -3
  38. package/package.json +2 -2
  39. package/{primitive.command-eg2c3m97.js → primitive.command-7tdj12wn.js} +4 -4
  40. package/{quality.command-b840977n.js → quality.command-29bgarh1.js} +2 -2
  41. package/{repair.command-r7z709yf.js → repair.command-yng4rf5d.js} +4 -4
  42. package/{scalar.command-t6hhty3f.js → scalar.command-1nk4329t.js} +3 -3
  43. package/{subspace.command-a1sf9n5a.js → subspace.command-5cehmcdd.js} +1 -1
  44. package/{tunnel.command-dcb0wg93.js → tunnel.command-yrd4atqy.js} +1 -1
  45. package/{verify.command-07fqhpak.js → verify.command-kbq0fcg8.js} +4 -4
  46. package/{workflow.command-c2jhzf7v.js → workflow.command-274qfa8z.js} +8 -8
  47. package/{workspace.command-gv20zq1z.js → workspace.command-r6hgmawy.js} +17 -16
@@ -1,4 +1,326 @@
1
1
  // @bun
2
+ // pkgs/@akanjs/language/akanGraph.ts
3
+ var capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
4
+ var lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
5
+ var memberSourcePattern = /\.(signal|service|store)\.ts$/;
6
+ var skippedPattern = /(?:\.(?:constant|document|dictionary|test|spec)\.tsx?|\/lib\/(?:cnst|db|dict|sig|srv|st|useClient|useServer)\.ts|\/index\.tsx?|^(?:apps|libs)\/[^/]+\/(?:client|server)\.ts)$/;
7
+ var scalarPattern = /\/lib\/__scalar\/([^/]+)\/[^/]+\.constant\.ts$/;
8
+ var moduleDirPattern = /\/lib\/([^/]+)\//;
9
+ var typeKinds = new Set(["model", "scalar", "enum"]);
10
+ var clientRoots = new Set(["fetch", "st", "sig"]);
11
+
12
+ class GraphBuilder {
13
+ #source;
14
+ #nodes = new Map;
15
+ #edges = new Map;
16
+ #contexts = new Map;
17
+ #members = new Map;
18
+ constructor(source) {
19
+ this.#source = source;
20
+ }
21
+ build() {
22
+ const { facts } = this.#source;
23
+ const constantsByOwner = new Map;
24
+ for (const file of facts)
25
+ constantsByOwner.set(file.owner, [...constantsByOwner.get(file.owner) ?? [], ...file.constants]);
26
+ const scopeOf = (owner) => [
27
+ ...constantsByOwner.get(owner) ?? [],
28
+ ...[...constantsByOwner].filter(([key]) => key !== owner && key?.startsWith("libs/")).flatMap(([, list]) => list)
29
+ ];
30
+ const typed = [];
31
+ for (const file of facts) {
32
+ const { owner } = file;
33
+ const scalar = this.#source.relative(file.fileName).match(scalarPattern)?.[1];
34
+ const scalarClass = scalar ? file.constants.find((constant) => constant.name === capitalize(scalar)) : undefined;
35
+ if (scalar && scalarClass) {
36
+ const id = this.#key("scalar", owner, scalar);
37
+ const node = this.#addNode(id, "scalar", owner, scalar, scalarClass.name, scalarClass.span);
38
+ node.fields = this.#fieldsOf(scalarClass, scopeOf(owner));
39
+ typed.push(node);
40
+ }
41
+ for (const item of file.enums) {
42
+ const id = this.#key("enum", owner, item.name);
43
+ this.#addNode(id, "enum", owner, this.#moduleDirOf(file.fileName), item.name, item.span).values = item.values;
44
+ }
45
+ }
46
+ for (const file of facts) {
47
+ const { owner } = file;
48
+ for (const service of file.services) {
49
+ const refName = service.model;
50
+ if (!refName)
51
+ continue;
52
+ const modelId = this.#key("model", owner, refName);
53
+ const modelClass = constantsByOwner.get(owner)?.find((constant) => constant.name === capitalize(refName));
54
+ if (modelClass && !this.#nodes.has(modelId)) {
55
+ const node = this.#addNode(modelId, "model", owner, refName, modelClass.name, modelClass.span);
56
+ node.fields = this.#fieldsOf(modelClass, scopeOf(owner));
57
+ typed.push(node);
58
+ }
59
+ for (const method of service.methods)
60
+ this.#addMember("method", owner, refName, method, `${service.name}.${method.name}`, file.fileName);
61
+ }
62
+ for (const filter of file.filters) {
63
+ if (!filter.name.endsWith("Filter"))
64
+ continue;
65
+ const refName = lowerFirst(filter.name.slice(0, -"Filter".length));
66
+ this.#addNode(this.#key("query", owner, refName), "query", owner, refName, "", filter.span);
67
+ for (const query of filter.queries)
68
+ this.#addNode(this.#key("query", owner, refName, query.name), "query", owner, refName, query.name, query.span);
69
+ }
70
+ for (const slice of file.slices) {
71
+ const refName = slice.model;
72
+ if (!refName)
73
+ continue;
74
+ const fallback = this.#addNode(this.#key("slice", owner, refName), "slice", owner, refName, "", slice.span, slice.guards);
75
+ for (const guard of slice.guards)
76
+ this.#guard(fallback, guard);
77
+ for (const key of slice.keys) {
78
+ const detail = [...key.guards, ...key.live ? ["live"] : []];
79
+ const node = this.#addMember("slice", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
80
+ for (const guard of key.guards)
81
+ this.#guard(node, guard);
82
+ }
83
+ }
84
+ for (const endpoint of file.endpoints) {
85
+ const refName = endpoint.model;
86
+ if (!refName)
87
+ continue;
88
+ for (const key of endpoint.keys) {
89
+ const detail = [...key.verb ? [key.verb] : [], ...key.guards];
90
+ const node = this.#addMember("endpoint", owner, refName, key, `${refName}.${key.name}`, file.fileName, detail);
91
+ for (const guard of key.guards)
92
+ this.#guard(node, guard);
93
+ }
94
+ }
95
+ for (const store of file.stores)
96
+ if (store.model)
97
+ for (const action of store.actions)
98
+ this.#addMember("action", owner, store.model, action, `${store.name}.${action.name}`, file.fileName);
99
+ }
100
+ const types = new Map;
101
+ for (const node of this.#nodes.values())
102
+ if (typeKinds.has(node.kind))
103
+ types.set(node.label, [...types.get(node.label) ?? [], node]);
104
+ for (const node of typed)
105
+ for (const field of node.fields ?? []) {
106
+ const candidates = (field.type ? types.get(field.type) ?? [] : []).filter((type) => this.#visible(type.owner, node.owner));
107
+ field.ref = (candidates.find((type) => type.owner === node.owner) ?? candidates[0])?.id ?? null;
108
+ if (field.ref)
109
+ this.#addEdge(node.id, field.ref, "field", `${field.name}${field.array ? "[]" : ""}`, field.at);
110
+ }
111
+ for (const [fileName, words] of this.#source.files)
112
+ this.#walk(fileName, words);
113
+ return {
114
+ version: 1,
115
+ nodes: [...this.#nodes.values()].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0),
116
+ edges: [...this.#edges.values()]
117
+ };
118
+ }
119
+ #key(kind, owner, scope, name = "") {
120
+ return `${kind}:${owner ?? ""}:${scope}${name ? `.${name}` : ""}`;
121
+ }
122
+ #location(span) {
123
+ return { file: this.#source.relative(span.fileName), line: span.line + 1, column: span.character + 1 };
124
+ }
125
+ #addNode(id, kind, owner, module, name, span, detail = [], label = (kind === "query" || kind === "slice") && module ? `${module}${name ? `.${name}` : " (default)"}` : name) {
126
+ const existing = this.#nodes.get(id);
127
+ if (existing)
128
+ return existing;
129
+ const node = {
130
+ id,
131
+ kind,
132
+ name,
133
+ label,
134
+ owner,
135
+ module,
136
+ detail,
137
+ at: span ? this.#location(span) : null
138
+ };
139
+ this.#nodes.set(id, node);
140
+ return node;
141
+ }
142
+ #addMember(kind, owner, refName, member, label, fileName, detail = []) {
143
+ const id = this.#key(kind, owner, refName, member.name);
144
+ const node = this.#addNode(id, kind, owner, refName, member.name, member.span, detail, label);
145
+ this.#contexts.set(fileName, [
146
+ ...this.#contexts.get(fileName) ?? [],
147
+ { id, kind, owner, module: refName, extent: member.extent }
148
+ ]);
149
+ const byName = `${kind}:${member.name}`;
150
+ this.#members.set(byName, [...this.#members.get(byName) ?? [], node]);
151
+ return node;
152
+ }
153
+ #addEdge(from, to, kind, label, at) {
154
+ if (from === to)
155
+ return;
156
+ const key = `${from}
157
+ ${to}
158
+ ${kind}
159
+ ${label ?? ""}`;
160
+ const existing = this.#edges.get(key);
161
+ if (existing)
162
+ existing.count += 1;
163
+ else
164
+ this.#edges.set(key, { from, to, kind, label, count: 1, at });
165
+ }
166
+ #guard(node, guard) {
167
+ const [role, name] = guard.includes(" ") ? guard.split(" ") : [null, guard];
168
+ if (!name || name === "?")
169
+ return;
170
+ const id = `guard:${name}`;
171
+ if (!this.#nodes.has(id))
172
+ this.#nodes.set(id, { id, kind: "guard", name, label: name, owner: null, module: null, detail: [], at: null });
173
+ this.#addEdge(node.id, id, "guard", role, node.at);
174
+ }
175
+ #moduleDirOf(fileName) {
176
+ return this.#source.relative(fileName).match(moduleDirPattern)?.[1] ?? null;
177
+ }
178
+ #fieldsOf(constant, scope) {
179
+ const fields = new Map;
180
+ const seen = new Set;
181
+ const visit = (current) => {
182
+ if (seen.has(current))
183
+ return;
184
+ seen.add(current);
185
+ for (const parent of current.parents) {
186
+ const parentClass = scope.find((other) => other.name === parent && other.span.fileName === current.span.fileName) ?? scope.find((other) => other.name === parent);
187
+ if (parentClass)
188
+ visit(parentClass);
189
+ }
190
+ for (const field of current.fields)
191
+ if (!fields.has(field.name))
192
+ fields.set(field.name, {
193
+ name: field.name,
194
+ type: field.type,
195
+ array: field.array,
196
+ optional: field.optional,
197
+ ref: null,
198
+ declaredIn: current.name,
199
+ at: this.#location(field.span)
200
+ });
201
+ };
202
+ visit(constant);
203
+ return [...fields.values()];
204
+ }
205
+ #visible(target, from) {
206
+ return !from || !target || target === from || target.startsWith("libs/");
207
+ }
208
+ #targetNodeOf({ family, owner, refName, sourceKey }) {
209
+ const isDefault = /^[A-Z]/.test(sourceKey);
210
+ const id = family === "slice" || family === "query" ? this.#key(family, owner, refName, isDefault ? "" : sourceKey) : family === "model" || family === "formSetter" ? this.#key("model", owner, refName) : family === "endpoint" ? this.#key("endpoint", owner, refName, sourceKey) : null;
211
+ return id && this.#nodes.has(id) ? id : null;
212
+ }
213
+ #membersNamed(kind, name, owner, refName) {
214
+ const nodes = (this.#members.get(`${kind}:${name}`) ?? []).filter((node) => (!refName || node.module === refName) && this.#visible(node.owner, owner));
215
+ const own = nodes.filter((node) => node.owner === owner);
216
+ return (own.length ? own : nodes).map((node) => node.id);
217
+ }
218
+ #plainTargetsOf(chain, name, context, owner) {
219
+ const [head, second] = chain ?? [];
220
+ if (chain?.length === 1 && head === "fetch")
221
+ return this.#membersNamed("endpoint", name, owner);
222
+ if (chain?.length === 2 && head === "st" && second === "do")
223
+ return this.#membersNamed("action", name, owner);
224
+ if (chain?.length === 1 && head === "this" && (context.kind === "method" || context.kind === "action"))
225
+ return this.#membersNamed(context.kind, name, context.owner, context.module).filter((id) => id.startsWith(`${context.kind}:${context.owner ?? ""}:`));
226
+ if (chain?.length === 2 && head === "this" && second && /.Service$/.test(second))
227
+ return this.#membersNamed("method", name, owner, second.slice(0, -"Service".length));
228
+ return [];
229
+ }
230
+ #walk(fileName, words) {
231
+ const relative = this.#source.relative(fileName);
232
+ const contexts = this.#contexts.get(fileName);
233
+ const isComponentFile = !memberSourcePattern.test(fileName) && !skippedPattern.test(relative) && (words.includes(`
234
+ fetch
235
+ `) || words.includes(`
236
+ st
237
+ `));
238
+ if (!contexts && !isComponentFile)
239
+ return;
240
+ const text = this.#source.readText(fileName);
241
+ if (text === undefined)
242
+ return;
243
+ const { ts } = this.#source;
244
+ const owner = this.#source.ownerOf(fileName);
245
+ const source = this.#source.parse(fileName, text);
246
+ const visit = (node) => {
247
+ if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
248
+ const start = node.name.getStart(source);
249
+ const chain = this.#chainOf(node.expression);
250
+ const context = contexts ? contexts.find(({ extent }) => extent.start <= start && start < extent.end) : chain && clientRoots.has(chain[0]) ? this.#componentOf(source, node) : undefined;
251
+ if (context)
252
+ this.#link(fileName, source, node.name, chain, context, owner);
253
+ }
254
+ ts.forEachChild(node, visit);
255
+ };
256
+ visit(source);
257
+ }
258
+ #link(fileName, source, identifier, chain, context, owner) {
259
+ const resolved = this.#source.resolve(fileName, identifier).map((target) => this.#targetNodeOf(target)).filter((id) => id !== null);
260
+ const targets = resolved.length ? resolved : this.#plainTargetsOf(chain, identifier.text, context, owner);
261
+ if (!targets.length)
262
+ return;
263
+ if (context.pending && !this.#nodes.has(context.id))
264
+ this.#nodes.set(context.id, context.pending);
265
+ const own = targets.filter((id) => this.#nodes.get(id)?.owner === owner);
266
+ const kind = context.kind === "component" ? "uses" : chain?.[0] === "fetch" ? "fetches" : "calls";
267
+ const position = source.getLineAndCharacterOfPosition(identifier.getStart(source));
268
+ const at = { file: this.#source.relative(fileName), line: position.line + 1, column: position.character + 1 };
269
+ for (const target of new Set(own.length ? own : targets))
270
+ this.#addEdge(context.id, target, kind, identifier.text, at);
271
+ }
272
+ #chainOf(expression) {
273
+ const { ts } = this.#source;
274
+ if (ts.isNonNullExpression(expression) || ts.isParenthesizedExpression(expression))
275
+ return this.#chainOf(expression.expression);
276
+ if (ts.isIdentifier(expression))
277
+ return [expression.text];
278
+ if (expression.kind === ts.SyntaxKind.ThisKeyword)
279
+ return ["this"];
280
+ if (!ts.isPropertyAccessExpression(expression))
281
+ return null;
282
+ const head = this.#chainOf(expression.expression);
283
+ return head ? [...head, expression.name.text] : null;
284
+ }
285
+ #componentOf(source, node) {
286
+ const { ts } = this.#source;
287
+ let top = node;
288
+ while (top.parent && !ts.isSourceFile(top.parent))
289
+ top = top.parent;
290
+ const declared = ts.isVariableStatement(top) ? top.declarationList.declarations[0]?.name : ts.isFunctionDeclaration(top) || ts.isClassDeclaration(top) ? top.name : undefined;
291
+ const isDefaultExport = ts.canHaveModifiers(top) && !!ts.getModifiers(top)?.some(({ kind }) => kind === ts.SyntaxKind.DefaultKeyword);
292
+ const name = declared && ts.isIdentifier(declared) && !isDefaultExport ? declared.text : "default";
293
+ const relative = this.#source.relative(source.fileName);
294
+ const owner = this.#source.ownerOf(source.fileName);
295
+ const id = `component:${relative}#${name}`;
296
+ const context = {
297
+ id,
298
+ kind: "component",
299
+ owner,
300
+ module: null,
301
+ extent: { start: top.getStart(source), end: top.getEnd() }
302
+ };
303
+ if (this.#nodes.has(id))
304
+ return context;
305
+ const pagePrefix = owner ? `${owner}/page/` : null;
306
+ const route = pagePrefix && relative.startsWith(pagePrefix) ? relative.slice(pagePrefix.length).replace(/\.tsx?$/, "") : null;
307
+ const base = relative.slice(relative.lastIndexOf("/") + 1).replace(/\.tsx?$/, "");
308
+ const label = route ? `${route}${name === "default" ? "" : `#${name}`}` : name === "default" ? base : `${base}.${name}`;
309
+ const position = source.getLineAndCharacterOfPosition((declared ?? top).getStart(source));
310
+ context.pending = {
311
+ id,
312
+ kind: "component",
313
+ name,
314
+ label,
315
+ owner,
316
+ module: this.#moduleDirOf(source.fileName),
317
+ detail: route ? ["page"] : [],
318
+ at: { file: relative, line: position.line + 1, column: position.character + 1 }
319
+ };
320
+ return context;
321
+ }
322
+ }
323
+
2
324
  // pkgs/@akanjs/language/ast.ts
3
325
  var createAst = (ts) => {
4
326
  const sourceFileFor = (fileName, content, scriptKind = ts.ScriptKind.TS) => ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true, scriptKind);
@@ -65,7 +387,7 @@ var createAst = (ts) => {
65
387
  };
66
388
 
67
389
  // pkgs/@akanjs/language/moduleFacts.ts
68
- var moduleCallees = new Set(["via", "from", "into", "serve", "slice", "endpoint", "store"]);
390
+ var moduleCallees = new Set(["via", "from", "into", "serve", "slice", "endpoint", "store", "enumOf"]);
69
391
  var argMethods = new Set(["param", "body", "search", "room", "msg"]);
70
392
  var ownerOf = (relativePath) => {
71
393
  const [root, name] = relativePath.split("/");
@@ -87,6 +409,10 @@ var createFactReader = (ts, ast) => {
87
409
  endCharacter: tail.character
88
410
  };
89
411
  };
412
+ const extentOf = (source, node) => ({
413
+ start: node.getStart(source),
414
+ end: node.getEnd()
415
+ });
90
416
  const unwrap = (expression) => {
91
417
  let current = expression;
92
418
  while (ts.isParenthesizedExpression(current) || ts.isAsExpression(current) || ts.isSatisfiesExpression(current))
@@ -143,6 +469,7 @@ var createFactReader = (ts, ast) => {
143
469
  {
144
470
  name,
145
471
  span: spanOf(source, property.name),
472
+ extent: extentOf(source, property),
146
473
  guards: root ? guardsIn(optionObjectOf(root)) : [],
147
474
  live: methods.includes("live"),
148
475
  argCount: methods.filter((method) => argMethods.has(method)).length
@@ -179,6 +506,7 @@ var createFactReader = (ts, ast) => {
179
506
  {
180
507
  name,
181
508
  span: spanOf(source, property.name),
509
+ extent: extentOf(source, property),
182
510
  verb: root ? verbOf(root.expression) : null,
183
511
  guards: root ? guardsIn(optionObjectOf(root)) : [],
184
512
  argCount: methods.filter((method) => argMethods.has(method)).length
@@ -190,17 +518,48 @@ var createFactReader = (ts, ast) => {
190
518
  const query = returnedObject(builder)?.properties.find((property) => ts.isPropertyAssignment(property) && ast.nodeName(property.name) === "query")?.initializer;
191
519
  return query && ts.isObjectLiteralExpression(query) ? objectKeys(source, query) : [];
192
520
  };
521
+ const typeOf = (expression) => {
522
+ const value = expression && unwrap(expression);
523
+ if (value && ts.isArrayLiteralExpression(value))
524
+ return { type: typeOf(value.elements[0]).type, array: true };
525
+ return { type: value ? ast.expressionName(value) : null, array: false };
526
+ };
527
+ const fieldsOf = (source, object) => (object?.properties ?? []).flatMap((property) => {
528
+ const name = ast.propertyName(property);
529
+ const node = keyName(property);
530
+ if (!name || !node)
531
+ return [];
532
+ const { root, methods } = ts.isPropertyAssignment(property) ? chainOf(property.initializer) : { root: null, methods: [] };
533
+ return [
534
+ { name, span: spanOf(source, node), ...typeOf(root?.arguments[0]), optional: methods.includes("optional") }
535
+ ];
536
+ });
193
537
  const constantOf = (source, name, call) => {
194
538
  const parents = call.arguments.map(unwrap).filter((arg) => ts.isIdentifier(arg) || ts.isPropertyAccessExpression(arg)).map((arg) => ast.expressionName(arg)).filter((parent) => parent !== null);
195
- const fields = call.arguments.flatMap((arg) => objectKeys(source, ast.firstObjectReturnedByArrow(arg)));
539
+ const fields = call.arguments.flatMap((arg) => fieldsOf(source, ast.firstObjectReturnedByArrow(arg)));
196
540
  return { ...name, parents, fields };
197
541
  };
542
+ const enumValuesOf = (call) => {
543
+ const list = call.arguments[1] && unwrap(call.arguments[1]);
544
+ if (!list || !ts.isArrayLiteralExpression(list))
545
+ return [];
546
+ return list.elements.flatMap((element) => ts.isStringLiteralLike(element) ? [element.text] : []);
547
+ };
548
+ const methodsOf = (source, statement) => statement.members.flatMap((member) => {
549
+ if (!ts.isMethodDeclaration(member) || !member.body)
550
+ return [];
551
+ const name = ast.nodeName(member.name);
552
+ if (!name || ts.getModifiers(member)?.some(({ kind }) => kind === ts.SyntaxKind.StaticKeyword))
553
+ return [];
554
+ return [{ name, span: spanOf(source, member.name), extent: extentOf(source, member) }];
555
+ });
198
556
  const lowerFirst = (text) => text.charAt(0).toLowerCase() + text.slice(1);
199
557
  const read = (source, owner) => {
200
558
  const facts = {
201
559
  fileName: source.fileName,
202
560
  owner,
203
561
  constants: [],
562
+ enums: [],
204
563
  filters: [],
205
564
  models: [],
206
565
  services: [],
@@ -219,12 +578,18 @@ var createFactReader = (ts, ast) => {
219
578
  const builder = builderOf(call);
220
579
  if (callee === "via")
221
580
  facts.constants.push(constantOf(source, name, call));
581
+ else if (callee === "enumOf")
582
+ facts.enums.push({ ...name, values: enumValuesOf(call) });
222
583
  else if (callee === "from")
223
584
  facts.filters.push({ ...name, queries: filterQueriesOf(source, builder) });
224
585
  else if (callee === "into")
225
586
  facts.models.push({ ...name, model: name.name.endsWith("Model") ? lowerFirst(name.name.slice(0, -5)) : null });
226
587
  else if (callee === "serve")
227
- facts.services.push({ ...name, model: moduleRefOf(call.arguments[0], "db") });
588
+ facts.services.push({
589
+ ...name,
590
+ model: moduleRefOf(call.arguments[0], "db"),
591
+ methods: methodsOf(source, statement)
592
+ });
228
593
  else if (callee === "slice")
229
594
  facts.slices.push({
230
595
  ...name,
@@ -242,7 +607,8 @@ var createFactReader = (ts, ast) => {
242
607
  facts.stores.push({
243
608
  ...name,
244
609
  model: moduleRefOf(call.arguments[0], "sig"),
245
- stateKeys: objectKeys(source, returnedObject(builder))
610
+ stateKeys: objectKeys(source, returnedObject(builder)),
611
+ actions: methodsOf(source, statement)
246
612
  });
247
613
  }
248
614
  return facts;
@@ -261,7 +627,7 @@ import {
261
627
  sliceNames,
262
628
  stateSetterName
263
629
  } from "akanjs/common/akanNames.ts";
264
- var capitalize = (text) => text.charAt(0).toUpperCase() + text.slice(1);
630
+ var capitalize2 = (text) => text.charAt(0).toUpperCase() + text.slice(1);
265
631
 
266
632
  class NameTable {
267
633
  #byName = new Map;
@@ -336,7 +702,7 @@ class NameTable {
336
702
  }
337
703
  #addGroup(group, constants) {
338
704
  const { owner, refName } = group;
339
- const Model = capitalize(refName);
705
+ const Model = capitalize2(refName);
340
706
  const base = { owner, refName };
341
707
  const modelClass = group.constants.find((constant) => constant.name === Model);
342
708
  const facts = group.facts;
@@ -629,6 +995,23 @@ ${[...new Set(text.match(wordPattern))].join(`
629
995
  referencesAt(givenName, offset, readText) {
630
996
  return this.#usesOf(this.#sourceEntriesAt(pathOf(givenName), offset), readText).map((use) => use.span);
631
997
  }
998
+ graph(readText) {
999
+ return new GraphBuilder({
1000
+ ts: this.#ts,
1001
+ facts: [...this.#facts].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([, facts]) => facts),
1002
+ files: [...this.#fileWords].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0),
1003
+ readText,
1004
+ parse: (fileName, text) => this.#parse(fileName, text),
1005
+ resolve: (fileName, identifier) => {
1006
+ if (!this.#nameTable().lookup(identifier.text).length)
1007
+ return [];
1008
+ const site = this.#siteOf(identifier);
1009
+ return site ? this.#resolve(fileName, site) : [];
1010
+ },
1011
+ relative: (fileName) => this.#relative(fileName),
1012
+ ownerOf: (fileName) => this.#ownerOf(fileName)
1013
+ }).build();
1014
+ }
632
1015
  renameTargetAt(givenName, offset) {
633
1016
  const source = this.#sourceEntriesAt(pathOf(givenName), offset).find((entry) => entry.renamed);
634
1017
  return source ? { family: source.family, sourceKey: source.sourceKey, span: source.span } : null;
@@ -23,7 +23,7 @@ import {
23
23
  workflowPathsForPlan,
24
24
  workflowRunArtifactPath,
25
25
  workflowSyncDir
26
- } from "./index-1404hqcj.js";
26
+ } from "./index-m02tdq8a.js";
27
27
 
28
28
  // pkgs/@akanjs/devkit/akanContext.ts
29
29
  import { readdir } from "fs/promises";
@@ -7,7 +7,7 @@ import {
7
7
  createWorkflowBaselineSummary,
8
8
  buildAkanModuleContextIndex,
9
9
  toolingRolloutGate
10
- } from "./index-1404hqcj.js";
10
+ } from "./index-m02tdq8a.js";
11
11
  import {
12
12
  buildResourceList,
13
13
  codexMcpConfigPath,
@@ -17,7 +17,7 @@ import {
17
17
  upsertCodexMcpServerBlock,
18
18
  renderDoctorText,
19
19
  AkanContextAnalyzer
20
- } from "./index-dbxac7mz.js";
20
+ } from "./index-j9d3mjx1.js";
21
21
  import {
22
22
  runner
23
23
  } from "./index-9zy8479y.js";
@@ -34,12 +34,15 @@ import {
34
34
  import {
35
35
  Prompter2
36
36
  } from "./index-j6eeh5d7.js";
37
+ import {
38
+ WorkspaceGraph
39
+ } from "./index-vzpnr12w.js";
37
40
  import {
38
41
  RepairRunner
39
- } from "./index-ms1am2wr.js";
42
+ } from "./index-tns543wd.js";
40
43
  import {
41
44
  WorkflowRunner
42
- } from "./index-mzjwq4dd.js";
45
+ } from "./index-9z3egsmg.js";
43
46
 
44
47
  // pkgs/@akanjs/devkit/akanMcpContract.ts
45
48
  import { lstatSync, realpathSync } from "fs";
@@ -294,6 +297,11 @@ var readonlyMcpTools = [
294
297
  description: "Legacy broad module context. Pass app in monorepos; prefer inspect_akan_context.moduleContext or fieldInsertionContext for typed add-field evidence.",
295
298
  inputSchema: { type: "object", properties: { app: stringProperty, module: stringProperty }, required: ["module"] }
296
299
  },
300
+ {
301
+ name: "get_graph",
302
+ description: "Read-only Akan Graph from source, no dev server needed: models with their fields and relations, slices and endpoints with guards, the service methods and queries each calls, the store actions that fetch them, and the components and pages that use them. Every node and edge carries its source location. Pass app and/or module to scope a large workspace.",
303
+ inputSchema: { type: "object", properties: { app: stringProperty, module: stringProperty } }
304
+ },
297
305
  {
298
306
  name: "get_guideline",
299
307
  description: "Return an Akan agent guideline resource by name.",
@@ -748,6 +756,11 @@ class ContextRunner2 extends runner("context") {
748
756
  }
749
757
  return modules;
750
758
  }
759
+ if (name === "get_graph")
760
+ return WorkspaceGraph.answer(await WorkspaceGraph.build(workspace), {
761
+ app: typeof args.app === "string" ? args.app : null,
762
+ module: typeof args.module === "string" ? args.module : null
763
+ });
751
764
  if (name === "get_guideline")
752
765
  return await Prompter2.getInstruction(stringArg(args, "name"));
753
766
  if (name === "doctor_workspace")
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  createAst,
8
8
  AkanIndex
9
- } from "./index-gf4fcw1n.js";
9
+ } from "./index-j2dgmzbj.js";
10
10
  import {
11
11
  camelToKebabCase
12
12
  } from "./index-9zy8479y.js";
@@ -331,6 +331,7 @@ import { MemoryLimit } from "akanjs/server/memoryLimit";
331
331
  var builderMsgTypeSet = new Set([
332
332
  "build-route-res",
333
333
  "build-csr-res",
334
+ "build-graph-res",
334
335
  "builder-ready",
335
336
  "invalidate",
336
337
  "css-updated",
@@ -422,7 +423,7 @@ class IncrementalBuilderHost {
422
423
  return;
423
424
  if (!msg || typeof msg !== "object")
424
425
  return;
425
- if (msg.type === "build-route-res" || msg.type === "build-csr-res")
426
+ if (msg.type === "build-route-res" || msg.type === "build-csr-res" || msg.type === "build-graph-res")
426
427
  this.#inFlight.delete(msg.id);
427
428
  if (builderMsgTypeSet.has(msg.type))
428
429
  this.#onMessage(msg);
@@ -553,7 +554,7 @@ class IncrementalBuilderHost {
553
554
  }
554
555
  try {
555
556
  this.#proc.send(message);
556
- if (message.type === "build-route" || message.type === "build-csr")
557
+ if (message.type === "build-route" || message.type === "build-csr" || message.type === "build-graph")
557
558
  this.#inFlight.set(message.id, message.type);
558
559
  return true;
559
560
  } catch (error) {
@@ -813,7 +814,7 @@ class DevBootLatch {
813
814
  }
814
815
 
815
816
  // pkgs/@akanjs/devkit/akanApp/akanApp.host.ts
816
- var backendMsgTypeSet = new Set(["build-route", "build-csr"]);
817
+ var backendMsgTypeSet = new Set(["build-route", "build-csr", "build-graph"]);
817
818
  var asMib = (bytes) => Math.round(bytes / 1024 / 1024);
818
819
  var BACKEND_RESTART_DEBOUNCE_MS = 120;
819
820
  var BACKEND_GRACEFUL_TIMEOUT_MS = 8000;
@@ -1235,7 +1236,7 @@ ${this.#backendStderrTail.join(`
1235
1236
  await this.#handleInvalidate(message);
1236
1237
  return;
1237
1238
  }
1238
- if (message.type === "build-route-res" || message.type === "build-csr-res") {
1239
+ if (message.type === "build-route-res" || message.type === "build-csr-res" || message.type === "build-graph-res") {
1239
1240
  const answer = this.#builderRequests.settle(message);
1240
1241
  if (!answer) {
1241
1242
  this.logger.verbose(`[builder] dropped a ${message.type} no live backend is waiting for (id=${message.id})`);
@@ -1610,6 +1611,8 @@ ${this.#backendStderrTail.join(`
1610
1611
  this.#sendToBackend({ type: "build-route-res", id: message.id, ok: false, error });
1611
1612
  else if (message.type === "build-csr")
1612
1613
  this.#sendToBackend({ type: "build-csr-res", id: message.id, ok: false, error });
1614
+ else if (message.type === "build-graph")
1615
+ this.#sendToBackend({ type: "build-graph-res", id: message.id, ok: false, error });
1613
1616
  else
1614
1617
  return false;
1615
1618
  return true;
@@ -1953,7 +1956,7 @@ ${this.#backendStderrTail.join(`
1953
1956
  Object.assign(this.env, { AKAN_DEV_CSR_REBUILD: "1" });
1954
1957
  this.logger.verbose(`[csr] armed dev CSR rebuilds (${message.reason})`);
1955
1958
  }
1956
- if (message.type === "build-route" || message.type === "build-csr") {
1959
+ if (message.type === "build-route" || message.type === "build-csr" || message.type === "build-graph") {
1957
1960
  const outgoing = this.#builderRequests.issue(message);
1958
1961
  if (this.#builder?.send(outgoing))
1959
1962
  return;
@@ -1,16 +1,16 @@
1
1
  // @bun
2
2
  import {
3
3
  jsonText
4
- } from "./index-1404hqcj.js";
4
+ } from "./index-m02tdq8a.js";
5
5
  import {
6
6
  akanMcpInstallTargets
7
- } from "./index-dbxac7mz.js";
7
+ } from "./index-j9d3mjx1.js";
8
8
  import {
9
9
  script
10
10
  } from "./index-9zy8479y.js";
11
11
  import {
12
12
  ContextRunner2
13
- } from "./index-f6zrhcnk.js";
13
+ } from "./index-jb2sreps.js";
14
14
 
15
15
  // pkgs/@akanjs/cli/context/context.script.ts
16
16
  import { Logger } from "akanjs/common";
@@ -30,7 +30,7 @@ import {
30
30
  import {
31
31
  createAst,
32
32
  createFactReader
33
- } from "./index-gf4fcw1n.js";
33
+ } from "./index-j2dgmzbj.js";
34
34
  import {
35
35
  collectRecipeSources2,
36
36
  scanRecipes2
@@ -18,7 +18,7 @@ import {
18
18
  } from "./index-9zy8479y.js";
19
19
  import {
20
20
  ApplicationScript
21
- } from "./index-ewbmfarf.js";
21
+ } from "./index-db2nqrad.js";
22
22
  import {
23
23
  PackageScript
24
24
  } from "./index-84h43kg6.js";
@@ -7,10 +7,10 @@ import {
7
7
  isWorkflowSysName,
8
8
  isWorkflowModuleName,
9
9
  renderRepairReport
10
- } from "./index-1404hqcj.js";
10
+ } from "./index-m02tdq8a.js";
11
11
  import {
12
12
  AkanContextAnalyzer
13
- } from "./index-dbxac7mz.js";
13
+ } from "./index-j9d3mjx1.js";
14
14
  import {
15
15
  runner
16
16
  } from "./index-9zy8479y.js";