@cortexkit/pi-magic-context 0.40.1 → 0.41.1

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.
package/README.md CHANGED
@@ -131,6 +131,15 @@ Magic Context stores everything in a single shared SQLite database at:
131
131
  ~/.local/share/cortexkit/magic-context/context.db
132
132
  ```
133
133
 
134
+ When a host isolates `XDG_DATA_HOME` per process, set
135
+ `MAGIC_CONTEXT_STORAGE_DIR` to the absolute, complete shared Magic Context
136
+ storage directory. The explicit path takes precedence over the XDG-derived path
137
+ and does not change Pi's own configuration or session directories. The host must
138
+ propagate one identical value to every process that shares the database; Magic
139
+ Context never originates this variable from its default. This affects the
140
+ harness-side database only, not `subc` daemon state. Mixed-version processes on
141
+ one directory still block migrations until all processes use a compatible build.
142
+
134
143
  This is the **same database** the OpenCode plugin and OMP extension use. Tables are scoped by:
135
144
  - `harness` column (`'pi'` or `'opencode'`) for session-scoped data; OMP intentionally uses `'pi'`
136
145
  - `project_path` (resolved git root) for project-scoped data (memories, embeddings, dreamer runs)
@@ -0,0 +1,64 @@
1
+ import"./index-1yh8g550.js";
2
+
3
+ // src/historian-calibration-extension.ts
4
+ var HISTORIAN_TEMPERATURE_ENV = "MAGIC_CONTEXT_HISTORIAN_TEMPERATURE";
5
+ var HISTORIAN_MAX_OUTPUT_TOKENS_ENV = "MAGIC_CONTEXT_HISTORIAN_MAX_OUTPUT_TOKENS";
6
+ function finiteNumber(value) {
7
+ if (value === undefined || value.trim().length === 0)
8
+ return;
9
+ const parsed = Number(value);
10
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined;
11
+ }
12
+ function calibrateHistorianProviderPayload(payload, temperature, maxOutputTokens) {
13
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload))
14
+ return payload;
15
+ if (temperature === undefined && maxOutputTokens === undefined)
16
+ return payload;
17
+ const calibrated = { ...payload };
18
+ const generationConfig = calibrated.generationConfig;
19
+ if (typeof generationConfig === "object" && generationConfig !== null && !Array.isArray(generationConfig)) {
20
+ calibrated.generationConfig = {
21
+ ...generationConfig,
22
+ ...temperature !== undefined ? { temperature } : {},
23
+ ...maxOutputTokens !== undefined ? { maxOutputTokens } : {}
24
+ };
25
+ return calibrated;
26
+ }
27
+ const inferenceConfig = calibrated.inferenceConfig;
28
+ if (typeof inferenceConfig === "object" && inferenceConfig !== null && !Array.isArray(inferenceConfig)) {
29
+ calibrated.inferenceConfig = {
30
+ ...inferenceConfig,
31
+ ...temperature !== undefined ? { temperature } : {},
32
+ ...maxOutputTokens !== undefined ? { maxTokens: maxOutputTokens } : {}
33
+ };
34
+ return calibrated;
35
+ }
36
+ if (temperature !== undefined) {
37
+ calibrated.temperature = temperature;
38
+ }
39
+ if (maxOutputTokens !== undefined) {
40
+ if ("max_output_tokens" in calibrated) {
41
+ calibrated.max_output_tokens = maxOutputTokens;
42
+ } else if ("max_completion_tokens" in calibrated) {
43
+ calibrated.max_completion_tokens = maxOutputTokens;
44
+ } else if ("max_tokens" in calibrated) {
45
+ calibrated.max_tokens = maxOutputTokens;
46
+ } else if ("maxTokens" in calibrated) {
47
+ calibrated.maxTokens = maxOutputTokens;
48
+ }
49
+ }
50
+ return calibrated;
51
+ }
52
+ function historianCalibrationExtension(pi) {
53
+ const temperature = finiteNumber(process.env[HISTORIAN_TEMPERATURE_ENV]);
54
+ const maxOutputTokens = finiteNumber(process.env[HISTORIAN_MAX_OUTPUT_TOKENS_ENV]);
55
+ if (temperature === undefined && maxOutputTokens === undefined)
56
+ return;
57
+ pi.on("before_provider_request", (event) => calibrateHistorianProviderPayload(event.payload, temperature, maxOutputTokens));
58
+ }
59
+ export {
60
+ HISTORIAN_MAX_OUTPUT_TOKENS_ENV,
61
+ HISTORIAN_TEMPERATURE_ENV,
62
+ calibrateHistorianProviderPayload,
63
+ historianCalibrationExtension as default
64
+ };