@akanjs/cli 3.2.0-rc.3 → 3.2.0-rc.30

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 (144) hide show
  1. package/.build-stamp +2 -1
  2. package/CodeAgent-c17abdbf.js +11 -0
  3. package/{CodeTui-wv9yf7eq.js → CodeTui-jed1nj82.js} +822 -666
  4. package/README.ko.md +26 -1
  5. package/README.md +26 -1
  6. package/TunnelShare-mbfcaqg0.js +18 -0
  7. package/agent.command-9whnc6vb.js +56 -0
  8. package/akanCode.js +12 -12
  9. package/appExecutor-020cyesq.js +11 -0
  10. package/{application.command-6515t682.js → application.command-4eqvyxkw.js} +77 -36
  11. package/{applicationBuildRunner-bqbyeg84.js → applicationBuildRunner-frtcrqfd.js} +18 -13
  12. package/buildBatch.proc.js +26 -11
  13. package/{cloud.command-32esk0v1.js → cloud.command-hbvmeezn.js} +31 -28
  14. package/cloud.script-9kmbr3d6.js +35 -0
  15. package/{code.command-xk7rwq2x.js → code.command-0ayrenk4.js} +14 -9
  16. package/{context.command-jwenkkf0.js → context.command-php852kf.js} +28 -23
  17. package/context.runner-nngmn7c0.js +34 -0
  18. package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
  19. package/{devTui-cd03z4mx.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 +29 -12
  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/conventions/rules/ts.md +3 -3
  28. package/guidelines/errorCodes/errorCodes.instruction.md +158 -0
  29. package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
  30. package/guidelines/mcpRule/mcpRule.instruction.md +96 -2
  31. package/guidelines/pageRule/pageRule.instruction.md +15 -1
  32. package/guidelines/runtimeRule/runtimeRule.instruction.md +12 -6
  33. package/guidelines/transportRule/transportRule.instruction.md +8 -1
  34. package/incrementalBuilder.proc.js +574 -410
  35. package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
  36. package/{index-xrmrvafh.js → index-0gaj78wn.js} +808 -694
  37. package/{index-j1hjb477.js → index-11d7nh8a.js} +1 -1
  38. package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
  39. package/{index-ygrdw6jw.js → index-1pjwsh2g.js} +65 -8
  40. package/{index-43acpsc7.js → index-28nk8w3j.js} +12 -12
  41. package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
  42. package/{index-8gm4yag8.js → index-42jhx2ya.js} +6 -6
  43. package/{index-2rqyrvcy.js → index-4st0hq72.js} +62 -33
  44. package/{index-bak9f2br.js → index-5d57kx0s.js} +15 -11
  45. package/{index-bdmgqzb5.js → index-6469101k.js} +58 -29
  46. package/{index-7kmbqp0b.js → index-6pxmcaq8.js} +1 -1
  47. package/{index-54s6knqe.js → index-6zb17wcm.js} +12 -10
  48. package/{index-0ba8nj4d.js → index-7bs463x7.js} +50 -38
  49. package/{index-y725zb1a.js → index-7v7tvgt7.js} +196 -168
  50. package/{index-r0a604h4.js → index-99kjwyma.js} +1 -1
  51. package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
  52. package/{index-386canwe.js → index-9rv2zt48.js} +186 -121
  53. package/{index-20wvskt8.js → index-9wab2ngg.js} +1 -1
  54. package/{index-2eym1yjb.js → index-9wjrwjgz.js} +288 -209
  55. package/{index-kcpk2d20.js → index-at6haq2x.js} +1474 -1139
  56. package/{index-6h775rv3.js → index-ba2xd32s.js} +53 -12
  57. package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
  58. package/{index-ngpt3zz3.js → index-bj8s07s7.js} +525 -440
  59. package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
  60. package/{index-vbhx60x5.js → index-cb91b6d8.js} +2140 -2165
  61. package/index-dss3ds74.js +127 -0
  62. package/{index-e22zedc2.js → index-f16kr6vj.js} +3 -3
  63. package/{index-ny2k80mv.js → index-ffa52fwf.js} +1 -1
  64. package/{index-djc5nxpy.js → index-fp5xf6ef.js} +6 -6
  65. package/{index-qrk06tfp.js → index-g45y5f3e.js} +2 -2
  66. package/{index-8jpc5fqv.js → index-g7jgd4xs.js} +2 -2
  67. package/index-j4yvgfhr.js +70 -0
  68. package/{index-ytpmk3pb.js → index-jgj31xvw.js} +18 -11
  69. package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
  70. package/{index-s34v3y28.js → index-m3t28rt3.js} +11 -11
  71. package/{index-dpgywgeq.js → index-m5gg0wzv.js} +27 -16
  72. package/index-na8r4a27.js +30 -0
  73. package/{index-h0p6n4k1.js → index-nm7nt9vm.js} +3 -3
  74. package/{index-j4hkbzj6.js → index-p06kfhdf.js} +6 -6
  75. package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
  76. package/{index-cmg5ngqa.js → index-p7beqww9.js} +2 -2
  77. package/{index-zhkcab5a.js → index-prgvqqxe.js} +580 -364
  78. package/{index-wfmpxke3.js → index-qssq2d41.js} +2775 -3677
  79. package/{index-sc0g6zbm.js → index-rwgqba9p.js} +24 -11
  80. package/{index-zcdmnfrf.js → index-s3m89wt2.js} +9 -9
  81. package/{index-v50xjbbe.js → index-t4d0ckde.js} +1 -1
  82. package/{index-9p260r4e.js → index-trffs83s.js} +538 -250
  83. package/{index-ddk49ypz.js → index-v929w7j7.js} +133 -49
  84. package/index-va90m8nd.js +25 -0
  85. package/index-vjbne22r.js +80 -0
  86. package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
  87. package/{index-39jz41jb.js → index-xs9a3ddt.js} +3 -3
  88. package/{index-84c2pgak.js → index-yvzm8mby.js} +94 -82
  89. package/{index-wr9magsr.js → index-yxkjsyx8.js} +3 -3
  90. package/index-ze48c0vd.js +788 -0
  91. package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
  92. package/index.js +29 -24
  93. package/libExecutor-tq994592.js +10 -0
  94. package/{library.command-qs8beggh.js → library.command-x219mhcx.js} +9 -4
  95. package/{localRegistry.command-hz4ged9n.js → localRegistry.command-zvdcejhn.js} +30 -24
  96. package/{module.command-z9js77m2.js → module.command-k6cwcm7g.js} +17 -8
  97. package/{package.command-zqenq8c0.js → package.command-vw7x09f8.js} +13 -8
  98. package/package.json +2 -2
  99. package/{page.command-t0nx1jat.js → page.command-gf06paq2.js} +9 -4
  100. package/{pipeline.command-2yjeas7m.js → pipeline.command-y07dgj9b.js} +14 -8
  101. package/pkgExecutor-stde3yc3.js +10 -0
  102. package/{primitive.command-v5kypwy4.js → primitive.command-edydvh07.js} +13 -8
  103. package/{projectTypecheck-s9hhe5sa.js → projectTypecheck-mk8wefvd.js} +2 -1
  104. package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
  105. package/{quality.command-q55j2htd.js → quality.command-mdb45vyr.js} +23 -16
  106. package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
  107. package/{repair.command-7ssbbdq2.js → repair.command-kvtaeecy.js} +13 -8
  108. package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
  109. package/{scalar.command-p5jb7z57.js → scalar.command-sjt9p5e1.js} +11 -6
  110. package/skills/akan-debug/SKILL.md +10 -3
  111. package/skills/akan-err/SKILL.md +7 -0
  112. package/skills/akan-mcp/SKILL.md +14 -2
  113. package/skills/akan-scaffold/SKILL.md +2 -2
  114. package/skills/akan-transport/SKILL.md +2 -0
  115. package/skills/akan-validate/SKILL.md +1 -0
  116. package/{subspace.command-7wxy6ptj.js → subspace.command-mkkqync4.js} +29 -23
  117. package/templates/app/page/_layout.tsx +13 -0
  118. package/templates/app/page/styles.css.template +40 -0
  119. package/templates/appSample/page/_index.tsx +9 -9
  120. package/templates/appSample/page/_layout.tsx +1 -0
  121. package/templates/appSample/page/styles.css.template +40 -5
  122. package/templates/appSample/ui/Recipe/jellyButton.ts +1 -1
  123. package/templates/biomeForm.ts +1 -1
  124. package/templates/env/_env.server.type.ts +1 -1
  125. package/templates/facetIndex/index.ts +2 -37
  126. package/templates/lib/sig.ts +0 -4
  127. package/templates/lib/useClient.ts +1 -1
  128. package/templates/workspaceRoot/AGENTS.md.template +2 -1
  129. package/{tunnel.command-22g11n0x.js → tunnel.command-tr5b3030.js} +17 -12
  130. package/{typeChecker-s640r6c0.js → typeChecker-bfrd1n9n.js} +1 -1
  131. package/typecheck.proc.js +6 -3
  132. package/{verify.command-m0wnndd7.js → verify.command-0p9h8tpp.js} +26 -20
  133. package/{workflow.command-jx8dqs9n.js → workflow.command-9mfcwqzj.js} +37 -19
  134. package/{workspace.command-ca9kfyt3.js → workspace.command-5hjtmcfs.js} +61 -54
  135. package/CodeAgent-e9c712an.js +0 -11
  136. package/TunnelShare-zkfkrw8w.js +0 -14
  137. package/agent.command-9erafkcb.js +0 -51
  138. package/cloud.script-arsagnq6.js +0 -30
  139. package/context.runner-mqpp67br.js +0 -29
  140. package/index-x3x31df8.js +0 -14
  141. /package/templates/{appSample → app}/public/fonts/Pretendard-Bold.woff2 +0 -0
  142. /package/templates/{appSample → app}/public/fonts/Pretendard-Medium.woff2 +0 -0
  143. /package/templates/{appSample → app}/public/fonts/Pretendard-Regular.woff2 +0 -0
  144. /package/templates/{appSample → app}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
@@ -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-0gaj78wn.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-ngpt3zz3.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-xrmrvafh.js";
24
+ } from "./index-bj8s07s7.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-fp5xf6ef.js";
28
31
  import {
29
32
  isPlaceholderAppId
30
- } from "./index-20wvskt8.js";
33
+ } from "./index-9wab2ngg.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-39jz41jb.js";
40
+ } from "./index-xs9a3ddt.js";
41
41
  import {
42
42
  RepairRunner
43
- } from "./index-8gm4yag8.js";
43
+ } from "./index-42jhx2ya.js";
44
44
  import {
45
45
  WorkflowRunner
46
- } from "./index-43acpsc7.js";
46
+ } from "./index-28nk8w3j.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",
@@ -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") {