@caupulican/pi-adaptative 0.81.2 → 0.81.4

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 (115) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/core/agent-session.d.ts +2 -23
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +139 -147
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/background-lane-controller.d.ts +2 -0
  7. package/dist/core/background-lane-controller.d.ts.map +1 -1
  8. package/dist/core/background-lane-controller.js +3 -0
  9. package/dist/core/background-lane-controller.js.map +1 -1
  10. package/dist/core/billing-failover-controller.d.ts +38 -0
  11. package/dist/core/billing-failover-controller.d.ts.map +1 -0
  12. package/dist/core/billing-failover-controller.js +78 -0
  13. package/dist/core/billing-failover-controller.js.map +1 -0
  14. package/dist/core/billing-failover.d.ts +25 -0
  15. package/dist/core/billing-failover.d.ts.map +1 -0
  16. package/dist/core/billing-failover.js +21 -0
  17. package/dist/core/billing-failover.js.map +1 -0
  18. package/dist/core/compaction-support.d.ts +10 -1
  19. package/dist/core/compaction-support.d.ts.map +1 -1
  20. package/dist/core/compaction-support.js +68 -9
  21. package/dist/core/compaction-support.js.map +1 -1
  22. package/dist/core/context-pipeline.d.ts +1 -0
  23. package/dist/core/context-pipeline.d.ts.map +1 -1
  24. package/dist/core/context-pipeline.js +51 -14
  25. package/dist/core/context-pipeline.js.map +1 -1
  26. package/dist/core/export-html/index.d.ts.map +1 -1
  27. package/dist/core/export-html/index.js +9 -9
  28. package/dist/core/export-html/index.js.map +1 -1
  29. package/dist/core/failure-corpus.d.ts +49 -0
  30. package/dist/core/failure-corpus.d.ts.map +1 -0
  31. package/dist/core/failure-corpus.js +61 -0
  32. package/dist/core/failure-corpus.js.map +1 -0
  33. package/dist/core/model-router/config-diagnostics.d.ts +1 -1
  34. package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
  35. package/dist/core/model-router/config-diagnostics.js +29 -1
  36. package/dist/core/model-router/config-diagnostics.js.map +1 -1
  37. package/dist/core/model-router/fitness-gate.d.ts +25 -0
  38. package/dist/core/model-router/fitness-gate.d.ts.map +1 -0
  39. package/dist/core/model-router/fitness-gate.js +34 -0
  40. package/dist/core/model-router/fitness-gate.js.map +1 -0
  41. package/dist/core/model-router/status.d.ts +29 -1
  42. package/dist/core/model-router/status.d.ts.map +1 -1
  43. package/dist/core/model-router/status.js +31 -4
  44. package/dist/core/model-router/status.js.map +1 -1
  45. package/dist/core/model-router-controller.d.ts +10 -1
  46. package/dist/core/model-router-controller.d.ts.map +1 -1
  47. package/dist/core/model-router-controller.js +110 -27
  48. package/dist/core/model-router-controller.js.map +1 -1
  49. package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
  50. package/dist/core/models/default-model-suggestions.js +18 -0
  51. package/dist/core/models/default-model-suggestions.js.map +1 -1
  52. package/dist/core/runtime-builder.d.ts +16 -0
  53. package/dist/core/runtime-builder.d.ts.map +1 -1
  54. package/dist/core/runtime-builder.js +88 -1
  55. package/dist/core/runtime-builder.js.map +1 -1
  56. package/dist/core/scout-controller.d.ts +44 -0
  57. package/dist/core/scout-controller.d.ts.map +1 -0
  58. package/dist/core/scout-controller.js +165 -0
  59. package/dist/core/scout-controller.js.map +1 -0
  60. package/dist/core/settings-manager.d.ts +17 -0
  61. package/dist/core/settings-manager.d.ts.map +1 -1
  62. package/dist/core/settings-manager.js +47 -3
  63. package/dist/core/settings-manager.js.map +1 -1
  64. package/dist/core/slash-commands.d.ts.map +1 -1
  65. package/dist/core/slash-commands.js +4 -0
  66. package/dist/core/slash-commands.js.map +1 -1
  67. package/dist/core/tools/bash.d.ts.map +1 -1
  68. package/dist/core/tools/bash.js +6 -8
  69. package/dist/core/tools/bash.js.map +1 -1
  70. package/dist/core/tools/context-scout.d.ts +19 -0
  71. package/dist/core/tools/context-scout.d.ts.map +1 -0
  72. package/dist/core/tools/context-scout.js +47 -0
  73. package/dist/core/tools/context-scout.js.map +1 -0
  74. package/dist/core/tools/index.d.ts +1 -0
  75. package/dist/core/tools/index.d.ts.map +1 -1
  76. package/dist/core/tools/index.js +1 -0
  77. package/dist/core/tools/index.js.map +1 -1
  78. package/dist/main.d.ts.map +1 -1
  79. package/dist/main.js +1 -1
  80. package/dist/main.js.map +1 -1
  81. package/dist/modes/interactive/components/fitness-role-selector.d.ts +1 -1
  82. package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
  83. package/dist/modes/interactive/components/fitness-role-selector.js +5 -0
  84. package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
  85. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  86. package/dist/modes/interactive/components/settings-selector.js +77 -7
  87. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  88. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  89. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  90. package/dist/modes/interactive/interactive-mode.js +13 -0
  91. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  92. package/dist/modes/interactive/local-model-commands.d.ts +5 -2
  93. package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
  94. package/dist/modes/interactive/local-model-commands.js +129 -1
  95. package/dist/modes/interactive/local-model-commands.js.map +1 -1
  96. package/dist/modes/interactive/session-flow-commands.d.ts +16 -0
  97. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  98. package/dist/modes/interactive/session-flow-commands.js +32 -0
  99. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  100. package/docs/bug-ledger.md +113 -0
  101. package/docs/index.md +1 -0
  102. package/docs/models.md +9 -0
  103. package/docs/providers.md +14 -0
  104. package/docs/scout.md +73 -0
  105. package/docs/settings.md +16 -3
  106. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  107. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  108. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  109. package/examples/extensions/sandbox/package-lock.json +2 -2
  110. package/examples/extensions/sandbox/package.json +1 -1
  111. package/examples/extensions/with-deps/package-lock.json +2 -2
  112. package/examples/extensions/with-deps/package.json +1 -1
  113. package/examples/sdk/12-full-control.ts +1 -1
  114. package/npm-shrinkwrap.json +12 -12
  115. package/package.json +4 -4
@@ -10,8 +10,9 @@
10
10
  * fitness-role-assignment), which keep exercising interactive-mode's thin
11
11
  * wrappers unchanged.
12
12
  */
13
- import type { Component, Container, TUI } from "@caupulican/pi-tui";
13
+ import { type Component, Container, type TUI } from "@caupulican/pi-tui";
14
14
  import type { AgentSession } from "../../core/agent-session.ts";
15
+ import type { ModelRegistry } from "../../core/model-registry.ts";
15
16
  import type { OllamaRuntime } from "../../core/models/local-runtime.ts";
16
17
  import type { SettingsManager } from "../../core/settings-manager.ts";
17
18
  import { type FitnessRole } from "./components/fitness-role-selector.ts";
@@ -26,7 +27,9 @@ export interface AssignRoleHost {
26
27
  }
27
28
  /** Seam for the fitness probe + role-selector flow — matches the fitness-probe-gate test. */
