Skip to content

Peter/357 extend ai workflows from the active document to the entire project - #422

Merged
petertzy merged 12 commits into
mainfrom
peter/357-extend-ai-workflows-from-the-active-document-to-the-entire-project
Oct 17, 2026
Merged

petertzy merged 12 commits into
mainfrom
peter/357-extend-ai-workflows-from-the-active-document-to-the-entire-project

Conversation

@petertzy

@petertzy petertzy commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Context

This task #357 is simply too large for one person to handle, especially given how important it is to the project's future development.

I would prefer all contributors with review permissions to collaborate on reviewing, refining, and improving the implementation, rather than leaving the entire responsibility to me. Otherwise, completing the task could take far too long.

Once the core concepts and essential functionality have been implemented, I believe we should merge the work into the main branch so that more contributors can get involved in further improving the features, user interface, and layout.

Instead of continuing to refine everything within a small group, I think opening up the development process to the broader community at an earlier stage would lead to better results. Keeping the work within our small group for too long may not be the most effective approach.

Summary

This PR extends the AI Work panel from a single active document to project-level workflows and introduces a project-oriented editor workspace.

  • Add an Explorer for opened project folders, including nested directories, duplicate-tab prevention, collapsible navigation, and automatic refresh after saving files.
  • Add project-level AI Work support with project discovery, on-demand file reads, multi-file change proposals, per-file diff review, and stale-result protection.
  • Make Markdown import the default file and folder workflow:
    • Open File converts compatible input formats to Markdown.
    • Open Folder recursively imports supported project files as Markdown.
    • Existing Markdown and text files retain their original paths and open in a clean state.
    • Converted files open as unsaved Markdown documents and use the normal save flow to choose an output path.
  • Keep Preview, AI, and Cite as mutually exclusive right-side panels.
  • Use an even editor/Preview split.
  • Remove the legacy editor/Preview display controls.
  • Preserve the existing application window size when opening projects.

Validation

  • npx tsc --noEmit
  • npm run lint
  • npm test
  • npm run build -- --webpack

…orkflows-from-the-active-document-to-the-entire-project

# Conflicts:
#	frontend/src/app/page.tsx

@karaaslanz karaaslanz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head 05cd48bbcc13634300e92479db449aa7b0b03756 for the new project Work task lifecycle. Two independently reproducible state-safety issues need fixing before merge:

1. Old project A proposal remains applicable under project B. frontend/src/hooks/useProjectWork.ts:52-60 validates the old task ID and checks editor tab snapshots, but never checks that task.root === projectRoot nor invalidates tasks on project changes. useProjectWorkspace.ts:7-24 changes projectRoot without clearing the existing proposal. Repro: obtain a reviewable proposal under project A; switch to project B without editing the current tabs; click Accept changes into editor. The proposal from A gets staged under the B UI. editor.applyProjectChanges receives A's old file_path and the backend validation does not check the active project.

2. Cancelled A can replace the newer B task state. useProjectWork.ts:21-32 shares one mutable cancelled boolean across runs. Starting B resets it to false. If an old A startProjectWork or stepProjectWork resolves afterwards, the A continuation at lines 39-44 can overwrite taskId.current and setTask for B. Repro: start A with a pending promise; discard A; start/finish B; resolve A. UI then displays task A in project B.

Exact-source verification: fetched useProjectWork.ts blob 29d20f1a39cf6455f6acc5149ebc5c04ef5dd1cc and project-work-guard.mjs blob 0ceef5a4b98b95eed45e5c02e69d6fe521fad66c at head 05cd48bb, stripped TypeScript with Node 24 and executed the actual hook with deterministic mock React hooks and controlled AI responses. Both bugs reproduced. This was a source-backed isolated hook harness, not a full browser/integration suite; no project files were altered.

Narrow fix/tests: discard/invalidate existing tasks when projectRoot changes; reject apply when task.root differs from the current root even after the async validate; use per-run generation IDs (checked after every awaited start/step/validate) rather than a shared cancellation boolean. Add tests for A?B with unchanged editor tabs and for late A resolution after B starts.

These are task-safety invariants, not a request to redesign #357.

@petertzy

Copy link
Copy Markdown
Owner Author

Thanks for your detailed review.
I've fixed both Project Work state-safety issues by invalidating tasks when switching projects, verifying project roots before and after async validation, and using per-run generation tokens to prevent outdated responses from overwriting newer tasks. I've also added regression tests for both scenarios.
Additionally, I've fixed similar issues affecting document-level translations and AI chat suggestions, ensuring that switching tabs invalidates pending requests and prevents outdated results from being applied.
I look forward to further feedback from others in our group and hope we can merge this PR into main by Saturday, so that more contributors from the broader community can get involved in improving it.

@karaaslanz karaaslanz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up to my CHANGES_REQUESTED review on prior head 05cd48bb. I independently examined the actual updated useProjectWork hook and project-work-guard.mjs at exact head ffeca0f257f71a619d4baaec91e6495b47dcc5a5 (pinned source blob SHAs d8e1b669fa463814e12a211bcb60f488507d1957 and b072a76ab449934529126994a90bb35bb565526e). The two previous project-task lifecycle findings appear resolved.

I exercised the real updated hook (TypeScript-stripped using Node 24) with deterministic mocked React hooks and controlled AI promises. 4/4 isolated scenarios PASS:

  1. A stale project A proposal cannot stage modifications after switching to B;
  2. A late cancelled project A response is discarded without overwriting B's task;
  3. a project switch while asynchronous validation is pending prevents late staging;
  4. a same-project proposal successfully stages exactly once.

The new root checks, invalidation on project change, and generation tokens protect the requested lifecycle. The exact-head upstream CI also reports success. This approves the corrections to my two original findings, not an independent review of every other file in this large PR. The 4 cases are source-backed isolated hook simulations, not a full browser/backend integration run.

@praghnyau praghnyau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Dark mode text is unreadable in the new Work panels

Several components added in this PR, including ProjectExplorer.tsx and ProjectWorkReview.tsx, use dark-mode background classes without corresponding dark-mode text colors. Since the root <body> in layout.tsx defines text-gray-900, the text inherits a near-black color when no explicit text color is set.

As a result, file names, folder names, review summaries, file paths, and diff previews become difficult or impossible to read against dark backgrounds. The Work scope label and dropdown in AIPanel.tsx have the same issue.

Could we add appropriate dark:text-gray-200 or dark:text-white classes to these elements, and ensure the diff preview and dropdown text remain readable in dark mode?

@petertzy

Copy link
Copy Markdown
Owner Author

Implemented dark-mode contrast fixes for the new project workspace and AI Work UI. Explorer entries, Project Work summaries, paths, diff previews, and the AI Work scope selector now use readable foreground and background colors in dark mode.

@petertzy
petertzy merged commit d09cb22 into main Oct 17, 2026
2 checks passed
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.

Extend AI Workflows from the Active Document to the Entire Project

3 participants