diff --git a/FORK.md b/FORK.md index 72555b2960605..9a461f9af419b 100644 --- a/FORK.md +++ b/FORK.md @@ -76,7 +76,7 @@ These files exist upstream, but J5 owns its copy outright and they are not integ ### Sanctioned appended integration cases -Against upstream pin `70d60e03a7a35c6fa131825bbfa05ec893e69912`, the inventory has 85 entries: 1–84 plus 15b. Sixteen are retired and keep their numbers (10–14, 15b, 16–18, 20, 27–29, 54, 55, 61), and 19 and 39 are retired except for a remainder. Existing numbers never change; a new case takes the next number. Line coordinates and landing SHAs below describe historical integrations; use named symbols and tests after upstream movement. Branding has its own inventory in `BRANDING.md`; temporary defect patches are listed separately below. +Against upstream pin `70d60e03a7a35c6fa131825bbfa05ec893e69912`, the inventory has 86 entries: 1–85 plus 15b. Sixteen are retired and keep their numbers (10–14, 15b, 16–18, 20, 27–29, 54, 55, 61), and 19 and 39 are retired except for a remainder. Existing numbers never change; a new case takes the next number. Line coordinates and landing SHAs below describe historical integrations; use named symbols and tests after upstream movement. Branding has its own inventory in `BRANDING.md`; temporary defect patches are listed separately below. 1. A1's independent communication-ledger migration lane: in `apps/server/src/persistence/Sqlite.ts`, `layerSetup` runs `runJ5CompatibleUpstreamMigrations` and then `runJ5A2AMigrations` where upstream calls `runMigrations()`, before upstream's `PRAGMA optimize`. Upstream's `layerConfig` has already run `initializeV2Database`, which copies `state.sqlite` to `statev2.sqlite`, so both run only against `statev2.sqlite`. J5 adopts that copy-on-first-start unchanged (Jackson's 2026-09-24 decision #2): an existing `statev2.sqlite` wins and `state.sqlite` is never recopied or written again, so the cutover is one-way: writes after the first V2 boot are invisible to an older binary. Snapshot before the upgrade, and roll back across it by stopping writers and moving `statev2.sqlite` aside (`docs/j5/runbooks/dogfood-runtime.md`); never run old and new binaries against the two files. `layerFromPath` calls one J5 step, `snapshotBeforeMigrations` (`apps/server/src/j5/persistence/MigrationSnapshot.ts`), before it builds the SQL layer, so every file-backed open is covered. When the database has migration history and either lane has a migration pending (upstream's `effect_sql_migrations` against upstream's manifest, or `j5_a2a_migrations` against J5's ledger list), it is first copied with `VACUUM INTO`, through a read-only connection, to `statev2.pre-migration-u-j.sqlite` beside it, named for the newest migration each lane had recorded. The copy is synchronous and does not use `node:sqlite`'s `backup()`: on the Node 26 that release executables embed, `backup()` rejects the one-step rate Node 24 accepts and its promise settles only when another event wakes the loop, which stopped the first nightly from starting. The snapshot is a compacted copy in rollback-journal mode; the server sets WAL again when it opens a restored one. A database with no history, or with nothing pending, is not copied. The newest three snapshots are kept (`MIGRATION_SNAPSHOTS_KEPT`) and older ones deleted. This is the roll-forward policy's emergency exit (issue #507): J5 adds no refusal to start on a database newer than the build, as upstream adds none for that case. Upstream refuses only a history that would skip one of V2's own migrations (`assertV2MigrationsCanRun` in `Migrations.ts`), and a second server on the same home (`apps/server/src/serverOwnership.ts`, exit 78), whose lock `layerMakeServer` takes before anything opens the database, so before the snapshot. A failed copy dies there, so the server does not start and nothing migrates. It dies rather than fails so the layer's error type, which upstream's tests name, stays upstream's. `MigrationSnapshot.test.ts` covers it. The `j5_run_observability_migrations` lane (one index) is not consulted. J5 tooling (`fleet-load.ts`, `devDeliverySeed.ts`, `dogfood-snapshot.sh`, `dogfood-local.sh`) targets `statev2.sqlite`; `apps/server/src/j5/persistence/StateV2Cutover.test.ts` covers the copy, no-recopy and failed-first-boot retry. Case 31 defines the compatibility wrapper; J5's own migration IDs remain in separate tracking tables and run after upstream migration completion. Upstream's `Sqlite.test.ts` test "collects planner statistics for an existing database on open" asserts the row count of the statistic only: with J5's tables in the database, `PRAGMA optimize`'s analysis limit makes the per-value estimate approximate (`1000 96` where upstream expects `1000 100`). 2. The authenticated J5 MCP registration seam: the `layer` of `apps/server/src/mcp/McpHttpServer.ts` calls `layerJ5Toolkits(toolkitRegistration)` (`apps/server/src/j5/a2a/mcp/registration.ts`) in place of upstream's orchestrator, thread, attachment, project and environment registrations. Upstream's preview, preview-controls, worktree, pull-request, device and html toolkits are registered whole, as upstream registers them. Upstream's lint rule `no-raw-mcp-registration` allows MCP registration only in `McpHttpServer.ts`, so J5 registers through the `toolkitRegistration` function that file passes in. `layerJ5Toolkits` registers J5's own tools and the admitted part of those five upstream toolkits. `upstreamCatalog.ts` selects the admitted tools one by one and runs them on upstream's own handlers through `handlersFor`, which is one documented cast. Upstream's `McpServer.toolkit` asks for every tool's declared dependencies at registration, so J5's environment toolkit registration (`registration.ts`) provides `ThreadCommandExecutor.layer`, as upstream's own does. `apps/server/src/mcp/McpInvocationContext.ts` exports `ALL_MCP_CAPABILITIES` and adds the `artifacts` capability that case 33's tools check; nothing imports the export at pin `70d60e03a7`. @@ -451,6 +451,20 @@ migrations after upstream migrations. 84. An agent's steer waits for a Claude turn's running tool calls (register D4, Bryant 2026-10-22). Upstream's `steerTurn` in `apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts` offers every steer with SDK priority `"now"`, which cancels running tool calls. J5-owned leaf `apps/server/src/j5/a2a/claudeAgentSteers.ts` sends a steer that isn't a person's with `"next"` instead: Claude Code lets the tool calls finish and adds the message at the next tool result. A person's steer keeps `"now"` and upstream's capability flags. A late steer can still be queued at the first result, so the leaf follows its `command_lifecycle` frames and holds a clean completion until the turn consuming the steer returns its result. Folded commands share that result. Failed results are never held; upstream handles a person's aborting steer itself. A CLI that reports no lifecycle frames never holds a turn, and a later native turn follows upstream's wake-turn path. Tracking uses a `Map` by provider turn and a `WeakSet` of queries reporting lifecycle. `SilenceDetector` releases tracked steers when a run ends without a clean SDK result, before its membership gate. It sends no unread-after-Stop notice; that design is deferred to #694. The adapter carries four hooks: the leaf import; `j5ObserveClaudeSteer` at the top of `handleSdkMessage`; `j5ClaudeSteerHoldsResult` beside upstream's `isClaudeActiveSteeringAbortResult` in the steered-result branch, where held usage joins `steeredSegmentUsage`; and `j5ClaudeSteerFields` plus `j5OfferClaudeSteer` around the offer in `steerTurn`. J5 delivery's `peerSteeringRun` selects running Claude turns by driver (case 26). Tests: `j5/a2a/claudeAgentSteers.test.ts` covers priority, lifecycle tracking, failed offers and cleanup; `j5/a2a/claudeAgentSteers.integration.test.ts` exercises the real adapter and orchestrator with a scripted SDK stream for mid-tool delivery, a late steer sharing one billed provider turn, Stop while held, and a person's `"now"` steer; `j5/a2a/SilenceDetector.test.ts` checks terminal cleanup without an unread notice. The hold relies on the `@internal` `command_lifecycle` contract of the user's own, unpinned `claude` binary (`provider/Drivers/ClaudeExecutable.ts`), not just the SDK version. For a fresh uuid user message, the assumptions are that the CLI emits `queued`, then consumption or cancellation frames, and a result for the consuming turn; J5 and upstream do not withdraw that queued message, and Stop closes the query. Check those assumptions at Claude Code upgrades as well as upstream advances, including cancellation sources and the four hooks. A steer racing Stop can still run a tool before the process closes (retired D5). Retire this case when upstream delivers agent steers without cancelling tools. If upstream #21158 lands, check that its capability guard does not turn J5's Claude peer steers back into queued turns. +85. Upstream's doors to a new thread, a fork and a new project follow the person's level, as do a thread's branch controls ([#640](https://github.com/Jacksondr5/j5code/issues/640), [#641](https://github.com/Jacksondr5/j5code/issues/641), register D33, Jackson's 2026-10-25 approval of one J5 check beside each upstream check). Upstream offers a new thread or a fork to every connection, a read-only one included, as local navigation (`threadActionRequiresOperate` leaves "New thread on " to it), and decides Add project and branch changes by server-wide permissions, which a device holds at its person's highest level anywhere (case 70). So a Viewer, a Viewer of one thread who writes to another, and a Collaborator on one thread were offered doors the server refuses: a thread or a fork needs the project, and a project needs a level at server scope (case 78's `NARROWED_COMMAND_SCOPES`). The rule is J5-owned `sharingAllowsStart` in `packages/client-runtime/src/j5/sharing.ts`: a thread or a fork takes the project's level (`projectLevelFor`), a project of its own a level at server scope, and a level on one thread starts nothing. The web reads it in `apps/web/src/j5/sharing/access.ts` through `useCanStartIn` (one function over every project, for lists), `useCanStartInAny` (one boolean for a row or a button, which renders again only when that answer changes), `useCanAddProject` and `useCanForkThread`; outside a render through `readCanStartThreadIn` in `startAccess.ts`, which imports nothing at runtime so upstream's new-thread helpers can load it without the connection runtime; and, for grouped projects, through `startableProjects.ts`: `startableProjectPicker` keeps only a group's checkouts that can take a thread before upstream's `buildSidebarProjectPickerEntries` picks one, `readStartableProjectRef` reads its first pick at click time, and `startableMemberRef` and `openableFromSearch` answer for a project picked from search. A server that has not answered withholds nothing. Each control is hidden or disabled as that surface already does for what a connection lacks: + + - `apps/web/src/components/Sidebar.tsx`: adds `useCanStartInAny` to its existing `access.ts` import and calls it over `projects`; the header's `newThreadDisabled` reads it, where it read `projects.length === 0`. It imports `readStartableProjectRef`: when `handleNewThreadClick`'s single-group shortcut is refused by `startNewThreadFromContext`, a click without Shift starts the thread in the checkout `readStartableProjectRef(projectGroups)` returns (the filtered picker's first), so a group mixing a checkout the person cannot start in with one they can does not leave the enabled button doing nothing; Shift+click keeps upstream's contextual project. + - `apps/web/src/components/LegacySidebar.tsx`: imports `useCanStartInAny`, and `readCanStartThreadIn` from `startAccess.ts`. `SidebarProjectItem` calls `useCanStartInAny(project.memberProjects)`, and the row's hover New thread button's positioning `
` takes `hidden` when no checkout in the group can take a thread, as the rows hide the actions a connection lacks. In `handleCreateThreadClick`'s checkout chooser, and in the thread menu's "New thread on ", an item is `disabled` by `readCanStartThreadIn`, as the menu disables Rename. The newer sidebar's and the thread view's menus get "New thread on " from case 71's `withSharingMenuItems` (`sharingMenu.ts`), with no further upstream edit. + - `apps/web/src/components/CommandPalette.tsx`: imports `useCanAddProject`, `useCanStartIn`, `startableProjectPicker`, `startableMemberRef` and `openableFromSearch`, and calls `useCanStartIn` and `startableProjectPicker` after `contextualProjectRef`. "New thread in…" lists `startPicker.projects` in place of `pickerProjects` and reads its groups from `startPicker.groupByTargetKey` (search terms and the click's checkout), and it is left out when it lists nothing; "New thread in " is offered only when the contextual project can take a thread. `canCreateProject` and `canCreateClonedProject` read `useCanAddProject`, which holds upstream's "Operate tasks" too, in place of `useEnvironmentScope(…, AuthOrchestrationOperateScope)`, so the browse and clone submits are disabled with upstream's "This connection cannot add projects." The New project flow's `canSubmitNewProject`, which upstream gates on no permission, also requires `canCreateProject`, and its Create tooltip says the same. A project picked from search still opens its group's latest thread; with none, `openProjectFromSearch` creates its draft in `startableMemberRef`'s checkout (the one picked, else another of its group the person may start in) in place of the picked one, and none when no checkout can take a thread. `projectSearchItems` maps upstream's items through `openableFromSearch` over a set of the projects with an unarchived thread (`searchProjectKeysWithThreads`), so a project with no thread to open and no checkout to start one in is listed `disabled`, as upstream lists a server that is not connected. + - `apps/web/src/lib/chatThreadActions.ts`: imports `readCanStartThreadIn` from `startAccess.ts`; `startNewThreadFromContext` also returns `false` when it refuses the context's project, so the `chat.new` and `chat.newLocal` keybindings and the sidebar's Shift+click do nothing there, as upstream's keybindings do for a permission the connection lacks. + - `apps/web/src/hooks/useScratchProject.ts`: imports and calls `useCanStartIn`; `scratchEnvironmentId` offers a server only where a project can be added, so "New thread without a project", its keybinding and the other scratch doors leave out a server that refuses `projects.openScratch` to a narrowed session. + - `apps/web/src/components/chat/MessagesTimeline.tsx`: imports `useCanForkThread`; `AssistantForkButton` calls it beside `canForkProjectedAssistantItem` and returns `null` on either, as it did on the one. + - `apps/web/src/components/chat/ChatHeader.tsx`: imports `useCanStartThreadIn` and calls it with the active project; the breadcrumb's project-name button, which starts a new thread in that project, is `disabled` when the person can't start one there. + - `apps/web/src/components/BranchToolbarBranchSelector.tsx`: imports `useCanOperateThread`; `canOperateThread`, which gates only the branch change, is `useCanOperateThread(environmentId, threadId)` in place of upstream's server-wide "Operate tasks". + - `apps/web/src/components/GitActionsControl.tsx`: imports `useCanOperateThread` and adds `canOperateThisThread` beside upstream's `canOperateThread`; `canChangeThreadBranch` ("Commit on new branch" and "Check out feature branch & continue") reads it in place of `canOperateThread`. Upstream's `canOperateThread` still gates the commit dialog's Open in editor buttons. `GitActionsControl.test.ts` and `GitActionsControl.lifecycle.test.ts` mock the J5 hook as that permission (one `vi.mock` each). + + Folder actions (commit, push, pull, Open in editor) are left to upstream's permissions: the server allows them to anyone who holds Collaborator at any scope (case 69, Jackson 2026-10-17), and a Viewer everywhere does not hold them. Mobile is not covered, with the rest of sharing on mobile ([#609](https://github.com/Jacksondr5/j5code/issues/609)). Proof: `packages/client-runtime/src/j5/sharing.test.ts`, "what a connection may start"; `apps/web/src/j5/sharing/sharingMenu.test.ts`, "a new thread from the thread menu"; and `apps/web/src/j5/sharing/startableProjects.test.ts`. On a pin advance: if upstream adds a door to a new thread, a fork or a project, add the call beside it; if upstream starts gating a new thread on its own permission, keep J5's call beside upstream's; if upstream renames `newThreadDisabled`, `handleNewThreadClick`, `handleCreateThreadClick`, `startNewThreadFromContext`, `openProjectFromSearch`, `projectSearchItems`, `scratchEnvironmentId`, `canCreateProject`, `canSubmitNewProject`, `canChangeThreadBranch` or `AssistantForkButton`, or changes how `buildSidebarProjectPickerEntries` picks a group's checkout, move the call with it. + ## Pin and upstream advance runbook Current pin: `70d60e03a7a35c6fa131825bbfa05ec893e69912`, upstream's nightly tag `v0.1.1-nightly.20261017.3238` on `main` (frozen 2026-10-17). The previous pin was `29980a31409234b676f97bd477c4e46fdb61a929`, from upstream `main`. @@ -790,16 +804,16 @@ explicitly marked. | `apps/web/src/environments/primary/auth.ts` | N | 70 | | `apps/web/src/components/CommandPalette.logic.test.ts` | R | 34 | | `apps/web/src/components/CommandPalette.logic.ts` | R | 34 | -| `apps/web/src/components/CommandPalette.tsx` | A | 42, 71, 75 | +| `apps/web/src/components/CommandPalette.tsx` | A | 42, 71, 75, 85 | | `apps/web/src/components/ConfirmDialogHost.tsx` | R | 22 | -| `apps/web/src/components/LegacySidebar.tsx` | R | 21, 22 | +| `apps/web/src/components/LegacySidebar.tsx` | A | 21, 22, 85 | | `apps/web/src/components/Sidebar.logic.test.ts` | R | 21 | | `apps/web/src/components/Sidebar.logic.ts` | R | 21 | -| `apps/web/src/components/Sidebar.tsx` | A | 21–23, 71, 73 | +| `apps/web/src/components/Sidebar.tsx` | A | 21–23, 71, 73, 85 | | `apps/web/src/components/chat/ChatComposer.tsx` | A | Saved-agent mentions, Role library, 45, 49, 73 | | `apps/web/src/components/chat/MessagesTimeline.test.tsx` | N | B | | `apps/web/src/components/chat/timelineMinimapItems.ts` | A | 24 | -| `apps/web/src/components/chat/MessagesTimeline.tsx` | A | B, 7, 24, 80 | +| `apps/web/src/components/chat/MessagesTimeline.tsx` | A | B, 7, 24, 80, 85 | | `apps/web/src/components/chat/QueuedRunsControl.tsx` | A | 24, 80 | | `apps/web/src/components/sidebar/SidebarChrome.tsx` | A | 6, 33, 75, B | | `apps/web/src/onboarding/firstRun.ts` | N | 75 | @@ -808,7 +822,7 @@ explicitly marked. | `apps/web/src/contextMenuFallback.ts` | N | 71 | | `apps/web/src/hooks/useThreadActionMenu.ts` | A | 21, 69, 71 | | `apps/web/src/hooks/useThreadActionMenu.test.ts` | A | 71 | -| `apps/web/src/components/chat/ChatHeader.tsx` | N | 73 | +| `apps/web/src/components/chat/ChatHeader.tsx` | N | 73, 85 | | `apps/web/src/components/chat/ThreadDetailsPanel.tsx` | N | 73 | | `apps/web/src/components/settings/SettingsScopeSentence.tsx` | N | 72 | | `apps/web/src/components/settings/ProjectSettingsPanel.tsx` | N | 72 | @@ -820,6 +834,12 @@ explicitly marked. | `apps/web/src/routes/welcome.tsx` | N | 73 | | `apps/web/src/components/PermissionUpdateNotice.tsx` | N | 73 | | `apps/web/src/components/PermissionUpdateNotice.test.tsx` | N | 73 | +| `apps/web/src/components/GitActionsControl.tsx` | N | 85 | +| `apps/web/src/components/GitActionsControl.test.ts` | N | 85 | +| `apps/web/src/components/GitActionsControl.lifecycle.test.ts` | N | 85 | +| `apps/web/src/components/BranchToolbarBranchSelector.tsx` | N | 85 | +| `apps/web/src/lib/chatThreadActions.ts` | N | 85 | +| `apps/web/src/hooks/useScratchProject.ts` | N | 85 | | `apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx` | N | 80 | | `apps/web/src/routes/pair.tsx` | N | 73 | | `apps/web/src/routes/__root.tsx` | N | 71, 73 | diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index 5448358fefe0a..e134c5ebc0100 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -70,6 +70,7 @@ import { ComposerControl } from "./chat/ComposerControl"; import { MiddleTruncate } from "./ui/middle-truncate"; import { BranchPicker, BranchPickerRefItem } from "./BranchPicker"; import { stackedThreadToast, toastManager } from "./ui/toast"; +import { useCanOperateThread } from "../j5/sharing/access"; export interface BranchToolbarBranchSelectorHandle { open: () => void; @@ -116,7 +117,7 @@ export function BranchToolbarBranchSelector({ }: BranchToolbarBranchSelectorProps) { const composerFloatingLayerProps = useComposerMenuProps(); const canWriteSourceControl = useEnvironmentScope(environmentId, AuthSourceControlWriteScope); - const canOperateThread = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope); + const canOperateThread = useCanOperateThread(environmentId, threadId); const stopThreadSession = useAtomCommand(threadEnvironment.stopSession, "thread session stop"); const updateThreadMetadata = useAtomCommand( threadEnvironment.updateMetadata, diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsx index 99e2ca4567de1..5f2a2535773f0 100644 --- a/apps/web/src/components/CommandPalette.tsx +++ b/apps/web/src/components/CommandPalette.tsx @@ -2,6 +2,12 @@ import { useHighlightsPaletteItems } from "../j5/highlights/highlightsPalette"; import { useSharingPaletteItems } from "../j5/sharing/sharingPalette"; +import { useCanAddProject, useCanStartIn } from "../j5/sharing/access"; +import { + openableFromSearch, + startableMemberRef, + startableProjectPicker, +} from "../j5/sharing/startableProjects"; import { threadPullRequestLinkMode } from "@t3tools/client-runtime/thread-pull-request-compatibility"; import { visibleThreadPullRequests } from "@t3tools/shared/threadPullRequests"; @@ -914,6 +920,12 @@ function OpenCommandPaletteDialog(props: { defaultProjectRef, handleNewThread, }); + const canStartIn = useCanStartIn(); + const startPicker = startableProjectPicker({ + groups: projectGroups, + preferredProjectRef: contextualProjectRef, + canStartIn, + }); const projectPickerEntries = buildSidebarProjectPickerEntries({ groups: projectGroups, preferredProjectRef: contextualProjectRef, @@ -973,7 +985,7 @@ function OpenCommandPaletteDialog(props: { }) ?? null; const browseEnvironmentId = sourcePicker?.environmentId ?? addProjectEnvironmentId ?? defaultAddProjectEnvironmentId; - const canCreateProject = useEnvironmentScope(browseEnvironmentId, AuthOrchestrationOperateScope); + const canCreateProject = useCanAddProject(browseEnvironmentId); const browseEnvironment = environments.find((environment) => environment.environmentId === browseEnvironmentId) ?? null; const browseEnvironmentIsDesktopLocal = @@ -1121,6 +1133,11 @@ function OpenCommandPaletteDialog(props: { [browseNavigation], ); + const searchProjectKeysWithThreads = new Set( + threads.flatMap((thread) => + thread.archivedAt === null ? [`${thread.environmentId}:${thread.projectId}`] : [], + ), + ); const openProjectFromSearch = async (project: (typeof projects)[number]) => { const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`); const groupedProjectKeys = group @@ -1152,7 +1169,8 @@ function OpenCommandPaletteDialog(props: { return; } - await handleNewThread(scopeProjectRef(project.environmentId, project.id)); + const startRef = startableMemberRef({ project, group, canStartIn }); + if (startRef) await handleNewThread(startRef); }; const projectSearchItems = buildProjectActionItems({ @@ -1189,6 +1207,19 @@ function OpenCommandPaletteDialog(props: { }, icon: projectFaviconIcon, runProject: openProjectFromSearch, + }).map((item, index) => { + // J5: a project with no thread to open and no checkout this person may start one in is shown + // but cannot be picked, as upstream shows a server that is not connected. + const project = pickerProjects[index]; + const openable = + !project || + openableFromSearch({ + project, + group: projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`), + projectKeysWithThreads: searchProjectKeysWithThreads, + canStartIn, + }); + return openable ? item : { ...item, disabled: true }; }); const projectThreadItems = (() => { @@ -1196,10 +1227,10 @@ function OpenCommandPaletteDialog(props: { isScratchProject(project, scratchWorkspaceRootFor(project.environmentId)); const projectItems = enumerateCommandPaletteItems( buildProjectActionItems({ - projects: pickerProjects.filter((project) => !isScratch(project)), + projects: startPicker.projects.filter((project) => !isScratch(project)), valuePrefix: "new-thread-in", searchTerms: (project) => { - const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`); + const group = startPicker.groupByTargetKey.get(`${project.environmentId}:${project.id}`); const location = projectEnvironmentLocationById.get(project.environmentId); return [ ...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ?? @@ -1232,7 +1263,7 @@ function OpenCommandPaletteDialog(props: { }, icon: projectFaviconIcon, runProject: async (project) => { - const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`); + const group = startPicker.groupByTargetKey.get(`${project.environmentId}:${project.id}`); const contextualRefBelongsToGroup = contextualProjectRef !== null && group?.memberProjectRefs.some( @@ -1654,12 +1685,16 @@ function OpenCommandPaletteDialog(props: { }); const highlightsPaletteItems = useHighlightsPaletteItems(); const actionItems: Array = []; - if (projects.length > 0) { + if (projects.length > 0 && projectThreadItems.length > 0) { const activeProjectTitle = projectPickerEntries.find((entry) => entry.isPreferred)?.group.displayName ?? (currentProjectId ? (projectTitleById.get(currentProjectId) ?? null) : null); - if (activeProjectTitle) { + if ( + activeProjectTitle && + contextualProjectRef !== null && + canStartIn(contextualProjectRef.environmentId, contextualProjectRef.projectId) + ) { actionItems.push({ kind: "action", value: "action:new-thread", @@ -2395,6 +2430,7 @@ function OpenCommandPaletteDialog(props: { newProjectFlow !== null && newProjectName.length > 0 && !isCreatingNewProject && + canCreateProject && canCreateProjectInEnvironment(browseEnvironment?.connection.phase); async function submitNewProject(): Promise { @@ -2894,10 +2930,7 @@ function OpenCommandPaletteDialog(props: { addProjectCloneFlow?.environmentId ?? null, AuthSourceControlWriteScope, ); - const canCreateClonedProject = useEnvironmentScope( - addProjectCloneFlow?.environmentId ?? null, - AuthOrchestrationOperateScope, - ); + const canCreateClonedProject = useCanAddProject(addProjectCloneFlow?.environmentId ?? null); const canCloneProject = canWriteSourceControl && canCreateClonedProject; const isCloneDestinationStep = addProjectCloneFlow?.step === "confirm"; const canSubmitBrowsePath = @@ -3232,7 +3265,11 @@ function OpenCommandPaletteDialog(props: { {createShortcutLabel} - {`Create (${createShortcutLabel})`} + + {canCreateProject + ? `Create (${createShortcutLabel})` + : "This connection cannot add projects."} + ) : addProjectCloneFlow?.step === "repository" ? ( diff --git a/apps/web/src/components/GitActionsControl.lifecycle.test.ts b/apps/web/src/components/GitActionsControl.lifecycle.test.ts index 84d5b1b4271f9..2dc4e856249af 100644 --- a/apps/web/src/components/GitActionsControl.lifecycle.test.ts +++ b/apps/web/src/components/GitActionsControl.lifecycle.test.ts @@ -26,6 +26,13 @@ vi.mock("~/state/session", () => ({ readEnvironmentScope: (environmentId: unknown, scope: string) => (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope), })); +// J5 (case 73): the thread's level is J5's; these tests hold the session's permission alone. +vi.mock("~/j5/sharing/access", () => ({ + useCanOperateThread: (environmentId: unknown) => + (environmentId === "environment" ? state.scopes : state.primaryScopes).has( + "orchestration:operate", + ), +})); vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command })); vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } })); vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: { discovery: () => null } })); diff --git a/apps/web/src/components/GitActionsControl.test.ts b/apps/web/src/components/GitActionsControl.test.ts index 1865117965403..26e193d2495b8 100644 --- a/apps/web/src/components/GitActionsControl.test.ts +++ b/apps/web/src/components/GitActionsControl.test.ts @@ -46,6 +46,13 @@ vi.mock("~/state/session", () => ({ readEnvironmentScope: (environmentId: unknown, scope: string) => (environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope), })); +// J5 (case 73): the thread's level is J5's; these tests hold the session's permission alone. +vi.mock("~/j5/sharing/access", () => ({ + useCanOperateThread: (environmentId: unknown) => + (environmentId === "environment" ? state.scopes : state.primaryScopes).has( + "orchestration:operate", + ), +})); vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command })); vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } })); vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: {} })); diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx index d72fb0f7e6a93..d6a46f79421c3 100644 --- a/apps/web/src/components/GitActionsControl.tsx +++ b/apps/web/src/components/GitActionsControl.tsx @@ -99,6 +99,7 @@ import { } from "~/lib/sourceControlActions"; import { useThreadProjection, useThreadShell } from "~/state/entities"; import { readEnvironmentScope, useEnvironmentScope } from "~/state/session"; +import { useCanOperateThread } from "~/j5/sharing/access"; import { useEnvironmentQuery } from "~/state/query"; import { serverEnvironment } from "~/state/server"; import { sourceControlEnvironment } from "~/state/sourceControl"; @@ -1004,6 +1005,10 @@ export default function GitActionsControl({ AuthSourceControlWriteScope, ); const canOperateThread = useEnvironmentScope(activeEnvironmentId, AuthOrchestrationOperateScope); + const canOperateThisThread = useCanOperateThread( + activeEnvironmentId, + activeThreadRef?.threadId ?? null, + ); const serverConfig = useAtomValue(serverEnvironment.configValueAtom(activeEnvironmentId)); const openInPreferredEditor = useOpenInPreferredEditor( activeEnvironmentId, @@ -1028,7 +1033,8 @@ export default function GitActionsControl({ const activeServerThread = activeServerThreadShell ?? activeServerThreadProjection?.projection.thread ?? null; const isLocalDraftThread = activeDraftThread !== null && activeServerThread === null; - const canChangeThreadBranch = canWriteSourceControl && (isLocalDraftThread || canOperateThread); + const canChangeThreadBranch = + canWriteSourceControl && (isLocalDraftThread || canOperateThisThread); const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext); const [isCommitDialogOpen, setIsCommitDialogOpen] = useState(false); const [dialogCommitMessage, setDialogCommitMessage] = useState(""); diff --git a/apps/web/src/components/LegacySidebar.tsx b/apps/web/src/components/LegacySidebar.tsx index bdae27c5a247a..0be178730482a 100644 --- a/apps/web/src/components/LegacySidebar.tsx +++ b/apps/web/src/components/LegacySidebar.tsx @@ -127,6 +127,8 @@ import { useDesktopUpdateState } from "../state/desktopUpdate"; import { useThreadActions } from "../hooks/useThreadActions"; import { archiveWithPreflight } from "../j5/a2a/archiveFlow"; +import { useCanStartInAny } from "../j5/sharing/access"; +import { readCanStartThreadIn } from "../j5/sharing/startAccess"; import { projectEnvironment } from "../state/projects"; import { threadEnvironment, useEnvironmentThread } from "../state/threads"; import { useEnvironment, useEnvironments, usePrimaryEnvironmentId } from "../state/environments"; @@ -1174,6 +1176,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec isManualProjectSorting, dragHandleProps, } = props; + const canStartThreadHere = useCanStartInAny(project.memberProjects); const environmentMachine = project.allRemoteMembersAreWsl ? "linux" : project.allRemoteMembersAreDesktopLocal @@ -2111,6 +2114,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec project.memberProjects.map((member) => ({ id: member.physicalProjectKey, label: formatProjectMemberActionLabel(member, project.groupedProjectCount), + disabled: !readCanStartThreadIn(scopeProjectRef(member.environmentId, member.id)), })), { x: event.clientX, @@ -2328,7 +2332,15 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec const clicked = await api.contextMenu.show( [ ...(thread.branch - ? [{ id: "new-thread-on-branch", label: `New thread on ${thread.branch}` }] + ? [ + { + id: "new-thread-on-branch", + label: `New thread on ${thread.branch}`, + disabled: !readCanStartThreadIn( + scopeProjectRef(thread.environmentId, thread.projectId), + ), + }, + ] : []), { id: "rename", label: "Rename thread", disabled: !canOperateThread }, { id: "mark-unread", label: "Mark unread" }, @@ -2531,7 +2543,10 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec +