Files
openclaw/scripts/check-ingress-agent-owner-context.mts
T
Peter Steinberger c70aee247e refactor(scripts): migrate JavaScript tools to TypeScript (#121005)
* refactor(scripts): migrate JavaScript tools to TypeScript

* fix(ci): keep changed-scope preflight zero-install

* fix(ci): preserve zero-install script owners

* fix(ci): complete script migration follow-through

* fix(release): keep stable closeout zero-install

* fix(scripts): preserve standalone execution boundaries

* fix(scripts): repair standalone loader boundaries

* fix(scripts): normalize gateway observation ids

* fix(scripts): keep Docker packager standalone

* test(scripts): preserve rebase cleanup helpers

* test(sessions): use tracked temp directory
2026-08-09 07:21:35 -07:00

50 lines
1.7 KiB
TypeScript

#!/usr/bin/env node
// Ensures ingress agent command callsites pass explicit owner context.
import path from "node:path";
import ts from "typescript";
import { bundledPluginFile } from "./lib/bundled-plugin-paths.mjs";
import { runCallsiteGuard } from "./lib/callsite-guard.mts";
import {
collectCallExpressionLines,
runAsScript,
unwrapExpression,
} from "./lib/ts-guard-utils.mts";
const sourceRoots = ["src/gateway", bundledPluginFile("discord", "src/voice")];
const enforcedFiles = new Set([
bundledPluginFile("discord", "src/voice/manager.ts"),
"src/gateway/openai-http.ts",
"src/gateway/openresponses-http.ts",
"src/gateway/server-methods/agent.ts",
"src/gateway/server-node-events.ts",
]);
/**
* Finds legacy `agentCommand(...)` call lines in ingress-owned source.
*/
function findLegacyAgentCommandCallLines(content: string, fileName = "source.ts") {
const sourceFile = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true);
return collectCallExpressionLines(ts, sourceFile, (node) => {
const callee = unwrapExpression(node.expression);
return ts.isIdentifier(callee) && callee.text === "agentCommand" ? callee : null;
});
}
/**
* Runs the ingress owner-context guard.
*/
async function main() {
await runCallsiteGuard({
importMetaUrl: import.meta.url,
sourceRoots,
findCallLines: findLegacyAgentCommandCallLines,
skipRelativePath: (relPath) => !enforcedFiles.has(relPath.replaceAll(path.sep, "/")),
header: "Found ingress callsites using local agentCommand() (must be explicit owner-aware):",
footer:
"Use agentCommandFromIngress(...) and pass senderIsOwner explicitly at ingress boundaries.",
});
}
runAsScript(import.meta.url, main);