Repository navigation
chore: sync public mirror from internal #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #!/usr/bin/env node | ||
| // @ts-check | ||
|
|
||
| import { spawnSync } from "node:child_process"; | ||
| import { mkdtempSync, readdirSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { | ||
| getWorkspacePackages, | ||
| loadRootPackage, | ||
| } from "./workspace-utils.js"; | ||
|
|
||
| const rootPackage = loadRootPackage(); | ||
| const bundled = Array.isArray(rootPackage.bundleDependencies) | ||
| ? rootPackage.bundleDependencies | ||
| : []; | ||
| const workspacePackages = await getWorkspacePackages(rootPackage); | ||
| const workspaceNames = new Set( | ||
| workspacePackages.map((workspacePackage) => workspacePackage.name), | ||
| ); | ||
| const bundledWorkspaceNames = bundled.filter((name) => workspaceNames.has(name)); | ||
|
|
||
| if (bundledWorkspaceNames.length === 0) { | ||
| console.log("No bundled workspace packages declared."); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| const packDir = mkdtempSync(join(tmpdir(), "maestro-packed-workspaces-")); | ||
|
|
||
| try { | ||
| const pack = spawnSync( | ||
| "npm", | ||
| ["pack", "--silent", "--pack-destination", packDir], | ||
| { | ||
| cwd: process.cwd(), | ||
| encoding: "utf-8", | ||
| stdio: ["ignore", "pipe", "pipe"], | ||
| }, | ||
| ); | ||
| if (pack.status !== 0) { | ||
| console.error("npm pack failed while checking bundled workspaces."); | ||
| if (pack.stdout) console.error(pack.stdout.trim()); | ||
| if (pack.stderr) console.error(pack.stderr.trim()); | ||
| process.exit(pack.status ?? 1); | ||
| } | ||
|
|
||
| const tarballs = readdirSync(packDir).filter((file) => file.endsWith(".tgz")); | ||
| if (tarballs.length !== 1) { | ||
| console.error( | ||
| `Expected npm pack to create one tarball, found ${tarballs.length}.`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const tarballPath = join(packDir, tarballs[0]); | ||
| const listing = spawnSync("tar", ["-tzf", tarballPath], { | ||
| encoding: "utf-8", | ||
| stdio: ["ignore", "pipe", "pipe"], | ||
| }); | ||
| if (listing.status !== 0) { | ||
| console.error(`Failed to inspect packed tarball ${tarballs[0]}.`); | ||
| if (listing.stderr) console.error(listing.stderr.trim()); | ||
| process.exit(listing.status ?? 1); | ||
| } | ||
|
|
||
| const entries = new Set(listing.stdout.split(/\r?\n/).filter(Boolean)); | ||
| const missing = bundledWorkspaceNames.filter( | ||
| (name) => !entries.has(`package/node_modules/${name}/package.json`), | ||
| ); | ||
| if (missing.length > 0) { | ||
| console.error("Packed tarball is missing bundled workspace packages:"); | ||
| for (const name of missing.sort()) { | ||
| console.error(`- ${name}`); | ||
| } | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log( | ||
| `Verified packed tarball includes bundled workspaces: ${bundledWorkspaceNames | ||
| .slice() | ||
| .sort() | ||
| .join(", ")}.`, | ||
| ); | ||
| } finally { | ||
| rmSync(packDir, { recursive: true, force: true }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -260,9 +260,6 @@ | |
| ["status", ["path", "paths", "cwd"]], | ||
| ]); | ||
|
|
||
| const GIT_SCOPED_REUSABLE_TOOL_RESULT_KEY_PREFIX = "git:"; | ||
| const RUN_SCOPED_REUSABLE_TOOL_RESULT_KEY_PREFIX = "run:"; | ||
|
|
||
| const REQUIRED_REPO_PATH_ARGUMENT_TOOLS = new Set(["read", "ls", "list"]); | ||
|
|
||
| function collectStringValues(value: unknown): string[] { | ||
|
|
@@ -308,28 +305,24 @@ | |
| } | ||
| } | ||
|
|
||
| function isToolCallIncludingIgnoredPaths(toolCall: ToolCall): boolean { | ||
| const toolName = toolCall.name.toLowerCase(); | ||
| function isStatusCallIncludingIgnored(toolCall: ToolCall): boolean { | ||
| if (toolCall.name.toLowerCase() !== "status") { | ||
| return false; | ||
| } | ||
| const args = toolCall.arguments; | ||
| if (!args || typeof args !== "object" || Array.isArray(args)) { | ||
| return false; | ||
| } | ||
| const record = args as Record<string, unknown>; | ||
| if (toolName === "status") { | ||
| return record.includeIgnored === true || record.include_ignored === true; | ||
| } | ||
| if (toolName === "search" || toolName === "parallel_ripgrep") { | ||
| return record.useGitIgnore === false || record.use_git_ignore === false; | ||
| } | ||
| return false; | ||
| return record.includeIgnored === true || record.include_ignored === true; | ||
| } | ||
|
Check failure on line 318 in src/agent/transport.ts
|
||
|
|
||
| function hasRepoScopedReusableArguments( | ||
| toolCall: ToolCall, | ||
| cwd: string, | ||
| ): boolean { | ||
| const toolName = toolCall.name.toLowerCase(); | ||
| if (isToolCallIncludingIgnoredPaths(toolCall)) { | ||
| if (isStatusCallIncludingIgnored(toolCall)) { | ||
| return false; | ||
| } | ||
| const argumentNames = REPO_PATH_ARGUMENTS_BY_TOOL.get(toolName) ?? []; | ||
|
|
@@ -475,26 +468,10 @@ | |
| "reusableToolResultCwd" in tools | ||
| ? tools.reusableToolResultCwd | ||
| : process.cwd(); | ||
| if (!tool || tool.annotations?.destructiveHint === true) { | ||
| return undefined; | ||
| } | ||
| if (!isReadOnlyTool(tool.name, tool.annotations, tool.source)) { | ||
| if (!tool || !isGitSnapshotReusableToolCall(tool, toolCall, cwd)) { | ||
| return undefined; | ||
| } | ||
| const toolName = tool.name.toLowerCase(); | ||
| const cacheKey = `${toolCall.name}:${stableStringify(toolCall.arguments)}`; | ||
| if (isGitSnapshotReusableToolCall(tool, toolCall, cwd)) { | ||
| return `${GIT_SCOPED_REUSABLE_TOOL_RESULT_KEY_PREFIX}${cacheKey}`; | ||
| } | ||
| if ( | ||
| tool.source !== undefined || | ||
| GIT_SNAPSHOT_REUSABLE_TOOL_NAMES.has(toolName) || | ||
| tool.annotations?.openWorldHint === true || | ||
| tool.executionLocation === "client" | ||
| ) { | ||
| return undefined; | ||
| } | ||
| return `${RUN_SCOPED_REUSABLE_TOOL_RESULT_KEY_PREFIX}${cacheKey}`; | ||
| return `${toolCall.name}:${stableStringify(toolCall.arguments)}`; | ||
| } | ||
|
|
||
| function isReadOnlyToolCallForCacheInvalidation( | ||
|
|
@@ -638,43 +615,6 @@ | |
| cacheGeneration.value += 1; | ||
| } | ||
|
|
||
| function clearRunScopedReusableToolResultState( | ||
| cache: Map<string, ReusableToolResultEntry>, | ||
| pending: Map<string, Promise<ToolExecutionOutcome>>, | ||
| policyCheckedKeys: Set<string>, | ||
| pendingSafetyChecks: Map<string, number>, | ||
| cacheGeneration: ReusableToolResultCacheGeneration, | ||
| ): void { | ||
| let cleared = false; | ||
| for (const key of cache.keys()) { | ||
| if (key.startsWith(RUN_SCOPED_REUSABLE_TOOL_RESULT_KEY_PREFIX)) { | ||
| cache.delete(key); | ||
| cleared = true; | ||
| } | ||
| } | ||
| for (const key of pending.keys()) { | ||
| if (key.startsWith(RUN_SCOPED_REUSABLE_TOOL_RESULT_KEY_PREFIX)) { | ||
| pending.delete(key); | ||
| cleared = true; | ||
| } | ||
| } | ||
| for (const key of policyCheckedKeys) { | ||
| if (key.startsWith(RUN_SCOPED_REUSABLE_TOOL_RESULT_KEY_PREFIX)) { | ||
| policyCheckedKeys.delete(key); | ||
| cleared = true; | ||
| } | ||
| } | ||
| for (const key of pendingSafetyChecks.keys()) { | ||
| if (key.startsWith(RUN_SCOPED_REUSABLE_TOOL_RESULT_KEY_PREFIX)) { | ||
| pendingSafetyChecks.delete(key); | ||
| cleared = true; | ||
| } | ||
| } | ||
| if (cleared) { | ||
| cacheGeneration.value += 1; | ||
| } | ||
| } | ||
|
|
||
| function invalidateReusableToolResultsAfterMutation( | ||
| toolCall: ToolCall, | ||
| tools: ToolDefinitionLookup | ToolMetadataCache, | ||
|
|
@@ -1180,13 +1120,6 @@ | |
| this.pendingReusableToolSafetyChecks; | ||
| const reusableToolResultCacheGeneration = | ||
| this.reusableToolResultCacheGeneration; | ||
| clearRunScopedReusableToolResultState( | ||
| reusableToolResults, | ||
| pendingReusableToolResults, | ||
| policyCheckedReusableToolResultKeys, | ||
| pendingReusableToolSafetyChecks, | ||
| reusableToolResultCacheGeneration, | ||
| ); | ||
| const pendingDynamicToolExecutions: PendingExecution[] = []; | ||
| const platformToolExecutionBridge = resolvePlatformToolExecutionBridge( | ||
| this.options.platformToolExecutionBridge, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactor now treats only
statuscalls as “ignored-path” reads, sosearch/parallel_ripgrepwithuseGitIgnore: falsecan be cached as git-snapshot-reusable. That is unsafe because the snapshot key incomputeReusableToolResultSnapshotis based on git-tracked state plus untracked non-ignored files (git status --untracked-files=allandls-files --exclude-standard), so edits under gitignored paths do not change the snapshot. In practice, repeatedsearchcalls that intentionally include ignored files can return stale cached results across turns.Useful? React with 👍 / 👎.