@caupulican/pi-adaptative 0.93.2 → 0.93.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +6 -6
  3. package/dist/cli/args.js +1 -1
  4. package/dist/cli/args.js.map +1 -1
  5. package/dist/core/agent-session-contracts.d.ts +2 -2
  6. package/dist/core/agent-session-contracts.d.ts.map +1 -1
  7. package/dist/core/agent-session-contracts.js.map +1 -1
  8. package/dist/core/agent-session.d.ts.map +1 -1
  9. package/dist/core/agent-session.js +1 -2
  10. package/dist/core/agent-session.js.map +1 -1
  11. package/dist/core/autonomy/subagent-prompt.d.ts +1 -1
  12. package/dist/core/autonomy/subagent-prompt.js.map +1 -1
  13. package/dist/core/cost-guard.js +1 -1
  14. package/dist/core/cost-guard.js.map +1 -1
  15. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  16. package/dist/core/delegation/worker-attempt-executor.js +7 -5
  17. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  18. package/dist/core/delegation/worker-delegation-request.d.ts +5 -2
  19. package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
  20. package/dist/core/delegation/worker-delegation-request.js +1 -1
  21. package/dist/core/delegation/worker-delegation-request.js.map +1 -1
  22. package/dist/core/goals/goal-session-controller.js +1 -1
  23. package/dist/core/goals/goal-session-controller.js.map +1 -1
  24. package/dist/core/model-router-controller.js +2 -2
  25. package/dist/core/model-router-controller.js.map +1 -1
  26. package/dist/core/orchestration/risk-budget.d.ts +0 -10
  27. package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
  28. package/dist/core/orchestration/risk-budget.js +0 -14
  29. package/dist/core/orchestration/risk-budget.js.map +1 -1
  30. package/dist/core/provider-prompt-contracts.d.ts +1 -0
  31. package/dist/core/provider-prompt-contracts.d.ts.map +1 -1
  32. package/dist/core/provider-prompt-contracts.js +6 -5
  33. package/dist/core/provider-prompt-contracts.js.map +1 -1
  34. package/dist/core/reflection-controller.js +1 -1
  35. package/dist/core/reflection-controller.js.map +1 -1
  36. package/dist/core/settings-manager.d.ts +5 -6
  37. package/dist/core/settings-manager.d.ts.map +1 -1
  38. package/dist/core/settings-manager.js +8 -13
  39. package/dist/core/settings-manager.js.map +1 -1
  40. package/dist/core/system-prompt-builder.d.ts +1 -4
  41. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  42. package/dist/core/system-prompt-builder.js +10 -10
  43. package/dist/core/system-prompt-builder.js.map +1 -1
  44. package/dist/core/tools/delegate.d.ts +0 -16
  45. package/dist/core/tools/delegate.d.ts.map +1 -1
  46. package/dist/core/tools/delegate.js +21 -11
  47. package/dist/core/tools/delegate.js.map +1 -1
  48. package/dist/core/tools/edit.js +1 -1
  49. package/dist/core/tools/edit.js.map +1 -1
  50. package/dist/core/tools/profile-writer.d.ts +0 -9
  51. package/dist/core/tools/profile-writer.d.ts.map +1 -1
  52. package/dist/core/tools/profile-writer.js +0 -3
  53. package/dist/core/tools/profile-writer.js.map +1 -1
  54. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  55. package/dist/modes/interactive/components/settings-selector.js +7 -16
  56. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  57. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  58. package/dist/modes/interactive/components/thinking-selector.js +2 -11
  59. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  60. package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
  61. package/dist/modes/interactive/local-model-commands.js +1 -10
  62. package/dist/modes/interactive/local-model-commands.js.map +1 -1
  63. package/dist/modes/interactive/thinking-level-descriptions.d.ts +4 -0
  64. package/dist/modes/interactive/thinking-level-descriptions.d.ts.map +1 -0
  65. package/dist/modes/interactive/thinking-level-descriptions.js +12 -0
  66. package/dist/modes/interactive/thinking-level-descriptions.js.map +1 -0
  67. package/docs/resources.md +1 -1
  68. package/docs/settings.md +7 -5
  69. package/docs/worker-profiles.md +3 -3
  70. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  71. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  72. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  73. package/examples/extensions/sandbox/package-lock.json +2 -2
  74. package/examples/extensions/sandbox/package.json +1 -1
  75. package/examples/extensions/with-deps/package-lock.json +2 -2
  76. package/examples/extensions/with-deps/package.json +1 -1
  77. package/npm-shrinkwrap.json +12 -12
  78. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"thinking-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/thinking-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAajE;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,2BAA2B;IACzE,YACC,YAAY,EAAE,aAAa,EAC3B,eAAe,EAAE,aAAa,EAAE,EAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EACxC,QAAQ,EAAE,MAAM,IAAI,EAcpB;CACD"}
1
+ {"version":3,"file":"thinking-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/thinking-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,2BAA2B;IACzE,YACC,YAAY,EAAE,aAAa,EAC3B,eAAe,EAAE,aAAa,EAAE,EAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EACxC,QAAQ,EAAE,MAAM,IAAI,EAcpB;CACD"}
@@ -1,14 +1,5 @@
1
+ import { THINKING_LEVEL_DESCRIPTIONS } from "../thinking-level-descriptions.js";
1
2
  import { BorderedSelectListComponent } from "./selector-list.js";
2
- const LEVEL_DESCRIPTIONS = {
3
- off: "No reasoning",
4
- minimal: "Very brief reasoning (~1k tokens)",
5
- low: "Light reasoning (~2k tokens)",
6
- medium: "Moderate reasoning (~8k tokens)",
7
- high: "Deep reasoning (~16k tokens)",
8
- xhigh: "Maximum reasoning (~32k tokens)",
9
- max: "Maximum reasoning depth for the hardest problems",
10
- ultra: "Maximum reasoning with reinforced proactive delegation",
11
- };
12
3
  /**
13
4
  * Component that renders a thinking level selector with borders
14
5
  */
