clawdbot-13a: migrate bundled session store callers

This commit is contained in:
Josh Lehman
2026-06-01 08:10:21 -07:00
parent 5caa1dbc82
commit 7975bc06ac
11 changed files with 299 additions and 105 deletions

View File

@@ -18,6 +18,11 @@ const legacyReaderNames = new Set([
"readSessionStoreReadOnly",
"resolveSessionStoreEntry",
]);
const legacyWholeStoreAccessNames = new Set([
...legacyReaderNames,
"saveSessionStore",
"updateSessionStore",
]);
export const migratedSessionAccessorFiles = new Set([
"src/commands/export-trajectory.ts",
@@ -36,10 +41,27 @@ export const migratedSessionAccessorFiles = new Set([
"src/infra/outbound/message-action-tts.ts",
]);
export const migratedBundledPluginSessionAccessorFiles = new Set([
"extensions/discord/src/monitor/native-command-model-picker-apply.ts",
"extensions/discord/src/monitor/thread-session-close.ts",
"extensions/telegram/src/bot-handlers.runtime.ts",
]);
function normalizeRelativePath(filePath) {
return filePath.replaceAll(path.sep, "/");
}
function legacyNamesForFile(fileName) {
const normalized = normalizeRelativePath(fileName);
if (
fileName === "source.ts" ||
[...migratedBundledPluginSessionAccessorFiles].some((filePath) => normalized.endsWith(filePath))
) {
return legacyWholeStoreAccessNames;
}
return legacyReaderNames;
}
function propertyAccessName(expression) {
const unwrapped = unwrapExpression(expression);
if (ts.isIdentifier(unwrapped)) {
@@ -66,6 +88,7 @@ function bindingName(node) {
export function findSessionAccessorBoundaryViolations(content, fileName = "source.ts") {
const sourceFile = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true);
const legacyNames = legacyNamesForFile(fileName);
const violations = [];
const visit = (node) => {
@@ -74,10 +97,10 @@ export function findSessionAccessorBoundaryViolations(content, fileName = "sourc
if (namedBindings && ts.isNamedImports(namedBindings)) {
for (const specifier of namedBindings.elements) {
const importedName = specifier.propertyName?.text ?? specifier.name.text;
if (legacyReaderNames.has(importedName)) {
if (legacyNames.has(importedName)) {
violations.push({
line: toLine(sourceFile, specifier),
reason: `imports legacy session store reader "${importedName}"`,
reason: `imports legacy session store access "${importedName}"`,
});
}
}
@@ -86,29 +109,29 @@ export function findSessionAccessorBoundaryViolations(content, fileName = "sourc
if (ts.isBindingElement(node)) {
const name = bindingName(node);
if (name && legacyReaderNames.has(name)) {
if (name && legacyNames.has(name)) {
violations.push({
line: toLine(sourceFile, node),
reason: `aliases legacy session store reader "${name}"`,
reason: `aliases legacy session store access "${name}"`,
});
}
}
if (ts.isPropertyAccessExpression(node) && legacyReaderNames.has(node.name.text)) {
if (ts.isPropertyAccessExpression(node) && legacyNames.has(node.name.text)) {
violations.push({
line: toLine(sourceFile, node.name),
reason: `references legacy session store reader "${node.name.text}"`,
reason: `references legacy session store access "${node.name.text}"`,
});
}
if (
ts.isElementAccessExpression(node) &&
ts.isStringLiteral(node.argumentExpression) &&
legacyReaderNames.has(node.argumentExpression.text)
legacyNames.has(node.argumentExpression.text)
) {
violations.push({
line: toLine(sourceFile, node.argumentExpression),
reason: `references legacy session store reader "${node.argumentExpression.text}"`,
reason: `references legacy session store access "${node.argumentExpression.text}"`,
});
}
@@ -116,12 +139,12 @@ export function findSessionAccessorBoundaryViolations(content, fileName = "sourc
const calleeName = propertyAccessName(node.expression);
if (
calleeName &&
legacyReaderNames.has(calleeName) &&
legacyNames.has(calleeName) &&
ts.isIdentifier(unwrapExpression(node.expression))
) {
violations.push({
line: toLine(sourceFile, node.expression),
reason: `calls legacy session store reader "${calleeName}"`,
reason: `calls legacy session store access "${calleeName}"`,
});
}
}
@@ -136,6 +159,8 @@ export function findSessionAccessorBoundaryViolations(content, fileName = "sourc
export async function main() {
const repoRoot = resolveRepoRoot(import.meta.url);
const sourceRoots = resolveSourceRoots(repoRoot, [
"extensions/discord/src/monitor",
"extensions/telegram/src",
"src/commands",
"src/config/sessions",
"src/cron",
@@ -145,8 +170,13 @@ export async function main() {
const violations = await collectFileViolations({
repoRoot,
sourceRoots,
skipFile: (filePath) =>
!migratedSessionAccessorFiles.has(normalizeRelativePath(path.relative(repoRoot, filePath))),
skipFile: (filePath) => {
const relativePath = normalizeRelativePath(path.relative(repoRoot, filePath));
return (
!migratedSessionAccessorFiles.has(relativePath) &&
!migratedBundledPluginSessionAccessorFiles.has(relativePath)
);
},
findViolations: findSessionAccessorBoundaryViolations,
});
@@ -155,12 +185,12 @@ export async function main() {
return;
}
console.error("Found legacy session store reader usage in session-accessor migrated files:");
console.error("Found legacy session store access usage in session-accessor migrated files:");
for (const violation of violations) {
console.error(`- ${violation.path}:${violation.line}: ${violation.reason}`);
}
console.error(
"Use src/config/sessions/session-accessor.ts helpers for migrated read/projection paths. Expand this ratchet only after a slice migrates more files.",
"Use src/config/sessions/session-accessor.ts helpers for migrated paths. Expand this ratchet only after a slice migrates more files.",
);
process.exit(1);
}