@yunhozz/arc 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/MANIFEST.sha256 +152 -155
  2. package/README.md +101 -35
  3. package/claude/agents/arc-implementer.md +7 -7
  4. package/claude/agents/arc-planner.md +5 -5
  5. package/claude/agents/arc-reviewer.md +6 -6
  6. package/claude/agents/arc-scouter.md +5 -5
  7. package/claude/agents/{arc-qa.md → arc-tester.md} +10 -10
  8. package/claude/skill/SKILL.md +7 -7
  9. package/claude/skill/models.toml +8 -8
  10. package/claude/skill/references/arc-visual-companion.md +2 -2
  11. package/claude/skill/references/commit.md +3 -3
  12. package/claude/skill/references/coordination.md +21 -25
  13. package/claude/skill/references/git-recovery.md +3 -1
  14. package/claude/skill/references/handoff-prep.md +3 -3
  15. package/claude/skill/references/handoff.md +16 -14
  16. package/claude/skill/references/limits.md +2 -2
  17. package/claude/skill/references/planning.md +12 -10
  18. package/claude/skill/references/verification.md +66 -39
  19. package/claude/skill/references/worktree-creation.md +2 -0
  20. package/claude/skill/scripts/model_config.py +25 -9
  21. package/codex/agents/arc-implementer.toml +7 -7
  22. package/codex/agents/arc-planner.toml +6 -6
  23. package/codex/agents/arc-reviewer.toml +7 -7
  24. package/codex/agents/arc-scouter.toml +6 -6
  25. package/codex/agents/{arc-qa.toml → arc-tester.toml} +10 -10
  26. package/codex/skill/SKILL.md +8 -8
  27. package/codex/skill/models.toml +8 -8
  28. package/codex/skill/references/arc-visual-companion.md +3 -3
  29. package/codex/skill/references/commit.md +4 -4
  30. package/codex/skill/references/coordination.md +20 -24
  31. package/codex/skill/references/git-recovery.md +2 -0
  32. package/codex/skill/references/handoff-prep.md +4 -4
  33. package/codex/skill/references/handoff.md +17 -15
  34. package/codex/skill/references/limits.md +2 -2
  35. package/codex/skill/references/planning.md +13 -11
  36. package/codex/skill/references/verification.md +67 -40
  37. package/codex/skill/references/worktree-creation.md +2 -0
  38. package/codex/skill/scripts/model_config.py +28 -15
  39. package/gemini/agents/arc-implementer.md +8 -8
  40. package/gemini/agents/arc-planner.md +6 -6
  41. package/gemini/agents/arc-reviewer.md +6 -6
  42. package/gemini/agents/arc-scouter.md +6 -6
  43. package/gemini/agents/{arc-qa.md → arc-tester.md} +11 -11
  44. package/gemini/skill/SKILL.md +7 -7
  45. package/gemini/skill/models.toml +7 -7
  46. package/gemini/skill/references/arc-visual-companion.md +2 -2
  47. package/gemini/skill/references/commit.md +3 -3
  48. package/gemini/skill/references/coordination.md +21 -25
  49. package/gemini/skill/references/git-recovery.md +3 -1
  50. package/gemini/skill/references/handoff-prep.md +3 -3
  51. package/gemini/skill/references/handoff.md +16 -14
  52. package/gemini/skill/references/limits.md +2 -2
  53. package/gemini/skill/references/planning.md +12 -10
  54. package/gemini/skill/references/verification.md +66 -39
  55. package/gemini/skill/references/worktree-creation.md +2 -0
  56. package/grok/agents/arc-implementer.md +7 -7
  57. package/grok/agents/arc-planner.md +5 -5
  58. package/grok/agents/arc-reviewer.md +6 -6
  59. package/grok/agents/arc-scouter.md +5 -5
  60. package/grok/agents/{arc-qa.md → arc-tester.md} +10 -10
  61. package/grok/skill/SKILL.md +7 -7
  62. package/grok/skill/models.toml +2 -2
  63. package/grok/skill/references/arc-visual-companion.md +2 -2
  64. package/grok/skill/references/commit.md +3 -3
  65. package/grok/skill/references/coordination.md +21 -25
  66. package/grok/skill/references/git-recovery.md +3 -1
  67. package/grok/skill/references/handoff-prep.md +3 -3
  68. package/grok/skill/references/handoff.md +16 -14
  69. package/grok/skill/references/limits.md +2 -2
  70. package/grok/skill/references/planning.md +12 -10
  71. package/grok/skill/references/verification.md +66 -39
  72. package/grok/skill/references/worktree-creation.md +2 -0
  73. package/lib/installer/install-mode.mjs +4 -2
  74. package/lib/installer/install.mjs +4 -3
  75. package/lib/installer/language.mjs +1 -1
  76. package/lib/installer/legacy-profiles.mjs +51 -0
  77. package/lib/installer/manifest.mjs +1 -1
  78. package/lib/installer/plan.mjs +5 -3
  79. package/lib/installer/preset.mjs +2 -2
  80. package/lib/installer/role-routing.mjs +49 -18
  81. package/lib/installer/runtime-assets.mjs +2 -5
  82. package/lib/installer/targets.mjs +4 -2
  83. package/lib/installer/transaction.mjs +35 -4
  84. package/lib/installer/uninstall.mjs +13 -10
  85. package/lib/installer/upgrade-state.mjs +13 -1
  86. package/lib/management/operations.mjs +13 -13
  87. package/lib/management/reapply.mjs +5 -3
  88. package/lib/models/config.mjs +25 -7
  89. package/lib/models/profiles.mjs +1 -1
  90. package/lib/platforms/formats/gemini-markdown.mjs +3 -3
  91. package/lib/platforms/formats/grok-markdown.mjs +3 -3
  92. package/lib/platforms/formats/markdown.mjs +2 -2
  93. package/lib/platforms/formats/toml.mjs +2 -2
  94. package/lib/policy/placement.mjs +1 -1
  95. package/lib/policy/render.mjs +3 -3
  96. package/lib/policy/role-policy.json +28 -28
  97. package/lib/prompts/agent-fragments.json +24 -24
  98. package/lib/prompts/render.mjs +9 -9
  99. package/lib/runtime/acceptance.mjs +4 -3
  100. package/lib/runtime/bootstrap.mjs +3 -1
  101. package/lib/runtime/command.mjs +27 -1
  102. package/lib/runtime/cooperative-schema.mjs +16 -5
  103. package/lib/runtime/cooperative.mjs +6 -3
  104. package/lib/runtime/evaluate.mjs +10 -7
  105. package/lib/runtime/handoff-record.mjs +58 -0
  106. package/lib/runtime/identity.mjs +10 -7
  107. package/lib/runtime/local-cli.mjs +9 -2
  108. package/lib/runtime/operations.mjs +41 -3
  109. package/lib/runtime/role-bridge-args.mjs +5 -5
  110. package/lib/runtime/role-bridge.mjs +10 -2
  111. package/lib/runtime/role-dispatch-policy.mjs +11 -6
  112. package/lib/runtime/role-dispatch-store.mjs +3 -0
  113. package/lib/runtime/role-observe.mjs +5 -5
  114. package/lib/runtime/role-routing-config.mjs +20 -6
  115. package/lib/runtime/role-routing.mjs +4 -3
  116. package/lib/runtime/schema.mjs +8 -5
  117. package/lib/runtime/scope.mjs +1 -1
  118. package/lib/runtime/store.mjs +2 -2
  119. package/lib/runtime/verification.mjs +15 -7
  120. package/lib/tui/app.mjs +36 -11
  121. package/lib/tui/interface.mjs +2 -2
  122. package/lib/tui/render.mjs +4 -2
  123. package/lib/tui/setup.mjs +1 -1
  124. package/lib/tui/terminal.mjs +5 -3
  125. package/lib/watch/brief.mjs +44 -0
  126. package/lib/watch/dispatch.mjs +44 -6
  127. package/lib/watch/index.mjs +107 -22
  128. package/lib/watch/labels.mjs +2 -1
  129. package/lib/watch/markdown.mjs +42 -9
  130. package/lib/watch/model.mjs +3 -2
  131. package/lib/watch/render.mjs +5 -4
  132. package/lib/watch/scope.mjs +125 -0
  133. package/lib/watch/watcher.mjs +149 -82
  134. package/lib/watch/worktree-menu.mjs +64 -0
  135. package/package.json +1 -1
  136. package/shared/skill/runtime/acceptance.mjs +4 -3
  137. package/shared/skill/runtime/bootstrap.mjs +3 -1
  138. package/shared/skill/runtime/command.mjs +27 -1
  139. package/shared/skill/runtime/cooperative-schema.mjs +16 -5
  140. package/shared/skill/runtime/cooperative.mjs +6 -3
  141. package/shared/skill/runtime/evaluate.mjs +10 -7
  142. package/shared/skill/runtime/handoff-record.mjs +58 -0
  143. package/shared/skill/runtime/identity.mjs +10 -7
  144. package/shared/skill/runtime/local-cli.mjs +9 -2
  145. package/shared/skill/runtime/operations.mjs +41 -3
  146. package/shared/skill/runtime/role-bridge-args.mjs +5 -5
  147. package/shared/skill/runtime/role-bridge.mjs +10 -2
  148. package/shared/skill/runtime/role-dispatch-policy.mjs +11 -6
  149. package/shared/skill/runtime/role-dispatch-store.mjs +3 -0
  150. package/shared/skill/runtime/role-observe.mjs +5 -5
  151. package/shared/skill/runtime/role-policy.json +28 -28
  152. package/shared/skill/runtime/role-routing-config.mjs +20 -6
  153. package/shared/skill/runtime/role-routing.mjs +4 -3
  154. package/shared/skill/runtime/schema.mjs +8 -5
  155. package/shared/skill/runtime/scope.mjs +1 -1
  156. package/shared/skill/runtime/store.mjs +2 -2
  157. package/shared/skill/runtime/verification.mjs +15 -7
  158. package/lib/runtime/final-verify.mjs +0 -2158
  159. package/lib/runtime/node-test-reporter.mjs +0 -81
  160. package/lib/runtime/test-results.mjs +0 -736
  161. package/lib/runtime/verify-cli.mjs +0 -60
  162. package/shared/skill/runtime/final-verify.mjs +0 -2158
  163. package/shared/skill/runtime/node-test-reporter.mjs +0 -81
  164. package/shared/skill/runtime/test-results.mjs +0 -736
  165. package/shared/skill/runtime/verify-cli.mjs +0 -60
