ollama-intern-mcp 1.0.0

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 (256) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +252 -0
  3. package/SECURITY.md +22 -0
  4. package/dist/corpus/chunker.d.ts +63 -0
  5. package/dist/corpus/chunker.d.ts.map +1 -0
  6. package/dist/corpus/chunker.js +230 -0
  7. package/dist/corpus/chunker.js.map +1 -0
  8. package/dist/corpus/fusion.d.ts +67 -0
  9. package/dist/corpus/fusion.d.ts.map +1 -0
  10. package/dist/corpus/fusion.js +76 -0
  11. package/dist/corpus/fusion.js.map +1 -0
  12. package/dist/corpus/indexer.d.ts +33 -0
  13. package/dist/corpus/indexer.d.ts.map +1 -0
  14. package/dist/corpus/indexer.js +201 -0
  15. package/dist/corpus/indexer.js.map +1 -0
  16. package/dist/corpus/lexical.d.ts +95 -0
  17. package/dist/corpus/lexical.d.ts.map +1 -0
  18. package/dist/corpus/lexical.js +227 -0
  19. package/dist/corpus/lexical.js.map +1 -0
  20. package/dist/corpus/manifest.d.ts +29 -0
  21. package/dist/corpus/manifest.d.ts.map +1 -0
  22. package/dist/corpus/manifest.js +45 -0
  23. package/dist/corpus/manifest.js.map +1 -0
  24. package/dist/corpus/refresh.d.ts +54 -0
  25. package/dist/corpus/refresh.d.ts.map +1 -0
  26. package/dist/corpus/refresh.js +155 -0
  27. package/dist/corpus/refresh.js.map +1 -0
  28. package/dist/corpus/searcher.d.ts +48 -0
  29. package/dist/corpus/searcher.d.ts.map +1 -0
  30. package/dist/corpus/searcher.js +131 -0
  31. package/dist/corpus/searcher.js.map +1 -0
  32. package/dist/corpus/storage.d.ts +56 -0
  33. package/dist/corpus/storage.d.ts.map +1 -0
  34. package/dist/corpus/storage.js +81 -0
  35. package/dist/corpus/storage.js.map +1 -0
  36. package/dist/coverage.d.ts +38 -0
  37. package/dist/coverage.d.ts.map +1 -0
  38. package/dist/coverage.js +117 -0
  39. package/dist/coverage.js.map +1 -0
  40. package/dist/embedMath.d.ts +22 -0
  41. package/dist/embedMath.d.ts.map +1 -0
  42. package/dist/embedMath.js +34 -0
  43. package/dist/embedMath.js.map +1 -0
  44. package/dist/envelope.d.ts +53 -0
  45. package/dist/envelope.d.ts.map +1 -0
  46. package/dist/envelope.js +32 -0
  47. package/dist/envelope.js.map +1 -0
  48. package/dist/errors.d.ts +20 -0
  49. package/dist/errors.d.ts.map +1 -0
  50. package/dist/errors.js +30 -0
  51. package/dist/errors.js.map +1 -0
  52. package/dist/evals/retrieval.d.ts +68 -0
  53. package/dist/evals/retrieval.d.ts.map +1 -0
  54. package/dist/evals/retrieval.js +173 -0
  55. package/dist/evals/retrieval.js.map +1 -0
  56. package/dist/guardrails/citations.d.ts +28 -0
  57. package/dist/guardrails/citations.d.ts.map +1 -0
  58. package/dist/guardrails/citations.js +45 -0
  59. package/dist/guardrails/citations.js.map +1 -0
  60. package/dist/guardrails/compileCheck.d.ts +20 -0
  61. package/dist/guardrails/compileCheck.d.ts.map +1 -0
  62. package/dist/guardrails/compileCheck.js +96 -0
  63. package/dist/guardrails/compileCheck.js.map +1 -0
  64. package/dist/guardrails/confidence.d.ts +21 -0
  65. package/dist/guardrails/confidence.d.ts.map +1 -0
  66. package/dist/guardrails/confidence.js +18 -0
  67. package/dist/guardrails/confidence.js.map +1 -0
  68. package/dist/guardrails/timeouts.d.ts +35 -0
  69. package/dist/guardrails/timeouts.d.ts.map +1 -0
  70. package/dist/guardrails/timeouts.js +58 -0
  71. package/dist/guardrails/timeouts.js.map +1 -0
  72. package/dist/guardrails/writeConfirm.d.ts +25 -0
  73. package/dist/guardrails/writeConfirm.d.ts.map +1 -0
  74. package/dist/guardrails/writeConfirm.js +35 -0
  75. package/dist/guardrails/writeConfirm.js.map +1 -0
  76. package/dist/index.d.ts +12 -0
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +153 -0
  79. package/dist/index.js.map +1 -0
  80. package/dist/observability.d.ts +66 -0
  81. package/dist/observability.d.ts.map +1 -0
  82. package/dist/observability.js +51 -0
  83. package/dist/observability.js.map +1 -0
  84. package/dist/ollama.d.ts +105 -0
  85. package/dist/ollama.d.ts.map +1 -0
  86. package/dist/ollama.js +109 -0
  87. package/dist/ollama.js.map +1 -0
  88. package/dist/prewarm.d.ts +28 -0
  89. package/dist/prewarm.d.ts.map +1 -0
  90. package/dist/prewarm.js +69 -0
  91. package/dist/prewarm.js.map +1 -0
  92. package/dist/profiles.d.ts +54 -0
  93. package/dist/profiles.d.ts.map +1 -0
  94. package/dist/profiles.js +95 -0
  95. package/dist/profiles.js.map +1 -0
  96. package/dist/protectedPaths.d.ts +33 -0
  97. package/dist/protectedPaths.d.ts.map +1 -0
  98. package/dist/protectedPaths.js +54 -0
  99. package/dist/protectedPaths.js.map +1 -0
  100. package/dist/runContext.d.ts +21 -0
  101. package/dist/runContext.d.ts.map +1 -0
  102. package/dist/runContext.js +9 -0
  103. package/dist/runContext.js.map +1 -0
  104. package/dist/semaphore.d.ts +16 -0
  105. package/dist/semaphore.d.ts.map +1 -0
  106. package/dist/semaphore.js +37 -0
  107. package/dist/semaphore.js.map +1 -0
  108. package/dist/sources.d.ts +19 -0
  109. package/dist/sources.d.ts.map +1 -0
  110. package/dist/sources.js +41 -0
  111. package/dist/sources.js.map +1 -0
  112. package/dist/tiers.d.ts +39 -0
  113. package/dist/tiers.d.ts.map +1 -0
  114. package/dist/tiers.js +44 -0
  115. package/dist/tiers.js.map +1 -0
  116. package/dist/tools/artifactDiff.d.ts +66 -0
  117. package/dist/tools/artifactDiff.d.ts.map +1 -0
  118. package/dist/tools/artifactDiff.js +66 -0
  119. package/dist/tools/artifactDiff.js.map +1 -0
  120. package/dist/tools/artifactExportToPath.d.ts +38 -0
  121. package/dist/tools/artifactExportToPath.d.ts.map +1 -0
  122. package/dist/tools/artifactExportToPath.js +51 -0
  123. package/dist/tools/artifactExportToPath.js.map +1 -0
  124. package/dist/tools/artifactList.d.ts +60 -0
  125. package/dist/tools/artifactList.d.ts.map +1 -0
  126. package/dist/tools/artifactList.js +107 -0
  127. package/dist/tools/artifactList.js.map +1 -0
  128. package/dist/tools/artifactRead.d.ts +43 -0
  129. package/dist/tools/artifactRead.d.ts.map +1 -0
  130. package/dist/tools/artifactRead.js +83 -0
  131. package/dist/tools/artifactRead.js.map +1 -0
  132. package/dist/tools/artifactSnippets.d.ts +56 -0
  133. package/dist/tools/artifactSnippets.d.ts.map +1 -0
  134. package/dist/tools/artifactSnippets.js +97 -0
  135. package/dist/tools/artifactSnippets.js.map +1 -0
  136. package/dist/tools/artifacts/diff.d.ts +161 -0
  137. package/dist/tools/artifacts/diff.d.ts.map +1 -0
  138. package/dist/tools/artifacts/diff.js +267 -0
  139. package/dist/tools/artifacts/diff.js.map +1 -0
  140. package/dist/tools/artifacts/export.d.ts +43 -0
  141. package/dist/tools/artifacts/export.d.ts.map +1 -0
  142. package/dist/tools/artifacts/export.js +113 -0
  143. package/dist/tools/artifacts/export.js.map +1 -0
  144. package/dist/tools/artifacts/scan.d.ts +86 -0
  145. package/dist/tools/artifacts/scan.d.ts.map +1 -0
  146. package/dist/tools/artifacts/scan.js +251 -0
  147. package/dist/tools/artifacts/scan.js.map +1 -0
  148. package/dist/tools/artifacts/snippets.d.ts +42 -0
  149. package/dist/tools/artifacts/snippets.d.ts.map +1 -0
  150. package/dist/tools/artifacts/snippets.js +165 -0
  151. package/dist/tools/artifacts/snippets.js.map +1 -0
  152. package/dist/tools/batch.d.ts +65 -0
  153. package/dist/tools/batch.d.ts.map +1 -0
  154. package/dist/tools/batch.js +117 -0
  155. package/dist/tools/batch.js.map +1 -0
  156. package/dist/tools/briefs/common.d.ts +65 -0
  157. package/dist/tools/briefs/common.d.ts.map +1 -0
  158. package/dist/tools/briefs/common.js +128 -0
  159. package/dist/tools/briefs/common.js.map +1 -0
  160. package/dist/tools/briefs/evidence.d.ts +40 -0
  161. package/dist/tools/briefs/evidence.d.ts.map +1 -0
  162. package/dist/tools/briefs/evidence.js +103 -0
  163. package/dist/tools/briefs/evidence.js.map +1 -0
  164. package/dist/tools/changeBrief.d.ts +85 -0
  165. package/dist/tools/changeBrief.d.ts.map +1 -0
  166. package/dist/tools/changeBrief.js +228 -0
  167. package/dist/tools/changeBrief.js.map +1 -0
  168. package/dist/tools/chat.d.ts +42 -0
  169. package/dist/tools/chat.d.ts.map +1 -0
  170. package/dist/tools/chat.js +49 -0
  171. package/dist/tools/chat.js.map +1 -0
  172. package/dist/tools/classify.d.ts +56 -0
  173. package/dist/tools/classify.d.ts.map +1 -0
  174. package/dist/tools/classify.js +103 -0
  175. package/dist/tools/classify.js.map +1 -0
  176. package/dist/tools/corpusAnswer.d.ts +79 -0
  177. package/dist/tools/corpusAnswer.d.ts.map +1 -0
  178. package/dist/tools/corpusAnswer.js +259 -0
  179. package/dist/tools/corpusAnswer.js.map +1 -0
  180. package/dist/tools/corpusIndex.d.ts +30 -0
  181. package/dist/tools/corpusIndex.d.ts.map +1 -0
  182. package/dist/tools/corpusIndex.js +67 -0
  183. package/dist/tools/corpusIndex.js.map +1 -0
  184. package/dist/tools/corpusList.d.ts +19 -0
  185. package/dist/tools/corpusList.d.ts.map +1 -0
  186. package/dist/tools/corpusList.js +34 -0
  187. package/dist/tools/corpusList.js.map +1 -0
  188. package/dist/tools/corpusRefresh.d.ts +29 -0
  189. package/dist/tools/corpusRefresh.d.ts.map +1 -0
  190. package/dist/tools/corpusRefresh.js +58 -0
  191. package/dist/tools/corpusRefresh.js.map +1 -0
  192. package/dist/tools/corpusSearch.d.ts +44 -0
  193. package/dist/tools/corpusSearch.d.ts.map +1 -0
  194. package/dist/tools/corpusSearch.js +80 -0
  195. package/dist/tools/corpusSearch.js.map +1 -0
  196. package/dist/tools/draft.d.ts +38 -0
  197. package/dist/tools/draft.d.ts.map +1 -0
  198. package/dist/tools/draft.js +72 -0
  199. package/dist/tools/draft.js.map +1 -0
  200. package/dist/tools/embed.d.ts +27 -0
  201. package/dist/tools/embed.d.ts.map +1 -0
  202. package/dist/tools/embed.js +41 -0
  203. package/dist/tools/embed.js.map +1 -0
  204. package/dist/tools/embedSearch.d.ts +58 -0
  205. package/dist/tools/embedSearch.d.ts.map +1 -0
  206. package/dist/tools/embedSearch.js +76 -0
  207. package/dist/tools/embedSearch.js.map +1 -0
  208. package/dist/tools/extract.d.ts +58 -0
  209. package/dist/tools/extract.d.ts.map +1 -0
  210. package/dist/tools/extract.js +93 -0
  211. package/dist/tools/extract.js.map +1 -0
  212. package/dist/tools/incidentBrief.d.ts +81 -0
  213. package/dist/tools/incidentBrief.d.ts.map +1 -0
  214. package/dist/tools/incidentBrief.js +252 -0
  215. package/dist/tools/incidentBrief.js.map +1 -0
  216. package/dist/tools/packs/changePack.d.ts +166 -0
  217. package/dist/tools/packs/changePack.d.ts.map +1 -0
  218. package/dist/tools/packs/changePack.js +470 -0
  219. package/dist/tools/packs/changePack.js.map +1 -0
  220. package/dist/tools/packs/incidentPack.d.ts +125 -0
  221. package/dist/tools/packs/incidentPack.d.ts.map +1 -0
  222. package/dist/tools/packs/incidentPack.js +354 -0
  223. package/dist/tools/packs/incidentPack.js.map +1 -0
  224. package/dist/tools/packs/repoPack.d.ts +207 -0
  225. package/dist/tools/packs/repoPack.d.ts.map +1 -0
  226. package/dist/tools/packs/repoPack.js +456 -0
  227. package/dist/tools/packs/repoPack.js.map +1 -0
  228. package/dist/tools/repoBrief.d.ts +81 -0
  229. package/dist/tools/repoBrief.d.ts.map +1 -0
  230. package/dist/tools/repoBrief.js +213 -0
  231. package/dist/tools/repoBrief.js.map +1 -0
  232. package/dist/tools/research.d.ts +45 -0
  233. package/dist/tools/research.d.ts.map +1 -0
  234. package/dist/tools/research.js +100 -0
  235. package/dist/tools/research.js.map +1 -0
  236. package/dist/tools/runner.d.ts +24 -0
  237. package/dist/tools/runner.d.ts.map +1 -0
  238. package/dist/tools/runner.js +47 -0
  239. package/dist/tools/runner.js.map +1 -0
  240. package/dist/tools/summarizeDeep.d.ts +49 -0
  241. package/dist/tools/summarizeDeep.d.ts.map +1 -0
  242. package/dist/tools/summarizeDeep.js +109 -0
  243. package/dist/tools/summarizeDeep.js.map +1 -0
  244. package/dist/tools/summarizeFast.d.ts +28 -0
  245. package/dist/tools/summarizeFast.d.ts.map +1 -0
  246. package/dist/tools/summarizeFast.js +43 -0
  247. package/dist/tools/summarizeFast.js.map +1 -0
  248. package/dist/tools/triageLogs.d.ts +51 -0
  249. package/dist/tools/triageLogs.d.ts.map +1 -0
  250. package/dist/tools/triageLogs.js +96 -0
  251. package/dist/tools/triageLogs.js.map +1 -0
  252. package/dist/version.d.ts +2 -0
  253. package/dist/version.d.ts.map +1 -0
  254. package/dist/version.js +2 -0
  255. package/dist/version.js.map +1 -0
  256. package/package.json +60 -0
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Targeted prewarm — pulls profile.prewarm tiers into VRAM at server startup
3
+ * so the first real Claude call doesn't eat cold-load latency.
4
+ *
5
+ * Behavior is profile policy, not magic:
6
+ * - dev-rtx5080: prewarm = ["instant"]
7
+ * - dev-rtx5080-llama: prewarm = ["instant"]
8
+ * - m5-max: prewarm = [] (cold-load on unified memory is ~free)
9
+ *
10
+ * Each prewarm attempt logs a {kind: "prewarm", ...} NDJSON event with
11
+ * model, success/failure, elapsed_ms, and residency. That keeps benchmarks
12
+ * able to distinguish cold from warm and keeps adoption data clean.
13
+ *
14
+ * Failures are logged but never thrown — server startup must not depend on
15
+ * Ollama being reachable. If the model is missing or Ollama is down, the
16
+ * server still comes up; the user sees the prewarm failure in the log.
17
+ */
18
+ import { resolveTier } from "./tiers.js";
19
+ import { timestamp } from "./observability.js";
20
+ /** Hard cap on per-tier prewarm wait. Long enough for a 14B cold load, short enough not to hang server startup. */
21
+ const PREWARM_TIMEOUT_MS = 60_000;
22
+ /**
23
+ * Run prewarm for the given tiers. Each tier issues a minimal generate
24
+ * (`prompt: "ok", num_predict: 1`) with `keep_alive: -1` so the model
25
+ * stays resident afterwards.
26
+ *
27
+ * Returns the count of successful prewarms; never throws.
28
+ */
29
+ export async function runPrewarm(ctx, tiers) {
30
+ let successes = 0;
31
+ for (const tier of tiers) {
32
+ const model = resolveTier(tier, ctx.tiers);
33
+ const startedAt = Date.now();
34
+ const controller = new AbortController();
35
+ const timer = setTimeout(() => controller.abort(), PREWARM_TIMEOUT_MS);
36
+ let success = false;
37
+ let error;
38
+ try {
39
+ await ctx.client.generate({
40
+ model,
41
+ prompt: "ok",
42
+ options: { num_predict: 1, temperature: 0 },
43
+ keep_alive: -1,
44
+ }, controller.signal);
45
+ success = true;
46
+ successes++;
47
+ }
48
+ catch (err) {
49
+ error = err instanceof Error ? err.message : String(err);
50
+ }
51
+ finally {
52
+ clearTimeout(timer);
53
+ }
54
+ const residency = success ? await ctx.client.residency(model).catch(() => null) : null;
55
+ await ctx.logger.log({
56
+ kind: "prewarm",
57
+ ts: timestamp(),
58
+ tier,
59
+ model,
60
+ hardware_profile: ctx.hardwareProfile,
61
+ success,
62
+ elapsed_ms: Date.now() - startedAt,
63
+ residency,
64
+ ...(error ? { error } : {}),
65
+ });
66
+ }
67
+ return successes;
68
+ }
69
+ //# sourceMappingURL=prewarm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prewarm.js","sourceRoot":"","sources":["../src/prewarm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,WAAW,EAAa,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,mHAAmH;AACnH,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAe,EAAE,KAAa;IAC7D,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3C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C,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5B,CAAC,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Hardware profiles — pick the right tier ladder for the machine running Ollama.
3
+ *
4
+ * The same code runs against very different hardware. This module encodes
5
+ * the "which model belongs on which tier for which box" decision explicitly
6
+ * so it's a product choice, not an env-var scavenger hunt.
7
+ *
8
+ * - dev-rtx5080 (default): Qwen ladder. Coherent day-to-day dogfooding.
9
+ * Same family top-to-bottom means a bad output is a tool/design problem,
10
+ * not a cross-family mismatch.
11
+ * - dev-rtx5080-llama: parity rail. Same instant/workhorse as default, but
12
+ * Llama 8B on Deep. Use this to measure whether Llama-family drift buys
13
+ * anything real before committing to it on the M5 Max.
14
+ * - m5-max: prod target. Real tier ladder once the box arrives.
15
+ *
16
+ * Per-tier env vars (INTERN_TIER_INSTANT, etc.) still override a profile's
17
+ * model picks, so one-off experiments don't require a new profile.
18
+ */
19
+ import type { Tier, TierConfig } from "./tiers.js";
20
+ export type ProfileName = "dev-rtx5080" | "dev-rtx5080-llama" | "m5-max";
21
+ export interface Profile {
22
+ name: ProfileName;
23
+ description: string;
24
+ tiers: TierConfig;
25
+ /**
26
+ * Per-tier timeouts in ms. Lives on the profile (not as a global constant)
27
+ * because cold-load behavior is hardware-bound — Instant needs 15s of
28
+ * margin on a 16GB-VRAM dev box but only 5s on M5 Max unified memory.
29
+ * Found via the first live dogfood pass: all Instant calls on RTX 5080
30
+ * timed out at 5s before first token.
31
+ */
32
+ timeouts: Record<Tier, number>;
33
+ /**
34
+ * Tiers to prewarm on server startup. Targeted adoption aid for tiers
35
+ * most likely to become habit (Instant), where cold-load drag would
36
+ * poison early product feel. NOT a blanket "make everything hot" knob —
37
+ * Workhorse and Deep are deliberately excluded so VRAM pressure and
38
+ * unintended residency churn don't start mattering.
39
+ */
40
+ prewarm: Tier[];
41
+ }
42
+ export declare const PROFILES: Record<ProfileName, Profile>;
43
+ export declare const DEFAULT_PROFILE: ProfileName;
44
+ /**
45
+ * Resolve the active profile from env. Selection order:
46
+ * 1. INTERN_PROFILE env var, if a known name
47
+ * 2. DEFAULT_PROFILE (dev-rtx5080)
48
+ *
49
+ * Per-tier env vars (INTERN_TIER_INSTANT, etc.) override the profile's picks.
50
+ * Profile.timeouts are not env-overridable — they are a hardware property,
51
+ * not a one-off tuning knob.
52
+ */
53
+ export declare function loadProfile(env?: NodeJS.ProcessEnv): Profile;
54
+ //# sourceMappingURL=profiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,mBAAmB,GAAG,QAAQ,CAAC;AAEzE,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;IAClB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/B;;;;;;OAMG;IACH,OAAO,EAAE,IAAI,EAAE,CAAC;CACjB;AAkBD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,CAuCjD,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,WAA2B,CAAC;AAM1D;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAUzE"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Hardware profiles — pick the right tier ladder for the machine running Ollama.
3
+ *
4
+ * The same code runs against very different hardware. This module encodes
5
+ * the "which model belongs on which tier for which box" decision explicitly
6
+ * so it's a product choice, not an env-var scavenger hunt.
7
+ *
8
+ * - dev-rtx5080 (default): Qwen ladder. Coherent day-to-day dogfooding.
9
+ * Same family top-to-bottom means a bad output is a tool/design problem,
10
+ * not a cross-family mismatch.
11
+ * - dev-rtx5080-llama: parity rail. Same instant/workhorse as default, but
12
+ * Llama 8B on Deep. Use this to measure whether Llama-family drift buys
13
+ * anything real before committing to it on the M5 Max.
14
+ * - m5-max: prod target. Real tier ladder once the box arrives.
15
+ *
16
+ * Per-tier env vars (INTERN_TIER_INSTANT, etc.) still override a profile's
17
+ * model picks, so one-off experiments don't require a new profile.
18
+ */
19
+ /** Timeouts sized for a 16GB-VRAM discrete-GPU box where cold load costs 3-5s. */
20
+ const DEV_RTX5080_TIMEOUTS = {
21
+ instant: 15_000,
22
+ workhorse: 20_000,
23
+ deep: 90_000,
24
+ embed: 10_000,
25
+ };
26
+ /** Timeouts sized for M5 Max 128GB unified memory where cold load is ~instant. */
27
+ const M5_MAX_TIMEOUTS = {
28
+ instant: 5_000,
29
+ workhorse: 20_000,
30
+ deep: 90_000,
31
+ embed: 10_000,
32
+ };
33
+ export const PROFILES = {
34
+ "dev-rtx5080": {
35
+ name: "dev-rtx5080",
36
+ description: "RTX 5080 16GB VRAM — Qwen ladder. Default dev profile for dogfooding the delegation spine.",
37
+ tiers: {
38
+ instant: "qwen2.5:7b-instruct-q4_K_M",
39
+ workhorse: "qwen2.5-coder:7b-instruct-q4_K_M",
40
+ deep: "qwen2.5:14b-instruct-q4_K_M",
41
+ embed: "nomic-embed-text",
42
+ },
43
+ timeouts: DEV_RTX5080_TIMEOUTS,
44
+ prewarm: ["instant"],
45
+ },
46
+ "dev-rtx5080-llama": {
47
+ name: "dev-rtx5080-llama",
48
+ description: "RTX 5080 with Llama 8B on Deep — parity comparison lane for future Llama-family Deep migration.",
49
+ tiers: {
50
+ instant: "qwen2.5:7b-instruct-q4_K_M",
51
+ workhorse: "qwen2.5-coder:7b-instruct-q4_K_M",
52
+ deep: "llama3.1:8b-instruct-q4_K_M",
53
+ embed: "nomic-embed-text",
54
+ },
55
+ timeouts: DEV_RTX5080_TIMEOUTS,
56
+ prewarm: ["instant"],
57
+ },
58
+ "m5-max": {
59
+ name: "m5-max",
60
+ description: "M5 Max 128GB unified — full tier ladder. Prod target.",
61
+ tiers: {
62
+ instant: "qwen2.5:14b-instruct-q4_K_M",
63
+ workhorse: "qwen2.5-coder:32b-instruct-q4_K_M",
64
+ deep: "llama3.3:70b-instruct-q4_K_M",
65
+ embed: "nomic-embed-text",
66
+ },
67
+ timeouts: M5_MAX_TIMEOUTS,
68
+ prewarm: [],
69
+ },
70
+ };
71
+ export const DEFAULT_PROFILE = "dev-rtx5080";
72
+ function isProfileName(x) {
73
+ return x === "dev-rtx5080" || x === "dev-rtx5080-llama" || x === "m5-max";
74
+ }
75
+ /**
76
+ * Resolve the active profile from env. Selection order:
77
+ * 1. INTERN_PROFILE env var, if a known name
78
+ * 2. DEFAULT_PROFILE (dev-rtx5080)
79
+ *
80
+ * Per-tier env vars (INTERN_TIER_INSTANT, etc.) override the profile's picks.
81
+ * Profile.timeouts are not env-overridable — they are a hardware property,
82
+ * not a one-off tuning knob.
83
+ */
84
+ export function loadProfile(env = process.env) {
85
+ const name = isProfileName(env.INTERN_PROFILE) ? env.INTERN_PROFILE : DEFAULT_PROFILE;
86
+ const base = PROFILES[name];
87
+ const tiers = {
88
+ instant: env.INTERN_TIER_INSTANT || base.tiers.instant,
89
+ workhorse: env.INTERN_TIER_WORKHORSE || base.tiers.workhorse,
90
+ deep: env.INTERN_TIER_DEEP || base.tiers.deep,
91
+ embed: env.INTERN_EMBED_MODEL || base.tiers.embed,
92
+ };
93
+ return { name, description: base.description, tiers, timeouts: base.timeouts, prewarm: base.prewarm };
94
+ }
95
+ //# sourceMappingURL=profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles.js","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;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AAqB;IAC1C,OAAO,CAAC,KAAK,aAAa,IAAI,CAAC,KAAK,mBAAmB,IAAI,CAAC,KAAK,QAAQ,CAAC;AAC5E,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,MAAyB,OAAO,CAAC,GAAG;IAC9D,MAAM,IAAI,GAAgB,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC;IACnG,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAe;QACxB,OAAO,EAAE,GAAG,CAAC,mBAAmB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO;QACtD,SAAS,EAAE,GAAG,CAAC,qBAAqB,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS;QAC5D,IAAI,EAAE,GAAG,CAAC,gBAAgB,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI;QAC7C,KAAK,EAAE,GAAG,CAAC,kBAAkB,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK;KAClD,CAAC;IACF,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;AACxG,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Protected-path list — explicit, versioned, one place.
3
+ *
4
+ * Writes from `ollama_draft` that target these paths require explicit
5
+ * `confirm_write: true`, enforced server-side (never prompt-side).
6
+ *
7
+ * Do NOT scatter conditionals across tool handlers. Add a new protected
8
+ * path here, bump PROTECTED_PATHS_VERSION, and the whole system picks it up.
9
+ */
10
+ export declare const PROTECTED_PATHS_VERSION = 1;
11
+ export interface ProtectedPathRule {
12
+ /** Glob-ish pattern, evaluated by matchesProtectedPath(). Use POSIX separators. */
13
+ pattern: string;
14
+ /** Human-readable reason shown in the error. */
15
+ reason: string;
16
+ }
17
+ /**
18
+ * Rules — kept explicit so a reviewer can eyeball them.
19
+ *
20
+ * Matching is substring-against-normalized-path with "/" as separator.
21
+ * A pattern ending in "/" matches any descendant.
22
+ */
23
+ export declare const PROTECTED_PATHS: ProtectedPathRule[];
24
+ /**
25
+ * Normalize a path for comparison: forward slashes, no leading ./, lowercase on Windows.
26
+ */
27
+ export declare function normalizePath(p: string): string;
28
+ export interface ProtectedMatch {
29
+ protected: boolean;
30
+ rule?: ProtectedPathRule;
31
+ }
32
+ export declare function matchesProtectedPath(path: string, rules?: ProtectedPathRule[]): ProtectedMatch;
33
+ //# sourceMappingURL=protectedPaths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protectedPaths.d.ts","sourceRoot":"","sources":["../src/protectedPaths.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,EAAE,iBAAiB,EAW9C,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,iBAAiB,CAAC;CAC1B;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,KAAK,GAAE,iBAAiB,EAAoB,GAC3C,cAAc,CAchB"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Protected-path list — explicit, versioned, one place.
3
+ *
4
+ * Writes from `ollama_draft` that target these paths require explicit
5
+ * `confirm_write: true`, enforced server-side (never prompt-side).
6
+ *
7
+ * Do NOT scatter conditionals across tool handlers. Add a new protected
8
+ * path here, bump PROTECTED_PATHS_VERSION, and the whole system picks it up.
9
+ */
10
+ export const PROTECTED_PATHS_VERSION = 1;
11
+ /**
12
+ * Rules — kept explicit so a reviewer can eyeball them.
13
+ *
14
+ * Matching is substring-against-normalized-path with "/" as separator.
15
+ * A pattern ending in "/" matches any descendant.
16
+ */
17
+ export const PROTECTED_PATHS = [
18
+ { pattern: "memory/", reason: "Canon-adjacent memory — human judgment only." },
19
+ { pattern: "MEMORY.md", reason: "Memory index — only the memory system updates this." },
20
+ { pattern: ".claude/", reason: "Claude configuration and rules — human-owned." },
21
+ { pattern: "docs/canon/", reason: "Game canon — authored by humans, never drafted." },
22
+ { pattern: "canon/", reason: "Game canon — authored by humans, never drafted." },
23
+ { pattern: "doctrine/", reason: "Combat/systems doctrine — human-owned." },
24
+ { pattern: "games/", reason: "Proprietary game data root." },
25
+ { pattern: ".git/", reason: "Git internals." },
26
+ { pattern: "SECURITY.md", reason: "Security policy — reviewed changes only." },
27
+ { pattern: "LICENSE", reason: "License — do not auto-modify." },
28
+ ];
29
+ /**
30
+ * Normalize a path for comparison: forward slashes, no leading ./, lowercase on Windows.
31
+ */
32
+ export function normalizePath(p) {
33
+ let n = p.replace(/\\/g, "/");
34
+ if (n.startsWith("./"))
35
+ n = n.slice(2);
36
+ return n;
37
+ }
38
+ export function matchesProtectedPath(path, rules = PROTECTED_PATHS) {
39
+ const n = normalizePath(path);
40
+ for (const rule of rules) {
41
+ const pat = rule.pattern;
42
+ if (pat.endsWith("/")) {
43
+ // Directory rule: any segment boundary containing the dir name matches.
44
+ if (n.startsWith(pat) || n.includes("/" + pat)) {
45
+ return { protected: true, rule };
46
+ }
47
+ }
48
+ else if (n === pat || n.endsWith("/" + pat)) {
49
+ return { protected: true, rule };
50
+ }
51
+ }
52
+ return { protected: false };
53
+ }
54
+ //# sourceMappingURL=protectedPaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protectedPaths.js","sourceRoot":"","sources":["../src/protectedPaths.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,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC;QACzB,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,wEAAwE;YACxE,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;gBAC/C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YACnC,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC;YAC9C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACnC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Shared dependencies every tool handler needs.
3
+ *
4
+ * Passing one RunContext is cleaner than threading 3+ positional args,
5
+ * and gives us a stable shape to extend later (metrics, tracing, etc.)
6
+ * without touching 8 call sites.
7
+ */
8
+ import type { OllamaClient } from "./ollama.js";
9
+ import type { Tier, TierConfig } from "./tiers.js";
10
+ import type { Logger } from "./observability.js";
11
+ export interface RunContext {
12
+ client: OllamaClient;
13
+ /** Concrete tier→model picks from the active Profile. */
14
+ tiers: TierConfig;
15
+ /** Per-tier timeouts in ms, sized for the active profile's hardware. */
16
+ timeouts: Record<Tier, number>;
17
+ /** Profile name written onto every envelope + NDJSON line. */
18
+ hardwareProfile: string;
19
+ logger: Logger;
20
+ }
21
+ //# sourceMappingURL=runContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runContext.d.ts","sourceRoot":"","sources":["../src/runContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,YAAY,CAAC;IACrB,yDAAyD;IACzD,KAAK,EAAE,UAAU,CAAC;IAClB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/B,8DAA8D;IAC9D,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared dependencies every tool handler needs.
3
+ *
4
+ * Passing one RunContext is cleaner than threading 3+ positional args,
5
+ * and gives us a stable shape to extend later (metrics, tracing, etc.)
6
+ * without touching 8 call sites.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=runContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runContext.js","sourceRoot":"","sources":["../src/runContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Global concurrency gate around the local Ollama instance.
3
+ * Local inference is bottlenecked on VRAM and compute; letting 20 calls
4
+ * race into llama.cpp just thrashes. Default to 2 concurrent calls.
5
+ */
6
+ export declare class Semaphore {
7
+ private permits;
8
+ private queue;
9
+ constructor(permits: number);
10
+ acquire(): Promise<() => void>;
11
+ private release;
12
+ /** For tests. */
13
+ get pending(): number;
14
+ }
15
+ export declare const ollamaSemaphore: Semaphore;
16
+ //# sourceMappingURL=semaphore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semaphore.d.ts","sourceRoot":"","sources":["../src/semaphore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,KAAK,CAAyB;gBAE1B,OAAO,EAAE,MAAM;IAIrB,OAAO,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC;IAapC,OAAO,CAAC,OAAO;IAMf,iBAAiB;IACjB,IAAI,OAAO,IAAI,MAAM,CAEpB;CACF;AAID,eAAO,MAAM,eAAe,WAAqC,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Global concurrency gate around the local Ollama instance.
3
+ * Local inference is bottlenecked on VRAM and compute; letting 20 calls
4
+ * race into llama.cpp just thrashes. Default to 2 concurrent calls.
5
+ */
6
+ export class Semaphore {
7
+ permits;
8
+ queue = [];
9
+ constructor(permits) {
10
+ this.permits = permits;
11
+ }
12
+ async acquire() {
13
+ if (this.permits > 0) {
14
+ this.permits--;
15
+ return () => this.release();
16
+ }
17
+ return new Promise((resolve) => {
18
+ this.queue.push(() => {
19
+ this.permits--;
20
+ resolve(() => this.release());
21
+ });
22
+ });
23
+ }
24
+ release() {
25
+ this.permits++;
26
+ const next = this.queue.shift();
27
+ if (next)
28
+ next();
29
+ }
30
+ /** For tests. */
31
+ get pending() {
32
+ return this.queue.length;
33
+ }
34
+ }
35
+ const DEFAULT_CONCURRENCY = Number(process.env.INTERN_MAX_CONCURRENT ?? 2);
36
+ export const ollamaSemaphore = new Semaphore(DEFAULT_CONCURRENCY);
37
+ //# sourceMappingURL=semaphore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semaphore.js","sourceRoot":"","sources":["../src/semaphore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,OAAO,SAAS;IACZ,OAAO,CAAS;IAChB,KAAK,GAAsB,EAAE,CAAC;IAEtC,YAAY,OAAe;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,EAAE;YACzC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;gBACnB,IAAI,CAAC,OAAO,EAAE,CAAC;gBACf,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,OAAO;QACb,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,IAAI;YAAE,IAAI,EAAE,CAAC;IACnB,CAAC;IAED,iBAAiB;IACjB,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,CAAC,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Shared source-file loader used by tools that accept `source_paths[]`.
3
+ *
4
+ * The point of a path-based tool input is context preservation — Claude does
5
+ * not pre-read the file, the server does. Keep this module fast and boring.
6
+ */
7
+ export interface LoadedSource {
8
+ path: string;
9
+ body: string;
10
+ }
11
+ /**
12
+ * Read each path, slice to `perFileMax` chars per file, return in input order.
13
+ * Throws SOURCE_PATH_NOT_FOUND on the first missing/unreadable path so the
14
+ * caller fails loud instead of getting a partial answer.
15
+ */
16
+ export declare function loadSources(paths: string[], perFileMax: number): Promise<LoadedSource[]>;
17
+ /** Format loaded sources as a single prompt block with begin/end markers per file. */
18
+ export declare function formatSourcesBlock(sources: LoadedSource[]): string;
19
+ //# sourceMappingURL=sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.d.ts","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,YAAY,EAAE,CAAC,CA2BzB;AAED,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,CAIlE"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Shared source-file loader used by tools that accept `source_paths[]`.
3
+ *
4
+ * The point of a path-based tool input is context preservation — Claude does
5
+ * not pre-read the file, the server does. Keep this module fast and boring.
6
+ */
7
+ import { readFile, stat } from "node:fs/promises";
8
+ import { resolve } from "node:path";
9
+ import { InternError } from "./errors.js";
10
+ /**
11
+ * Read each path, slice to `perFileMax` chars per file, return in input order.
12
+ * Throws SOURCE_PATH_NOT_FOUND on the first missing/unreadable path so the
13
+ * caller fails loud instead of getting a partial answer.
14
+ */
15
+ export async function loadSources(paths, perFileMax) {
16
+ const loaded = [];
17
+ for (const p of paths) {
18
+ const abs = resolve(p);
19
+ try {
20
+ const st = await stat(abs);
21
+ if (!st.isFile()) {
22
+ throw new InternError("SOURCE_PATH_NOT_FOUND", `Not a file: ${p}`, "Pass file paths only, not directories.", false);
23
+ }
24
+ const raw = await readFile(abs, "utf8");
25
+ loaded.push({ path: p, body: raw.slice(0, perFileMax) });
26
+ }
27
+ catch (err) {
28
+ if (err instanceof InternError)
29
+ throw err;
30
+ throw new InternError("SOURCE_PATH_NOT_FOUND", `Cannot read source path: ${p} — ${err.message}`, "Check the path exists and is readable.", false);
31
+ }
32
+ }
33
+ return loaded;
34
+ }
35
+ /** Format loaded sources as a single prompt block with begin/end markers per file. */
36
+ export function formatSourcesBlock(sources) {
37
+ return sources
38
+ .map((s) => `=== BEGIN ${s.path} ===\n${s.body}\n=== END ${s.path} ===`)
39
+ .join("\n\n");
40
+ }
41
+ //# sourceMappingURL=sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources.js","sourceRoot":"","sources":["../src/sources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAO1C;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAe,EACf,UAAkB;IAElB,MAAM,MAAM,GAAmB,EAAE,CAAC;IAClC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC;YACH,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;YAC3B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,WAAW,CACnB,uBAAuB,EACvB,eAAe,CAAC,EAAE,EAClB,wCAAwC,EACxC,KAAK,CACN,CAAC;YACJ,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,WAAW;gBAAE,MAAM,GAAG,CAAC;YAC1C,MAAM,IAAI,WAAW,CACnB,uBAAuB,EACvB,4BAA4B,CAAC,MAAO,GAAa,CAAC,OAAO,EAAE,EAC3D,wCAAwC,EACxC,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,kBAAkB,CAAC,OAAuB;IACxD,OAAO,OAAO;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,IAAI,MAAM,CAAC;SACvE,IAAI,CAAC,MAAM,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Tier shape and constants — tier→model selection lives in ./profiles.ts.
3
+ *
4
+ * Claude picks the tier by picking the tool. Tools declare their tier;
5
+ * resolveTier() turns a Tier into the concrete model name from a TierConfig,
6
+ * which comes from the active Profile.
7
+ */
8
+ export type Tier = "instant" | "workhorse" | "deep" | "embed";
9
+ export interface TierConfig {
10
+ instant: string;
11
+ workhorse: string;
12
+ deep: string;
13
+ embed: string;
14
+ }
15
+ export declare function resolveTier(tier: Tier, config: TierConfig): string;
16
+ /**
17
+ * Per-tier timeouts in ms. Used by guardrails/timeouts.ts to enforce
18
+ * degradation rules and decide fallback behavior.
19
+ */
20
+ export declare const TIER_TIMEOUT_MS: Record<Tier, number>;
21
+ /**
22
+ * Fallback tier — what to degrade to when a tier's timeout fires.
23
+ * Deep → workhorse → instant. Embed has no fallback (no cheaper embed tier).
24
+ */
25
+ export declare const TIER_FALLBACK: Record<Tier, Tier | null>;
26
+ /**
27
+ * Default temperatures by work shape. Small models reward tight scaffolding;
28
+ * these map to the patterns in the handoff prompt-shape notes.
29
+ */
30
+ export declare const TEMPERATURE_BY_SHAPE: {
31
+ readonly classify: 0.1;
32
+ readonly extract: 0.1;
33
+ readonly triage: 0.1;
34
+ readonly summarize: 0.3;
35
+ readonly research: 0.3;
36
+ readonly draft: 0.4;
37
+ readonly chat: 0.7;
38
+ };
39
+ //# sourceMappingURL=tiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiers.d.ts","sourceRoot":"","sources":["../src/tiers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE9D,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAElE;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAKhD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAKnD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;CAQvB,CAAC"}
package/dist/tiers.js ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Tier shape and constants — tier→model selection lives in ./profiles.ts.
3
+ *
4
+ * Claude picks the tier by picking the tool. Tools declare their tier;
5
+ * resolveTier() turns a Tier into the concrete model name from a TierConfig,
6
+ * which comes from the active Profile.
7
+ */
8
+ export function resolveTier(tier, config) {
9
+ return config[tier];
10
+ }
11
+ /**
12
+ * Per-tier timeouts in ms. Used by guardrails/timeouts.ts to enforce
13
+ * degradation rules and decide fallback behavior.
14
+ */
15
+ export const TIER_TIMEOUT_MS = {
16
+ instant: 5_000,
17
+ workhorse: 20_000,
18
+ deep: 90_000,
19
+ embed: 10_000,
20
+ };
21
+ /**
22
+ * Fallback tier — what to degrade to when a tier's timeout fires.
23
+ * Deep → workhorse → instant. Embed has no fallback (no cheaper embed tier).
24
+ */
25
+ export const TIER_FALLBACK = {
26
+ deep: "workhorse",
27
+ workhorse: "instant",
28
+ instant: null,
29
+ embed: null,
30
+ };
31
+ /**
32
+ * Default temperatures by work shape. Small models reward tight scaffolding;
33
+ * these map to the patterns in the handoff prompt-shape notes.
34
+ */
35
+ export const TEMPERATURE_BY_SHAPE = {
36
+ classify: 0.1,
37
+ extract: 0.1,
38
+ triage: 0.1,
39
+ summarize: 0.3,
40
+ research: 0.3,
41
+ draft: 0.4,
42
+ chat: 0.7,
43
+ };
44
+ //# sourceMappingURL=tiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiers.js","sourceRoot":"","sources":["../src/tiers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAWH,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,MAAkB;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAyB;IACnD,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,MAAM;IACjB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAA8B;IACtD,IAAI,EAAE,WAAW;IACjB,SAAS,EAAE,SAAS;IACpB,OAAO,EAAE,IAAI;IACb,KAAK,EAAE,IAAI;CACZ,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,GAAG;IACX,SAAS,EAAE,GAAG;IACd,QAAQ,EAAE,GAAG;IACb,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,GAAG;CACD,CAAC"}