@akanjs/cli 3.2.0-rc.2 → 3.2.0-rc.21

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 (132) hide show
  1. package/.build-stamp +2 -1
  2. package/CodeAgent-faqv7t4g.js +11 -0
  3. package/{CodeTui-zyc7zaq6.js → CodeTui-vqck9tet.js} +822 -666
  4. package/README.ko.md +26 -1
  5. package/README.md +26 -1
  6. package/TunnelShare-bwe3ddv7.js +18 -0
  7. package/agent.command-p75jvgrd.js +56 -0
  8. package/akanCode.js +12 -12
  9. package/appExecutor-020cyesq.js +11 -0
  10. package/{application.command-vb278qnq.js → application.command-ta2knqxm.js} +72 -34
  11. package/{applicationBuildRunner-bqbyeg84.js → applicationBuildRunner-gkh82j2b.js} +18 -13
  12. package/buildBatch.proc.js +26 -11
  13. package/{cloud.command-ca777ee2.js → cloud.command-v3jhfvm5.js} +31 -28
  14. package/cloud.script-be9s1432.js +35 -0
  15. package/{code.command-j08txqcd.js → code.command-mh7dh1st.js} +14 -9
  16. package/{context.command-2fa6egp9.js → context.command-1ycfjkdd.js} +28 -23
  17. package/context.runner-333jkz86.js +34 -0
  18. package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
  19. package/{devTui-w38ch13a.js → devTui-rf374y2w.js} +1 -1
  20. package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
  21. package/{guideline.command-w6yqpdec.js → guideline.command-w1grfwh7.js} +9 -4
  22. package/guidelines/agentRule/agentRule.instruction.md +17 -5
  23. package/guidelines/akanApi/akanApi.instruction.md +5 -3
  24. package/guidelines/conventions/core.md +23 -5
  25. package/guidelines/conventions/rules/app.md +4 -1
  26. package/guidelines/conventions/rules/page.md +5 -0
  27. package/guidelines/errorCodes/errorCodes.instruction.md +158 -0
  28. package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
  29. package/guidelines/mcpRule/mcpRule.instruction.md +86 -2
  30. package/guidelines/pageRule/pageRule.instruction.md +11 -1
  31. package/guidelines/runtimeRule/runtimeRule.instruction.md +7 -2
  32. package/guidelines/transportRule/transportRule.instruction.md +8 -1
  33. package/incrementalBuilder.proc.js +574 -410
  34. package/{index-c5ymqb05.js → index-013n6z7m.js} +12 -12
  35. package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
  36. package/{index-8nbx607g.js → index-0hj82f9w.js} +136 -48
  37. package/{index-ebwkh7bt.js → index-1c0mjc2b.js} +25 -7
  38. package/{index-6h775rv3.js → index-1jk52ffq.js} +53 -12
  39. package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
  40. package/{index-ygrdw6jw.js → index-1pjwsh2g.js} +65 -8
  41. package/{index-cbcwxp5v.js → index-22g3jq43.js} +9 -7
  42. package/{index-466z5931.js → index-2d9nm03s.js} +580 -364
  43. package/{index-0fj9ra3q.js → index-2k6mve6a.js} +18 -11
  44. package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
  45. package/{index-j7p0jgaq.js → index-52w4jb87.js} +6 -6
  46. package/{index-e22zedc2.js → index-5h888r6j.js} +3 -3
  47. package/{index-7kmbqp0b.js → index-6pxmcaq8.js} +1 -1
  48. package/{index-xa0289eg.js → index-6zb17wcm.js} +16 -9
  49. package/{index-qgazn58x.js → index-7a07tdap.js} +50 -38
  50. package/{index-m5sg5spm.js → index-7ehdht84.js} +565 -187
  51. package/{index-y725zb1a.js → index-7v7tvgt7.js} +196 -168
  52. package/{index-pq5rjkch.js → index-88s746ns.js} +7 -2
  53. package/{index-r0a604h4.js → index-99kjwyma.js} +1 -1
  54. package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
  55. package/{index-386canwe.js → index-9rv2zt48.js} +186 -121
  56. package/{index-wr9magsr.js → index-9zswcze5.js} +3 -3
  57. package/{index-xq97me1h.js → index-a41vv4cy.js} +811 -697
  58. package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
  59. package/{index-bdmgqzb5.js → index-bket1068.js} +58 -29
  60. package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
  61. package/{index-1cb9apzn.js → index-czf94w8c.js} +2 -2
  62. package/{index-65b6ms4c.js → index-d3178asw.js} +15 -11
  63. package/index-dss3ds74.js +127 -0
  64. package/{index-annxfpgz.js → index-eyfty8kk.js} +9 -9
  65. package/{index-ny2k80mv.js → index-ffa52fwf.js} +1 -1
  66. package/{index-8jpc5fqv.js → index-g7jgd4xs.js} +2 -2
  67. package/{index-abfbf01s.js → index-gwsesvqc.js} +2 -2
  68. package/{index-kcpk2d20.js → index-h1w4wqgd.js} +1474 -1139
  69. package/{index-j1hjb477.js → index-hp2c7xc2.js} +1 -1
  70. package/index-j4yvgfhr.js +70 -0
  71. package/{index-84c2pgak.js → index-jx2jcw1r.js} +89 -78
  72. package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
  73. package/{index-2gees180.js → index-mpp4aas6.js} +62 -33
  74. package/index-na8r4a27.js +30 -0
  75. package/{index-0mqga3h9.js → index-nmxszh6x.js} +525 -440
  76. package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
  77. package/{index-20wvskt8.js → index-pt0agdck.js} +1 -1
  78. package/{index-htxck0pn.js → index-q444k260.js} +15 -10
  79. package/{index-wfmpxke3.js → index-qssq2d41.js} +2775 -3677
  80. package/{index-23860fej.js → index-rwgqba9p.js} +24 -9
  81. package/{index-v50xjbbe.js → index-t4d0ckde.js} +1 -1
  82. package/index-va90m8nd.js +25 -0
  83. package/index-vjbne22r.js +80 -0
  84. package/{index-djc5nxpy.js → index-w23tf30e.js} +6 -6
  85. package/{index-mvwvxgtd.js → index-wa01phm9.js} +289 -210
  86. package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
  87. package/{index-vbhx60x5.js → index-xwe7y0gf.js} +2140 -2165
  88. package/index-ze48c0vd.js +788 -0
  89. package/{index-dk4g0x0d.js → index-zttyg7tg.js} +27 -16
  90. package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
  91. package/index.js +29 -24
  92. package/libExecutor-tq994592.js +10 -0
  93. package/{library.command-8d03a0pq.js → library.command-x219mhcx.js} +9 -4
  94. package/{localRegistry.command-vyv5k6t0.js → localRegistry.command-4p17wa9t.js} +30 -24
  95. package/{module.command-vy3kg965.js → module.command-tjthnvvr.js} +17 -8
  96. package/{package.command-qjh13rs9.js → package.command-c6df2hxx.js} +13 -8
  97. package/package.json +2 -2
  98. package/{page.command-t0nx1jat.js → page.command-gf06paq2.js} +9 -4
  99. package/{pipeline.command-2yjeas7m.js → pipeline.command-y07dgj9b.js} +14 -8
  100. package/pkgExecutor-stde3yc3.js +10 -0
  101. package/{primitive.command-8vm49279.js → primitive.command-0enfygxn.js} +13 -8
  102. package/{projectTypecheck-s9hhe5sa.js → projectTypecheck-mk8wefvd.js} +2 -1
  103. package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
  104. package/{quality.command-v76fev72.js → quality.command-dkbdztad.js} +23 -16
  105. package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
  106. package/{repair.command-fp4m3w03.js → repair.command-g5vd95ax.js} +13 -8
  107. package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
  108. package/{scalar.command-hxe6try8.js → scalar.command-7909pg0d.js} +11 -6
  109. package/skills/akan-debug/SKILL.md +10 -3
  110. package/skills/akan-err/SKILL.md +7 -0
  111. package/skills/akan-mcp/SKILL.md +13 -2
  112. package/skills/akan-scaffold/SKILL.md +2 -2
  113. package/skills/akan-transport/SKILL.md +2 -0
  114. package/skills/akan-validate/SKILL.md +1 -0
  115. package/{subspace.command-q42n1844.js → subspace.command-at4jt1fb.js} +29 -23
  116. package/templates/biomeForm.ts +1 -1
  117. package/templates/env/_env.server.type.ts +1 -1
  118. package/templates/facetIndex/index.ts +2 -37
  119. package/templates/lib/sig.ts +0 -4
  120. package/templates/lib/useClient.ts +1 -1
  121. package/templates/workspaceRoot/AGENTS.md.template +2 -1
  122. package/{tunnel.command-22g11n0x.js → tunnel.command-91h92dwr.js} +17 -12
  123. package/{typeChecker-s640r6c0.js → typeChecker-bfrd1n9n.js} +1 -1
  124. package/typecheck.proc.js +6 -3
  125. package/{verify.command-rx43bha1.js → verify.command-pzky05ts.js} +26 -20
  126. package/{workflow.command-yg0d8mmq.js → workflow.command-mqqe4n12.js} +37 -19
  127. package/{workspace.command-fcfztvn5.js → workspace.command-y4rznvhx.js} +64 -53
  128. package/CodeAgent-6cpjtj25.js +0 -11
  129. package/TunnelShare-zkfkrw8w.js +0 -14
  130. package/agent.command-kf1g3nh4.js +0 -51
  131. package/cloud.script-agpxzq6j.js +0 -30
  132. package/context.runner-ftv8373t.js +0 -29
