@gaunt-sloth/core 2.0.0-alpha.2 → 2.0.0-alpha.21
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/.gsloth.code.md +10 -0
- package/README.md +6 -6
- package/dist/config/defaults.d.ts +85 -0
- package/dist/config/defaults.js +103 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/jsonc.d.ts +12 -0
- package/dist/config/jsonc.js +41 -0
- package/dist/config/jsonc.js.map +1 -0
- package/dist/config/loader.d.ts +169 -0
- package/dist/config/loader.js +872 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +673 -0
- package/dist/config/schema.js +524 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/shell-policy.d.ts +331 -0
- package/dist/config/shell-policy.js +238 -0
- package/dist/config/shell-policy.js.map +1 -0
- package/dist/config/types.d.ts +596 -0
- package/dist/config/types.js +13 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config.d.ts +18 -647
- package/dist/config.js +15 -516
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +42 -0
- package/dist/constants.js +42 -0
- package/dist/constants.js.map +1 -1
- package/dist/core/GthAbstractAgent.d.ts +85 -2
- package/dist/core/GthAbstractAgent.js +398 -28
- package/dist/core/GthAbstractAgent.js.map +1 -1
- package/dist/core/GthAgentRunner.d.ts +158 -1
- package/dist/core/GthAgentRunner.js +367 -4
- package/dist/core/GthAgentRunner.js.map +1 -1
- package/dist/core/GthLangChainAgent.js +193 -16
- package/dist/core/GthLangChainAgent.js.map +1 -1
- package/dist/core/debugCapture.d.ts +59 -0
- package/dist/core/debugCapture.js +101 -0
- package/dist/core/debugCapture.js.map +1 -0
- package/dist/core/gthLeanAgentFactory.d.ts +9 -0
- package/dist/core/gthLeanAgentFactory.js +10 -0
- package/dist/core/gthLeanAgentFactory.js.map +1 -0
- package/dist/core/plainToolIndication.d.ts +15 -0
- package/dist/core/plainToolIndication.js +148 -0
- package/dist/core/plainToolIndication.js.map +1 -0
- package/dist/core/runStats.d.ts +41 -0
- package/dist/core/runStats.js +73 -0
- package/dist/core/runStats.js.map +1 -0
- package/dist/core/shell/ShellCommandFailedError.d.ts +54 -0
- package/dist/core/shell/ShellCommandFailedError.js +68 -0
- package/dist/core/shell/ShellCommandFailedError.js.map +1 -0
- package/dist/core/shell/allowlist.d.ts +75 -0
- package/dist/core/shell/allowlist.js +187 -0
- package/dist/core/shell/allowlist.js.map +1 -0
- package/dist/core/shell/arity.d.ts +75 -0
- package/dist/core/shell/arity.js +313 -0
- package/dist/core/shell/arity.js.map +1 -0
- package/dist/core/shell/judge.d.ts +161 -0
- package/dist/core/shell/judge.js +261 -0
- package/dist/core/shell/judge.js.map +1 -0
- package/dist/core/shell/normalize.d.ts +27 -0
- package/dist/core/shell/normalize.js +53 -0
- package/dist/core/shell/normalize.js.map +1 -0
- package/dist/core/toolDisplay.d.ts +101 -0
- package/dist/core/toolDisplay.js +374 -0
- package/dist/core/toolDisplay.js.map +1 -0
- package/dist/core/toolOutputChannel.d.ts +68 -0
- package/dist/core/toolOutputChannel.js +112 -0
- package/dist/core/toolOutputChannel.js.map +1 -0
- package/dist/core/types.d.ts +173 -0
- package/dist/core/types.js.map +1 -1
- package/dist/history/historyFormat.d.ts +28 -0
- package/dist/history/historyFormat.js +127 -0
- package/dist/history/historyFormat.js.map +1 -0
- package/dist/history/historyStore.d.ts +198 -0
- package/dist/history/historyStore.js +482 -0
- package/dist/history/historyStore.js.map +1 -0
- package/dist/history/recordSession.d.ts +37 -0
- package/dist/history/recordSession.js +56 -0
- package/dist/history/recordSession.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic.d.ts +1 -1
- package/dist/providers/anthropic.js +5 -10
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/deepseek.d.ts +1 -1
- package/dist/providers/deepseek.js +5 -10
- package/dist/providers/deepseek.js.map +1 -1
- package/dist/providers/geminiSchemaSanitizer.d.ts +52 -0
- package/dist/providers/geminiSchemaSanitizer.js +201 -0
- package/dist/providers/geminiSchemaSanitizer.js.map +1 -0
- package/dist/providers/google-genai.d.ts +1 -1
- package/dist/providers/google-genai.js +9 -11
- package/dist/providers/google-genai.js.map +1 -1
- package/dist/providers/groq.d.ts +1 -1
- package/dist/providers/groq.js +5 -10
- package/dist/providers/groq.js.map +1 -1
- package/dist/providers/huggingface.d.ts +25 -0
- package/dist/providers/huggingface.js +69 -0
- package/dist/providers/huggingface.js.map +1 -0
- package/dist/providers/modelCatalog.d.ts +109 -0
- package/dist/providers/modelCatalog.js +245 -0
- package/dist/providers/modelCatalog.js.map +1 -0
- package/dist/providers/modelDiscovery.d.ts +111 -3
- package/dist/providers/modelDiscovery.js +183 -27
- package/dist/providers/modelDiscovery.js.map +1 -1
- package/dist/providers/ollama.d.ts +19 -5
- package/dist/providers/ollama.js +60 -52
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +5 -10
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/openrouter.d.ts +1 -1
- package/dist/providers/openrouter.js +12 -12
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/providers/vertexai.d.ts +1 -1
- package/dist/providers/vertexai.js +9 -11
- package/dist/providers/vertexai.js.map +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.js +5 -10
- package/dist/providers/xai.js.map +1 -1
- package/dist/runtime/askStructured.d.ts +62 -0
- package/dist/runtime/askStructured.js +76 -0
- package/dist/runtime/askStructured.js.map +1 -0
- package/dist/runtime/conversation.d.ts +59 -0
- package/dist/runtime/conversation.js +137 -0
- package/dist/runtime/conversation.js.map +1 -0
- package/dist/runtime/singleShot.d.ts +24 -5
- package/dist/runtime/singleShot.js +56 -9
- package/dist/runtime/singleShot.js.map +1 -1
- package/dist/utils/aiignoreUtils.js.map +1 -1
- package/dist/utils/binaryOutputUtils.js.map +1 -1
- package/dist/utils/consoleUtils.d.ts +22 -0
- package/dist/utils/consoleUtils.js +45 -0
- package/dist/utils/consoleUtils.js.map +1 -1
- package/dist/utils/debugDump.d.ts +57 -0
- package/dist/utils/debugDump.js +236 -0
- package/dist/utils/debugDump.js.map +1 -0
- package/dist/utils/debugUtils.d.ts +13 -4
- package/dist/utils/debugUtils.js +36 -13
- package/dist/utils/debugUtils.js.map +1 -1
- package/dist/utils/fileUtils.d.ts +24 -2
- package/dist/utils/fileUtils.js +54 -12
- package/dist/utils/fileUtils.js.map +1 -1
- package/dist/utils/llmUtils.js.map +1 -1
- package/dist/utils/redactSecrets.d.ts +63 -0
- package/dist/utils/redactSecrets.js +238 -0
- package/dist/utils/redactSecrets.js.map +1 -0
- package/dist/utils/systemPromptNotes.d.ts +181 -0
- package/dist/utils/systemPromptNotes.js +298 -0
- package/dist/utils/systemPromptNotes.js.map +1 -0
- package/dist/utils/systemUtils.d.ts +32 -1
- package/dist/utils/systemUtils.js +50 -3
- package/dist/utils/systemUtils.js.map +1 -1
- package/dist/utils/toolMatching.d.ts +30 -0
- package/dist/utils/toolMatching.js +44 -0
- package/dist/utils/toolMatching.js.map +1 -0
- package/package.json +17 -8
- package/schema/gsloth-config.schema.json +2111 -0
package/dist/utils/debugUtils.js
CHANGED
|
@@ -3,6 +3,30 @@ import { dirname, resolve } from 'node:path';
|
|
|
3
3
|
import { inspect } from 'node:util';
|
|
4
4
|
const DEBUG_LOG_FILE = 'gaunt-sloth.log';
|
|
5
5
|
let debugEnabled = false;
|
|
6
|
+
/**
|
|
7
|
+
* GS2-46 — bounded in-memory ring buffer of debug-log lines, populated by every `debugLog*`
|
|
8
|
+
* variant UNCONDITIONALLY (independent of `debugEnabled`, which only gates the on-disk write
|
|
9
|
+
* below). This is deliberately always-on and forward-looking: GS2-48 (crash handler) expects
|
|
10
|
+
* "the last-N debugLog buffer lines already held in memory" to exist regardless of whether
|
|
11
|
+
* `config.debugLog` was ever turned on for the session, and `/debug-dump` (GS2-46) surfaces it
|
|
12
|
+
* verbatim. Capped so a long session can't grow this without bound.
|
|
13
|
+
*/
|
|
14
|
+
const DEBUG_LOG_BUFFER_MAX = 1000;
|
|
15
|
+
const debugLogBuffer = [];
|
|
16
|
+
/** Push one formatted line into the ring buffer, evicting the oldest entry once at capacity. */
|
|
17
|
+
function pushToDebugLogBuffer(entry) {
|
|
18
|
+
debugLogBuffer.push(entry);
|
|
19
|
+
if (debugLogBuffer.length > DEBUG_LOG_BUFFER_MAX) {
|
|
20
|
+
debugLogBuffer.shift();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* GS2-46 — read the current debug-log ring buffer (oldest first). Returns a copy so callers
|
|
25
|
+
* (e.g. the `/debug-dump` writer) can't mutate the live buffer.
|
|
26
|
+
*/
|
|
27
|
+
export function getDebugLogBuffer() {
|
|
28
|
+
return [...debugLogBuffer];
|
|
29
|
+
}
|
|
6
30
|
/**
|
|
7
31
|
* Initialize debug logging based on config
|
|
8
32
|
*/
|
|
@@ -27,15 +51,17 @@ export function initDebugLogging(enabled) {
|
|
|
27
51
|
}
|
|
28
52
|
}
|
|
29
53
|
/**
|
|
30
|
-
* Log a debug message
|
|
54
|
+
* Log a debug message. Always pushed into the in-memory ring buffer (GS2-46); only appended to
|
|
55
|
+
* the on-disk log file when debug logging is enabled.
|
|
31
56
|
*/
|
|
32
57
|
export function debugLog(message) {
|
|
58
|
+
const timestamp = new Date().toISOString();
|
|
59
|
+
const logEntry = `[${timestamp}] ${message}`;
|
|
60
|
+
pushToDebugLogBuffer(logEntry);
|
|
33
61
|
if (!debugEnabled)
|
|
34
62
|
return;
|
|
35
|
-
const timestamp = new Date().toISOString();
|
|
36
|
-
const logEntry = `[${timestamp}] ${message}\n`;
|
|
37
63
|
try {
|
|
38
|
-
appendFileSync(resolve(DEBUG_LOG_FILE), logEntry
|
|
64
|
+
appendFileSync(resolve(DEBUG_LOG_FILE), `${logEntry}\n`, 'utf8');
|
|
39
65
|
}
|
|
40
66
|
catch (error) {
|
|
41
67
|
// Ignore logging errors to prevent breaking the main flow
|
|
@@ -43,21 +69,19 @@ export function debugLog(message) {
|
|
|
43
69
|
}
|
|
44
70
|
}
|
|
45
71
|
/**
|
|
46
|
-
* Log multiple lines with proper formatting
|
|
72
|
+
* Log multiple lines with proper formatting. Always buffered (GS2-46); delegates to `debugLog`
|
|
73
|
+
* for the on-disk gating.
|
|
47
74
|
*/
|
|
48
75
|
export function debugLogMultiline(title, content) {
|
|
49
|
-
if (!debugEnabled)
|
|
50
|
-
return;
|
|
51
76
|
debugLog(`=== ${title} ===`);
|
|
52
77
|
debugLog(content);
|
|
53
78
|
debugLog(`=== End ${title} ===\n`);
|
|
54
79
|
}
|
|
55
80
|
/**
|
|
56
|
-
* Log an object using Node.js inspect with reasonable depth
|
|
81
|
+
* Log an object using Node.js inspect with reasonable depth. Always buffered (GS2-46); delegates
|
|
82
|
+
* to `debugLogMultiline`/`debugLog` for the on-disk gating.
|
|
57
83
|
*/
|
|
58
84
|
export function debugLogObject(title, obj) {
|
|
59
|
-
if (!debugEnabled)
|
|
60
|
-
return;
|
|
61
85
|
try {
|
|
62
86
|
// Use Node.js inspect with reasonable depth and no colors for log files
|
|
63
87
|
const formatted = inspect(obj, { showHidden: false, depth: 3, colors: false });
|
|
@@ -68,11 +92,10 @@ export function debugLogObject(title, obj) {
|
|
|
68
92
|
}
|
|
69
93
|
}
|
|
70
94
|
/**
|
|
71
|
-
* Log error with stack trace
|
|
95
|
+
* Log error with stack trace. Always buffered (GS2-46); delegates to `debugLog` for the on-disk
|
|
96
|
+
* gating.
|
|
72
97
|
*/
|
|
73
98
|
export function debugLogError(context, error) {
|
|
74
|
-
if (!debugEnabled)
|
|
75
|
-
return;
|
|
76
99
|
debugLog(`❌ Error in ${context}:`);
|
|
77
100
|
if (error instanceof Error) {
|
|
78
101
|
debugLog(` Message: ${error.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debugUtils.js","sourceRoot":"","sources":["../../src/utils/debugUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,cAAc,GAAG,iBAAiB,CAAC;AACzC,IAAI,YAAY,GAAG,KAAK,CAAC;AAEzB;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,YAAY,GAAG,OAAO,CAAC;IACvB,IAAI,YAAY,EAAE,CAAC;QACjB,uCAAuC;QACvC,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAChC,IAAI,CAAC;YACH,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACvC,6DAA6D;QAC/D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,8CAA8C;QAChD,CAAC;QAED,qBAAqB;QACrB,QAAQ,CAAC,mCAAmC,CAAC,CAAC;QAC9C,QAAQ,CAAC,cAAc,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACnD,QAAQ,CAAC,aAAa,OAAO,EAAE,CAAC,CAAC;QACjC,QAAQ,CAAC,oCAAoC,CAAC,CAAC;IACjD,CAAC;AACH,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"debugUtils.js","sourceRoot":"","sources":["../../src/utils/debugUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,c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xC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,QAAQ,CAAC,gBAAgB,CAAC,CAAC;YAC3B,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,YAAY,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IACD,QAAQ,CAAC,EAAE,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -60,11 +60,33 @@ export declare function readMultipleFilesFromProjectDir(fileNames: string | stri
|
|
|
60
60
|
* package dir.
|
|
61
61
|
*/
|
|
62
62
|
export declare function readFileFromInstallDir(filePath: string, packageDir?: string): string;
|
|
63
|
-
|
|
63
|
+
/**
|
|
64
|
+
* No-clobber write: writes `content` only when `filePath` does not already exist.
|
|
65
|
+
* @returns `true` when the file was written, `false` when it was skipped because it
|
|
66
|
+
* already existed. Callers use the return value to avoid claiming success on a skip.
|
|
67
|
+
*/
|
|
68
|
+
export declare function writeFileIfNotExistsWithMessages(filePath: string, content: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Unconditional write: writes (or overwrites) `content` at `filePath`, creating parent
|
|
71
|
+
* directories as needed. Use this only for the config-overwrite path (an explicit user /
|
|
72
|
+
* `--force` decision); the no-clobber {@link writeFileIfNotExistsWithMessages} still guards
|
|
73
|
+
* user-editable preamble files (guidelines / review).
|
|
74
|
+
*/
|
|
75
|
+
export declare function writeFileWithMessages(filePath: string, content: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Config-file write that honours an overwrite flag.
|
|
78
|
+
* - `force === true` → always (over)writes.
|
|
79
|
+
* - `force === false` → no-clobber (skips + warns when the file already exists).
|
|
80
|
+
* @returns `true` when a write happened, `false` when it was skipped.
|
|
81
|
+
*/
|
|
82
|
+
export declare function writeConfigFileWithMessages(filePath: string, content: string, force?: boolean): boolean;
|
|
64
83
|
export declare function appendToFile(filePath: string, content: string): void;
|
|
65
84
|
export declare function readFileSyncWithMessages(filePath: string, errorMessageIn?: string, noFileMessage?: string): string;
|
|
66
85
|
/**
|
|
67
|
-
* Dynamically imports a module from a file path from the outside of the installation dir
|
|
86
|
+
* Dynamically imports a module from a file path from the outside of the installation dir.
|
|
87
|
+
* `.ts` modules are loaded through jiti (Node's native dynamic `import()` cannot load
|
|
88
|
+
* TypeScript), so `.gsloth.config.ts` honours the same async `configure()` contract as
|
|
89
|
+
* `.js`/`.mjs`. All other extensions use native dynamic import.
|
|
68
90
|
* @returns A promise that resolves to the imported module
|
|
69
91
|
*/
|
|
70
92
|
export declare function importExternalFile(filePath: string): Promise<Record<string, any>>;
|
package/dist/utils/fileUtils.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, resolve } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import {
|
|
4
|
+
import { getProjectDir } from '#src/utils/systemUtils.js';
|
|
5
5
|
import { GSLOTH_DIR, GSLOTH_SETTINGS_DIR } from '#src/constants.js';
|
|
6
6
|
import { displayError, displayInfo, displaySuccess, displayWarning, } from '#src/utils/consoleUtils.js';
|
|
7
7
|
import { wrapContent } from '#src/utils/llmUtils.js';
|
|
8
8
|
import url from 'node:url';
|
|
9
|
+
import { createJiti } from 'jiti';
|
|
9
10
|
/**
|
|
10
11
|
* Checks if .gsloth directory exists in the project root
|
|
11
12
|
* @returns Boolean indicating whether .gsloth directory exists
|
|
12
13
|
*/
|
|
13
14
|
export function gslothDirExists() {
|
|
14
|
-
const currentDir =
|
|
15
|
+
const currentDir = getProjectDir();
|
|
15
16
|
const gslothDirPath = resolve(currentDir, GSLOTH_DIR);
|
|
16
17
|
return existsSync(gslothDirPath);
|
|
17
18
|
}
|
|
@@ -21,7 +22,7 @@ export function gslothDirExists() {
|
|
|
21
22
|
* @returns The resolved path where the file should be written
|
|
22
23
|
*/
|
|
23
24
|
export function getGslothFilePath(filename) {
|
|
24
|
-
const currentDir =
|
|
25
|
+
const currentDir = getProjectDir();
|
|
25
26
|
if (gslothDirExists()) {
|
|
26
27
|
const gslothDirPath = resolve(currentDir, GSLOTH_DIR);
|
|
27
28
|
return resolve(gslothDirPath, filename);
|
|
@@ -40,7 +41,7 @@ export function getGslothFilePath(filename) {
|
|
|
40
41
|
* @returns The resolved path where the configuration file should be written
|
|
41
42
|
*/
|
|
42
43
|
export function getGslothConfigWritePath(filename) {
|
|
43
|
-
const currentDir =
|
|
44
|
+
const currentDir = getProjectDir();
|
|
44
45
|
if (gslothDirExists()) {
|
|
45
46
|
const gslothDirPath = resolve(currentDir, GSLOTH_DIR);
|
|
46
47
|
const gslothSettingsPath = resolve(gslothDirPath, GSLOTH_SETTINGS_DIR);
|
|
@@ -59,10 +60,10 @@ export function getGslothConfigWritePath(filename) {
|
|
|
59
60
|
* @returns The resolved path where the configuration file should be found
|
|
60
61
|
*/
|
|
61
62
|
export function getGslothConfigReadPath(filename, identityProfileRaw) {
|
|
62
|
-
const
|
|
63
|
+
const baseDir = getProjectDir();
|
|
63
64
|
const identityProfile = identityProfileRaw?.trim();
|
|
64
65
|
if (gslothDirExists()) {
|
|
65
|
-
const gslothDirPath = resolve(
|
|
66
|
+
const gslothDirPath = resolve(baseDir, GSLOTH_DIR);
|
|
66
67
|
const gslothSettingsPath = resolve(gslothDirPath, GSLOTH_SETTINGS_DIR);
|
|
67
68
|
const configPath = identityProfile
|
|
68
69
|
? resolve(gslothSettingsPath, identityProfile, filename)
|
|
@@ -71,7 +72,7 @@ export function getGslothConfigReadPath(filename, identityProfileRaw) {
|
|
|
71
72
|
return configPath;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
return resolve(
|
|
75
|
+
return resolve(baseDir, filename);
|
|
75
76
|
}
|
|
76
77
|
/**
|
|
77
78
|
* Resolve an explicit output path string to an absolute file path.
|
|
@@ -80,7 +81,7 @@ export function getGslothConfigReadPath(filename, identityProfileRaw) {
|
|
|
80
81
|
* - If it's a bare filename, place it under .gsloth/ when present, otherwise project root.
|
|
81
82
|
*/
|
|
82
83
|
export function resolveOutputPath(writeOutputToFile) {
|
|
83
|
-
const currentDir =
|
|
84
|
+
const currentDir = getProjectDir();
|
|
84
85
|
const provided = String(writeOutputToFile).trim();
|
|
85
86
|
// Detect if provided path contains path separators (cross-platform)
|
|
86
87
|
const hasSeparator = provided.includes('/') || provided.includes('\\');
|
|
@@ -125,7 +126,7 @@ export function generateStandardFileName(command) {
|
|
|
125
126
|
return `gth_${dateTimeStr}_${commandStr}.md`;
|
|
126
127
|
}
|
|
127
128
|
export function readFileFromProjectDir(fileName) {
|
|
128
|
-
const currentDir =
|
|
129
|
+
const currentDir = getProjectDir();
|
|
129
130
|
const filePath = resolve(currentDir, fileName);
|
|
130
131
|
displayInfo(`Reading file ${filePath}...`);
|
|
131
132
|
return readFileSyncWithMessages(filePath);
|
|
@@ -162,6 +163,11 @@ export function readFileFromInstallDir(filePath, packageDir = corePackageDir) {
|
|
|
162
163
|
throw readFromInstallDirError;
|
|
163
164
|
}
|
|
164
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* No-clobber write: writes `content` only when `filePath` does not already exist.
|
|
168
|
+
* @returns `true` when the file was written, `false` when it was skipped because it
|
|
169
|
+
* already existed. Callers use the return value to avoid claiming success on a skip.
|
|
170
|
+
*/
|
|
165
171
|
export function writeFileIfNotExistsWithMessages(filePath, content) {
|
|
166
172
|
displayInfo(`checking ${filePath} existence`);
|
|
167
173
|
if (!existsSync(filePath)) {
|
|
@@ -172,10 +178,38 @@ export function writeFileIfNotExistsWithMessages(filePath, content) {
|
|
|
172
178
|
}
|
|
173
179
|
writeFileSync(filePath, content);
|
|
174
180
|
displaySuccess(`Created ${filePath}`);
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
displayWarning(`${filePath} already exists`);
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Unconditional write: writes (or overwrites) `content` at `filePath`, creating parent
|
|
188
|
+
* directories as needed. Use this only for the config-overwrite path (an explicit user /
|
|
189
|
+
* `--force` decision); the no-clobber {@link writeFileIfNotExistsWithMessages} still guards
|
|
190
|
+
* user-editable preamble files (guidelines / review).
|
|
191
|
+
*/
|
|
192
|
+
export function writeFileWithMessages(filePath, content) {
|
|
193
|
+
const parentDir = dirname(filePath);
|
|
194
|
+
if (!existsSync(parentDir)) {
|
|
195
|
+
mkdirSync(parentDir, { recursive: true });
|
|
175
196
|
}
|
|
176
|
-
|
|
177
|
-
|
|
197
|
+
const existed = existsSync(filePath);
|
|
198
|
+
writeFileSync(filePath, content);
|
|
199
|
+
displaySuccess(existed ? `Overwrote ${filePath}` : `Created ${filePath}`);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Config-file write that honours an overwrite flag.
|
|
203
|
+
* - `force === true` → always (over)writes.
|
|
204
|
+
* - `force === false` → no-clobber (skips + warns when the file already exists).
|
|
205
|
+
* @returns `true` when a write happened, `false` when it was skipped.
|
|
206
|
+
*/
|
|
207
|
+
export function writeConfigFileWithMessages(filePath, content, force = false) {
|
|
208
|
+
if (force) {
|
|
209
|
+
writeFileWithMessages(filePath, content);
|
|
210
|
+
return true;
|
|
178
211
|
}
|
|
212
|
+
return writeFileIfNotExistsWithMessages(filePath, content);
|
|
179
213
|
}
|
|
180
214
|
export function appendToFile(filePath, content) {
|
|
181
215
|
try {
|
|
@@ -206,11 +240,19 @@ export function readFileSyncWithMessages(filePath, errorMessageIn, noFileMessage
|
|
|
206
240
|
}
|
|
207
241
|
}
|
|
208
242
|
/**
|
|
209
|
-
* Dynamically imports a module from a file path from the outside of the installation dir
|
|
243
|
+
* Dynamically imports a module from a file path from the outside of the installation dir.
|
|
244
|
+
* `.ts` modules are loaded through jiti (Node's native dynamic `import()` cannot load
|
|
245
|
+
* TypeScript), so `.gsloth.config.ts` honours the same async `configure()` contract as
|
|
246
|
+
* `.js`/`.mjs`. All other extensions use native dynamic import.
|
|
210
247
|
* @returns A promise that resolves to the imported module
|
|
211
248
|
*/
|
|
212
249
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
213
250
|
export function importExternalFile(filePath) {
|
|
251
|
+
if (filePath.endsWith('.ts')) {
|
|
252
|
+
const jiti = createJiti(import.meta.url);
|
|
253
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
254
|
+
return jiti.import(filePath);
|
|
255
|
+
}
|
|
214
256
|
const configFileUrl = url.pathToFileURL(filePath).toString();
|
|
215
257
|
return import(configFileUrl);
|
|
216
258
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileUtils.js","sourceRoot":"","sources":["../../src/utils/fileUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fileUtils.js","sourceRoot":"","sources":["../../src/utils/fileUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,E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"version":3,"file":"llmUtils.js","sourceRoot":"","sources":["../../src/utils/llmUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,
|
|
1
|
+
{"version":3,"file":"llmUtils.js","sourceRoot":"","sources":["../../src/utils/llmUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,cAAc,GAAW,IAAI;IAChE,OAAO;QACL,cAAc;QACd,YAAY,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;KAC1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CAAC,EAAE,CAAC;YACjF,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,GAAG,GAAG,KAAK,cAAc,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,CAAC;IACvD,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAkE,EAClE,SAAS,GAAG,GAAG;IAEf,MAAM,SAAS,GAAG,SAAS;SACxB,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;QAChB,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QACnC,MAAM,aAAa,GAAG,kBAAkB,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAC9D,OAAO,GAAG,QAAQ,CAAC,IAAI,IAAI,aAAa,GAAG,CAAC;IAC9C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,6CAA6C;IAC7C,OAAO,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* GS2-47 — a shared, reusable secret-redaction pass for diagnostic output.
|
|
4
|
+
*
|
|
5
|
+
* Built for `/debug-dump` ({@link file://./debugDump.ts}) but deliberately generic and
|
|
6
|
+
* dependency-free — it takes `env` as a PARAMETER rather than reading `process.env`, so the pass is
|
|
7
|
+
* pure, deterministic in tests, and reusable by GS2-48's crash-report handler (which hard-depends on
|
|
8
|
+
* this module). Nothing here reads ambient process state.
|
|
9
|
+
*
|
|
10
|
+
* DESIGN DECISION (settled by the coordinator, GS2-47): **PATTERN-ONLY** redaction — we do NOT scan
|
|
11
|
+
* for high-entropy strings. Rationale: pattern-only is safe to reason about and near-zero
|
|
12
|
+
* false-positive; entropy scanning catches marginally more but produces false-positive redactions
|
|
13
|
+
* the user has to squint through, degrading the dump's debug value. A high-entropy scanner is a
|
|
14
|
+
* DELIBERATELY-DEFERRED option (a config surface for it could be added later if ever warranted) and
|
|
15
|
+
* is intentionally NOT implemented here.
|
|
16
|
+
*
|
|
17
|
+
* Three techniques, in priority order:
|
|
18
|
+
* 1. [load-bearing] Known-secret VALUE substitution — collect the literal values of secret-named
|
|
19
|
+
* env vars + inline config secrets, then substitute every occurrence across ALL artifacts. This
|
|
20
|
+
* catches a leaked key wherever it surfaces (config, env, transcript, log) with no guessing.
|
|
21
|
+
* 2. Provider key/token PATTERNS — a tight, documented, prefix-anchored set of well-known key
|
|
22
|
+
* shapes plus explicit auth-header contexts. We never blanket-redact long alphanumeric strings.
|
|
23
|
+
* 3. Sensitive config-FIELD masking — mask the VALUES of secret-named config keys while preserving
|
|
24
|
+
* structure (the key stays; only the value becomes the marker).
|
|
25
|
+
*
|
|
26
|
+
* Fail-safe throughout: on any internal error the functions redact MORE (return the marker), never
|
|
27
|
+
* less — a redaction hiccup must never cause raw content to be emitted.
|
|
28
|
+
*/
|
|
29
|
+
/** The visible, greppable placeholder substituted for every redacted secret value. */
|
|
30
|
+
export declare const REDACTED = "<redacted>";
|
|
31
|
+
/**
|
|
32
|
+
* Collect the literal secret VALUES to substitute everywhere (technique 1), from two sources:
|
|
33
|
+
* - process-env vars whose NAME matches {@link SECRET_ENV_NAME_RE}, PLUS the specific var(s) named
|
|
34
|
+
* by any `apiKeyEnvironmentVariable` in the config;
|
|
35
|
+
* - non-empty inline secret field values in the config (technique 3's field names), so a key pasted
|
|
36
|
+
* inline is scrubbed wherever it *also* surfaces (transcript, log, env), not only in config.json.
|
|
37
|
+
*
|
|
38
|
+
* `env` is a PARAMETER — never read ambiently — so the pass is pure, reusable (GS2-48) and
|
|
39
|
+
* deterministic in tests. Values shorter than {@link MIN_SECRET_LITERAL_LENGTH} are skipped. The
|
|
40
|
+
* result is returned longest-first so an overlapping-substring secret can't leave a shorter one
|
|
41
|
+
* partially intact. Never throws (a hostile config getter is swallowed — patterns + structural
|
|
42
|
+
* masking still apply).
|
|
43
|
+
*/
|
|
44
|
+
export declare function collectSecretValues(config: unknown, env: Record<string, string | undefined>): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Redact a STRING: substitute every known literal secret value (technique 1, longest-first), then
|
|
47
|
+
* apply the provider key/auth patterns (technique 2). Never throws — on any error it returns the
|
|
48
|
+
* fully-withheld marker (fail safe: redact MORE, never emit the raw text). Applying it twice is
|
|
49
|
+
* safe (re-redacting already-redacted text is a no-op).
|
|
50
|
+
*/
|
|
51
|
+
export declare function redactText(text: string, secrets: readonly string[]): string;
|
|
52
|
+
/**
|
|
53
|
+
* Deep-redact an arbitrary value for serialization: mask the VALUES of secret-named fields
|
|
54
|
+
* (technique 3 — structure preserved: the key stays, only its value becomes the marker) and run
|
|
55
|
+
* {@link redactText} over every string leaf (techniques 1 + 2). Circular refs are broken; functions
|
|
56
|
+
* and bigints are rendered the way `safeStringify` would, so the result is JSON-safe. Pure — never
|
|
57
|
+
* mutates the input. `apiKeyEnvironmentVariable` is intentionally NOT masked (it is a var name).
|
|
58
|
+
*
|
|
59
|
+
* Intended for the CONFIG artifact (where field-name masking is wanted). Non-config artifacts use
|
|
60
|
+
* {@link redactText} over their stringified form instead (literal + pattern only), so a legitimate
|
|
61
|
+
* `token`/`secret`-named field in tool output is not blanket-masked.
|
|
62
|
+
*/
|
|
63
|
+
export declare function redactValue(value: unknown, secrets: readonly string[]): unknown;
|