@@ -56,7 +56,12 @@ import {
5656 projectNameFromRemote ,
5757 resolveProjectIdentifier ,
5858} from "@/altimate/workspace/detect"
59- import { accountDigest , readLocalBinding , recordApprovedBinding } from "@/altimate/workspace/state"
59+ import {
60+ accountDigest ,
61+ readLocalBinding ,
62+ recordApprovedBinding ,
63+ resolvePinnedBindingForRouting ,
64+ } from "@/altimate/workspace/state"
6065import {
6166 describeOffer ,
6267 installCommand ,
@@ -1215,6 +1220,8 @@ async function runFlow(api: TuiPluginApi, directory: string): Promise<void> {
12151220 // Resolved before the dialog renders — see AlreadyLinkedDialog's comment
12161221 // on why this can't be fetched async inside the dialog itself.
12171222 const manageUrl = await resolveManageUrl ( serverBinding . datamate . id )
1223+ // Same pinning as the offline branch: Attach may come long after this pre-check.
1224+ const discoveredAs = await accountDigest ( )
12181225 api . ui . dialog . replace ( ( ) => (
12191226 < AlreadyLinkedDialog
12201227 api = { api }
@@ -1225,7 +1232,26 @@ async function runFlow(api: TuiPluginApi, directory: string): Promise<void> {
12251232 hasDrift = { hasDrift }
12261233 driftedWas = { hasDrift ? boundIdent : undefined }
12271234 manageUrl = { manageUrl }
1228- onAttach = { ( ) => recordApprovedBinding ( directory , discovered ) }
1235+ onAttach = { async ( ) => {
1236+ // Re-confirm before seeding: the account or the project's link can change between the
1237+ // pre-check and the click, and the seed must go to the link that still stands.
1238+ const who = await accountDigest ( )
1239+ const live = await WorkspaceApi . getBindingForProject ( identifier ) . catch ( ( ) => undefined )
1240+ if ( who !== null && who === discoveredAs && live ?. datamate . id === discovered . datamateId ) {
1241+ await recordApprovedBinding ( directory , discovered , { account : who } )
1242+ return
1243+ }
1244+ api . ui . toast ( {
1245+ variant : "warning" ,
1246+ message :
1247+ who !== discoveredAs
1248+ ? "Your Altimate account changed while attaching, so saved memory was not sent. Try Attach again."
1249+ : live === undefined
1250+ ? "Could not confirm the link with the workspace service, so saved memory was not sent. Try Attach again once it is reachable."
1251+ : "This project is no longer linked to that workspace, so nothing was attached. Run /workspace to see its current link." ,
1252+ duration : 8_000 ,
1253+ } )
1254+ } }
12291255 />
12301256 ) )
12311257 return
@@ -1870,7 +1896,10 @@ async function runWorkspaceManage(api: TuiPluginApi, directory: string): Promise
18701896 const linked = report . binding !== null
18711897 // Resolved before render, like AlreadyLinkedDialog's: an option appearing after
18721898 // paint would shift the row under the user's cursor.
1873- const manageUrl = report . binding ? await resolveManageUrl ( report . binding . datamateId ) : null
1899+ // Under an IDE pin, skills, memory and routing follow the pinned workspace, so Open must too.
1900+ const pinned = await resolvePinnedBindingForRouting ( directory ) . catch ( ( ) => null )
1901+ const openId = pinned ?. status === "bound" ? pinned . binding . datamateId : report . binding ?. datamateId
1902+ const manageUrl = openId !== undefined ? await resolveManageUrl ( openId ) : null
18741903
18751904 api . ui . dialog . replace ( ( ) => (
18761905 < api . ui . DialogSelect
0 commit comments