@akanjs/devkit 3.3.0-rc.7 → 3.3.0-rc.70

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 (358) hide show
  1. package/DEV_RUNTIME_KNOBS.md +1 -1
  2. package/README.ko.md +10 -3
  3. package/README.md +10 -4
  4. package/akanApp/akanApp.host.test.ts +4 -2
  5. package/akanApp/akanApp.host.ts +26 -2
  6. package/akanApp/akanApp.host.wiring.test.ts +111 -0
  7. package/akanApp/devHostPolicy.ts +5 -0
  8. package/akanApp/devMetadataRestart.ts +93 -0
  9. package/akanApp/devRecycler.test.ts +2 -0
  10. package/akanApp/devRecycler.ts +9 -0
  11. package/akanConfig/akanBin.ts +4 -0
  12. package/akanConfig/akanConfig.test.ts +320 -21
  13. package/akanConfig/akanConfig.ts +113 -272
  14. package/akanConfig/akanPreview.test.ts +28 -0
  15. package/akanConfig/akanPreview.ts +24 -0
  16. package/akanConfig/akanWorkers.test.ts +73 -0
  17. package/akanConfig/akanWorkers.ts +61 -0
  18. package/akanConfig/desktopServerConfig.ts +96 -0
  19. package/akanConfig/dockerImage.ts +229 -0
  20. package/akanConfig/index.ts +3 -0
  21. package/akanConfig/nativeFileSettings.ts +33 -0
  22. package/akanConfig/nativeKeys.ts +52 -0
  23. package/akanConfig/types.ts +4 -0
  24. package/app/appBin.test.ts +63 -0
  25. package/app/appBin.ts +50 -0
  26. package/app/applicationBuildReporter.test.ts +51 -1
  27. package/app/applicationBuildReporter.ts +6 -1
  28. package/app/applicationBuildRunner.test.ts +358 -5
  29. package/app/applicationBuildRunner.ts +221 -31
  30. package/app/clientServerBoundary.test.ts +115 -0
  31. package/app/clientServerBoundary.ts +89 -0
  32. package/app/dictionarySizes.test.ts +40 -0
  33. package/app/dictionarySizes.ts +95 -0
  34. package/app/routeFilesReport.test.ts +59 -0
  35. package/app/routeFilesReport.ts +46 -0
  36. package/app/routeJsBudget.ts +18 -4
  37. package/artifact/implicitRootLayout.test.ts +19 -0
  38. package/artifact/implicitRootLayout.ts +16 -2
  39. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  40. package/artifact/storeBootstrap.test.ts +28 -0
  41. package/artifact/storeBootstrap.ts +64 -8
  42. package/biome.base.json +7 -5
  43. package/codeAgent/index.ts +1 -34
  44. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  45. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  46. package/codeAgent/skills/akan-debug/SKILL.md +8 -3
  47. package/codeAgent/skills/akan-deps/SKILL.md +10 -3
  48. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  49. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  50. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  51. package/codeAgent/skills/akan-page/SKILL.md +65 -30
  52. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  53. package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
  54. package/codeAgent/skills/akan-service/SKILL.md +21 -20
  55. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  56. package/codeAgent/skills/akan-ui/SKILL.md +16 -21
  57. package/codeAgent/skills/akan-validate/SKILL.md +8 -2
  58. package/commandDecorators/command.ts +28 -12
  59. package/commandDecorators/commandBuilder.ts +8 -1
  60. package/commandDecorators/commandDecorators.test.ts +70 -3
  61. package/commandDecorators/helpFormatter.ts +14 -12
  62. package/context/akanContext.ts +2 -0
  63. package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
  64. package/csrE2e/ssrRegistry.e2e.test.ts +108 -22
  65. package/docs/apiReference.test.ts +25 -0
  66. package/docs/apiReference.ts +38 -5
  67. package/docs/declarationReader.ts +30 -0
  68. package/executors/appExecutor.ts +26 -12
  69. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  70. package/executors/clientRuntimeKeys.fixture.json +393 -0
  71. package/executors/clientRuntimeKeys.test.ts +1690 -0
  72. package/executors/executor.ts +14 -6
  73. package/executors/executors.test.ts +155 -1
  74. package/executors/pkgExecutor.ts +2 -1
  75. package/executors/sysExecutor.ts +112 -8
  76. package/executors/workspaceExecutor.ts +7 -4
  77. package/frontendBuild/allRoutesBuilder.ts +99 -7
  78. package/frontendBuild/autoImportSync.ts +3 -2
  79. package/frontendBuild/buildRouteClient.test.ts +686 -13
  80. package/frontendBuild/clientBuildTypes.ts +26 -0
  81. package/frontendBuild/clientEntriesBundler.ts +49 -1
  82. package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
  83. package/frontendBuild/clientEntryDiscovery.ts +136 -14
  84. package/frontendBuild/clientEntryGroups.test.ts +77 -0
  85. package/frontendBuild/clientEntryGroups.ts +61 -0
  86. package/frontendBuild/csrDevArtifactWriter.ts +2 -2
  87. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  88. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  89. package/frontendBuild/csrDevPatcher.test.ts +4 -5
  90. package/frontendBuild/csrDevPatcher.ts +37 -11
  91. package/frontendBuild/csrDevTypes.ts +9 -0
  92. package/frontendBuild/devBarrelImports.test.ts +154 -0
  93. package/frontendBuild/devBarrelImports.ts +83 -23
  94. package/frontendBuild/devChangePlanner.ts +0 -1
  95. package/frontendBuild/devRegistryBundler.ts +4 -2
  96. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  97. package/frontendBuild/devRouteRuntime.ts +167 -0
  98. package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
  99. package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
  100. package/frontendBuild/dictionaryConstants.ts +136 -0
  101. package/frontendBuild/dictionaryOwnParts.ts +88 -0
  102. package/frontendBuild/dictionaryPackState.ts +131 -0
  103. package/frontendBuild/dictionaryPacking.test.ts +207 -0
  104. package/frontendBuild/dictionaryPacking.ts +160 -0
  105. package/frontendBuild/dictionaryRoutes.test.ts +251 -0
  106. package/frontendBuild/dictionaryRoutes.ts +227 -0
  107. package/frontendBuild/frontendBuild.test.ts +5 -3
  108. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  109. package/frontendBuild/pagesBundleBuilder.ts +78 -2
  110. package/frontendBuild/precompressArtifacts.test.ts +22 -0
  111. package/frontendBuild/precompressArtifacts.ts +34 -8
  112. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  113. package/frontendBuild/renderedEntries.ts +144 -0
  114. package/frontendBuild/routeClientBuilder.ts +407 -43
  115. package/frontendBuild/routeHandoffs.test.ts +155 -0
  116. package/frontendBuild/routeHandoffs.ts +117 -0
  117. package/frontendBuild/routeModulePreloads.test.ts +32 -0
  118. package/frontendBuild/routeModulePreloads.ts +20 -11
  119. package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
  120. package/frontendBuild/routeRuntimeCheck.ts +248 -0
  121. package/frontendBuild/routeRuntimePays.test.ts +143 -0
  122. package/frontendBuild/routeRuntimePays.ts +117 -0
  123. package/frontendBuild/ssrBaseArtifactBuilder.ts +30 -35
  124. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  125. package/frontendBuild/ssrDevBundler.ts +66 -11
  126. package/frontendBuild/vendorFileImports.test.ts +254 -0
  127. package/frontendBuild/vendorFileImports.ts +163 -0
  128. package/frontendBuild/vendorNarrowing.test.ts +47 -3
  129. package/frontendBuild/vendorNarrowing.ts +38 -2
  130. package/frontendBuild/vendorSpecifiers.ts +2 -0
  131. package/guideline/agentAssets.ts +1 -1
  132. package/incrementalBuilder/buildBatch.proc.ts +35 -9
  133. package/incrementalBuilder/buildBatchProtocol.ts +2 -1
  134. package/incrementalBuilder/builderBoot.ts +5 -5
  135. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  136. package/incrementalBuilder/builderLanes.ts +2 -2
  137. package/incrementalBuilder/builderWatch.ts +19 -9
  138. package/incrementalBuilder/csrRegistry.ts +4 -4
  139. package/incrementalBuilder/incrementalBuilder.proc.test.ts +159 -0
  140. package/incrementalBuilder/incrementalBuilder.proc.ts +38 -10
  141. package/incrementalBuilder/pendingMetadata.test.ts +27 -0
  142. package/incrementalBuilder/pendingMetadata.ts +19 -0
  143. package/incrementalBuilder/ssrRegistry.ts +6 -6
  144. package/index.ts +1 -1
  145. package/integration/devStability.integration.test.ts +46 -21
  146. package/integration/renderAdmissionSoak.test.ts +99 -0
  147. package/integration/renderAdmissionSoak.ts +609 -0
  148. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  149. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  150. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  151. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  152. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  153. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  154. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  155. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  156. package/lint/biomeBase.test.ts +50 -3
  157. package/lint/biomeBase.ts +1 -1
  158. package/lint/biomeCheck.test.ts +162 -0
  159. package/lint/biomeCheck.ts +131 -0
  160. package/lint/linter.test.ts +16 -11
  161. package/lint/no-arbitrary-color.grit +5 -0
  162. package/lint/no-conditional-st-hook.grit +5 -1
  163. package/lint/no-daisyui-legacy-class.grit +8 -0
  164. package/lint/no-document-cookie.grit +3 -0
  165. package/lint/no-inline-color.grit +10 -2
  166. package/lint/no-oversized-list-limit.grit +2 -0
  167. package/lint/no-raw-palette-class.grit +7 -0
  168. package/lint/no-unpublished-form-setter.grit +2 -0
  169. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  170. package/lint/no-web-storage.grit +3 -0
  171. package/lint/withheldEnvFile.ts +17 -0
  172. package/mobile/desktopBin.ts +2 -2
  173. package/mobile/desktopServerStage.test.ts +18 -3
  174. package/mobile/desktopServerStage.ts +7 -2
  175. package/mobile/nativeApp.test.ts +7 -5
  176. package/mobile/nativeApp.ts +2 -2
  177. package/mobile/nativeConfig.test.ts +96 -1
  178. package/mobile/nativeConfig.ts +46 -12
  179. package/mobile/nativePublicEnv.ts +1 -1
  180. package/mobile/serverBundleSecrets.ts +43 -0
  181. package/package.json +22 -178
  182. package/packageExports.test.ts +39 -24
  183. package/preview/PreviewView.ts +25 -3
  184. package/quality/dictionaryKeys.test.ts +356 -0
  185. package/quality/dictionaryKeys.ts +488 -0
  186. package/quality/objectImportReport.test.ts +36 -0
  187. package/quality/objectImportReport.ts +105 -0
  188. package/quality/qualityScanner.ts +1 -1
  189. package/quality/routeRuntimeReport.test.ts +91 -0
  190. package/quality/routeRuntimeReport.ts +121 -0
  191. package/quality/runtimeConstantFacts.ts +71 -0
  192. package/quality/runtimeConstantGraph.ts +123 -0
  193. package/quality/runtimeConstantReads.ts +116 -0
  194. package/quality/runtimeImports.test.ts +190 -0
  195. package/quality/runtimeImports.ts +233 -0
  196. package/quality/runtimeKeyNames.ts +46 -0
  197. package/quality/runtimeLexicalScope.ts +132 -0
  198. package/quality/runtimeMarkerReach.test.ts +84 -0
  199. package/quality/runtimeMarkerReach.ts +255 -0
  200. package/quality/runtimeModuleFacts.ts +290 -0
  201. package/quality/runtimeNameTable.test.ts +172 -0
  202. package/quality/runtimeNameTable.ts +477 -0
  203. package/quality/runtimeScopeReport.test.ts +123 -0
  204. package/quality/runtimeScopeReport.ts +167 -0
  205. package/quality/runtimeSliceKey.ts +269 -0
  206. package/quality/runtimeSyntax.ts +133 -0
  207. package/quality/runtimeTable.fixture.ts +189 -0
  208. package/quality/runtimeUse.test.ts +737 -0
  209. package/quality/runtimeUse.ts +696 -0
  210. package/quality/runtimeUseReadable.test.ts +393 -0
  211. package/quality/ssrScanner.test.ts +13 -0
  212. package/quality/ssrScanner.ts +1 -1
  213. package/quality/translatorBindings.ts +187 -0
  214. package/test/fakeTerminal.ts +45 -0
  215. package/test/secretEnvFixture.ts +134 -0
  216. package/test/testHelpers.ts +11 -0
  217. package/transforms/barrelAnalyzer.ts +26 -4
  218. package/transforms/barrelImportsPlugin.ts +121 -32
  219. package/transforms/exportReach.test.ts +162 -0
  220. package/transforms/exportReach.ts +308 -0
  221. package/transforms/frameworkObjects.fixture.tsx +58 -0
  222. package/transforms/frameworkObjects.test.ts +54 -0
  223. package/transforms/modelReference.test.ts +196 -0
  224. package/transforms/modelReference.ts +39 -0
  225. package/transforms/moduleParts.test.ts +225 -0
  226. package/transforms/moduleParts.ts +418 -0
  227. package/transforms/objectImportEdits.ts +150 -0
  228. package/transforms/objectMemberImports.test.ts +633 -0
  229. package/transforms/objectMemberImports.ts +571 -0
  230. package/transforms/objectMemberLookup.ts +150 -0
  231. package/transforms/objectModule.test.ts +307 -0
  232. package/transforms/objectModule.ts +482 -0
  233. package/transforms/objectModuleAnalyzer.ts +104 -0
  234. package/transforms/partImports.test.ts +76 -0
  235. package/transforms/partImports.ts +110 -0
  236. package/transforms/partModules.test.ts +187 -0
  237. package/transforms/partModules.ts +90 -0
  238. package/transforms/partPurity.ts +124 -0
  239. package/transforms/reactIconImports.test.ts +231 -0
  240. package/transforms/reactIconImports.ts +325 -0
  241. package/transforms/routeConstants.ts +122 -0
  242. package/transforms/routeRuntime.test.ts +835 -0
  243. package/transforms/routeRuntime.ts +703 -0
  244. package/transforms/routeRuntimeEdits.ts +92 -0
  245. package/transforms/routeRuntimeGraph.ts +66 -0
  246. package/transforms/routeRuntimePlan.ts +244 -0
  247. package/transforms/secretEnvDeclaration.test.ts +208 -0
  248. package/transforms/secretEnvDeclaration.ts +213 -0
  249. package/transforms/secretEnvFile.test.ts +117 -0
  250. package/transforms/secretEnvFile.ts +113 -0
  251. package/transforms/secretEnvName.test.ts +54 -0
  252. package/transforms/secretEnvName.ts +29 -0
  253. package/transforms/secretEnvSource.test.ts +148 -0
  254. package/transforms/secretEnvSource.ts +166 -0
  255. package/transforms/serverEnvEvaluationError.ts +11 -0
  256. package/transforms/serverEnvPlugin.test.ts +2 -1
  257. package/transforms/serverEnvPlugin.ts +13 -0
  258. package/transforms/serverEnvProfile.test.ts +129 -2
  259. package/transforms/serverEnvProfile.ts +126 -40
  260. package/transforms/serverEnvSecrets.test.ts +292 -0
  261. package/transforms/signalDescriptors.test.ts +280 -0
  262. package/transforms/signalDescriptors.ts +227 -0
  263. package/transforms/thisFreeExports.ts +87 -0
  264. package/transforms/transforms.test.ts +180 -3
  265. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  266. package/tunnel/createTunnel.test.ts +29 -8
  267. package/tunnel/createTunnel.ts +22 -11
  268. package/tunnel/ssh2Module.test.ts +37 -0
  269. package/tunnel/ssh2Module.ts +28 -0
  270. package/tunnel/sshTunnel.ts +4 -2
  271. package/typecheck/projectTypecheck.test.ts +32 -1
  272. package/typecheck/projectTypecheck.ts +3 -3
  273. package/typecheck/typeChecker.test.ts +49 -0
  274. package/typecheck/typeChecker.ts +9 -7
  275. package/typecheck/withheldDiagnostics.ts +41 -0
  276. package/util/devInstallCommand.ts +7 -0
  277. package/util/fileEditor.ts +1 -0
  278. package/util/jsonFormatter.test.ts +13 -9
  279. package/util/selectModel.ts +1 -0
  280. package/workflow/executor.ts +6 -2
  281. package/workflow/index.ts +1 -0
  282. package/workflow/plan.ts +36 -7
  283. package/workflow/types.ts +1 -1
  284. package/workflow/uiTarget.ts +50 -0
  285. package/workspace/envSeed.test.ts +30 -1
  286. package/workspace/envSeed.ts +30 -1
  287. package/workspace/getRelatedCnsts.ts +7 -0
  288. package/workspace/mainCheckout.test.ts +55 -0
  289. package/workspace/mainCheckout.ts +38 -0
  290. package/workspace/scanInfo.test.ts +39 -0
  291. package/workspace/scanInfo.ts +55 -6
  292. package/workspace/slicePlanner.ts +2 -1
  293. package/workspace/workspaceLayout.test.ts +22 -1
  294. package/workspace/workspaceLayout.ts +3 -3
  295. package/CHANGELOG.md +0 -2718
  296. package/codeAgent/agent/AkanCodeCompaction.ts +0 -49
  297. package/codeAgent/agent/AkanCodeServices.ts +0 -122
  298. package/codeAgent/agent/AkanContextFiles.ts +0 -94
  299. package/codeAgent/agent/CodeAgent.ts +0 -606
  300. package/codeAgent/agent/CodeAgentAsks.ts +0 -66
  301. package/codeAgent/agent/CodeAgentEventMapper.ts +0 -225
  302. package/codeAgent/agent/CodeAgentGate.ts +0 -239
  303. package/codeAgent/agent/CodeAgentProxy.ts +0 -83
  304. package/codeAgent/agent/CodeAgentRpcHost.ts +0 -109
  305. package/codeAgent/agent/CodeAgentRpcListener.ts +0 -195
  306. package/codeAgent/agent/CodeAgentStreamPrinter.ts +0 -86
  307. package/codeAgent/agent/CodeAgentSuspended.ts +0 -85
  308. package/codeAgent/agent/CodeAgentUi.ts +0 -47
  309. package/codeAgent/agent/CodeMailbox.ts +0 -148
  310. package/codeAgent/agent/CodeSessionFork.ts +0 -56
  311. package/codeAgent/agent/CodeSessionIndex.ts +0 -78
  312. package/codeAgent/agent/SubagentPool.ts +0 -219
  313. package/codeAgent/agent/WorkspaceTrust.ts +0 -200
  314. package/codeAgent/agent/akanCodeCompaction.test.ts +0 -36
  315. package/codeAgent/agent/akanCodeModel.ts +0 -47
  316. package/codeAgent/agent/akanCodeServices.test.ts +0 -54
  317. package/codeAgent/agent/akanContextFiles.test.ts +0 -116
  318. package/codeAgent/agent/akanSystemPrompt.ts +0 -50
  319. package/codeAgent/agent/codeAgent.test.ts +0 -275
  320. package/codeAgent/agent/codeAgentContract.test.ts +0 -643
  321. package/codeAgent/agent/codeAgentHosts.ts +0 -30
  322. package/codeAgent/agent/codeAgentProxy.test.ts +0 -126
  323. package/codeAgent/agent/codeAgentRpcListener.test.ts +0 -215
  324. package/codeAgent/agent/codeAgentSuspended.test.ts +0 -47
  325. package/codeAgent/agent/codeMailbox.test.ts +0 -76
  326. package/codeAgent/agent/codeSessionFork.test.ts +0 -58
  327. package/codeAgent/agent/codeSessionIndex.test.ts +0 -77
  328. package/codeAgent/agent/consoleToStderr.ts +0 -8
  329. package/codeAgent/agent/jsonLines.ts +0 -29
  330. package/codeAgent/agent/stringArg.ts +0 -5
  331. package/codeAgent/feedback/DevLogFeedback.ts +0 -82
  332. package/codeAgent/feedback/PreviewFeedback.ts +0 -46
  333. package/codeAgent/feedback/TurnFeedback.ts +0 -98
  334. package/codeAgent/feedback/VerifyFeedback.ts +0 -39
  335. package/codeAgent/tools/AkanCli.ts +0 -51
  336. package/codeAgent/tools/AkanCodePlugins.ts +0 -142
  337. package/codeAgent/tools/AkanEditScope.ts +0 -53
  338. package/codeAgent/tools/AkanEnvKeys.ts +0 -50
  339. package/codeAgent/tools/AkanToolPack.ts +0 -86
  340. package/codeAgent/tools/AkanVerifier.ts +0 -30
  341. package/codeAgent/tools/AskToolPack.ts +0 -99
  342. package/codeAgent/tools/DeepSeekWeb.ts +0 -127
  343. package/codeAgent/tools/MailToolPack.ts +0 -76
  344. package/codeAgent/tools/McpClient.ts +0 -209
  345. package/codeAgent/tools/McpOAuth.ts +0 -233
  346. package/codeAgent/tools/McpOAuthLoopback.ts +0 -64
  347. package/codeAgent/tools/McpServerConfig.ts +0 -131
  348. package/codeAgent/tools/McpSignIn.ts +0 -158
  349. package/codeAgent/tools/McpTokenStore.ts +0 -128
  350. package/codeAgent/tools/McpToolPack.ts +0 -206
  351. package/codeAgent/tools/SessionToolPack.ts +0 -91
  352. package/codeAgent/tools/WebToolPack.ts +0 -315
  353. package/codeAgent/tools/akanCodePlugins.test.ts +0 -954
  354. package/codeAgent/tools/askToolPack.test.ts +0 -116
  355. package/codeAgent/tools/deepSeekWeb.test.ts +0 -113
  356. package/codeAgent/tools/mcpOAuth.test.ts +0 -648
  357. package/codeAgent/tools/mcpServerConfig.test.ts +0 -341
  358. package/piDependencyPins.test.ts +0 -45