@@ -1,4 +1,17 @@
1
1
  // @bun
2
+ import {
3
+ runner
4
+ } from "./index-9rv2zt48.js";
5
+ import {
6
+ AppExecutor2
7
+ } from "./index-ze48c0vd.js";
8
+ import {
9
+ jsonText,
10
+ workflowStatus,
11
+ createWorkflowBaselineSummary,
12
+ buildAkanModuleContextIndex,
13
+ toolingRolloutGate
14
+ } from "./index-a41vv4cy.js";
2
15
  import {
3
16
  buildResourceList,
4
17
  codexMcpConfigPath,
@@ -8,47 +21,232 @@ import {
8
21
  upsertCodexMcpServerBlock,
9
22
  renderDoctorText,
10
23
  AkanContextAnalyzer
11
- } from "./index-0mqga3h9.js";
12
- import {
13
- AppExecutor
14
- } from "./index-wfmpxke3.js";
15
- import {
16
- jsonText,
17
- workflowStatus,
18
- createWorkflowBaselineSummary,
19
- buildAkanModuleContextIndex,
20
- toolingRolloutGate
21
- } from "./index-xq97me1h.js";
24
+ } from "./index-nmxszh6x.js";
22
25
  import {
23
- runner
24
- } from "./index-386canwe.js";
26
+ Prompter2
27
+ } from "./index-knpm8sdm.js";
25
28
  import {
26
29
  NativeApp
27
- } from "./index-djc5nxpy.js";
30
+ } from "./index-w23tf30e.js";
28
31
  import {
29
32
  isPlaceholderAppId
30
- } from "./index-20wvskt8.js";
33
+ } from "./index-pt0agdck.js";
31
34
  import {
32
35
  getMobileTargets,
33
36
  appIdsOf
34
37
  } from "./index-m9jj544v.js";
