@showrun/core 0.1.5 → 0.1.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Emrah Yalaz, Anil Seyrek, Mahmut Karaca
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/config.d.ts CHANGED
@@ -70,6 +70,12 @@ export declare function loadConfig(): ResolvedConfigPaths;
70
70
  * Apply config values to `process.env`, only setting vars that are not already present.
71
71
  */
72
72
  export declare function applyConfigToEnv(config: ShowRunConfig): void;
73
+ /**
74
+ * Update the global config.json with a set of env-var-name → value pairs.
75
+ * Creates the config directory and file if they don't exist.
76
+ * Only writes non-empty string values.
77
+ */
78
+ export declare function updateGlobalConfig(values: Record<string, string>): void;
73
79
  /**
74
80
  * Resolve a filename by searching local paths first (cwd, then ancestors),
75
81
  * then config directories (highest priority first).
@@ -81,6 +87,14 @@ export declare function resolveFilePath(filename: string): string | null;
81
87
  * Get the global config directory path for the current platform.
82
88
  */
83
89
  export declare function getGlobalConfigDir(): string;
90
+ /**
91
+ * Get the global data directory path for the current platform.
92
+ * Used for databases, run logs, and default taskpacks.
93
+ *
94
+ * Linux/macOS: $XDG_DATA_HOME/showrun (default ~/.local/share/showrun)
95
+ * Windows: %LOCALAPPDATA%\showrun (fallback %APPDATA%\showrun)
96
+ */
97
+ export declare function getGlobalDataDir(): string;
84
98
  /**
85
99
  * Ensure a system prompt file exists in a config directory.
86
100
  * If the prompt was found outside config dirs (e.g. repo root), copy it
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAUH,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE;QACJ,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,iBAAiB,CAAC;QAC9B,MAAM,CAAC,EAAE,iBAAiB,CAAC;KAC5B,CAAC;IACF,KAAK,CAAC,EAAE;QACN,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,CAAC;IACF,OAAO,CAAC,EAAE;QACR,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,0BAA0B,CAAC,EAAE,MAAM,CAAC;KACrC,CAAC;IACF,UAAU,CAAC,EAAE;QACX,WAAW,CAAC,EAAE;YACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;YAClB,GAAG,CAAC,EAAE,MAAM,CAAC;YACb,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,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;AAMD;;;GAGG;AACH,wBAAgB,UAAU,IAAI,mBAAmB,CAmBhD;AAoDD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAQ5D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CA0BvE;AAID;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAsB/D;AAID;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAS3C;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAWzC;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAmB1F;AAID;;;GAGG;AACH,wBAAgB,UAAU,IAAI,mBAAmB,CAShD;AAID,eAAO,MAAM,uBAAuB,EAAE,aAoBrC,CAAC"}
package/dist/config.js CHANGED
@@ -12,7 +12,7 @@ import { existsSync, copyFileSync } from 'fs';
12
12
  import { resolve, join, parse as parsePath } from 'path';
13
13
  import { platform, homedir } from 'os';
14
14
  import { cwd } from 'process';
15
- import { ensureDir, readJsonFile } from './packUtils.js';
15
+ import { ensureDir, readJsonFile, atomicWrite } from './packUtils.js';
16
16
  // ── Deep merge helper ──────────────────────────────────────────────────────
17
17
  /**
18
18
  * Recursively merge `override` into `base`, returning a new object.
@@ -151,6 +151,20 @@ function getNestedValue(obj, path) {
151
151
  }
152
152
  return current;
153
153
  }
154
+ /**
155
+ * Set a value at a nested path in an object, creating intermediate objects as needed.
156
+ */
157
+ function setNestedValue(obj, path, value) {
158
+ let current = obj;
159
+ for (let i = 0; i < path.length - 1; i++) {
160
+ const key = path[i];
161
+ if (current[key] === undefined || current[key] === null || typeof current[key] !== 'object') {
162
+ current[key] = {};
163
+ }
164
+ current = current[key];
165
+ }
166
+ current[path[path.length - 1]] = value;
167
+ }
154
168
  /**
155
169
  * Apply config values to `process.env`, only setting vars that are not already present.
156
170
  */
@@ -164,6 +178,37 @@ export function applyConfigToEnv(config) {
164
178
  }
165
179
  }
166
180
  }
181
+ /**
182
+ * Update the global config.json with a set of env-var-name → value pairs.
183
+ * Creates the config directory and file if they don't exist.
184
+ * Only writes non-empty string values.
185
+ */
186
+ export function updateGlobalConfig(values) {
187
+ const globalDir = getGlobalConfigDir();
188
+ const configPath = join(globalDir, 'config.json');
189
+ ensureDir(globalDir);
190
+ let config;
191
+ if (existsSync(configPath)) {
192
+ try {
193
+ config = readJsonFile(configPath);
194
+ }
195
+ catch {
196
+ config = JSON.parse(JSON.stringify(DEFAULT_CONFIG_TEMPLATE));
197
+ }
198
+ }
199
+ else {
200
+ config = JSON.parse(JSON.stringify(DEFAULT_CONFIG_TEMPLATE));
201
+ }
202
+ for (const [envVar, value] of Object.entries(values)) {
203
+ if (!value)
204
+ continue;
205
+ const mapping = CONFIG_TO_ENV.find(m => m.envVar === envVar);
206
+ if (mapping) {
207
+ setNestedValue(config, mapping.path, value);
208
+ }
209
+ }
210
+ atomicWrite(configPath, JSON.stringify(config, null, 2) + '\n');
211
+ }
167
212
  // ── File resolution ────────────────────────────────────────────────────────
168
213
  /**
169
214
  * Resolve a filename by searching local paths first (cwd, then ancestors),
@@ -209,6 +254,27 @@ export function getGlobalConfigDir() {
209
254
  const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
210
255
  return join(xdgConfig, 'showrun');
211
256
  }
257
+ /**
258
+ * Get the global data directory path for the current platform.
259
+ * Used for databases, run logs, and default taskpacks.
260
+ *
261
+ * Linux/macOS: $XDG_DATA_HOME/showrun (default ~/.local/share/showrun)
262
+ * Windows: %LOCALAPPDATA%\showrun (fallback %APPDATA%\showrun)
263
+ */
264
+ export function getGlobalDataDir() {
265
+ const os = platform();
266
+ if (os === 'win32') {
267
+ const localAppData = process.env.LOCALAPPDATA;
268
+ if (localAppData)
269
+ return join(localAppData, 'showrun');
270
+ const appData = process.env.APPDATA;
271
+ if (appData)
272
+ return join(appData, 'showrun');
273
+ return join(homedir(), 'AppData', 'Local', 'showrun');
274
+ }
275
+ const xdgData = process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share');
276
+ return join(xdgData, 'showrun');
277
+ }
212
278
  /**
213
279
  * Ensure a system prompt file exists in a config directory.
214
280
  * If the prompt was found outside config dirs (e.g. repo root), copy it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@showrun/core",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Core types and utilities for Task Pack framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,11 +14,6 @@
14
14
  "files": [
15
15
  "dist"
16
16
  ],
17
- "scripts": {
18
- "build": "tsc",
19
- "test": "vitest run",
20
- "test:watch": "vitest"
21
- },
22
17
  "dependencies": {
23
18
  "@jmespath-community/jmespath": "^1.3.0",
24
19
  "camoufox-js": "^0.8.5",
@@ -45,5 +40,10 @@
45
40
  },
46
41
  "publishConfig": {
47
42
  "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest"
48
48
  }
49
- }
49
+ }