Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/agent/query-index/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class QueryIndexStore {
try {
ensureQueryIndexSchema(db);
db.pragma("journal_mode = WAL");
db.pragma("synchronous = NORMAL");
db.pragma("foreign_keys = ON");
} catch (error) {
db.close();
Expand Down
5 changes: 3 additions & 2 deletions src/agent/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,17 +974,18 @@
relation: "anchor",
}));

while (queue.length) {
const current = queue.shift()!;
let queueHead = 0;
while (queueHead < queue.length) {
const current = queue[queueHead++];
const existing = reachable.get(current.file);

Check failure on line 980 in src/agent/search.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

'current' is possibly 'undefined'.
if (existing && existing.distance <= current.distance) continue;

Check failure on line 981 in src/agent/search.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

'current' is possibly 'undefined'.
reachable.set(current.file, current);

Check failure on line 982 in src/agent/search.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

Argument of type 'ReachableFile | undefined' is not assignable to parameter of type 'ReachableFile'.

Check failure on line 982 in src/agent/search.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

'current' is possibly 'undefined'.
if (current.distance >= depth) continue;

Check failure on line 983 in src/agent/search.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

'current' is possibly 'undefined'.

for (const neighbor of fileNeighborIndex.get(current.file) ?? []) {

Check failure on line 985 in src/agent/search.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

'current' is possibly 'undefined'.
queue.push({
file: neighbor.file,
distance: current.distance + 1,

Check failure on line 988 in src/agent/search.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

'current' is possibly 'undefined'.
relation: neighbor.relation,
});
}
Expand Down
29 changes: 12 additions & 17 deletions src/indexer/build-cache/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ import {
import { assertFilePathWithinRoot, fileIdentityKey, isFilePathWithinRoot } from "../../util/paths.js";
import { getGitBlobHashes } from "../../util/git.js";
import { stringifyUnknown } from "../../util/ast.js";
import {
cacheAbsolutePath,
cacheRelativePath,
cacheRoot,
fileSignature,
} from "./module-cache.js";
import { cacheAbsolutePath, cacheRelativePath, cacheRoot, fileSignature } from "./module-cache.js";
import type { BuildOptions } from "../types.js";
import type { ManifestBuildOptions } from "./options.js";

Expand All @@ -39,19 +34,17 @@ export async function collectWorkspaceManifestDependencyEdges(
allowedManifestFiles?: ReadonlySet<string>,
logLevel?: LogLevel,
): Promise<Edge[]> {
const manifestPaths = await listProjectFiles(projectRoot, ["**/package.json"], {
...discovery,
...(logLevel ? { logLevel } : {}),
});
const scopedManifestPaths = allowedManifestFiles
? manifestPaths.filter((manifestPath) => allowedManifestFiles.has(manifestPath))
: manifestPaths;
if (!scopedManifestPaths.length) return [];

const manifestPaths = allowedManifestFiles
? [...allowedManifestFiles].filter((manifestPath) => path.basename(manifestPath) === "package.json")
: await listProjectFiles(projectRoot, ["**/package.json"], {
...discovery,
...(logLevel ? { logLevel } : {}),
});
if (!manifestPaths.length) return [];
const manifestByPackageName = new Map<string, string>();
const parsedByPath = new Map<string, PackageJsonDependencyInfo>();

for (const manifestPath of scopedManifestPaths) {
for (const manifestPath of manifestPaths) {
try {
const raw = await fsp.readFile(manifestPath, "utf8");
const parsed = JSON.parse(raw) as PackageJsonDependencyInfo;
Expand Down Expand Up @@ -133,7 +126,9 @@ export function transformManifestEntries(
edge.to.type === "file"
? {
...edge.to,
path: toRelative ? cacheRelativePath(projectRoot, edge.to.path) : cacheAbsolutePath(projectRoot, edge.to.path),
path: toRelative
? cacheRelativePath(projectRoot, edge.to.path)
: cacheAbsolutePath(projectRoot, edge.to.path),
}
: edge.to,
})),
Expand Down
5 changes: 4 additions & 1 deletion src/indexer/build-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,12 @@
opts: BuildOptions | undefined;
gitSigMap: Map<string, string>;
cacheEnabled: boolean;
needsContentHash: boolean;
concurrency: number;
}): Promise<Map<string, FileSignature>> {
const entries = await mapLimit(args.files, args.concurrency, async (file) => {
const gitSig = args.gitSigMap.get(file);
const sigInfo = await fileSignature(file, args.opts?.cacheStrict, gitSig, {
const sigInfo = await fileSignature(file, args.needsContentHash ? args.opts?.cacheStrict : false, gitSig, {
forceContentHash: args.cacheEnabled && !gitSig,
});
return [file, sigInfo] as const;
Expand Down Expand Up @@ -658,6 +659,7 @@
opts,
gitSigMap,
cacheEnabled,
needsContentHash: true,
concurrency: conc,
});
const sqlCorpusSig = sqlCorpusSignature(sqlFiles, fileSignatures);
Expand Down Expand Up @@ -1432,6 +1434,7 @@
opts,
gitSigMap,
cacheEnabled,
needsContentHash: cacheEnabled || useManifest || opts?.cacheStrict === true,

Check failure on line 1437 in src/indexer/build-index.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

Cannot find name 'useManifest'. Did you mean 'manifest'?
concurrency: conc,
});
const modules = new Map<FileId, ModuleIndex>();
Expand Down
48 changes: 35 additions & 13 deletions src/util/projectFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
onlyFiles?: boolean;
markDirectories?: boolean;
knownSymlinkDirectories?: readonly string[];
resolvedSafeSymlinkDirectories?: readonly string[];
onSymlinkDirectoriesDiscovered?: (directories: readonly string[]) => void;
};

Expand Down Expand Up @@ -335,6 +336,13 @@
picomatch(globPattern, { dot: true }),
);
const patternMatchers = patterns.map((pattern) => picomatch(normalizeGlobPattern(pattern), { dot: true }));
const projectFileDefinitionMatchers = PROJECT_FILE_DEFINITIONS.map((definition) =>
definition.patterns.map((pattern) =>
pattern.includes("*") || pattern.includes("?")
? new RegExp("^" + pattern.replace(/\./g, "\\.").replace(/\*/g, ".*") + "$")
: undefined,
),
);
const translatedUserIgnoreGlobs = translateGlobRootIgnoreGlobsForScanRoot(root, globRoot, userIgnoreGlobs);
const fastGlobIgnoreGlobs = [...DEFAULT_PROJECT_FILE_IGNORES, ...translatedUserIgnoreGlobs];

Expand Down Expand Up @@ -365,25 +373,33 @@
ignore: translatedUserIgnoreGlobs,
})
: [];
const linkedFiles = await listEntriesFromSafeSymlinkDirectories(root, realRoot, patterns, fastGlobIgnoreGlobs, {
const symlinkOptions = {
globRoot,
filterIgnoreGlobs: [...DEFAULT_PROJECT_FILE_IGNORES, ...userIgnoreGlobs],
...(options?.knownSymlinkDirectories !== undefined
? { knownSymlinkDirectories: options.knownSymlinkDirectories }
: {}),
...(options?.onSymlinkDirectoriesDiscovered
? { onSymlinkDirectoriesDiscovered: options.onSymlinkDirectoriesDiscovered }
: {}),
};
const safeSymlinkDirectories = await resolveSafeSymlinkDirectories(
root,
realRoot,
fastGlobIgnoreGlobs,
symlinkOptions,
);
const linkedFiles = await listEntriesFromSafeSymlinkDirectories(root, realRoot, patterns, fastGlobIgnoreGlobs, {
...symlinkOptions,
filterIgnoreGlobs: [...DEFAULT_PROJECT_FILE_IGNORES, ...userIgnoreGlobs],
resolvedSafeSymlinkDirectories: safeSymlinkDirectories,
});
const linkedOverrideFiles =
includeGlobs.length === 0
? []
: await listEntriesFromSafeSymlinkDirectories(root, realRoot, patterns, translatedUserIgnoreGlobs, {
globRoot,
filterIgnoreGlobs: userIgnoreGlobs,
...(options?.knownSymlinkDirectories !== undefined
? { knownSymlinkDirectories: options.knownSymlinkDirectories }
: {}),
resolvedSafeSymlinkDirectories: safeSymlinkDirectories,
});
const rootSafeFiles = await filterRealPathsWithinRootEntries(
[...files, ...includedOverrideFiles, ...linkedFiles, ...linkedOverrideFiles],
Expand Down Expand Up @@ -537,11 +553,12 @@
.filter(Boolean)
.map((globPattern) => picomatch(globPattern, { dot: true }));
const locationIndependentIgnores = ignore.map(normalizeGlobPattern).filter(isLocationIndependentGlob);
const safeSymlinkDirectories = await resolveSafeSymlinkDirectories(root, realRoot, ignore, options);
const safeSymlinkDirectories =
options.resolvedSafeSymlinkDirectories ?? (await resolveSafeSymlinkDirectories(root, realRoot, ignore, options));
if (!safeSymlinkDirectories.length) return [];
const filesByPath = new Map<string, string>();
const filesByDirectory = await mapLimitSemaphore(
safeSymlinkDirectories,

Check failure on line 561 in src/util/projectFiles.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

Argument of type 'readonly string[]' is not assignable to parameter of type 'string[]'.
REALPATH_FILTER_CONCURRENCY,
async (directory) =>
(
Expand All @@ -560,7 +577,7 @@
}),
);
for (const files of filesByDirectory) {
for (const file of files) {

Check failure on line 580 in src/util/projectFiles.ts

View workflow job for this annotation

GitHub Actions / build-and-test-windows

'files' is of type 'unknown'.
filesByPath.set(normalizePath(file), file);
}
}
Expand Down Expand Up @@ -659,22 +676,27 @@
realRoot,
);

const projectFileDefinitionMatchers = PROJECT_FILE_DEFINITIONS.map((definition) =>
definition.patterns.map((pattern) =>
pattern.includes("*") || pattern.includes("?")
? new RegExp("^" + pattern.replace(/\./g, "\\.").replace(/\*/g, ".*") + "$")
: undefined,
),
);
const entries: ProjectFileInfo[] = [];
const matchTasks = rootSafeMatches.map(async (cleanMatch) => {
const stats = await fsp.stat(cleanMatch);
const isDir = stats.isDirectory();
const fileName = path.basename(cleanMatch);

for (const def of PROJECT_FILE_DEFINITIONS) {
for (let definitionIndex = 0; definitionIndex < PROJECT_FILE_DEFINITIONS.length; definitionIndex++) {
const def = PROJECT_FILE_DEFINITIONS[definitionIndex];
if (isDir && def.kind !== "dir") continue;
if (!isDir && def.kind !== "file") continue;

const matchesPattern = def.patterns.some((p) => {
if (p.includes("*") || p.includes("?")) {
const re = new RegExp("^" + p.replace(/\./g, "\\.").replace(/\*/g, ".*") + "$");
return re.test(fileName);
}
return p === fileName;
const matchesPattern = def.patterns.some((pattern, patternIndex) => {
const matcher = projectFileDefinitionMatchers[definitionIndex][patternIndex];
return matcher ? matcher.test(fileName) : pattern === fileName;
});

if (matchesPattern) {
Expand Down
Loading