28
29
  export interface RunFitnessHost {
29
- readonly session: Pick<AgentSession, "runModelFitness">;
30
+ readonly session: Pick<AgentSession, "runModelFitness"> & {
31
+ modelRegistry?: ModelRegistry;
32
+ };
30
33
  readonly settingsManager: SettingsManager;
31
34
  readonly chatContainer: Container;
32
35
  readonly ui: TUI;
@@ -1 +1 @@
1
- {"version":3,"file":"local-model-commands.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/local-model-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAGpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAIhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAGxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,KAAK,WAAW,EAA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AAG,OAAO,CAAC,IAAI,CAAC,CAwD/F;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB9E;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BzE;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BrH;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC3G;AAED,iGAAiG;AACjG,kGAA4F;AAC5F,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAiBtE;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAmBnE;AAED;kGACkG;AAClG,wBAAsB,mBAAmB,CACxC,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CAuCf;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAgCjG","sourcesContent":["/**\n * `/models` local-model lifecycle and `/fitness` probe/role-assignment flows\n * extracted from interactive-mode.\n *\n * `/models` is a USER-invoked local-model manager (list/add/remove/stop, never a\n * model-invokable tool); the fitness helpers probe a model on the current host\n * and land a shaped role. The server/selector flows share a `LocalModelHost`\n * seam, while `runFitnessAndAssign`/`assignFitnessRole` take narrow host shapes\n * matching their prototype-driven behaviour tests (fitness-probe-gate,\n * fitness-role-assignment), which keep exercising interactive-mode's thin\n * wrappers unchanged.\n */\n\nimport type { Component, Container, TUI } from \"@caupulican/pi-tui\";\nimport { Spacer, Text } from \"@caupulican/pi-tui\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport { DEFAULT_MODEL_SUGGESTIONS } from \"../../core/models/default-model-suggestions.ts\";\nimport { FitnessStore } from \"../../core/models/fitness-store.ts\";\nimport { registerLocalModel, unregisterLocalModel } from \"../../core/models/local-registration.ts\";\nimport type { OllamaRuntime } from \"../../core/models/local-runtime.ts\";\nimport { matchesInstalledLocalModel, normalizeModelSource } from \"../../core/models/model-ref.ts\";\nimport { formatModelFitnessReport, isProbeAllFailed } from \"../../core/research/model-fitness.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { type FitnessRole, FitnessRoleSelectorComponent } from \"./components/fitness-role-selector.ts\";\nimport { ModelSelectorComponent } from \"./components/model-selector.ts\";\nimport { ModelSuggestionSelectorComponent } from \"./components/model-suggestion-selector.ts\";\n\ntype SelectorFactory = (done: () => void) => { component: Component; focus: Component };\n\n/** Narrow seam for persisting a probed model's role — matches the fitness-role test. */\nexport interface AssignRoleHost {\n\treadonly settingsManager: SettingsManager;\n\tshowStatus(message: string): void;\n}\n\n/** Seam for the fitness probe + role-selector flow — matches the fitness-probe-gate test. */\nexport interface RunFitnessHost {\n\treadonly session: Pick<AgentSession, \"runModelFitness\">;\n\treadonly settingsManager: SettingsManager;\n\treadonly chatContainer: Container;\n\treadonly ui: TUI;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\n/** Full seam for the `/models` server/selector flows. */\nexport interface LocalModelHost {\n\treadonly localRuntime: OllamaRuntime;\n\treadonly session: AgentSession;\n\treadonly settingsManager: SettingsManager;\n\treadonly ui: TUI;\n\treadonly chatContainer: Container;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\n/**\n * /models — USER-invoked local model lifecycle (never a model-invokable tool):\n * list/add/remove/stop per local-model-lifecycle-design.md. Removal is explicit-only with\n * full disclosure; a pasted install command is parsed for its ref, never executed.\n */\nexport async function handleModelsCommand(host: LocalModelHost, argsText: string): Promise<void> {\n\tconst [action = \"list\", ...rest] = argsText.split(/\\s+/).filter(Boolean);\n\ttry {\n\t\tif (action === \"suggest\" || action === \"suggestions\") {\n\t\t\tshowModelSuggestionSelector(host);\n\t\t\treturn;\n\t\t}\n\t\tif (action === \"stop\") {\n\t\t\tconst stopped = host.localRuntime.stop();\n\t\t\thost.showStatus(\n\t\t\t\tstopped.stopped\n\t\t\t\t\t? \"Pi-managed local model server stopped (models remain installed).\"\n\t\t\t\t\t: \"No pi-managed server running (a system server, if any, is not pi's to stop).\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"add\") {\n\t\t\tconst rawRef = rest.join(\" \");\n\t\t\tif (!rawRef) {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t\"Usage: /models add <ollama-tag | hf.co/org/repo[:quant] | huggingface URL | pasted install command>\",\n\t\t\t\t);\n\t\t\t\thost.showStatus(\"Or start from a validated suggestion: /models suggest\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst source = normalizeModelSource(rawRef);\n\t\t\tif (source.type === \"rejected\") {\n\t\t\t\thost.showStatus(`Not added: ${source.reason}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"api\") {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t`${source.ref} is an API model — nothing to install. Configure auth for the provider, then probe it with /fitness ${source.ref}.`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait addLocalModel(host, source.pullRef);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"remove\") {\n\t\t\tconst ref = rest[0];\n\t\t\tconst confirmed = rest[1] === \"confirm\";\n\t\t\tif (!ref) {\n\t\t\t\thost.showStatus(\"Usage: /models remove <ref> confirm\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait removeLocalModel(host, ref, confirmed);\n\t\t\treturn;\n\t\t}\n\n\t\tawait listLocalModels(host);\n\t} catch (error) {\n\t\thost.showError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\nexport async function ensureLocalServer(host: LocalModelHost): Promise<boolean> {\n\tconst status = await host.localRuntime.detect();\n\tif (status.serverUp) return true;\n\tif (!status.binaryPath) {\n\t\tfor (const line of host.localRuntime.installGuide()) host.showStatus(line);\n\t\treturn false;\n\t}\n\thost.showStatus(\n\t\t`Starting local model server (${status.binarySource} binary, owned storage: ${status.ownedModelsDir})…`,\n\t);\n\tconst started = await host.localRuntime.start();\n\tif (!started.started) {\n\t\thost.showStatus(`Could not start the local server: ${started.reason}`);\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport async function listLocalModels(host: LocalModelHost): Promise<void> {\n\tconst status = await host.localRuntime.detect();\n\tif (!status.serverUp) {\n\t\tif (!status.binaryPath) {\n\t\t\tfor (const line of host.localRuntime.installGuide()) host.showStatus(line);\n\t\t\treturn;\n\t\t}\n\t\thost.showStatus(\n\t\t\t`Local server not running (binary: ${status.binarySource}). /models add starts it on demand; /fitness probes registered models.`,\n\t\t);\n\t\treturn;\n\t}\n\tconst models = await host.localRuntime.list();\n\tconst fitness = FitnessStore.forAgentDir(getAgentDir()).getForHost();\n\tconst lines = [\n\t\t`Local models (${status.managedByPi ? `pi-managed server, storage: ${status.ownedModelsDir}` : \"system server — storage owned by the system daemon\"}):`,\n\t\t...(models.length === 0\n\t\t\t? [\" (none installed — /models add <ref>, or /models suggest for a validated roster)\"]\n\t\t\t: []),\n\t\t...models.map((model) => {\n\t\t\tconst report = fitness.find((entry) => entry.model === `ollama/${model.name}`);\n\t\t\tconst gb = (model.sizeBytes / 1e9).toFixed(2);\n\t\t\tconst probe = report\n\t\t\t\t? `probed ${report.at.slice(0, 10)}: digest ${report.report.digest?.succeeded ?? \"?\"}/${report.report.digest?.total ?? \"?\"}, tool-calls ${report.report.toolCall.succeeded}/${report.report.toolCall.total}${report.report.tokensPerSecond ? `, ~${report.report.tokensPerSecond} tok/s` : \"\"}`\n\t\t\t\t: `unprobed — run /fitness ollama/${model.name}`;\n\t\t\treturn ` - ${model.name} (${gb} GB) · ${probe}`;\n\t\t}),\n\t\t\"Commands: /models add <ref> · /models remove <ref> confirm · /models stop\",\n\t];\n\tfor (const line of lines) host.showStatus(line);\n}\n\nexport async function addLocalModel(host: LocalModelHost, pullRef: string, preselectRole?: FitnessRole): Promise<void> {\n\tif (!(await ensureLocalServer(host))) return;\n\thost.showStatus(`Pulling ${pullRef}… (weights land in the server's model storage)`);\n\tlet lastShown = 0;\n\tconst pulled = await host.localRuntime.pull(pullRef, (progress) => {\n\t\tconst now = Date.now();\n\t\tif (now - lastShown > 2000) {\n\t\t\tlastShown = now;\n\t\t\thost.showStatus(` ${pullRef}: ${progress}`);\n\t\t}\n\t});\n\tif (!pulled.ok) {\n\t\thost.showStatus(`Pull failed: ${pulled.error}`);\n\t\treturn;\n\t}\n\tconst registration = registerLocalModel({\n\t\tagentDir: getAgentDir(),\n\t\tref: pullRef,\n\t\tbaseUrl: host.localRuntime.baseUrl,\n\t});\n\tif (!registration.ok) {\n\t\thost.showStatus(`Pulled, but not auto-registered: ${registration.reason}`);\n\t\tif (registration.manualSnippet) {\n\t\t\thost.showStatus(`Add this to ${registration.modelsJsonPath} yourself:\\n${registration.manualSnippet}`);\n\t\t}\n\t\treturn;\n\t}\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(`${pullRef} installed and registered as ollama/${pullRef}. Probing fitness…`);\n\tawait runFitnessAndAssign(host, `ollama/${pullRef}`, preselectRole);\n}\n\nexport async function removeLocalModel(host: LocalModelHost, ref: string, confirmed: boolean): Promise<void> {\n\tconst status = await host.localRuntime.detect();\n\tif (!status.serverUp) {\n\t\thost.showStatus(\"Local server not running — start it (any /models action) before removing.\");\n\t\treturn;\n\t}\n\tconst models = await host.localRuntime.list();\n\tconst target = models.find((model) => matchesInstalledLocalModel(ref, model.name));\n\tif (!target) {\n\t\thost.showStatus(\n\t\t\t`${ref} is not installed. Installed: ${models.map((model) => model.name).join(\", \") || \"(none)\"}`,\n\t\t);\n\t\treturn;\n\t}\n\tif (!confirmed) {\n\t\t// EXPLICIT USER ACTION ONLY: full disclosure, then require the confirm token.\n\t\tconst gb = (target.sizeBytes / 1e9).toFixed(2);\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t`Removing ${ref} will delete:`,\n\t\t\t\t` - model weights (${gb} GB) from ${status.managedByPi ? status.ownedModelsDir : \"the system server's storage\"}`,\n\t\t\t\t` - the ollama/${ref} entry in models.json`,\n\t\t\t\t` - its cached fitness report for this host`,\n\t\t\t\t`Run: /models remove ${ref} confirm`,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\tconst removed = await host.localRuntime.remove(ref);\n\tif (!removed.ok) {\n\t\thost.showStatus(`Remove failed: ${removed.error}`);\n\t\treturn;\n\t}\n\tunregisterLocalModel({ agentDir: getAgentDir(), ref });\n\tFitnessStore.forAgentDir(getAgentDir()).remove(`ollama/${ref}`);\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(`${ref} removed: weights deleted, registration and fitness report dropped.`);\n}\n\n/** /fitness with no args: pick a model from the configured registry, probe it, assign a role. */\n/** Pick a validated suggestion → install it → probe on this host → land its shaped role. */\nexport function showModelSuggestionSelector(host: LocalModelHost): void {\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelSuggestionSelectorComponent(\n\t\t\tDEFAULT_MODEL_SUGGESTIONS,\n\t\t\tasync (suggestion) => {\n\t\t\t\tdone();\n\t\t\t\t// The shaped role rides along so the post-probe selector lands on it pre-selected;\n\t\t\t\t// non-tool-callers carry curator/judge/none, never executor, so this can't footgun.\n\t\t\t\tawait addLocalModel(host, suggestion.pullRef, suggestion.assignRole);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\nexport function showFitnessModelSelector(host: LocalModelHost): void {\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelSelectorComponent(\n\t\t\thost.ui,\n\t\t\thost.session.model,\n\t\t\thost.settingsManager,\n\t\t\thost.session.modelRegistry,\n\t\t\thost.session.scopedModels,\n\t\t\tasync (model) => {\n\t\t\t\tdone();\n\t\t\t\tawait runFitnessAndAssign(host, `${model.provider}/${model.id}`);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\n/** Probe a model's fitness, show the report, then offer one-step role assignment. When the model\n * came from a validated suggestion, `preselectRole` lands its shaped role already highlighted. */\nexport async function runFitnessAndAssign(\n\thost: RunFitnessHost,\n\tmodelRef: string,\n\tpreselectRole?: FitnessRole,\n): Promise<void> {\n\thost.showStatus(`Model fitness probe running on ${modelRef}… (6 surfaces; local models may take a few minutes)`);\n\ttry {\n\t\tconst outcome = await host.session.runModelFitness({ model: modelRef });\n\t\tif (!outcome.started) {\n\t\t\thost.showStatus(`Model fitness skipped: ${outcome.skipReason}`);\n\t\t\treturn;\n\t\t}\n\t\thost.chatContainer.addChild(new Spacer(1));\n\t\thost.chatContainer.addChild(new Text(formatModelFitnessReport(outcome.model, outcome.report), 1, 0));\n\t\thost.ui.requestRender();\n\t\t// Validate-before-load: zero successes on every probed surface means the model cannot\n\t\t// drive any of the harness's subagent contracts on this host — refuse adoption instead\n\t\t// of landing a role selector the user might reflexively confirm (this is the reported\n\t\t// bug: a 0/3-everywhere model still got set as judge model and saved to Model Router).\n\t\tif (isProbeAllFailed(outcome.report)) {\n\t\t\thost.showStatus(\n\t\t\t\t`${outcome.model} failed the fitness probe on all surfaces — not configured. Use /model to set it manually if you accept the risk.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\thost.showSelector((done) => {\n\t\t\tconst selector = new FitnessRoleSelectorComponent(\n\t\t\t\toutcome.model,\n\t\t\t\t(role) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tassignFitnessRole(host, outcome.model, role);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t},\n\t\t\t\tpreselectRole,\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector };\n\t\t});\n\t} catch (error) {\n\t\thost.showError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\n/** Persist a role assignment from the post-probe selector into the matching settings. */\nexport function assignFitnessRole(host: AssignRoleHost, modelRef: string, role: FitnessRole): void {\n\tif (role === \"none\") {\n\t\thost.showStatus(`Fitness result for ${modelRef} saved. Assign a role later from /settings.`);\n\t\treturn;\n\t}\n\tif (role === \"curator\") {\n\t\tconst current = host.settingsManager.getContextCurationSettings();\n\t\thost.settingsManager.setContextCurationSettings({ ...current, enabled: true, model: modelRef });\n\t\thost.showStatus(`Context curation enabled with ${modelRef} as the curator.`);\n\t\treturn;\n\t}\n\tif (role === \"executor\") {\n\t\tconst router = host.settingsManager.getModelRouterSettings();\n\t\thost.settingsManager.setModelRouterSettings({ ...router, executorModel: modelRef });\n\t\tconst hint = router.enabled ? \"\" : \" Model router is currently disabled — enable it in /settings → Model Router.\";\n\t\thost.showStatus(`${modelRef} set as the toolkit executor (direct Level-0 hits route to it).${hint}`);\n\t\treturn;\n\t}\n\tconst router = host.settingsManager.getModelRouterSettings();\n\tconst field =\n\t\trole === \"router-cheap\"\n\t\t\t? \"cheapModel\"\n\t\t\t: role === \"router-medium\"\n\t\t\t\t? \"mediumModel\"\n\t\t\t\t: role === \"router-expensive\"\n\t\t\t\t\t? \"expensiveModel\"\n\t\t\t\t\t: role === \"judge\"\n\t\t\t\t\t\t? \"judgeModel\"\n\t\t\t\t\t\t: \"learningModel\";\n\thost.settingsManager.setModelRouterSettings({ ...router, [field]: modelRef });\n\tconst hint = router.enabled ? \"\" : \" Model router is currently disabled — enable it in /settings → Model Router.\";\n\thost.showStatus(`${modelRef} set as ${role.replace(\"router-\", \"router \")} model.${hint}`);\n}\n"]}
1
+ {"version":3,"file":"local-model-commands.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/local-model-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,EACN,KAAK,SAAS,EACd,SAAS,EAMT,KAAK,GAAG,EACR,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAMlE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAGxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,EAAE,KAAK,WAAW,EAAgC,MAAM,uCAAuC,CAAC;AAKvG,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAoCxF,0FAAwF;AACxF,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,+FAA6F;AAC7F,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,iBAAiB,CAAC,GAAG;QAAE,aAAa,CAAC,EAAE,aAAa,CAAA;KAAE,CAAC;IAC5F,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC;IACjB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,SAAS,CAAC,OAAO,EAAE,MAAM,GAA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kGACkG;AAClG,wBAAsB,mBAAmB,CACxC,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CAkDf;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAqCjG","sourcesContent":["/**\n * `/models` local-model lifecycle and `/fitness` probe/role-assignment flows\n * extracted from interactive-mode.\n *\n * `/models` is a USER-invoked local-model manager (list/add/remove/stop, never a\n * model-invokable tool); the fitness helpers probe a model on the current host\n * and land a shaped role. The server/selector flows share a `LocalModelHost`\n * seam, while `runFitnessAndAssign`/`assignFitnessRole` take narrow host shapes\n * matching their prototype-driven behaviour tests (fitness-probe-gate,\n * fitness-role-assignment), which keep exercising interactive-mode's thin\n * wrappers unchanged.\n */\n\nimport type { ThinkingLevel } from \"@caupulican/pi-agent-core\";\nimport { getSupportedThinkingLevels } from \"@caupulican/pi-ai\";\nimport {\n\ttype Component,\n\tContainer,\n\ttype SelectItem,\n\tSelectList,\n\ttype SelectListLayoutOptions,\n\tSpacer,\n\tText,\n\ttype TUI,\n} from \"@caupulican/pi-tui\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { resolveCliModel } from \"../../core/model-resolver.ts\";\nimport { evaluateSurfaceFitness } from \"../../core/model-router/fitness-gate.ts\";\nimport { DEFAULT_MODEL_SUGGESTIONS } from \"../../core/models/default-model-suggestions.ts\";\nimport { FitnessStore } from \"../../core/models/fitness-store.ts\";\nimport { registerLocalModel, unregisterLocalModel } from \"../../core/models/local-registration.ts\";\nimport type { OllamaRuntime } from \"../../core/models/local-runtime.ts\";\nimport { matchesInstalledLocalModel, normalizeModelSource } from \"../../core/models/model-ref.ts\";\nimport { formatModelFitnessReport, isProbeAllFailed } from \"../../core/research/model-fitness.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { DynamicBorder } from \"./components/dynamic-border.ts\";\nimport { type FitnessRole, FitnessRoleSelectorComponent } from \"./components/fitness-role-selector.ts\";\nimport { ModelSelectorComponent } from \"./components/model-selector.ts\";\nimport { ModelSuggestionSelectorComponent } from \"./components/model-suggestion-selector.ts\";\nimport { getSelectListTheme } from \"./theme/theme.ts\";\n\ntype SelectorFactory = (done: () => void) => { component: Component; focus: Component };\n\nconst MODEL_ROUTER_THINKING_SELECT_LIST_LAYOUT: SelectListLayoutOptions = {\n\tminPrimaryColumnWidth: 12,\n\tmaxPrimaryColumnWidth: 32,\n};\n\nconst MODEL_ROUTER_THINKING_INHERIT_VALUE = \"__inherit_model_router_thinking__\";\nconst MODEL_ROUTER_THINKING_INHERIT_LABEL = \"(inherit)\";\n\nconst THINKING_LEVEL_DESCRIPTIONS: Record<ThinkingLevel, string> = {\n\toff: \"No reasoning\",\n\tminimal: \"Very brief reasoning (~1k tokens)\",\n\tlow: \"Light reasoning (~2k tokens)\",\n\tmedium: \"Moderate reasoning (~8k tokens)\",\n\thigh: \"Deep reasoning (~16k tokens)\",\n\txhigh: \"Maximum reasoning (~32k tokens)\",\n};\n\nconst MODEL_ROUTER_THINKING_FALLBACK_LEVELS: readonly ThinkingLevel[] = [\n\t\"off\",\n\t\"minimal\",\n\t\"low\",\n\t\"medium\",\n\t\"high\",\n\t\"xhigh\",\n];\n\ntype RouterThinkingLevel = ThinkingLevel | typeof MODEL_ROUTER_THINKING_INHERIT_VALUE;\ntype ModelRouterThinkingField =\n\t| \"cheapThinking\"\n\t| \"mediumThinking\"\n\t| \"expensiveThinking\"\n\t| \"executorThinking\"\n\t| \"judgeThinking\";\n\n/** Narrow seam for persisting a probed model's role — matches the fitness-role test. */\nexport interface AssignRoleHost {\n\treadonly settingsManager: SettingsManager;\n\tshowStatus(message: string): void;\n}\n\n/** Seam for the fitness probe + role-selector flow — matches the fitness-probe-gate test. */\nexport interface RunFitnessHost {\n\treadonly session: Pick<AgentSession, \"runModelFitness\"> & { modelRegistry?: ModelRegistry };\n\treadonly settingsManager: SettingsManager;\n\treadonly chatContainer: Container;\n\treadonly ui: TUI;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\n/** Full seam for the `/models` server/selector flows. */\nexport interface LocalModelHost {\n\treadonly localRuntime: OllamaRuntime;\n\treadonly session: AgentSession;\n\treadonly settingsManager: SettingsManager;\n\treadonly ui: TUI;\n\treadonly chatContainer: Container;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\nclass ModelRouterThinkingSelectorComponent extends Container {\n\tprivate selectList: SelectList;\n\n\tconstructor(\n\t\tcurrentLevel: RouterThinkingLevel,\n\t\tavailableLevels: ThinkingLevel[],\n\t\tonSelect: (level: RouterThinkingLevel) => void,\n\t\tonCancel: () => void,\n\t) {\n\t\tsuper();\n\n\t\tconst thinkingOptions: SelectItem[] = [\n\t\t\t{\n\t\t\t\tvalue: MODEL_ROUTER_THINKING_INHERIT_VALUE,\n\t\t\t\tlabel: MODEL_ROUTER_THINKING_INHERIT_LABEL,\n\t\t\t\tdescription: \"Use current session default for this tier.\",\n\t\t\t},\n\t\t\t...availableLevels.map((level) => ({\n\t\t\t\tvalue: level,\n\t\t\t\tlabel: level,\n\t\t\t\tdescription: THINKING_LEVEL_DESCRIPTIONS[level],\n\t\t\t})),\n\t\t];\n\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.selectList = new SelectList(\n\t\t\tthinkingOptions,\n\t\t\tthinkingOptions.length,\n\t\t\tgetSelectListTheme(),\n\t\t\tMODEL_ROUTER_THINKING_SELECT_LIST_LAYOUT,\n\t\t);\n\n\t\tconst index = thinkingOptions.findIndex((item) => item.value === currentLevel);\n\t\tif (index !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(index);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tonSelect(item.value as RouterThinkingLevel);\n\t\t};\n\t\tthis.selectList.onCancel = () => {\n\t\t\tonCancel();\n\t\t};\n\n\t\tthis.addChild(this.selectList);\n\t\tthis.addChild(new DynamicBorder());\n\t}\n}\n/**\n * /models — USER-invoked local model lifecycle (never a model-invokable tool):\n * list/add/remove/stop per local-model-lifecycle-design.md. Removal is explicit-only with\n * full disclosure; a pasted install command is parsed for its ref, never executed.\n */\nexport async function handleModelsCommand(host: LocalModelHost, argsText: string): Promise<void> {\n\tconst [action = \"list\", ...rest] = argsText.split(/\\s+/).filter(Boolean);\n\ttry {\n\t\tif (action === \"suggest\" || action === \"suggestions\") {\n\t\t\tshowModelSuggestionSelector(host);\n\t\t\treturn;\n\t\t}\n\t\tif (action === \"stop\") {\n\t\t\tconst stopped = host.localRuntime.stop();\n\t\t\thost.showStatus(\n\t\t\t\tstopped.stopped\n\t\t\t\t\t? \"Pi-managed local model server stopped (models remain installed).\"\n\t\t\t\t\t: \"No pi-managed server running (a system server, if any, is not pi's to stop).\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"add\") {\n\t\t\tconst rawRef = rest.join(\" \");\n\t\t\tif (!rawRef) {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t\"Usage: /models add <ollama-tag | hf.co/org/repo[:quant] | huggingface URL | pasted install command>\",\n\t\t\t\t);\n\t\t\t\thost.showStatus(\"Or start from a validated suggestion: /models suggest\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst source = normalizeModelSource(rawRef);\n\t\t\tif (source.type === \"rejected\") {\n\t\t\t\thost.showStatus(`Not added: ${source.reason}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"api\") {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t`${source.ref} is an API model — nothing to install. Configure auth for the provider, then probe it with /fitness ${source.ref}.`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait addLocalModel(host, source.pullRef);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"remove\") {\n\t\t\tconst ref = rest[0];\n\t\t\tconst confirmed = rest[1] === \"confirm\";\n\t\t\tif (!ref) {\n\t\t\t\thost.showStatus(\"Usage: /models remove <ref> confirm\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait removeLocalModel(host, ref, confirmed);\n\t\t\treturn;\n\t\t}\n\n\t\tawait listLocalModels(host);\n\t} catch (error) {\n\t\thost.showError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\nexport async function ensureLocalServer(host: LocalModelHost): Promise<boolean> {\n\tconst status = await host.localRuntime.detect();\n\tif (status.serverUp) return true;\n\tif (!status.binaryPath) {\n\t\tfor (const line of host.localRuntime.installGuide()) host.showStatus(line);\n\t\treturn false;\n\t}\n\thost.showStatus(\n\t\t`Starting local model server (${status.binarySource} binary, owned storage: ${status.ownedModelsDir})…`,\n\t);\n\tconst started = await host.localRuntime.start();\n\tif (!started.started) {\n\t\thost.showStatus(`Could not start the local server: ${started.reason}`);\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport async function listLocalModels(host: LocalModelHost): Promise<void> {\n\tconst status = await host.localRuntime.detect();\n\tif (!status.serverUp) {\n\t\tif (!status.binaryPath) {\n\t\t\tfor (const line of host.localRuntime.installGuide()) host.showStatus(line);\n\t\t\treturn;\n\t\t}\n\t\thost.showStatus(\n\t\t\t`Local server not running (binary: ${status.binarySource}). /models add starts it on demand; /fitness probes registered models.`,\n\t\t);\n\t\treturn;\n\t}\n\tconst models = await host.localRuntime.list();\n\tconst fitness = FitnessStore.forAgentDir(getAgentDir()).getForHost();\n\tconst lines = [\n\t\t`Local models (${status.managedByPi ? `pi-managed server, storage: ${status.ownedModelsDir}` : \"system server — storage owned by the system daemon\"}):`,\n\t\t...(models.length === 0\n\t\t\t? [\" (none installed — /models add <ref>, or /models suggest for a validated roster)\"]\n\t\t\t: []),\n\t\t...models.map((model) => {\n\t\t\tconst report = fitness.find((entry) => entry.model === `ollama/${model.name}`);\n\t\t\tconst gb = (model.sizeBytes / 1e9).toFixed(2);\n\t\t\tconst probe = report\n\t\t\t\t? `probed ${report.at.slice(0, 10)}: digest ${report.report.digest?.succeeded ?? \"?\"}/${report.report.digest?.total ?? \"?\"}, tool-calls ${report.report.toolCall.succeeded}/${report.report.toolCall.total}${report.report.tokensPerSecond ? `, ~${report.report.tokensPerSecond} tok/s` : \"\"}`\n\t\t\t\t: `unprobed — run /fitness ollama/${model.name}`;\n\t\t\treturn ` - ${model.name} (${gb} GB) · ${probe}`;\n\t\t}),\n\t\t\"Commands: /models add <ref> · /models remove <ref> confirm · /models stop\",\n\t];\n\tfor (const line of lines) host.showStatus(line);\n}\n\nexport async function addLocalModel(host: LocalModelHost, pullRef: string, preselectRole?: FitnessRole): Promise<void> {\n\tif (!(await ensureLocalServer(host))) return;\n\thost.showStatus(`Pulling ${pullRef}… (weights land in the server's model storage)`);\n\tlet lastShown = 0;\n\tconst pulled = await host.localRuntime.pull(pullRef, (progress) => {\n\t\tconst now = Date.now();\n\t\tif (now - lastShown > 2000) {\n\t\t\tlastShown = now;\n\t\t\thost.showStatus(` ${pullRef}: ${progress}`);\n\t\t}\n\t});\n\tif (!pulled.ok) {\n\t\thost.showStatus(`Pull failed: ${pulled.error}`);\n\t\treturn;\n\t}\n\tconst registration = registerLocalModel({\n\t\tagentDir: getAgentDir(),\n\t\tref: pullRef,\n\t\tbaseUrl: host.localRuntime.baseUrl,\n\t});\n\tif (!registration.ok) {\n\t\thost.showStatus(`Pulled, but not auto-registered: ${registration.reason}`);\n\t\tif (registration.manualSnippet) {\n\t\t\thost.showStatus(`Add this to ${registration.modelsJsonPath} yourself:\\n${registration.manualSnippet}`);\n\t\t}\n\t\treturn;\n\t}\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(`${pullRef} installed and registered as ollama/${pullRef}. Probing fitness…`);\n\tawait runFitnessAndAssign(host, `ollama/${pullRef}`, preselectRole);\n}\n\nexport async function removeLocalModel(host: LocalModelHost, ref: string, confirmed: boolean): Promise<void> {\n\tconst status = await host.localRuntime.detect();\n\tif (!status.serverUp) {\n\t\thost.showStatus(\"Local server not running — start it (any /models action) before removing.\");\n\t\treturn;\n\t}\n\tconst models = await host.localRuntime.list();\n\tconst target = models.find((model) => matchesInstalledLocalModel(ref, model.name));\n\tif (!target) {\n\t\thost.showStatus(\n\t\t\t`${ref} is not installed. Installed: ${models.map((model) => model.name).join(\", \") || \"(none)\"}`,\n\t\t);\n\t\treturn;\n\t}\n\tif (!confirmed) {\n\t\t// EXPLICIT USER ACTION ONLY: full disclosure, then require the confirm token.\n\t\tconst gb = (target.sizeBytes / 1e9).toFixed(2);\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t`Removing ${ref} will delete:`,\n\t\t\t\t` - model weights (${gb} GB) from ${status.managedByPi ? status.ownedModelsDir : \"the system server's storage\"}`,\n\t\t\t\t` - the ollama/${ref} entry in models.json`,\n\t\t\t\t` - its cached fitness report for this host`,\n\t\t\t\t`Run: /models remove ${ref} confirm`,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\tconst removed = await host.localRuntime.remove(ref);\n\tif (!removed.ok) {\n\t\thost.showStatus(`Remove failed: ${removed.error}`);\n\t\treturn;\n\t}\n\tunregisterLocalModel({ agentDir: getAgentDir(), ref });\n\tFitnessStore.forAgentDir(getAgentDir()).remove(`ollama/${ref}`);\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(`${ref} removed: weights deleted, registration and fitness report dropped.`);\n}\n\n/** /fitness with no args: pick a model from the configured registry, probe it, assign a role. */\n/** Pick a validated suggestion → install it → probe on this host → land its shaped role. */\nexport function showModelSuggestionSelector(host: LocalModelHost): void {\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelSuggestionSelectorComponent(\n\t\t\tDEFAULT_MODEL_SUGGESTIONS,\n\t\t\tasync (suggestion) => {\n\t\t\t\tdone();\n\t\t\t\t// The shaped role rides along so the post-probe selector lands on it pre-selected;\n\t\t\t\t// non-tool-callers carry curator/judge/none, never executor, so this can't footgun.\n\t\t\t\tawait addLocalModel(host, suggestion.pullRef, suggestion.assignRole);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\nexport function showFitnessModelSelector(host: LocalModelHost): void {\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelSelectorComponent(\n\t\t\thost.ui,\n\t\t\thost.session.model,\n\t\t\thost.settingsManager,\n\t\t\thost.session.modelRegistry,\n\t\t\thost.session.scopedModels,\n\t\t\tasync (model) => {\n\t\t\t\tdone();\n\t\t\t\tawait runFitnessAndAssign(host, `${model.provider}/${model.id}`);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\n/** Resolve the routed model's supported thinking levels for a fitness-assignment flow, with a safe fallback. */\nfunction getModelThinkingLevels(modelRegistry: ModelRegistry | undefined, modelRef: string): ThinkingLevel[] {\n\tif (!modelRegistry) {\n\t\treturn [...MODEL_ROUTER_THINKING_FALLBACK_LEVELS];\n\t}\n\tconst resolved = resolveCliModel({ cliModel: modelRef, modelRegistry });\n\tif (!resolved.model) {\n\t\treturn [...MODEL_ROUTER_THINKING_FALLBACK_LEVELS];\n\t}\n\treturn getSupportedThinkingLevels(resolved.model);\n}\n\nfunction getModelRouterThinkingField(role: FitnessRole): ModelRouterThinkingField | undefined {\n\tif (role === \"router-cheap\") {\n\t\treturn \"cheapThinking\";\n\t}\n\tif (role === \"router-medium\") {\n\t\treturn \"mediumThinking\";\n\t}\n\tif (role === \"router-expensive\") {\n\t\treturn \"expensiveThinking\";\n\t}\n\tif (role === \"executor\") {\n\t\treturn \"executorThinking\";\n\t}\n\tif (role === \"judge\") {\n\t\treturn \"judgeThinking\";\n\t}\n\treturn undefined;\n}\n\nfunction promptForModelRouterThinking(host: RunFitnessHost, modelRef: string, role: FitnessRole): void {\n\tconst thinkingField = getModelRouterThinkingField(role);\n\tif (!thinkingField) {\n\t\treturn;\n\t}\n\n\tconst modelRegistry = host.session.modelRegistry;\n\tconst availableLevels = getModelThinkingLevels(modelRegistry, modelRef);\n\tconst settings = host.settingsManager.getModelRouterSettings();\n\tconst configuredThinking = settings[thinkingField];\n\tconst currentThinking =\n\t\tconfiguredThinking && availableLevels.includes(configuredThinking)\n\t\t\t? configuredThinking\n\t\t\t: MODEL_ROUTER_THINKING_INHERIT_VALUE;\n\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelRouterThinkingSelectorComponent(\n\t\t\tcurrentThinking,\n\t\t\tavailableLevels,\n\t\t\t(level) => {\n\t\t\t\tdone();\n\t\t\t\thost.settingsManager.setModelRouterSettings({\n\t\t\t\t\t...settings,\n\t\t\t\t\t[thinkingField]: level === MODEL_ROUTER_THINKING_INHERIT_VALUE ? undefined : level,\n\t\t\t\t});\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\n/** Probe a model's fitness, show the report, then offer one-step role assignment. When the model\n * came from a validated suggestion, `preselectRole` lands its shaped role already highlighted. */\nexport async function runFitnessAndAssign(\n\thost: RunFitnessHost,\n\tmodelRef: string,\n\tpreselectRole?: FitnessRole,\n): Promise<void> {\n\thost.showStatus(`Model fitness probe running on ${modelRef}… (6 surfaces; local models may take a few minutes)`);\n\ttry {\n\t\tconst outcome = await host.session.runModelFitness({ model: modelRef });\n\t\tif (!outcome.started) {\n\t\t\thost.showStatus(`Model fitness skipped: ${outcome.skipReason}`);\n\t\t\treturn;\n\t\t}\n\t\thost.chatContainer.addChild(new Spacer(1));\n\t\thost.chatContainer.addChild(new Text(formatModelFitnessReport(outcome.model, outcome.report), 1, 0));\n\t\thost.ui.requestRender();\n\t\t// Validate-before-load: zero successes on every probed surface means the model cannot\n\t\t// drive any of the harness's subagent contracts on this host — refuse adoption instead\n\t\t// of landing a role selector the user might reflexively confirm (this is the reported\n\t\t// bug: a 0/3-everywhere model still got set as judge model and saved to Model Router).\n\t\tif (isProbeAllFailed(outcome.report)) {\n\t\t\thost.showStatus(\n\t\t\t\t`${outcome.model} failed the fitness probe on all surfaces — not configured. Use /model to set it manually if you accept the risk.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\thost.showSelector((done) => {\n\t\t\tconst selector = new FitnessRoleSelectorComponent(\n\t\t\t\toutcome.model,\n\t\t\t\t(role) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tif (role === \"scout\") {\n\t\t\t\t\t\tconst verdict = evaluateSurfaceFitness(\"scout_auto\", outcome.report);\n\t\t\t\t\t\tif (!verdict.fit) {\n\t\t\t\t\t\t\tconst reason = verdict.reason === \"lane_failed\" ? `failed ${verdict.lane}` : \"was not probed\";\n\t\t\t\t\t\t\thost.showStatus(\n\t\t\t\t\t\t\t\t`${outcome.model} not assigned as scout: ${reason} on the scout_auto fitness exam. Use the docs/scout.md Modelfile recipe, then rerun /fitness.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tassignFitnessRole(host, outcome.model, role);\n\t\t\t\t\tpromptForModelRouterThinking(host, outcome.model, role);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t},\n\t\t\t\tpreselectRole,\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector };\n\t\t});\n\t} catch (error) {\n\t\thost.showError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\n/** Persist a role assignment from the post-probe selector into the matching settings. */\nexport function assignFitnessRole(host: AssignRoleHost, modelRef: string, role: FitnessRole): void {\n\tif (role === \"none\") {\n\t\thost.showStatus(`Fitness result for ${modelRef} saved. Assign a role later from /settings.`);\n\t\treturn;\n\t}\n\tif (role === \"curator\") {\n\t\tconst current = host.settingsManager.getContextCurationSettings();\n\t\thost.settingsManager.setContextCurationSettings({ ...current, enabled: true, model: modelRef });\n\t\thost.showStatus(`Context curation enabled with ${modelRef} as the curator.`);\n\t\treturn;\n\t}\n\tif (role === \"executor\") {\n\t\tconst router = host.settingsManager.getModelRouterSettings();\n\t\thost.settingsManager.setModelRouterSettings({ ...router, executorModel: modelRef });\n\t\tconst hint = router.enabled ? \"\" : \" Model router is currently disabled — enable it in /settings → Model Router.\";\n\t\thost.showStatus(`${modelRef} set as the toolkit executor (direct Level-0 hits route to it).${hint}`);\n\t\treturn;\n\t}\n\tif (role === \"scout\") {\n\t\thost.settingsManager.setScoutSettings({ enabled: true, model: modelRef });\n\t\thost.showStatus(`${modelRef} set as the repository scout (context_scout enabled).`);\n\t\treturn;\n\t}\n\tconst router = host.settingsManager.getModelRouterSettings();\n\tconst field =\n\t\trole === \"router-cheap\"\n\t\t\t? \"cheapModel\"\n\t\t\t: role === \"router-medium\"\n\t\t\t\t? \"mediumModel\"\n\t\t\t\t: role === \"router-expensive\"\n\t\t\t\t\t? \"expensiveModel\"\n\t\t\t\t\t: role === \"judge\"\n\t\t\t\t\t\t? \"judgeModel\"\n\t\t\t\t\t\t: \"learningModel\";\n\thost.settingsManager.setModelRouterSettings({ ...router, [field]: modelRef });\n\tconst hint = router.enabled ? \"\" : \" Model router is currently disabled — enable it in /settings → Model Router.\";\n\thost.showStatus(`${modelRef} set as ${role.replace(\"router-\", \"router \")} model.${hint}`);\n}\n"]}
@@ -10,16 +10,75 @@
10
10
  * fitness-role-assignment), which keep exercising interactive-mode's thin
