Skip to content

🌳 feat: List Attached Workspace Trees - #15527

Merged
danny-avila merged 8 commits into
devfrom
danny-avila/code-workspace-list
Sep 4, 2026
Merged

danny-avila merged 8 commits into
devfrom
danny-avila/code-workspace-list

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

Summary

I added model-facing file discovery for attached code environments so an agent can begin in an existing project, Git repository, or empty directory and learn the available workspace paths before reading them. This PR is stacked on #15525 and depends on LibreChat-AI/code-interpreter#92.

  • Register list_workspace_files only when the selected code environment is attached.
  • Route bounded listing requests through the authenticated principal-selected Code API worker.
  • Validate strict response shapes, unique portable paths, result limits, and requested-subtree confinement before returning data to the model.
  • Apply configured file-name filters to every returned path before emitting any listing.
  • Forward the run abort signal through LibreChat and the Code API request so Stop cancels in-flight discovery.
  • Preserve the tool name in historical agent contexts for durable conversation replay.

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • Ran 218 focused @librechat/api tests covering handlers, tool registration, and the workspace HTTP client.
  • Ran 144 focused backend tests covering Code API request wiring and stable agent dependencies.
  • Ran import sorting, diff validation, and changed-file TypeScript checks.
  • Ran a live LibreChat handler → Code API → Redis lease → outbound @librechat/code worker test against a plain non-Git directory; the model-facing result was workspace/src/app.ts.

Test Configuration:

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • Any changes dependent on mine have been merged and published in downstream modules.

@danny-avila
danny-avila force-pushed the danny-avila/code-workspace-list branch from 566ea90 to 3585e1f Compare September 2, 2026 19:16
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review\n\nPlease review the current PR head 3585e1fe95a75cda035c2ec37ca2ea3b22e5dc95. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-04T14:48:23.467400Z 77c01e6 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3585e1fe95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/code/workspace.ts Outdated
Comment thread packages/api/src/agents/tools.ts
@danny-avila
danny-avila force-pushed the danny-avila/code-workspace-list branch from 3585e1f to 9fec91f Compare September 2, 2026 19:31
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review\n\nPlease review the current PR head 9fec91f35d1568f1062447041f04f6ea6de1119b. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 9fec91f35d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
danny-avila force-pushed the danny-avila/code-workspace-list branch from 9fec91f to ccd4c34 Compare September 2, 2026 19:37
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review\n\nPlease review the current PR head ccd4c34. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

https://github.com/danny-avila/LibreChat/blob/ccd4c344ef08cd7de571d21f8a145a67ebc7dada/api/server/services/ToolService.js#L2004-L2006
P1 Badge Treat workspace listings as code-execution requests

When list_workspace_files is the only call in a tool batch, this detector remains false because it recognizes only search_workspace. The agents controller passes a defined actionsEnabled boolean, so loadToolsForExecution then skips capability resolution, sets codeExecutionEnabled/statefulCodeSessions to false, and constructs the default code context; handleWorkspaceListCall consequently rejects the call because environmentType is no longer attached. Include the listing tool in this routing check, as is already done for workspace search.


https://github.com/danny-avila/LibreChat/blob/ccd4c344ef08cd7de571d21f8a145a67ebc7dada/packages/api/src/agents/handlers.ts#L2351
P2 Badge Prefix search matches with the workspace namespace

When the model follows a search_workspace match by passing the returned path to read_file, this output supplies src/app.ts even though attached files are routed only when the path starts with workspace/. The unprefixed path instead enters skill/sandbox resolution and commonly fails to read the matched file. Emit workspace/${match.path} here, matching handleWorkspaceListCall, so search results are directly usable by the advertised reader.


https://github.com/danny-avila/LibreChat/blob/ccd4c344ef08cd7de571d21f8a145a67ebc7dada/packages/api/src/code/workspace.ts#L175-L177
P1 Badge Preserve cancellation while reading response bodies

If the run is aborted after the worker has returned headers but while reader.read() is still waiting for body data, the stream rejects with an abort error here and this catch converts it to WorkspaceToolHttpError('invalid'). The outer cancellation check and all three workspace handlers can then no longer recognize the abort, so they return an ordinary tool error and the canceled agent run may continue. Preserve abort errors from the body reader just as executeWorkspaceTool already preserves aborts raised during fetchImpl.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review\n\nPlease review the current PR head ccd4c34. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: ccd4c344ef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila changed the title 🧭 feat: Discover Attached Workspace Files 🌳 feat: List Attached Workspace Trees Sep 3, 2026
Copilot AI lite review requested due to automatic review settings September 3, 2026 13:44
@danny-avila

