@caupulican/pi-adaptative 0.84.1 → 0.85.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -8
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -8
  6. package/dist/bundled-resources/runtimes/pi-shell-engine/arithmetic.py +364 -0
  7. package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +2 -1
  8. package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +16 -0
  9. package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +137 -14
  10. package/dist/bundled-resources/runtimes/pi-shell-engine/nodes.py +23 -2
  11. package/dist/bundled-resources/runtimes/pi-shell-engine/parser.py +134 -6
  12. package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +25 -2
  13. package/dist/bundled-resources/skills/deduplicate-by-evidence/SKILL.md +7 -5
  14. package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +63 -0
  15. package/dist/core/agent-session.d.ts.map +1 -1
  16. package/dist/core/agent-session.js +8 -0
  17. package/dist/core/agent-session.js.map +1 -1
  18. package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
  19. package/dist/core/autonomy/lane-tool-surface.js +4 -2
  20. package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
  21. package/dist/core/background-lane-controller.d.ts +3 -0
  22. package/dist/core/background-lane-controller.d.ts.map +1 -1
  23. package/dist/core/background-lane-controller.js +6 -0
  24. package/dist/core/background-lane-controller.js.map +1 -1
  25. package/dist/core/compaction-controller.d.ts +2 -0
  26. package/dist/core/compaction-controller.d.ts.map +1 -1
  27. package/dist/core/compaction-controller.js +35 -13
  28. package/dist/core/compaction-controller.js.map +1 -1
  29. package/dist/core/default-tool-surface.d.ts.map +1 -1
  30. package/dist/core/default-tool-surface.js +1 -0
  31. package/dist/core/default-tool-surface.js.map +1 -1
  32. package/dist/core/delegation/worker-delegation-controller.d.ts +7 -0
  33. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  34. package/dist/core/delegation/worker-delegation-controller.js +28 -0
  35. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  36. package/dist/core/delegation/worker-profile-resolver.d.ts +2 -0
  37. package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
  38. package/dist/core/delegation/worker-profile-resolver.js +46 -11
  39. package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
  40. package/dist/core/doctor.d.ts +1 -1
  41. package/dist/core/doctor.d.ts.map +1 -1
  42. package/dist/core/doctor.js +5 -4
  43. package/dist/core/doctor.js.map +1 -1
  44. package/dist/core/failure-corpus.d.ts +26 -1
  45. package/dist/core/failure-corpus.d.ts.map +1 -1
  46. package/dist/core/failure-corpus.js +17 -0
  47. package/dist/core/failure-corpus.js.map +1 -1
  48. package/dist/core/model-capability.d.ts.map +1 -1
  49. package/dist/core/model-capability.js +1 -0
  50. package/dist/core/model-capability.js.map +1 -1
  51. package/dist/core/model-tool-protocol.d.ts +3 -2
  52. package/dist/core/model-tool-protocol.d.ts.map +1 -1
  53. package/dist/core/model-tool-protocol.js +5 -1
  54. package/dist/core/model-tool-protocol.js.map +1 -1
  55. package/dist/core/models/runtime-process.d.ts +7 -1
  56. package/dist/core/models/runtime-process.d.ts.map +1 -1
  57. package/dist/core/models/runtime-process.js +4 -2
  58. package/dist/core/models/runtime-process.js.map +1 -1
  59. package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
  60. package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
  61. package/dist/core/orchestration/lane-tool-manifests.js +6 -1
  62. package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
  63. package/dist/core/orchestration/session-task-profile-store.d.ts +31 -0
  64. package/dist/core/orchestration/session-task-profile-store.d.ts.map +1 -0
  65. package/dist/core/orchestration/session-task-profile-store.js +138 -0
  66. package/dist/core/orchestration/session-task-profile-store.js.map +1 -0
  67. package/dist/core/orchestration/task-profile-writer.d.ts +58 -0
  68. package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -0
  69. package/dist/core/orchestration/task-profile-writer.js +165 -0
  70. package/dist/core/orchestration/task-profile-writer.js.map +1 -0
  71. package/dist/core/process-matrix/runtime.js +43 -11
  72. package/dist/core/process-matrix/runtime.js.map +1 -1
  73. package/dist/core/resource-loader.d.ts +2 -0
  74. package/dist/core/resource-loader.d.ts.map +1 -1
  75. package/dist/core/resource-loader.js +18 -6
  76. package/dist/core/resource-loader.js.map +1 -1
  77. package/dist/core/runtime-builder.d.ts +3 -1
  78. package/dist/core/runtime-builder.d.ts.map +1 -1
  79. package/dist/core/runtime-builder.js +14 -0
  80. package/dist/core/runtime-builder.js.map +1 -1
  81. package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
  82. package/dist/core/security/untrusted-boundary.js +4 -6
  83. package/dist/core/security/untrusted-boundary.js.map +1 -1
  84. package/dist/core/session-role.d.ts.map +1 -1
  85. package/dist/core/session-role.js +1 -0
  86. package/dist/core/session-role.js.map +1 -1
  87. package/dist/core/system-prompt.d.ts.map +1 -1
  88. package/dist/core/system-prompt.js +21 -23
  89. package/dist/core/system-prompt.js.map +1 -1
  90. package/dist/core/tool-capability-policy.js +1 -1
  91. package/dist/core/tool-capability-policy.js.map +1 -1
  92. package/dist/core/tool-recovery-log-records.d.ts +33 -1
  93. package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
  94. package/dist/core/tool-recovery-log-records.js +59 -12
  95. package/dist/core/tool-recovery-log-records.js.map +1 -1
  96. package/dist/core/tool-recovery-logger.d.ts +12 -1
  97. package/dist/core/tool-recovery-logger.d.ts.map +1 -1
  98. package/dist/core/tool-recovery-logger.js +24 -1
  99. package/dist/core/tool-recovery-logger.js.map +1 -1
  100. package/dist/core/tool-repair-health.d.ts.map +1 -1
  101. package/dist/core/tool-repair-health.js +6 -0
  102. package/dist/core/tool-repair-health.js.map +1 -1
  103. package/dist/core/tools/bash.d.ts +3 -8
  104. package/dist/core/tools/bash.d.ts.map +1 -1
  105. package/dist/core/tools/bash.js +4 -28
  106. package/dist/core/tools/bash.js.map +1 -1
  107. package/dist/core/tools/delegate.js +4 -4
  108. package/dist/core/tools/delegate.js.map +1 -1
  109. package/dist/core/tools/edit-diff.d.ts +32 -5
  110. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  111. package/dist/core/tools/edit-diff.js +137 -69
  112. package/dist/core/tools/edit-diff.js.map +1 -1
  113. package/dist/core/tools/edit.d.ts +22 -7
  114. package/dist/core/tools/edit.d.ts.map +1 -1
  115. package/dist/core/tools/edit.js +128 -55
  116. package/dist/core/tools/edit.js.map +1 -1
  117. package/dist/core/tools/file-mutation-intent.d.ts +70 -0
  118. package/dist/core/tools/file-mutation-intent.d.ts.map +1 -0
  119. package/dist/core/tools/file-mutation-intent.js +325 -0
  120. package/dist/core/tools/file-mutation-intent.js.map +1 -0
  121. package/dist/core/tools/find.d.ts +2 -1
  122. package/dist/core/tools/find.d.ts.map +1 -1
  123. package/dist/core/tools/find.js +2 -6
  124. package/dist/core/tools/find.js.map +1 -1
  125. package/dist/core/tools/goal.d.ts.map +1 -1
  126. package/dist/core/tools/goal.js +41 -18
  127. package/dist/core/tools/goal.js.map +1 -1
  128. package/dist/core/tools/grep.d.ts +2 -1
  129. package/dist/core/tools/grep.d.ts.map +1 -1
  130. package/dist/core/tools/grep.js +2 -6
  131. package/dist/core/tools/grep.js.map +1 -1
  132. package/dist/core/tools/index.d.ts +3 -1
  133. package/dist/core/tools/index.d.ts.map +1 -1
  134. package/dist/core/tools/index.js +31 -8
  135. package/dist/core/tools/index.js.map +1 -1
  136. package/dist/core/tools/managed-search-tool.d.ts +8 -0
  137. package/dist/core/tools/managed-search-tool.d.ts.map +1 -0
  138. package/dist/core/tools/managed-search-tool.js +10 -0
  139. package/dist/core/tools/managed-search-tool.js.map +1 -0
  140. package/dist/core/tools/profile-writer.d.ts +33 -0
  141. package/dist/core/tools/profile-writer.d.ts.map +1 -0
  142. package/dist/core/tools/profile-writer.js +67 -0
  143. package/dist/core/tools/profile-writer.js.map +1 -0
  144. package/dist/core/tools/shell-command-parser.d.ts +4 -3
  145. package/dist/core/tools/shell-command-parser.d.ts.map +1 -1
  146. package/dist/core/tools/shell-command-parser.js +32 -7
  147. package/dist/core/tools/shell-command-parser.js.map +1 -1
  148. package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
  149. package/dist/core/tools/shell-contract-router.js +23 -1
  150. package/dist/core/tools/shell-contract-router.js.map +1 -1
  151. package/dist/core/tools/task-steps.d.ts.map +1 -1
  152. package/dist/core/tools/task-steps.js +6 -11
  153. package/dist/core/tools/task-steps.js.map +1 -1
  154. package/dist/core/tools/tmux-dispatch.d.ts +2 -0
  155. package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
  156. package/dist/core/tools/tmux-dispatch.js +16 -2
  157. package/dist/core/tools/tmux-dispatch.js.map +1 -1
  158. package/dist/core/tools/windows-shell-engine.js +1 -1
  159. package/dist/core/tools/windows-shell-engine.js.map +1 -1
  160. package/dist/core/tools/write.d.ts +24 -7
  161. package/dist/core/tools/write.d.ts.map +1 -1
  162. package/dist/core/tools/write.js +182 -107
  163. package/dist/core/tools/write.js.map +1 -1
  164. package/dist/index.d.ts +1 -1
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +1 -1
  167. package/dist/index.js.map +1 -1
  168. package/dist/jscpd-cli.d.ts +3 -0
  169. package/dist/jscpd-cli.d.ts.map +1 -0
  170. package/dist/jscpd-cli.js +22 -0
  171. package/dist/jscpd-cli.js.map +1 -0
  172. package/dist/modes/interactive/components/profile-resource-editor.js +2 -2
  173. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  174. package/dist/modes/interactive/components/tool-execution.d.ts +1 -0
  175. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  176. package/dist/modes/interactive/components/tool-execution.js +85 -3
  177. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  178. package/dist/modes/interactive/interactive-mode.js +1 -1
  179. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  180. package/dist/utils/bundled-jscpd.d.ts +20 -0
  181. package/dist/utils/bundled-jscpd.d.ts.map +1 -0
  182. package/dist/utils/bundled-jscpd.js +154 -0
  183. package/dist/utils/bundled-jscpd.js.map +1 -0
  184. package/dist/utils/paths.js +1 -1
  185. package/dist/utils/paths.js.map +1 -1
  186. package/dist/utils/shell.d.ts.map +1 -1
  187. package/dist/utils/shell.js +11 -0
  188. package/dist/utils/shell.js.map +1 -1
  189. package/dist/utils/tools-manager.d.ts +19 -2
  190. package/dist/utils/tools-manager.d.ts.map +1 -1
  191. package/dist/utils/tools-manager.js +92 -40
  192. package/dist/utils/tools-manager.js.map +1 -1
  193. package/docs/index.md +3 -0
  194. package/docs/managed-data-tools.md +15 -0
  195. package/docs/models.md +1 -1
  196. package/docs/quickstart.md +2 -2
  197. package/docs/settings.md +1 -1
  198. package/docs/tool-boundary-performance-roadmap-2026-08-02.md +166 -0
  199. package/docs/tool-repair.md +4 -4
  200. package/docs/windows.md +7 -5
  201. package/docs/worker-profiles.md +16 -0
  202. package/examples/extensions/built-in-tool-renderer.ts +12 -5
  203. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  204. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  205. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  206. package/examples/extensions/minimal-mode.ts +8 -7
  207. package/examples/extensions/prompt-customizer.ts +4 -2
  208. package/examples/extensions/sandbox/package-lock.json +2 -2
  209. package/examples/extensions/sandbox/package.json +1 -1
  210. package/examples/extensions/ssh.ts +113 -24
  211. package/examples/extensions/with-deps/package-lock.json +2 -2
  212. package/examples/extensions/with-deps/package.json +1 -1
  213. package/npm-shrinkwrap.json +112 -12
  214. package/package.json +7 -5