@@ -3,7 +3,7 @@ import {inspectStandaloneProfile} from './install-mode.mjs';
3
3
  import {inspectPath,TargetConfigurationError} from './targets.mjs';
4
4
  import {loadModelConfig,withRoles,serializeModelConfig,resolveModelSettings,renderProfiles} from '../models/index.mjs';
5
5
  import {assertPlanSnapshot,applyTransaction} from './transaction.mjs';
6
- import {readModelFileVersion} from '../models/config.mjs';
6
+ import {MODEL_SCHEMA_VERSION,readModelFileVersion} from '../models/config.mjs';
7
7
  import {isDeepStrictEqual} from 'node:util';
8
8
  import {assertCatalogRoles} from '../models/catalog.mjs';
9
9
  import {validatePlanSet,renderStandaloneProfiles} from './plan.mjs';
@@ -19,7 +19,7 @@ export function buildPresetPlan({target,roles,safeFs,verifiedCatalog,payload,loa
19
19
  const profileInputs=residualPaths.length?renderStandaloneProfiles({platforms,runtimePlatforms,payload:payload??loadPayload(),target,modelConfig:next,language:parseLanguage(read(path.join(target.home,'skills/arc/settings.toml'))).language}):new Map();
20
20
  for(const entry of originalProfiles)profileInputs.set(...entry);
21
21
  const profiles=renderProfiles(profileInputs,resolveModelSettings(next,{runtimePlatforms}),{runtimePlatforms,renderProfile:installerRegistryOf({platforms}).getPlatform(target.platform).profiles.render}),specs=[];
22
- if(readModelFileVersion(originalModels)<3||!isDeepStrictEqual(config.roles,next.roles))specs.push({path:modelsPath,bytes:Buffer.from(serializeModelConfig(next,{runtimePlatforms}))});
22
+ if(readModelFileVersion(originalModels)<MODEL_SCHEMA_VERSION||!isDeepStrictEqual(config.roles,next.roles))specs.push({path:modelsPath,bytes:Buffer.from(serializeModelConfig(next,{runtimePlatforms}))});
23
23
  for(const[name,bytes]of profiles)if(originalProfiles.has(name)&&!bytes.equals(originalProfiles.get(name)))specs.push({path:path.join(target.home,'agents',name),bytes});
24
24
  return{target,roles:next.roles,snapshot,managedPaths,residualPaths,externalPaths:[],specs};
25
25
  }
@@ -13,7 +13,8 @@ import {renderProfiles,resolveModelSettings} from '../models/index.mjs';
13
13
  import {COOPERATIVE_RUNTIME_MODULES,cooperativeVersions} from '../runtime/bootstrap.mjs';
14
14
  import {acquireRoleRoutingLock} from '../runtime/role-routing.mjs';
15
15
  import {NON_TERMINAL_STATES,listLeases,readLease,writeLease} from '../runtime/role-dispatch-store.mjs';
16
- import {ROUTING_ROLES,parseRoleRoutingConfig,serializeRoleRoutingConfig,validateRoleRoutingConfig} from '../runtime/role-routing-config.mjs';
16
+ import {ROUTING_CONFIG_VERSION,ROUTING_ROLES,parseRoleRoutingConfig,serializeRoleRoutingConfig,validateRoleRoutingConfig} from '../runtime/role-routing-config.mjs';
17
+ import {inspectLegacyProfiles,legacyRole,legacyRoutingNames} from './legacy-profiles.mjs';
17
18
 
18
19
  const digest=bytes=>'sha256:'+crypto.createHash('sha256').update(bytes).digest('hex');
19
20
  const validHash=value=>typeof value==='string'&&/^sha256:[a-f0-9]{64}$/.test(value);
@@ -23,6 +24,9 @@ const profilePath=(target,role,runtimePlatforms)=>path.join(target.home,'agents'
23
24
  const markerPath=target=>path.join(target.home,'arc-role-platform-routing.prepared.json');
24
25
  const activePath=(targets,anchor)=>path.join(targets[anchor].home,'arc-role-platform-routing.json');
25
26
  const read=(safeFs,filename,snapshot)=>inspectPath(safeFs,filename,{kind:'file',read:true,snapshot});
27
+ const relativeProfile=(target,filename)=>path.relative(target.home,filename).split(path.sep).join('/');
28
+ const matchesProfile=(entry,file,relative)=>exact(entry,['path','hash'])&&entry.path===relative&&file.exists&&entry.hash===digest(file.bytes);
29
+ const hasLegacyRole=bytes=>Object.hasOwn(JSON.parse(bytes.toString('utf8')).roles,legacyRole);
26
30
 
27
31
  export const legacyAnchorPlatform = 'codex';
28
32
  // Only installers read the historical v1 order. Runtime activation stays strict.
@@ -33,7 +37,7 @@ export function parseInstalledRoutingConfig(text,{runtimePlatforms}={}){
33
37
  const historical=createPlatformRegistry([...registry.byAnchorOrder()].sort((a,b)=>Number(b.id===legacyAnchorPlatform)-Number(a.id===legacyAnchorPlatform)).map((descriptor,anchorOrder)=>({...descriptor,anchorOrder})));
34
38
  config=parseRoleRoutingConfig(text,{runtimePlatforms:historical});
35
39
  }
36
- return validateRoleRoutingConfig({...config,version:2,platforms:[...config.platforms].sort((a,b)=>registry.getPlatform(a).anchorOrder-registry.getPlatform(b).anchorOrder)},{runtimePlatforms:registry});
40
+ return validateRoleRoutingConfig({...config,version:ROUTING_CONFIG_VERSION,platforms:[...config.platforms].sort((a,b)=>registry.getPlatform(a).anchorOrder-registry.getPlatform(b).anchorOrder)},{runtimePlatforms:registry});
37
41
  }
38
42
 
39
43
  export function renameCompositeProfile(bytes,platform,role,revision,context={}){
@@ -52,16 +56,26 @@ export function prepareCompositeFiles({context,targets,config,platforms=config.p
52
56
  const previousActive=activePath(targets,previous?.anchor??anchor),previousFile=previousActive===active?activeFile:read(context.safeFs,previousActive,snapshot);
53
57
  let previousConfig=null;if(previousFile.exists)try{previousConfig=parseInstalledRoutingConfig(previousFile.bytes.toString('utf8'),{runtimePlatforms});}catch{fail('Existing composite configuration cannot be verified');}
54
58
  if(previousConfig?.revision===config.revision&&!previousFile.bytes.equals(bytes))fail('A published revision cannot be reused with different content');
55
- const markers={},existingProfiles={},desired={};
59
+ const markers={},existingProfiles={},desired={},legacyRemovals=[],legacyResiduals=[];
56
60
  for(const platform of platforms){
57
61
  const target=targets[platform],found=read(context.safeFs,markerPath(target),snapshot);let marker=null;
58
62
  if(found.exists)try{marker=JSON.parse(found.bytes.toString('utf8'));}catch{fail('Existing composite marker cannot be verified');}
59
63
  const oldRoles=marker&&marker.profiles&&typeof marker.profiles==='object'&&!Array.isArray(marker.profiles)?Object.keys(marker.profiles):[];
60
- if(marker&&(!exact(marker,['version','revision','platform','targetHome','activeConfigPath','configHash','runtime','profiles'])||marker.version!==1||typeof marker.revision!=='string'||!marker.revision||marker.platform!==platform||marker.targetHome!==target.home||marker.activeConfigPath!==previousActive||!validHash(marker.configHash)||!exact(marker.runtime,['version','hash','policyHash'])||typeof marker.runtime.version!=='string'||!marker.runtime.version||!validHash(marker.runtime.hash)||!validHash(marker.runtime.policyHash)||oldRoles.some(role=>!ROUTING_ROLES.includes(role))||previousConfig&&(marker.revision!==previousConfig.revision||marker.configHash!==digest(previousFile.bytes)||!exact(marker.profiles,ROUTING_ROLES.filter(role=>previousConfig.roles[role].platform===platform)))))fail('Existing composite marker does not match configuration');
64
+ const legacy=previousConfig?.roles.arc_tester.platform===platform&&hasLegacyRole(previousFile.bytes);
65
+ const markerRoles=ROUTING_ROLES.map(role=>legacy&&role==='arc_tester'?legacyRole:role);
66
+ if(marker&&(!exact(marker,['version','revision','platform','targetHome','activeConfigPath','configHash','runtime','profiles'])||marker.version!==1||typeof marker.revision!=='string'||!marker.revision||marker.platform!==platform||marker.targetHome!==target.home||marker.activeConfigPath!==previousActive||!validHash(marker.configHash)||!exact(marker.runtime,['version','hash','policyHash'])||typeof marker.runtime.version!=='string'||!marker.runtime.version||!validHash(marker.runtime.hash)||!validHash(marker.runtime.policyHash)||oldRoles.some(role=>!markerRoles.includes(role))||previousConfig&&(marker.revision!==previousConfig.revision||marker.configHash!==digest(previousFile.bytes)||!exact(marker.profiles,markerRoles.filter((_,index)=>previousConfig.roles[ROUTING_ROLES[index]].platform===platform)))))fail('Existing composite marker does not match configuration');
67
+ let legacyProfile;
68
+ if(legacy){
69
+ const inspected=inspectCompositeRemoval({target,safeFs:context.safeFs,activeConfigPath:previousActive,snapshot,runtimePlatforms,platforms:context.platforms,migrateLegacy:true});
70
+ if(inspected.residualPaths.length||!inspected.legacyProfile)fail('Existing composite profile does not match its marker');
71
+ legacyProfile=inspected.legacyProfile;
72
+ }
73
+ const legacyProfiles=inspectLegacyProfiles({platform,agentsDir:path.join(target.home,'agents'),mode:{profile:legacyProfile},safeFs:context.safeFs,snapshot,platforms:context.platforms});
74
+ legacyRemovals.push(...legacyProfiles.remove);legacyResiduals.push(...legacyProfiles.residual);
61
75
  markers[platform]=marker;existingProfiles[platform]={};
62
76
  for(const role of ROUTING_ROLES){
63
77
  const filename=profilePath(target,role,runtimePlatforms),file=read(context.safeFs,filename,snapshot),old=marker?.profiles?.[role];
64
- if(old&&(!exact(old,['path','hash'])||old.path!==path.relative(target.home,filename).split(path.sep).join('/')||!file.exists||old.hash!==digest(file.bytes)))fail('Existing composite profile does not match its marker');
78
+ if(old&&!matchesProfile(old,file,relativeProfile(target,filename)))fail('Existing composite profile does not match its marker');
65
79
  if(file.exists&&!old)fail('Unmanaged composite profile already exists');
66
80
  existingProfiles[platform][role]=Boolean(old);
67
81
  }
@@ -80,13 +94,15 @@ export function prepareCompositeFiles({context,targets,config,platforms=config.p
80
94
  const transitionRemovals=[],standaloneWrites=[],externalPaths=[],removed=(previous?.platforms??[]).filter(platform=>!platforms.includes(platform));
81
95
  const payload=removed.length?verifyPayload(context):null;
82
96
  for(const platform of removed){
83
- const target=targets[platform],owned=inspectCompositeRemoval({target,safeFs:context.safeFs,activeConfigPath:previousActive,snapshot,runtimePlatforms});
97
+ const target=targets[platform],owned=inspectCompositeRemoval({target,safeFs:context.safeFs,activeConfigPath:previousActive,snapshot,runtimePlatforms,platforms:context.platforms,migrateLegacy:true});
98
+ const legacy=inspectLegacyProfiles({platform,agentsDir:path.join(target.home,'agents'),mode:{profile:owned.legacyProfile},safeFs:context.safeFs,snapshot,platforms:context.platforms});
99
+ legacyRemovals.push(...legacy.remove);legacyResiduals.push(...legacy.residual);
84
100
  transitionRemovals.push(...owned.removals);residualPaths.push(...owned.residualPaths);
85
101
  const restored=restoreStandaloneSpecs({context,target,payload,snapshot});standaloneWrites.push(...restored.writes);externalPaths.push(...restored.externalPaths);residualPaths.push(...restored.residualPaths);
86
102
  }
87
103
  if(previous&&previous.anchor!==anchor)transitionRemovals.push(previousActive);
88
- const managedPaths=[...new Set([...standaloneRemovals,active,...platforms.flatMap(platform=>[markerPath(targets[platform]),...ROUTING_ROLES.map(role=>profilePath(targets[platform],role,runtimePlatforms))]),...transitionRemovals,...standaloneWrites.map(spec=>spec.path)])];
89
- return {target:targets[anchor],targets,platforms,anchor,previous,config,bytes,snapshot,managedPaths,externalPaths,desired,existingProfiles,standaloneRemovals,transitionRemovals:[...new Set(transitionRemovals)],standaloneWrites,residualPaths};
104
+ const managedPaths=[...new Set([...standaloneRemovals,...legacyRemovals,active,...platforms.flatMap(platform=>[markerPath(targets[platform]),...ROUTING_ROLES.map(role=>profilePath(targets[platform],role,runtimePlatforms))]),...transitionRemovals,...standaloneWrites.map(spec=>spec.path)])];
105
+ return {target:targets[anchor],targets,platforms,anchor,previous,config,bytes,snapshot,managedPaths,externalPaths,desired,existingProfiles,standaloneRemovals,legacyRemovals,legacyResiduals,transitionRemovals:[...new Set(transitionRemovals)],standaloneWrites,residualPaths};
90
106
  }
91
107
 
92
108
  export function readCompositeRoutingConfig(context,targets){
@@ -96,7 +112,7 @@ export function readCompositeRoutingConfig(context,targets){
96
112
  }
97
113
 
98
114
  /** Return only composite paths whose current bytes match the active marker. */
99
- export function inspectCompositeRemoval({target,safeFs,activeConfigPath,snapshot,runtimePlatforms}){
115
+ export function inspectCompositeRemoval({target,safeFs,activeConfigPath,snapshot,runtimePlatforms,platforms,migrateLegacy=false}){
100
116
  const markerFile=read(safeFs,markerPath(target),snapshot),activeFile=activeConfigPath?read(safeFs,activeConfigPath,snapshot):{exists:false},files={};
101
117
  for(const role of ROUTING_ROLES)files[role]=read(safeFs,profilePath(target,role,runtimePlatforms),snapshot);
102
118
  const existing=[...(markerFile.exists?[markerPath(target)]:[]),...ROUTING_ROLES.filter(role=>files[role].exists).map(role=>profilePath(target,role,runtimePlatforms)),...(activeFile.exists&&target.home===path.dirname(activeConfigPath)?[activeConfigPath]:[])];
@@ -104,9 +120,22 @@ export function inspectCompositeRemoval({target,safeFs,activeConfigPath,snapshot
104
120
  try{
105
121
  if(!activeFile.exists||!markerFile.exists)throw Error('Incomplete composite ownership');
106
122
  const config=parseInstalledRoutingConfig(activeFile.bytes.toString('utf8'),{runtimePlatforms}),marker=JSON.parse(markerFile.bytes.toString('utf8')),roles=ROUTING_ROLES.filter(role=>config.roles[role].platform===target.platform);
107
- if(!exact(marker,['version','revision','platform','targetHome','activeConfigPath','configHash','runtime','profiles'])||marker.version!==1||marker.revision!==config.revision||marker.platform!==target.platform||marker.targetHome!==target.home||marker.activeConfigPath!==activeConfigPath||marker.configHash!==digest(activeFile.bytes)||!exact(marker.profiles,roles))throw Error('Marker mismatch');
108
- for(const role of ROUTING_ROLES){const entry=marker.profiles[role],file=files[role],relative=path.relative(target.home,profilePath(target,role,runtimePlatforms)).split(path.sep).join('/');if(entry&&(!exact(entry,['path','hash'])||entry.path!==relative||!file.exists||entry.hash!==digest(file.bytes))||file.exists&&!entry)throw Error('Profile ownership mismatch');}
109
- return {removals:existing,residualPaths:[]};
123
+ const legacy=migrateLegacy&&roles.includes('arc_tester')&&hasLegacyRole(activeFile.bytes);
124
+ const expectedRoles=legacy?roles.map(role=>role==='arc_tester'?legacyRole:role):roles;
125
+ if(!exact(marker,['version','revision','platform','targetHome','activeConfigPath','configHash','runtime','profiles'])||marker.version!==1||marker.revision!==config.revision||marker.platform!==target.platform||marker.targetHome!==target.home||marker.activeConfigPath!==activeConfigPath||marker.configHash!==digest(activeFile.bytes)||!exact(marker.profiles,expectedRoles))throw Error('Marker mismatch');
126
+ for(const role of ROUTING_ROLES){const entry=marker.profiles[role],file=files[role],relative=relativeProfile(target,profilePath(target,role,runtimePlatforms));if(entry&&!matchesProfile(entry,file,relative)||file.exists&&!entry)throw Error('Profile ownership mismatch');}
127
+ let legacyProfile;
128
+ if(legacy){
129
+ const entry=marker.profiles[legacyRole];
130
+ const filename=legacyRoutingNames(target.platform,{platforms}).map(name=>path.join(target.home,'agents',name)).find(name=>relativeProfile(target,name)===entry?.path);
131
+ if(!filename||!exact(entry,['path','hash'])||!validHash(entry.hash))throw Error('Legacy profile marker mismatch');
132
+ const file=read(safeFs,filename,snapshot);
133
+ if(!file.exists)throw Error('Legacy profile is missing');
134
+ // This proves the slot and its recorded hash. Legacy cleanup independently
135
+ // compares the bytes before it can add a removal to a transaction.
136
+ legacyProfile={path:filename,hash:entry.hash};
137
+ }
138
+ return {removals:existing,residualPaths:[],...(legacyProfile?{legacyProfile}:{})};
110
139
  }catch{return {removals:[],residualPaths:existing};}
111
140
  }
112
141
 
@@ -187,13 +216,13 @@ export async function publishCompositeFiles({context,prepared,beforePublish}){
187
216
  markers[platform]={version:1,revision:config.revision,platform,targetHome:target.home,activeConfigPath:activePath(targets,anchor),configHash:digest(bytes),runtime:{version:versions.runtime,hash:runtimeHash,policyHash},profiles};
188
217
  }
189
218
  assertPlanSnapshot({snapshot:runtimeSnapshot},{safeFs:context.safeFs});
190
- const specs=[...(prepared.modelWrites??[]),...(prepared.standaloneRemovals??[]).map(path=>({path,remove:true})),...(prepared.transitionRemovals??[]).map(path=>({path,remove:true})),...(prepared.standaloneWrites??[])];
219
+ const specs=[...(prepared.modelWrites??[]),...(prepared.standaloneRemovals??[]).map(path=>({path,remove:true})),...(prepared.legacyRemovals??[]).map(path=>({path,remove:true})),...(prepared.transitionRemovals??[]).map(path=>({path,remove:true})),...(prepared.standaloneWrites??[])];
191
220
  for(const platform of platforms)for(const role of ROUTING_ROLES){const filename=profilePath(targets[platform],role,runtimePlatforms),content=prepared.desired[platform]?.[role];if(content)specs.push({path:filename,bytes:content});else if(prepared.existingProfiles[platform][role])specs.push({path:filename,remove:true});}
192
221
  for(const platform of platforms)specs.push({path:markerPath(targets[platform]),bytes:Buffer.from(JSON.stringify(markers[platform],null,2)+'\n')});
193
222
  specs.push({path:activePath(targets,anchor),bytes});
194
223
  const hooks={...context.hooks,fault:event=>{if(event.phase==='before-publish'&&event.path===activePath(targets,anchor))assertPlanSnapshot({snapshot:runtimeSnapshot},{safeFs:context.safeFs});context.hooks?.fault?.(event);}};
195
224
  let result;try{result=applyTransaction(prepared,{safeFs:context.safeFs,signal:context.signal,hooks,specs});}catch(error){error.activation=error.rollback==='restored'?'held':'unknown';throw error;}
196
- published=true;publication={published:true,revision:config.revision,residualPaths:[...(prepared.residualPaths??[]),...result.residualPaths],cleanupError:result.cleanupError};
225
+ published=true;publication={published:true,revision:config.revision,legacyResiduals:prepared.legacyResiduals??[],residualPaths:[...(prepared.residualPaths??[]),...(prepared.legacyResiduals??[]),...result.residualPaths],cleanupError:result.cleanupError};
197
226
  }catch(error){failure=error;failed=true;}
198
227
  const failedLocks=[];
199
228
  for(const {home,release}of releases.reverse()){let released=false;try{released=await release();}catch{}if(!released)failedLocks.push(path.join(home,'arc-role-platform-routing.lock'));}
@@ -233,12 +262,14 @@ function restoreStandaloneSpecs({context,target,payload,snapshot}){
233
262
  /** Restore standalone profiles and remove verified routing files in one transaction. */
234
263
  export function prepareCompositeDeactivation({context,targets,payload,platforms=assertVerifiedInstallMode({safeFs:context.safeFs,targets,platforms:context.platforms}).platforms,anchor=sortByAnchor(platforms,installerRegistryOf(context))[0]}){
235
264
  const snapshot=new Map();assertVerifiedInstallMode({safeFs:context.safeFs,targets,snapshot,platforms:context.platforms});
236
- const removals=[],writes=[],residualPaths=[],externalPaths=[];
265
+ const removals=[],writes=[],residualPaths=[],legacyResiduals=[],externalPaths=[];
237
266
  for(const platform of platforms){
238
- const target=targets[platform],owned=inspectCompositeRemoval({target,safeFs:context.safeFs,activeConfigPath:activePath(targets,anchor),snapshot,runtimePlatforms:context.runtimePlatforms});removals.push(...owned.removals);
267
+ const target=targets[platform],owned=inspectCompositeRemoval({target,safeFs:context.safeFs,activeConfigPath:activePath(targets,anchor),snapshot,runtimePlatforms:context.runtimePlatforms,platforms:context.platforms,migrateLegacy:true});removals.push(...owned.removals);
268
+ const legacy=inspectLegacyProfiles({platform,agentsDir:path.join(target.home,'agents'),mode:{profile:owned.legacyProfile},safeFs:context.safeFs,snapshot,platforms:context.platforms});
269
+ removals.push(...legacy.remove);legacyResiduals.push(...legacy.residual);
239
270
  const restored=restoreStandaloneSpecs({context,target,payload,snapshot});writes.push(...restored.writes);residualPaths.push(...restored.residualPaths);externalPaths.push(...restored.externalPaths);
240
271
  }
241
- return{target:targets[anchor],targets,platforms,anchor,snapshot,managedPaths:[...new Set([...removals,...writes.map(item=>item.path)])],externalPaths,removals:[...new Set(removals)],writes,residualPaths};
272
+ return{target:targets[anchor],targets,platforms,anchor,snapshot,managedPaths:[...new Set([...removals,...writes.map(item=>item.path)])],externalPaths,removals:[...new Set(removals)],writes,residualPaths,legacyResiduals};
242
273
  }
243
274
  export async function publishCompositeDeactivation({context,prepared}){
244
275
  let release,result,failure;const {anchor=sortByAnchor(prepared.platforms??installerRegistryOf(context).byAnchorOrder().map(descriptor=>descriptor.runtime.id),installerRegistryOf(context))[0]}=prepared;
@@ -246,7 +277,7 @@ export async function publishCompositeDeactivation({context,prepared}){
246
277
  release=await acquireRoleRoutingLock(prepared.targets[anchor].home);await assertNoActiveBridgeDispatch(prepared.targets[anchor].home,context.runtimePlatforms);
247
278
  assertPlanSnapshot(prepared,{safeFs:context.safeFs});assertVerifiedInstallMode({safeFs:context.safeFs,targets:prepared.targets,platforms:context.platforms});
248
279
  const applied=applyTransaction(prepared,{safeFs:context.safeFs,signal:context.signal,hooks:context.hooks,specs:[...prepared.removals.map(path=>({path,remove:true})),...prepared.writes]});
249
- result={residualPaths:[...prepared.residualPaths,...applied.residualPaths],cleanupError:applied.cleanupError};
280
+ result={legacyResiduals:prepared.legacyResiduals??[],residualPaths:[...prepared.residualPaths,...(prepared.legacyResiduals??[]),...applied.residualPaths],cleanupError:applied.cleanupError};
250
281
  }catch(error){failure=error;}
251
282
  let released=true;if(release)try{released=await release();}catch{released=false;}
252
283
  if(!released){const lockPath=path.join(prepared.targets[anchor].home,'arc-role-platform-routing.lock');failure??=new TargetConfigurationError('Composite publication lock ownership could not be verified');failure.lockReleaseFailed=true;failure.residualPaths=[...new Set([...(failure.residualPaths??[]),...(result?.residualPaths??[]),lockPath])];if(result?.cleanupError)failure.cleanupError=result.cleanupError;}
@@ -13,16 +13,15 @@ export const RUNTIME_MODULE_PATHS = Object.freeze([
13
13
  'lib/runtime/cooperative.mjs',
14
14
  'lib/runtime/evaluate.mjs',
15
15
  'lib/runtime/external.mjs',
16
- 'lib/runtime/final-verify.mjs',
17
16
  'lib/runtime/gate.mjs',
18
17
  'lib/runtime/gemini-stream.mjs',
19
18
  'lib/runtime/git-evidence.mjs',
20
19
  'lib/runtime/git-query.mjs',
21
20
  'lib/runtime/grok-sandbox.mjs',
22
21
  'lib/runtime/grok-stream.mjs',
22
+ 'lib/runtime/handoff-record.mjs',
23
23
  'lib/runtime/identity.mjs',
24
24
  'lib/runtime/local-cli.mjs',
25
- 'lib/runtime/node-test-reporter.mjs',
26
25
  'lib/runtime/operations.mjs',
27
26
  'lib/runtime/platform-registry.mjs',
28
27
  'lib/runtime/role-bridge-args.mjs',
@@ -37,7 +36,5 @@ export const RUNTIME_MODULE_PATHS = Object.freeze([
37
36
  'lib/runtime/scope.mjs',
38
37
  'lib/runtime/store.mjs',
39
38
  'lib/runtime/target-preparation.mjs',
40
- 'lib/runtime/test-results.mjs',
41
- 'lib/runtime/verification.mjs',
42
- 'lib/runtime/verify-cli.mjs'
39
+ 'lib/runtime/verification.mjs'
43
40
  ]);
@@ -1,13 +1,15 @@
1
1
  import {installerRegistryOf} from '../platforms/index.mjs';
2
2
  import {standaloneProfileFile} from '../runtime/platform-registry.mjs';
3
+ import {unknownPlatformMessage} from '../runtime/local-cli.mjs';
3
4
  import path from 'node:path';import crypto from 'node:crypto';
4
5
  import {TargetConfigurationError} from './target-errors.mjs';
5
6
  export {TargetConfigurationError} from './target-errors.mjs';
6
7
  const fail=message=>{throw new TargetConfigurationError(message);};
7
8
  export function resolveTarget(platform,{userHome,env={},cwd,platforms}={}){
8
- const descriptor=installerRegistryOf({platforms}).getPlatform(platform);if(!descriptor)fail('Target must be codex or claude');
9
+ const registry=installerRegistryOf({platforms}),descriptor=registry.getPlatform(platform);
10
+ if(!descriptor)fail(unknownPlatformMessage(platform,registry.byDisplayOrder().map(({runtime})=>runtime.id)));
9
11
  let home;try{home=descriptor.runtime.home.resolve({userHome,env,cwd});}catch(error){fail(error.message);}
10
- const profileNames=['scouter','planner','implementer','qa','reviewer'].map(role=>standaloneProfileFile(descriptor.runtime,`arc_${role}`));
12
+ const profileNames=['scouter','planner','implementer','tester','reviewer'].map(role=>standaloneProfileFile(descriptor.runtime,`arc_${role}`));
11
13
  return Object.freeze({platform,home,userHome:path.resolve(userHome),payloadPrefix:descriptor.payloadPrefix,profileNames:Object.freeze(profileNames),instructionPath:path.join(home,descriptor.instructionFile),runtimeConfigPath:path.join(home,descriptor.runtimeConfigFile),globalPaths:Object.freeze(descriptor.globalPaths.map(name=>path.join(home,name)))});
12
14
  }
13
15
  export function resolveTargets(context={}){
@@ -29,7 +29,38 @@ function assertParentNamespace(safeFs,action){
29
29
  }
30
30
  function openParent(safeFs,absolute,created){
31
31
  const components=path.dirname(absolute).split('/').filter(Boolean);let current=safeFs.openRoot('/'),prefix='';
32
- try{for(const name of components){prefix+='/'+name;let stat=exists(current,name);if(!stat){current.mkdir(name,0o700);stat=current.lstat(name);created.push(prefix);}if(typeOf(stat)!==0o040000)fail('Unsafe install parent');const next=current.openDir(name);if(!sameObjectIdentity(stat,next.stat())){next.close();fail('Install parent changed');}current.close();current=next;}return current;}catch(error){current.close();throw error;}
32
+ try{for(const name of components){
33
+ prefix+='/'+name;
34
+ let stat=exists(current,name);
35
+ if(!stat){
36
+ const parentIdentity=current.stat();
37
+ current.mkdir(name,0o700);
38
+ stat=current.lstat(name);
39
+ created.push({path:prefix,identity:stat,parentIdentity});
40
+ }
41
+ if(typeOf(stat)!==0o040000)fail('Unsafe install parent');
42
+ const next=current.openDir(name);if(!sameObjectIdentity(stat,next.stat())){next.close();fail('Install parent changed');}
43
+ current.close();current=next;
44
+ }return current;}catch(error){current.close();throw error;}
45
+ }
46
+ function cleanupCreatedParents(created,safeFs,paths,errors){
47
+ // Each parent was recorded before any children created beneath it.
48
+ for(const entry of created.toReversed()){
49
+ let parent;
50
+ try{
51
+ parent=safeFs.openRoot(path.dirname(entry.path));
52
+ if(!sameObjectIdentity(entry.parentIdentity,parent.stat()))continue;
53
+ const name=path.basename(entry.path),current=exists(parent,name);
54
+ if(!current||!sameObjectIdentity(entry.identity,current))continue;
55
+ parent.rmdir(name);
56
+ parent.sync();
57
+ }catch(cause){
58
+ // rmdir is atomic with respect to entries added to the directory.
59
+ if(['ENOENT','ENOTEMPTY','EEXIST'].includes(cause.code))continue;
60
+ paths.push(entry.path);
61
+ errors.push(new Error(`Rollback parent cleanup failed for ${entry.path}: ${cause.message}`,{cause}));
62
+ }finally{parent?.close();}
63
+ }
33
64
  }
34
65
  function treeFromDirectory(directory){
35
66
  const entries=new Map();function walk(handle,prefix=''){for(const name of handle.readDir()){const key=prefix?prefix+'/'+name:name,stat=handle.lstat(name),type=typeOf(stat);
@@ -55,11 +86,11 @@ function snapshotEntry(parent,name){const stat=exists(parent,name);if(!stat)retu
55
86
  function equalMoved(a,b){return a&&b&&['dev','ino','mode','size','mtimeNs','type','sha256','link'].every(k=>a[k]===b[k]);}
56
87
  export function applyTransaction(plan,{safeFs,signal,hooks={},specs:explicitSpecs}){
57
88
  assertPlanSnapshot(plan,{safeFs});const actions=[],areas=[],parents=[],created=[],actionLog=[],byParent=new Map();
58
- const cleanAreas=()=>{const paths=[],errors=[];for(const area of areas){const result=cleanupStage(area,{safeFs,hooks:{fault:event=>hooks.fault?.({...event,plan})}});paths.push(...result.residualPaths);if(result.cleanupError)errors.push(result.cleanupError);}return{paths,error:errors.length?Object.assign(new AggregateError(errors,errors.map(error=>error.message).join('; ')),{code:'ARC_INSTALL_CLEANUP',residualPaths:paths}):null};};
89
+ const cleanAreas=({rollback=false}={})=>{const paths=[],errors=[];for(const area of areas){const result=cleanupStage(area,{safeFs,hooks:{fault:event=>hooks.fault?.({...event,plan})}});paths.push(...result.residualPaths);if(result.cleanupError)errors.push(result.cleanupError);}if(rollback)cleanupCreatedParents(created,safeFs,paths,errors);return{paths,error:errors.length?Object.assign(new AggregateError(errors,errors.map(error=>error.message).join('; ')),{code:'ARC_INSTALL_CLEANUP',residualPaths:paths}):null};};
59
90
  const event=(phase,details={})=>{actionLog.push({phase,...details});if(signal?.aborted)throw new InstallError('Install interrupted','ARC_INSTALL_CANCELLED');hooks.fault?.({phase,...details,plan});};
60
91
  try{
61
92
  event('before-prepare');
62
- const specs=explicitSpecs??plan.uninstallSpecs??[{path:plan.target.home+'/skills/arc',tree:composeStaticArcSkillTree(plan.generated.skill)},...[...(plan.profileWrites??plan.generated.profiles)].map(([name,bytes])=>({path:plan.target.home+'/agents/'+name,bytes})),...plan.globalChanges.map(change=>({path:change.path,bytes:change.content}))];
93
+ const specs=explicitSpecs??plan.uninstallSpecs??[{path:plan.target.home+'/skills/arc',tree:composeStaticArcSkillTree(plan.generated.skill)},...[...(plan.profileWrites??plan.generated.profiles)].map(([name,bytes])=>({path:plan.target.home+'/agents/'+name,bytes})),...(plan.legacyRemovals??[]).map(path=>({path,remove:true})),...plan.globalChanges.map(change=>({path:change.path,bytes:change.content}))];
63
94
  for(const spec of specs){if(!spec.remove&&!spec.tree&&!Buffer.isBuffer(spec.bytes))fail('Missing verified staged data');const parent=openParent(safeFs,spec.path,created);parents.push(parent);const name=path.basename(spec.path);event('before-stage',{path:spec.path});let area=byParent.get(path.dirname(spec.path));if(area&&!sameObjectIdentity(parent.stat(),area.parent.stat()))fail('Reused staging parent identity changed','ARC_INSTALL_DRIFT');if(!area){const stageName='.arc-stage-'+randomUUID();parent.mkdir(stageName,0o700);const stage=parent.openDir(stageName);area={parent,stage,name:stageName,path:path.dirname(spec.path)+'/'+stageName,identity:stage.stat(),expected:new Map()};areas.push(area);byParent.set(path.dirname(spec.path),area);}const stage=area.stage,preparedName='prepared-'+actions.length,previousName='previous-'+actions.length,rollbackName='rollback-installed-'+actions.length;
64
95
  if(spec.remove){}
65
96
  else if(spec.tree){stage.mkdir(preparedName,0o700);const dir=stage.openDir(preparedName);try{writeTree(dir,spec.tree);if(spec.rootMetadata)finishDirectory(dir,spec.rootMetadata.mode,spec.rootMetadata);else dir.sync();}finally{dir.close();}}
@@ -77,7 +108,7 @@ export function applyTransaction(plan,{safeFs,signal,hooks={},specs:explicitSpec
77
108
  for(const action of actions)assertParentNamespace(safeFs,action);
78
109
  const cleaned=cleanAreas();return{actionLog,installedSnapshot:new Map(actions.map(a=>[a.path,a.installed])),residualPaths:cleaned.paths,cleanupError:cleaned.error};
79
110
  }catch(cause){const recovery=[],detachedParents=new Set();for(const action of [...actions].reverse()){try{hooks.fault?.({phase:'before-rollback',path:action.path,plan});if(action.published){if(!equalMoved(action.installed??action.prepared,snapshotEntry(action.parent,action.name)))fail('Installed target changed before rollback');action.parent.renameNoReplaceTo(action.name,action.stage,action.rollbackName);action.area.expected.set(action.rollbackName,action.installed??action.prepared);if(!equalMoved(action.installed??action.prepared,snapshotEntry(action.stage,action.rollbackName)))fail('Rollback source changed');}if(action.moved||action.published)try{assertParentNamespace(safeFs,action);}catch(error){detachedParents.add(path.dirname(action.path));throw error;}if(action.moved){if(!equalMoved(action.previous,snapshotEntry(action.stage,action.previousName)))fail('Previous entry changed');action.stage.renameNoReplaceTo(action.previousName,action.parent,action.name);action.area.expected.delete(action.previousName);try{assertParentNamespace(safeFs,action);}catch(error){detachedParents.add(path.dirname(action.path));if(!equalMoved(action.previous,snapshotEntry(action.parent,action.name)))throw error;action.parent.renameNoReplaceTo(action.name,action.stage,action.previousName);action.area.expected.set(action.previousName,action.previous);throw error;}}hooks.fault?.({phase:'after-rollback',path:action.path,plan});}catch{recovery.push(action.path,action.area.path);}}
80
- const cleaned=recovery.length?{paths:areas.map(area=>area.path),error:null}:cleanAreas();
111
+ const cleaned=recovery.length?{paths:areas.map(area=>area.path),error:null}:cleanAreas({rollback:true});
81
112
  const details={cause,actionLog,detachedParents:[...detachedParents],residualPaths:[...new Set([...recovery,...cleaned.paths])],cleanupError:cleaned.error,rollback:recovery.length?'failed':'restored'};
82
113
  if(recovery.length)throw new InstallError(detachedParents.size?'Rollback namespace unavailable; reported stage paths are last-known locations':'Rollback conflict; preserve reported residual paths','ARC_INSTALL_RECOVERY',details);
83
114
  if(cleaned.error)throw new InstallError('Rollback restored targets; '+cleaned.error.message,'ARC_INSTALL_CLEANUP',details);
@@ -7,7 +7,8 @@ import {validatePlanSet} from './plan.mjs';
7
7
  import {removeManagedBlock} from './global-config.mjs';
8
8
  import {attachShellCompletionCleanup} from './shell-completion.mjs';
9
9
  import {inspectCompositeRemoval} from './role-routing.mjs';
10
- export function buildUninstallPlan({target,safeFs,skipGlobal=false,removeCompletion=true,compositeActivePath,platforms,runtimePlatforms}){
10
+ import {inspectLegacyProfiles} from './legacy-profiles.mjs';
11
+ export function buildUninstallPlan({target,safeFs,skipGlobal=false,removeCompletion=true,compositeActivePath,platforms,runtimePlatforms,migrateLegacy=false}){
11
12
  const snapshot=new Map(),removals=[],managedPaths=[path.join(target.home,'skills/arc'),...target.profileNames.map(name=>path.join(target.home,'agents',name))],globalChanges=[];
12
13
  const standaloneResidual=[];
13
14
  for(const filename of managedPaths){if(filename===managedPaths[0]){const found=inspectPath(safeFs,filename,{kind:'directory',tree:true,allowLinks:true,snapshot});if(found.exists)removals.push(filename);}else{const found=inspectStandaloneProfile({safeFs,target,role:path.basename(filename).split('.')[0].replace('-','_'),snapshot,platforms});if(found.owned)removals.push(filename);else if(found.exists)standaloneResidual.push(filename);}}
@@ -32,24 +33,26 @@ export function buildUninstallPlan({target,safeFs,skipGlobal=false,removeComplet
32
33
  }
33
34
  }
34
35
  }
35
- const composite=inspectCompositeRemoval({target,safeFs,activeConfigPath:compositeActivePath,snapshot,runtimePlatforms});
36
- removals.push(...composite.removals);managedPaths.push(...composite.removals);
37
- const plan={target,skipGlobal,snapshot,removals,managedPaths,externalPaths:[],globalChanges,compositeOwned:composite.removals.length>0,compositeResidual:[...standaloneResidual,...composite.residualPaths],summary};
36
+ const composite=inspectCompositeRemoval({target,safeFs,activeConfigPath:compositeActivePath,snapshot,runtimePlatforms,platforms,migrateLegacy});
37
+ const legacy=inspectLegacyProfiles({platform:target.platform,agentsDir:path.join(target.home,'agents'),mode:{profile:composite.legacyProfile},safeFs,snapshot,platforms});
38
+ removals.push(...composite.removals,...legacy.remove);managedPaths.push(...composite.removals,...legacy.remove);
39
+ const plan={target,skipGlobal,snapshot,removals,managedPaths,externalPaths:[],globalChanges,compositeOwned:composite.removals.length>0,compositeResidual:[...standaloneResidual,...composite.residualPaths],legacyResiduals:legacy.residual,summary};
38
40
  if(removeCompletion)attachShellCompletionCleanup([plan],{safeFs});return plan;
39
41
  }
40
42
  import {assertPlanSnapshot,applyUninstallTransaction} from './transaction.mjs';
41
43
  export async function uninstallTargets(plans,{safeFs,signal,hooks={}}){
42
- const results=plans.map(plan=>({platform:plan.target.platform,status:'not-started',rollback:'not-needed',residualPaths:[...(plan.compositeResidual??[])],error:null}));let invalid=false;
44
+ const results=plans.map(plan=>({platform:plan.target.platform,status:'not-started',rollback:'not-needed',residualPaths:[...(plan.compositeResidual??[]),...(plan.legacyResiduals??[])],legacyResiduals:plan.legacyResiduals??[],error:null}));let invalid=false;
45
+ const legacyResiduals=[...new Set(results.flatMap(item=>item.legacyResiduals))];
43
46
  // Each standalone preview retains its snapshot; only the first plan owns the shared shell write.
44
47
  for(const plan of plans.slice(1)){const filename=path.join(plans[0].target.userHome,'.zshrc');plan.managedPaths=plan.managedPaths.filter(name=>name!==filename);plan.globalChanges=plan.globalChanges.filter(change=>change.path!==filename);plan.snapshot.delete(filename);}
45
- try{validatePlanSet(plans);}catch(error){return{results:results.map(item=>({...item,status:'failed',error})),interrupted:false};}
48
+ try{validatePlanSet(plans);}catch(error){return{results:results.map(item=>({...item,status:'failed',error})),interrupted:false,legacyResiduals};}
46
49
  for(let i=0;i<plans.length;i++)try{assertPlanSnapshot(plans[i],{safeFs});}catch(error){results[i]={...results[i],status:'failed',error};invalid=true;}
47
- if(invalid)return{results,interrupted:false};
50
+ if(invalid)return{results,interrupted:false,legacyResiduals};
48
51
 
49
52
  for(let i=0;i<plans.length;i++){
50
- if(signal?.aborted)return{results,interrupted:true};const plan=plans[i];
53
+ if(signal?.aborted)return{results,interrupted:true,legacyResiduals};const plan=plans[i];
51
54
  try{assertPlanSnapshot(plan,{safeFs});const applied=applyUninstallTransaction(plan,{safeFs,signal,hooks});results[i]={...results[i],status:'uninstalled',residualPaths:[...results[i].residualPaths,...applied.residualPaths],error:applied.cleanupError??null};if(applied.cleanupError)break;}
52
- catch(error){results[i]={...results[i],status:'failed',rollback:error.rollback??'not-needed',residualPaths:[...results[i].residualPaths,...(error.residualPaths??[])],error};return{results,interrupted:Boolean(signal?.aborted)};}
55
+ catch(error){results[i]={...results[i],status:'failed',rollback:error.rollback??'not-needed',residualPaths:[...results[i].residualPaths,...(error.residualPaths??[])],error};return{results,interrupted:Boolean(signal?.aborted),legacyResiduals};}
53
56
  }
54
- return{results,interrupted:false};
57
+ return{results,interrupted:false,legacyResiduals};
55
58
  }
@@ -8,6 +8,8 @@ import {parseSettings} from './language.mjs';
8
8
  import {parseLimits} from './limits.mjs';
9
9
  import {removeManagedBlock} from './global-config.mjs';
10
10
  import {removeShellCompletion} from './shell-completion.mjs';
11
+ import {inspectLegacyProfiles,legacyProfileNames} from './legacy-profiles.mjs';
12
+ import {standaloneProfileFile} from '../runtime/platform-registry.mjs';
11
13
  const fail=message=>{throw new TargetConfigurationError(message);};
12
14
  export function collectInstalledState({safeFs,userHome,env={},cwd,platforms,runtimePlatforms}){
13
15
  if(env.CODEX_HOME!==undefined&&!path.isAbsolute(env.CODEX_HOME)&&env.CODEX_HOME!=='~'&&!env.CODEX_HOME.startsWith('~/')&&(!cwd||!path.isAbsolute(cwd)))fail('A verified invocation cwd is required for relative CODEX_HOME');
@@ -23,7 +25,17 @@ export function collectInstalledState({safeFs,userHome,env={},cwd,platforms,runt
23
25
  const instruction=inspectPath(safeFs,target.instructionPath,{kind:'file',read:true,snapshot}),managed=instruction.exists?removeManagedBlock(instruction.bytes):{changed:false};
24
26
  if(!skill.exists){if(profiles.some(item=>item.exists&&item.owned)||managed.changed)fail(`Incomplete ARC installation: ${target.home}`);residualPaths.push(...profiles.filter(item=>item.exists&&!item.owned).map(item=>item.path));continue;}
25
27
  function mandatory(name){const found=inspectPath(safeFs,path.join(arc,name),{kind:'file',read:true,snapshot});if(!found.exists||!found.bytes.length)fail(`Incomplete ARC installation: missing ${name} at ${target.home}`);return found.bytes;}
26
- mandatory('SKILL.md');if(profiles.some(item=>!item.exists))fail(`Incomplete ARC installation: missing profile at ${target.home}`);
28
+ mandatory('SKILL.md');
29
+ const missing=profiles.filter(item=>!item.exists);
30
+ if(missing.length){
31
+ const agentsDir=path.join(target.home,'agents'),descriptor=registry.getPlatform(platform);
32
+ const tester=path.join(agentsDir,standaloneProfileFile(descriptor.runtime,'arc_tester'));
33
+ if(missing.length!==1||missing[0].path!==tester)fail(`Incomplete ARC installation: missing profile at ${target.home}`);
34
+ const evidence=new Map(),legacy=inspectLegacyProfiles({platform,agentsDir,safeFs,snapshot:evidence,platforms});
35
+ if(!legacy.remove.length)fail(`Incomplete ARC installation: missing profile at ${target.home}`);
36
+ const candidate=legacyProfileNames(platform,{platforms}).map(name=>path.join(agentsDir,name)).find(name=>legacy.remove.includes(name));
37
+ snapshot.set(candidate,evidence.get(candidate));
38
+ }
27
39
  let language,runMode,modelConfig,limits;
28
40
  try{
29
41
  const parsed=parseSettings(mandatory('settings.toml'));
@@ -2,7 +2,7 @@ import {readInstallMode,assertVerifiedInstallMode} from '../installer/install-mo
2
2
  import os from 'node:os';
3
3
  import {fileURLToPath} from 'node:url';
4
4
  import {resolveTarget,resolveTargets} from '../installer/targets.mjs';
5
- import {defaultCompositePlatformIds,installerRegistryOf,sortByAnchor,sortByDisplay,platformLabel} from '../platforms/index.mjs';
5
+ import {defaultCompositePlatformIds,installerRegistryOf,sortByAnchor,platformLabel} from '../platforms/index.mjs';
6
6
  import {platformAvailability} from '../platforms/availability.mjs';
7
7
  import {buildInstallPlan,renderStandaloneProfiles,validatePlanSet} from '../installer/plan.mjs';
8
8
  import {verifyPayload} from '../installer/manifest.mjs';
@@ -14,7 +14,7 @@ import {inspectGlobalArc} from '../npm/context.mjs';
14
14
  import {uninstallGlobal,sameGlobalArc} from '../npm/uninstall.mjs';
15
15
  import {collectStatus} from './status.mjs';
16
16
  import {loadModelConfig,serializeModelConfig} from '../models/index.mjs';
17
- import {readModelFileVersion} from '../models/config.mjs';
17
+ import {MODEL_SCHEMA_VERSION,readModelFileVersion} from '../models/config.mjs';
18
18
  import {buildRoleRoutingConfig} from '../runtime/role-routing-config.mjs';
19
19
  import {loadStaticModelCatalog,assertCompositeCatalogRoles} from '../models/static-catalog.mjs';
20
20
  import {prepareCompositeFiles,publishCompositeFiles,readCompositeRoutingConfig,prepareCompositeDeactivation,publishCompositeDeactivation,forceFinishDispatches} from '../installer/role-routing.mjs';
@@ -41,16 +41,15 @@ export async function prepareOperation(context,options,{selections=[]}={}){
41
41
  const platformOrder=options.target==='all'?(options.kind==='uninstall'?registry.byDisplayOrder():registry.byAnchorOrder()).filter(standaloneVerified).map(descriptor=>descriptor.runtime.id):[options.target];
42
42
  const skipped=options.target==='all'?platformOrder.flatMap(platform=>{const unresolved=resolved.unresolved.find(item=>item.platform===platform);return unresolved?[{platform,status:'skipped',residualPaths:[],error:unresolved.error}]:[];}):[];
43
43
  if(options.kind==='uninstall'&&skipped.length)throw new TargetConfigurationError(`Cannot uninstall everything: ${skipped.map(item=>`${platformLabel(item.platform,registry)} home cannot be resolved (${item.error.message})`).join('; ')}. Unset the variable or uninstall platforms individually.`);
44
- const modeOptions={safeFs:context.safeFs,...resolved,platforms:registry};
44
+ const modeOptions={safeFs:context.safeFs,...resolved,platforms:registry},mode=readInstallMode(modeOptions);
45
45
  if(registry.isPlatformId(options.target)||(options.target==='all'&&options.kind!=='uninstall')){
46
- const mode=readInstallMode(modeOptions);
47
46
  if(mode.mode==='unverified')assertVerifiedInstallMode(modeOptions);
48
47
  if(mode.mode==='composite'&&(options.target==='all'||mode.platforms.includes(options.target))){if(options.target==='all'||!options.switchFromComposite)throw new TargetConfigurationError('Mixed routing is active; confirm the switch first');return{kind:'switch',operation:options.kind,deactivation:prepareCompositeDeactivation({context,targets,payload:verifyPayload(context),platforms:mode.platforms,anchor:mode.anchor}),options:{...options}};}
49
48
  }
50
49
  if(options.kind==='uninstall')options={...options,removeCli:options.removeCli!==false};
51
- let compositeActivePath,compositeUninstallAnchor;if(options.kind==='uninstall'){const mode=readInstallMode(modeOptions),anchor=mode.mode==='composite'?mode.anchor:registry.byAnchorOrder().find(descriptor=>targets[descriptor.runtime.id])?.runtime.id;if(anchor)compositeActivePath=path.join(targets[anchor].home,'arc-role-platform-routing.json');if(mode.mode==='composite')compositeUninstallAnchor=anchor;}
50
+ let compositeActivePath,compositeUninstallAnchor;if(options.kind==='uninstall'){const anchor=mode.mode==='composite'?mode.anchor:registry.byAnchorOrder().find(descriptor=>targets[descriptor.runtime.id])?.runtime.id;if(anchor)compositeActivePath=path.join(targets[anchor].home,'arc-role-platform-routing.json');if(mode.mode==='composite')compositeUninstallAnchor=anchor;}
52
51
  const platforms=platformOrder.filter(platform=>!skipped.some(item=>item.platform===platform)),payload=options.kind==='install'?verifyPayload(context):null;
53
- const plans=platforms.map(platform=>{const target=resolveTarget(platform,context),selection=selections.find(item=>item.target.platform===platform&&item.target.home===target.home);if(options.kind==='preset')return buildPresetPlan({platforms:registry,runtimePlatforms:context.runtimePlatforms,loadPayload:()=>verifyPayload(context),target,roles:options.roles,safeFs:context.safeFs,verifiedCatalog:options.verifiedCatalog});if(options.kind==='uninstall')return buildUninstallPlan({platforms:registry,runtimePlatforms:context.runtimePlatforms,target,safeFs:context.safeFs,skipGlobal:options.skipGlobal,removeCompletion:options.removeCli!==false,compositeActivePath});return buildInstallPlan({platforms:registry,runtimePlatforms:context.runtimePlatforms,payload,target,limitsPreview:selection?.preview,languagePreview:selection?.languagePreview,roles:options.roles,verifiedCatalog:options.verifiedCatalog,language:options.language,runMode:options.runMode,skipGlobal:options.skipGlobal,safeFs:context.safeFs,limits:{...(options.maxTotalSubagents===undefined?{}:{max_total_subagents:options.maxTotalSubagents}),...(options.maxConcurrentSubagents===undefined?{}:{max_concurrent_subagents:options.maxConcurrentSubagents})},concurrentExplicit:options.maxConcurrentSubagents!==undefined||Boolean(options.concurrentSelected)});});
52
+ const plans=platforms.map(platform=>{const target=resolveTarget(platform,context),selection=selections.find(item=>item.target.platform===platform&&item.target.home===target.home);if(options.kind==='preset')return buildPresetPlan({platforms:registry,runtimePlatforms:context.runtimePlatforms,loadPayload:()=>verifyPayload(context),target,roles:options.roles,safeFs:context.safeFs,verifiedCatalog:options.verifiedCatalog});if(options.kind==='uninstall')return buildUninstallPlan({platforms:registry,runtimePlatforms:context.runtimePlatforms,target,safeFs:context.safeFs,skipGlobal:options.skipGlobal,removeCompletion:options.removeCli!==false,compositeActivePath,migrateLegacy:mode.mode==='composite'});return buildInstallPlan({platforms:registry,runtimePlatforms:context.runtimePlatforms,payload,target,limitsPreview:selection?.preview,languagePreview:selection?.languagePreview,roles:options.roles,verifiedCatalog:options.verifiedCatalog,language:options.language,runMode:options.runMode,skipGlobal:options.skipGlobal,safeFs:context.safeFs,limits:{...(options.maxTotalSubagents===undefined?{}:{max_total_subagents:options.maxTotalSubagents}),...(options.maxConcurrentSubagents===undefined?{}:{max_concurrent_subagents:options.maxConcurrentSubagents})},concurrentExplicit:options.maxConcurrentSubagents!==undefined||Boolean(options.concurrentSelected)});});
54
53
  // Retain the active config until every other uninstall snapshot has read it.
55
54
  if(compositeUninstallAnchor&&options.target==='all')plans.sort((a,b)=>Number(a.target.platform===compositeUninstallAnchor)-Number(b.target.platform===compositeUninstallAnchor));
56
55
  if(options.kind==='install')attachShellCompletionCleanup(plans,context);
@@ -90,7 +89,7 @@ export async function prepareCompositeOperation(context,options){
90
89
  const statuses=await collectStatus(context);
91
90
  const warnings=await assertCompositeAvailability(context,config,statuses);
92
91
  for(let i=0;i<platforms.length;i++)for(let j=0;j<i;j++){const a=targets[platforms[i]].home,b=targets[platforms[j]].home;if(a===b||a.startsWith(b+path.sep)||b.startsWith(a+path.sep))throw new TargetConfigurationError('Selected platform homes overlap');}
93
- if(options.kind==='preset'&&statuses.some(status=>platforms.includes(status.platform)&&status.state!=='installed'))throw new TargetConfigurationError('Both ARC installations are required to change composite settings');
92
+ if(options.kind==='preset'&&statuses.some(status=>platforms.includes(status.platform)&&status.state!=='installed'))throw new TargetConfigurationError('All participating ARC installations are required to change composite settings');
94
93
  const plans=[],profileInputs={},modelConfigs={},sourceSnapshot=new Map(),externalPaths=[];
95
94
  if(options.kind==='install'){
96
95
  const payload=verifyPayload(context);
@@ -100,7 +99,7 @@ export async function prepareCompositeOperation(context,options){
100
99
  const parsed=languageFile.exists?parseSettings(languageFile.bytes):null;
101
100
  const language=options.settings?.language??parsed?.language??'en';
102
101
  const runMode=options.settings?.runMode??parsed?.runMode??'supervised';
103
- const plan=buildInstallPlan({platforms:registry,runtimePlatforms:context.runtimePlatforms,payload,target,profiles:mode.mode==='composite'&&mode.platforms.includes(platform)?'omit':'write',modelConfig,language,runMode,safeFs:context.safeFs,limits:{...(options.settings?.maxTotalSubagents===undefined?{}:{max_total_subagents:options.settings.maxTotalSubagents}),...(options.settings?.maxConcurrentSubagents===undefined?{}:{max_concurrent_subagents:options.settings.maxConcurrentSubagents})},skipGlobal:options.settings?.skipGlobal??false,concurrentExplicit:Boolean(options.settings?.concurrentSelected)||options.settings?.maxConcurrentSubagents!==undefined});assertPlanSnapshot({snapshot:existing},{safeFs:context.safeFs});
102
+ const plan=buildInstallPlan({platforms:registry,runtimePlatforms:context.runtimePlatforms,payload,target,profiles:mode.mode==='composite'&&mode.platforms.includes(platform)?'omit':'write',deferLegacyProfiles:true,modelConfig,language,runMode,safeFs:context.safeFs,limits:{...(options.settings?.maxTotalSubagents===undefined?{}:{max_total_subagents:options.settings.maxTotalSubagents}),...(options.settings?.maxConcurrentSubagents===undefined?{}:{max_concurrent_subagents:options.settings.maxConcurrentSubagents})},skipGlobal:options.settings?.skipGlobal??false,concurrentExplicit:Boolean(options.settings?.concurrentSelected)||options.settings?.maxConcurrentSubagents!==undefined});assertPlanSnapshot({snapshot:existing},{safeFs:context.safeFs});
104
103
  plans.push(plan);profileInputs[platform]=plan.generated.profiles;modelConfigs[platform]=modelConfig;
105
104
  }
106
105
  attachShellCompletionCleanup(plans,context);validatePlanSet(plans);
@@ -113,7 +112,7 @@ export async function prepareCompositeOperation(context,options){
113
112
  files.modelWrites=[];
114
113
  if(options.kind==='preset')for(const platform of platforms){
115
114
  const filename=path.join(targets[platform].home,'skills/arc/models.toml'),found=inspectPath(context.safeFs,filename,{kind:'file',read:true,snapshot:files.snapshot});
116
- if(found.exists&&readModelFileVersion(found.bytes)<3){files.modelWrites.push({path:filename,bytes:Buffer.from(serializeModelConfig(modelConfigs[platform],context))});files.managedPaths.push(filename);}
115
+ if(found.exists&&readModelFileVersion(found.bytes)<MODEL_SCHEMA_VERSION){files.modelWrites.push({path:filename,bytes:Buffer.from(serializeModelConfig(modelConfigs[platform],context))});files.managedPaths.push(filename);}
117
116
  }
118
117
  files.externalPaths.push(...externalPaths.filter(filename=>!files.modelWrites.some(write=>write.path===filename)));
119
118
  return {kind:'composite',operation:options.kind,plans,files,config,options:{target:'composite'},...(warnings.length?{warnings}:{}),...(mode.legacyAnchor?{anchorMove:{from:mode.anchor,to:anchor}}:{}),summary:['Composite configuration will be published only after all participating targets are ready.','Per-role execution support is reported by routing-status.']};
@@ -124,6 +123,7 @@ export async function forceFinishBlockingDispatches(context,entries){
124
123
  }
125
124
  export async function executeCompositeOperation(context,prepared){
126
125
  const held={routeStatus:'held',supportStatus:'unverified',reason:'Per-role execution support is reported by routing-status.'};
126
+ const legacyResiduals=prepared.files.legacyResiduals??[];
127
127
  let result={results:[],interrupted:false},installationHeld;
128
128
  try{
129
129
  await assertCompositeAvailability(context,prepared.config,await collectStatus(context,{codexCheck:'local'}));
@@ -141,12 +141,12 @@ export async function executeCompositeOperation(context,prepared){
141
141
  if(prepared.operation==='install'){result=await installTargets(prepared.plans,{safeFs:context.safeFs,signal:context.signal,hooks:context.hooks,platforms:installerRegistryOf(context)});if(result.interrupted||result.results.some(item=>item.status!=='installed'||item.error)){installationHeld={...operationResult(result),activation:'held',support:held};throw new TargetConfigurationError('Participating installations are incomplete');}}
142
142
  if(prepared.operation==='install')for(const plan of prepared.plans)for(const name of plan.profileWrites.keys()){const filename=path.join(plan.target.home,'agents',name);inspectPath(context.safeFs,filename,{kind:'file',read:true,snapshot:prepared.files.snapshot});if(!prepared.files.standaloneRemovals.includes(filename)){prepared.files.standaloneRemovals.push(filename);prepared.files.managedPaths.push(filename);}}
143
143
  if(context.signal?.aborted){installationHeld={...operationResult({...result,interrupted:true}),activation:'held',support:held};throw new TargetConfigurationError('Install interrupted');}
144
- const statuses=await collectStatus(context,{codexCheck:'local'});await assertCompositeAvailability(context,prepared.config,statuses);if(prepared.operation!=='install'&&statuses.some(status=>prepared.config.platforms.includes(status.platform)&&status.state!=='installed'))throw new TargetConfigurationError('Both ARC installations must be complete before publication');
144
+ const statuses=await collectStatus(context,{codexCheck:'local'});await assertCompositeAvailability(context,prepared.config,statuses);if(prepared.operation!=='install'&&statuses.some(status=>prepared.config.platforms.includes(status.platform)&&status.state!=='installed'))throw new TargetConfigurationError('All participating ARC installations must be complete before publication');
145
145
  };
146
146
  if(!moving)await ready();
147
147
  const publication=await publishCompositeFiles({context,prepared:prepared.files,...(moving?{beforePublish:ready}:{})});
148
148
  const history=moving?[`Dispatch history stays in ${prepared.files.targets[prepared.files.previous.anchor].home}/arc-role-dispatch.`]:[];
149
- return {...operationResult(result),code:publication.cleanupError?1:0,activation:'published',publication,support:held,...(publication.cleanupError?{error:publication.cleanupError}:{}),messages:[`Mixed routing on: ${sortByDisplay(prepared.config.platforms,installerRegistryOf(context)).map(id=>platformLabel(id,installerRegistryOf(context))).join(' + ')}.`,'After upgrading ARC, run Configure again.',...history,...(publication.residualPaths??[]).map(value=>'Residual path: '+value)]};
149
+ return {...operationResult(result),legacyResiduals,code:publication.cleanupError?1:0,activation:'published',publication,support:held,...(publication.cleanupError?{error:publication.cleanupError}:{}),messages:[...history,...(publication.residualPaths??[]).map(value=>'Residual path: '+value)]};
150
150
  }catch(error){if(installationHeld&&!error.lockReleaseFailed)return installationHeld;return {code:context.signal?.aborted?130:1,exitSession:false,interrupted:Boolean(context.signal?.aborted),results:result.results,activation:error.activation??'held',support:held,error,messages:[...(Array.isArray(error.activeDispatches)?[`${prepared.files.previous&&prepared.files.previous.anchor!==prepared.files.anchor?'Active dispatches':'Active bridge dispatches'}: ${error.activeDispatches.join(', ')}`]:[]),...(error.activation==='unknown'?['Configuration publication state is unknown; inspect the reported paths before retrying.']:[]),...(error.residualPaths??[]).map(value=>'Residual path: '+value)]};}
151
151
  }
152
152
  export function operationResult(result,successStatuses=['installed']){return{...result,code:result.interrupted?130:result.results.every(item=>successStatuses.includes(item.status)&&!item.error)?0:1,exitSession:false};}
@@ -165,8 +165,8 @@ async function uninstallPrepared(context,prepared,options){
165
165
  export async function executeOperation(context,prepared){
166
166
  if(prepared.kind==='switch'){
167
167
  let deactivation;const messages=[];
168
- try{deactivation=await publishCompositeDeactivation({context,prepared:prepared.deactivation});messages.push('Mixed routing turned off.',...deactivation.residualPaths.map(p=>'Residual path: '+p));if(deactivation.cleanupError)return{code:1,exitSession:false,interrupted:false,results:[],messages,error:deactivation.cleanupError};
169
- const next=await prepareOperation(context,{...prepared.options,switchFromComposite:false}),result=await executeOperation(context,next);return{...result,messages:[...messages,...(result.messages??[])]};
168
+ try{deactivation=await publishCompositeDeactivation({context,prepared:prepared.deactivation});messages.push('Mixed routing turned off.',...deactivation.residualPaths.map(p=>'Residual path: '+p));if(deactivation.cleanupError)return{code:1,exitSession:false,interrupted:false,results:[],legacyResiduals:deactivation.legacyResiduals,messages,error:deactivation.cleanupError};
169
+ const next=await prepareOperation(context,{...prepared.options,switchFromComposite:false}),result=await executeOperation(context,next);return{...result,legacyResiduals:[...new Set([...deactivation.legacyResiduals,...(result.legacyResiduals??[])])],messages:[...messages,...(result.messages??[])]};
170
170
  }catch(error){return{code:context.signal?.aborted?130:1,exitSession:false,interrupted:Boolean(context.signal?.aborted),results:[],error,messages:[...messages,...(error.activeDispatches?[`Active bridge dispatches: ${error.activeDispatches.join(', ')}`]:[]),...(error.residualPaths??[]).map(p=>'Residual path: '+p)]};}
171
171
  }
172
172
  if(prepared.kind==='composite')return executeCompositeOperation(context,prepared);
@@ -63,6 +63,7 @@ async function applyConfiguration(context,options){
63
63
  messages:result.messages?.filter(message=>result.activation==='unknown'
64
64
  ?!message.startsWith('Residual path: '):message.startsWith('Dispatch history stays in ')),
65
65
  published:target===undefined?result.activation==='published':result.results.some(item=>item.status==='installed'),
66
+ legacyResiduals:result.legacyResiduals??[],
66
67
  residualPaths:[...(result.publication?.residualPaths??[]),...(error?.residualPaths??[]),...result.results.flatMap(item=>item.residualPaths??[])],
67
68
  };
68
69
  }catch(error){return {code:context.signal?.aborted?130:1,error,residualPaths:error.residualPaths??[]};}
@@ -70,14 +71,14 @@ async function applyConfiguration(context,options){
70
71
 
71
72
  export async function reapplyConfiguration(options={}){
72
73
  const {signal,loadCatalog}=options;
73
- const residualPaths=new Set(),applied=[],failures=[],messages=[];
74
+ const residualPaths=new Set(),legacyResiduals=new Set(),applied=[],failures=[],messages=[];
74
75
  let mode,unknown;
75
76
  const incomplete=(error,code=signal?.aborted?130:1)=>({
76
- status:unknown?'unknown':'held',mode,code,error:unknown?.error??error,residualPaths:[...residualPaths],
77
+ status:unknown?'unknown':'held',mode,code,error:unknown?.error??error,residualPaths:[...residualPaths],legacyResiduals:[...legacyResiduals],
77
78
  ...(unknown?{messages:unknown.messages}:error.activeDispatches?{activeDispatches:error.activeDispatches}:{}),
78
79
  ...(applied.length?{applied}:{}),
79
80
  });
80
- const completed=(code,error)=>({status:'applied',mode,platforms:applied,residualPaths:[...residualPaths],code,...(messages.length?{messages}:{}),...(error?{error}:{})});
81
+ const completed=(code,error)=>({status:'applied',mode,platforms:applied,residualPaths:[...residualPaths],legacyResiduals:[...legacyResiduals],code,...(messages.length?{messages}:{}),...(error?{error}:{})});
81
82
  try{
82
83
  signal?.throwIfAborted();
83
84
  const context=await createManagementContext(options),installState=currentInstallState(context);
@@ -93,6 +94,7 @@ export async function reapplyConfiguration(options={}){
93
94
  for(const target of targets){
94
95
  const result=await applyConfiguration(context,{installState,statuses,target,currentConfig,loadCatalog});
95
96
  for(const filename of result.residualPaths)residualPaths.add(filename);
97
+ for(const filename of result.legacyResiduals??[])legacyResiduals.add(filename);
96
98
  const error=result.error??new TargetConfigurationError('Configure Apply did not complete');
97
99
  if(result.unknown){
98
100
  unknown={error,messages:result.messages};