11
11
  * wrappers unchanged.
12
12
  */
13
- import { Spacer, Text } from "@caupulican/pi-tui";
13
+ import { getSupportedThinkingLevels } from "@caupulican/pi-ai";
14
+ import { Container, SelectList, Spacer, Text, } from "@caupulican/pi-tui";
14
15
  import { getAgentDir } from "../../config.js";
16
+ import { resolveCliModel } from "../../core/model-resolver.js";
17
+ import { evaluateSurfaceFitness } from "../../core/model-router/fitness-gate.js";
15
18
  import { DEFAULT_MODEL_SUGGESTIONS } from "../../core/models/default-model-suggestions.js";
16
19
  import { FitnessStore } from "../../core/models/fitness-store.js";
17
20
  import { registerLocalModel, unregisterLocalModel } from "../../core/models/local-registration.js";
18
21
  import { matchesInstalledLocalModel, normalizeModelSource } from "../../core/models/model-ref.js";
19
22
  import { formatModelFitnessReport, isProbeAllFailed } from "../../core/research/model-fitness.js";
23
+ import { DynamicBorder } from "./components/dynamic-border.js";
20
24
  import { FitnessRoleSelectorComponent } from "./components/fitness-role-selector.js";
21
25
  import { ModelSelectorComponent } from "./components/model-selector.js";