Copy link
Copy Markdown
Collaborator Author

Resolved the stack conflict and all three latest findings at current head 6b0c843: standalone list_workspace_files now participates in attached code-route resolution; search results use workspace/ paths; response-body cancellation is preserved from the lower layer. Listing output is additionally UTF-8 byte-bounded without partial paths. Focused verification: 335 package tests and 115 ToolService tests pass.\n\n@codex review commit 6b0c843

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

executeWorkspaceTool request validation currently rejects dot-segment paths like ./src, which contradicts the new tests and prevents intended attached-workspace usage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR adds a new model-facing discovery tool, list_workspace_files, to safely enumerate relative file paths inside attached code workspaces. It extends the existing attached-workspace HTTP bridge to support a list_files operation, ensures results are bounded/filterable, and wires the tool through agent registration/handler plumbing (including cancellation forwarding) and legacy /api service integration.

Changes:

  • Add a list_files workspace-tool request/response shape with strict validation, subtree confinement, and result limits.
  • Register list_workspace_files only when workspace tools are enabled for attached environments, and route calls through the principal-selected Code API worker with abort forwarding.
  • Add/extend tests across the TypeScript and legacy JS layers to cover tool registration, handler behavior, filtering, and routing.
File summaries
File Description
packages/api/src/code/workspace.ts Adds list_files protocol support and strengthens result validation (including subtree checks).
packages/api/src/code/workspace.spec.ts Adds tests for dot-segment request paths and bounded file listing validation.
packages/api/src/agents/tools.ts Introduces the list_workspace_files tool definition and registers it alongside other attached-workspace tools.
packages/api/src/agents/tools.spec.ts Verifies historical tool-name retention and tool registration/shape for list_workspace_files.
packages/api/src/agents/handlers.ts Implements list_workspace_files execution, filtering, truncation, and cancellation forwarding.
packages/api/src/agents/handlers.spec.ts Adds handler tests for routing, truncation without partial paths, and filename filtering behavior.
packages/api/src/agents/background.ts Ensures the new tool is excluded from background execution.
packages/api/src/agents/background.spec.ts Tests that list_workspace_files stays in the foreground even if requested in background.
api/server/services/ToolService.js Treats workspace listing as a code-execution tool for attached routing/capability gating.
api/server/services/Files/Code/process.js Adds the legacy-layer listWorkspaceFiles implementation that calls executeWorkspaceTool.
api/server/services/Files/Code/process.spec.js Tests authenticated forwarding and correct worker routing/headers for listings.
api/server/services/Endpoints/agents/skillDeps.js Exposes listWorkspaceFiles in agent skill deps for handler wiring.
api/server/services/Endpoints/agents/skillDeps.spec.js Verifies the dependency is present and forwarded through the deps object.
api/server/services/Endpoints/agents/initialize.spec.js Updates expected tool-name sets to include list_workspace_files.
api/server/services/tests/ToolService.spec.js Adds a regression test ensuring attached routing is preserved when listing is the only requested tool.
Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/api/src/code/workspace.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b0c843ac3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/code/workspace.ts
Comment thread packages/api/src/agents/handlers.ts Outdated
Comment thread packages/api/src/agents/handlers.ts Outdated
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 6df5914. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6df5914f97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/code/workspace.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 6df5914. The earlier request did not receive an acknowledgement. Confirm this exact commit is reviewed, focusing on canonical path validation, line-delimited filename safety, truncation boundaries, and the inherited operation allowlist.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6df5914f97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/agents/handlers.ts Outdated
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head f90ad2c. This head depends on LibreChat-AI/code-interpreter#106 for the matching list continuation protocol.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: f90ad2c116

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Base automatically changed from danny-avila/code-workspace-search to dev September 4, 2026 14:07
@danny-avila
danny-avila force-pushed the danny-avila/code-workspace-list branch from 565df56 to 65a52d2 Compare September 4, 2026 14:25
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the current PR head 77c01e6ed606547f96d61c6a56b1a607c2227609. Confirm that this exact commit is the reviewed commit and ignore findings that apply only to earlier heads.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 77c01e6ed6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
danny-avila force-pushed the danny-avila/code-workspace-list branch from 77c01e6 to 03cc788 Compare September 4, 2026 14:52
@danny-avila
danny-avila merged commit e23e13e into dev Sep 4, 2026
7 checks passed
@danny-avila
danny-avila deleted the danny-avila/code-workspace-list branch September 4, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants