Skip to content

Commit 4e6ab01

Browse files
committed
fix: eliminate dist/dist/ build corruption at source — remove hardcoded ../../dist/ fallback paths, use import.meta.url resolution, disable stale source maps, add prebuild clean
Three files were confirmed as dist/dist/ corruption sources: - strray-codex-injection.ts/js: removed ../../dist/core/... fallback candidates, use cwd-relative paths in loadStringRayComponents() - import-resolver.ts: use join(currentDir, ..) instead of ../dist/ relative paths - GitHookTrigger.ts: use STRRAY_DIST_PATH env var instead of hardcoded /dist/ in dynamic imports Also: disable sourceMap + declarationMap in tsconfig (unnecessary bloat, caused missing map warnings), add prebuild clean step to remove tsconfig.tsbuildinfo before each build (prevents incremental cache corruption)
1 parent 5e4e47a commit 4e6ab01

6 files changed

Lines changed: 28 additions & 40 deletions

File tree

.opencode/plugin/strray-codex-injection.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ async function loadFrameworkLogger() {
3030
return _frameworkLogger;
3131
const candidates = [
3232
"../core/framework-logger.js",
33-
"../../dist/core/framework-logger.js",
3433
"../../node_modules/strray-ai/dist/core/framework-logger.js",
3534
];
3635
for (const p of candidates) {
@@ -53,7 +52,6 @@ async function loadConfigPaths() {
5352
return;
5453
const candidates = [
5554
"../core/config-paths.js",
56-
"../../dist/core/config-paths.js",
5755
"../../node_modules/strray-ai/dist/core/config-paths.js",
5856
];
5957
for (const p of candidates) {
@@ -87,7 +85,6 @@ async function importSystemPromptGenerator() {
8785
return;
8886
const candidates = [
8987
"../core/system-prompt-generator.js",
90-
"../../dist/core/system-prompt-generator.js",
9188
"../../node_modules/strray-ai/dist/core/system-prompt-generator.js",
9289
];
9390
for (const p of candidates) {
@@ -107,39 +104,40 @@ async function loadStringRayComponents() {
107104
if (_ProcessorManager && _StrRayStateManager && _featuresConfigLoader)
108105
return;
109106
const logger = await getOrCreateLogger(process.cwd());
107+
const root = process.cwd();
110108
try {
111-
logger.log(`🔄 Attempting to load from ../../dist/`);
112-
const procModule = await import("../../dist/processors/processor-manager.js");
113-
const stateModule = await import("../../dist/state/state-manager.js");
114-
const featuresModule = await import("../../dist/core/features-config.js");
109+
logger.log(`🔄 Attempting to load from cwd/dist/`);
110+
const procModule = await import(`${root}/dist/processors/processor-manager.js`);
111+
const stateModule = await import(`${root}/dist/state/state-manager.js`);
112+
const featuresModule = await import(`${root}/dist/core/features-config.js`);
115113
_ProcessorManager = procModule.ProcessorManager;
116114
_StrRayStateManager = stateModule.StrRayStateManager;
117115
_featuresConfigLoader = featuresModule.featuresConfigLoader;
118116
_detectTaskType = featuresModule.detectTaskType;
119-
logger.log(`✅ Loaded from ../../dist/`);
117+
logger.log(`✅ Loaded from cwd/dist/`);
120118
return;
121119
}
122120
catch (e) {
123121
const message = e instanceof Error ? e.message : String(e);
124-
logger.log(`❌ Failed to load from ../../dist/: ${message}`);
122+
logger.log(`❌ Failed to load from cwd/dist/: ${message}`);
125123
}
126124
const pluginPaths = ["strray-ai", "strray-framework"];
127125
for (const pluginPath of pluginPaths) {
128126
try {
129-
logger.log(`🔄 Attempting to load from ../../node_modules/${pluginPath}/dist/`);
130-
const pm = await import(`../../node_modules/${pluginPath}/dist/processors/processor-manager.js`);
131-
const sm = await import(`../../node_modules/${pluginPath}/dist/state/state-manager.js`);
132-
const fm = await import(`../../node_modules/${pluginPath}/dist/core/features-config.js`);
127+
logger.log(`🔄 Attempting to load from node_modules/${pluginPath}/dist/`);
128+
const pm = await import(`${root}/node_modules/${pluginPath}/dist/processors/processor-manager.js`);
129+
const sm = await import(`${root}/node_modules/${pluginPath}/dist/state/state-manager.js`);
130+
const fm = await import(`${root}/node_modules/${pluginPath}/dist/core/features-config.js`);
133131
_ProcessorManager = pm.ProcessorManager;
134132
_StrRayStateManager = sm.StrRayStateManager;
135133
_featuresConfigLoader = fm.featuresConfigLoader;
136134
_detectTaskType = fm.detectTaskType;
137-
logger.log(`✅ Loaded from ../../node_modules/${pluginPath}/dist/`);
135+
logger.log(`✅ Loaded from node_modules/${pluginPath}/dist/`);
138136
return;
139137
}
140138
catch (e) {
141139
const message = e instanceof Error ? e.message : String(e);
142-
logger.log(`❌ Failed to load from ../../node_modules/${pluginPath}/dist/: ${message}`);
140+
logger.log(`❌ Failed to load from node_modules/${pluginPath}/dist/: ${message}`);
143141
}
144142
}
145143
}
@@ -836,5 +834,4 @@ export default async function strrayCodexPlugin(input) {
836834
logger.log("✅ Plugin config hook completed");
837835
},
838836
};
839-
}
840-
//# sourceMappingURL=strray-codex-injection.js.map
837+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"prepublishOnly": "npm run prepare-consumer && npm run build:all && find dist -name '*.d.ts' -o -name '*.d.ts.map' -o -name '*.js.map' | xargs rm -f",
4747
"version:bump": "node scripts/node/version-manager.mjs",
4848
"version": "node scripts/node/version-manager.mjs",
49+
"prebuild": "rm -rf dist tsconfig.tsbuildinfo tsconfig.*.tsbuildinfo",
4950
"build": "tsc && mkdir -p dist/public dist/scripts && cp -r public/* dist/public/ && cp scripts/validate-stringray-comprehensive.js dist/scripts/ && cp scripts/hooks/pre-command dist/scripts/ && cp scripts/hooks/pre-command.mjs dist/scripts/ && cp README.md AGENTS.md CHANGELOG.md LICENSE dist/ && find src -name '*.mjs' ! -path '*/__tests__/*' | while read f; do tgt=\"dist/${f#src/}\"; mkdir -p \"$(dirname $tgt)\"; cp \"$f\" \"$tgt\"; done && for dir in skills integrations mcps; do find src/$dir -type f ! -name '*.ts' ! -path '*/.pytest_cache/*' | while read f; do tgt=\"dist/${f#src/}\"; mkdir -p \"$(dirname $tgt)\"; cp \"$f\" \"$tgt\"; done; done && mkdir -p dist/plugin && cp .opencode/plugin/strray-codex-injection.js dist/plugin/strray-codex-injection.js && cp -r src/opencode/ .opencode/",
5051
"build:all": "npm run build",
5152
"ci-install": "npm ci",

src/plugin/strray-codex-injection.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ async function loadFrameworkLogger(): Promise<FrameworkLoggerLike> {
136136
if (_frameworkLogger) return _frameworkLogger;
137137
const candidates = [
138138
"../core/framework-logger.js",
139-
"../../dist/core/framework-logger.js",
140139
"../../node_modules/strray-ai/dist/core/framework-logger.js",
141140
];
142141
for (const p of candidates) {
@@ -158,7 +157,6 @@ async function loadConfigPaths(): Promise<void> {
158157
if (_resolveCodexPath && _resolveStateDir) return;
159158
const candidates = [
160159
"../core/config-paths.js",
161-
"../../dist/core/config-paths.js",
162160
"../../node_modules/strray-ai/dist/core/config-paths.js",
163161
];
164162
for (const p of candidates) {
@@ -192,7 +190,6 @@ async function importSystemPromptGenerator(): Promise<void> {
192190

193191
const candidates = [
194192
"../core/system-prompt-generator.js",
195-
"../../dist/core/system-prompt-generator.js",
196193
"../../node_modules/strray-ai/dist/core/system-prompt-generator.js",
197194
];
198195
for (const p of candidates) {

src/postprocessor/triggers/GitHookTrigger.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,9 @@ fi
525525
try {
526526
// Use dynamic import that works in both dev and consumer
527527
const basePath = process.env.STRRAY_BASE_PATH || '.';
528+
const distPath = process.env.STRRAY_DIST_PATH || 'dist';
528529
// First archive logs (compress and rotate) before cleanup
529-
const { archiveLogFiles } = await import(basePath + '/dist/postprocessor/triggers/GitHookTrigger.js');
530+
const { archiveLogFiles } = await import(basePath + '/' + distPath + '/postprocessor/triggers/GitHookTrigger.js');
530531
const archiveResult = await archiveLogFiles({
531532
archiveDirectory: 'logs/framework',
532533
maxFileSizeMB: 10, // Archive if > 10MB
@@ -541,7 +542,7 @@ fi
541542
}
542543
543544
// Then cleanup old files
544-
const { cleanupLogFiles } = await import(basePath + '/dist/postprocessor/triggers/GitHookTrigger.js');
545+
const { cleanupLogFiles } = await import(basePath + '/' + distPath + '/postprocessor/triggers/GitHookTrigger.js');
545546
const result = await cleanupLogFiles({
546547
maxAgeHours: 24,
547548
excludePatterns: [

src/utils/import-resolver.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,13 @@ export class ImportResolver {
112112
const fullModuleName = subPath ? `${subPath}/${moduleName}` : moduleName;
113113

114114
if (this.isTesting) {
115-
// In tests, prefer built versions to avoid import issues
116-
return `../dist/${fullModuleName}.js`;
115+
return join(this.currentDir, "..", `${fullModuleName}.js`);
117116
} else if (this.isDevelopment) {
118-
// In development, use source files
119-
return `../src/${fullModuleName}.ts`;
117+
return join(this.currentDir, "..", `${fullModuleName}.ts`);
120118
} else if (this.isBuilt || this.isInstalled) {
121-
// In built/deployed environments, use compiled files
122-
return `../dist/${fullModuleName}.js`;
119+
return join(this.currentDir, "..", `${fullModuleName}.js`);
123120
} else {
124-
// Fallback - try built first, then source
125-
return `../dist/${fullModuleName}.js`;
121+
return join(this.currentDir, "..", `${fullModuleName}.js`);
126122
}
127123
}
128124

@@ -190,20 +186,16 @@ export class ImportResolver {
190186
const paths: string[] = [];
191187

192188
if (this.isDevelopment) {
193-
// Development alternatives
194189
paths.push(
195-
`../dist/${fullModuleName}.js`,
196-
`../src/${fullModuleName}.ts`,
190+
join(this.currentDir, "..", `${fullModuleName}.js`),
191+
join(this.currentDir, "..", `${fullModuleName}.ts`),
197192
`./${fullModuleName}.ts`,
198-
`../dist/${fullModuleName}.js`,
199193
);
200194
} else {
201-
// Built/deployed alternatives
202195
paths.push(
203-
`../src/${fullModuleName}.ts`,
204-
`../dist/${fullModuleName}.js`,
196+
join(this.currentDir, "..", `${fullModuleName}.ts`),
197+
join(this.currentDir, "..", `${fullModuleName}.js`),
205198
`./${fullModuleName}.js`,
206-
`../dist/${fullModuleName}.js`,
207199
);
208200
}
209201

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"skipLibCheck": true,
1212
"forceConsistentCasingInFileNames": true,
1313
"declaration": true,
14-
"declarationMap": true,
15-
"sourceMap": true,
14+
"declarationMap": false,
15+
"sourceMap": false,
1616
"outDir": "./dist",
1717
"rootDir": "./src",
1818
"removeComments": false,

0 commit comments

Comments
 (0)