22
26
  import { ModelSuggestionSelectorComponent } from "./components/model-suggestion-selector.js";
27
+ import { getSelectListTheme } from "./theme/theme.js";
28
+ const MODEL_ROUTER_THINKING_SELECT_LIST_LAYOUT = {
29
+ minPrimaryColumnWidth: 12,
30
+ maxPrimaryColumnWidth: 32,
31
+ };
32
+ const MODEL_ROUTER_THINKING_INHERIT_VALUE = "__inherit_model_router_thinking__";
33
+ const MODEL_ROUTER_THINKING_INHERIT_LABEL = "(inherit)";
34
+ const THINKING_LEVEL_DESCRIPTIONS = {
35
+ off: "No reasoning",
36
+ minimal: "Very brief reasoning (~1k tokens)",
37
+ low: "Light reasoning (~2k tokens)",
38
+ medium: "Moderate reasoning (~8k tokens)",
39
+ high: "Deep reasoning (~16k tokens)",
40
+ xhigh: "Maximum reasoning (~32k tokens)",
41
+ };
42
+ const MODEL_ROUTER_THINKING_FALLBACK_LEVELS = [
43
+ "off",
44
+ "minimal",
45
+ "low",
46
+ "medium",
47
+ "high",
48
+ "xhigh",
49
+ ];
50
+ class ModelRouterThinkingSelectorComponent extends Container {
51
+ selectList;
52
+ constructor(currentLevel, availableLevels, onSelect, onCancel) {
53
+ super();
54
+ const thinkingOptions = [
55
+ {
56
+ value: MODEL_ROUTER_THINKING_INHERIT_VALUE,
57
+ label: MODEL_ROUTER_THINKING_INHERIT_LABEL,
58
+ description: "Use current session default for this tier.",
59
+ },
60
+ ...availableLevels.map((level) => ({
61
+ value: level,
62
+ label: level,
63
+ description: THINKING_LEVEL_DESCRIPTIONS[level],
64
+ })),
65
+ ];
66
+ this.addChild(new DynamicBorder());
67
+ this.selectList = new SelectList(thinkingOptions, thinkingOptions.length, getSelectListTheme(), MODEL_ROUTER_THINKING_SELECT_LIST_LAYOUT);
68
+ const index = thinkingOptions.findIndex((item) => item.value === currentLevel);
69
+ if (index !== -1) {
70
+ this.selectList.setSelectedIndex(index);
71
+ }
72
+ this.selectList.onSelect = (item) => {
73
+ onSelect(item.value);
74
+ };
75
+ this.selectList.onCancel = () => {
76
+ onCancel();
77
+ };
78
+ this.addChild(this.selectList);
79
+ this.addChild(new DynamicBorder());
80
+ }
81
+ }
23
82
  /**
24
83
  * /models — USER-invoked local model lifecycle (never a model-invokable tool):
25
84
  * list/add/remove/stop per local-model-lifecycle-design.md. Removal is explicit-only with
@@ -216,6 +275,61 @@ export function showFitnessModelSelector(host) {
216
275
  return { component: selector, focus: selector };
217
276
  });
218
277
  }
278
+ /** Resolve the routed model's supported thinking levels for a fitness-assignment flow, with a safe fallback. */
279
+ function getModelThinkingLevels(modelRegistry, modelRef) {
280
+ if (!modelRegistry) {
281
+ return [...MODEL_ROUTER_THINKING_FALLBACK_LEVELS];
282
+ }
283
+ const resolved = resolveCliModel({ cliModel: modelRef, modelRegistry });
284
+ if (!resolved.model) {
285
+ return [...MODEL_ROUTER_THINKING_FALLBACK_LEVELS];
286
+ }
287
+ return getSupportedThinkingLevels(resolved.model);
288
+ }
289
+ function getModelRouterThinkingField(role) {
290
+ if (role === "router-cheap") {
291
+ return "cheapThinking";
292
+ }
293
+ if (role === "router-medium") {
294
+ return "mediumThinking";
295
+ }
296
+ if (role === "router-expensive") {
297
+ return "expensiveThinking";
298
+ }
299
+ if (role === "executor") {
300
+ return "executorThinking";
301
+ }
302
+ if (role === "judge") {
303
+ return "judgeThinking";
304
+ }
305
+ return undefined;
306
+ }
307
+ function promptForModelRouterThinking(host, modelRef, role) {
308
+ const thinkingField = getModelRouterThinkingField(role);
309
+ if (!thinkingField) {
310
+ return;
311
+ }
312
+ const modelRegistry = host.session.modelRegistry;
313
+ const availableLevels = getModelThinkingLevels(modelRegistry, modelRef);
314
+ const settings = host.settingsManager.getModelRouterSettings();
315
+ const configuredThinking = settings[thinkingField];
316
+ const currentThinking = configuredThinking && availableLevels.includes(configuredThinking)
317
+ ? configuredThinking
318
+ : MODEL_ROUTER_THINKING_INHERIT_VALUE;
319
+ host.showSelector((done) => {
320
+ const selector = new ModelRouterThinkingSelectorComponent(currentThinking, availableLevels, (level) => {
321
+ done();
322
+ host.settingsManager.setModelRouterSettings({
323
+ ...settings,
324
+ [thinkingField]: level === MODEL_ROUTER_THINKING_INHERIT_VALUE ? undefined : level,
325
+ });
326
+ }, () => {
327
+ done();
328
+ host.ui.requestRender();
329
+ });
330
+ return { component: selector, focus: selector };
331
+ });
332
+ }
219
333
  /** Probe a model's fitness, show the report, then offer one-step role assignment. When the model
220
334
  * came from a validated suggestion, `preselectRole` lands its shaped role already highlighted. */