@@ -1 +1 @@
1
- {"version":3,"file":"worker-profile-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-profile-resolver.ts"],"names":[],"mappings":"AAQA,OAAO,EACN,mCAAmC,EACnC,+BAA+B,GAC/B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAG9E,OAAO,EAAE,6BAA6B,EAA4C,MAAM,8BAA8B,CAAC;AAsBvH,MAAM,OAAO,qBAAqB;IAIjC,YAAY,OAAqC;QAFhC,sBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;QAGtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,OAAO;QACN,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,6BAA6B,EAAE,CAAC;QACnE,MAAM,iBAAiB,GACtB,aAAa,EAAE,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAChG,OAAO,IAAI,CAAC,YAAY,EAAE;aACxB,QAAQ,CAAC,MAAM,CACf,CAAC,OAAO,EAAE,EAAE,CACX,OAAO,CAAC,IAAI,KAAK,cAAc,IAAI,CAAC,CAAC,iBAAiB,IAAI,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CACpG;aACA,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAClB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,OAAO,CAAC,WAAW;SAChC,CAAC,CAAC,CAAC;IACN,CAAC;IAED,OAAO,CACN,OAAgC,EAChC,gBAAoC;QAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,gBAAgB,CAAC;QACh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,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACzB;SACD,CAAC;IACH,CAAC;IAEO,mBAAmB,CAAC,SAAiB;QAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,6BAA6B,EAAE,CAAC;QACnE,OAAO,CACN,CAAC,aAAa;YACd,CAAC,aAAa,CAAC,IAAI,KAAK,cAAc,IAAI,aAAa,CAAC,kBAAkB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAC/F,CAAC;IACH,CAAC;IAEO,YAAY;QACnB,MAAM,MAAM,GAAG,IAAI,yBAAyB,CAAC;YAC5C,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;YAC/B,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;YACrB,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,gBAAgB,EAAE;SACpE,CAAC,CAAC,IAAI,EAAE,CAAC;QACV,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YAC7C,MAAM,GAAG,GAAG,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC;YACxD,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,SAAS;YAC9C,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,kCAAkC,UAAU,CAAC,IAAI,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;CACD","sourcesContent":["import type { Api, Model } from \"@caupulican/pi-ai\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport type {\n\tOrchestrationModelBinding,\n\tOrchestrationProfile,\n\tResourcePointer,\n\tWorkerProfileExecutionContract,\n} from \"../orchestration/contracts.ts\";\nimport {\n\tresolveConfiguredOrchestrationModel,\n\tresolvePinnedOrchestrationModel,\n} from \"../orchestration/model-binding.ts\";\nimport { OrchestrationProfileStore } from \"../orchestration/profile-store.ts\";\nimport type { SettingsManager } from \"../settings-manager.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\nimport { catalogWorkerResourcePointers, type WorkerResourceCatalogResourceLoader } from \"./worker-resource-catalog.ts\";\n\nexport interface ResolvedWorkerProfile {\n\tmodel: Model<Api>;\n\tmodelBinding: OrchestrationModelBinding;\n\tprofile: OrchestrationProfile;\n\t/** Metadata-only pointers admitted from the profile-linked resource configuration. */\n\tresourcePointers: readonly ResourcePointer[];\n\tsoul?: string;\n}\n\nexport interface WorkerProfileResolverOptions {\n\tagentDir: string;\n\tcwd: string;\n\tgetSettingsManager(): SettingsManager;\n\tgetResourceLoader(): WorkerResourceCatalogResourceLoader;\n\tgetModelRegistry(): ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n\tgetActiveOrchestrationProfile(): OrchestrationProfile | undefined;\n\tonDiagnostic(message: string): void;\n}\n\nexport class WorkerProfileResolver {\n\tprivate readonly options: WorkerProfileResolverOptions;\n\tprivate readonly warnedDiagnostics = new Set<string>();\n\n\tconstructor(options: WorkerProfileResolverOptions) {\n\t\tthis.options = options;\n\t}\n\n\tcatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\tconst activeProfile = this.options.getActiveOrchestrationProfile();\n\t\tconst allowedProfileIds =\n\t\t\tactiveProfile?.role === \"orchestrator\" ? new Set(activeProfile.dispatchProfileIds) : undefined;\n\t\treturn this.loadProfiles()\n\t\t\t.profiles.filter(\n\t\t\t\t(profile) =>\n\t\t\t\t\tprofile.role !== \"orchestrator\" && (!allowedProfileIds || allowedProfileIds.has(profile.profileId)),\n\t\t\t)\n\t\t\t.map((profile) => ({\n\t\t\t\tprofileId: profile.profileId,\n\t\t\t\trole: profile.role,\n\t\t\t\tdescription: profile.description,\n\t\t\t}));\n\t}\n\n\tresolve(\n\t\trequest: WorkerDelegationRequest,\n\t\tdefaultProfileId: string | undefined,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tconst profileId = request.profileId?.trim() || defaultProfileId;\n\t\tif (!profileId) return { ok: false, reason: \"orchestration_profile_required\" };\n\t\tconst selected = this.resolveProfileId(profileId);\n\t\tif (!selected.ok) return selected;\n\t\tconst profile = selected.resolved.profile;\n\t\tif (request.verificationOfTaskId && profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\tif (!request.verificationOfTaskId && profile.role === \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verifier_profile_requires_runtime_dispatch\" };\n\t\t}\n\t\treturn selected;\n\t}\n\n\tresolveVerifier(\n\t\tworkerProfile: OrchestrationProfile,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tif (!workerProfile.requireIndependentVerification || !workerProfile.verificationProfileId) {\n\t\t\treturn { ok: false, reason: \"independent_verifier_not_configured\" };\n\t\t}\n\t\tconst selected = this.resolveProfileId(workerProfile.verificationProfileId);\n\t\tif (!selected.ok) return selected;\n\t\tif (selected.resolved.profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\treturn selected;\n\t}\n\n\tresolveContract(\n\t\tcontract: WorkerProfileExecutionContract,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\t// The architect allowlist authorized this immutable contract at admission. Live session/goal\n\t\t// controls may revoke execution, but mutable profile files cannot retroactively redefine it.\n\t\tconst resolvedModel = resolvePinnedOrchestrationModel(\n\t\t\tcontract.modelBinding,\n\t\t\tthis.options.getModelRegistry(),\n\t\t\t(model) => this.options.isModelExhausted(model),\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_profile_model_unavailable\" };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: structuredClone(contract.profile),\n\t\t\t\tresourcePointers: structuredClone(contract.resourcePointers),\n\t\t\t\t...(contract.soul ? { soul: contract.soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate resolveProfileId(\n\t\tprofileId: string,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tif (!this.isProfileAuthorized(profileId)) {\n\t\t\treturn { ok: false, reason: \"orchestration_profile_not_authorized_for_orchestrator\" };\n\t\t}\n\t\tconst profile = this.loadProfiles().registry.get(profileId);\n\t\tif (!profile) return { ok: false, reason: \"orchestration_profile_not_found\" };\n\t\tconst resolvedModel = resolveConfiguredOrchestrationModel(profile, this.options.getModelRegistry(), (model) =>\n\t\t\tthis.options.isModelExhausted(model),\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_profile_model_unavailable\" };\n\t\tconst linkedProfiles = profile.resourceProfileNames.map((name) =>\n\t\t\tthis.options.getSettingsManager().getProfileRegistry().getProfile(name),\n\t\t);\n\t\tif (linkedProfiles.some((linked) => linked === undefined)) {\n\t\t\treturn { ok: false, reason: \"orchestration_resource_profile_not_found\" };\n\t\t}\n\t\tconst soul = linkedProfiles\n\t\t\t.flatMap((linked) => (linked?.soul ? [linked.soul] : []))\n\t\t\t.join(\"\\n\\n\")\n\t\t\t.trim();\n\t\tconst resourcePointers = catalogWorkerResourcePointers({\n\t\t\tcwd: this.options.cwd,\n\t\t\tresourceLoader: this.options.getResourceLoader(),\n\t\t\tresourceProfiles: linkedProfiles.filter(\n\t\t\t\t(linked): linked is NonNullable<typeof linked> => linked !== undefined,\n\t\t\t),\n\t\t});\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile,\n\t\t\t\tresourcePointers,\n\t\t\t\t...(soul ? { soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate isProfileAuthorized(profileId: string): boolean {\n\t\tconst activeProfile = this.options.getActiveOrchestrationProfile();\n\t\treturn (\n\t\t\t!activeProfile ||\n\t\t\t(activeProfile.role === \"orchestrator\" && activeProfile.dispatchProfileIds.includes(profileId))\n\t\t);\n\t}\n\n\tprivate loadProfiles(): ReturnType<OrchestrationProfileStore[\"load\"]> {\n\t\tconst loaded = new OrchestrationProfileStore({\n\t\t\tagentDir: this.options.agentDir,\n\t\t\tcwd: this.options.cwd,\n\t\t\tprojectTrusted: this.options.getSettingsManager().isProjectTrusted(),\n\t\t}).load();\n\t\tfor (const diagnostic of loaded.diagnostics) {\n\t\t\tconst key = `${diagnostic.path}\\0${diagnostic.message}`;\n\t\t\tif (this.warnedDiagnostics.has(key)) continue;\n\t\t\tthis.warnedDiagnostics.add(key);\n\t\t\tthis.options.onDiagnostic(`Orchestration profile ignored (${diagnostic.path}): ${diagnostic.message}`);\n\t\t}\n\t\treturn loaded;\n\t}\n}\n"]}
1
+ {"version":3,"file":"worker-profile-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-profile-resolver.ts"],"names":[],"mappings":"AAQA,OAAO,EACN,mCAAmC,EACnC,+BAA+B,GAC/B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAI9E,OAAO,EAAE,6BAA6B,EAA4C,MAAM,8BAA8B,CAAC;AA6BvH,MAAM,OAAO,qBAAqB;IAIjC,YAAY,OAAqC;QAFhC,sBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;QAGtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,OAAO;QACN,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACnC,OAAO,MAAM,CAAC,QAAQ;aACpB,MAAM,CAAC,C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KAAK,MAAM,UAAU,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC;YACnD,MAAM,GAAG,GAAG,YAAY,UAAU,EAAE,CAAC;YACrC,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,SAAS;YAC9C,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,iCAAiC,UAAU,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,MAAM,QAAQ,GAAG,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QACzF,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoC,CAAC;QACjE,KAAK,MAAM,MAAM,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC;YAC3C,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;gBAAE,SAAS;YACrD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;YACvD,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IAC7C,CAAC;CACD","sourcesContent":["import type { Api, Model } from \"@caupulican/pi-ai\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport type {\n\tOrchestrationModelBinding,\n\tOrchestrationProfile,\n\tResourcePointer,\n\tWorkerProfileExecutionContract,\n} from \"../orchestration/contracts.ts\";\nimport {\n\tresolveConfiguredOrchestrationModel,\n\tresolvePinnedOrchestrationModel,\n} from \"../orchestration/model-binding.ts\";\nimport { OrchestrationProfileStore } from \"../orchestration/profile-store.ts\";\nimport type { SessionTaskProfileRecord, SessionTaskProfileStore } from \"../orchestration/session-task-profile-store.ts\";\nimport type { SettingsManager } from \"../settings-manager.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\nimport { catalogWorkerResourcePointers, type WorkerResourceCatalogResourceLoader } from \"./worker-resource-catalog.ts\";\n\nexport interface ResolvedWorkerProfile {\n\tmodel: Model<Api>;\n\tmodelBinding: OrchestrationModelBinding;\n\tprofile: OrchestrationProfile;\n\t/** Metadata-only pointers admitted from the profile-linked resource configuration. */\n\tresourcePointers: readonly ResourcePointer[];\n\tsoul?: string;\n}\n\nexport interface WorkerProfileResolverOptions {\n\tagentDir: string;\n\tcwd: string;\n\tgetSettingsManager(): SettingsManager;\n\tgetResourceLoader(): WorkerResourceCatalogResourceLoader;\n\tgetModelRegistry(): ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n\tgetActiveOrchestrationProfile(): OrchestrationProfile | undefined;\n\tgetTaskProfileStore(): SessionTaskProfileStore;\n\tonDiagnostic(message: string): void;\n}\n\ninterface LoadedWorkerProfiles {\n\tprofiles: OrchestrationProfile[];\n\tregistry: ReadonlyMap<string, OrchestrationProfile>;\n\ttaskRegistry: ReadonlyMap<string, SessionTaskProfileRecord>;\n}\n\nexport class WorkerProfileResolver {\n\tprivate readonly options: WorkerProfileResolverOptions;\n\tprivate readonly warnedDiagnostics = new Set<string>();\n\n\tconstructor(options: WorkerProfileResolverOptions) {\n\t\tthis.options = options;\n\t}\n\n\tcatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\tconst loaded = this.loadProfiles();\n\t\treturn loaded.profiles\n\t\t\t.filter((profile) => profile.role !== \"orchestrator\" && this.isProfileAuthorized(profile.profileId, loaded))\n\t\t\t.map((profile) => ({\n\t\t\t\tprofileId: profile.profileId,\n\t\t\t\trole: profile.role,\n\t\t\t\tdescription: profile.description,\n\t\t\t}));\n\t}\n\n\tresolve(\n\t\trequest: WorkerDelegationRequest,\n\t\tdefaultProfileId: string | undefined,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tconst requestedProfileId = request.profileId?.trim();\n\t\tconst activeProfile = this.options.getActiveOrchestrationProfile();\n\t\tconst loaded = this.loadProfiles();\n\t\tconst requestedTaskProfile = requestedProfileId ? loaded.taskRegistry.has(requestedProfileId) : false;\n\t\t// A regular session uses the owner's fixed default even if the model invents or mistypes a\n\t\t// profile id. Only an owner-authored orchestrator is a routing authority, and its selections\n\t\t// remain constrained by dispatchProfileIds in resolveProfileId().\n\t\tconst profileId =\n\t\t\tactiveProfile?.role === \"orchestrator\"\n\t\t\t\t? requestedProfileId || defaultProfileId\n\t\t\t\t: requestedTaskProfile\n\t\t\t\t\t? requestedProfileId\n\t\t\t\t\t: defaultProfileId || requestedProfileId;\n\t\tif (!profileId) return { ok: false, reason: \"orchestration_profile_required\" };\n\t\tconst selected = this.resolveProfileId(profileId, loaded);\n\t\tif (!selected.ok) return selected;\n\t\tconst profile = selected.resolved.profile;\n\t\tif (request.verificationOfTaskId && profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\tif (!request.verificationOfTaskId && profile.role === \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verifier_profile_requires_runtime_dispatch\" };\n\t\t}\n\t\treturn selected;\n\t}\n\n\tresolveVerifier(\n\t\tworkerProfile: OrchestrationProfile,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tif (!workerProfile.requireIndependentVerification || !workerProfile.verificationProfileId) {\n\t\t\treturn { ok: false, reason: \"independent_verifier_not_configured\" };\n\t\t}\n\t\tconst selected = this.resolveProfileId(workerProfile.verificationProfileId);\n\t\tif (!selected.ok) return selected;\n\t\tif (selected.resolved.profile.role !== \"verifier\") {\n\t\t\treturn { ok: false, reason: \"verification_profile_role_mismatch\" };\n\t\t}\n\t\treturn selected;\n\t}\n\n\tresolveContract(\n\t\tcontract: WorkerProfileExecutionContract,\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\t// The architect allowlist authorized this immutable contract at admission. Live session/goal\n\t\t// controls may revoke execution, but mutable profile files cannot retroactively redefine it.\n\t\tconst resolvedModel = resolvePinnedOrchestrationModel(\n\t\t\tcontract.modelBinding,\n\t\t\tthis.options.getModelRegistry(),\n\t\t\t(model) => this.options.isModelExhausted(model),\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_profile_model_unavailable\" };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: structuredClone(contract.profile),\n\t\t\t\tresourcePointers: structuredClone(contract.resourcePointers),\n\t\t\t\t...(contract.soul ? { soul: contract.soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate resolveProfileId(\n\t\tprofileId: string,\n\t\tloaded: LoadedWorkerProfiles = this.loadProfiles(),\n\t): { ok: true; resolved: ResolvedWorkerProfile } | { ok: false; reason: string } {\n\t\tif (!this.isProfileAuthorized(profileId, loaded)) {\n\t\t\treturn { ok: false, reason: \"orchestration_profile_not_authorized_for_orchestrator\" };\n\t\t}\n\t\tconst profile = loaded.registry.get(profileId);\n\t\tif (!profile) return { ok: false, reason: \"orchestration_profile_not_found\" };\n\t\tconst resolvedModel = resolveConfiguredOrchestrationModel(profile, this.options.getModelRegistry(), (model) =>\n\t\t\tthis.options.isModelExhausted(model),\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_profile_model_unavailable\" };\n\t\tconst linkedProfiles = profile.resourceProfileNames.map((name) =>\n\t\t\tthis.options.getSettingsManager().getProfileRegistry().getProfile(name),\n\t\t);\n\t\tif (linkedProfiles.some((linked) => linked === undefined)) {\n\t\t\treturn { ok: false, reason: \"orchestration_resource_profile_not_found\" };\n\t\t}\n\t\tconst soul = linkedProfiles\n\t\t\t.flatMap((linked) => (linked?.soul ? [linked.soul] : []))\n\t\t\t.join(\"\\n\\n\")\n\t\t\t.trim();\n\t\tconst resourcePointers = catalogWorkerResourcePointers({\n\t\t\tcwd: this.options.cwd,\n\t\t\tresourceLoader: this.options.getResourceLoader(),\n\t\t\tresourceProfiles: linkedProfiles.filter(\n\t\t\t\t(linked): linked is NonNullable<typeof linked> => linked !== undefined,\n\t\t\t),\n\t\t});\n\t\treturn {\n\t\t\tok: true,\n\t\t\tresolved: {\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile,\n\t\t\t\tresourcePointers,\n\t\t\t\t...(soul ? { soul } : {}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate isProfileAuthorized(profileId: string, loaded: LoadedWorkerProfiles): boolean {\n\t\tconst activeProfile = this.options.getActiveOrchestrationProfile();\n\t\tconst taskRecord = loaded.taskRegistry.get(profileId);\n\t\tif (taskRecord) {\n\t\t\treturn (\n\t\t\t\t!activeProfile ||\n\t\t\t\t(activeProfile.role === \"orchestrator\" &&\n\t\t\t\t\ttaskRecord.authorProfileId === activeProfile.profileId &&\n\t\t\t\t\tactiveProfile.dispatchProfileIds.includes(taskRecord.baseProfileId))\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\t!activeProfile ||\n\t\t\t(activeProfile.role === \"orchestrator\" && activeProfile.dispatchProfileIds.includes(profileId))\n\t\t);\n\t}\n\n\tprivate loadProfiles(): LoadedWorkerProfiles {\n\t\tconst loaded = new OrchestrationProfileStore({\n\t\t\tagentDir: this.options.agentDir,\n\t\t\tcwd: this.options.cwd,\n\t\t\tprojectTrusted: this.options.getSettingsManager().isProjectTrusted(),\n\t\t}).load();\n\t\tfor (const diagnostic of loaded.diagnostics) {\n\t\t\tconst key = `${diagnostic.path}\\0${diagnostic.message}`;\n\t\t\tif (this.warnedDiagnostics.has(key)) continue;\n\t\t\tthis.warnedDiagnostics.add(key);\n\t\t\tthis.options.onDiagnostic(`Orchestration profile ignored (${diagnostic.path}): ${diagnostic.message}`);\n\t\t}\n\t\tconst taskProfiles = this.options.getTaskProfileStore().load();\n\t\tfor (const diagnostic of taskProfiles.diagnostics) {\n\t\t\tconst key = `session\\0${diagnostic}`;\n\t\t\tif (this.warnedDiagnostics.has(key)) continue;\n\t\t\tthis.warnedDiagnostics.add(key);\n\t\t\tthis.options.onDiagnostic(`Session task profile ignored: ${diagnostic}`);\n\t\t}\n\t\tconst profiles = [...loaded.profiles];\n\t\tconst registry = new Map(loaded.profiles.map((profile) => [profile.profileId, profile]));\n\t\tconst taskRegistry = new Map<string, SessionTaskProfileRecord>();\n\t\tfor (const record of taskProfiles.records) {\n\t\t\tif (registry.has(record.profile.profileId)) continue;\n\t\t\tprofiles.push(record.profile);\n\t\t\tregistry.set(record.profile.profileId, record.profile);\n\t\t\ttaskRegistry.set(record.profile.profileId, record);\n\t\t}\n\t\treturn { profiles, registry, taskRegistry };\n\t}\n}\n"]}
@@ -45,7 +45,7 @@ export interface DoctorDeps {
45
45
  loadAvailableFffNodePackage: () => unknown | undefined;
46
46
  ensureFffNodePackage: (silent?: boolean) => Promise<unknown | undefined>;
47
47
  getLastFffInstallOutcome: () => FffInstallOutcome | undefined;
48
- ensureTool: (tool: "jq" | "rg", silent: boolean) => Promise<string | undefined>;
48
+ ensureTool: (tool: "jq" | "jscpd" | "rg", silent: boolean) => Promise<string | undefined>;
49
49
  ensurePythonRuntime: (options: {
50
50
  silent: boolean;
51
51
  }) => Promise<PythonRuntimeOutcome>;
@@ -1 +1 @@
1
- {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/core/doctor.ts"],"names":[],"mappings":"AAEA,OAAO,EAGN,KAAK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AAC;IACnC,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;CAC9D;AAED,MAAM,WAAW,gBAAgB;IAChC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAsJD,wBAAsB,SAAS,CAC9B,IAAI,GAAE,UAA2B,EACjC,OAAO,GAAE,gBAAqB,GAC5B,OAAO,CAAC,YAAY,CAAC,CAWvB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAc/D;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,GAAE,UAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAOzF"}
@@ -55,8 +55,8 @@ async function checkFffNode(deps, silent) {
55
55
  /** MANAGED tools: exact releases and checksums are owned by tools-manager. */
56
56
  async function checkManagedDataTool(deps, tool, silent) {
57
57
  const path = await deps.ensureTool(tool, silent);
58
- const id = tool === "rg" ? "ripgrep" : "jq";
59
- const label = tool === "rg" ? "ripgrep (rg)" : "jq (JSON projection)";
58
+ const id = tool === "rg" ? "ripgrep" : tool;
59
+ const label = tool === "rg" ? "ripgrep (rg)" : tool === "jscpd" ? "jscpd v5 (clone scanner)" : "jq (JSON projection)";
60
60
  if (!path)
61
61
  return { id, label, kind: "managed", present: false, detail: "managed install unavailable" };
62
62
  const version = firstLine(deps.probeVersion(path));
@@ -142,14 +142,15 @@ function checkAgentDirectoryLayout(deps) {
142
142
  }
143
143
  export async function runDoctor(deps = realDoctorDeps, options = {}) {
144
144
  const silent = options.silent ?? true;
145
- const [fffNode, ripgrep, jq, ollama, python] = await Promise.all([
145
+ const [fffNode, ripgrep, jq, jscpd, ollama, python] = await Promise.all([
146
146
  checkFffNode(deps, silent),
147
147
  checkManagedDataTool(deps, "rg", silent),
148
148
  checkManagedDataTool(deps, "jq", silent),
149
+ checkManagedDataTool(deps, "jscpd", silent),
149
150
  checkOllama(deps),
150
151
  checkPython(deps, silent),
151
152
  ]);
152
- return { checks: [fffNode, ripgrep, jq, ollama, python], notices: checkAgentDirectoryLayout(deps) };
153
+ return { checks: [fffNode, ripgrep, jq, jscpd, ollama, python], notices: checkAgentDirectoryLayout(deps) };
153
154
  }
154
155
  export function formatDoctorReport(report) {
155
156
  const lines = [];
@@ -1 +1 @@
1
- {"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/core/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACN,oBAAoB,EACpB,UAAU,EAEV,wBAAwB,EACxB,2BAA2B,EAC3B,YAAY,GACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAmC,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC3G,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAA6B,MAAM,qBAAqB,CAAC;AAqErF,MAAM,cAAc,GAAe;IAClC,2BAA2B;IAC3B,oBAAoB;IACpB,wBAAwB;IACxB,UAAU;IACV,mBAAmB;IACnB,YAAY;IACZ,aAAa,EAAE,IAAI,aAAa,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,CAAC;IAC7D,2BAA2B,EAAE,GAAG,EAAE,CAAC,2BAA2B,CAAC,WAAW,EAAE,CAAC;CAC7E,CAAC;AAEF,SAAS,kBAAkB,CAAC,OAAsC;IACjE,QAAQ,OAAO,EAAE,MAAM,EAAE,CAAC;QACzB,KAAK,mBAAmB;YACvB,OAAO,mBAAmB,CAAC;QAC5B,KAAK,WAAW;YACf,OAAO,oBAAoB,CAAC;QAC7B,KAAK,SAAS;YACb,OAAO,+BAA+B,CAAC;QACxC,KAAK,sBAAsB;YAC1B,OAAO,mCAAmC,CAAC;QAC5C,KAAK,gBAAgB;YACpB,OAAO,mBAAmB,OAAO,CAAC,MAAM,EAAE,CAAC;QAC5C;YACC,OAAO,aAAa,CAAC;I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AAC,KAAK,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAI,GAAe,cAAc;IACzE,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,KAAK,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAClH,CAAC;AACF,CAAC","sourcesContent":["import chalk from \"chalk\";\nimport { getAgentDir } from \"../config.ts\";\nimport {\n\tensureFffNodePackage,\n\tensureTool,\n\ttype FffInstallOutcome,\n\tgetLastFffInstallOutcome,\n\tloadAvailableFffNodePackage,\n\tprobeVersion,\n} from \"../utils/tools-manager.ts\";\nimport { type AgentDirectoryLayoutReport, inspectAgentDirectoryLayout } from \"./agent-directory-layout.ts\";\nimport { OllamaRuntime } from \"./models/local-runtime.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"./python-runtime.ts\";\n\n/**\n * Environment doctor: verifies required tooling and installs what it safely\n * can, instead of leaving provisioning entirely to lazy first-use (the exact\n * gap behind \"ran `pi-adaptative update` on another machine and fff-node\n * never got installed\" -- see fff-lazy-install.test.ts/fff-search-tools.test.ts\n * for the underlying lazy-install fix; this module is the proactive half).\n *\n * Two tool kinds, two different postures:\n * - \"managed\": pi owns provisioning and attempts it when absent (fff-node,\n * pinned rg/jq/uv, and the Python interpreter resolved through uv).\n * - \"system\": pi does not own the install (Ollama). GUIDE MODE only -- exact\n * manual steps are reported, never executed.\n */\n\nexport type DoctorToolKind = \"managed\" | \"system\";\n\nexport interface DoctorCheck {\n\t/** Stable identifier, e.g. \"fff-node\", \"ripgrep\", \"jq\", \"ollama\", \"python\". */\n\tid: string;\n\t/** Human-readable label for the report. */\n\tlabel: string;\n\tkind: DoctorToolKind;\n\tpresent: boolean;\n\t/** Version/path/status summary, present or not. */\n\tdetail?: string;\n\t/** Only set for a \"managed\" tool: whether an install was just attempted. */\n\tinstallAttempted?: boolean;\n\t/** Only set for a \"system\" tool that's missing: exact manual steps, never executed. */\n\tguide?: string[];\n}\n\nexport interface DoctorReport {\n\tchecks: DoctorCheck[];\n\tnotices?: DoctorNotice[];\n}\n\nexport interface DoctorNotice {\n\tid: string;\n\tlabel: string;\n\tdetail: string;\n}\n\n/** Minimal slice of OllamaRuntime the doctor needs -- lets tests inject a fake without touching the real runtime. */\nexport type DoctorOllamaRuntime = Pick<OllamaRuntime, \"detect\" | \"installGuide\">;\n\nexport interface DoctorDeps {\n\tloadAvailableFffNodePackage: () => unknown | undefined;\n\tensureFffNodePackage: (silent?: boolean) => Promise<unknown | undefined>;\n\tgetLastFffInstallOutcome: () => FffInstallOutcome | undefined;\n\tensureTool: (tool: \"jq\" | \"rg\", silent: boolean) => Promise<string | undefined>;\n\tensurePythonRuntime: (options: { silent: boolean }) => Promise<PythonRuntimeOutcome>;\n\t/** Best-effort `<command> --version` probe; undefined if it can't be run. Used only to enrich a status line, never for presence detection. */\n\tprobeVersion: (command: string, versionArgs?: readonly string[]) => string | undefined;\n\tollamaRuntime: DoctorOllamaRuntime;\n\tinspectAgentDirectoryLayout: () => AgentDirectoryLayoutReport;\n}\n\nexport interface RunDoctorOptions {\n\t/**\n\t * Whether the fff-node managed install (if one is attempted) stays quiet.\n\t * Default true, matching runUpdatePreflight's existing background\n\t * behavior. The interactive `doctor` command passes `false` so a\n\t * multi-second install doesn't read as a silent hang.\n\t */\n\tsilent?: boolean;\n}\n\nconst realDoctorDeps: DoctorDeps = {\n\tloadAvailableFffNodePackage,\n\tensureFffNodePackage,\n\tgetLastFffInstallOutcome,\n\tensureTool,\n\tensurePythonRuntime,\n\tprobeVersion,\n\tollamaRuntime: new OllamaRuntime({ agentDir: getAgentDir() }),\n\tinspectAgentDirectoryLayout: () => inspectAgentDirectoryLayout(getAgentDir()),\n};\n\nfunction describeFffOutcome(outcome: FffInstallOutcome | undefined): string {\n\tswitch (outcome?.status) {\n\t\tcase \"already-available\":\n\t\t\treturn \"already available\";\n\t\tcase \"installed\":\n\t\t\treturn \"installed just now\";\n\t\tcase \"offline\":\n\t\t\treturn \"offline mode enabled, skipped\";\n\t\tcase \"unsupported-platform\":\n\t\t\treturn \"no native build for this platform\";\n\t\tcase \"install-failed\":\n\t\t\treturn `install failed: ${outcome.reason}`;\n\t\tdefault:\n\t\t\treturn \"unavailable\";\n\t}\n}\n\n/** First line only -- a compiled-features/build-flags tail (e.g. rg --version) is noise in a one-line status report. */\nfunction firstLine(text: string | undefined): string | undefined {\n\treturn text?.split(\"\\n\")[0];\n}\n\n/** MANAGED tool: pi owns this install path, so the doctor actually attempts it when missing. */\nasync function checkFffNode(deps: DoctorDeps, silent: boolean): Promise<DoctorCheck> {\n\t// Delegate entirely to ensureFffNodePackage rather than re-deriving \"is it\n\t// already there\" here: that function (and its offline/unsupported-platform/\n\t// cooldown handling, see tools-manager.ts) is the single source of truth for\n\t// whether an install should even be attempted -- the doctor must not\n\t// duplicate or second-guess that logic, only report its outcome honestly.\n\tconst installed = await deps.ensureFffNodePackage(silent);\n\tconst outcome = deps.getLastFffInstallOutcome();\n\treturn {\n\t\tid: \"fff-node\",\n\t\tlabel: \"FFF native search (@ff-labs/fff-node)\",\n\t\tkind: \"managed\",\n\t\tpresent: Boolean(installed),\n\t\tinstallAttempted: outcome !== undefined && outcome.status !== \"already-available\",\n\t\tdetail: describeFffOutcome(outcome),\n\t};\n}\n\n/** MANAGED tools: exact releases and checksums are owned by tools-manager. */\nasync function checkManagedDataTool(deps: DoctorDeps, tool: \"jq\" | \"rg\", silent: boolean): Promise<DoctorCheck> {\n\tconst path = await deps.ensureTool(tool, silent);\n\tconst id = tool === \"rg\" ? \"ripgrep\" : \"jq\";\n\tconst label = tool === \"rg\" ? \"ripgrep (rg)\" : \"jq (JSON projection)\";\n\tif (!path) return { id, label, kind: \"managed\", present: false, detail: \"managed install unavailable\" };\n\tconst version = firstLine(deps.probeVersion(path));\n\treturn {\n\t\tid,\n\t\tlabel,\n\t\tkind: \"managed\",\n\t\tpresent: true,\n\t\tdetail: version ? `${path} (${version})` : path,\n\t};\n}\n\n/** SYSTEM tool: guide mode only, never installed by the doctor (OllamaRuntime.installGuide() is itself already guide-mode-only). */\nasync function checkOllama(deps: DoctorDeps): Promise<DoctorCheck> {\n\tconst status = await deps.ollamaRuntime.detect();\n\tif (!status.binaryPath) {\n\t\treturn {\n\t\t\tid: \"ollama\",\n\t\t\tlabel: \"Ollama (local model runtime)\",\n\t\t\tkind: \"system\",\n\t\t\tpresent: false,\n\t\t\tguide: deps.ollamaRuntime.installGuide(),\n\t\t};\n\t}\n\tconst version = firstLine(deps.probeVersion(status.binaryPath));\n\tconst versionSuffix = version ? `, ${version}` : \"\";\n\tconst activeStore = status.activeStore\n\t\t? `${status.activeStore.path} [${status.activeStore.kind}, ${status.activeStore.modelCount} model(s)]`\n\t\t: `none; pi-owned store ${status.ownedModelsDir} has ${status.ownedStore.modelCount} model(s)`;\n\treturn {\n\t\tid: \"ollama\",\n\t\tlabel: \"Ollama (local model runtime)\",\n\t\tkind: \"system\",\n\t\tpresent: true,\n\t\tdetail: `binary: ${status.binaryPath} [${status.binarySource}]${versionSuffix}; server: ${status.serverUp ? \"up\" : \"down\"} at ${status.serverUrl}; active store: ${activeStore}`,\n\t};\n}\n\n/** MANAGED tool: uv and Python share one deduplicated runtime manager with bounded provisioning. */\nasync function checkPython(deps: DoctorDeps, silent: boolean): Promise<DoctorCheck> {\n\tconst outcome = await deps.ensurePythonRuntime({ silent });\n\tif (outcome.status !== \"ready\") {\n\t\treturn {\n\t\t\tid: \"python\",\n\t\t\tlabel: \"Python (uv-managed)\",\n\t\t\tkind: \"managed\",\n\t\t\tpresent: false,\n\t\t\tdetail: outcome.reason,\n\t\t};\n\t}\n\treturn {\n\t\tid: \"python\",\n\t\tlabel: \"Python (uv-managed)\",\n\t\tkind: \"managed\",\n\t\tpresent: true,\n\t\tinstallAttempted: outcome.pythonInstalled,\n\t\tdetail: `uv: ${outcome.uvPath}; python: ${outcome.pythonPath}${outcome.pythonInstalled ? \" (installed just now)\" : \"\"}`,\n\t};\n}\n\nfunction checkAgentDirectoryLayout(deps: DoctorDeps): DoctorNotice[] {\n\tconst report = deps.inspectAgentDirectoryLayout();\n\tif (report.error) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tid: \"agent-directory-layout\",\n\t\t\t\tlabel: \"Agent directory layout\",\n\t\t\t\tdetail: `could not inspect ${report.agentDir}: ${report.error}`,\n\t\t\t},\n\t\t];\n\t}\n\tif (report.unexpectedEntryCount === 0 && !report.truncated) return [];\n\n\tconst listed = report.unexpectedEntries.join(\", \");\n\tconst omitted = report.unexpectedEntryCount - report.unexpectedEntries.length;\n\tconst count = report.truncated ? `at least ${report.unexpectedEntryCount}` : String(report.unexpectedEntryCount);\n\tconst listing = listed ? `: ${listed}${omitted > 0 ? ` (+${omitted} more)` : \"\"}` : \"\";\n\tconst truncation = report.truncated ? `; scan stopped after ${report.scannedEntries} entries` : \"\";\n\treturn [\n\t\t{\n\t\t\tid: \"agent-directory-layout\",\n\t\t\tlabel: \"Agent directory layout\",\n\t\t\tdetail: `${count} unexpected root entr${report.unexpectedEntryCount === 1 ? \"y\" : \"ies\"}${listing}${truncation}. Extension data belongs under state/extensions, cache/extensions, or leased work/extensions`,\n\t\t},\n\t];\n}\n\nexport async function runDoctor(\n\tdeps: DoctorDeps = realDoctorDeps,\n\toptions: RunDoctorOptions = {},\n): Promise<DoctorReport> {\n\tconst silent = options.silent ?? true;\n\tconst [fffNode, ripgrep, jq, ollama, python] = await Promise.all([\n\t\tcheckFffNode(deps, silent),\n\t\tcheckManagedDataTool(deps, \"rg\", silent),\n\t\tcheckManagedDataTool(deps, \"jq\", silent),\n\t\tcheckOllama(deps),\n\t\tcheckPython(deps, silent),\n\t]);\n\treturn { checks: [fffNode, ripgrep, jq, ollama, python], notices: checkAgentDirectoryLayout(deps) };\n}\n\nexport function formatDoctorReport(report: DoctorReport): string {\n\tconst lines: string[] = [];\n\tfor (const check of report.checks) {\n\t\tconst status = check.present ? chalk.green(\"[OK]\") : chalk.yellow(\"[MISSING]\");\n\t\tconst detail = check.detail ? ` -- ${check.detail}` : \"\";\n\t\tlines.push(`${status} ${check.label}${detail}`);\n\t\tif (!check.present && check.guide) {\n\t\t\tfor (const guideLine of check.guide) lines.push(` ${guideLine}`);\n\t\t}\n\t}\n\tfor (const notice of report.notices ?? []) {\n\t\tlines.push(`${chalk.yellow(\"[WARN]\")} ${notice.label} -- ${notice.detail}`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Best-effort preflight meant to be called right after `pi-adaptative update`\n * succeeds. Must never fail the update itself: any error here is swallowed\n * and reported as a skipped check, not surfaced as an update failure.\n */\nexport async function runUpdatePreflight(deps: DoctorDeps = realDoctorDeps): Promise<void> {\n\ttry {\n\t\tconst report = await runDoctor(deps);\n\t\tconsole.log(`\\n${formatDoctorReport(report)}\\n`);\n\t} catch (error) {\n\t\tconsole.log(chalk.dim(`(environment check skipped: ${error instanceof Error ? error.message : String(error)})`));\n\t}\n}\n"]}
1
+ {"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/core/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EACN,oBAAoB,EACpB,UAAU,EAEV,wBAAwB,EACxB,2BAA2B,EAC3B,YAAY,GACZ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,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,KAAK,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,+BAA+B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAClH,CAAC;AACF,CAAC","sourcesContent":["import chalk from \"chalk\";\nimport { getAgentDir } from \"../config.ts\";\nimport {\n\tensureFffNodePackage,\n\tensureTool,\n\ttype FffInstallOutcome,\n\tgetLastFffInstallOutcome,\n\tloadAvailableFffNodePackage,\n\tprobeVersion,\n} from \"../utils/tools-manager.ts\";\nimport { type AgentDirectoryLayoutReport, inspectAgentDirectoryLayout } from \"./agent-directory-layout.ts\";\nimport { OllamaRuntime } from \"./models/local-runtime.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"./python-runtime.ts\";\n\n/**\n * Environment doctor: verifies required tooling and installs what it safely\n * can, instead of leaving provisioning entirely to lazy first-use (the exact\n * gap behind \"ran `pi-adaptative update` on another machine and fff-node\n * never got installed\" -- see fff-lazy-install.test.ts/fff-search-tools.test.ts\n * for the underlying lazy-install fix; this module is the proactive half).\n *\n * Two tool kinds, two different postures:\n * - \"managed\": pi owns provisioning and attempts it when absent (fff-node,\n * pinned rg/jq/uv, and the Python interpreter resolved through uv).\n * - \"system\": pi does not own the install (Ollama). GUIDE MODE only -- exact\n * manual steps are reported, never executed.\n */\n\nexport type DoctorToolKind = \"managed\" | \"system\";\n\nexport interface DoctorCheck {\n\t/** Stable identifier, e.g. \"fff-node\", \"ripgrep\", \"jq\", \"ollama\", \"python\". */\n\tid: string;\n\t/** Human-readable label for the report. */\n\tlabel: string;\n\tkind: DoctorToolKind;\n\tpresent: boolean;\n\t/** Version/path/status summary, present or not. */\n\tdetail?: string;\n\t/** Only set for a \"managed\" tool: whether an install was just attempted. */\n\tinstallAttempted?: boolean;\n\t/** Only set for a \"system\" tool that's missing: exact manual steps, never executed. */\n\tguide?: string[];\n}\n\nexport interface DoctorReport {\n\tchecks: DoctorCheck[];\n\tnotices?: DoctorNotice[];\n}\n\nexport interface DoctorNotice {\n\tid: string;\n\tlabel: string;\n\tdetail: string;\n}\n\n/** Minimal slice of OllamaRuntime the doctor needs -- lets tests inject a fake without touching the real runtime. */\nexport type DoctorOllamaRuntime = Pick<OllamaRuntime, \"detect\" | \"installGuide\">;\n\nexport interface DoctorDeps {\n\tloadAvailableFffNodePackage: () => unknown | undefined;\n\tensureFffNodePackage: (silent?: boolean) => Promise<unknown | undefined>;\n\tgetLastFffInstallOutcome: () => FffInstallOutcome | undefined;\n\tensureTool: (tool: \"jq\" | \"jscpd\" | \"rg\", silent: boolean) => Promise<string | undefined>;\n\tensurePythonRuntime: (options: { silent: boolean }) => Promise<PythonRuntimeOutcome>;\n\t/** Best-effort `<command> --version` probe; undefined if it can't be run. Used only to enrich a status line, never for presence detection. */\n\tprobeVersion: (command: string, versionArgs?: readonly string[]) => string | undefined;\n\tollamaRuntime: DoctorOllamaRuntime;\n\tinspectAgentDirectoryLayout: () => AgentDirectoryLayoutReport;\n}\n\nexport interface RunDoctorOptions {\n\t/**\n\t * Whether the fff-node managed install (if one is attempted) stays quiet.\n\t * Default true, matching runUpdatePreflight's existing background\n\t * behavior. The interactive `doctor` command passes `false` so a\n\t * multi-second install doesn't read as a silent hang.\n\t */\n\tsilent?: boolean;\n}\n\nconst realDoctorDeps: DoctorDeps = {\n\tloadAvailableFffNodePackage,\n\tensureFffNodePackage,\n\tgetLastFffInstallOutcome,\n\tensureTool,\n\tensurePythonRuntime,\n\tprobeVersion,\n\tollamaRuntime: new OllamaRuntime({ agentDir: getAgentDir() }),\n\tinspectAgentDirectoryLayout: () => inspectAgentDirectoryLayout(getAgentDir()),\n};\n\nfunction describeFffOutcome(outcome: FffInstallOutcome | undefined): string {\n\tswitch (outcome?.status) {\n\t\tcase \"already-available\":\n\t\t\treturn \"already available\";\n\t\tcase \"installed\":\n\t\t\treturn \"installed just now\";\n\t\tcase \"offline\":\n\t\t\treturn \"offline mode enabled, skipped\";\n\t\tcase \"unsupported-platform\":\n\t\t\treturn \"no native build for this platform\";\n\t\tcase \"install-failed\":\n\t\t\treturn `install failed: ${outcome.reason}`;\n\t\tdefault:\n\t\t\treturn \"unavailable\";\n\t}\n}\n\n/** First line only -- a compiled-features/build-flags tail (e.g. rg --version) is noise in a one-line status report. */\nfunction firstLine(text: string | undefined): string | undefined {\n\treturn text?.split(\"\\n\")[0];\n}\n\n/** MANAGED tool: pi owns this install path, so the doctor actually attempts it when missing. */\nasync function checkFffNode(deps: DoctorDeps, silent: boolean): Promise<DoctorCheck> {\n\t// Delegate entirely to ensureFffNodePackage rather than re-deriving \"is it\n\t// already there\" here: that function (and its offline/unsupported-platform/\n\t// cooldown handling, see tools-manager.ts) is the single source of truth for\n\t// whether an install should even be attempted -- the doctor must not\n\t// duplicate or second-guess that logic, only report its outcome honestly.\n\tconst installed = await deps.ensureFffNodePackage(silent);\n\tconst outcome = deps.getLastFffInstallOutcome();\n\treturn {\n\t\tid: \"fff-node\",\n\t\tlabel: \"FFF native search (@ff-labs/fff-node)\",\n\t\tkind: \"managed\",\n\t\tpresent: Boolean(installed),\n\t\tinstallAttempted: outcome !== undefined && outcome.status !== \"already-available\",\n\t\tdetail: describeFffOutcome(outcome),\n\t};\n}\n\n/** MANAGED tools: exact releases and checksums are owned by tools-manager. */\nasync function checkManagedDataTool(\n\tdeps: DoctorDeps,\n\ttool: \"jq\" | \"jscpd\" | \"rg\",\n\tsilent: boolean,\n): Promise<DoctorCheck> {\n\tconst path = await deps.ensureTool(tool, silent);\n\tconst id = tool === \"rg\" ? \"ripgrep\" : tool;\n\tconst label =\n\t\ttool === \"rg\" ? \"ripgrep (rg)\" : tool === \"jscpd\" ? \"jscpd v5 (clone scanner)\" : \"jq (JSON projection)\";\n\tif (!path) return { id, label, kind: \"managed\", present: false, detail: \"managed install unavailable\" };\n\tconst version = firstLine(deps.probeVersion(path));\n\treturn {\n\t\tid,\n\t\tlabel,\n\t\tkind: \"managed\",\n\t\tpresent: true,\n\t\tdetail: version ? `${path} (${version})` : path,\n\t};\n}\n\n/** SYSTEM tool: guide mode only, never installed by the doctor (OllamaRuntime.installGuide() is itself already guide-mode-only). */\nasync function checkOllama(deps: DoctorDeps): Promise<DoctorCheck> {\n\tconst status = await deps.ollamaRuntime.detect();\n\tif (!status.binaryPath) {\n\t\treturn {\n\t\t\tid: \"ollama\",\n\t\t\tlabel: \"Ollama (local model runtime)\",\n\t\t\tkind: \"system\",\n\t\t\tpresent: false,\n\t\t\tguide: deps.ollamaRuntime.installGuide(),\n\t\t};\n\t}\n\tconst version = firstLine(deps.probeVersion(status.binaryPath));\n\tconst versionSuffix = version ? `, ${version}` : \"\";\n\tconst activeStore = status.activeStore\n\t\t? `${status.activeStore.path} [${status.activeStore.kind}, ${status.activeStore.modelCount} model(s)]`\n\t\t: `none; pi-owned store ${status.ownedModelsDir} has ${status.ownedStore.modelCount} model(s)`;\n\treturn {\n\t\tid: \"ollama\",\n\t\tlabel: \"Ollama (local model runtime)\",\n\t\tkind: \"system\",\n\t\tpresent: true,\n\t\tdetail: `binary: ${status.binaryPath} [${status.binarySource}]${versionSuffix}; server: ${status.serverUp ? \"up\" : \"down\"} at ${status.serverUrl}; active store: ${activeStore}`,\n\t};\n}\n\n/** MANAGED tool: uv and Python share one deduplicated runtime manager with bounded provisioning. */\nasync function checkPython(deps: DoctorDeps, silent: boolean): Promise<DoctorCheck> {\n\tconst outcome = await deps.ensurePythonRuntime({ silent });\n\tif (outcome.status !== \"ready\") {\n\t\treturn {\n\t\t\tid: \"python\",\n\t\t\tlabel: \"Python (uv-managed)\",\n\t\t\tkind: \"managed\",\n\t\t\tpresent: false,\n\t\t\tdetail: outcome.reason,\n\t\t};\n\t}\n\treturn {\n\t\tid: \"python\",\n\t\tlabel: \"Python (uv-managed)\",\n\t\tkind: \"managed\",\n\t\tpresent: true,\n\t\tinstallAttempted: outcome.pythonInstalled,\n\t\tdetail: `uv: ${outcome.uvPath}; python: ${outcome.pythonPath}${outcome.pythonInstalled ? \" (installed just now)\" : \"\"}`,\n\t};\n}\n\nfunction checkAgentDirectoryLayout(deps: DoctorDeps): DoctorNotice[] {\n\tconst report = deps.inspectAgentDirectoryLayout();\n\tif (report.error) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tid: \"agent-directory-layout\",\n\t\t\t\tlabel: \"Agent directory layout\",\n\t\t\t\tdetail: `could not inspect ${report.agentDir}: ${report.error}`,\n\t\t\t},\n\t\t];\n\t}\n\tif (report.unexpectedEntryCount === 0 && !report.truncated) return [];\n\n\tconst listed = report.unexpectedEntries.join(\", \");\n\tconst omitted = report.unexpectedEntryCount - report.unexpectedEntries.length;\n\tconst count = report.truncated ? `at least ${report.unexpectedEntryCount}` : String(report.unexpectedEntryCount);\n\tconst listing = listed ? `: ${listed}${omitted > 0 ? ` (+${omitted} more)` : \"\"}` : \"\";\n\tconst truncation = report.truncated ? `; scan stopped after ${report.scannedEntries} entries` : \"\";\n\treturn [\n\t\t{\n\t\t\tid: \"agent-directory-layout\",\n\t\t\tlabel: \"Agent directory layout\",\n\t\t\tdetail: `${count} unexpected root entr${report.unexpectedEntryCount === 1 ? \"y\" : \"ies\"}${listing}${truncation}. Extension data belongs under state/extensions, cache/extensions, or leased work/extensions`,\n\t\t},\n\t];\n}\n\nexport async function runDoctor(\n\tdeps: DoctorDeps = realDoctorDeps,\n\toptions: RunDoctorOptions = {},\n): Promise<DoctorReport> {\n\tconst silent = options.silent ?? true;\n\tconst [fffNode, ripgrep, jq, jscpd, ollama, python] = await Promise.all([\n\t\tcheckFffNode(deps, silent),\n\t\tcheckManagedDataTool(deps, \"rg\", silent),\n\t\tcheckManagedDataTool(deps, \"jq\", silent),\n\t\tcheckManagedDataTool(deps, \"jscpd\", silent),\n\t\tcheckOllama(deps),\n\t\tcheckPython(deps, silent),\n\t]);\n\treturn { checks: [fffNode, ripgrep, jq, jscpd, ollama, python], notices: checkAgentDirectoryLayout(deps) };\n}\n\nexport function formatDoctorReport(report: DoctorReport): string {\n\tconst lines: string[] = [];\n\tfor (const check of report.checks) {\n\t\tconst status = check.present ? chalk.green(\"[OK]\") : chalk.yellow(\"[MISSING]\");\n\t\tconst detail = check.detail ? ` -- ${check.detail}` : \"\";\n\t\tlines.push(`${status} ${check.label}${detail}`);\n\t\tif (!check.present && check.guide) {\n\t\t\tfor (const guideLine of check.guide) lines.push(` ${guideLine}`);\n\t\t}\n\t}\n\tfor (const notice of report.notices ?? []) {\n\t\tlines.push(`${chalk.yellow(\"[WARN]\")} ${notice.label} -- ${notice.detail}`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n\n/**\n * Best-effort preflight meant to be called right after `pi-adaptative update`\n * succeeds. Must never fail the update itself: any error here is swallowed\n * and reported as a skipped check, not surfaced as an update failure.\n */\nexport async function runUpdatePreflight(deps: DoctorDeps = realDoctorDeps): Promise<void> {\n\ttry {\n\t\tconst report = await runDoctor(deps);\n\t\tconsole.log(`\\n${formatDoctorReport(report)}\\n`);\n\t} catch (error) {\n\t\tconsole.log(chalk.dim(`(environment check skipped: ${error instanceof Error ? error.message : String(error)})`));\n\t}\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { ClassifiedError } from "@caupulican/pi-agent-core";
2
+ import type { ToolFailurePhase } from "@caupulican/pi-ai/tool-repair-registry";
2
3
  export interface ProviderFailureCorpusRecord {
3
4
  ts: string;
4
5
  provider?: string;
@@ -23,7 +24,19 @@ export interface ToolValidationFailureCorpusRecord {
23
24
  shape: ToolValidationFailureShapeEntry[];
24
25
  errorKeywords: string[];
25
26
  }
26
- export type FailureCorpusRecord = ProviderFailureCorpusRecord | ToolValidationFailureCorpusRecord;
27
+ export interface ToolExecutionFailureCorpusRecord {
28
+ kind: "tool_execution";
29
+ ts: string;
30
+ provider?: string;
31
+ modelId?: string;
32
+ tool: string;
33
+ state: "failed" | "rejected";
34
+ phase: ToolFailurePhase;
35
+ failureCode: string;
36
+ diagnostic?: string;
37
+ nextAction: string;
38
+ }
39
+ export type FailureCorpusRecord = ProviderFailureCorpusRecord | ToolValidationFailureCorpusRecord | ToolExecutionFailureCorpusRecord;
27
40
  export interface FailureCorpusStats {
28
41
  total: number;
29
42
  unknown: number;
@@ -37,6 +50,17 @@ export declare function createToolValidationFailureCorpusRecord(args: {
37
50
  errorKeywords?: readonly string[];
38
51
  ts: string;
39
52
  }): ToolValidationFailureCorpusRecord;
53
+ export declare function createToolExecutionFailureCorpusRecord(args: {
54
+ provider?: string;
55
+ modelId?: string;
56
+ tool: string;
57
+ state: "failed" | "rejected";
58
+ phase: ToolFailurePhase;
59
+ failureCode: string;
60
+ diagnostic?: string;
61
+ nextAction: string;
62
+ ts: string;
63
+ }): ToolExecutionFailureCorpusRecord;
40
64
  export declare function writeFailureCorpusRecord(filePath: string, record: FailureCorpusRecord): void;
41
65
  export declare class FailureCorpusRecorder {
42
66
  private total;
@@ -63,6 +87,7 @@ export declare class FailureCorpusRecorder {
63
87
  shape: readonly ToolValidationFailureShapeEntry[];
64
88
  errorKeywords?: readonly string[];
65
89
  }): void;
90
+ recordToolExecution(args: Omit<Parameters<typeof createToolExecutionFailureCorpusRecord>[0], "ts">): void;
66
91
  stats(): FailureCorpusStats;
67
92
  private appendRecord;
68
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"failure-corpus.d.ts","sourceRoot":"","sources":["../../src/core/failure-corpus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAIjE,MAAM,WAAW,2BAA2B;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,eAAe,CAAC,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AE,GAAG,IAAI,CAWxG;IAED,oBAAoB,CAAC,IAAI,EAAE;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;QAChC,KAAK,EAAE,SAAS,+BAA+B,EAAE,CAAC;QAClD,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;KAClC,GAAG,IAAI,CAEP;IAED,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,sCAAsC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,IAAI,CAExG;IAED,KAAK,IAAI,kBAAkB,CAE1B;IAED,OAAO,CAAC,YAAY;CAOpB;AAaD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD"}
@@ -26,6 +26,20 @@ export function createToolValidationFailureCorpusRecord(args) {
26
26
  .map((value) => value.slice(0, MAX_DETAIL_CHARS)),
27
27
  };
28
28
  }
29
+ export function createToolExecutionFailureCorpusRecord(args) {
30
+ return {
31
+ kind: "tool_execution",
32
+ ts: args.ts,
33
+ provider: args.provider?.slice(0, MAX_DETAIL_CHARS),
34
+ modelId: args.modelId?.slice(0, MAX_DETAIL_CHARS),
35
+ tool: args.tool.slice(0, MAX_DETAIL_CHARS),
36
+ state: args.state,
37
+ phase: args.phase,
38
+ failureCode: args.failureCode.slice(0, MAX_DETAIL_CHARS),
39
+ ...(args.diagnostic ? { diagnostic: redactSecrets(args.diagnostic).slice(0, MAX_DETAIL_CHARS) } : {}),
40
+ nextAction: redactSecrets(args.nextAction).slice(0, MAX_DETAIL_CHARS),
41
+ };
42
+ }
29
43
  export function writeFailureCorpusRecord(filePath, record) {
30
44
  appendBoundedJsonLineSync(filePath, record, FAILURE_CORPUS_LIMITS);
31
45
  }
@@ -53,6 +67,9 @@ export class FailureCorpusRecorder {
53
67
  recordToolValidation(args) {
54
68
  this.appendRecord(createToolValidationFailureCorpusRecord({ ...args, ts: this.now().toISOString() }));
55
69
  }
70
+ recordToolExecution(args) {
71
+ this.appendRecord(createToolExecutionFailureCorpusRecord({ ...args, ts: this.now().toISOString() }));
72
+ }
56
73
  stats() {
57
74
  return { total: this.total, unknown: this.unknown };
58
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"failure-corpus.js","sourceRoot":"","sources":["../../src/core/failure-corpus.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAA2B,MAAM,yBAAyB,CAAC;AAoC7F,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAC5B,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,qBAAqB,GAAuB;IACjD,QAAQ,EAAE,GAAG,GAAG,IAAI;IACpB,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1C,UAAU,EAAE,KAAK;CACjB,CAAC;AAEF,MAAM,UAAU,uCAAuC,CAAC,IAQvD;IACA,OAAO;QACN,IAAI,EAAE,iBAAiB;QACvB,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC;QACnD,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC;QACjD,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC;QAC1C,YAAY,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;aAC3C,IAAI,EAAE;aACN,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC;aAC1B,GAAG,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KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC;QAC3D,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/E,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAe;IAC5C,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACvF,CAAC","sourcesContent":["import type { ClassifiedError } from \"@caupulican/pi-agent-core\";\nimport { redactKnownSecrets } from \"./security/secret-text.ts\";\nimport { appendBoundedJsonLineSync, type BoundedJsonlLimits } from \"./util/bounded-jsonl.ts\";\n\nexport interface ProviderFailureCorpusRecord {\n\tts: string;\n\tprovider?: string;\n\tmodelId?: string;\n\treason: ClassifiedError[\"reason\"];\n\tretryable: boolean;\n\tmessage: string;\n}\n\nexport interface ToolValidationFailureShapeEntry {\n\tpath: string;\n\texpectedType: string;\n\treceivedType: string;\n\tkeyword?: string;\n}\n\nexport interface ToolValidationFailureCorpusRecord {\n\tkind: \"tool_validation\";\n\tts: string;\n\tprovider?: string;\n\tmodelId?: string;\n\ttool: string;\n\tfailureModes: string[];\n\tshape: ToolValidationFailureShapeEntry[];\n\terrorKeywords: string[];\n}\n\nexport type FailureCorpusRecord = ProviderFailureCorpusRecord | ToolValidationFailureCorpusRecord;\n\nexport interface FailureCorpusStats {\n\ttotal: number;\n\tunknown: number;\n}\n\nconst MAX_MESSAGE_CHARS = 500;\nconst MAX_DETAIL_ITEMS = 50;\nconst MAX_DETAIL_CHARS = 256;\nconst FAILURE_CORPUS_LIMITS: BoundedJsonlLimits = {\n\tmaxBytes: 512 * 1024,\n\ttargetBytes: Math.floor(512 * 1024 * 0.75),\n\tmaxRecords: 1_000,\n};\n\nexport function createToolValidationFailureCorpusRecord(args: {\n\tprovider?: string;\n\tmodelId?: string;\n\ttool: string;\n\tfailureModes: readonly string[];\n\tshape: readonly ToolValidationFailureShapeEntry[];\n\terrorKeywords?: readonly string[];\n\tts: string;\n}): ToolValidationFailureCorpusRecord {\n\treturn {\n\t\tkind: \"tool_validation\",\n\t\tts: args.ts,\n\t\tprovider: args.provider?.slice(0, MAX_DETAIL_CHARS),\n\t\tmodelId: args.modelId?.slice(0, MAX_DETAIL_CHARS),\n\t\ttool: args.tool.slice(0, MAX_DETAIL_CHARS),\n\t\tfailureModes: [...new Set(args.failureModes)]\n\t\t\t.sort()\n\t\t\t.slice(0, MAX_DETAIL_ITEMS)\n\t\t\t.map((value) => value.slice(0, MAX_DETAIL_CHARS)),\n\t\tshape: sanitizeToolValidationShape(args.shape),\n\t\terrorKeywords: [...new Set(args.errorKeywords ?? [])]\n\t\t\t.sort()\n\t\t\t.slice(0, MAX_DETAIL_ITEMS)\n\t\t\t.map((value) => value.slice(0, MAX_DETAIL_CHARS)),\n\t};\n}\n\nexport function writeFailureCorpusRecord(filePath: string, record: FailureCorpusRecord): void {\n\tappendBoundedJsonLineSync(filePath, record, FAILURE_CORPUS_LIMITS);\n}\n\nexport class FailureCorpusRecorder {\n\tprivate total = 0;\n\tprivate unknown = 0;\n\tprivate readonly filePath: string;\n\tprivate readonly now: () => Date;\n\tprivate readonly debug: (message: string) => void;\n\n\tconstructor(args: { filePath: string; now?: () => Date; debug?: (message: string) => void }) {\n\t\tthis.filePath = args.filePath;\n\t\tthis.now = args.now ?? (() => new Date());\n\t\tthis.debug = args.debug ?? (() => {});\n\t}\n\n\trecord(args: { provider?: string; modelId?: string; message: string; classified: ClassifiedError }): void {\n\t\tthis.total += 1;\n\t\tif (args.classified.reason === \"unknown\") this.unknown += 1;\n\t\tthis.appendRecord({\n\t\t\tts: this.now().toISOString(),\n\t\t\tprovider: args.provider,\n\t\t\tmodelId: args.modelId,\n\t\t\treason: args.classified.reason,\n\t\t\tretryable: args.classified.retryable,\n\t\t\tmessage: redactSecrets(args.message).slice(0, MAX_MESSAGE_CHARS),\n\t\t});\n\t}\n\n\trecordToolValidation(args: {\n\t\tprovider?: string;\n\t\tmodelId?: string;\n\t\ttool: string;\n\t\tfailureModes: readonly string[];\n\t\tshape: readonly ToolValidationFailureShapeEntry[];\n\t\terrorKeywords?: readonly string[];\n\t}): void {\n\t\tthis.appendRecord(createToolValidationFailureCorpusRecord({ ...args, ts: this.now().toISOString() }));\n\t}\n\n\tstats(): FailureCorpusStats {\n\t\treturn { total: this.total, unknown: this.unknown };\n\t}\n\n\tprivate appendRecord(record: FailureCorpusRecord): void {\n\t\ttry {\n\t\t\twriteFailureCorpusRecord(this.filePath, record);\n\t\t} catch (error) {\n\t\t\tthis.debug(`failure corpus write skipped: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t}\n}\n\nfunction sanitizeToolValidationShape(\n\tshape: readonly ToolValidationFailureShapeEntry[],\n): ToolValidationFailureShapeEntry[] {\n\treturn shape.slice(0, MAX_DETAIL_ITEMS).map((entry) => ({\n\t\tpath: entry.path.slice(0, MAX_DETAIL_CHARS),\n\t\texpectedType: entry.expectedType.slice(0, MAX_DETAIL_CHARS),\n\t\treceivedType: entry.receivedType.slice(0, MAX_DETAIL_CHARS),\n\t\t...(entry.keyword ? { keyword: entry.keyword.slice(0, MAX_DETAIL_CHARS) } : {}),\n\t}));\n}\n\nexport function redactSecrets(message: string): string {\n\treturn redactKnownSecrets(message).replace(/[A-Za-z0-9+/]{40,}={0,2}/g, \"[REDACTED]\");\n}\n"]}
1
+ {"version":3,"file":"failure-corpus.js","sourceRoot":"","sources":["../../src/core/failure-corpus.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAA2B,MAAM,yBAAyB,CAAC;AAoD7F,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,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AAK,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,CAAC,iCAAiC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvG,CAAC;IACF,CAAC;CACD;AAED,SAAS,2BAA2B,CACnC,KAAiD;IAEjD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvD,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC;QAC3C,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC;QAC3D,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC;QAC3D,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/E,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAe;IAC5C,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACvF,CAAC","sourcesContent":["import type { ClassifiedError } from \"@caupulican/pi-agent-core\";\nimport type { ToolFailurePhase } from \"@caupulican/pi-ai/tool-repair-registry\";\nimport { redactKnownSecrets } from \"./security/secret-text.ts\";\nimport { appendBoundedJsonLineSync, type BoundedJsonlLimits } from \"./util/bounded-jsonl.ts\";\n\nexport interface ProviderFailureCorpusRecord {\n\tts: string;\n\tprovider?: string;\n\tmodelId?: string;\n\treason: ClassifiedError[\"reason\"];\n\tretryable: boolean;\n\tmessage: string;\n}\n\nexport interface ToolValidationFailureShapeEntry {\n\tpath: string;\n\texpectedType: string;\n\treceivedType: string;\n\tkeyword?: string;\n}\n\nexport interface ToolValidationFailureCorpusRecord {\n\tkind: \"tool_validation\";\n\tts: string;\n\tprovider?: string;\n\tmodelId?: string;\n\ttool: string;\n\tfailureModes: string[];\n\tshape: ToolValidationFailureShapeEntry[];\n\terrorKeywords: string[];\n}\n\nexport interface ToolExecutionFailureCorpusRecord {\n\tkind: \"tool_execution\";\n\tts: string;\n\tprovider?: string;\n\tmodelId?: string;\n\ttool: string;\n\tstate: \"failed\" | \"rejected\";\n\tphase: ToolFailurePhase;\n\tfailureCode: string;\n\tdiagnostic?: string;\n\tnextAction: string;\n}\n\nexport type FailureCorpusRecord =\n\t| ProviderFailureCorpusRecord\n\t| ToolValidationFailureCorpusRecord\n\t| ToolExecutionFailureCorpusRecord;\n\nexport interface FailureCorpusStats {\n\ttotal: number;\n\tunknown: number;\n}\n\nconst MAX_MESSAGE_CHARS = 500;\nconst MAX_DETAIL_ITEMS = 50;\nconst MAX_DETAIL_CHARS = 256;\nconst FAILURE_CORPUS_LIMITS: BoundedJsonlLimits = {\n\tmaxBytes: 512 * 1024,\n\ttargetBytes: Math.floor(512 * 1024 * 0.75),\n\tmaxRecords: 1_000,\n};\n\nexport function createToolValidationFailureCorpusRecord(args: {\n\tprovider?: string;\n\tmodelId?: string;\n\ttool: string;\n\tfailureModes: readonly string[];\n\tshape: readonly ToolValidationFailureShapeEntry[];\n\terrorKeywords?: readonly string[];\n\tts: string;\n}): ToolValidationFailureCorpusRecord {\n\treturn {\n\t\tkind: \"tool_validation\",\n\t\tts: args.ts,\n\t\tprovider: args.provider?.slice(0, MAX_DETAIL_CHARS),\n\t\tmodelId: args.modelId?.slice(0, MAX_DETAIL_CHARS),\n\t\ttool: args.tool.slice(0, MAX_DETAIL_CHARS),\n\t\tfailureModes: [...new Set(args.failureModes)]\n\t\t\t.sort()\n\t\t\t.slice(0, MAX_DETAIL_ITEMS)\n\t\t\t.map((value) => value.slice(0, MAX_DETAIL_CHARS)),\n\t\tshape: sanitizeToolValidationShape(args.shape),\n\t\terrorKeywords: [...new Set(args.errorKeywords ?? [])]\n\t\t\t.sort()\n\t\t\t.slice(0, MAX_DETAIL_ITEMS)\n\t\t\t.map((value) => value.slice(0, MAX_DETAIL_CHARS)),\n\t};\n}\n\nexport function createToolExecutionFailureCorpusRecord(args: {\n\tprovider?: string;\n\tmodelId?: string;\n\ttool: string;\n\tstate: \"failed\" | \"rejected\";\n\tphase: ToolFailurePhase;\n\tfailureCode: string;\n\tdiagnostic?: string;\n\tnextAction: string;\n\tts: string;\n}): ToolExecutionFailureCorpusRecord {\n\treturn {\n\t\tkind: \"tool_execution\",\n\t\tts: args.ts,\n\t\tprovider: args.provider?.slice(0, MAX_DETAIL_CHARS),\n\t\tmodelId: args.modelId?.slice(0, MAX_DETAIL_CHARS),\n\t\ttool: args.tool.slice(0, MAX_DETAIL_CHARS),\n\t\tstate: args.state,\n\t\tphase: args.phase,\n\t\tfailureCode: args.failureCode.slice(0, MAX_DETAIL_CHARS),\n\t\t...(args.diagnostic ? { diagnostic: redactSecrets(args.diagnostic).slice(0, MAX_DETAIL_CHARS) } : {}),\n\t\tnextAction: redactSecrets(args.nextAction).slice(0, MAX_DETAIL_CHARS),\n\t};\n}\n\nexport function writeFailureCorpusRecord(filePath: string, record: FailureCorpusRecord): void {\n\tappendBoundedJsonLineSync(filePath, record, FAILURE_CORPUS_LIMITS);\n}\n\nexport class FailureCorpusRecorder {\n\tprivate total = 0;\n\tprivate unknown = 0;\n\tprivate readonly filePath: string;\n\tprivate readonly now: () => Date;\n\tprivate readonly debug: (message: string) => void;\n\n\tconstructor(args: { filePath: string; now?: () => Date; debug?: (message: string) => void }) {\n\t\tthis.filePath = args.filePath;\n\t\tthis.now = args.now ?? (() => new Date());\n\t\tthis.debug = args.debug ?? (() => {});\n\t}\n\n\trecord(args: { provider?: string; modelId?: string; message: string; classified: ClassifiedError }): void {\n\t\tthis.total += 1;\n\t\tif (args.classified.reason === \"unknown\") this.unknown += 1;\n\t\tthis.appendRecord({\n\t\t\tts: this.now().toISOString(),\n\t\t\tprovider: args.provider,\n\t\t\tmodelId: args.modelId,\n\t\t\treason: args.classified.reason,\n\t\t\tretryable: args.classified.retryable,\n\t\t\tmessage: redactSecrets(args.message).slice(0, MAX_MESSAGE_CHARS),\n\t\t});\n\t}\n\n\trecordToolValidation(args: {\n\t\tprovider?: string;\n\t\tmodelId?: string;\n\t\ttool: string;\n\t\tfailureModes: readonly string[];\n\t\tshape: readonly ToolValidationFailureShapeEntry[];\n\t\terrorKeywords?: readonly string[];\n\t}): void {\n\t\tthis.appendRecord(createToolValidationFailureCorpusRecord({ ...args, ts: this.now().toISOString() }));\n\t}\n\n\trecordToolExecution(args: Omit<Parameters<typeof createToolExecutionFailureCorpusRecord>[0], \"ts\">): void {\n\t\tthis.appendRecord(createToolExecutionFailureCorpusRecord({ ...args, ts: this.now().toISOString() }));\n\t}\n\n\tstats(): FailureCorpusStats {\n\t\treturn { total: this.total, unknown: this.unknown };\n\t}\n\n\tprivate appendRecord(record: FailureCorpusRecord): void {\n\t\ttry {\n\t\t\twriteFailureCorpusRecord(this.filePath, record);\n\t\t} catch (error) {\n\t\t\tthis.debug(`failure corpus write skipped: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t}\n}\n\nfunction sanitizeToolValidationShape(\n\tshape: readonly ToolValidationFailureShapeEntry[],\n): ToolValidationFailureShapeEntry[] {\n\treturn shape.slice(0, MAX_DETAIL_ITEMS).map((entry) => ({\n\t\tpath: entry.path.slice(0, MAX_DETAIL_CHARS),\n\t\texpectedType: entry.expectedType.slice(0, MAX_DETAIL_CHARS),\n\t\treceivedType: entry.receivedType.slice(0, MAX_DETAIL_CHARS),\n\t\t...(entry.keyword ? { keyword: entry.keyword.slice(0, MAX_DETAIL_CHARS) } : {}),\n\t}));\n}\n\nexport function redactSecrets(message: string): string {\n\treturn redactKnownSecrets(message).replace(/[A-Za-z0-9+/]{40,}={0,2}/g, \"[REDACTED]\");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"model-capability.d.ts","sourceRoot":"","sources":["../../src/core/model-capability.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,KAAK,GAAG,oBAAoB,CAAC;AAExE,MAAM,WAAW,sBAAsB;IACtC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,0FAA0F;IAC1F,sBAAsB,EAAE,OAAO,CAAC;IAChC,4EAA4E;IAC5E,mBAAmB,EAAE,MAAM,CAAC;CAC5B;AAED,8DAA8D;AAC9D,eAAO,MAAM,iCAAiC,QAAS,CAAC;AACxD,oFAAoF;AACpF,eAAO,MAAM,iCAAiC,QAAS,CAAC;AACxD,+EAA+E;AAC/E,eAAO,MAAM,oCAAoC,OAAQ,CAAC;AAE1D,eAAO,MAAM,mCAAmC,EAAE,SAAS,MAAM,EAWhE,CAAC;AACF,eAAO,MAAM,sCAAsC,EAAE,SAAS,MAAM,EAUnE,CAAC;AACF,eAAO,MAAM,mCAAmC,EAAE,SAAS,MAAM,EAAO,CAAC;AAEzE,eAAO,MAAM,8BAA8B,OAAO,CAAC;AA0CnD,wBAAgB,4BAA4B,CAAC,IAAI,EAAE;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,mBAAmB,CAAC;CAC3B,GAAG,sBAAsB,CA2BzB;AAED,6FAA6F;AAC7F,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AC5B,GAAG,iBAAiB,GAAG,SAAS,CAOhC;AAED,6EAA6E;AAC7E,eAAO,MAAM,0BAA0B,uCAAuC,CAAC;AAE/E,0GAA0G;AAC1G,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAI5F"}
@@ -15,6 +15,7 @@ export const MODEL_CAPABILITY_LEAN_MIN_CONTEXT = 16_384;
15
15
  export const MODEL_CAPABILITY_MINIMAL_MIN_CONTEXT = 8_192;
16
16
  export const MODEL_CAPABILITY_LEAN_BLOCKED_TOOLS = [
17
17
  "delegate",
18
+ "profile_writer",
18
19
  "context_audit",
19
20
  "goal",
20
21
  "worktree_sync",
@@ -1 +1 @@
1
- {"version":3,"file":"model-capability.js","sourceRoot":"","sources":["../../src/core/model-capability.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAoBH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AACxD,oFAAoF;AACpF,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AACxD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,oCAAoC,GAAG,KAAK,CAAC;AAE1D,MAAM,CAAC,MAAM,mCAAmC,GAAsB;IACrE,UAAU;IACV,eAAe;IACf,MAAM;IACN,eAAe;IACf,kBAAkB;IAClB,cAAc;IACd,UAAU;IACV,eAAe;IACf,eAAe;IACf,oBAAoB;CACpB,CAAC;AACF,MAAM,CAAC,MAAM,sCAAsC,GAAsB;IACxE,MAAM;IACN,MAAM;IACN,QAAQ;IACR,YAAY;IACZ,MAAM;IACN,OAAO;IACP,cAAc;IACd,+FAA+F;IAC/F,oBAAoB;CACpB,CAAC;AACF,MAAM,CAAC,MAAM,mCAAmC,GAAsB,EAAE,CAAC;AAEzE,MAAM,CAAC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AACnD,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC,SAA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,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnG,OAAO,GAAG,0BAA0B,GAAG,UAAU,UAAU,OAAO,CAAC,eAAe,kBAAkB,UAAU,WAAW,OAAO,CAAC,MAAM,EAAE,CAAC;AAC3I,CAAC","sourcesContent":["/**\n * Model capability auto-detection: derive what the harness may load onto a model FROM the model's\n * own metadata (`Model.contextWindow`), so small open models (4k/8k/16k windows, sub-1B params)\n * can still hold a usable chat instead of drowning in tool schemas and background-lane prompts.\n *\n * Derivation is metadata-first; defaults apply only when the metadata is missing (unknown/zero\n * window keeps today's full behavior rather than guessing). Detection can be disabled or forced\n * per class via the `modelCapability.mode` setting.\n */\n\nexport type ModelCapabilityClass = \"full\" | \"lean\" | \"minimal\" | \"chat\";\n\nexport type ModelCapabilityMode = \"auto\" | \"off\" | ModelCapabilityClass;\n\nexport interface ModelCapabilityProfile {\n\tclass: ModelCapabilityClass;\n\tcontextWindow?: number;\n\treasonCode: string;\n\t/** Allow-list; undefined = no allow-list restriction. */\n\tallowedToolNames?: readonly string[];\n\t/** Block-list applied after the allow-list; undefined = nothing blocked. */\n\tblockedToolNames?: readonly string[];\n\t/** Whether idle background lanes (goal auto-continue, research) may run on this model. */\n\tbackgroundLanesEnabled: boolean;\n\t/** Output-token cap for lane isolated completions, scaled to the window. */\n\tlaneMaxOutputTokens: number;\n}\n\n/** Windows at or above this keep the full harness surface. */\nexport const MODEL_CAPABILITY_FULL_MIN_CONTEXT = 32_768;\n/** Windows at or above this keep core tools but shed background-autonomy extras. */\nexport const MODEL_CAPABILITY_LEAN_MIN_CONTEXT = 16_384;\n/** Windows at or above this get the minimal coding set; below is chat-only. */\nexport const MODEL_CAPABILITY_MINIMAL_MIN_CONTEXT = 8_192;\n\nexport const MODEL_CAPABILITY_LEAN_BLOCKED_TOOLS: readonly string[] = [\n\t\"delegate\",\n\t\"context_audit\",\n\t\"goal\",\n\t\"worktree_sync\",\n\t\"improvement_loop\",\n\t\"extensionify\",\n\t\"skillify\",\n\t\"model_fitness\",\n\t\"context_scout\",\n\t\"tmux_agent_manager\",\n];\nexport const MODEL_CAPABILITY_MINIMAL_ALLOWED_TOOLS: readonly string[] = [\n\t\"read\",\n\t\"bash\",\n\t\"python\",\n\t\"powershell\",\n\t\"edit\",\n\t\"write\",\n\t\"ask_question\",\n\t// The executor tool: minimal-class models ARE the daily-ops executors, and its schema is tiny.\n\t\"run_toolkit_script\",\n];\nexport const MODEL_CAPABILITY_CHAT_ALLOWED_TOOLS: readonly string[] = [];\n\nexport const DEFAULT_LANE_MAX_OUTPUT_TOKENS = 2048;\nconst MIN_LANE_MAX_OUTPUT_TOKENS = 256;\n\nfunction laneOutputTokensForWindow(contextWindow: number | undefined): number {\n\tif (contextWindow === undefined || contextWindow <= 0) return DEFAULT_LANE_MAX_OUTPUT_TOKENS;\n\t// A lane completion may use at most an eighth of the window for output, floored so tiny\n\t// windows still produce something parseable.\n\treturn Math.min(DEFAULT_LANE_MAX_OUTPUT_TOKENS, Math.max(MIN_LANE_MAX_OUTPUT_TOKENS, Math.floor(contextWindow / 8)));\n}\n\nfunction profileForClass(\n\tcapabilityClass: ModelCapabilityClass,\n\treasonCode: string,\n\tcontextWindow: number | undefined,\n): ModelCapabilityProfile {\n\tconst base = {\n\t\tclass: capabilityClass,\n\t\treasonCode,\n\t\tbackgroundLanesEnabled: true,\n\t\tlaneMaxOutputTokens: laneOutputTokensForWindow(contextWindow),\n\t\t...(contextWindow !== undefined && contextWindow > 0 ? { contextWindow } : {}),\n\t};\n\tswitch (capabilityClass) {\n\t\tcase \"full\":\n\t\t\treturn base;\n\t\tcase \"lean\":\n\t\t\treturn { ...base, blockedToolNames: MODEL_CAPABILITY_LEAN_BLOCKED_TOOLS };\n\t\tcase \"minimal\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\tallowedToolNames: MODEL_CAPABILITY_MINIMAL_ALLOWED_TOOLS,\n\t\t\t\tbackgroundLanesEnabled: false,\n\t\t\t};\n\t\tcase \"chat\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\tallowedToolNames: MODEL_CAPABILITY_CHAT_ALLOWED_TOOLS,\n\t\t\t\tbackgroundLanesEnabled: false,\n\t\t\t};\n\t}\n}\n\nexport function deriveModelCapabilityProfile(args: {\n\tcontextWindow?: number;\n\tmode?: ModelCapabilityMode;\n}): ModelCapabilityProfile {\n\tconst mode = args.mode ?? \"auto\";\n\tconst contextWindow =\n\t\targs.contextWindow !== undefined && Number.isFinite(args.contextWindow) && args.contextWindow > 0\n\t\t\t? args.contextWindow\n\t\t\t: undefined;\n\tif (mode === \"off\") {\n\t\treturn profileForClass(\"full\", \"detection_disabled\", contextWindow);\n\t}\n\tif (mode !== \"auto\") {\n\t\treturn profileForClass(mode, \"forced_by_setting\", contextWindow);\n\t}\n\n\tif (contextWindow === undefined) {\n\t\t// Metadata missing: defaults, never guesses.\n\t\treturn profileForClass(\"full\", \"unknown_context_window_defaults\", undefined);\n\t}\n\tif (contextWindow >= MODEL_CAPABILITY_FULL_MIN_CONTEXT) {\n\t\treturn profileForClass(\"full\", \"large_context_window\", contextWindow);\n\t}\n\tif (contextWindow >= MODEL_CAPABILITY_LEAN_MIN_CONTEXT) {\n\t\treturn profileForClass(\"lean\", \"lean_context_window\", contextWindow);\n\t}\n\tif (contextWindow >= MODEL_CAPABILITY_MINIMAL_MIN_CONTEXT) {\n\t\treturn profileForClass(\"minimal\", \"minimal_context_window\", contextWindow);\n\t}\n\treturn profileForClass(\"chat\", \"chat_only_context_window\", contextWindow);\n}\n\n/** Apply the profile's allow/block lists to a requested tool-name list, preserving order. */\nexport function filterToolNamesForCapability(toolNames: readonly string[], profile: ModelCapabilityProfile): string[] {\n\tlet filtered = [...toolNames];\n\tif (profile.allowedToolNames !== undefined) {\n\t\tconst allowed = new Set(profile.allowedToolNames);\n\t\tfiltered = filtered.filter((name) => allowed.has(name));\n\t}\n\tif (profile.blockedToolNames !== undefined) {\n\t\tconst blocked = new Set(profile.blockedToolNames);\n\t\tfiltered = filtered.filter((name) => !blocked.has(name));\n\t}\n\treturn filtered;\n}\n\n/**\n * Lane-worker eligibility: a session bound to a worktree-sync lane (`--worktree-lane` /\n * `PI_WORKTREE_LANE`, see worktree-sync/runtime.ts) is expected to drive the FULL multi-step\n * lane-gate/recovery surface -- sync, conflict recovery, land -- unattended. A sub-full capability\n * class or a model with no working native tool-call path cannot reliably drive that surface. This\n * rides the SAME capability system every other adaptation in this file rides (class + context\n * window + the `/toolprobe` verdict) -- no parallel mechanism, no new env var, no new registry field.\n */\nexport type LaneWorkerRefusalReason =\n\t| \"capability_class_below_full\"\n\t| \"context_window_unknown\"\n\t| \"tool_calling_unadvertised\"\n\t| \"tool_calling_demoted\";\n\nexport interface LaneWorkerRefusal {\n\treason: LaneWorkerRefusalReason;\n\tcapabilityClass: ModelCapabilityClass;\n\tcontextWindow?: number;\n}\n\n/**\n * Decide whether the model described by `args` may drive a worktree-sync lane worker. First\n * failure wins, in order: capability class below full; an unknown/undeclared context window (the\n * classifier's own registry-derived SSOT -- see `deriveModelCapabilityProfile`; a full class can\n * still carry an undefined window via the `unknown_context_window_defaults` fallback); no\n * ADVERTISED native tool-call path (`Model.textToolCallProtocol` unset/false -- set true means\n * phone-only); or a GRADED `/toolprobe` demotion to \"text-protocol\"/\"none\". An UNPROBED model (no\n * verdict on record yet) is eligible on its advertised support alone -- unprobed is never treated\n * as demoted. `undefined` means eligible.\n */\nexport function evaluateLaneWorkerRefusal(args: {\n\tcapabilityClass: ModelCapabilityClass;\n\tcontextWindow: number | undefined;\n\ttoolCallingAdvertised: boolean;\n\ttoolCallingDemoted: boolean;\n}): LaneWorkerRefusal | undefined {\n\tconst { capabilityClass, contextWindow, toolCallingAdvertised, toolCallingDemoted } = args;\n\tif (capabilityClass !== \"full\") return { reason: \"capability_class_below_full\", capabilityClass, contextWindow };\n\tif (contextWindow === undefined) return { reason: \"context_window_unknown\", capabilityClass, contextWindow };\n\tif (!toolCallingAdvertised) return { reason: \"tool_calling_unadvertised\", capabilityClass, contextWindow };\n\tif (toolCallingDemoted) return { reason: \"tool_calling_demoted\", capabilityClass, contextWindow };\n\treturn undefined;\n}\n\n/** Stable, greppable prefix for {@link formatLaneWorkerRefusal}'s output. */\nexport const LANE_WORKER_REFUSAL_PREFIX = \"worktree-sync lane-worker refusal:\";\n\n/** Format a refusal into one deterministic, greppable line naming the lane, class, window, and reason. */\nexport function formatLaneWorkerRefusal(refusal: LaneWorkerRefusal, laneKey?: string): string {\n\tconst laneSuffix = laneKey !== undefined ? ` lane=${laneKey}` : \"\";\n\tconst windowText = refusal.contextWindow !== undefined ? String(refusal.contextWindow) : \"unknown\";\n\treturn `${LANE_WORKER_REFUSAL_PREFIX}${laneSuffix} class=${refusal.capabilityClass} contextWindow=${windowText} reason=${refusal.reason}`;\n}\n"]}
1
+ {"version":3,"file":"model-capability.js","sourceRoot":"","sources":["../../src/core/model-capability.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAoBH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AACxD,oFAAoF;AACpF,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AACxD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,oCAAoC,GAAG,KAAK,CAAC;AAE1D,MAAM,CAAC,MAAM,mCAAmC,GAAsB;IACrE,UAAU;IACV,gBAAgB;IAChB,eAAe;IACf,MAAM;IACN,eAAe;IACf,kBAAkB;IAClB,cAAc;IACd,UAAU;IACV,eAAe;IACf,eAAe;IACf,oBAAoB;CACpB,CAAC;AACF,MAAM,CAAC,MAAM,sCAAsC,GAAsB;IACxE,MAAM;IACN,MAAM;IACN,QAAQ;IACR,YAAY;IACZ,MAAM;IACN,OAAO;IACP,cAAc;IACd,+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AAM,CAAC,MAAM,0BAA0B,GAAG,oCAAoC,CAAC;AAE/E,0GAA0G;AAC1G,MAAM,UAAU,uBAAuB,CAAC,OAA0B,EAAE,OAAgB;IACnF,MAAM,UAAU,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACnG,OAAO,GAAG,0BAA0B,GAAG,UAAU,UAAU,OAAO,CAAC,eAAe,kBAAkB,UAAU,WAAW,OAAO,CAAC,MAAM,EAAE,CAAC;AAC3I,CAAC","sourcesContent":["/**\n * Model capability auto-detection: derive what the harness may load onto a model FROM the model's\n * own metadata (`Model.contextWindow`), so small open models (4k/8k/16k windows, sub-1B params)\n * can still hold a usable chat instead of drowning in tool schemas and background-lane prompts.\n *\n * Derivation is metadata-first; defaults apply only when the metadata is missing (unknown/zero\n * window keeps today's full behavior rather than guessing). Detection can be disabled or forced\n * per class via the `modelCapability.mode` setting.\n */\n\nexport type ModelCapabilityClass = \"full\" | \"lean\" | \"minimal\" | \"chat\";\n\nexport type ModelCapabilityMode = \"auto\" | \"off\" | ModelCapabilityClass;\n\nexport interface ModelCapabilityProfile {\n\tclass: ModelCapabilityClass;\n\tcontextWindow?: number;\n\treasonCode: string;\n\t/** Allow-list; undefined = no allow-list restriction. */\n\tallowedToolNames?: readonly string[];\n\t/** Block-list applied after the allow-list; undefined = nothing blocked. */\n\tblockedToolNames?: readonly string[];\n\t/** Whether idle background lanes (goal auto-continue, research) may run on this model. */\n\tbackgroundLanesEnabled: boolean;\n\t/** Output-token cap for lane isolated completions, scaled to the window. */\n\tlaneMaxOutputTokens: number;\n}\n\n/** Windows at or above this keep the full harness surface. */\nexport const MODEL_CAPABILITY_FULL_MIN_CONTEXT = 32_768;\n/** Windows at or above this keep core tools but shed background-autonomy extras. */\nexport const MODEL_CAPABILITY_LEAN_MIN_CONTEXT = 16_384;\n/** Windows at or above this get the minimal coding set; below is chat-only. */\nexport const MODEL_CAPABILITY_MINIMAL_MIN_CONTEXT = 8_192;\n\nexport const MODEL_CAPABILITY_LEAN_BLOCKED_TOOLS: readonly string[] = [\n\t\"delegate\",\n\t\"profile_writer\",\n\t\"context_audit\",\n\t\"goal\",\n\t\"worktree_sync\",\n\t\"improvement_loop\",\n\t\"extensionify\",\n\t\"skillify\",\n\t\"model_fitness\",\n\t\"context_scout\",\n\t\"tmux_agent_manager\",\n];\nexport const MODEL_CAPABILITY_MINIMAL_ALLOWED_TOOLS: readonly string[] = [\n\t\"read\",\n\t\"bash\",\n\t\"python\",\n\t\"powershell\",\n\t\"edit\",\n\t\"write\",\n\t\"ask_question\",\n\t// The executor tool: minimal-class models ARE the daily-ops executors, and its schema is tiny.\n\t\"run_toolkit_script\",\n];\nexport const MODEL_CAPABILITY_CHAT_ALLOWED_TOOLS: readonly string[] = [];\n\nexport const DEFAULT_LANE_MAX_OUTPUT_TOKENS = 2048;\nconst MIN_LANE_MAX_OUTPUT_TOKENS = 256;\n\nfunction laneOutputTokensForWindow(contextWindow: number | undefined): number {\n\tif (contextWindow === undefined || contextWindow <= 0) return DEFAULT_LANE_MAX_OUTPUT_TOKENS;\n\t// A lane completion may use at most an eighth of the window for output, floored so tiny\n\t// windows still produce something parseable.\n\treturn Math.min(DEFAULT_LANE_MAX_OUTPUT_TOKENS, Math.max(MIN_LANE_MAX_OUTPUT_TOKENS, Math.floor(contextWindow / 8)));\n}\n\nfunction profileForClass(\n\tcapabilityClass: ModelCapabilityClass,\n\treasonCode: string,\n\tcontextWindow: number | undefined,\n): ModelCapabilityProfile {\n\tconst base = {\n\t\tclass: capabilityClass,\n\t\treasonCode,\n\t\tbackgroundLanesEnabled: true,\n\t\tlaneMaxOutputTokens: laneOutputTokensForWindow(contextWindow),\n\t\t...(contextWindow !== undefined && contextWindow > 0 ? { contextWindow } : {}),\n\t};\n\tswitch (capabilityClass) {\n\t\tcase \"full\":\n\t\t\treturn base;\n\t\tcase \"lean\":\n\t\t\treturn { ...base, blockedToolNames: MODEL_CAPABILITY_LEAN_BLOCKED_TOOLS };\n\t\tcase \"minimal\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\tallowedToolNames: MODEL_CAPABILITY_MINIMAL_ALLOWED_TOOLS,\n\t\t\t\tbackgroundLanesEnabled: false,\n\t\t\t};\n\t\tcase \"chat\":\n\t\t\treturn {\n\t\t\t\t...base,\n\t\t\t\tallowedToolNames: MODEL_CAPABILITY_CHAT_ALLOWED_TOOLS,\n\t\t\t\tbackgroundLanesEnabled: false,\n\t\t\t};\n\t}\n}\n\nexport function deriveModelCapabilityProfile(args: {\n\tcontextWindow?: number;\n\tmode?: ModelCapabilityMode;\n}): ModelCapabilityProfile {\n\tconst mode = args.mode ?? \"auto\";\n\tconst contextWindow =\n\t\targs.contextWindow !== undefined && Number.isFinite(args.contextWindow) && args.contextWindow > 0\n\t\t\t? args.contextWindow\n\t\t\t: undefined;\n\tif (mode === \"off\") {\n\t\treturn profileForClass(\"full\", \"detection_disabled\", contextWindow);\n\t}\n\tif (mode !== \"auto\") {\n\t\treturn profileForClass(mode, \"forced_by_setting\", contextWindow);\n\t}\n\n\tif (contextWindow === undefined) {\n\t\t// Metadata missing: defaults, never guesses.\n\t\treturn profileForClass(\"full\", \"unknown_context_window_defaults\", undefined);\n\t}\n\tif (contextWindow >= MODEL_CAPABILITY_FULL_MIN_CONTEXT) {\n\t\treturn profileForClass(\"full\", \"large_context_window\", contextWindow);\n\t}\n\tif (contextWindow >= MODEL_CAPABILITY_LEAN_MIN_CONTEXT) {\n\t\treturn profileForClass(\"lean\", \"lean_context_window\", contextWindow);\n\t}\n\tif (contextWindow >= MODEL_CAPABILITY_MINIMAL_MIN_CONTEXT) {\n\t\treturn profileForClass(\"minimal\", \"minimal_context_window\", contextWindow);\n\t}\n\treturn profileForClass(\"chat\", \"chat_only_context_window\", contextWindow);\n}\n\n/** Apply the profile's allow/block lists to a requested tool-name list, preserving order. */\nexport function filterToolNamesForCapability(toolNames: readonly string[], profile: ModelCapabilityProfile): string[] {\n\tlet filtered = [...toolNames];\n\tif (profile.allowedToolNames !== undefined) {\n\t\tconst allowed = new Set(profile.allowedToolNames);\n\t\tfiltered = filtered.filter((name) => allowed.has(name));\n\t}\n\tif (profile.blockedToolNames !== undefined) {\n\t\tconst blocked = new Set(profile.blockedToolNames);\n\t\tfiltered = filtered.filter((name) => !blocked.has(name));\n\t}\n\treturn filtered;\n}\n\n/**\n * Lane-worker eligibility: a session bound to a worktree-sync lane (`--worktree-lane` /\n * `PI_WORKTREE_LANE`, see worktree-sync/runtime.ts) is expected to drive the FULL multi-step\n * lane-gate/recovery surface -- sync, conflict recovery, land -- unattended. A sub-full capability\n * class or a model with no working native tool-call path cannot reliably drive that surface. This\n * rides the SAME capability system every other adaptation in this file rides (class + context\n * window + the `/toolprobe` verdict) -- no parallel mechanism, no new env var, no new registry field.\n */\nexport type LaneWorkerRefusalReason =\n\t| \"capability_class_below_full\"\n\t| \"context_window_unknown\"\n\t| \"tool_calling_unadvertised\"\n\t| \"tool_calling_demoted\";\n\nexport interface LaneWorkerRefusal {\n\treason: LaneWorkerRefusalReason;\n\tcapabilityClass: ModelCapabilityClass;\n\tcontextWindow?: number;\n}\n\n/**\n * Decide whether the model described by `args` may drive a worktree-sync lane worker. First\n * failure wins, in order: capability class below full; an unknown/undeclared context window (the\n * classifier's own registry-derived SSOT -- see `deriveModelCapabilityProfile`; a full class can\n * still carry an undefined window via the `unknown_context_window_defaults` fallback); no\n * ADVERTISED native tool-call path (`Model.textToolCallProtocol` unset/false -- set true means\n * phone-only); or a GRADED `/toolprobe` demotion to \"text-protocol\"/\"none\". An UNPROBED model (no\n * verdict on record yet) is eligible on its advertised support alone -- unprobed is never treated\n * as demoted. `undefined` means eligible.\n */\nexport function evaluateLaneWorkerRefusal(args: {\n\tcapabilityClass: ModelCapabilityClass;\n\tcontextWindow: number | undefined;\n\ttoolCallingAdvertised: boolean;\n\ttoolCallingDemoted: boolean;\n}): LaneWorkerRefusal | undefined {\n\tconst { capabilityClass, contextWindow, toolCallingAdvertised, toolCallingDemoted } = args;\n\tif (capabilityClass !== \"full\") return { reason: \"capability_class_below_full\", capabilityClass, contextWindow };\n\tif (contextWindow === undefined) return { reason: \"context_window_unknown\", capabilityClass, contextWindow };\n\tif (!toolCallingAdvertised) return { reason: \"tool_calling_unadvertised\", capabilityClass, contextWindow };\n\tif (toolCallingDemoted) return { reason: \"tool_calling_demoted\", capabilityClass, contextWindow };\n\treturn undefined;\n}\n\n/** Stable, greppable prefix for {@link formatLaneWorkerRefusal}'s output. */\nexport const LANE_WORKER_REFUSAL_PREFIX = \"worktree-sync lane-worker refusal:\";\n\n/** Format a refusal into one deterministic, greppable line naming the lane, class, window, and reason. */\nexport function formatLaneWorkerRefusal(refusal: LaneWorkerRefusal, laneKey?: string): string {\n\tconst laneSuffix = laneKey !== undefined ? ` lane=${laneKey}` : \"\";\n\tconst windowText = refusal.contextWindow !== undefined ? String(refusal.contextWindow) : \"unknown\";\n\treturn `${LANE_WORKER_REFUSAL_PREFIX}${laneSuffix} class=${refusal.capabilityClass} contextWindow=${windowText} reason=${refusal.reason}`;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { type Api, type Model, type SimpleStreamOptions } from "@caupulican/pi-ai";
2
2
  import type { ModelAdaptationProfile } from "./models/adaptation-store.ts";
3
3
  export declare const MODEL_TOOL_PROTOCOL_VERSION = 1;
4
- export type ModelToolProtocolReasonCode = "settings_disabled" | "settings_enabled" | "model_enabled" | "probe_calibrated" | "probe_calibration_missing" | "probe_calibration_failed" | "probe_calibration_invalid" | "native_default";
4
+ export type ModelToolProtocolReasonCode = "settings_disabled" | "settings_enabled" | "model_enabled" | "probe_calibrated" | "probe_calibration_missing" | "probe_calibration_failed" | "probe_calibration_invalid" | "probe_native" | "native_default";
5
5
  export interface ModelToolProtocolResolution {
6
6
  protocol: SimpleStreamOptions["textToolCallProtocol"];
7
7
  reasonCode: ModelToolProtocolReasonCode;
@@ -10,7 +10,8 @@ export interface ModelToolProtocolResolution {
10
10
  /**
11
11
  * Resolve the effective tool-call transport for any model and execution lane.
12
12
  *
13
- * Explicit settings win, followed by model metadata and then graded probe evidence. A probe-driven
13
+ * A disabled setting and proven native capability always keep the native path active. Text-protocol
14
+ * settings and model metadata apply only when native capability has not been proven. A probe-driven
14
15
  * text protocol is usable only with a current, recognized calibration; otherwise the model stays on
15
16
  * native calls for this turn. Callers use the reason code for diagnostics, but never reimplement the
16
17
  * precedence or silently substitute the default dialect.
@@ -1 +1 @@
1
- {"version":3,"file":"model-tool-protocol.d.ts","sourceRoot":"","sources":["../../src/core/model-tool-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAA6B,KAAK,KAAK,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAE3E,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C,MAAM,MAAM,2BAA2B,GACpC,mBAAmB,GACnB,kBAAkB,GAClB,eAAe,GACf,kBAAkB,GAClB,2BAA2B,GAC3B,0BAA0B,GAC1B,2BAA2B,GAC3B,gBAAgB,CAAC;AAEpB,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,EAAE,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;IACtD,UAAU,EAAE,2BAA2B,CAAC;IACxC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC9C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAChD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,IAAI,CAAC,sBAAsB,EAAE,UAAU,GAAG,WAAW,CAAC,CAAC;CACnE,GAAG,2BAA2B,CAgC9B"}
1
+ {"version":3,"file":"model-tool-protocol.d.ts","sourceRoot":"","sources":["../../src/core/model-tool-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAA6B,KAAK,KAAK,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC9G,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAE3E,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C,MAAM,MAAM,2BAA2B,GACpC,mBAAmB,GACnB,kBAAkB,GAClB,eAAe,GACf,kBAAkB,GAClB,2BAA2B,GAC3B,0BAA0B,GAC1B,2BAA2B,GAC3B,cAAc,GACd,gBAAgB,CAAC;AAEpB,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,EAAE,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;IACtD,UAAU,EAAE,2BAA2B,CAAC;IACxC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC9C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,sBAAsB,CAAC,CAAC;IAChD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,IAAI,CAAC,sBAAsB,EAAE,UAAU,GAAG,WAAW,CAAC,CAAC;CACnE,GAAG,2BAA2B,CAmC9B"}
@@ -3,7 +3,8 @@ export const MODEL_TOOL_PROTOCOL_VERSION = 1;
3
3
  /**
4
4
  * Resolve the effective tool-call transport for any model and execution lane.
5
5
  *
6
- * Explicit settings win, followed by model metadata and then graded probe evidence. A probe-driven
6
+ * A disabled setting and proven native capability always keep the native path active. Text-protocol
7
+ * settings and model metadata apply only when native capability has not been proven. A probe-driven
7
8
  * text protocol is usable only with a current, recognized calibration; otherwise the model stays on
8
9
  * native calls for this turn. Callers use the reason code for diagnostics, but never reimplement the
9
10
  * precedence or silently substitute the default dialect.
@@ -12,6 +13,9 @@ export function resolveModelToolProtocol(args) {
12
13
  if (args.settingsOverride === false) {
13
14
  return { protocol: undefined, reasonCode: "settings_disabled" };
14
15
  }
16
+ if (args.adaptation.toolProbe?.status === "native") {
17
+ return { protocol: undefined, reasonCode: "probe_native" };
18
+ }
15
19
  if (args.settingsOverride === true) {
16
20
  return { protocol: true, reasonCode: "settings_enabled" };
17
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"model-tool-protocol.js","sourceRoot":"","sources":["../../src/core/model-tool-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,yBAAyB,EAAwC,MAAM,mBAAmB,CAAC;AAG9G,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAkB7C;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAIxC;IACA,IAAI,IAAI,CAAC,gBAAgB,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,EAAE,CAAC;IACjE,CAAC;IACD,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,EAAE,CAAC;QACpC,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,kBAAkB,EAAE,CAAC;IAC3D,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,CAAC,oBAAoB,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;IACxD,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,KAAK,eAAe,EAAE,CAAC;QAC3D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC9D,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC7C,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,2BAA2B,EAAE,CAAC;IACzE,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO;YACN,QAAQ,EAAE,SAAS;YACnB,UAAU,EAAE,0BAA0B;YACtC,aAAa,EAAE,WAAW,CAAC,aAAa;SACxC,CAAC;IACH,CAAC;IACD,IAAI,WAAW,CAAC,OAAO,KAAK,2BAA2B,IAAI,CAAC,yBAAyB,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5G,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,2BAA2B,EAAE,CAAC;IACzE,CAAC;IACD,OAAO;QACN,QAAQ,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE;QAC1C,UAAU,EAAE,kBAAkB;KAC9B,CAAC;AACH,CAAC","sourcesContent":["import { type Api, isTextToolProtocolVariant, type Model, type SimpleStreamOptions } from \"@caupulican/pi-ai\";\nimport type { ModelAdaptationProfile } from \"./models/adaptation-store.ts\";\n\nexport const MODEL_TOOL_PROTOCOL_VERSION = 1;\n\nexport type ModelToolProtocolReasonCode =\n\t| \"settings_disabled\"\n\t| \"settings_enabled\"\n\t| \"model_enabled\"\n\t| \"probe_calibrated\"\n\t| \"probe_calibration_missing\"\n\t| \"probe_calibration_failed\"\n\t| \"probe_calibration_invalid\"\n\t| \"native_default\";\n\nexport interface ModelToolProtocolResolution {\n\tprotocol: SimpleStreamOptions[\"textToolCallProtocol\"];\n\treasonCode: ModelToolProtocolReasonCode;\n\tvariantsTried?: readonly string[];\n}\n\n/**\n * Resolve the effective tool-call transport for any model and execution lane.\n *\n * Explicit settings win, followed by model metadata and then graded probe evidence. A probe-driven\n * text protocol is usable only with a current, recognized calibration; otherwise the model stays on\n * native calls for this turn. Callers use the reason code for diagnostics, but never reimplement the\n * precedence or silently substitute the default dialect.\n */\nexport function resolveModelToolProtocol(args: {\n\tmodel: Pick<Model<Api>, \"textToolCallProtocol\">;\n\tsettingsOverride?: boolean;\n\tadaptation: Pick<ModelAdaptationProfile, \"protocol\" | \"toolProbe\">;\n}): ModelToolProtocolResolution {\n\tif (args.settingsOverride === false) {\n\t\treturn { protocol: undefined, reasonCode: \"settings_disabled\" };\n\t}\n\tif (args.settingsOverride === true) {\n\t\treturn { protocol: true, reasonCode: \"settings_enabled\" };\n\t}\n\tif (args.model.textToolCallProtocol === true) {\n\t\treturn { protocol: true, reasonCode: \"model_enabled\" };\n\t}\n\tif (args.adaptation.toolProbe?.status !== \"text-protocol\") {\n\t\treturn { protocol: undefined, reasonCode: \"native_default\" };\n\t}\n\n\tconst calibration = args.adaptation.protocol;\n\tif (!calibration) {\n\t\treturn { protocol: undefined, reasonCode: \"probe_calibration_missing\" };\n\t}\n\tif (calibration.status === \"failed\") {\n\t\treturn {\n\t\t\tprotocol: undefined,\n\t\t\treasonCode: \"probe_calibration_failed\",\n\t\t\tvariantsTried: calibration.variantsTried,\n\t\t};\n\t}\n\tif (calibration.version !== MODEL_TOOL_PROTOCOL_VERSION || !isTextToolProtocolVariant(calibration.variant)) {\n\t\treturn { protocol: undefined, reasonCode: \"probe_calibration_invalid\" };\n\t}\n\treturn {\n\t\tprotocol: { variant: calibration.variant },\n\t\treasonCode: \"probe_calibrated\",\n\t};\n}\n"]}
1
+ {"version":3,"file":"model-tool-protocol.js","sourceRoot":"","sources":["../../src/core/model-tool-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,yBAAyB,EAAwC,MAAM,mBAAmB,CAAC;AAG9G,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAmB7C;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAIxC;IACA,IAAI,IAAI,CAAC,gBAAgB,KAAK,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AE,SAAS,EAAE,UAAU,EAAE,2BAA2B,EAAE,CAAC;IACzE,CAAC;IACD,OAAO;QACN,QAAQ,EAAE,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE;QAC1C,UAAU,EAAE,kBAAkB;KAC9B,CAAC;AACH,CAAC","sourcesContent":["import { type Api, isTextToolProtocolVariant, type Model, type SimpleStreamOptions } from \"@caupulican/pi-ai\";\nimport type { ModelAdaptationProfile } from \"./models/adaptation-store.ts\";\n\nexport const MODEL_TOOL_PROTOCOL_VERSION = 1;\n\nexport type ModelToolProtocolReasonCode =\n\t| \"settings_disabled\"\n\t| \"settings_enabled\"\n\t| \"model_enabled\"\n\t| \"probe_calibrated\"\n\t| \"probe_calibration_missing\"\n\t| \"probe_calibration_failed\"\n\t| \"probe_calibration_invalid\"\n\t| \"probe_native\"\n\t| \"native_default\";\n\nexport interface ModelToolProtocolResolution {\n\tprotocol: SimpleStreamOptions[\"textToolCallProtocol\"];\n\treasonCode: ModelToolProtocolReasonCode;\n\tvariantsTried?: readonly string[];\n}\n\n/**\n * Resolve the effective tool-call transport for any model and execution lane.\n *\n * A disabled setting and proven native capability always keep the native path active. Text-protocol\n * settings and model metadata apply only when native capability has not been proven. A probe-driven\n * text protocol is usable only with a current, recognized calibration; otherwise the model stays on\n * native calls for this turn. Callers use the reason code for diagnostics, but never reimplement the\n * precedence or silently substitute the default dialect.\n */\nexport function resolveModelToolProtocol(args: {\n\tmodel: Pick<Model<Api>, \"textToolCallProtocol\">;\n\tsettingsOverride?: boolean;\n\tadaptation: Pick<ModelAdaptationProfile, \"protocol\" | \"toolProbe\">;\n}): ModelToolProtocolResolution {\n\tif (args.settingsOverride === false) {\n\t\treturn { protocol: undefined, reasonCode: \"settings_disabled\" };\n\t}\n\tif (args.adaptation.toolProbe?.status === \"native\") {\n\t\treturn { protocol: undefined, reasonCode: \"probe_native\" };\n\t}\n\tif (args.settingsOverride === true) {\n\t\treturn { protocol: true, reasonCode: \"settings_enabled\" };\n\t}\n\tif (args.model.textToolCallProtocol === true) {\n\t\treturn { protocol: true, reasonCode: \"model_enabled\" };\n\t}\n\tif (args.adaptation.toolProbe?.status !== \"text-protocol\") {\n\t\treturn { protocol: undefined, reasonCode: \"native_default\" };\n\t}\n\n\tconst calibration = args.adaptation.protocol;\n\tif (!calibration) {\n\t\treturn { protocol: undefined, reasonCode: \"probe_calibration_missing\" };\n\t}\n\tif (calibration.status === \"failed\") {\n\t\treturn {\n\t\t\tprotocol: undefined,\n\t\t\treasonCode: \"probe_calibration_failed\",\n\t\t\tvariantsTried: calibration.variantsTried,\n\t\t};\n\t}\n\tif (calibration.version !== MODEL_TOOL_PROTOCOL_VERSION || !isTextToolProtocolVariant(calibration.variant)) {\n\t\treturn { protocol: undefined, reasonCode: \"probe_calibration_invalid\" };\n\t}\n\treturn {\n\t\tprotocol: { variant: calibration.variant },\n\t\treasonCode: \"probe_calibrated\",\n\t};\n}\n"]}
@@ -22,7 +22,13 @@ export interface RuntimeCommandRunnerLimits {
22
22
  * Output is retained as chunk tails and flattened once, after the child reaches a terminal state.
23
23
  */
24
24
  export declare function createRuntimeCommandRunner(limits: RuntimeCommandRunnerLimits): RuntimeCommandRunner;
25
- export declare function runtimeCommandAvailable(command: string): boolean;
25
+ type RuntimeCommandProbe = (command: string, args: string[], options: {
26
+ encoding: "utf8";
27
+ timeout: number;
28
+ }) => {
29
+ error?: unknown;
30
+ };
31
+ export declare function runtimeCommandAvailable(command: string, probe?: RuntimeCommandProbe): boolean;
26
32
  export declare function runtimeSleep(ms: number): Promise<void>;
27
33
  export type ManagedRuntimeChild = Pick<ChildProcess, "pid" | "kill" | "unref" | "on">;
28
34
  export interface ManagedRuntimeSpawnOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-process.d.ts","sourceRoot":"","sources":["../../../src/core/models/runtime-process.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAS,MAAM,oBAAoB,CAAC;AAG9D,OAAO,KAAK,EAAE,Q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AO,EAAE,MAAM,KAAK,OAAO,CAAC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,6EAA6E;AAC7E,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA4BnH"}
@@ -64,8 +64,10 @@ export function createRuntimeCommandRunner(limits) {
64
64
  }
65
65
  };
66
66
  }
67
- export function runtimeCommandAvailable(command) {
68
- return spawnProcessSync(command, ["--version"], { encoding: "utf8", timeout: 5_000 }).error === undefined;
67
+ export function runtimeCommandAvailable(command, probe = spawnProcessSync) {
68
+ // Node returns `undefined` on success; cross-spawn normalizes that field to `null` on Windows.
69
+ // Both are the absence of an error. A strict undefined check made every Windows probe fail.
70
+ return probe(command, ["--version"], { encoding: "utf8", timeout: 5_000 }).error == null;
69
71
  }
70
72
  export function runtimeSleep(ms) {
71
73
  return sleep(ms);