@@ -17,7 +8,7 @@ export class ThinkingSelectorComponent extends BorderedSelectListComponent {
17
8
  const thinkingLevels = availableLevels.map((level) => ({
18
9
  value: level,
19
10
  label: level,
20
- description: LEVEL_DESCRIPTIONS[level],
11
+ description: THINKING_LEVEL_DESCRIPTIONS[level],
21
12
  }));
22
13
  super({
23
14
  items: thinkingLevels,
@@ -1 +1 @@
1
- {"version":3,"file":"thinking-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/thinking-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,MAAM,kBAAkB,GAAkC;IACzD,GAAG,EAAE,cAAc;IACnB,OAAO,EAAE,mCAAmC;IAC5C,GAAG,EAAE,8BAA8B;IACnC,MAAM,EAAE,iCAAiC;IACzC,IAAI,EAAE,8BAA8B;IACpC,KAAK,EAAE,iCAAiC;IACxC,GAAG,EAAE,kDAAkD;IACvD,KAAK,EAAE,wDAAwD;CAC/D,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,2BAA2B;IACzE,YACC,YAA2B,EAC3B,eAAgC,EAChC,QAAwC,EACxC,QAAoB;QAEpB,MAAM,cAAc,GAAiB,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACpE,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,KAAK;YACZ,WAAW,EAAE,kBAAkB,CAAC,KAAK,CAAC;SACtC,CAAC,CAAC,CAAC;QACJ,KAAK,CAAC;YACL,KAAK,EAAE,cAAc;YACrB,UAAU,EAAE,cAAc,CAAC,MAAM;YACjC,YAAY,EAAE,YAAY;YAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAsB,CAAC;YACrD,QAAQ;SACR,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import type { ThinkingLevel } from \"@caupulican/pi-agent-core\";\nimport type { SelectItem } from \"@caupulican/pi-tui\";\nimport { BorderedSelectListComponent } from \"./selector-list.ts\";\n\nconst 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\tmax: \"Maximum reasoning depth for the hardest problems\",\n\tultra: \"Maximum reasoning with reinforced proactive delegation\",\n};\n\n/**\n * Component that renders a thinking level selector with borders\n */\nexport class ThinkingSelectorComponent extends BorderedSelectListComponent {\n\tconstructor(\n\t\tcurrentLevel: ThinkingLevel,\n\t\tavailableLevels: ThinkingLevel[],\n\t\tonSelect: (level: ThinkingLevel) => void,\n\t\tonCancel: () => void,\n\t) {\n\t\tconst thinkingLevels: SelectItem[] = availableLevels.map((level) => ({\n\t\t\tvalue: level,\n\t\t\tlabel: level,\n\t\t\tdescription: LEVEL_DESCRIPTIONS[level],\n\t\t}));\n\t\tsuper({\n\t\t\titems: thinkingLevels,\n\t\t\tmaxVisible: thinkingLevels.length,\n\t\t\tcurrentValue: currentLevel,\n\t\t\tonSelect: (value) => onSelect(value as ThinkingLevel),\n\t\t\tonCancel,\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"thinking-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/thinking-selector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,2BAA2B;IACzE,YACC,YAA2B,EAC3B,eAAgC,EAChC,QAAwC,EACxC,QAAoB;QAEpB,MAAM,cAAc,GAAiB,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACpE,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,KAAK;YACZ,WAAW,EAAE,2BAA2B,CAAC,KAAK,CAAC;SAC/C,CAAC,CAAC,CAAC;QACJ,KAAK,CAAC;YACL,KAAK,EAAE,cAAc;YACrB,UAAU,EAAE,cAAc,CAAC,MAAM;YACjC,YAAY,EAAE,YAAY;YAC1B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAsB,CAAC;YACrD,QAAQ;SACR,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import type { ThinkingLevel } from \"@caupulican/pi-agent-core\";\nimport type { SelectItem } from \"@caupulican/pi-tui\";\nimport { THINKING_LEVEL_DESCRIPTIONS } from \"../thinking-level-descriptions.ts\";\nimport { BorderedSelectListComponent } from \"./selector-list.ts\";\n\n/**\n * Component that renders a thinking level selector with borders\n */\nexport class ThinkingSelectorComponent extends BorderedSelectListComponent {\n\tconstructor(\n\t\tcurrentLevel: ThinkingLevel,\n\t\tavailableLevels: ThinkingLevel[],\n\t\tonSelect: (level: ThinkingLevel) => void,\n\t\tonCancel: () => void,\n\t) {\n\t\tconst thinkingLevels: SelectItem[] = availableLevels.map((level) => ({\n\t\t\tvalue: level,\n\t\t\tlabel: level,\n\t\t\tdescription: THINKING_LEVEL_DESCRIPTIONS[level],\n\t\t}));\n\t\tsuper({\n\t\t\titems: thinkingLevels,\n\t\t\tmaxVisible: thinkingLevels.length,\n\t\t\tcurrentValue: currentLevel,\n\t\t\tonSelect: (value) => onSelect(value as ThinkingLevel),\n\t\t\tonCancel,\n\t\t});\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"local-model-commands.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/local-model-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,EACN,KAAK,SAAS,EACd,SAAS,EAIT,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,EAAE,oBAAoB,EAAE,KAAK,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAWxG,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAG7F,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AASpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,OAAO,EAAE,KAAK,WAAW,EAAgC,MAAM,uCAAuC,CAAC;AAMvG,KAAK,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK;IAAE,SAAS,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAsCxF,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAC1C,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,6FAA6F;AAC7F,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,kBAAkB,GAAG,iBAAiB,CAAC,GAAG;QAAE,aAAa,CAAC,EAAE,aAAa,CAAA;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AqDzE;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA4DrH;AAED,wBAAsB,oBAAoB,CACzC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CA8Cf;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAC1C,IAAI,EAAE,cAAc,EACpB,UAAU,EAAE,oBAAoB,EAChC,aAAa,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CAwDf;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC3G;AAuED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCxE;AA2FD,iGAAiG;AACjG,4FAA4F;AAC5F,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CA2CtE;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAmBnE;AAoED;kGACkG;AAClG,wBAAsB,mBAAmB,CACxC,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CA+Df;AAqBD,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAqCjG"}
1
+ {"version":3,"file":"local-model-commands.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/local-model-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;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CAAC,CA8Cf;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAC1C,IAAI,EAAE,cAAc,EACpB,UAAU,EAAE,oBAAoB,EAChC,aAAa,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CAwDf;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC3G;AAuED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCxE;AA2FD,iGAAiG;AACjG,4FAA4F;AAC5F,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CA2CtE;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAmBnE;AAoED;kGACkG;AAClG,wBAAsB,mBAAmB,CACxC,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,IAAI,CAAC,CA+Df;AAqBD,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAqCjG"}
@@ -33,22 +33,13 @@ import { ModelSelectorComponent } from "./components/model-selector.js";
33
33
  import { ModelSuggestionSelectorComponent } from "./components/model-suggestion-selector.js";
34
34
  import { presentModelFitnessOutcome } from "./model-fitness-presentation.js";
35
35
  import { getSelectListTheme } from "./theme/theme.js";
36
+ import { THINKING_LEVEL_DESCRIPTIONS } from "./thinking-level-descriptions.js";
36
37
  const MODEL_ROUTER_THINKING_SELECT_LIST_LAYOUT = {
37
38
  minPrimaryColumnWidth: 12,
38
39
  maxPrimaryColumnWidth: 32,
39
40
  };
40
41
  const MODEL_ROUTER_THINKING_INHERIT_VALUE = "__inherit_model_router_thinking__";
41
42
  const MODEL_ROUTER_THINKING_INHERIT_LABEL = "(inherit)";
42
- const THINKING_LEVEL_DESCRIPTIONS = {
43
- off: "No reasoning",
44
- minimal: "Very brief reasoning (~1k tokens)",
45
- low: "Light reasoning (~2k tokens)",
46
- medium: "Moderate reasoning (~8k tokens)",
47
- high: "Deep reasoning (~16k tokens)",
48
- xhigh: "Maximum reasoning (~32k tokens)",
49
- max: "Maximum reasoning depth for the hardest problems",
50
- ultra: "Maximum reasoning with reinforced proactive delegation",
51
- };
52
43
  const MODEL_ROUTER_THINKING_FALLBACK_LEVELS = [
53
44
  "off",
54
45
  "minimal",
@@ -1 +1 @@
1
- {"version":3,"file":"local-model-commands.js","sourceRoot":"","sources":["../../../src/modes/interactive/local-model-commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAEN,SAAS,EAET,UAAU,GAGV,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,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAA6B,MAAM,uCAAuC,CAAC;AACxG,OAAO,EACN,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,EAClB,0BAA0B,EAC1B,yBAAyB,EACzB,oBAA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AC,CAAC;AAC3F,CAAC","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 { existsSync, rmSync } from \"node:fs\";\nimport { totalmem } from \"node:os\";\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\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 { deriveLocalContextSizing } from \"../../core/models/context-sizing.ts\";\nimport { DEFAULT_MODEL_SUGGESTIONS } from \"../../core/models/default-model-suggestions.ts\";\nimport { FitnessStore } from \"../../core/models/fitness-store.ts\";\nimport { PrismLlamaCppRuntime, type PrismModelDescriptor } from \"../../core/models/llamacpp-runtime.ts\";\nimport {\n\tHF_TRANSFORMERS_PROVIDER,\n\tPRISM_LLAMACPP_PROVIDER,\n\tregisterLocalModel,\n\tregisterPrismLlamaCppModel,\n\tregisterTransformersModel,\n\tunregisterLocalModel,\n\tunregisterPrismLlamaCppModel,\n\tunregisterTransformersModel,\n} from \"../../core/models/local-registration.ts\";\nimport type { OllamaRuntime, TransformersRuntime } from \"../../core/models/local-runtime.ts\";\nimport { planManagedOllamaModel } from \"../../core/models/managed-ollama-model.ts\";\nimport { matchesInstalledLocalModel, normalizeModelSource } from \"../../core/models/model-ref.ts\";\nimport { NeedleRuntime } from \"../../core/models/needle-runtime.ts\";\nimport {\n\tderivePrismLlamaCppNumCtx,\n\tensurePrismModelFilesThenServe,\n\tisPiManagedPrismLlamaCppModel,\n\tPRISM_LLAMACPP_DESCRIPTORS,\n\tPRISM_LLAMACPP_SERVE_PORT,\n} from \"../../core/models/prism-llamacpp-lifecycle.ts\";\nimport { isProbeAllFailed } from \"../../core/research/model-fitness.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport type { ToolProbeResult } from \"../../core/tool-protocol-controller.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 { presentModelFitnessOutcome } from \"./model-fitness-presentation.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\tmax: \"Maximum reasoning depth for the hardest problems\",\n\tultra: \"Maximum reasoning with reinforced proactive delegation\",\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, \"probeToolCalling\" | \"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\tgetTransformersRuntime(modelId: string, baseUrl?: string): TransformersRuntime;\n\t/**\n\t * Seam for the pi-managed prism llama.cpp runtime (Bonsai-27B and future curated prism-ml\n\t * models). Production (interactive-mode.ts's `localModelHost()`) always supplies this, wired\n\t * through `AgentSession.getPrismLlamaCppRuntime()` -> `LocalRuntimeController`'s cached instance\n\t * — the SAME instance the readiness gate uses, mirroring `getTransformersRuntime` above (cached\n\t * for the session's lifetime, so `stop()`/`removePrismLlamaCppModel` reattach to the SAME\n\t * instance that holds the running child process instead of each tracking an untracked one).\n\t * Optional only so tests can inject a fake without needing the full session stack; the fallback\n\t * below (a fresh, uncached instance) is a test convenience, never the production path.\n\t */\n\tgetPrismLlamaCppRuntime?(): PrismLlamaCppRuntime;\n\t/**\n\t * Seam for the pi-managed needle runtime (see needle-runtime.ts) — optional so tests can inject a\n\t * fake, falling back to a fresh instance otherwise. Unlike `getPrismLlamaCppRuntime` above, needle\n\t * has no session-caching need: every invocation is a one-shot `runCommand` call with no persistent\n\t * child process to reattach to (needle-runtime.ts's `dispose()` is a documented no-op), so a fresh\n\t * instance per call is functionally identical to a cached one — `runtimeDir()`/`modelsDir()`/\n\t * `checkpointPath()` are pure path derivations from `agentDir`, not in-memory state.\n\t */\n\tgetNeedleRuntime?(): NeedleRuntime;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\nfunction getPrismLlamaCppRuntime(host: LocalModelHost): PrismLlamaCppRuntime {\n\treturn host.getPrismLlamaCppRuntime?.() ?? new PrismLlamaCppRuntime({ agentDir: getAgentDir() });\n}\n\nfunction getNeedleRuntime(host: LocalModelHost): NeedleRuntime {\n\treturn host.getNeedleRuntime?.() ?? new NeedleRuntime({ agentDir: getAgentDir() });\n}\n\n/**\n * Mirrors needle-runtime.ts's own (module-private, not exported) NEEDLE_SMOKE_TOOLS — the default\n * tool set for `/models needle <query>` when no tools-json is supplied, so an ad-hoc probe has the\n * same sensible starting point the install pipeline's own smoke test already exercises. Kept in\n * sync manually since the source constant isn't exported from the frozen runtime module.\n */\nconst NEEDLE_DEFAULT_TOOLS = [\n\t{\n\t\tname: \"get_weather\",\n\t\tdescription: \"Get current weather for a city.\",\n\t\tparameters: { location: { type: \"string\", description: \"City name.\", required: true } },\n\t},\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\tlet stoppedTransformers = 0;\n\t\t\tfor (const model of host.session.modelRegistry\n\t\t\t\t.getAll()\n\t\t\t\t.filter((entry) => entry.provider === HF_TRANSFORMERS_PROVIDER)) {\n\t\t\t\tconst serverUrl = model.baseUrl.replace(/\\/v1\\/?$/, \"\");\n\t\t\t\tif (host.getTransformersRuntime(model.id, serverUrl).stop().stopped) stoppedTransformers++;\n\t\t\t}\n\t\t\t// Only touch the prism runtime when a pi-managed prism model is actually registered —\n\t\t\t// never construct/stop it on a session that never used one. isPiManagedPrismLlamaCppModel\n\t\t\t// is the SAME discriminator the readiness gate uses, so this never reaches for a user's own\n\t\t\t// hand-configured llama-cpp entry (e.g. the built-in llama-cpp/local catalog model).\n\t\t\tconst hasPiManagedPrismModel = host.session.modelRegistry\n\t\t\t\t.getAll()\n\t\t\t\t.some((entry) => isPiManagedPrismLlamaCppModel(entry));\n\t\t\tconst stoppedPrism = hasPiManagedPrismModel && getPrismLlamaCppRuntime(host).stop().stopped;\n\t\t\tconst stoppedAny = stopped.stopped || stoppedTransformers > 0 || stoppedPrism;\n\t\t\thost.showStatus(\n\t\t\t\tstoppedAny\n\t\t\t\t\t? `Pi-managed local model server stopped${stoppedTransformers > 0 ? ` (${stoppedTransformers} Transformers sidecar(s))` : \"\"}${stoppedPrism ? \" (prism llama.cpp server)\" : \"\"}; 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 === \"import\") {\n\t\t\tconst imported = host.localRuntime.importUserModels();\n\t\t\thost.showStatus(\n\t\t\t\t`Imported Ollama models from ${imported.sourceDir} into pi-owned store ${imported.targetDir}: ` +\n\t\t\t\t\t`${imported.manifestsImported} manifest(s), ${imported.blobsHardlinked} blob(s) hardlinked, ` +\n\t\t\t\t\t`${imported.blobsCopied} blob(s) copied, ${imported.blobsSkipped + imported.manifestsSkipped} existing file(s) skipped.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"needle\") {\n\t\t\tif (rest.length === 0) {\n\t\t\t\thost.showStatus(\"Usage: /models needle <query> [tools-json]\");\n\t\t\t\thost.showStatus(\n\t\t\t\t\t` tools-json defaults to the smoke-test tool set: ${JSON.stringify(NEEDLE_DEFAULT_TOOLS)}`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait runNeedleQuery(host, rest);\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] | curated HF full-base ref | 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\tif (source.type === \"transformers\") {\n\t\t\t\tawait addTransformersModel(host, source.modelId);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"prism-llamacpp\") {\n\t\t\t\tconst descriptor = PRISM_LLAMACPP_DESCRIPTORS[source.modelId];\n\t\t\t\tif (!descriptor) {\n\t\t\t\t\thost.showStatus(`${source.modelId} has no curated prism llama.cpp descriptor — this is a wiring bug.`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait addPrismLlamaCppModel(host, descriptor);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"needle\") {\n\t\t\t\tawait addNeedleModel(host);\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\tconst source = normalizeModelSource(ref);\n\t\t\tif (source.type === \"transformers\") {\n\t\t\t\tawait removeTransformersModel(host, source.modelId, confirmed);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"prism-llamacpp\") {\n\t\t\t\tawait removePrismLlamaCppModel(host, source.modelId, confirmed);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"needle\") {\n\t\t\t\tawait removeNeedleModel(host, confirmed);\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\nfunction formatOllamaStore(store: { kind: string; path: string; modelCount: number } | undefined): string {\n\tif (!store) return \"unknown store (0 model(s))\";\n\treturn `${store.path} [${store.kind}, ${store.modelCount} model(s)]`;\n}\n\nexport async function ensureLocalServer(host: LocalModelHost): Promise<boolean> {\n\tconst status = await host.localRuntime.detect();\n\tif (status.serverUp) {\n\t\tif (status.activeStore?.kind === \"pi-owned\") return true;\n\t\thost.showStatus(\n\t\t\t`Ollama is already running on ${status.serverUrl} with store ${formatOllamaStore(status.activeStore)}; ` +\n\t\t\t\t`pi's canonical store is ${status.ownedModelsDir} (${status.ownedStore.modelCount} model(s)). ` +\n\t\t\t\t\"Stop the other serve or run /models import before adding models.\",\n\t\t);\n\t\treturn false;\n\t}\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\tconst models = status.serverUp ? await host.localRuntime.list() : [];\n\tconst ollamaLines = status.serverUp\n\t\t? [\n\t\t\t\t`Ollama models (active store: ${formatOllamaStore(status.activeStore)}; pi-owned store: ${status.ownedModelsDir} with ${status.ownedStore.modelCount} model(s)):`,\n\t\t\t\t...(models.length === 0\n\t\t\t\t\t? [\" (none installed — /models add <ref>, /models import, or /models suggest for a validated roster)\"]\n\t\t\t\t\t: []),\n\t\t\t]\n\t\t: [\n\t\t\t\t\"Ollama models:\",\n\t\t\t\t...(status.binaryPath\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t` server not running (binary: ${status.binarySource}). /models add starts it on demand; /fitness probes registered models.`,\n\t\t\t\t\t\t]\n\t\t\t\t\t: host.localRuntime.installGuide().map((line) => ` ${line}`)),\n\t\t\t];\n\tconst fitness = FitnessStore.forAgentDir(getAgentDir()).getForHost();\n\tconst transformersModels = host.session.modelRegistry\n\t\t.getAll()\n\t\t.filter((model) => model.provider === HF_TRANSFORMERS_PROVIDER);\n\tconst transformersLines = await Promise.all(\n\t\ttransformersModels.map(async (model) => {\n\t\t\tconst serverUrl = model.baseUrl.replace(/\\/v1\\/?$/, \"\");\n\t\t\tconst runtime = host.getTransformersRuntime(model.id, serverUrl);\n\t\t\tconst runtimeStatus = await runtime.detect();\n\t\t\tconst report = fitness.find((entry) => entry.model === `${HF_TRANSFORMERS_PROVIDER}/${model.id}`);\n\t\t\tconst readiness = runtimeStatus.serverUp\n\t\t\t\t? \"server running\"\n\t\t\t\t: runtimeStatus.runtimeInstalled\n\t\t\t\t\t? \"runtime installed\"\n\t\t\t\t\t: \"runtime missing\";\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 ${HF_TRANSFORMERS_PROVIDER}/${model.id}`;\n\t\t\treturn ` - ${model.id} (${readiness}, cache: ${runtimeStatus.cacheDir}) · ${probe}`;\n\t\t}),\n\t);\n\tconst lines = [\n\t\t...ollamaLines,\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...(transformersLines.length > 0 ? [\"Pi-managed Transformers models:\", ...transformersLines] : []),\n\t\t\"Commands: /models import · /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 pi's owned Ollama store)`);\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 installed = await host.localRuntime.list().catch(() => []);\n\tconst installedEntry = installed.find((entry) => matchesInstalledLocalModel(pullRef, entry.name));\n\tconst shown = await host.localRuntime.show(pullRef);\n\tconst sizing =\n\t\tinstalledEntry && shown.ok\n\t\t\t? deriveLocalContextSizing({\n\t\t\t\t\thost: { totalMemBytes: totalmem() },\n\t\t\t\t\tmodel: { modelInfo: shown.info.modelInfo, weightsBytes: installedEntry.sizeBytes },\n\t\t\t\t\truntime: { supportsKvQuantization: true },\n\t\t\t\t})\n\t\t\t: undefined;\n\tconst managedPlan = planManagedOllamaModel({\n\t\tsourceRef: pullRef,\n\t\tmodelInfo: shown.ok ? shown.info.modelInfo : {},\n\t\tnumCtx: sizing?.numCtx,\n\t});\n\tlet registeredRef = pullRef;\n\tif (managedPlan) {\n\t\tconst created = await host.localRuntime.createModel({\n\t\t\tname: managedPlan.name,\n\t\t\t...managedPlan.create,\n\t\t});\n\t\tif (!created.ok) {\n\t\t\thost.showStatus(`Pulled, but could not create the managed model profile: ${created.error}`);\n\t\t\treturn;\n\t\t}\n\t\tregisteredRef = managedPlan.name;\n\t}\n\tconst registration = registerLocalModel({\n\t\tagentDir: getAgentDir(),\n\t\tref: registeredRef,\n\t\tbaseUrl: host.localRuntime.baseUrl,\n\t\tcontextWindow: sizing?.numCtx,\n\t\tservedContextWindow: sizing?.numCtx,\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/${registeredRef}. Probing fitness…`);\n\tawait runFitnessAndAssign(host, `ollama/${registeredRef}`, preselectRole);\n}\n\nexport async function addTransformersModel(\n\thost: LocalModelHost,\n\tmodelId: string,\n\tpreselectRole?: FitnessRole,\n): Promise<void> {\n\tconst runtime = host.getTransformersRuntime(modelId);\n\tlet status = await runtime.detect();\n\tif (!status.runtimeInstalled) {\n\t\thost.showStatus(`Installing isolated Transformers runtime for ${modelId} at ${status.venvDir}…`);\n\t\tconst installed = await runtime.installManaged((progress) => host.showStatus(` transformers: ${progress}`));\n\t\tif (!installed.ok) {\n\t\t\thost.showStatus(`Transformers runtime install failed: ${installed.error}`);\n\t\t\treturn;\n\t\t}\n\t\tstatus = await runtime.detect();\n\t}\n\tif (!status.runtimeInstalled) {\n\t\thost.showStatus(`Transformers runtime is still unavailable at ${status.venvDir}.`);\n\t\treturn;\n\t}\n\n\tconst downloaded = await runtime.downloadModel((progress) => host.showStatus(` ${modelId}: ${progress}`));\n\tif (!downloaded.ok) {\n\t\thost.showStatus(`Model download failed: ${downloaded.error}`);\n\t\treturn;\n\t}\n\n\tconst started = await runtime.start();\n\tif (!started.started && started.reason !== \"already_running\") {\n\t\thost.showStatus(`Could not start Transformers sidecar: ${started.reason}`);\n\t\treturn;\n\t}\n\n\tconst registration = registerTransformersModel({\n\t\tagentDir: getAgentDir(),\n\t\tmodelId,\n\t\tbaseUrl: runtime.baseUrl,\n\t});\n\tif (!registration.ok) {\n\t\thost.showStatus(`Installed, 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(\n\t\t`${modelId} installed in pi-managed Transformers and registered as ${HF_TRANSFORMERS_PROVIDER}/${modelId}. Probing fitness…`,\n\t);\n\tawait runFitnessAndAssign(host, `${HF_TRANSFORMERS_PROVIDER}/${modelId}`, preselectRole);\n}\n\n/**\n * Zero-setup pipeline for a curated prism llama.cpp model (Bonsai-27B): install the pinned prism\n * llama.cpp runtime (prebuilt release download, no compiler needed), ensure both GGUF files and\n * start llama-server (see `ensurePrismModelFilesThenServe`), register the model, then probe\n * fitness. Mirrors addTransformersModel's shape — each stage checks its own `{ ok }`/\n * `{ runtimeInstalled }` result and stops with an honest status message on failure; nothing\n * continues past a failed stage.\n */\nexport async function addPrismLlamaCppModel(\n\thost: LocalModelHost,\n\tdescriptor: PrismModelDescriptor,\n\tpreselectRole?: FitnessRole,\n): Promise<void> {\n\tconst runtime = getPrismLlamaCppRuntime(host);\n\tconst modelId = descriptor.repo;\n\n\tlet status = await runtime.detect();\n\tif (!status.runtimeInstalled) {\n\t\thost.showStatus(`Installing prism llama.cpp runtime for ${descriptor.displayName} at ${runtime.runtimeDir()}…`);\n\t\tconst installed = await runtime.installManaged((progress) => host.showStatus(` prism-llamacpp: ${progress}`));\n\t\tif (!installed.ok) {\n\t\t\thost.showStatus(`Prism llama.cpp runtime install failed: ${installed.error}`);\n\t\t\treturn;\n\t\t}\n\t\tstatus = await runtime.detect();\n\t}\n\tif (!status.runtimeInstalled) {\n\t\thost.showStatus(`Prism llama.cpp runtime is still unavailable at ${runtime.runtimeDir()}.`);\n\t\treturn;\n\t}\n\n\tconst numCtx = derivePrismLlamaCppNumCtx(totalmem());\n\tconst served = await ensurePrismModelFilesThenServe(\n\t\truntime,\n\t\tdescriptor,\n\t\t{ port: PRISM_LLAMACPP_SERVE_PORT, numCtx },\n\t\t(message) => host.showStatus(message),\n\t);\n\tif (!served.ok) {\n\t\tconst label =\n\t\t\tserved.stage === \"model-download\"\n\t\t\t\t? \"Model download failed\"\n\t\t\t\t: served.stage === \"mmproj-download\"\n\t\t\t\t\t? \"Vision projector download failed\"\n\t\t\t\t\t: \"Could not start llama-server\";\n\t\thost.showStatus(`${label}: ${served.error}`);\n\t\treturn;\n\t}\n\n\tconst registration = registerPrismLlamaCppModel({\n\t\tagentDir: getAgentDir(),\n\t\tmodelId,\n\t\tbaseUrl: served.baseUrl,\n\t\tcontextWindow: numCtx,\n\t\tservedContextWindow: numCtx,\n\t});\n\tif (!registration.ok) {\n\t\thost.showStatus(`Served, 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(\n\t\t`${descriptor.displayName} installed and registered as ${PRISM_LLAMACPP_PROVIDER}/${modelId}. Probing fitness…`,\n\t);\n\tawait runFitnessAndAssign(host, `${PRISM_LLAMACPP_PROVIDER}/${modelId}`, 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\nasync function removeTransformersModel(host: LocalModelHost, modelId: string, confirmed: boolean): Promise<void> {\n\tconst runtime = host.getTransformersRuntime(modelId);\n\tconst status = await runtime.detect();\n\tif (!confirmed) {\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t`Removing ${modelId} will delete:`,\n\t\t\t\t` - the ${HF_TRANSFORMERS_PROVIDER}/${modelId} entry in models.json`,\n\t\t\t\t` - its cached fitness report for this host`,\n\t\t\t\t`It will stop this session's Transformers sidecar if running. Cached weights remain under ${status.cacheDir}.`,\n\t\t\t\t`Run: /models remove hf.co/${modelId} confirm`,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\truntime.stop();\n\tconst registration = unregisterTransformersModel({ agentDir: getAgentDir(), modelId });\n\tif (!registration.ok) {\n\t\thost.showStatus(`Remove failed: ${registration.reason}`);\n\t\treturn;\n\t}\n\tFitnessStore.forAgentDir(getAgentDir()).remove(`${HF_TRANSFORMERS_PROVIDER}/${modelId}`);\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(\n\t\t`${modelId} registration and fitness report dropped; cached weights remain under ${status.cacheDir}.`,\n\t);\n}\n\n/**\n * Drop a pi-managed prism llama.cpp model's registration and fitness report. Production supplies a\n * session-cached runtime (see `LocalModelHost.getPrismLlamaCppRuntime`'s doc comment), the SAME\n * instance the readiness gate uses, so `stop()` here reliably reaches the tracked child whenever\n * THIS session is the one that started it — including a server started earlier in the session by\n * the readiness gate itself, not just by a prior `/models add`. Only a server started by a\n * DIFFERENT process/session (pi restarted, a different terminal) is out of reach; the status text\n * only carries that caveat, not a blanket \"may not stop\" disclaimer.\n */\nasync function removePrismLlamaCppModel(host: LocalModelHost, modelId: string, confirmed: boolean): Promise<void> {\n\tconst runtime = getPrismLlamaCppRuntime(host);\n\tif (!confirmed) {\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t`Removing ${modelId} will delete:`,\n\t\t\t\t` - the ${PRISM_LLAMACPP_PROVIDER}/${modelId} entry in models.json`,\n\t\t\t\t` - its cached fitness report for this host`,\n\t\t\t\t`Downloaded GGUF weights remain under ${runtime.modelsDir()}. Its llama-server will be stopped if ` +\n\t\t\t\t\t`this session started it; if it was started by a different pi process or session, it will keep ` +\n\t\t\t\t\t`serving on 127.0.0.1:${PRISM_LLAMACPP_SERVE_PORT} until stopped manually.`,\n\t\t\t\t`Run: /models remove hf.co/${modelId} confirm`,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\tconst stopped = runtime.stop();\n\tconst registration = unregisterPrismLlamaCppModel({ agentDir: getAgentDir(), modelId });\n\tif (!registration.ok) {\n\t\thost.showStatus(`Remove failed: ${registration.reason}`);\n\t\treturn;\n\t}\n\tFitnessStore.forAgentDir(getAgentDir()).remove(`${PRISM_LLAMACPP_PROVIDER}/${modelId}`);\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(\n\t\t`${modelId} registration and fitness report dropped; downloaded weights remain under ${runtime.modelsDir()}.` +\n\t\t\t(stopped.stopped\n\t\t\t\t? \" Its llama-server was stopped.\"\n\t\t\t\t: ` No llama-server tracked by this session — if one is still running (started by a different pi process or session), stop it manually on port ${PRISM_LLAMACPP_SERVE_PORT}.`),\n\t);\n}\n\n/**\n * Zero-setup pipeline for needle (see needle-runtime.ts): a standalone 26M-parameter function-call\n * test bench, NOT a chat/executor/lane model — no OpenAI-compatible endpoint, no models.json\n * registration, no /fitness probe. Install the pinned needle clone+venv (menu pick = consent, same\n * doctrine as the Transformers/prism precedents), download and sha256-verify the pickle checkpoint\n * (never called implicitly by installManaged — see the module's SECURITY note: the checkpoint is a\n * pickle file, arbitrary code execution on load by construction, so this is deliberately a separate\n * consent-adjacent step, not folded into install), then run its own smoke test as the honest\n * post-install verification. Each stage checks its own `{ ok }` result and stops with a stage-tagged\n * status on failure; nothing continues past a failed stage.\n */\nexport async function addNeedleModel(host: LocalModelHost): Promise<void> {\n\tconst runtime = getNeedleRuntime(host);\n\n\tlet status = await runtime.detect();\n\tif (!status.installed) {\n\t\thost.showStatus(`Installing needle (function-call test bench) at ${runtime.runtimeDir()}…`);\n\t\tconst installed = await runtime.installManaged((progress) => host.showStatus(` needle: ${progress}`));\n\t\tif (!installed.ok) {\n\t\t\thost.showStatus(`needle install failed: ${installed.error}`);\n\t\t\treturn;\n\t\t}\n\t\tstatus = await runtime.detect();\n\t}\n\tif (!status.installed) {\n\t\thost.showStatus(`needle is still unavailable at ${runtime.runtimeDir()}.`);\n\t\treturn;\n\t}\n\n\tconst downloaded = await runtime.downloadWeights((progress) => host.showStatus(` ${progress}`));\n\tif (!downloaded.ok) {\n\t\thost.showStatus(`needle weights download failed: ${downloaded.error}`);\n\t\treturn;\n\t}\n\n\thost.showStatus(\"Running needle smoke test (function-call probe)…\");\n\tconst smoke = await runtime.smokeTest();\n\tif (!smoke.ok || !smoke.call) {\n\t\thost.showStatus(\n\t\t\t`needle smoke test failed: ${smoke.error ?? \"smoke test reported success but returned no parsed call\"}`,\n\t\t);\n\t\treturn;\n\t}\n\thost.showStatus(\n\t\t`needle installed and verified: smoke test called ${smoke.call.name}(${JSON.stringify(smoke.call.arguments)}) ` +\n\t\t\t`in ${smoke.latencyMs}ms. Use /models needle <query> [tools-json] to test it further — it is a standalone ` +\n\t\t\t\"bench, not a chat/executor lane.\",\n\t);\n}\n\n/**\n * Wipe pi's needle runtime (clone+venv) and downloaded checkpoint. Unlike the other /models remove\n * flows, there is no models.json entry or fitness report to drop (needle never registers as a model\n * — see the roster entry's rationale) and no server process to stop (every needle invocation is a\n * one-shot runCommand call — see needle-runtime.ts's `dispose()` doc comment); removal is purely\n * deleting the two pi-owned directories. needle-runtime.ts exposes no delete method of its own (its\n * public surface is detect/installManaged/downloadWeights/runFunctionCall/smokeTest/dispose), so\n * this deletes directly via the runtime's own path-derivation methods.\n */\nasync function removeNeedleModel(host: LocalModelHost, confirmed: boolean): Promise<void> {\n\tconst runtime = getNeedleRuntime(host);\n\tconst runtimeDir = runtime.runtimeDir();\n\tconst modelsDir = runtime.modelsDir();\n\tif (!confirmed) {\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t\"Removing needle will delete:\",\n\t\t\t\t` - the pi-managed needle runtime (clone + venv) at ${runtimeDir}`,\n\t\t\t\t` - the downloaded checkpoint at ${runtime.checkpointPath()}`,\n\t\t\t\t\"needle has no models.json entry or fitness report — it is a standalone function-call test bench, \" +\n\t\t\t\t\t\"never registered as a chat/lane model.\",\n\t\t\t\t\"Run: /models remove hf.co/Cactus-Compute/needle confirm\",\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\tif (existsSync(runtimeDir)) rmSync(runtimeDir, { recursive: true, force: true });\n\tif (existsSync(modelsDir)) rmSync(modelsDir, { recursive: true, force: true });\n\thost.showStatus(`needle removed: deleted ${runtimeDir} and ${modelsDir}.`);\n}\n\n/**\n * `/models needle <query> [tools-json]` — the actual test surface for needle (see the roster\n * entry's rationale: there is no chat lane to probe it through). `tools-json`, when present, must be\n * the LAST whitespace-split token and start with `[`/`{` (compact JSON, no embedded spaces) —\n * anything else is treated as part of the query and the default smoke-test tool set is used. A fast\n * `detect()`-based pre-check gives friendly install guidance without spawning a doomed process;\n * `runFunctionCall`'s own not-installed/checkpoint-missing pre-flight is still the final honest\n * backstop if state changes between the check and the call.\n */\nasync function runNeedleQuery(host: LocalModelHost, args: string[]): Promise<void> {\n\tif (args.length === 0) {\n\t\thost.showStatus(\"Usage: /models needle <query> [tools-json]\");\n\t\treturn;\n\t}\n\n\tconst runtime = getNeedleRuntime(host);\n\tconst status = await runtime.detect();\n\tif (!status.installed) {\n\t\thost.showStatus(\n\t\t\t\"needle is not installed. Run /models add hf.co/Cactus-Compute/needle first (or /models suggest).\",\n\t\t);\n\t\treturn;\n\t}\n\tif (!status.checkpointPresent) {\n\t\thost.showStatus(\n\t\t\t\"needle is installed but its checkpoint hasn't been downloaded. Run /models add hf.co/Cactus-Compute/needle to fetch and verify it.\",\n\t\t);\n\t\treturn;\n\t}\n\n\tlet tools: unknown = NEEDLE_DEFAULT_TOOLS;\n\tlet toolsJsonParsed = false;\n\tconst last = args[args.length - 1];\n\tif (last && (last.startsWith(\"[\") || last.startsWith(\"{\"))) {\n\t\ttry {\n\t\t\ttools = JSON.parse(last);\n\t\t\ttoolsJsonParsed = true;\n\t\t} catch {\n\t\t\t// Not valid JSON — treat the whole thing as the query, keep the default tools.\n\t\t}\n\t}\n\tconst query = (toolsJsonParsed ? args.slice(0, -1) : args).join(\" \");\n\tif (!query.trim()) {\n\t\thost.showStatus(\"Usage: /models needle <query> [tools-json]\");\n\t\treturn;\n\t}\n\n\thost.showStatus(`needle: running \"${query}\"…`);\n\tconst startedAt = Date.now();\n\tconst result = await runtime.runFunctionCall({ query, tools });\n\tconst latencyMs = Date.now() - startedAt;\n\tif (!result.ok) {\n\t\thost.showStatus(`needle call failed (${latencyMs}ms): ${result.error}\\nraw output:\\n${result.rawOutput}`);\n\t\treturn;\n\t}\n\thost.showStatus(`needle (${latencyMs}ms): ${result.call.name}(${JSON.stringify(result.call.arguments)})`);\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\tconst source = normalizeModelSource(suggestion.pullRef);\n\t\t\t\tif (source.type === \"transformers\") {\n\t\t\t\t\tawait addTransformersModel(host, source.modelId, suggestion.assignRole);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (source.type === \"prism-llamacpp\") {\n\t\t\t\t\tconst descriptor = PRISM_LLAMACPP_DESCRIPTORS[source.modelId];\n\t\t\t\t\tif (!descriptor) {\n\t\t\t\t\t\thost.showStatus(\n\t\t\t\t\t\t\t`Suggestion ${suggestion.name} maps to an unknown curated prism model \"${source.modelId}\" — wiring bug.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait addPrismLlamaCppModel(host, descriptor, suggestion.assignRole);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (source.type === \"needle\") {\n\t\t\t\t\tawait addNeedleModel(host);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (source.type === \"local\") {\n\t\t\t\t\tawait addLocalModel(host, source.pullRef, suggestion.assignRole);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\thost.showStatus(\n\t\t\t\t\t`Suggestion ${suggestion.name} is not installable: ${source.type === \"rejected\" ? source.reason : source.ref}`,\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\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 (!presentModelFitnessOutcome(host, outcome)) return;\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\tlet toolProbe: ToolProbeResult | undefined;\n\t\tif (preselectRole === undefined || roleRequiresToolExecution(preselectRole)) {\n\t\t\thost.showStatus(`Real tool execution probe running on ${outcome.model}…`);\n\t\t\ttry {\n\t\t\t\tconst toolProbeReport = await host.session.probeToolCalling(outcome.model);\n\t\t\t\ttoolProbe =\n\t\t\t\t\ttoolProbeReport.results.find((result) => result.model === outcome.model) ??\n\t\t\t\t\t(toolProbeReport.results.length === 1 ? toolProbeReport.results[0] : undefined);\n\t\t\t} catch (error) {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t`Real tool execution probe unavailable for ${outcome.model}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\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\tconst toolFailure = toolRoleFailure(role, toolProbe);\n\t\t\t\t\tif (toolFailure) {\n\t\t\t\t\t\thost.showStatus(`${outcome.model} not assigned as ${role}: real tool execution ${toolFailure}.`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\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\nfunction roleRequiresToolExecution(role: FitnessRole): boolean {\n\treturn (\n\t\trole === \"executor\" ||\n\t\trole === \"scout\" ||\n\t\trole === \"router-cheap\" ||\n\t\trole === \"router-medium\" ||\n\t\trole === \"router-expensive\"\n\t);\n}\n\nfunction toolRoleFailure(role: FitnessRole, probe: ToolProbeResult | undefined): string | undefined {\n\tif (!roleRequiresToolExecution(role)) return undefined;\n\tif (!probe) return \"was not proven; run /toolprobe and retry /fitness\";\n\tif (probe.verdict === \"text-protocol\") return undefined;\n\tif (probe.verdict === \"native\" && probe.nativeGrade === \"task\") return undefined;\n\tif (probe.verdict === \"native\") return `reported native ${probe.nativeGrade ?? \"ungraded\"}, not task-scale calls`;\n\treturn `probe reported none${probe.diagnostic ? ` (${probe.diagnostic})` : \"\"}`;\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"]}
1
+ {"version":3,"file":"local-model-commands.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;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,8EAA8E,CAAC;IAClH,IAAI,CAAC,UAAU,CAAC,GAAG,QAAQ,WAAW,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;AAC3F,CAAC","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 { existsSync, rmSync } from \"node:fs\";\nimport { totalmem } from \"node:os\";\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\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 { deriveLocalContextSizing } from \"../../core/models/context-sizing.ts\";\nimport { DEFAULT_MODEL_SUGGESTIONS } from \"../../core/models/default-model-suggestions.ts\";\nimport { FitnessStore } from \"../../core/models/fitness-store.ts\";\nimport { PrismLlamaCppRuntime, type PrismModelDescriptor } from \"../../core/models/llamacpp-runtime.ts\";\nimport {\n\tHF_TRANSFORMERS_PROVIDER,\n\tPRISM_LLAMACPP_PROVIDER,\n\tregisterLocalModel,\n\tregisterPrismLlamaCppModel,\n\tregisterTransformersModel,\n\tunregisterLocalModel,\n\tunregisterPrismLlamaCppModel,\n\tunregisterTransformersModel,\n} from \"../../core/models/local-registration.ts\";\nimport type { OllamaRuntime, TransformersRuntime } from \"../../core/models/local-runtime.ts\";\nimport { planManagedOllamaModel } from \"../../core/models/managed-ollama-model.ts\";\nimport { matchesInstalledLocalModel, normalizeModelSource } from \"../../core/models/model-ref.ts\";\nimport { NeedleRuntime } from \"../../core/models/needle-runtime.ts\";\nimport {\n\tderivePrismLlamaCppNumCtx,\n\tensurePrismModelFilesThenServe,\n\tisPiManagedPrismLlamaCppModel,\n\tPRISM_LLAMACPP_DESCRIPTORS,\n\tPRISM_LLAMACPP_SERVE_PORT,\n} from \"../../core/models/prism-llamacpp-lifecycle.ts\";\nimport { isProbeAllFailed } from \"../../core/research/model-fitness.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport type { ToolProbeResult } from \"../../core/tool-protocol-controller.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 { presentModelFitnessOutcome } from \"./model-fitness-presentation.ts\";\nimport { getSelectListTheme } from \"./theme/theme.ts\";\nimport { THINKING_LEVEL_DESCRIPTIONS } from \"./thinking-level-descriptions.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 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, \"probeToolCalling\" | \"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\tgetTransformersRuntime(modelId: string, baseUrl?: string): TransformersRuntime;\n\t/**\n\t * Seam for the pi-managed prism llama.cpp runtime (Bonsai-27B and future curated prism-ml\n\t * models). Production (interactive-mode.ts's `localModelHost()`) always supplies this, wired\n\t * through `AgentSession.getPrismLlamaCppRuntime()` -> `LocalRuntimeController`'s cached instance\n\t * — the SAME instance the readiness gate uses, mirroring `getTransformersRuntime` above (cached\n\t * for the session's lifetime, so `stop()`/`removePrismLlamaCppModel` reattach to the SAME\n\t * instance that holds the running child process instead of each tracking an untracked one).\n\t * Optional only so tests can inject a fake without needing the full session stack; the fallback\n\t * below (a fresh, uncached instance) is a test convenience, never the production path.\n\t */\n\tgetPrismLlamaCppRuntime?(): PrismLlamaCppRuntime;\n\t/**\n\t * Seam for the pi-managed needle runtime (see needle-runtime.ts) — optional so tests can inject a\n\t * fake, falling back to a fresh instance otherwise. Unlike `getPrismLlamaCppRuntime` above, needle\n\t * has no session-caching need: every invocation is a one-shot `runCommand` call with no persistent\n\t * child process to reattach to (needle-runtime.ts's `dispose()` is a documented no-op), so a fresh\n\t * instance per call is functionally identical to a cached one — `runtimeDir()`/`modelsDir()`/\n\t * `checkpointPath()` are pure path derivations from `agentDir`, not in-memory state.\n\t */\n\tgetNeedleRuntime?(): NeedleRuntime;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowSelector(create: SelectorFactory): void;\n}\n\nfunction getPrismLlamaCppRuntime(host: LocalModelHost): PrismLlamaCppRuntime {\n\treturn host.getPrismLlamaCppRuntime?.() ?? new PrismLlamaCppRuntime({ agentDir: getAgentDir() });\n}\n\nfunction getNeedleRuntime(host: LocalModelHost): NeedleRuntime {\n\treturn host.getNeedleRuntime?.() ?? new NeedleRuntime({ agentDir: getAgentDir() });\n}\n\n/**\n * Mirrors needle-runtime.ts's own (module-private, not exported) NEEDLE_SMOKE_TOOLS — the default\n * tool set for `/models needle <query>` when no tools-json is supplied, so an ad-hoc probe has the\n * same sensible starting point the install pipeline's own smoke test already exercises. Kept in\n * sync manually since the source constant isn't exported from the frozen runtime module.\n */\nconst NEEDLE_DEFAULT_TOOLS = [\n\t{\n\t\tname: \"get_weather\",\n\t\tdescription: \"Get current weather for a city.\",\n\t\tparameters: { location: { type: \"string\", description: \"City name.\", required: true } },\n\t},\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\tlet stoppedTransformers = 0;\n\t\t\tfor (const model of host.session.modelRegistry\n\t\t\t\t.getAll()\n\t\t\t\t.filter((entry) => entry.provider === HF_TRANSFORMERS_PROVIDER)) {\n\t\t\t\tconst serverUrl = model.baseUrl.replace(/\\/v1\\/?$/, \"\");\n\t\t\t\tif (host.getTransformersRuntime(model.id, serverUrl).stop().stopped) stoppedTransformers++;\n\t\t\t}\n\t\t\t// Only touch the prism runtime when a pi-managed prism model is actually registered —\n\t\t\t// never construct/stop it on a session that never used one. isPiManagedPrismLlamaCppModel\n\t\t\t// is the SAME discriminator the readiness gate uses, so this never reaches for a user's own\n\t\t\t// hand-configured llama-cpp entry (e.g. the built-in llama-cpp/local catalog model).\n\t\t\tconst hasPiManagedPrismModel = host.session.modelRegistry\n\t\t\t\t.getAll()\n\t\t\t\t.some((entry) => isPiManagedPrismLlamaCppModel(entry));\n\t\t\tconst stoppedPrism = hasPiManagedPrismModel && getPrismLlamaCppRuntime(host).stop().stopped;\n\t\t\tconst stoppedAny = stopped.stopped || stoppedTransformers > 0 || stoppedPrism;\n\t\t\thost.showStatus(\n\t\t\t\tstoppedAny\n\t\t\t\t\t? `Pi-managed local model server stopped${stoppedTransformers > 0 ? ` (${stoppedTransformers} Transformers sidecar(s))` : \"\"}${stoppedPrism ? \" (prism llama.cpp server)\" : \"\"}; 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 === \"import\") {\n\t\t\tconst imported = host.localRuntime.importUserModels();\n\t\t\thost.showStatus(\n\t\t\t\t`Imported Ollama models from ${imported.sourceDir} into pi-owned store ${imported.targetDir}: ` +\n\t\t\t\t\t`${imported.manifestsImported} manifest(s), ${imported.blobsHardlinked} blob(s) hardlinked, ` +\n\t\t\t\t\t`${imported.blobsCopied} blob(s) copied, ${imported.blobsSkipped + imported.manifestsSkipped} existing file(s) skipped.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (action === \"needle\") {\n\t\t\tif (rest.length === 0) {\n\t\t\t\thost.showStatus(\"Usage: /models needle <query> [tools-json]\");\n\t\t\t\thost.showStatus(\n\t\t\t\t\t` tools-json defaults to the smoke-test tool set: ${JSON.stringify(NEEDLE_DEFAULT_TOOLS)}`,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait runNeedleQuery(host, rest);\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] | curated HF full-base ref | 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\tif (source.type === \"transformers\") {\n\t\t\t\tawait addTransformersModel(host, source.modelId);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"prism-llamacpp\") {\n\t\t\t\tconst descriptor = PRISM_LLAMACPP_DESCRIPTORS[source.modelId];\n\t\t\t\tif (!descriptor) {\n\t\t\t\t\thost.showStatus(`${source.modelId} has no curated prism llama.cpp descriptor — this is a wiring bug.`);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tawait addPrismLlamaCppModel(host, descriptor);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"needle\") {\n\t\t\t\tawait addNeedleModel(host);\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\tconst source = normalizeModelSource(ref);\n\t\t\tif (source.type === \"transformers\") {\n\t\t\t\tawait removeTransformersModel(host, source.modelId, confirmed);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"prism-llamacpp\") {\n\t\t\t\tawait removePrismLlamaCppModel(host, source.modelId, confirmed);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (source.type === \"needle\") {\n\t\t\t\tawait removeNeedleModel(host, confirmed);\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\nfunction formatOllamaStore(store: { kind: string; path: string; modelCount: number } | undefined): string {\n\tif (!store) return \"unknown store (0 model(s))\";\n\treturn `${store.path} [${store.kind}, ${store.modelCount} model(s)]`;\n}\n\nexport async function ensureLocalServer(host: LocalModelHost): Promise<boolean> {\n\tconst status = await host.localRuntime.detect();\n\tif (status.serverUp) {\n\t\tif (status.activeStore?.kind === \"pi-owned\") return true;\n\t\thost.showStatus(\n\t\t\t`Ollama is already running on ${status.serverUrl} with store ${formatOllamaStore(status.activeStore)}; ` +\n\t\t\t\t`pi's canonical store is ${status.ownedModelsDir} (${status.ownedStore.modelCount} model(s)). ` +\n\t\t\t\t\"Stop the other serve or run /models import before adding models.\",\n\t\t);\n\t\treturn false;\n\t}\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\tconst models = status.serverUp ? await host.localRuntime.list() : [];\n\tconst ollamaLines = status.serverUp\n\t\t? [\n\t\t\t\t`Ollama models (active store: ${formatOllamaStore(status.activeStore)}; pi-owned store: ${status.ownedModelsDir} with ${status.ownedStore.modelCount} model(s)):`,\n\t\t\t\t...(models.length === 0\n\t\t\t\t\t? [\" (none installed — /models add <ref>, /models import, or /models suggest for a validated roster)\"]\n\t\t\t\t\t: []),\n\t\t\t]\n\t\t: [\n\t\t\t\t\"Ollama models:\",\n\t\t\t\t...(status.binaryPath\n\t\t\t\t\t? [\n\t\t\t\t\t\t\t` server not running (binary: ${status.binarySource}). /models add starts it on demand; /fitness probes registered models.`,\n\t\t\t\t\t\t]\n\t\t\t\t\t: host.localRuntime.installGuide().map((line) => ` ${line}`)),\n\t\t\t];\n\tconst fitness = FitnessStore.forAgentDir(getAgentDir()).getForHost();\n\tconst transformersModels = host.session.modelRegistry\n\t\t.getAll()\n\t\t.filter((model) => model.provider === HF_TRANSFORMERS_PROVIDER);\n\tconst transformersLines = await Promise.all(\n\t\ttransformersModels.map(async (model) => {\n\t\t\tconst serverUrl = model.baseUrl.replace(/\\/v1\\/?$/, \"\");\n\t\t\tconst runtime = host.getTransformersRuntime(model.id, serverUrl);\n\t\t\tconst runtimeStatus = await runtime.detect();\n\t\t\tconst report = fitness.find((entry) => entry.model === `${HF_TRANSFORMERS_PROVIDER}/${model.id}`);\n\t\t\tconst readiness = runtimeStatus.serverUp\n\t\t\t\t? \"server running\"\n\t\t\t\t: runtimeStatus.runtimeInstalled\n\t\t\t\t\t? \"runtime installed\"\n\t\t\t\t\t: \"runtime missing\";\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 ${HF_TRANSFORMERS_PROVIDER}/${model.id}`;\n\t\t\treturn ` - ${model.id} (${readiness}, cache: ${runtimeStatus.cacheDir}) · ${probe}`;\n\t\t}),\n\t);\n\tconst lines = [\n\t\t...ollamaLines,\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...(transformersLines.length > 0 ? [\"Pi-managed Transformers models:\", ...transformersLines] : []),\n\t\t\"Commands: /models import · /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 pi's owned Ollama store)`);\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 installed = await host.localRuntime.list().catch(() => []);\n\tconst installedEntry = installed.find((entry) => matchesInstalledLocalModel(pullRef, entry.name));\n\tconst shown = await host.localRuntime.show(pullRef);\n\tconst sizing =\n\t\tinstalledEntry && shown.ok\n\t\t\t? deriveLocalContextSizing({\n\t\t\t\t\thost: { totalMemBytes: totalmem() },\n\t\t\t\t\tmodel: { modelInfo: shown.info.modelInfo, weightsBytes: installedEntry.sizeBytes },\n\t\t\t\t\truntime: { supportsKvQuantization: true },\n\t\t\t\t})\n\t\t\t: undefined;\n\tconst managedPlan = planManagedOllamaModel({\n\t\tsourceRef: pullRef,\n\t\tmodelInfo: shown.ok ? shown.info.modelInfo : {},\n\t\tnumCtx: sizing?.numCtx,\n\t});\n\tlet registeredRef = pullRef;\n\tif (managedPlan) {\n\t\tconst created = await host.localRuntime.createModel({\n\t\t\tname: managedPlan.name,\n\t\t\t...managedPlan.create,\n\t\t});\n\t\tif (!created.ok) {\n\t\t\thost.showStatus(`Pulled, but could not create the managed model profile: ${created.error}`);\n\t\t\treturn;\n\t\t}\n\t\tregisteredRef = managedPlan.name;\n\t}\n\tconst registration = registerLocalModel({\n\t\tagentDir: getAgentDir(),\n\t\tref: registeredRef,\n\t\tbaseUrl: host.localRuntime.baseUrl,\n\t\tcontextWindow: sizing?.numCtx,\n\t\tservedContextWindow: sizing?.numCtx,\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/${registeredRef}. Probing fitness…`);\n\tawait runFitnessAndAssign(host, `ollama/${registeredRef}`, preselectRole);\n}\n\nexport async function addTransformersModel(\n\thost: LocalModelHost,\n\tmodelId: string,\n\tpreselectRole?: FitnessRole,\n): Promise<void> {\n\tconst runtime = host.getTransformersRuntime(modelId);\n\tlet status = await runtime.detect();\n\tif (!status.runtimeInstalled) {\n\t\thost.showStatus(`Installing isolated Transformers runtime for ${modelId} at ${status.venvDir}…`);\n\t\tconst installed = await runtime.installManaged((progress) => host.showStatus(` transformers: ${progress}`));\n\t\tif (!installed.ok) {\n\t\t\thost.showStatus(`Transformers runtime install failed: ${installed.error}`);\n\t\t\treturn;\n\t\t}\n\t\tstatus = await runtime.detect();\n\t}\n\tif (!status.runtimeInstalled) {\n\t\thost.showStatus(`Transformers runtime is still unavailable at ${status.venvDir}.`);\n\t\treturn;\n\t}\n\n\tconst downloaded = await runtime.downloadModel((progress) => host.showStatus(` ${modelId}: ${progress}`));\n\tif (!downloaded.ok) {\n\t\thost.showStatus(`Model download failed: ${downloaded.error}`);\n\t\treturn;\n\t}\n\n\tconst started = await runtime.start();\n\tif (!started.started && started.reason !== \"already_running\") {\n\t\thost.showStatus(`Could not start Transformers sidecar: ${started.reason}`);\n\t\treturn;\n\t}\n\n\tconst registration = registerTransformersModel({\n\t\tagentDir: getAgentDir(),\n\t\tmodelId,\n\t\tbaseUrl: runtime.baseUrl,\n\t});\n\tif (!registration.ok) {\n\t\thost.showStatus(`Installed, 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(\n\t\t`${modelId} installed in pi-managed Transformers and registered as ${HF_TRANSFORMERS_PROVIDER}/${modelId}. Probing fitness…`,\n\t);\n\tawait runFitnessAndAssign(host, `${HF_TRANSFORMERS_PROVIDER}/${modelId}`, preselectRole);\n}\n\n/**\n * Zero-setup pipeline for a curated prism llama.cpp model (Bonsai-27B): install the pinned prism\n * llama.cpp runtime (prebuilt release download, no compiler needed), ensure both GGUF files and\n * start llama-server (see `ensurePrismModelFilesThenServe`), register the model, then probe\n * fitness. Mirrors addTransformersModel's shape — each stage checks its own `{ ok }`/\n * `{ runtimeInstalled }` result and stops with an honest status message on failure; nothing\n * continues past a failed stage.\n */\nexport async function addPrismLlamaCppModel(\n\thost: LocalModelHost,\n\tdescriptor: PrismModelDescriptor,\n\tpreselectRole?: FitnessRole,\n): Promise<void> {\n\tconst runtime = getPrismLlamaCppRuntime(host);\n\tconst modelId = descriptor.repo;\n\n\tlet status = await runtime.detect();\n\tif (!status.runtimeInstalled) {\n\t\thost.showStatus(`Installing prism llama.cpp runtime for ${descriptor.displayName} at ${runtime.runtimeDir()}…`);\n\t\tconst installed = await runtime.installManaged((progress) => host.showStatus(` prism-llamacpp: ${progress}`));\n\t\tif (!installed.ok) {\n\t\t\thost.showStatus(`Prism llama.cpp runtime install failed: ${installed.error}`);\n\t\t\treturn;\n\t\t}\n\t\tstatus = await runtime.detect();\n\t}\n\tif (!status.runtimeInstalled) {\n\t\thost.showStatus(`Prism llama.cpp runtime is still unavailable at ${runtime.runtimeDir()}.`);\n\t\treturn;\n\t}\n\n\tconst numCtx = derivePrismLlamaCppNumCtx(totalmem());\n\tconst served = await ensurePrismModelFilesThenServe(\n\t\truntime,\n\t\tdescriptor,\n\t\t{ port: PRISM_LLAMACPP_SERVE_PORT, numCtx },\n\t\t(message) => host.showStatus(message),\n\t);\n\tif (!served.ok) {\n\t\tconst label =\n\t\t\tserved.stage === \"model-download\"\n\t\t\t\t? \"Model download failed\"\n\t\t\t\t: served.stage === \"mmproj-download\"\n\t\t\t\t\t? \"Vision projector download failed\"\n\t\t\t\t\t: \"Could not start llama-server\";\n\t\thost.showStatus(`${label}: ${served.error}`);\n\t\treturn;\n\t}\n\n\tconst registration = registerPrismLlamaCppModel({\n\t\tagentDir: getAgentDir(),\n\t\tmodelId,\n\t\tbaseUrl: served.baseUrl,\n\t\tcontextWindow: numCtx,\n\t\tservedContextWindow: numCtx,\n\t});\n\tif (!registration.ok) {\n\t\thost.showStatus(`Served, 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(\n\t\t`${descriptor.displayName} installed and registered as ${PRISM_LLAMACPP_PROVIDER}/${modelId}. Probing fitness…`,\n\t);\n\tawait runFitnessAndAssign(host, `${PRISM_LLAMACPP_PROVIDER}/${modelId}`, 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\nasync function removeTransformersModel(host: LocalModelHost, modelId: string, confirmed: boolean): Promise<void> {\n\tconst runtime = host.getTransformersRuntime(modelId);\n\tconst status = await runtime.detect();\n\tif (!confirmed) {\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t`Removing ${modelId} will delete:`,\n\t\t\t\t` - the ${HF_TRANSFORMERS_PROVIDER}/${modelId} entry in models.json`,\n\t\t\t\t` - its cached fitness report for this host`,\n\t\t\t\t`It will stop this session's Transformers sidecar if running. Cached weights remain under ${status.cacheDir}.`,\n\t\t\t\t`Run: /models remove hf.co/${modelId} confirm`,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\truntime.stop();\n\tconst registration = unregisterTransformersModel({ agentDir: getAgentDir(), modelId });\n\tif (!registration.ok) {\n\t\thost.showStatus(`Remove failed: ${registration.reason}`);\n\t\treturn;\n\t}\n\tFitnessStore.forAgentDir(getAgentDir()).remove(`${HF_TRANSFORMERS_PROVIDER}/${modelId}`);\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(\n\t\t`${modelId} registration and fitness report dropped; cached weights remain under ${status.cacheDir}.`,\n\t);\n}\n\n/**\n * Drop a pi-managed prism llama.cpp model's registration and fitness report. Production supplies a\n * session-cached runtime (see `LocalModelHost.getPrismLlamaCppRuntime`'s doc comment), the SAME\n * instance the readiness gate uses, so `stop()` here reliably reaches the tracked child whenever\n * THIS session is the one that started it — including a server started earlier in the session by\n * the readiness gate itself, not just by a prior `/models add`. Only a server started by a\n * DIFFERENT process/session (pi restarted, a different terminal) is out of reach; the status text\n * only carries that caveat, not a blanket \"may not stop\" disclaimer.\n */\nasync function removePrismLlamaCppModel(host: LocalModelHost, modelId: string, confirmed: boolean): Promise<void> {\n\tconst runtime = getPrismLlamaCppRuntime(host);\n\tif (!confirmed) {\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t`Removing ${modelId} will delete:`,\n\t\t\t\t` - the ${PRISM_LLAMACPP_PROVIDER}/${modelId} entry in models.json`,\n\t\t\t\t` - its cached fitness report for this host`,\n\t\t\t\t`Downloaded GGUF weights remain under ${runtime.modelsDir()}. Its llama-server will be stopped if ` +\n\t\t\t\t\t`this session started it; if it was started by a different pi process or session, it will keep ` +\n\t\t\t\t\t`serving on 127.0.0.1:${PRISM_LLAMACPP_SERVE_PORT} until stopped manually.`,\n\t\t\t\t`Run: /models remove hf.co/${modelId} confirm`,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\tconst stopped = runtime.stop();\n\tconst registration = unregisterPrismLlamaCppModel({ agentDir: getAgentDir(), modelId });\n\tif (!registration.ok) {\n\t\thost.showStatus(`Remove failed: ${registration.reason}`);\n\t\treturn;\n\t}\n\tFitnessStore.forAgentDir(getAgentDir()).remove(`${PRISM_LLAMACPP_PROVIDER}/${modelId}`);\n\thost.session.modelRegistry.refresh();\n\thost.showStatus(\n\t\t`${modelId} registration and fitness report dropped; downloaded weights remain under ${runtime.modelsDir()}.` +\n\t\t\t(stopped.stopped\n\t\t\t\t? \" Its llama-server was stopped.\"\n\t\t\t\t: ` No llama-server tracked by this session — if one is still running (started by a different pi process or session), stop it manually on port ${PRISM_LLAMACPP_SERVE_PORT}.`),\n\t);\n}\n\n/**\n * Zero-setup pipeline for needle (see needle-runtime.ts): a standalone 26M-parameter function-call\n * test bench, NOT a chat/executor/lane model — no OpenAI-compatible endpoint, no models.json\n * registration, no /fitness probe. Install the pinned needle clone+venv (menu pick = consent, same\n * doctrine as the Transformers/prism precedents), download and sha256-verify the pickle checkpoint\n * (never called implicitly by installManaged — see the module's SECURITY note: the checkpoint is a\n * pickle file, arbitrary code execution on load by construction, so this is deliberately a separate\n * consent-adjacent step, not folded into install), then run its own smoke test as the honest\n * post-install verification. Each stage checks its own `{ ok }` result and stops with a stage-tagged\n * status on failure; nothing continues past a failed stage.\n */\nexport async function addNeedleModel(host: LocalModelHost): Promise<void> {\n\tconst runtime = getNeedleRuntime(host);\n\n\tlet status = await runtime.detect();\n\tif (!status.installed) {\n\t\thost.showStatus(`Installing needle (function-call test bench) at ${runtime.runtimeDir()}…`);\n\t\tconst installed = await runtime.installManaged((progress) => host.showStatus(` needle: ${progress}`));\n\t\tif (!installed.ok) {\n\t\t\thost.showStatus(`needle install failed: ${installed.error}`);\n\t\t\treturn;\n\t\t}\n\t\tstatus = await runtime.detect();\n\t}\n\tif (!status.installed) {\n\t\thost.showStatus(`needle is still unavailable at ${runtime.runtimeDir()}.`);\n\t\treturn;\n\t}\n\n\tconst downloaded = await runtime.downloadWeights((progress) => host.showStatus(` ${progress}`));\n\tif (!downloaded.ok) {\n\t\thost.showStatus(`needle weights download failed: ${downloaded.error}`);\n\t\treturn;\n\t}\n\n\thost.showStatus(\"Running needle smoke test (function-call probe)…\");\n\tconst smoke = await runtime.smokeTest();\n\tif (!smoke.ok || !smoke.call) {\n\t\thost.showStatus(\n\t\t\t`needle smoke test failed: ${smoke.error ?? \"smoke test reported success but returned no parsed call\"}`,\n\t\t);\n\t\treturn;\n\t}\n\thost.showStatus(\n\t\t`needle installed and verified: smoke test called ${smoke.call.name}(${JSON.stringify(smoke.call.arguments)}) ` +\n\t\t\t`in ${smoke.latencyMs}ms. Use /models needle <query> [tools-json] to test it further — it is a standalone ` +\n\t\t\t\"bench, not a chat/executor lane.\",\n\t);\n}\n\n/**\n * Wipe pi's needle runtime (clone+venv) and downloaded checkpoint. Unlike the other /models remove\n * flows, there is no models.json entry or fitness report to drop (needle never registers as a model\n * — see the roster entry's rationale) and no server process to stop (every needle invocation is a\n * one-shot runCommand call — see needle-runtime.ts's `dispose()` doc comment); removal is purely\n * deleting the two pi-owned directories. needle-runtime.ts exposes no delete method of its own (its\n * public surface is detect/installManaged/downloadWeights/runFunctionCall/smokeTest/dispose), so\n * this deletes directly via the runtime's own path-derivation methods.\n */\nasync function removeNeedleModel(host: LocalModelHost, confirmed: boolean): Promise<void> {\n\tconst runtime = getNeedleRuntime(host);\n\tconst runtimeDir = runtime.runtimeDir();\n\tconst modelsDir = runtime.modelsDir();\n\tif (!confirmed) {\n\t\thost.showStatus(\n\t\t\t[\n\t\t\t\t\"Removing needle will delete:\",\n\t\t\t\t` - the pi-managed needle runtime (clone + venv) at ${runtimeDir}`,\n\t\t\t\t` - the downloaded checkpoint at ${runtime.checkpointPath()}`,\n\t\t\t\t\"needle has no models.json entry or fitness report — it is a standalone function-call test bench, \" +\n\t\t\t\t\t\"never registered as a chat/lane model.\",\n\t\t\t\t\"Run: /models remove hf.co/Cactus-Compute/needle confirm\",\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t\treturn;\n\t}\n\tif (existsSync(runtimeDir)) rmSync(runtimeDir, { recursive: true, force: true });\n\tif (existsSync(modelsDir)) rmSync(modelsDir, { recursive: true, force: true });\n\thost.showStatus(`needle removed: deleted ${runtimeDir} and ${modelsDir}.`);\n}\n\n/**\n * `/models needle <query> [tools-json]` — the actual test surface for needle (see the roster\n * entry's rationale: there is no chat lane to probe it through). `tools-json`, when present, must be\n * the LAST whitespace-split token and start with `[`/`{` (compact JSON, no embedded spaces) —\n * anything else is treated as part of the query and the default smoke-test tool set is used. A fast\n * `detect()`-based pre-check gives friendly install guidance without spawning a doomed process;\n * `runFunctionCall`'s own not-installed/checkpoint-missing pre-flight is still the final honest\n * backstop if state changes between the check and the call.\n */\nasync function runNeedleQuery(host: LocalModelHost, args: string[]): Promise<void> {\n\tif (args.length === 0) {\n\t\thost.showStatus(\"Usage: /models needle <query> [tools-json]\");\n\t\treturn;\n\t}\n\n\tconst runtime = getNeedleRuntime(host);\n\tconst status = await runtime.detect();\n\tif (!status.installed) {\n\t\thost.showStatus(\n\t\t\t\"needle is not installed. Run /models add hf.co/Cactus-Compute/needle first (or /models suggest).\",\n\t\t);\n\t\treturn;\n\t}\n\tif (!status.checkpointPresent) {\n\t\thost.showStatus(\n\t\t\t\"needle is installed but its checkpoint hasn't been downloaded. Run /models add hf.co/Cactus-Compute/needle to fetch and verify it.\",\n\t\t);\n\t\treturn;\n\t}\n\n\tlet tools: unknown = NEEDLE_DEFAULT_TOOLS;\n\tlet toolsJsonParsed = false;\n\tconst last = args[args.length - 1];\n\tif (last && (last.startsWith(\"[\") || last.startsWith(\"{\"))) {\n\t\ttry {\n\t\t\ttools = JSON.parse(last);\n\t\t\ttoolsJsonParsed = true;\n\t\t} catch {\n\t\t\t// Not valid JSON — treat the whole thing as the query, keep the default tools.\n\t\t}\n\t}\n\tconst query = (toolsJsonParsed ? args.slice(0, -1) : args).join(\" \");\n\tif (!query.trim()) {\n\t\thost.showStatus(\"Usage: /models needle <query> [tools-json]\");\n\t\treturn;\n\t}\n\n\thost.showStatus(`needle: running \"${query}\"…`);\n\tconst startedAt = Date.now();\n\tconst result = await runtime.runFunctionCall({ query, tools });\n\tconst latencyMs = Date.now() - startedAt;\n\tif (!result.ok) {\n\t\thost.showStatus(`needle call failed (${latencyMs}ms): ${result.error}\\nraw output:\\n${result.rawOutput}`);\n\t\treturn;\n\t}\n\thost.showStatus(`needle (${latencyMs}ms): ${result.call.name}(${JSON.stringify(result.call.arguments)})`);\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\tconst source = normalizeModelSource(suggestion.pullRef);\n\t\t\t\tif (source.type === \"transformers\") {\n\t\t\t\t\tawait addTransformersModel(host, source.modelId, suggestion.assignRole);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (source.type === \"prism-llamacpp\") {\n\t\t\t\t\tconst descriptor = PRISM_LLAMACPP_DESCRIPTORS[source.modelId];\n\t\t\t\t\tif (!descriptor) {\n\t\t\t\t\t\thost.showStatus(\n\t\t\t\t\t\t\t`Suggestion ${suggestion.name} maps to an unknown curated prism model \"${source.modelId}\" — wiring bug.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait addPrismLlamaCppModel(host, descriptor, suggestion.assignRole);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (source.type === \"needle\") {\n\t\t\t\t\tawait addNeedleModel(host);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (source.type === \"local\") {\n\t\t\t\t\tawait addLocalModel(host, source.pullRef, suggestion.assignRole);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\thost.showStatus(\n\t\t\t\t\t`Suggestion ${suggestion.name} is not installable: ${source.type === \"rejected\" ? source.reason : source.ref}`,\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\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 (!presentModelFitnessOutcome(host, outcome)) return;\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\tlet toolProbe: ToolProbeResult | undefined;\n\t\tif (preselectRole === undefined || roleRequiresToolExecution(preselectRole)) {\n\t\t\thost.showStatus(`Real tool execution probe running on ${outcome.model}…`);\n\t\t\ttry {\n\t\t\t\tconst toolProbeReport = await host.session.probeToolCalling(outcome.model);\n\t\t\t\ttoolProbe =\n\t\t\t\t\ttoolProbeReport.results.find((result) => result.model === outcome.model) ??\n\t\t\t\t\t(toolProbeReport.results.length === 1 ? toolProbeReport.results[0] : undefined);\n\t\t\t} catch (error) {\n\t\t\t\thost.showStatus(\n\t\t\t\t\t`Real tool execution probe unavailable for ${outcome.model}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\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\tconst toolFailure = toolRoleFailure(role, toolProbe);\n\t\t\t\t\tif (toolFailure) {\n\t\t\t\t\t\thost.showStatus(`${outcome.model} not assigned as ${role}: real tool execution ${toolFailure}.`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\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\nfunction roleRequiresToolExecution(role: FitnessRole): boolean {\n\treturn (\n\t\trole === \"executor\" ||\n\t\trole === \"scout\" ||\n\t\trole === \"router-cheap\" ||\n\t\trole === \"router-medium\" ||\n\t\trole === \"router-expensive\"\n\t);\n}\n\nfunction toolRoleFailure(role: FitnessRole, probe: ToolProbeResult | undefined): string | undefined {\n\tif (!roleRequiresToolExecution(role)) return undefined;\n\tif (!probe) return \"was not proven; run /toolprobe and retry /fitness\";\n\tif (probe.verdict === \"text-protocol\") return undefined;\n\tif (probe.verdict === \"native\" && probe.nativeGrade === \"task\") return undefined;\n\tif (probe.verdict === \"native\") return `reported native ${probe.nativeGrade ?? \"ungraded\"}, not task-scale calls`;\n\treturn `probe reported none${probe.diagnostic ? ` (${probe.diagnostic})` : \"\"}`;\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"]}
@@ -0,0 +1,4 @@
1
+ import type { ThinkingLevel } from "@caupulican/pi-agent-core";
2
+ /** Provider-neutral labels shared by every interactive thinking-level selector. */
3
+ export declare const THINKING_LEVEL_DESCRIPTIONS: Readonly<Record<ThinkingLevel, string>>;
4
+ //# sourceMappingURL=thinking-level-descriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-level-descriptions.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/thinking-level-descriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,mFAAmF;AACnF,eAAO,MAAM,2BAA2B,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAS/E,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** Provider-neutral labels shared by every interactive thinking-level selector. */
2
+ export const THINKING_LEVEL_DESCRIPTIONS = {
3
+ off: "No reasoning",
4
+ minimal: "Very brief reasoning (~1k tokens)",
5
+ low: "Light reasoning (~2k tokens)",
6
+ medium: "Moderate reasoning (~8k tokens)",
7
+ high: "Deep reasoning (~16k tokens)",
8
+ xhigh: "Maximum reasoning (~32k tokens)",
9
+ max: "Maximum reasoning depth for the hardest problems",
10
+ ultra: "Maximum available reasoning effort (provider permitting)",
11
+ };
12
+ //# sourceMappingURL=thinking-level-descriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-level-descriptions.js","sourceRoot":"","sources":["../../../src/modes/interactive/thinking-level-descriptions.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,MAAM,CAAC,MAAM,2BAA2B,GAA4C;IACnF,GAAG,EAAE,cAAc;IACnB,OAAO,EAAE,mCAAmC;IAC5C,GAAG,EAAE,8BAA8B;IACnC,MAAM,EAAE,iCAAiC;IACzC,IAAI,EAAE,8BAA8B;IACpC,KAAK,EAAE,iCAAiC;IACxC,GAAG,EAAE,kDAAkD;IACvD,KAAK,EAAE,0DAA0D;CACjE,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@caupulican/pi-agent-core\";\n\n/** Provider-neutral labels shared by every interactive thinking-level selector. */\nexport const THINKING_LEVEL_DESCRIPTIONS: Readonly<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\tmax: \"Maximum reasoning depth for the hardest problems\",\n\tultra: \"Maximum available reasoning effort (provider permitting)\",\n};\n"]}
package/docs/resources.md CHANGED
@@ -45,7 +45,7 @@ A profile is a complete allow/block contract over six kinds: `extensions`, `skil
45
45
 
46
46
  Under strict UAC, an unmentioned kind is denied. Granting every resource of a kind must be explicit with `allow: ["*"]`; `block: ["*"]` means "none." This keeps a saved situation exact when new extensions, tools, or other resources are installed later.
47
47
 
48
- A profile may also bind a **model**, **thinking level**, **soul**, and **modelRouter** block that apply when the profile is active. When `model` is omitted, the profile inherits the session/settings model. Use `/settings` → **Resources** → **Manage Profiles / Situations** → **Edit profile model** to pin a model or return an existing profile to inherited behavior; editing the active profile applies immediately through transactional reload. Thinking is one of `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`, or `ultra`. Ultra uses the model's strongest mapped reasoning level and reinforces proactive delegation when the `delegate` tool is granted; delegation itself remains available independently on capable models. Explicit CLI flags still win over a profile's foreground model/thinking, which in turn win over the settings default. A profile's `modelRouter` block overrides matching global/project router fields while that situation is active.
48
+ A profile may also bind a **model**, **thinking level**, **soul**, and **modelRouter** block that apply when the profile is active. When `model` is omitted, the profile inherits the session/settings model. Use `/settings` → **Resources** → **Manage Profiles / Situations** → **Edit profile model** to pin a model or return an existing profile to inherited behavior; editing the active profile applies immediately through transactional reload. Thinking is one of `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`, or `ultra`; Ultra requests the model's strongest mapped reasoning level. Delegation guidance depends on the active `delegate` tool and worker-delegation setting, not on provider identity, model identity, or thinking level; the provider-neutral model-capability profile may still narrow tools for very small context windows. Explicit CLI flags still win over a profile's foreground model/thinking, which in turn win over the settings default. A profile's `modelRouter` block overrides matching global/project router fields while that situation is active.
49
49
 
50
50
  Pi activates the complete situation as one runtime generation: model/router, thinking, soul, extensions, skills, prompts, agents, themes, and tools are reloaded together. A failed reload restores the prior valid generation instead of persisting a partial selection.
51
51
 
package/docs/settings.md CHANGED
@@ -164,7 +164,9 @@ Fitness applicability is intentionally split by autonomy level:
164
164
 
165
165
  Pi's native delegation runtime is a durable recursive agent tree. A profile is not required. A profile-free root agent starts from the foreground model and the maximum classified core worker surface the host can materialize: `read`, `grep`, `find`, `ls`, `write`, `edit`, `memory`, the platform shell, and `delegate`. Live service switches can revoke memory, writes, or delegation. Every descendant inherits its parent's immutable execution grant and the tree's remaining budget by default.
166
166
 
167
- An agent may set `authority` on `delegate` to choose its child's role label, authenticated model, supported reasoning level, semantic capabilities, tools, read/write paths, and budget. Omitted fields inherit from the parent or selected preset. The host validates the request, resolves the concrete model and tools, intersects execution authority with the immutable parent grant and live global switches, then persists the exact result before the child starts. A descendant can specialize or narrow authority but cannot add an execution capability, tool, path, or budget that the parent did not hold. Profile selection also cannot add context: every child resource pointer must fully match an ancestral pointer (ID alone is insufficient), soul text must match exactly, and a verifier stays within its previously admitted ancestral verifier or worker boundary. Roles are descriptive routing and audit labels; the built-in compiler does not impose hidden role ceilings, though an embedding may supply an explicit host ceiling.
167
+ Whenever `delegate` is active, root and worker prompts use the same provider-neutral decision rule: delegate useful independent research, implementation, tests, or specialist review early; keep dependent or trivial work local. Reasoning level, provider identity, and model identity do not enable or suppress that policy; the model-capability profile may still narrow tools for very small context windows.
168
+
169
+ An agent may set `authority` on `delegate` to choose its child's role label, authenticated model, supported reasoning level, and classified tool names. Omitted fields inherit from the parent or selected preset. The model-facing start schema has no per-dispatch budget field: ordinary starts inherit the unbounded baseline, host settings, or an owner-authored profile ceiling. The host validates the request, resolves the concrete model and tools, intersects execution authority with the immutable parent grant and live global switches, then persists the exact result before the child starts. A descendant can specialize or narrow authority but cannot add an execution capability, tool, path, or budget that the parent did not hold. Profile selection also cannot add context: every child resource pointer must fully match an ancestral pointer (ID alone is insufficient), soul text must match exactly, and a verifier stays within its previously admitted ancestral verifier or worker boundary. Roles are descriptive routing and audit labels; the built-in compiler does not impose hidden role ceilings, though an embedding may supply an explicit host ceiling.
168
170
 
169
171
  `workerDelegation.modelPins` optionally lets the owner fix the provider, model, and thinking level used by each fresh worker role. With no pins, delegation keeps the adaptive behavior above exactly. An applicable pin overrides model/thinking chosen by `authority` or a preset, while role, tools, resources, paths, and budgets still follow normal admission. This applies to fresh top-level workers, fresh nested workers, and mandatory verifiers. The admitted binding is persisted and reported by `delegate start`; queued work, retries, resumes, recovery, and later tasks on a reused `agentId` keep that immutable contract even if settings change.
170
172
 
@@ -242,7 +244,7 @@ Transient attempt retries are evidence-gated. A classified provider or transport
242
244
 
243
245
  `delegate` returns a stable agent/lane identity immediately. A fresh `start` does not accept `laneId`; omit it, retain the returned `agentId`, and pass that `agentId` to a later `start` to reuse the persistent worker. Completion persists a bounded terminal handoff before waking the parent; late output stays in the worker transcript instead of racing into the active foreground transcript. Review-pending results remain `partial` and project blockers remain `blocked` in lane status and terminal handoffs instead of either being collapsed into harness failures. A scheduled transient retry is reported as nonterminal with its durable state retained. A full parent mailbox retains the attempt-keyed handoff until an explicit terminal, mailbox-capacity, state-change, or recovery event drains it—there is no retry polling loop. Exact replays are inert, conflicts fail closed, and delivery errors remain retained. Use `delegate { action: "status", laneId }` for bounded lane-result retrieval.
244
246
 
245
- Global profiles live at `~/.pi/agent/profiles/orchestration/<id>.json`; project profiles live at `.pi/profiles/orchestration/<id>.json`. They are optional presets for model, reasoning, tools, resources, budget, verification, prompt defaults, and recursive `delegationLimits`. Select one with `profileId` on a call or configure `workerDelegation.orchestrationProfile`. `dispatchProfileIds` is preset-routing metadata, not an admission allowlist. Profile `maxConcurrent` is retained in the authored schema but does not override the global scheduler. `delegate` actions `profile_inspect` and `profile_create` manage optional immutable session-scoped narrowings; direct authority selection does not require one.
247
+ Global profiles live at `~/.pi/agent/profiles/orchestration/<id>.json`; project profiles live at `.pi/profiles/orchestration/<id>.json`. They are optional presets for model, reasoning, tools, resources, budget, verification, prompt defaults, and recursive `delegationLimits`. Select one with `profileId` on a call or configure `workerDelegation.orchestrationProfile`. `dispatchProfileIds` is preset-routing metadata, not an admission allowlist. Profile `maxConcurrent` is retained in the authored schema but does not override the global scheduler. `delegate` actions `profile_inspect` and `profile_create` manage optional immutable session-scoped narrowings; task profiles inherit the owner-authored base budget unchanged, and direct authority selection does not require a profile.
246
248
 
247
249
  A preset with `requireIndependentVerification: true` still names an owner-authored `verificationProfileId`. The runtime creates a separate durable verifier task and accepts the implementation only after a typed verifier decision. A profile using `run_process` must declare `executionPolicy`; that tool launches only listed executables as direct argv. The platform shell is different: it is a real persistent per-agent shell and is not OS/container isolation. Shell commands can exercise the host process, filesystem, network, and credentials available to Pi; direct `write`/`edit` path scopes do not sandbox shell side effects.
248
250
 
@@ -252,8 +254,8 @@ Direct `write`/`edit` calls use review-after-apply semantics. The compiled grant
252
254
  |---------|------|---------|-------------|
253
255
  | `workerDelegation.enabled` | boolean | `true` | Enable autonomous recursive agent trees; explicit `false` is a hard off-switch |
254
256
  | `workerDelegation.orchestrationProfile` | string | - | Optional default execution preset; agents may replace its defaults within inherited authority |
255
- | `workerDelegation.maxUsd` | number | `0.5` | Cumulative USD ceiling for one root tree; explicit `0` opts into an unbounded settings-level ceiling |
256
- | `workerDelegation.maxWallClockMs` | number | `120000` | Cumulative active wall-clock ceiling for one root tree; explicit `0` opts into an unbounded settings-level ceiling |
257
+ | `workerDelegation.maxUsd` | number | `0` | Cumulative USD ceiling for one root tree; `0` is unbounded and a positive value explicitly enables the ceiling |
258
+ | `workerDelegation.maxWallClockMs` | number | `0` | Cumulative active wall-clock ceiling for one root tree; `0` is unbounded and a positive value explicitly enables the ceiling |
257
259
  | `workerDelegation.maxConcurrent` | number | `20` | Global running-agent concurrency inside the fixed fleet and queue bounds |
258
260
  | `workerDelegation.writeEnabled` | boolean | `true` | Expose direct `write`/`edit`; explicit `false` revokes them for newly admitted work and narrows resumed grants |
259
261
  | `workerDelegation.writePaths` | string[] | `["."]` | Global envelope for direct child writes; an explicit empty array revokes direct `write`/`edit` |
@@ -347,7 +349,7 @@ The checkpoint owns user intent mechanically: `## Active Task` copies the latest
347
349
 
348
350
  | Setting | Type | Default | Description |
349
351
  |---------|------|---------|-------------|
350
- | `costGuard.maxTurnUsd` | number | `2.5` | Projected per-turn USD warning ceiling; `0` disables the guard |
352
+ | `costGuard.maxTurnUsd` | number | `0` | Projected per-turn USD warning ceiling; disabled by default, positive values explicitly enable it |
351
353
  | `costGuard.action` | string | `"warn"` | `"warn"` only reports the estimate; `"downgrade"` also lowers reasoning one rung for that request without changing saved/profile state |
352
354
 
353
355
  The projection uses the session response reserve, cached-input rates, and model-declared long-context tiers. ChatGPT subscription usage is marked `(sub)` and does not enter the USD guard.