35
- import {
36
- Prompter2
37
- } from "./index-j6eeh5d7.js";
38
38
  import {
39
39
  WorkspaceGraph
40
- } from "./index-ebwkh7bt.js";
40
+ } from "./index-1c0mjc2b.js";
41
41
  import {
42
42
  RepairRunner
43
- } from "./index-cbcwxp5v.js";
43
+ } from "./index-22g3jq43.js";
44
44
  import {
45
45
  WorkflowRunner
46
- } from "./index-c5ymqb05.js";
46
+ } from "./index-013n6z7m.js";
47
47
 
48
- // pkgs/@akanjs/devkit/akanMcpContract.ts
48
+ // pkgs/@akanjs/devkit/context/akanMcpContract.ts
49
49
  import { lstatSync, realpathSync } from "fs";
50
50
  import path from "path";
51
51
  import { isRecord } from "akanjs/common";
52
+
53
+ // pkgs/@akanjs/devkit/context/akanContextInspection.ts
54
+ var inspectDiagnostic = (severity, code, message) => ({ severity, code, message });
55
+ var moduleEvidence = (module) => ({
56
+ kind: "module",
57
+ target: `${module.sysName}:${module.name}`,
58
+ path: module.path,
59
+ summary: `${module.kind} module at ${module.path} with ${module.files.length} source file(s).`
60
+ });
61
+ var moduleCandidate = (module) => ({
62
+ app: module.sysName,
63
+ sysType: module.sysType,
64
+ module: module.name,
65
+ kind: module.kind,
66
+ path: module.path,
67
+ files: module.files
68
+ });
69
+
70
+ class AkanContextInspection {
71
+ #workspace;
72
+ #question;
73
+ #diagnostics = [];
74
+ constructor(workspace, props) {
75
+ this.#workspace = workspace;
76
+ this.#question = props.question;
77
+ if (props.draft.type !== props.request.type) {
78
+ this.#diagnostics.push(inspectDiagnostic("warning", "inspect-draft-request-mismatch", `Draft chose ${props.draft.type}, but request uses ${props.request.type}.`));
79
+ }
80
+ }
81
+ escape(request) {
82
+ return this.#result("escape", [{ kind: "escape", summary: request.reason }], {
83
+ action: "escape",
84
+ reason: request.reason,
85
+ ...request.nextStep ? { args: { nextStep: request.nextStep } } : {}
86
+ }, { reason: request.reason, nextStep: request.nextStep ?? null });
87
+ }
88
+ async workflowDiagnostics(request, artifactPath) {
89
+ const doctor = await AkanContextAnalyzer.doctor(this.#workspace, {
90
+ strict: true,
91
+ runIdOrPlan: artifactPath
92
+ });
93
+ const toWorkflowDiagnostic = ({ severity, code, message, scope }, context) => ({ severity, code, message, scope, context });
94
+ const baselineSummary = createWorkflowBaselineSummary((doctor.baselineDiagnostics ?? []).map((diagnostic) => toWorkflowDiagnostic(diagnostic, diagnostic.context)), { detailsIncluded: false });
95
+ this.#diagnostics.push(...(doctor.workflowDiagnostics ?? doctor.diagnostics).map((diagnostic) => toWorkflowDiagnostic(diagnostic, {
96
+ ...diagnostic.context,
97
+ ...diagnostic.path ? { paths: [diagnostic.path] } : {}
98
+ })));
99
+ return this.#result("workflowDiagnostics", [
100
+ {
101
+ kind: "workflow",
102
+ target: request.runIdOrPlan,
103
+ summary: `Workflow diagnostics status is ${doctor.status}.`
104
+ }
105
+ ], {
106
+ action: doctor.status === "passed" ? "answer" : "validate",
107
+ reason: doctor.status === "passed" ? "No strict workspace diagnostics were found for the workflow context." : "Review diagnostics before applying or manually editing source files."
108
+ }, {
109
+ status: doctor.status,
110
+ baselineSummary,
111
+ baselineDiagnostics: 0,
112
+ workflowDiagnostics: doctor.workflowDiagnostics?.length ?? 0
113
+ });
114
+ }
115
+ async workspaceOverview() {
116
+ const context = await AkanContextAnalyzer.analyze(this.#workspace, {
117
+ app: null,
118
+ module: null,
119
+ includeAbstractContent: false
120
+ });
121
+ return this.#result("workspaceOverview", [
122
+ {
123
+ kind: "workspace",
124
+ summary: `${context.repoName} has ${context.apps.length} app(s), ${context.libs.length} lib(s), and ${context.pkgs.length} package(s).`
125
+ }
126
+ ], {
127
+ action: "inspect",
128
+ reason: "Choose moduleContext or fieldInsertionContext for module-scoped evidence before planning a workflow.",
129
+ tool: "inspect_akan_context"
130
+ }, {
131
+ repoName: context.repoName,
132
+ apps: context.apps.map((app) => ({ name: app.name, path: app.path, modules: app.modules.length })),
133
+ libs: context.libs.map((lib) => ({ name: lib.name, path: lib.path, modules: lib.modules.length })),
134
+ pkgs: context.pkgs.map((pkg) => ({ name: pkg.name, path: pkg.path, version: pkg.version ?? null })),
135
+ generatedFiles: context.generatedFiles,
136
+ validationCommands: context.validationCommands
137
+ });
138
+ }
139
+ async moduleContext(request) {
140
+ const modules = await this.#matchingModules(request);
141
+ const unresolved = this.#unresolvedModule(request, modules);
142
+ if (unresolved)
143
+ return unresolved;
144
+ const module = modules[0];
145
+ return this.#result("moduleContext", [moduleEvidence(module)], {
146
+ action: "inspect",
147
+ reason: "Use fieldInsertionContext when preparing add-field or escape when source body details are required.",
148
+ tool: "inspect_akan_context"
149
+ }, { module: moduleCandidate(module) });
150
+ }
151
+ async fieldInsertionContext(request) {
152
+ const modules = await this.#matchingModules(request);
153
+ const unresolved = this.#unresolvedModule(request, modules);
154
+ if (unresolved)
155
+ return unresolved;
156
+ const module = modules[0];
157
+ if (module.kind !== "domain") {
158
+ this.#diagnostics.push(inspectDiagnostic("error", "field-insertion-unsupported-module-kind", `fieldInsertionContext currently targets domain modules; ${module.sysName}:${module.name} is ${module.kind}.`));
159
+ }
160
+ const moduleIndex = await buildAkanModuleContextIndex(this.#workspace, module, { field: request.field });
161
+ this.#diagnostics.push(...moduleIndex.diagnostics);
162
+ return this.#result("fieldInsertionContext", [
163
+ moduleEvidence(module),
164
+ {
165
+ kind: "field-insertion",
166
+ target: `${module.sysName}:${module.name}.${request.field}`,
167
+ path: module.path,
168
+ summary: "M2 returns source-body-free AST index evidence for constant fields, dictionary model labels, and light projection fields."
169
+ }
170
+ ], module.kind === "domain" ? {
171
+ action: "plan_workflow",
172
+ reason: "The module target is unambiguous; create an add-field workflow plan before source edits.",
173
+ tool: "plan_workflow",
174
+ args: {
175
+ workflow: "add-field",
176
+ inputs: {
177
+ app: module.sysName,
178
+ module: module.name,
179
+ field: request.field,
180
+ type: request.fieldType
181
+ }
182
+ }
183
+ } : {
184
+ action: "escape",
185
+ reason: "This module kind is not a supported add-field target in the P1 context contract."
186
+ }, {
187
+ target: {
188
+ app: module.sysName,
189
+ module: module.name,
190
+ field: request.field,
191
+ fieldType: request.fieldType
192
+ },
193
+ files: moduleIndex.files,
194
+ moduleIndex
195
+ });
196
+ }
197
+ async#matchingModules(request) {
198
+ const context = await AkanContextAnalyzer.analyze(this.#workspace, {
199
+ app: request.app ?? null,
200
+ module: request.module ?? null,
201
+ includeAbstractContent: false
202
+ });
203
+ return AkanContextAnalyzer.findModules(context, request.module, {
204
+ app: request.app ?? null
205
+ });
206
+ }
207
+ #unresolvedModule(request, modules) {
208
+ if (modules.length === 0) {
209
+ this.#diagnostics.push(inspectDiagnostic("error", "inspect-module-not-found", `No module matched ${request.app ? `${request.app}:` : ""}${request.module}.`));
210
+ return this.#result(request.type, [], {
211
+ action: "escape",
212
+ reason: "The requested module was not found in the workspace index; inspect workspace files or clarify the target."
213
+ }, { candidates: [] });
214
+ }
215
+ if (!request.app && modules.length > 1) {
216
+ this.#diagnostics.push(inspectDiagnostic("error", "inspect-module-ambiguous", `Multiple modules match "${request.module}". Re-run with app to disambiguate.`));
217
+ return this.#result(request.type, modules.map(moduleEvidence), {
218
+ action: "clarify",
219
+ reason: "Multiple modules have the same name; choose an app before planning a workflow."
220
+ }, { candidates: modules.map(moduleCandidate) });
221
+ }
222
+ return null;
223
+ }
224
+ #result(type, evidence, next, data) {
225
+ return {
226
+ schemaVersion: 1,
227
+ type,
228
+ question: this.#question,
229
+ diagnostics: this.#diagnostics,
230
+ evidence,
231
+ next,
232
+ ...data ? { data } : {}
233
+ };
234
+ }
235
+ }
236
+
237
+ // pkgs/@akanjs/devkit/context/akanMcpToolError.ts
238
+ import { AkanError } from "akanjs/base";
239
+
240
+ class AkanMcpToolError extends AkanError {
241
+ constructor(code, message) {
242
+ super(code, message, { statusCode: 400 });
243
+ }
244
+ static failureOf(error) {
245
+ return AkanError.is(error) ? { code: error.code, statusCode: error.statusCode } : { code: "toolFailed", statusCode: 500 };
246
+ }
247
+ }
248
+
249
+ // pkgs/@akanjs/devkit/context/akanMcpContract.ts
52
250
  var emptySchema = { type: "object", properties: {} };
