mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-03 17:53:39 +00:00
* refactor: remove TypeScript 6 from plugin runtime and tooling Keep source plugin loading on Jiti and native module transforms, move development analysis and declaration builds to TypeScript 7, and preserve captured loader and input ownership contracts. Scaffolds compile to the same entry path without shipping a compiler in production. * refactor: use native checker for restart preflight detection * fix: keep test-directory docs out of native helper scans * fix: preserve native compiler tooling across CI runtimes Keep compiler-backed tests on the supported Node transport, preserve declared Windows aliases and partial-source analysis, and bind relocated SDK reports to their installed compiler. Retain strict package input admission and the existing fixture assertions. * test: compare messaging guard diagnostics without sorting * fix: bound native tooling memory and preserve bootstrap loading * fix: bound native declaration builds with tsdown scheduling * fix: retire compiler-only helpers from installed packages * test: migrate routing import scan to native parser * test(ui): wait for recovered model catalog receipt
98 lines
3 KiB
TypeScript
98 lines
3 KiB
TypeScript
#!/usr/bin/env node
|
|
|
|
// Blocks host-random tmpdir usage in messaging/channel runtime sources.
|
|
import * as ts from "typescript/unstable/ast";
|
|
import { runCallsiteGuard } from "./lib/callsite-guard.mts";
|
|
import { classifyBundledExtensionSourcePath } from "./lib/extension-source-classifier.mts";
|
|
import {
|
|
collectCallExpressionLines,
|
|
runAsScript,
|
|
unwrapExpression,
|
|
} from "./lib/ts-guard-utils.mts";
|
|
|
|
/**
|
|
* Source roots scanned for unsafe messaging tmpdir usage.
|
|
*/
|
|
export const messagingTmpdirGuardSourceRoots = [
|
|
"src/channels",
|
|
"src/infra/outbound",
|
|
"src/line",
|
|
"src/media",
|
|
"src/media-understanding",
|
|
"extensions",
|
|
];
|
|
function collectOsTmpdirImports(sourceFile: ts.SourceFile) {
|
|
const osModuleSpecifiers = new Set(["node:os", "os"]);
|
|
const osNamespaceOrDefault = new Set<string>();
|
|
const namedTmpdir = new Set<string>();
|
|
for (const statement of sourceFile.statements) {
|
|
if (!ts.isImportDeclaration(statement)) {
|
|
continue;
|
|
}
|
|
if (!statement.importClause || !ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
continue;
|
|
}
|
|
if (!osModuleSpecifiers.has(statement.moduleSpecifier.text)) {
|
|
continue;
|
|
}
|
|
const clause = statement.importClause;
|
|
if (clause.name) {
|
|
osNamespaceOrDefault.add(clause.name.text);
|
|
}
|
|
if (!clause.namedBindings) {
|
|
continue;
|
|
}
|
|
if (ts.isNamespaceImport(clause.namedBindings)) {
|
|
osNamespaceOrDefault.add(clause.namedBindings.name.text);
|
|
continue;
|
|
}
|
|
for (const element of clause.namedBindings.elements) {
|
|
if ((element.propertyName?.text ?? element.name.text) === "tmpdir") {
|
|
namedTmpdir.add(element.name.text);
|
|
}
|
|
}
|
|
}
|
|
return { osNamespaceOrDefault, namedTmpdir };
|
|
}
|
|
|
|
/**
|
|
* Finds `os.tmpdir()` or imported `tmpdir()` call lines in source.
|
|
*/
|
|
export function findMessagingTmpdirCallLines(
|
|
_content: string,
|
|
_fileName: string,
|
|
sourceFile: ts.SourceFile,
|
|
): number[] {
|
|
const { osNamespaceOrDefault, namedTmpdir } = collectOsTmpdirImports(sourceFile);
|
|
return collectCallExpressionLines(sourceFile, (node) => {
|
|
const callee = unwrapExpression(node.expression);
|
|
if (
|
|
ts.isPropertyAccessExpression(callee) &&
|
|
callee.name.text === "tmpdir" &&
|
|
ts.isIdentifier(callee.expression) &&
|
|
osNamespaceOrDefault.has(callee.expression.text)
|
|
) {
|
|
return callee;
|
|
}
|
|
return ts.isIdentifier(callee) && namedTmpdir.has(callee.text) ? callee : null;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Runs the messaging tmpdir guard.
|
|
*/
|
|
export async function main() {
|
|
await runCallsiteGuard({
|
|
importMetaUrl: import.meta.url,
|
|
sourceRoots: messagingTmpdirGuardSourceRoots,
|
|
skipRelativePath: (relPath) =>
|
|
relPath.startsWith("extensions/") && classifyBundledExtensionSourcePath(relPath).isTestLike,
|
|
findCallLines: findMessagingTmpdirCallLines,
|
|
header: "Found os.tmpdir()/tmpdir() usage in messaging/channel runtime sources:",
|
|
footer:
|
|
"Use resolvePreferredOpenClawTmpDir() or plugin-sdk temp helpers instead of host tmp defaults.",
|
|
sortViolations: false,
|
|
});
|
|
}
|
|
|
|
runAsScript(import.meta.url, main);
|