@@ -386,68 +386,78 @@ export namespace SessionPrompt {
386386 }
387387 }
388388 } else {
389- try {
390- const skillSync = await import ( "../altimate/workspace/skill-sync" )
391- const dir = Instance . directory
392- const refreshRegistry = ( ) => refreshSkillRegistry ( dir )
393-
394- // A sync that ran elsewhere — a bind, most commonly — changes the
395- // snapshot with no instance context to refresh from. Pick that up before
396- // deciding whether this turn needs to poll at all.
397- await refreshRegistry ( )
398-
399- if ( ! ( await skillSync . recentlySynced ( dir ) ) ) {
400- const applied = skillSync . syncSkills ( dir ) . then ( async ( result ) => {
401- // Its own catch: a failed refresh must not take the warning with it.
402- // After an account switch the next re-sync can be a poll interval
403- // away, so the problem would otherwise go unsaid for minutes.
404- await refreshRegistry ( ) . catch ( ( err ) =>
405- log . warn ( "workspace skill registry refresh failed" , { err : String ( err ) } ) ,
406- )
407- // A skill that silently fails to arrive looks exactly like a
408- // workspace with no skills. Say which, and why. Imported only when
409- // there is something to show, keeping the common path free of it.
410- const problem = skillSync . describeSyncProblems ( result )
411- if ( problem && skillSync . shouldAnnounce ( dir , problem ) ) {
412- // Latched before delivery so concurrent turns joining this run do
413- // not both warn; released if nothing was shown, so a later turn
414- // tries again instead of the problem staying silent for good.
415- let shown = false
416- try {
417- const { isHeadless } = await import ( "../altimate/workspace/engine-seams" )
418- const { notify, printLine } = await import ( "../altimate/workspace/engine-probes" )
419- if ( isHeadless ( ) ) {
420- // `altimate-code run` has no toast renderer; the engine reports
421- // the same way. One line: printLine strips newlines.
422- printLine ( `${ problem . title } : ${ problem . message . split ( "\n" ) . join ( "; " ) } ` )
423- shown = true
424- } else {
425- shown = await notify ( { ...problem , variant : "warning" } )
389+ // Workspaces are on by default, so this branch runs on every user's turn. Awaiting it puts
390+ // event-loop ticks (and up to WORKSPACE_SKILL_WAIT_MS) before `createUserMessage` — the
391+ // reordering described above. Only a project that already has a workspace snapshot can have
392+ // skills to land on this turn, so only that case waits; everyone else starts the sync in the
393+ // background and keeps the synchronous path. A link found by that background sync shows its
394+ // skills from the next turn.
395+ const workspaceSkillTurn = async ( ) => {
396+ try {
397+ const skillSync = await import ( "../altimate/workspace/skill-sync" )
398+ const dir = Instance . directory
399+ const refreshRegistry = ( ) => refreshSkillRegistry ( dir )
400+
401+ // A sync that ran elsewhere — a bind, most commonly — changes the
402+ // snapshot with no instance context to refresh from. Pick that up before
403+ // deciding whether this turn needs to poll at all.
404+ await refreshRegistry ( )
405+
406+ if ( ! ( await skillSync . recentlySynced ( dir ) ) ) {
407+ const applied = skillSync . syncSkills ( dir ) . then ( async ( result ) => {
408+ // Its own catch: a failed refresh must not take the warning with it.
409+ // After an account switch the next re-sync can be a poll interval
410+ // away, so the problem would otherwise go unsaid for minutes.
411+ await refreshRegistry ( ) . catch ( ( err ) =>
412+ log . warn ( "workspace skill registry refresh failed" , { err : String ( err ) } ) ,
413+ )
414+ // A skill that silently fails to arrive looks exactly like a
415+ // workspace with no skills. Say which, and why. Imported only when
416+ // there is something to show, keeping the common path free of it.
417+ const problem = skillSync . describeSyncProblems ( result )
418+ if ( problem && skillSync . shouldAnnounce ( dir , problem ) ) {
419+ // Latched before delivery so concurrent turns joining this run do
420+ // not both warn; released if nothing was shown, so a later turn
421+ // tries again instead of the problem staying silent for good.
422+ let shown = false
423+ try {
424+ const { isHeadless } = await import ( "../altimate/workspace/engine-seams" )
425+ const { notify, printLine } = await import ( "../altimate/workspace/engine-probes" )
426+ if ( isHeadless ( ) ) {
427+ // `altimate-code run` has no toast renderer; the engine reports
428+ // the same way. One line: printLine strips newlines.
429+ printLine ( `${ problem . title } : ${ problem . message . split ( "\n" ) . join ( "; " ) } ` )
430+ shown = true
431+ } else {
432+ shown = await notify ( { ...problem , variant : "warning" } )
433+ }
434+ } finally {
435+ if ( ! shown ) skillSync . forgetAnnouncement ( dir , problem )
426436 }
427- } finally {
428- if ( ! shown ) skillSync . forgetAnnouncement ( dir , problem )
429437 }
438+ } )
439+ applied . catch ( ( err ) => log . warn ( "workspace skill sync failed" , { err : String ( err ) } ) )
440+ // Timer cleared when the sync wins the race: an armed timer keeps the
441+ // event loop alive, so a short-lived `run` would linger for the rest
442+ // of the bound, once per turn.
443+ let timer : ReturnType < typeof setTimeout > | undefined
444+ try {
445+ await Promise . race ( [
446+ applied ,
447+ new Promise ( ( r ) => {
448+ timer = setTimeout ( r , WORKSPACE_SKILL_WAIT_MS )
449+ } ) ,
450+ ] )
451+ } finally {
452+ if ( timer ) clearTimeout ( timer )
430453 }
431- } )
432- applied . catch ( ( err ) => log . warn ( "workspace skill sync failed" , { err : String ( err ) } ) )
433- // Timer cleared when the sync wins the race: an armed timer keeps the
434- // event loop alive, so a short-lived `run` would linger for the rest
435- // of the bound, once per turn.
436- let timer : ReturnType < typeof setTimeout > | undefined
437- try {
438- await Promise . race ( [
439- applied ,
440- new Promise ( ( r ) => {
441- timer = setTimeout ( r , WORKSPACE_SKILL_WAIT_MS )
442- } ) ,
443- ] )
444- } finally {
445- if ( timer ) clearTimeout ( timer )
446454 }
455+ } catch ( err ) {
456+ log . warn ( "workspace skill sync failed" , { err : String ( err ) } )
447457 }
448- } catch ( err ) {
449- log . warn ( "workspace skill sync failed" , { err : String ( err ) } )
450458 }
459+ if ( existsSync ( path . join ( Instance . directory , ".altimate-code" , "skill" , "_workspace" ) ) ) await workspaceSkillTurn ( )
460+ else void workspaceSkillTurn ( )
451461 }
452462 // altimate_change end
453463
0 commit comments