53
251
  var stringProperty = { type: "string" };
54
252
  var booleanProperty = { type: "boolean" };
@@ -174,7 +372,7 @@ var workflowArtifactPath = (workspace, filePath) => {
174
372
  const root = path.resolve(workspace.workspaceRoot, workflowArtifactDir);
175
373
  const resolved = workflowRunIdPattern.test(filePath) && !filePath.endsWith(".json") ? path.join(root, "runs", `${filePath}.json`) : path.resolve(workspace.workspaceRoot, filePath);
176
374
  if (!isInside(root, resolved) || !staysInside(workspace.workspaceRoot, root, resolved))
177
- throw new Error(`MCP workflow files live under ${workflowArtifactDir}/ of the workspace, not ${JSON.stringify(filePath)}.`);
375
+ throw new AkanMcpToolError("invalidArgument", `MCP workflow files live under ${workflowArtifactDir}/ of the workspace, not ${JSON.stringify(filePath)}.`);
178
376
  return resolved;
179
377
  };
180
378
  var defaultWorkflowPlanPath = (workflow, inputs) => {
@@ -208,7 +406,7 @@ var applyFirstPolicy = {
208
406
  var stringArg = (args, key) => {
209
407
  const value = args[key];
210
408
  if (typeof value !== "string" || !value)
211
- throw new Error(`MCP tool argument "${key}" is required.`);
409
+ throw new AkanMcpToolError("invalidArgument", `MCP tool argument "${key}" is required.`);
212
410
  return value;
213
411
  };
214
412
  var workflowInputsArg = (args) => {
@@ -221,14 +419,14 @@ var inspectAkanContextPropsArg = (args) => {
221
419
  const question = stringArg(args, "question");
222
420
  const review = stringArg(args, "review");
223
421
  if (!isRecord(args.draft))
224
- throw new Error('MCP tool argument "draft" is required.');
422
+ throw new AkanMcpToolError("invalidArgument", 'MCP tool argument "draft" is required.');
225
423
  if (!isRecord(args.request))
226
- throw new Error('MCP tool argument "request" is required.');
424
+ throw new AkanMcpToolError("invalidArgument", 'MCP tool argument "request" is required.');
227
425
  if (!isInspectAkanContextRequestType(args.draft.type)) {
228
- throw new Error('MCP tool argument "draft.type" must be a supported inspect_akan_context request type.');
426
+ throw new AkanMcpToolError("invalidArgument", 'MCP tool argument "draft.type" must be a supported inspect_akan_context request type.');
229
427
  }
230
428
  if (!isInspectAkanContextRequestType(args.request.type)) {
231
- throw new Error('MCP tool argument "request.type" must be a supported inspect_akan_context request type.');
429
+ throw new AkanMcpToolError("invalidArgument", 'MCP tool argument "request.type" must be a supported inspect_akan_context request type.');
232
430
  }
233
431
  const base = { question, draft: { reason: stringArg(args.draft, "reason"), type: args.draft.type }, review };
234
432
  const request = args.request;
@@ -257,21 +455,6 @@ var inspectAkanContextPropsArg = (args) => {
257
455
  request: { type: "escape", reason: stringArg(request, "reason"), nextStep: optionalString(request, "nextStep") }
258
456
  };
259
457
  };
260
- var inspectDiagnostic = (severity, code, message) => ({ severity, code, message });
261
- var moduleEvidence = (module) => ({
262
- kind: "module",
263
- target: `${module.sysName}:${module.name}`,
264
- path: module.path,
265
- summary: `${module.kind} module at ${module.path} with ${module.files.length} source file(s).`
266
- });
267
- var moduleCandidate = (module) => ({
268
- app: module.sysName,
269
- sysType: module.sysType,
270
- module: module.name,
271
- kind: module.kind,
272
- path: module.path,
273
- files: module.files
274
- });
275
458
  var readonlyMcpTools = [
276
459
  {
277
460
  name: "inspect_akan_context",
@@ -300,7 +483,7 @@ var readonlyMcpTools = [
300
483
  },
301
484
  {
302
485
  name: "get_graph",
303
- description: "Read-only Akan Graph from source, no dev server needed: models with their fields and relations, slices and endpoints with the guards they name (each guard keyed by the app or lib that declares it, with its scope and the comment that says what it checks), the service methods and queries each calls, the store actions that fetch them, and the components and routes that use them. A module's jobs (internal: interval, cron, timeout, initialize, destroy, process) read their schedule and server or operation modes and call service methods like endpoints do; each adaptor a service plugs (an adapt() class, or an akanjs role) is a node, a method that calls it links to it, and an adaptor links to the adaptors it plugs itself. Each page/ file is a route (its URL pattern after the locale) or a layout, layouts wrap what they contain, and a route or layout that runs .guard() reads `guard` and links each function its guard calls; a layout's guard gates every route it wraps. A graph too large to answer unscoped drops first the routes and layouts that neither changed nor use a change; app or module brings them back. Every node and edge carries its source location. Pass app and/or module to scope a large workspace. Pass since (a git revision such as main, or HEAD for uncommitted work) for the Change Map instead: what changed since HEAD forked from it, working tree included, with each node, field and edge marked added, removed or changed, the unchanged neighbours they call or are called by, and the changed files no node covers, each marked the same way.",
486
+ description: "Read-only Akan Graph from source, no dev server needed: models with their fields and relations, slices and endpoints with the guards they name (each guard keyed by the app or lib that declares it, with its scope and the comment that says what it checks), the service methods and queries each calls, the store actions that fetch them, and the components and routes that use them. A module's jobs (internal: interval, cron, timeout, initialize, destroy, process) read their schedule and server or operation modes and call service methods like endpoints do; each adaptor a service plugs (an adapt() class, or an akanjs role) is a node, a method that calls it links to it (an app service holds the fields its module's lib services plug, unless it declares the field itself), an adaptor links to the adaptors it plugs itself, a class from a package outside the workspace is adaptor:<package>:<Name>, and a role an app binds with applyAdaptor(Role, Impl) links to that implementation (binds, labelled with the app; a scope keeps its app's bindings). Each page/ file is a route (its URL pattern after the locale) or a layout, layouts wrap what they contain, and a route or layout that runs .guard() reads `guard` and links each function its guard calls; a layout's guard gates every route it wraps. A graph too large to answer unscoped drops first the routes and layouts that neither changed nor use a change; app or module brings them back. Every node and edge carries its source location. Pass app and/or module to scope a large workspace. Pass since (a git revision such as main, or HEAD for uncommitted work) for the Change Map instead: what changed since HEAD forked from it, working tree included, with each node, field and edge marked added, removed or changed, the unchanged neighbours they call or are called by, and the changed files no node covers, each marked the same way.",
304
487
  inputSchema: { type: "object", properties: { app: stringProperty, module: stringProperty, since: stringProperty } }
305
488
  },
306
489
  {
@@ -356,7 +539,7 @@ var planMcpTools = [
356
539
  var applyMcpTools = [
357
540
  {
358
541
  name: "apply_workflow",
359
- description: "Apply a stored workflow plan before direct edits and return validationTarget, plus next.tool=run_validation unless the apply failed.",
542
+ description: "Apply a stored workflow plan before direct edits and return validationTarget. Unless it failed, next.tool is run_validation after an apply and apply_workflow without dryRun after a dry run.",
360
543
  inputSchema: {
361
544
  type: "object",
362
545
  properties: { planPath: stringProperty, dryRun: booleanProperty },
@@ -458,149 +641,38 @@ var createAkanValidationContract = (listTools = listAkanMcpTools) => ({
458
641
  });
459
642
  var inspectAkanContext = async (workspace, args) => {
460
643
  const props = inspectAkanContextPropsArg(args);
461
- const diagnostics = [];
462
- if (props.draft.type !== props.request.type) {
463
- diagnostics.push(inspectDiagnostic("warning", "inspect-draft-request-mismatch", `Draft chose ${props.draft.type}, but request uses ${props.request.type}.`));
464
- }
465
- const baseResult = (type, evidence, next, data) => ({
466
- schemaVersion: 1,
467
- type,
468
- question: props.question,
469
- diagnostics,
470
- evidence,
471
- next,
472
- ...data ? { data } : {}
473
- });
474
- if (props.request.type === "escape") {
475
- return baseResult("escape", [{ kind: "escape", summary: props.request.reason }], {
476
- action: "escape",
477
- reason: props.request.reason,
478
- ...props.request.nextStep ? { args: { nextStep: props.request.nextStep } } : {}
479
- }, { reason: props.request.reason, nextStep: props.request.nextStep ?? null });
480
- }
481
- if (props.request.type === "workflowDiagnostics") {
482
- const doctor = await AkanContextAnalyzer.doctor(workspace, {
483
- strict: true,
484
- runIdOrPlan: workflowArtifactPath(workspace, props.request.runIdOrPlan)
485
- });
486
- const toWorkflowDiagnostic = ({ severity, code, message, scope }, context) => ({ severity, code, message, scope, context });
487
- const baselineSummary = createWorkflowBaselineSummary((doctor.baselineDiagnostics ?? []).map((diagnostic) => toWorkflowDiagnostic(diagnostic, diagnostic.context)), { detailsIncluded: false });
488
- diagnostics.push(...(doctor.workflowDiagnostics ?? doctor.diagnostics).map((diagnostic) => toWorkflowDiagnostic(diagnostic, {
489
- ...diagnostic.context,
490
- ...diagnostic.path ? { paths: [diagnostic.path] } : {}
491
- })));
492
- return baseResult("workflowDiagnostics", [
493
- {
494
- kind: "workflow",
495
- target: props.request.runIdOrPlan,
496
- summary: `Workflow diagnostics status is ${doctor.status}.`
497
- }
498
- ], {
499
- action: doctor.status === "passed" ? "answer" : "validate",
500
- reason: doctor.status === "passed" ? "No strict workspace diagnostics were found for the workflow context." : "Review diagnostics before applying or manually editing source files."
501
- }, {
502
- status: doctor.status,
503
- baselineSummary,
504
- baselineDiagnostics: 0,
505
- workflowDiagnostics: doctor.workflowDiagnostics?.length ?? 0
506
- });
507
- }
508
- const moduleRequest = props.request.type === "moduleContext" || props.request.type === "fieldInsertionContext" ? props.request : null;
509
- const context = await AkanContextAnalyzer.analyze(workspace, {
510
- app: moduleRequest?.app ?? null,
511
- module: moduleRequest?.module ?? null,
512
- includeAbstractContent: false
513
- });
514
- if (props.request.type === "workspaceOverview") {
515
- return baseResult("workspaceOverview", [
516
- {
517
- kind: "workspace",
518
- summary: `${context.repoName} has ${context.apps.length} app(s), ${context.libs.length} lib(s), and ${context.pkgs.length} package(s).`
519
- }
520
- ], {
521
- action: "inspect",
522
- reason: "Choose moduleContext or fieldInsertionContext for module-scoped evidence before planning a workflow.",
523
- tool: "inspect_akan_context"
524
- }, {
525
- repoName: context.repoName,
526
- apps: context.apps.map((app) => ({ name: app.name, path: app.path, modules: app.modules.length })),
527
- libs: context.libs.map((lib) => ({ name: lib.name, path: lib.path, modules: lib.modules.length })),
528
- pkgs: context.pkgs.map((pkg) => ({ name: pkg.name, path: pkg.path, version: pkg.version ?? null })),
529
- generatedFiles: context.generatedFiles,
530
- validationCommands: context.validationCommands
531
- });
532
- }
533
- const modules = AkanContextAnalyzer.findModules(context, props.request.module, {
534
- app: props.request.app ?? null
535
- });
536
- if (modules.length === 0) {
537
- diagnostics.push(inspectDiagnostic("error", "inspect-module-not-found", `No module matched ${props.request.app ? `${props.request.app}:` : ""}${props.request.module}.`));
538
- return baseResult(props.request.type, [], {
539
- action: "escape",
540
- reason: "The requested module was not found in the workspace index; inspect workspace files or clarify the target."
541
- }, { candidates: [] });
542
- }
543
- if (!props.request.app && modules.length > 1) {
544
- diagnostics.push(inspectDiagnostic("error", "inspect-module-ambiguous", `Multiple modules match "${props.request.module}". Re-run with app to disambiguate.`));
545
- return baseResult(props.request.type, modules.map(moduleEvidence), {
546
- action: "clarify",
547
- reason: "Multiple modules have the same name; choose an app before planning a workflow."
548
- }, { candidates: modules.map(moduleCandidate) });
549
- }
550
- const module = modules[0];
551
- if (props.request.type === "moduleContext") {
552
- return baseResult("moduleContext", [moduleEvidence(module)], {
553
- action: "inspect",
554
- reason: "Use fieldInsertionContext when preparing add-field or escape when source body details are required.",
555
- tool: "inspect_akan_context"
556
- }, { module: moduleCandidate(module) });
557
- }
558
- if (module.kind !== "domain") {
559
- diagnostics.push(inspectDiagnostic("error", "field-insertion-unsupported-module-kind", `fieldInsertionContext currently targets domain modules; ${module.sysName}:${module.name} is ${module.kind}.`));
560
- }
561
- const moduleIndex = await buildAkanModuleContextIndex(workspace, module, { field: props.request.field });
562
- diagnostics.push(...moduleIndex.diagnostics);
563
- return baseResult("fieldInsertionContext", [
564
- moduleEvidence(module),
565
- {
566
- kind: "field-insertion",
567
- target: `${module.sysName}:${module.name}.${props.request.field}`,
568
- path: module.path,
569
- summary: "M2 returns source-body-free AST index evidence for constant fields, dictionary model labels, and light projection fields."
570
- }
571
- ], module.kind === "domain" ? {
572
- action: "plan_workflow",
573
- reason: "The module target is unambiguous; create an add-field workflow plan before source edits.",
574
- tool: "plan_workflow",
575
- args: {
576
- workflow: "add-field",
577
- inputs: {
578
- app: module.sysName,
579
- module: module.name,
580
- field: props.request.field,
581
- type: props.request.fieldType
582
- }
583
- }
584
- } : {
585
- action: "escape",
586
- reason: "This module kind is not a supported add-field target in the P1 context contract."
587
- }, {
588
- target: {
589
- app: module.sysName,
590
- module: module.name,
591
- field: props.request.field,
592
- fieldType: props.request.fieldType
593
- },
594
- files: moduleIndex.files,
595
- moduleIndex
596
- });
644
+ const inspection = new AkanContextInspection(workspace, props);
645
+ const { request } = props;
646
+ if (request.type === "escape")
647
+ return inspection.escape(request);
648
+ if (request.type === "workflowDiagnostics")
649
+ return await inspection.workflowDiagnostics(request, workflowArtifactPath(workspace, request.runIdOrPlan));
650
+ if (request.type === "workspaceOverview")
651
+ return await inspection.workspaceOverview();
652
+ if (request.type === "moduleContext")
653
+ return await inspection.moduleContext(request);
654
+ return await inspection.fieldInsertionContext(request);
597
655
  };
598
656
 
599
657
  // pkgs/@akanjs/cli/context/context.runner.ts
658
+ import { MCP_FAILURE_META } from "akanjs/common";
600
659
  var toolErrorText = (error) => {
601
660
  const message = error instanceof Error ? error.message : String(error);
602
661
  return message.replace(/\/(?:[^\s"'/]+\/)*(?=(?:pkgs|apps|libs|infra)\/)/g, "<workspace>/");
603
662
  };
663
+ var assertMcpToolListed = (name, mode) => {
664
+ const isListed = (tools) => tools.some((tool) => tool.name === name);
665
+ if (!isListed(listAkanMcpTools("apply")))
666
+ throw new AkanMcpToolError("unknownTool", `Unknown tool: ${name}`);
667
+ if (!isListed(listAkanMcpTools(mode)))
668
+ throw new AkanMcpToolError("toolUnavailable", `MCP tool "${name}" is not available in ${mode} mode.`);
669
+ };
670
+ var guidelineOf = async (name) => {
671
+ const guidelines = await Prompter2.listGuidelines();
672
+ if (!guidelines.includes(name))
673
+ throw new AkanMcpToolError("invalidArgument", `Unknown guideline "${name}". Available: ${guidelines.join(", ")}`);
674
+ return await Prompter2.getInstruction(name);
675
+ };
604
676
  var compactDoctorWorkspaceResult = (result, includeBaselineDetails) => {
605
677
  const baselineDiagnostics = result.baselineDiagnostics ?? [];
606
678
  const baselineSummary = createWorkflowBaselineSummary(baselineDiagnostics.map(({ severity, code, message, scope, context }) => ({
@@ -644,7 +716,7 @@ class ContextRunner2 extends runner("context") {
644
716
  const diagnostics = [];
645
717
  let toolchainChecked = false;
646
718
  for (const appName of appNames) {
647
- const app = AppExecutor.from(workspace, appName);
719
+ const app = AppExecutor2.from(workspace, appName);
648
720
  const config = await app.getConfig();
649
721
  if (!config.hasNativeConfig)
650
722
  continue;
@@ -716,10 +788,7 @@ class ContextRunner2 extends runner("context") {
716
788
  return listAkanMcpTools(mode, { guidelineNames });
717
789
  }
718
790
  async callMcpTool(workspace, name, args = {}, { mode = "readonly" } = {}) {
719
- const availableTools = this.listMcpTools(mode);
720
- if (!availableTools.some((tool) => tool.name === name)) {
721
- throw new Error(`MCP tool "${name}" is not available in ${mode} mode.`);
722
- }
791
+ assertMcpToolListed(name, mode);
723
792
  if (name === "inspect_akan_context")
724
793
  return await inspectAkanContext(workspace, args);
725
794
  if (name === "get_workspace_summary" || name === "list_apps" || name === "list_modules" || name === "get_module_context") {
@@ -765,7 +834,7 @@ class ContextRunner2 extends runner("context") {
765
834
  return typeof args.since === "string" ? WorkspaceGraph.answerChanges(await WorkspaceGraph.changes(workspace, args.since), scope) : WorkspaceGraph.answer(await WorkspaceGraph.build(workspace), scope);
766
835
  }
767
836
  if (name === "get_guideline")
768
- return await Prompter2.getInstruction(stringArg(args, "name"));
837
+ return await guidelineOf(stringArg(args, "name"));
769
838
  if (name === "doctor_workspace")
770
839
  return compactDoctorWorkspaceResult(await AkanContextAnalyzer.doctor(workspace, {
771
840
  strict: !!args.strict,
@@ -795,21 +864,8 @@ class ContextRunner2 extends runner("context") {
795
864
  policy: applyFirstPolicy
796
865
  };
797
866
  }
798
- if (name === "apply_workflow") {
799
- const report = parseJsonOutput(await new WorkflowRunner().apply(workflowArtifactPath(workspace, stringArg(args, "planPath")), {
800
- format: "json",
801
- dryRun: !!args.dryRun,
802
- workspace,
803
- registry: WorkflowRunner.stepRegistry(workspace)
804
- }));
805
- const validationTarget = typeof report.validationTarget === "string" ? report.validationTarget : typeof report.applyReportPath === "string" ? report.applyReportPath : stringArg(args, "planPath");
806
- return {
807
- ...report,
808
- validationTarget,
809
- ...report.status === "failed" ? {} : { next: { tool: "run_validation", args: { runIdOrPlan: validationTarget } } },
810
- policy: applyFirstPolicy
811
- };
812
- }
867
+ if (name === "apply_workflow")
868
+ return await this.#applyWorkflow(workspace, args);
813
869
  if (name === "run_validation")
814
870
  return parseJsonOutput(await new WorkflowRunner().validate(workflowArtifactPath(workspace, stringArg(args, "runIdOrPlan")), {
815
871
  format: "json",
@@ -833,7 +889,36 @@ class ContextRunner2 extends runner("context") {
833
889
  module: stringArg(args, "module"),
834
890
  format: "json"
835
891
  }));
836
- throw new Error(`Unknown tool: ${name}`);
892
+ throw new AkanMcpToolError("unknownTool", `Unknown tool: ${name}`);
893
+ }
894
+ async answerMcpTool(workspace, name, args, { mode = "readonly" } = {}) {
895
+ try {
896
+ const result = await this.callMcpTool(workspace, name, args, { mode });
897
+ const text = typeof result === "string" ? result : jsonText(result, { trailingNewline: false });
898
+ return { content: [{ type: "text", text }] };
899
+ } catch (error) {
900
+ return {
901
+ content: [{ type: "text", text: toolErrorText(error) }],
902
+ isError: true,
903
+ _meta: { [MCP_FAILURE_META]: AkanMcpToolError.failureOf(error) }
904
+ };
905
+ }
906
+ }
907
+ async#applyWorkflow(workspace, args) {
908
+ const planPath = stringArg(args, "planPath");
909
+ const report = parseJsonOutput(await new WorkflowRunner().apply(workflowArtifactPath(workspace, planPath), {
910
+ format: "json",
911
+ dryRun: !!args.dryRun,
912
+ workspace,
913
+ registry: WorkflowRunner.stepRegistry(workspace)
914
+ }));
915
+ const validationTarget = typeof report.validationTarget === "string" ? report.validationTarget : typeof report.applyReportPath === "string" ? report.applyReportPath : planPath;
916
+ return {
917
+ ...report,
918
+ validationTarget,
919
+ ...report.status === "failed" ? {} : args.dryRun ? { next: { tool: "apply_workflow", args: { planPath } } } : { next: { tool: "run_validation", args: { runIdOrPlan: validationTarget } } },
920
+ policy: applyFirstPolicy
921
+ };
837
922
  }
838
923
  async runMcp(workspace, { mode = "readonly" } = {}) {
839
924
  const decoder = new TextDecoder;
@@ -897,13 +982,7 @@ ${payload}`);
897
982
  } else if (request.method === "tools/call") {
898
983
  const name = params.name;
899
984
  const args = params.arguments ?? {};
900
- try {
901
- const result = await this.callMcpTool(workspace, name, args, { mode });
902
- const text = typeof result === "string" ? result : jsonText(result, { trailingNewline: false });
903
- respond(request.id, { content: [{ type: "text", text }] }, framing);
904
- } catch (error) {
905
- respond(request.id, { content: [{ type: "text", text: toolErrorText(error) }], isError: true }, framing);
906
- }
985
+ respond(request.id, await this.answerMcpTool(workspace, name, args, { mode }), framing);
907
986
  } else if (request.method === "resources/list") {
908
987
  respond(request.id, { resources }, framing);
909
988
  } else if (request.method === "resources/read") {
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- // pkgs/@akanjs/devkit/subspaceConfig.ts
2
+ // pkgs/@akanjs/devkit/subspace/subspaceConfig.ts
3
3
  class SubspaceConfig {
4
4
  static source = "subspace in the workspace root akan.config.ts";
5
5
  static defaultPushableBranches = ["main", "develop", "debug"];
@@ -24,6 +24,8 @@ class SubspaceConfig {
24
24
  for (const subspace of this.subspaces) {
25
25
  if (!subspace.name || !subspace.repo)
26
26
  throw new Error(`${SubspaceConfig.source}: every subspace needs a name and a repo`);
27
+ if (subspace.repo.startsWith("-"))
28
+ throw new Error(`${SubspaceConfig.source}: subspace "${subspace.name}" repo "${subspace.repo}" reads as a git option`);
27
29
  if (!SubspaceConfig.namePattern.test(subspace.name))
28
30
  throw new Error(`${SubspaceConfig.source}: subspace name "${subspace.name}" takes letters, digits, ".", "_" and "-", starting with a letter or digit`);
29
31
  if (seenNames.has(subspace.name))