@@ -101,6 +101,8 @@ export interface Manifest {
101101interface RemoteSummary {
102102 publicId : string
103103 updatedAt : string
104+ /** Display name, for the sync-state change list. Optional: sync never depends on it. */
105+ name ?: string
104106}
105107
106108/** ``CustomSkillDetail.files`` — ``CustomSkillFileMeta`` is ``{path, size}``. */
@@ -244,6 +246,39 @@ export function describeSyncProblems(result: SyncResult): { title: string; messa
244246 return { title : `${ n } workspace skill${ n === 1 ? "" : "s" } skipped` , message : lines . join ( "\n" ) }
245247}
246248
249+ // altimate_change start — workspace sync state
250+ /** Record this run in the workspace sync state. `rows` is the list the published snapshot
251+ * describes, or null when the run left the snapshot as it was — the items are then
252+ * unknown to this run and the previous record stands. Imported lazily: the state module
253+ * reaches the bus, which this module must not load on the opted-out path. */
254+ async function recordSyncState (
255+ directory : string ,
256+ datamateId : number ,
257+ result : SyncResult ,
258+ rows : RemoteSummary [ ] | null ,
259+ dropped : Set < string > ,
260+ ) : Promise < void > {
261+ const problem = describeSyncProblems ( result )
262+ const items = rows
263+ ? Object . fromEntries (
264+ rows
265+ . filter ( ( row ) => ! dropped . has ( row . publicId ) )
266+ . map ( ( row ) => [ row . publicId , { label : displayId ( row . name ?? row . publicId ) , version : row . updatedAt } ] ) ,
267+ )
268+ : undefined
269+ try {
270+ const SyncState = await import ( "./sync-state" )
271+ await SyncState . record ( directory , datamateId , "skills" , {
272+ ...( items ? { items } : { } ) ,
273+ ...( problem ? { error : `${ problem . title } : ${ problem . message . split ( "\n" ) . join ( "; " ) } ` } : { } ) ,
274+ } )
275+ } catch ( err ) {
276+ // Status metadata: never the reason a sync fails.
277+ log . warn ( "could not record the skill sync state" , { err : String ( err ) } )
278+ }
279+ }
280+ // altimate_change end
281+
247282/** A fixed, user-facing reason for a skill that failed to sync. The raw error
248283 * can carry request URLs, server text or local paths — diagnostics for the
249284 * log, not for a toast. */
@@ -746,10 +781,14 @@ function parsePage(
746781 const rows : RemoteSummary [ ] = [ ]
747782 for ( const row of p . items ) {
748783 if ( ! row || typeof row !== "object" ) return null
749- const r = row as { public_id ?: unknown ; updated_at ?: unknown }
784+ const r = row as { public_id ?: unknown ; updated_at ?: unknown ; name ?: unknown }
750785 if ( typeof r . public_id !== "string" || ! r . public_id ) return null
751786 if ( typeof r . updated_at !== "string" || ! r . updated_at ) return null
752- rows . push ( { publicId : r . public_id , updatedAt : r . updated_at } )
787+ rows . push ( {
788+ publicId : r . public_id ,
789+ updatedAt : r . updated_at ,
790+ ...( typeof r . name === "string" && r . name ? { name : r . name } : { } ) ,
791+ } )
753792 }
754793 return { rows, pages : rawPages , total }
755794}
@@ -1109,6 +1148,15 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
11091148 // Set once the workspace's list has actually been read. Only then has this
11101149 // project been "checked", and only then should the poll interval start.
11111150 let sawRemote = false
1151+ // altimate_change start — workspace sync state
1152+ // What the sync-state record needs: the workspace checked, the list it read, the skills
1153+ // that list named but this run could not install (and had no previous copy of), and
1154+ // whether the run left a snapshot describing that list.
1155+ let checkedDatamateId : number | undefined
1156+ let remoteRows : RemoteSummary [ ] | null = null
1157+ const dropped = new Set < string > ( )
1158+ let published = false
1159+ // altimate_change end
11121160 const run = ( async ( ) => {
11131161 // Checked BEFORE the binding: `resolveBinding` needs credentials too, so a
11141162 // disconnected client would otherwise return on a null binding and never
@@ -1212,6 +1260,7 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
12121260 return
12131261 }
12141262 const binding = outcome . binding
1263+ checkedDatamateId = binding . datamateId
12151264
12161265 // Refuse to touch a directory we did not create. Everything below either
12171266 // deletes this tree or replaces it wholesale, so without this a user's own
@@ -1279,6 +1328,7 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
12791328 return
12801329 }
12811330 sawRemote = true
1331+ remoteRows = remote
12821332 syncedFor . set ( canon , accountKeyOf ( creds . altimateInstanceName , creds . altimateUrl , account ) )
12831333 // The workspace has skills now, even if installing them fails below.
12841334 if ( remote . length > 0 ) await clearEmptyRecordFor ( canon , currentEmptyKey )
@@ -1289,6 +1339,7 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
12891339 // live by then — another process can swap a partial snapshot in
12901340 // between, and the marker would vouch for a sync this run never made.
12911341 validated = manifest
1342+ published = true
12921343 return
12931344 }
12941345
@@ -1302,6 +1353,7 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
13021353 if ( written && ( after ?. status !== "bound" || after . binding . datamateId !== binding . datamateId ) )
13031354 await withdrawEmptyRecord ( canon , written )
13041355 changed = true
1356+ published = true
13051357 log . info ( "workspace has no custom skills; removed the local snapshot" )
13061358 return
13071359 }
@@ -1354,6 +1406,7 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
13541406 failed = true
13551407 log . warn ( "skipping a workspace skill with an unusable id" , { skill : summary . publicId } )
13561408 skippedSkills . push ( { skill : displayId ( summary . publicId ) , reason : "its id is not usable as a folder name" } )
1409+ dropped . add ( summary . publicId )
13571410 continue
13581411 }
13591412 try {
@@ -1435,6 +1488,7 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
14351488 }
14361489 if ( ! carried ) {
14371490 await fs . rm ( path . join ( staging , summary . publicId ) , { recursive : true , force : true } ) . catch ( ( ) => { } )
1491+ dropped . add ( summary . publicId )
14381492 }
14391493 log . warn ( "skipping a workspace skill; the rest of the snapshot still publishes" , {
14401494 skill : summary . publicId ,
@@ -1516,6 +1570,7 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
15161570 await fs . rm ( retired , { recursive : true , force : true } ) . catch ( ( ) => { } )
15171571 await clearEmptyRecordFor ( canon , currentEmptyKey )
15181572 changed = true
1573+ published = true
15191574 log . info ( "workspace skills synced" , {
15201575 datamateId : binding . datamateId ,
15211576 skills : remote . length ,
@@ -1566,7 +1621,11 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
15661621 // too — otherwise a problem it fixed would stay latched, and its return
15671622 // would never be announced.
15681623 if ( skippedSkills . length === 0 && ! syncError ) store . announced . delete ( canon )
1569- return { changed, skipped : skippedSkills , error : syncError }
1624+ const result : SyncResult = { changed, skipped : skippedSkills , error : syncError }
1625+ // altimate_change start — workspace sync state
1626+ if ( checkedDatamateId !== undefined ) await recordSyncState ( canon , checkedDatamateId , result , published ? remoteRows : null , dropped )
1627+ // altimate_change end
1628+ return result
15701629 } ) ( )
15711630 inFlight . set ( canon , settled )
15721631 try {
0 commit comments