221
335
  export async function runFitnessAndAssign(host, modelRef, preselectRole) {
@@ -240,7 +354,16 @@ export async function runFitnessAndAssign(host, modelRef, preselectRole) {
240
354
  host.showSelector((done) => {
241
355
  const selector = new FitnessRoleSelectorComponent(outcome.model, (role) => {
242
356
  done();
357
+ if (role === "scout") {
358
+ const verdict = evaluateSurfaceFitness("scout_auto", outcome.report);
359
+ if (!verdict.fit) {
360
+ const reason = verdict.reason === "lane_failed" ? `failed ${verdict.lane}` : "was not probed";
361
+ host.showStatus(`${outcome.model} not assigned as scout: ${reason} on the scout_auto fitness exam. Use the docs/scout.md Modelfile recipe, then rerun /fitness.`);
362
+ return;
363
+ }
364
+ }
243
365
  assignFitnessRole(host, outcome.model, role);
366
+ promptForModelRouterThinking(host, outcome.model, role);
244
367
  }, () => {
245
368
  done();
246
369
  host.ui.requestRender();
@@ -271,6 +394,11 @@ export function assignFitnessRole(host, modelRef, role) {
271
394
  host.showStatus(`${modelRef} set as the toolkit executor (direct Level-0 hits route to it).${hint}`);
272
395
  return;
273
396
  }
397
+ if (role === "scout") {
398
+ host.settingsManager.setScoutSettings({ enabled: true, model: modelRef });
399
+ host.showStatus(`${modelRef} set as the repository scout (context_scout enabled).`);
400
+ return;
401
+ }
274
402
  const router = host.settingsManager.getModelRouterSettings();
275
403
  const field = role === "router-cheap"
276
404
  ? "cheapModel"
@@ -1 +1 @@
1
- {"version":3,"file":"local-model-commands.js","sourceRoot":"","sources":["../../../src/modes/interactive/local-model-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAEnG,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAElG,OAAO,EAAoB,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,gCAAgC,EAAE,MAAM,2CAA2C,CAAC;AAiC7F;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAoB,EAAE,QAAgB,EAAiB;IAChG,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,KA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and `/fitness` probe/role-assignment flows\n * extracted from interactive-mode.\n *\n * `/models` is a USER-invoked local-model manager (list/add/remove/stop, never a\n * model-invokable tool); the fitness helpers probe a model on the current host\n * and land a shaped role. The server/selector flows share a `LocalModelHost`\n * seam, while `runFitnessAndAssign`/`assignFitnessRole` take narrow host shapes\n * matching their prototype-driven behaviour tests (fitness-probe-gate,\n * fitness-role-assignment), which keep exercising interactive-mode's thin\n * wrappers unchanged.\n */\n\nimport type { Component, Container, TUI } from \"@caupulican/pi-tui\";\nimport { Spacer, Text } from \"@caupulican/pi-tui\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport { DEFAULT_MODEL_SUGGESTIONS } from \"../../core/models/default-model-suggestions.ts\";\nimport { FitnessStore } from \"../../core/models/fitness-store.ts\";\nimport { registerLocalModel, unregisterLocalModel } from \"../../core/models/local-registration.ts\";\nimport type { OllamaRuntime } from \"../../core/models/local-runtime.ts\";\nimport { matchesInstalledLocalModel, normalizeModelSource } from \"../../core/models/model-ref.ts\";\nimport { formatModelFitnessReport, isProbeAllFailed } from \"../../core/research/model-fitness.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { type FitnessRole, FitnessRoleSelectorComponent } from \"./components/fitness-role-selector.ts\";\nimport { ModelSelectorComponent } from \"./components/model-selector.ts\";\nimport { ModelSuggestionSelectorComponent } from \"./components/model-suggestion-selector.ts\";\n\ntype SelectorFactory = (done: () => void) => { component: Component; focus: Component };\n\n/** Narrow seam for persisting a probed model's role — matches the fitness-role test. */\nexport interface AssignRoleHost {\n\treadonly settingsManager: SettingsManager;\n\tshowStatus(message: string): void;\n}\n\n/** Seam for the fitness probe + role-selector flow — matches the fitness-probe-gate test. */\nexport interface RunFitnessHost {\n\treadonly session: Pick<AgentSession, \"runModelFitness\">;\n\treadonly settingsManager: SettingsManager;\n\treadonly chatContainer: Container;\n\treadonly ui: TUI;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\n/** Full seam for the `/models` server/selector flows. */\nexport interface LocalModelHost {\n\treadonly localRuntime: OllamaRuntime;\n\treadonly session: AgentSession;\n\treadonly settingsManager: SettingsManager;\n\treadonly ui: TUI;\n\treadonly chatContainer: Container;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\n/**\n * /models — USER-invoked local model lifecycle (never a model-invokable tool):\n * list/add/remove/stop per local-model-lifecycle-design.md. Removal is explicit-only with\n * full disclosure; a pasted install command is parsed for its ref, never executed.\n */\nexport async function handleModelsCommand(host: LocalModelHost, argsText: string): Promise<void> {\n\tconst [action = \"list\", ...rest] = argsText.split(/\\s+/).filter(Boolean);\n\ttry {\n\t\tif (action === \"suggest\" || action === \"suggestions\") {\n\t\t\tshowModelSuggestionSelector(host);\n\t\t\treturn;\n\t\t}\n\t\tif (action === \"stop\") {\n\t\t\tconst stopped = host.localRuntime.stop();\n\t\t\thost.showStatus(\n\t\t\t\tstopped.stopped\n\t\t\t\t\t? \"Pi-managed local model server stopped (models remain installed).\"\n\t\t\t\t\t: \"No pi-managed server running (a system server, if any, is not pi's to stop).\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"add\") {\n\t\t\tconst rawRef = rest.join(\" \");\n\t\t\tif (!rawRef) {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t\"Usage: /models add <ollama-tag | hf.co/org/repo[:quant] | huggingface URL | pasted install command>\",\n\t\t\t\t);\n\t\t\t\thost.showStatus(\"Or start from a validated suggestion: /models suggest\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst source = normalizeModelSource(rawRef);\n\t\t\tif (source.type === \"rejected\") {\n\t\t\t\thost.showStatus(`Not added: ${source.reason}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"api\") {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t`${source.ref} is an API model — nothing to install. Configure auth for the provider, then probe it with /fitness ${source.ref}.`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait addLocalModel(host, source.pullRef);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"remove\") {\n\t\t\tconst ref = rest[0];\n\t\t\tconst confirmed = rest[1] === \"confirm\";\n\t\t\tif (!ref) {\n\t\t\t\thost.showStatus(\"Usage: /models remove <ref> confirm\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait removeLocalModel(host, ref, confirmed);\n\t\t\treturn;\n\t\t}\n\n\t\tawait listLocalModels(host);\n\t} catch (error) {\n\t\thost.showError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\nexport async function ensureLocalServer(host: LocalModelHost): Promise<boolean> {\n\tconst status = await host.localRuntime.detect();\n\tif (status.serverUp) return true;\n\tif (!status.binaryPath) {\n\t\tfor (const line of host.localRuntime.installGuide()) host.showStatus(line);\n\t\treturn false;\n\t}\n\thost.showStatus(\n\t\t`Starting local model server (${status.binarySource} binary, owned storage: ${status.ownedModelsDir})…`,\n\t);\n\tconst started = await host.localRuntime.start();\n\tif (!started.started) {\n\t\thost.showStatus(`Could not start the local server: ${started.reason}`);\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport async function listLocalModels(host: LocalModelHost): Promise<void> {\n\tconst status = await host.localRuntime.detect();\n\tif (!status.serverUp) {\n\t\tif (!status.binaryPath) {\n\t\t\tfor (const line of host.localRuntime.installGuide()) host.showStatus(line);\n\t\t\treturn;\n\t\t}\n\t\thost.showStatus(\n\t\t\t`Local server not running (binary: ${status.binarySource}). /models add starts it on demand; /fitness probes registered models.`,\n\t\t);\n\t\treturn;\n\t}\n\tconst models = await host.localRuntime.list();\n\tconst fitness = FitnessStore.forAgentDir(getAgentDir()).getForHost();\n\tconst lines = [\n\t\t`Local models (${status.managedByPi ? `pi-managed server, storage: ${status.ownedModelsDir}` : \"system server — storage owned by the system daemon\"}):`,\n\t\t...(models.length === 0\n\t\t\t? [\" (none installed — /models add <ref>, or /models suggest for a validated roster)\"]\n\t\t\t: []),\n\t\t...models.map((model) => {\n\t\t\tconst report = fitness.find((entry) => entry.model === `ollama/${model.name}`);\n\t\t\tconst gb = (model.sizeBytes / 1e9).toFixed(2);\n\t\t\tconst probe = report\n\t\t\t\t? `probed ${report.at.slice(0, 10)}: digest ${report.report.digest?.succeeded ?? \"?\"}/${report.report.digest?.total ?? \"?\"}, tool-calls ${report.report.toolCall.succeeded}/${report.report.toolCall.total}${report.report.tokensPerSecond ? `, ~${report.report.tokensPerSecond} tok/s` : \"\"}`\n\t\t\t\t: `unprobed — run /fitness ollama/${model.name}`;\n\t\t\treturn ` - ${model.name} (${gb} GB) · ${probe}`;\n\t\t}),\n\t\t\"Commands: /models add <ref> · /models remove <ref> confirm · /models stop\",\n\t];\n\tfor (const line of lines) host.showStatus(line);\n}\n\nexport async function addLocalModel(host: LocalModelHost, pullRef: string, preselectRole?: FitnessRole): Promise<void> {\n\tif (!(await ensureLocalServer(host))) return;\n\thost.showStatus(`Pulling ${pullRef}… (weights land in the server's model storage)`);\n\tlet lastShown = 0;\n\tconst pulled = await host.localRuntime.pull(pullRef, (progress) => {\n\t\tconst now = Date.now();\n\t\tif (now - lastShown > 2000) {\n\t\t\tlastShown = now;\n\t\t\thost.showStatus(` ${pullRef}: ${progress}`);\n\t\t}\n\t});\n\tif (!pulled.ok) {\n\t\thost.showStatus(`Pull failed: ${pulled.error}`);\n\t\treturn;\n\t}\n\tconst registration = registerLocalModel({\n\t\tagentDir: getAgentDir(),\n\t\tref: pullRef,\n\t\tbaseUrl: host.localRuntime.baseUrl,\n\t});\n\tif (!registration.ok) {\n\t\thost.showStatus(`Pulled, but not auto-registered: ${registration.reason}`);\n\t\tif (registration.manualSnippet) {\n\t\t\thost.showStatus(`Add this to ${registration.modelsJsonPath} yourself:\\n${registration.manualSnippet}`);\n\t\t}\n\t\treturn;\n\t}\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(`${pullRef} installed and registered as ollama/${pullRef}. Probing fitness…`);\n\tawait runFitnessAndAssign(host, `ollama/${pullRef}`, preselectRole);\n}\n\nexport async function removeLocalModel(host: LocalModelHost, ref: string, confirmed: boolean): Promise<void> {\n\tconst status = await host.localRuntime.detect();\n\tif (!status.serverUp) {\n\t\thost.showStatus(\"Local server not running — start it (any /models action) before removing.\");\n\t\treturn;\n\t}\n\tconst models = await host.localRuntime.list();\n\tconst target = models.find((model) => matchesInstalledLocalModel(ref, model.name));\n\tif (!target) {\n\t\thost.showStatus(\n\t\t\t`${ref} is not installed. Installed: ${models.map((model) => model.name).join(\", \") || \"(none)\"}`,\n\t\t);\n\t\treturn;\n\t}\n\tif (!confirmed) {\n\t\t// EXPLICIT USER ACTION ONLY: full disclosure, then require the confirm token.\n\t\tconst gb = (target.sizeBytes / 1e9).toFixed(2);\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t`Removing ${ref} will delete:`,\n\t\t\t\t` - model weights (${gb} GB) from ${status.managedByPi ? status.ownedModelsDir : \"the system server's storage\"}`,\n\t\t\t\t` - the ollama/${ref} entry in models.json`,\n\t\t\t\t` - its cached fitness report for this host`,\n\t\t\t\t`Run: /models remove ${ref} confirm`,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\tconst removed = await host.localRuntime.remove(ref);\n\tif (!removed.ok) {\n\t\thost.showStatus(`Remove failed: ${removed.error}`);\n\t\treturn;\n\t}\n\tunregisterLocalModel({ agentDir: getAgentDir(), ref });\n\tFitnessStore.forAgentDir(getAgentDir()).remove(`ollama/${ref}`);\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(`${ref} removed: weights deleted, registration and fitness report dropped.`);\n}\n\n/** /fitness with no args: pick a model from the configured registry, probe it, assign a role. */\n/** Pick a validated suggestion → install it → probe on this host → land its shaped role. */\nexport function showModelSuggestionSelector(host: LocalModelHost): void {\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelSuggestionSelectorComponent(\n\t\t\tDEFAULT_MODEL_SUGGESTIONS,\n\t\t\tasync (suggestion) => {\n\t\t\t\tdone();\n\t\t\t\t// The shaped role rides along so the post-probe selector lands on it pre-selected;\n\t\t\t\t// non-tool-callers carry curator/judge/none, never executor, so this can't footgun.\n\t\t\t\tawait addLocalModel(host, suggestion.pullRef, suggestion.assignRole);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\nexport function showFitnessModelSelector(host: LocalModelHost): void {\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelSelectorComponent(\n\t\t\thost.ui,\n\t\t\thost.session.model,\n\t\t\thost.settingsManager,\n\t\t\thost.session.modelRegistry,\n\t\t\thost.session.scopedModels,\n\t\t\tasync (model) => {\n\t\t\t\tdone();\n\t\t\t\tawait runFitnessAndAssign(host, `${model.provider}/${model.id}`);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\n/** Probe a model's fitness, show the report, then offer one-step role assignment. When the model\n * came from a validated suggestion, `preselectRole` lands its shaped role already highlighted. */\nexport async function runFitnessAndAssign(\n\thost: RunFitnessHost,\n\tmodelRef: string,\n\tpreselectRole?: FitnessRole,\n): Promise<void> {\n\thost.showStatus(`Model fitness probe running on ${modelRef}… (6 surfaces; local models may take a few minutes)`);\n\ttry {\n\t\tconst outcome = await host.session.runModelFitness({ model: modelRef });\n\t\tif (!outcome.started) {\n\t\t\thost.showStatus(`Model fitness skipped: ${outcome.skipReason}`);\n\t\t\treturn;\n\t\t}\n\t\thost.chatContainer.addChild(new Spacer(1));\n\t\thost.chatContainer.addChild(new Text(formatModelFitnessReport(outcome.model, outcome.report), 1, 0));\n\t\thost.ui.requestRender();\n\t\t// Validate-before-load: zero successes on every probed surface means the model cannot\n\t\t// drive any of the harness's subagent contracts on this host — refuse adoption instead\n\t\t// of landing a role selector the user might reflexively confirm (this is the reported\n\t\t// bug: a 0/3-everywhere model still got set as judge model and saved to Model Router).\n\t\tif (isProbeAllFailed(outcome.report)) {\n\t\t\thost.showStatus(\n\t\t\t\t`${outcome.model} failed the fitness probe on all surfaces — not configured. Use /model to set it manually if you accept the risk.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\thost.showSelector((done) => {\n\t\t\tconst selector = new FitnessRoleSelectorComponent(\n\t\t\t\toutcome.model,\n\t\t\t\t(role) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tassignFitnessRole(host, outcome.model, role);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t},\n\t\t\t\tpreselectRole,\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector };\n\t\t});\n\t} catch (error) {\n\t\thost.showError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\n/** Persist a role assignment from the post-probe selector into the matching settings. */\nexport function assignFitnessRole(host: AssignRoleHost, modelRef: string, role: FitnessRole): void {\n\tif (role === \"none\") {\n\t\thost.showStatus(`Fitness result for ${modelRef} saved. Assign a role later from /settings.`);\n\t\treturn;\n\t}\n\tif (role === \"curator\") {\n\t\tconst current = host.settingsManager.getContextCurationSettings();\n\t\thost.settingsManager.setContextCurationSettings({ ...current, enabled: true, model: modelRef });\n\t\thost.showStatus(`Context curation enabled with ${modelRef} as the curator.`);\n\t\treturn;\n\t}\n\tif (role === \"executor\") {\n\t\tconst router = host.settingsManager.getModelRouterSettings();\n\t\thost.settingsManager.setModelRouterSettings({ ...router, executorModel: modelRef });\n\t\tconst hint = router.enabled ? \"\" : \" Model router is currently disabled — enable it in /settings → Model Router.\";\n\t\thost.showStatus(`${modelRef} set as the toolkit executor (direct Level-0 hits route to it).${hint}`);\n\t\treturn;\n\t}\n\tconst router = host.settingsManager.getModelRouterSettings();\n\tconst field =\n\t\trole === \"router-cheap\"\n\t\t\t? \"cheapModel\"\n\t\t\t: role === \"router-medium\"\n\t\t\t\t? \"mediumModel\"\n\t\t\t\t: role === \"router-expensive\"\n\t\t\t\t\t? \"expensiveModel\"\n\t\t\t\t\t: role === \"judge\"\n\t\t\t\t\t\t? \"judgeModel\"\n\t\t\t\t\t\t: \"learningModel\";\n\thost.settingsManager.setModelRouterSettings({ ...router, [field]: modelRef });\n\tconst hint = router.enabled ? \"\" : \" Model router is currently disabled — enable it in /settings → Model Router.\";\n\thost.showStatus(`${modelRef} set as ${role.replace(\"router-\", \"router \")} model.${hint}`);\n}\n"]}
1
+ {"version":3,"file":"local-model-commands.js","sourceRoot":"","sources":["../../../src/modes/interactive/local-model-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAEN,SAAS,EAET,UAAU,EAEV,MAAM,EACN,IAAI,GAEJ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAEnG,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAElG,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAoB,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,C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;QACpF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,kFAA8E,CAAC;QAClH,IAAI,CAAC,UAAU,CAAC,GAAG,QAAQ,kEAAkE,IAAI,EAAE,CAAC,CAAC;QACrG,OAAO;IACR,CAAC;IACD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC1E,IAAI,CAAC,UAAU,CAAC,GAAG,QAAQ,uDAAuD,CAAC,CAAC;QACpF,OAAO;IACR,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,sBAAsB,EAAE,CAAC;IAC7D,MAAM,KAAK,GACV,IAAI,KAAK,cAAc;QACtB,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,IAAI,KAAK,eAAe;YACzB,CAAC,CAAC,aAAa;YACf,CAAC,CAAC,IAAI,KAAK,kBAAkB;gBAC5B,CAAC,CAAC,gBAAgB;gBAClB,CAAC,CAAC,IAAI,KAAK,OAAO;oBACjB,CAAC,CAAC,YAAY;oBACd,CAAC,CAAC,eAAe,CAAC;IACvB,IAAI,CAAC,eAAe,CAAC,sBAAsB,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,kFAA8E,CAAC;IAClH,IAAI,CAAC,UAAU,CAAC,GAAG,QAAQ,WAAW,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;AAAA,CAC1F","sourcesContent":["/**\n * `/models` local-model lifecycle and `/fitness` probe/role-assignment flows\n * extracted from interactive-mode.\n *\n * `/models` is a USER-invoked local-model manager (list/add/remove/stop, never a\n * model-invokable tool); the fitness helpers probe a model on the current host\n * and land a shaped role. The server/selector flows share a `LocalModelHost`\n * seam, while `runFitnessAndAssign`/`assignFitnessRole` take narrow host shapes\n * matching their prototype-driven behaviour tests (fitness-probe-gate,\n * fitness-role-assignment), which keep exercising interactive-mode's thin\n * wrappers unchanged.\n */\n\nimport type { ThinkingLevel } from \"@caupulican/pi-agent-core\";\nimport { getSupportedThinkingLevels } from \"@caupulican/pi-ai\";\nimport {\n\ttype Component,\n\tContainer,\n\ttype SelectItem,\n\tSelectList,\n\ttype SelectListLayoutOptions,\n\tSpacer,\n\tText,\n\ttype TUI,\n} from \"@caupulican/pi-tui\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { resolveCliModel } from \"../../core/model-resolver.ts\";\nimport { evaluateSurfaceFitness } from \"../../core/model-router/fitness-gate.ts\";\nimport { DEFAULT_MODEL_SUGGESTIONS } from \"../../core/models/default-model-suggestions.ts\";\nimport { FitnessStore } from \"../../core/models/fitness-store.ts\";\nimport { registerLocalModel, unregisterLocalModel } from \"../../core/models/local-registration.ts\";\nimport type { OllamaRuntime } from \"../../core/models/local-runtime.ts\";\nimport { matchesInstalledLocalModel, normalizeModelSource } from \"../../core/models/model-ref.ts\";\nimport { formatModelFitnessReport, isProbeAllFailed } from \"../../core/research/model-fitness.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { DynamicBorder } from \"./components/dynamic-border.ts\";\nimport { type FitnessRole, FitnessRoleSelectorComponent } from \"./components/fitness-role-selector.ts\";\nimport { ModelSelectorComponent } from \"./components/model-selector.ts\";\nimport { ModelSuggestionSelectorComponent } from \"./components/model-suggestion-selector.ts\";\nimport { getSelectListTheme } from \"./theme/theme.ts\";\n\ntype SelectorFactory = (done: () => void) => { component: Component; focus: Component };\n\nconst MODEL_ROUTER_THINKING_SELECT_LIST_LAYOUT: SelectListLayoutOptions = {\n\tminPrimaryColumnWidth: 12,\n\tmaxPrimaryColumnWidth: 32,\n};\n\nconst MODEL_ROUTER_THINKING_INHERIT_VALUE = \"__inherit_model_router_thinking__\";\nconst MODEL_ROUTER_THINKING_INHERIT_LABEL = \"(inherit)\";\n\nconst THINKING_LEVEL_DESCRIPTIONS: Record<ThinkingLevel, string> = {\n\toff: \"No reasoning\",\n\tminimal: \"Very brief reasoning (~1k tokens)\",\n\tlow: \"Light reasoning (~2k tokens)\",\n\tmedium: \"Moderate reasoning (~8k tokens)\",\n\thigh: \"Deep reasoning (~16k tokens)\",\n\txhigh: \"Maximum reasoning (~32k tokens)\",\n};\n\nconst MODEL_ROUTER_THINKING_FALLBACK_LEVELS: readonly ThinkingLevel[] = [\n\t\"off\",\n\t\"minimal\",\n\t\"low\",\n\t\"medium\",\n\t\"high\",\n\t\"xhigh\",\n];\n\ntype RouterThinkingLevel = ThinkingLevel | typeof MODEL_ROUTER_THINKING_INHERIT_VALUE;\ntype ModelRouterThinkingField =\n\t| \"cheapThinking\"\n\t| \"mediumThinking\"\n\t| \"expensiveThinking\"\n\t| \"executorThinking\"\n\t| \"judgeThinking\";\n\n/** Narrow seam for persisting a probed model's role — matches the fitness-role test. */\nexport interface AssignRoleHost {\n\treadonly settingsManager: SettingsManager;\n\tshowStatus(message: string): void;\n}\n\n/** Seam for the fitness probe + role-selector flow — matches the fitness-probe-gate test. */\nexport interface RunFitnessHost {\n\treadonly session: Pick<AgentSession, \"runModelFitness\"> & { modelRegistry?: ModelRegistry };\n\treadonly settingsManager: SettingsManager;\n\treadonly chatContainer: Container;\n\treadonly ui: TUI;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\n/** Full seam for the `/models` server/selector flows. */\nexport interface LocalModelHost {\n\treadonly localRuntime: OllamaRuntime;\n\treadonly session: AgentSession;\n\treadonly settingsManager: SettingsManager;\n\treadonly ui: TUI;\n\treadonly chatContainer: Container;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\nclass ModelRouterThinkingSelectorComponent extends Container {\n\tprivate selectList: SelectList;\n\n\tconstructor(\n\t\tcurrentLevel: RouterThinkingLevel,\n\t\tavailableLevels: ThinkingLevel[],\n\t\tonSelect: (level: RouterThinkingLevel) => void,\n\t\tonCancel: () => void,\n\t) {\n\t\tsuper();\n\n\t\tconst thinkingOptions: SelectItem[] = [\n\t\t\t{\n\t\t\t\tvalue: MODEL_ROUTER_THINKING_INHERIT_VALUE,\n\t\t\t\tlabel: MODEL_ROUTER_THINKING_INHERIT_LABEL,\n\t\t\t\tdescription: \"Use current session default for this tier.\",\n\t\t\t},\n\t\t\t...availableLevels.map((level) => ({\n\t\t\t\tvalue: level,\n\t\t\t\tlabel: level,\n\t\t\t\tdescription: THINKING_LEVEL_DESCRIPTIONS[level],\n\t\t\t})),\n\t\t];\n\n\t\tthis.addChild(new DynamicBorder());\n\n\t\tthis.selectList = new SelectList(\n\t\t\tthinkingOptions,\n\t\t\tthinkingOptions.length,\n\t\t\tgetSelectListTheme(),\n\t\t\tMODEL_ROUTER_THINKING_SELECT_LIST_LAYOUT,\n\t\t);\n\n\t\tconst index = thinkingOptions.findIndex((item) => item.value === currentLevel);\n\t\tif (index !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(index);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tonSelect(item.value as RouterThinkingLevel);\n\t\t};\n\t\tthis.selectList.onCancel = () => {\n\t\t\tonCancel();\n\t\t};\n\n\t\tthis.addChild(this.selectList);\n\t\tthis.addChild(new DynamicBorder());\n\t}\n}\n/**\n * /models — USER-invoked local model lifecycle (never a model-invokable tool):\n * list/add/remove/stop per local-model-lifecycle-design.md. Removal is explicit-only with\n * full disclosure; a pasted install command is parsed for its ref, never executed.\n */\nexport async function handleModelsCommand(host: LocalModelHost, argsText: string): Promise<void> {\n\tconst [action = \"list\", ...rest] = argsText.split(/\\s+/).filter(Boolean);\n\ttry {\n\t\tif (action === \"suggest\" || action === \"suggestions\") {\n\t\t\tshowModelSuggestionSelector(host);\n\t\t\treturn;\n\t\t}\n\t\tif (action === \"stop\") {\n\t\t\tconst stopped = host.localRuntime.stop();\n\t\t\thost.showStatus(\n\t\t\t\tstopped.stopped\n\t\t\t\t\t? \"Pi-managed local model server stopped (models remain installed).\"\n\t\t\t\t\t: \"No pi-managed server running (a system server, if any, is not pi's to stop).\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"add\") {\n\t\t\tconst rawRef = rest.join(\" \");\n\t\t\tif (!rawRef) {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t\"Usage: /models add <ollama-tag | hf.co/org/repo[:quant] | huggingface URL | pasted install command>\",\n\t\t\t\t);\n\t\t\t\thost.showStatus(\"Or start from a validated suggestion: /models suggest\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst source = normalizeModelSource(rawRef);\n\t\t\tif (source.type === \"rejected\") {\n\t\t\t\thost.showStatus(`Not added: ${source.reason}`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"api\") {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t`${source.ref} is an API model — nothing to install. Configure auth for the provider, then probe it with /fitness ${source.ref}.`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait addLocalModel(host, source.pullRef);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"remove\") {\n\t\t\tconst ref = rest[0];\n\t\t\tconst confirmed = rest[1] === \"confirm\";\n\t\t\tif (!ref) {\n\t\t\t\thost.showStatus(\"Usage: /models remove <ref> confirm\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait removeLocalModel(host, ref, confirmed);\n\t\t\treturn;\n\t\t}\n\n\t\tawait listLocalModels(host);\n\t} catch (error) {\n\t\thost.showError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\nexport async function ensureLocalServer(host: LocalModelHost): Promise<boolean> {\n\tconst status = await host.localRuntime.detect();\n\tif (status.serverUp) return true;\n\tif (!status.binaryPath) {\n\t\tfor (const line of host.localRuntime.installGuide()) host.showStatus(line);\n\t\treturn false;\n\t}\n\thost.showStatus(\n\t\t`Starting local model server (${status.binarySource} binary, owned storage: ${status.ownedModelsDir})…`,\n\t);\n\tconst started = await host.localRuntime.start();\n\tif (!started.started) {\n\t\thost.showStatus(`Could not start the local server: ${started.reason}`);\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport async function listLocalModels(host: LocalModelHost): Promise<void> {\n\tconst status = await host.localRuntime.detect();\n\tif (!status.serverUp) {\n\t\tif (!status.binaryPath) {\n\t\t\tfor (const line of host.localRuntime.installGuide()) host.showStatus(line);\n\t\t\treturn;\n\t\t}\n\t\thost.showStatus(\n\t\t\t`Local server not running (binary: ${status.binarySource}). /models add starts it on demand; /fitness probes registered models.`,\n\t\t);\n\t\treturn;\n\t}\n\tconst models = await host.localRuntime.list();\n\tconst fitness = FitnessStore.forAgentDir(getAgentDir()).getForHost();\n\tconst lines = [\n\t\t`Local models (${status.managedByPi ? `pi-managed server, storage: ${status.ownedModelsDir}` : \"system server — storage owned by the system daemon\"}):`,\n\t\t...(models.length === 0\n\t\t\t? [\" (none installed — /models add <ref>, or /models suggest for a validated roster)\"]\n\t\t\t: []),\n\t\t...models.map((model) => {\n\t\t\tconst report = fitness.find((entry) => entry.model === `ollama/${model.name}`);\n\t\t\tconst gb = (model.sizeBytes / 1e9).toFixed(2);\n\t\t\tconst probe = report\n\t\t\t\t? `probed ${report.at.slice(0, 10)}: digest ${report.report.digest?.succeeded ?? \"?\"}/${report.report.digest?.total ?? \"?\"}, tool-calls ${report.report.toolCall.succeeded}/${report.report.toolCall.total}${report.report.tokensPerSecond ? `, ~${report.report.tokensPerSecond} tok/s` : \"\"}`\n\t\t\t\t: `unprobed — run /fitness ollama/${model.name}`;\n\t\t\treturn ` - ${model.name} (${gb} GB) · ${probe}`;\n\t\t}),\n\t\t\"Commands: /models add <ref> · /models remove <ref> confirm · /models stop\",\n\t];\n\tfor (const line of lines) host.showStatus(line);\n}\n\nexport async function addLocalModel(host: LocalModelHost, pullRef: string, preselectRole?: FitnessRole): Promise<void> {\n\tif (!(await ensureLocalServer(host))) return;\n\thost.showStatus(`Pulling ${pullRef}… (weights land in the server's model storage)`);\n\tlet lastShown = 0;\n\tconst pulled = await host.localRuntime.pull(pullRef, (progress) => {\n\t\tconst now = Date.now();\n\t\tif (now - lastShown > 2000) {\n\t\t\tlastShown = now;\n\t\t\thost.showStatus(` ${pullRef}: ${progress}`);\n\t\t}\n\t});\n\tif (!pulled.ok) {\n\t\thost.showStatus(`Pull failed: ${pulled.error}`);\n\t\treturn;\n\t}\n\tconst registration = registerLocalModel({\n\t\tagentDir: getAgentDir(),\n\t\tref: pullRef,\n\t\tbaseUrl: host.localRuntime.baseUrl,\n\t});\n\tif (!registration.ok) {\n\t\thost.showStatus(`Pulled, but not auto-registered: ${registration.reason}`);\n\t\tif (registration.manualSnippet) {\n\t\t\thost.showStatus(`Add this to ${registration.modelsJsonPath} yourself:\\n${registration.manualSnippet}`);\n\t\t}\n\t\treturn;\n\t}\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(`${pullRef} installed and registered as ollama/${pullRef}. Probing fitness…`);\n\tawait runFitnessAndAssign(host, `ollama/${pullRef}`, preselectRole);\n}\n\nexport async function removeLocalModel(host: LocalModelHost, ref: string, confirmed: boolean): Promise<void> {\n\tconst status = await host.localRuntime.detect();\n\tif (!status.serverUp) {\n\t\thost.showStatus(\"Local server not running — start it (any /models action) before removing.\");\n\t\treturn;\n\t}\n\tconst models = await host.localRuntime.list();\n\tconst target = models.find((model) => matchesInstalledLocalModel(ref, model.name));\n\tif (!target) {\n\t\thost.showStatus(\n\t\t\t`${ref} is not installed. Installed: ${models.map((model) => model.name).join(\", \") || \"(none)\"}`,\n\t\t);\n\t\treturn;\n\t}\n\tif (!confirmed) {\n\t\t// EXPLICIT USER ACTION ONLY: full disclosure, then require the confirm token.\n\t\tconst gb = (target.sizeBytes / 1e9).toFixed(2);\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t`Removing ${ref} will delete:`,\n\t\t\t\t` - model weights (${gb} GB) from ${status.managedByPi ? status.ownedModelsDir : \"the system server's storage\"}`,\n\t\t\t\t` - the ollama/${ref} entry in models.json`,\n\t\t\t\t` - its cached fitness report for this host`,\n\t\t\t\t`Run: /models remove ${ref} confirm`,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\tconst removed = await host.localRuntime.remove(ref);\n\tif (!removed.ok) {\n\t\thost.showStatus(`Remove failed: ${removed.error}`);\n\t\treturn;\n\t}\n\tunregisterLocalModel({ agentDir: getAgentDir(), ref });\n\tFitnessStore.forAgentDir(getAgentDir()).remove(`ollama/${ref}`);\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(`${ref} removed: weights deleted, registration and fitness report dropped.`);\n}\n\n/** /fitness with no args: pick a model from the configured registry, probe it, assign a role. */\n/** Pick a validated suggestion → install it → probe on this host → land its shaped role. */\nexport function showModelSuggestionSelector(host: LocalModelHost): void {\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelSuggestionSelectorComponent(\n\t\t\tDEFAULT_MODEL_SUGGESTIONS,\n\t\t\tasync (suggestion) => {\n\t\t\t\tdone();\n\t\t\t\t// The shaped role rides along so the post-probe selector lands on it pre-selected;\n\t\t\t\t// non-tool-callers carry curator/judge/none, never executor, so this can't footgun.\n\t\t\t\tawait addLocalModel(host, suggestion.pullRef, suggestion.assignRole);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\nexport function showFitnessModelSelector(host: LocalModelHost): void {\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelSelectorComponent(\n\t\t\thost.ui,\n\t\t\thost.session.model,\n\t\t\thost.settingsManager,\n\t\t\thost.session.modelRegistry,\n\t\t\thost.session.scopedModels,\n\t\t\tasync (model) => {\n\t\t\t\tdone();\n\t\t\t\tawait runFitnessAndAssign(host, `${model.provider}/${model.id}`);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\n/** Resolve the routed model's supported thinking levels for a fitness-assignment flow, with a safe fallback. */\nfunction getModelThinkingLevels(modelRegistry: ModelRegistry | undefined, modelRef: string): ThinkingLevel[] {\n\tif (!modelRegistry) {\n\t\treturn [...MODEL_ROUTER_THINKING_FALLBACK_LEVELS];\n\t}\n\tconst resolved = resolveCliModel({ cliModel: modelRef, modelRegistry });\n\tif (!resolved.model) {\n\t\treturn [...MODEL_ROUTER_THINKING_FALLBACK_LEVELS];\n\t}\n\treturn getSupportedThinkingLevels(resolved.model);\n}\n\nfunction getModelRouterThinkingField(role: FitnessRole): ModelRouterThinkingField | undefined {\n\tif (role === \"router-cheap\") {\n\t\treturn \"cheapThinking\";\n\t}\n\tif (role === \"router-medium\") {\n\t\treturn \"mediumThinking\";\n\t}\n\tif (role === \"router-expensive\") {\n\t\treturn \"expensiveThinking\";\n\t}\n\tif (role === \"executor\") {\n\t\treturn \"executorThinking\";\n\t}\n\tif (role === \"judge\") {\n\t\treturn \"judgeThinking\";\n\t}\n\treturn undefined;\n}\n\nfunction promptForModelRouterThinking(host: RunFitnessHost, modelRef: string, role: FitnessRole): void {\n\tconst thinkingField = getModelRouterThinkingField(role);\n\tif (!thinkingField) {\n\t\treturn;\n\t}\n\n\tconst modelRegistry = host.session.modelRegistry;\n\tconst availableLevels = getModelThinkingLevels(modelRegistry, modelRef);\n\tconst settings = host.settingsManager.getModelRouterSettings();\n\tconst configuredThinking = settings[thinkingField];\n\tconst currentThinking =\n\t\tconfiguredThinking && availableLevels.includes(configuredThinking)\n\t\t\t? configuredThinking\n\t\t\t: MODEL_ROUTER_THINKING_INHERIT_VALUE;\n\n\thost.showSelector((done) => {\n\t\tconst selector = new ModelRouterThinkingSelectorComponent(\n\t\t\tcurrentThinking,\n\t\t\tavailableLevels,\n\t\t\t(level) => {\n\t\t\t\tdone();\n\t\t\t\thost.settingsManager.setModelRouterSettings({\n\t\t\t\t\t...settings,\n\t\t\t\t\t[thinkingField]: level === MODEL_ROUTER_THINKING_INHERIT_VALUE ? undefined : level,\n\t\t\t\t});\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tdone();\n\t\t\t\thost.ui.requestRender();\n\t\t\t},\n\t\t);\n\t\treturn { component: selector, focus: selector };\n\t});\n}\n\n/** Probe a model's fitness, show the report, then offer one-step role assignment. When the model\n * came from a validated suggestion, `preselectRole` lands its shaped role already highlighted. */\nexport async function runFitnessAndAssign(\n\thost: RunFitnessHost,\n\tmodelRef: string,\n\tpreselectRole?: FitnessRole,\n): Promise<void> {\n\thost.showStatus(`Model fitness probe running on ${modelRef}… (6 surfaces; local models may take a few minutes)`);\n\ttry {\n\t\tconst outcome = await host.session.runModelFitness({ model: modelRef });\n\t\tif (!outcome.started) {\n\t\t\thost.showStatus(`Model fitness skipped: ${outcome.skipReason}`);\n\t\t\treturn;\n\t\t}\n\t\thost.chatContainer.addChild(new Spacer(1));\n\t\thost.chatContainer.addChild(new Text(formatModelFitnessReport(outcome.model, outcome.report), 1, 0));\n\t\thost.ui.requestRender();\n\t\t// Validate-before-load: zero successes on every probed surface means the model cannot\n\t\t// drive any of the harness's subagent contracts on this host — refuse adoption instead\n\t\t// of landing a role selector the user might reflexively confirm (this is the reported\n\t\t// bug: a 0/3-everywhere model still got set as judge model and saved to Model Router).\n\t\tif (isProbeAllFailed(outcome.report)) {\n\t\t\thost.showStatus(\n\t\t\t\t`${outcome.model} failed the fitness probe on all surfaces — not configured. Use /model to set it manually if you accept the risk.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\thost.showSelector((done) => {\n\t\t\tconst selector = new FitnessRoleSelectorComponent(\n\t\t\t\toutcome.model,\n\t\t\t\t(role) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tif (role === \"scout\") {\n\t\t\t\t\t\tconst verdict = evaluateSurfaceFitness(\"scout_auto\", outcome.report);\n\t\t\t\t\t\tif (!verdict.fit) {\n\t\t\t\t\t\t\tconst reason = verdict.reason === \"lane_failed\" ? `failed ${verdict.lane}` : \"was not probed\";\n\t\t\t\t\t\t\thost.showStatus(\n\t\t\t\t\t\t\t\t`${outcome.model} not assigned as scout: ${reason} on the scout_auto fitness exam. Use the docs/scout.md Modelfile recipe, then rerun /fitness.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tassignFitnessRole(host, outcome.model, role);\n\t\t\t\t\tpromptForModelRouterThinking(host, outcome.model, role);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\thost.ui.requestRender();\n\t\t\t\t},\n\t\t\t\tpreselectRole,\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector };\n\t\t});\n\t} catch (error) {\n\t\thost.showError(error instanceof Error ? error.message : String(error));\n\t}\n}\n\n/** Persist a role assignment from the post-probe selector into the matching settings. */\nexport function assignFitnessRole(host: AssignRoleHost, modelRef: string, role: FitnessRole): void {\n\tif (role === \"none\") {\n\t\thost.showStatus(`Fitness result for ${modelRef} saved. Assign a role later from /settings.`);\n\t\treturn;\n\t}\n\tif (role === \"curator\") {\n\t\tconst current = host.settingsManager.getContextCurationSettings();\n\t\thost.settingsManager.setContextCurationSettings({ ...current, enabled: true, model: modelRef });\n\t\thost.showStatus(`Context curation enabled with ${modelRef} as the curator.`);\n\t\treturn;\n\t}\n\tif (role === \"executor\") {\n\t\tconst router = host.settingsManager.getModelRouterSettings();\n\t\thost.settingsManager.setModelRouterSettings({ ...router, executorModel: modelRef });\n\t\tconst hint = router.enabled ? \"\" : \" Model router is currently disabled — enable it in /settings → Model Router.\";\n\t\thost.showStatus(`${modelRef} set as the toolkit executor (direct Level-0 hits route to it).${hint}`);\n\t\treturn;\n\t}\n\tif (role === \"scout\") {\n\t\thost.settingsManager.setScoutSettings({ enabled: true, model: modelRef });\n\t\thost.showStatus(`${modelRef} set as the repository scout (context_scout enabled).`);\n\t\treturn;\n\t}\n\tconst router = host.settingsManager.getModelRouterSettings();\n\tconst field =\n\t\trole === \"router-cheap\"\n\t\t\t? \"cheapModel\"\n\t\t\t: role === \"router-medium\"\n\t\t\t\t? \"mediumModel\"\n\t\t\t\t: role === \"router-expensive\"\n\t\t\t\t\t? \"expensiveModel\"\n\t\t\t\t\t: role === \"judge\"\n\t\t\t\t\t\t? \"judgeModel\"\n\t\t\t\t\t\t: \"learningModel\";\n\thost.settingsManager.setModelRouterSettings({ ...router, [field]: modelRef });\n\tconst hint = router.enabled ? \"\" : \" Model router is currently disabled — enable it in /settings → Model Router.\";\n\thost.showStatus(`${modelRef} set as ${role.replace(\"router-\", \"router \")} model.${hint}`);\n}\n"]}
@@ -17,6 +17,7 @@ import { type Component, type Container, Loader, type TUI } from "@caupulican/pi
17
17
  import type { AgentSession, GoalContinuationLoopOptions, GoalContinuationLoopResult } from "../../core/agent-session.ts";
18
18
  import type { AgentSessionRuntime } from "../../core/agent-session-runtime.ts";
19
19
  import type { ExtensionCommandContext } from "../../core/extensions/index.ts";
20
+ import type { GoalState } from "../../core/goals/goal-state.ts";
20
21
  import type { KeybindingsManager } from "../../core/keybindings.ts";
21
22
  import { MissingSessionCwdError } from "../../core/session-cwd.ts";
22
23
  import type { SettingsManager } from "../../core/settings-manager.ts";
@@ -110,6 +111,21 @@ export type ParsedGoalContinueCommand = {
110
111
  ok: false;
111
112
  error: string;
112
113
  };
114
+ export interface GoalCommandHost {
115
+ readonly session: {
116
+ getGoalStateSnapshot: () => GoalState | undefined;
117
+ saveGoalStateSnapshot: (state: GoalState) => string;
118
+ sendUserMessage: (content: string) => Promise<void>;
119
+ continueGoalLoop: (options: GoalContinuationLoopOptions) => Promise<GoalContinuationLoopResult>;
120
+ getGoalRuntimeSnapshot: (settings: {
121
+ maxStallTurns: number;
122
+ }) => ReturnType<AgentSession["getGoalRuntimeSnapshot"]>;
123
+ };
124
+ showStatus(message: string): void;
125
+ showError(message: string): void;
126
+ refreshAutonomyFooterStatus(): void;
127
+ }
128
+ export declare function handleGoalCommand(host: GoalCommandHost, text: string): Promise<void>;
113
129
  export interface GoalContinueCommandHost {
114
130
  readonly session: {
115
131
  continueGoalLoop: (options: GoalContinuationLoopOptions) => Promise<GoalContinuationLoopResult>;