@@ -1,49 +0,0 @@
1
- import type { SettingsManager } from "@earendil-works/pi-coding-agent";
2
- import type { CodeAgentModel } from "./akanCodeModel";
3
-
4
- type CompactedModel = Pick<CodeAgentModel, "provider" | "id" | "contextWindow">;
5
-
6
- // The engine compacts above `contextWindow - reserveTokens`, so a share of the window becomes a reserve per model.
7
- export class AkanCodeCompaction {
8
- // Twice the engine's 16,384: at 16k a reasoning model stops mid-thought at the compaction threshold,
9
- // and the recovery re-sends a near-full window to retry the turn.
10
- static readonly reserveFloor = 32_768;
11
- static readonly steps = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] as const;
12
-
13
- static isStep(percent: number) {
14
- return AkanCodeCompaction.steps.some((step) => step === percent);
15
- }
16
-
17
- /** `100` is the default itself, so it is stored as no choice at all. */
18
- static normalize(percent: number | undefined) {
19
- if (percent === undefined) return undefined;
20
- if (!AkanCodeCompaction.isStep(percent))
21
- throw new Error(`Autocompact takes a percent in steps of 10: ${AkanCodeCompaction.steps.join(", ")}.`);
22
- return percent === 100 ? undefined : percent;
23
- }
24
-
25
- static thresholdOf(contextWindow: number, percent: number | undefined) {
26
- const share = percent ? Math.floor((contextWindow * percent) / 100) : contextWindow;
27
- return Math.min(share, contextWindow - AkanCodeCompaction.reserveFloor);
28
- }
29
-
30
- static apply(settings: SettingsManager, model: CompactedModel, percent: number | undefined) {
31
- const threshold = AkanCodeCompaction.thresholdOf(model.contextWindow, percent);
32
- // Keyed by model, so the next model is never checked against a reserve sized for this one's window.
33
- settings.applyOverrides({
34
- compaction: {
35
- modelOverrides: { [`${model.provider}/${model.id}`]: { reserveTokens: model.contextWindow - threshold } },
36
- },
37
- });
38
- }
39
-
40
- /** Why `percent` cannot work on `model`, or undefined when it can. */
41
- static problemOf(model: CompactedModel, percent: number, keepRecentTokens: number) {
42
- const name = `${model.provider}/${model.id}`;
43
- if (model.contextWindow <= 0) return `${name} declares no context window, so it has no share to compact at.`;
44
- const threshold = AkanCodeCompaction.thresholdOf(model.contextWindow, percent);
45
- if (threshold >= keepRecentTokens) return undefined;
46
- const k = (tokens: number) => `${Math.round(tokens / 1000)}k`;
47
- return `Compacting at ${percent}% of the ${k(model.contextWindow)} window of ${name} starts at ${k(threshold)}, under the ${k(keepRecentTokens)} of recent turns every compaction keeps, so every turn would compact again.`;
48
- }
49
- }
@@ -1,122 +0,0 @@
1
- import { existsSync, mkdirSync, mkdtempSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import path from "node:path";
4
- import { type InlineExtension, ModelRuntime, SessionManager, SettingsManager } from "@earendil-works/pi-coding-agent";
5
- import type { CodeAgentProfile } from "akanjs/common";
6
- import { AkanEnvKeys } from "../tools/AkanEnvKeys";
7
- import { AkanCodeCompaction } from "./AkanCodeCompaction";
8
- import { type AkanContextFile, AkanContextFiles } from "./AkanContextFiles";
9
- import { akanCodePaths } from "./akanCodePaths";
10
- import { akanSystemPrompt } from "./akanSystemPrompt";
11
- import type { CodeAgentProxy } from "./CodeAgentProxy";
12
- import { CodeSessionIndex } from "./CodeSessionIndex";
13
- import { WorkspaceTrust } from "./WorkspaceTrust";
14
-
15
- type PrepareRequest = (
16
- model: unknown,
17
- options?: Record<string, unknown>,
18
- ) => Promise<{ model: { compat?: Record<string, unknown> } }>;
19
-
20
- export interface AkanCodeServicesOptions {
21
- workspaceRoot: string;
22
- cwd: string;
23
- profile: CodeAgentProfile;
24
- extensions: InlineExtension[];
25
- sessionId?: string;
26
- }
27
-
28
- // All four engine services are injected explicitly: any one left out makes the engine fall back to `~/.pi/`.
29
- export class AkanCodeServices {
30
- static settings() {
31
- // In memory on purpose: file settings would be a second configuration surface beside the profile.
32
- // `enableInstallTelemetry` defaults to true and adds pi-branded headers to OpenRouter/NVIDIA/Cloudflare calls.
33
- return SettingsManager.inMemory({
34
- enableInstallTelemetry: false,
35
- enableAnalytics: false,
36
- quietStartup: true,
37
- compaction: { reserveTokens: AkanCodeCompaction.reserveFloor },
38
- // pi 1.5 defaults to "idle", which sends billed cache refreshes for up to 30 minutes between turns.
39
- cacheWarming: "streaming",
40
- });
41
- }
42
-
43
- // The engine locks and rewrites `authPath` itself, so two `akan code` refreshing a token at once cannot clobber it.
44
- static async runtime(workspaceRoot: string, proxy: CodeAgentProxy | null = null) {
45
- akanCodePaths.ensureGlobalDir();
46
- const runtime = await ModelRuntime.create({
47
- //* Behind a proxy no real key may reach a request, so credentials live in a throwaway file.
48
- authPath: proxy
49
- ? path.join(mkdtempSync(path.join(tmpdir(), "akan-code-proxy-")), "auth.json")
50
- : akanCodePaths.authFile(),
51
- modelsPath: akanCodePaths.modelsFile(),
52
- });
53
- AkanCodeServices.#holdMessageThreadsOff(runtime);
54
- if (proxy) await proxy.apply(runtime);
55
- else await AkanEnvKeys.apply(runtime, workspaceRoot);
56
- return runtime;
57
- }
58
-
59
- // pi 1.5 turned Anthropic message threads on for api.anthropic.com; a models.json `compat` that names it still wins.
60
- static #holdMessageThreadsOff(runtime: ModelRuntime) {
61
- const target = runtime as unknown as { prepareRequest?: PrepareRequest };
62
- const original = target.prepareRequest?.bind(runtime);
63
- if (!original) throw new Error("The model runtime no longer exposes prepareRequest; update AkanCodeServices");
64
- target.prepareRequest = async (model, options) => {
65
- const prepared = await original(model, options);
66
- if (prepared.model.compat?.supportsMessageThreads !== undefined) return prepared;
67
- return {
68
- ...prepared,
69
- model: { ...prepared.model, compat: { ...prepared.model.compat, supportsMessageThreads: false } },
70
- };
71
- };
72
- }
73
-
74
- static sessions(workspaceRoot: string, cwd: string, profile: CodeAgentProfile, resume?: string) {
75
- //* `remote` has no store of its own yet, so it keeps a file session: a pod worker's suspended asks need it.
76
- if (profile.session.store === "memory") return SessionManager.inMemory(cwd);
77
- const dir = akanCodePaths.sessionsDir(workspaceRoot);
78
- mkdirSync(dir, { recursive: true });
79
- const manager = SessionManager.create(cwd, dir);
80
- if (!resume) return manager;
81
- const file = CodeSessionIndex.fileOf(dir, resume);
82
- // A mistyped id that quietly opened a new session would look like a session that lost its history.
83
- if (!file) throw new Error(`No stored session ${resume} in ${dir}`);
84
- manager.setSessionFile(file);
85
- return manager;
86
- }
87
-
88
- // Skills are text, never code that runs, so unlike extensions they may come from the home directory too.
89
- static #skillPaths(profile: CodeAgentProfile, workspaceRoot: string) {
90
- if (!profile.context.skills) return [];
91
- const dirs = [
92
- akanCodePaths.builtinSkillsDir(),
93
- akanCodePaths.globalSkillsDir(),
94
- akanCodePaths.skillsDir(workspaceRoot),
95
- ];
96
- return dirs.filter((dir): dir is string => !!dir && existsSync(dir));
97
- }
98
-
99
- static resourceOptions(options: AkanCodeServicesOptions) {
100
- // A path that does not exist is reported as a load error rather than skipped, and these two are optional.
101
- const present = (dir: string) => (existsSync(dir) ? [dir] : []);
102
- return {
103
- noExtensions: true,
104
- // Disables only the engine's default skill locations (`~/.pi/skills`, `.pi/`); `additionalSkillPaths` merge.
105
- noSkills: true,
106
- noPromptTemplates: true,
107
- noThemes: true,
108
- noContextFiles: !options.profile.context.projectFiles,
109
- agentsFilesOverride: ({ agentsFiles }: { agentsFiles: AkanContextFile[] }) => ({
110
- agentsFiles: options.profile.context.projectFiles
111
- ? AkanContextFiles.extend(agentsFiles, { workspaceRoot: options.workspaceRoot, cwd: options.cwd })
112
- : agentsFiles,
113
- }),
114
- appendSystemPrompt: [akanSystemPrompt(options.profile)],
115
- additionalExtensionPaths: WorkspaceTrust.isTrusted(options.workspaceRoot, "extensions")
116
- ? present(akanCodePaths.extensionsDir(options.workspaceRoot))
117
- : [],
118
- additionalSkillPaths: AkanCodeServices.#skillPaths(options.profile, options.workspaceRoot),
119
- extensionFactories: options.extensions,
120
- };
121
- }
122
- }
@@ -1,94 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
- import path from "node:path";
3
-
4
- export interface AkanContextFile {
5
- path: string;
6
- content: string;
7
- }
8
-
9
- export interface AkanContextFilesOptions {
10
- workspaceRoot: string;
11
- cwd: string;
12
- }
13
-
14
- // The engine takes only the first of `AGENTS.override.md · AGENTS.md · CLAUDE.md` per directory and never reads
15
- // `.cursor/rules`; this appends what it drops, after the engine's own list.
16
- export class AkanContextFiles {
17
- /** Cursor's frontmatter block, which is metadata for its own rule picker and not instruction for a model. */
18
- static readonly #frontmatter = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
19
-
20
- static extend(base: AkanContextFile[], options: AkanContextFilesOptions): AkanContextFile[] {
21
- const seen = new Set(base.map((file) => file.path));
22
- // Keyed by content too: the usual way to carry both names is a symlink or a one-line pointer.
23
- const contents = new Set(base.map((file) => file.content.trim()));
24
- const added: AkanContextFile[] = [];
25
- for (const file of [...AkanContextFiles.#claude(base), ...AkanContextFiles.#cursor(options)]) {
26
- if (seen.has(file.path) || contents.has(file.content.trim()) || !file.content.trim()) continue;
27
- seen.add(file.path);
28
- contents.add(file.content.trim());
29
- added.push(file);
30
- }
31
- return [...base, ...added];
32
- }
33
-
34
- // Not beside an `AGENTS.override.md`: that file exists to displace the others in its directory.
35
- static #claude(base: AkanContextFile[]) {
36
- const files: AkanContextFile[] = [];
37
- for (const file of base) {
38
- if (!/^AGENTS\.(md|MD)$/.test(path.basename(file.path))) continue;
39
- for (const name of ["CLAUDE.md", "CLAUDE.MD"]) {
40
- const candidate = path.join(path.dirname(file.path), name);
41
- const content = AkanContextFiles.#read(candidate);
42
- if (content !== undefined) files.push({ path: candidate, content });
43
- }
44
- }
45
- return files;
46
- }
47
-
48
- // Only `alwaysApply: true` or frontmatter-less rules: Cursor's `globs`/`description`/manual kinds are scoped.
49
- static #cursor(options: AkanContextFilesOptions) {
50
- const files: AkanContextFile[] = [];
51
- const roots = [...new Set([options.workspaceRoot, options.cwd])];
52
- for (const root of roots) {
53
- const legacy = AkanContextFiles.#read(path.join(root, ".cursorrules"));
54
- if (legacy !== undefined) files.push({ path: path.join(root, ".cursorrules"), content: legacy });
55
- for (const file of AkanContextFiles.#mdcFiles(path.join(root, ".cursor", "rules"))) {
56
- const raw = AkanContextFiles.#read(file);
57
- if (raw === undefined) continue;
58
- const body = AkanContextFiles.#applied(raw);
59
- if (body !== undefined) files.push({ path: file, content: body });
60
- }
61
- }
62
- return files;
63
- }
64
-
65
- static #applied(raw: string) {
66
- const match = AkanContextFiles.#frontmatter.exec(raw);
67
- if (!match) return raw;
68
- if (!/^\s*alwaysApply\s*:\s*true\s*$/m.test(match[1] ?? "")) return undefined;
69
- return raw.slice(match[0].length);
70
- }
71
-
72
- /** Sorted, because the order rules reach the model in is otherwise the order a directory happens to list. */
73
- static #mdcFiles(dir: string) {
74
- if (!existsSync(dir)) return [];
75
- try {
76
- return readdirSync(dir, { recursive: true, withFileTypes: true })
77
- .filter((entry) => entry.isFile() && entry.name.endsWith(".mdc"))
78
- .map((entry) => path.join(entry.parentPath ?? dir, entry.name))
79
- .sort();
80
- } catch {
81
- return [];
82
- }
83
- }
84
-
85
- static #read(file: string) {
86
- try {
87
- if (!existsSync(file) || !statSync(file).isFile()) return undefined;
88
- return readFileSync(file, "utf8").replace(/^/, "");
89
- } catch {
90
- // A rule file that cannot be read costs its own rules. It must not cost the session its start.
91
- return undefined;
92
- }
93
- }
94
- }