@fbincon/claude-code-statusline 3.11.0 → 3.13.0

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 (193) hide show
  1. package/README.md +82 -79
  2. package/candidate.json +356 -254
  3. package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.d.ts +1 -0
  4. package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.js +9 -0
  5. package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.js.map +1 -1
  6. package/node_modules/@fbincon/statusline-cli/dist/src/config/commands.js +23 -0
  7. package/node_modules/@fbincon/statusline-cli/dist/src/config/commands.js.map +1 -1
  8. package/node_modules/@fbincon/statusline-cli/dist/src/config/profile-command.js +7 -3
  9. package/node_modules/@fbincon/statusline-cli/dist/src/config/profile-command.js.map +1 -1
  10. package/node_modules/@fbincon/statusline-cli/dist/src/config/reuse.d.ts +3 -0
  11. package/node_modules/@fbincon/statusline-cli/dist/src/config/reuse.js +62 -0
  12. package/node_modules/@fbincon/statusline-cli/dist/src/config/reuse.js.map +1 -0
  13. package/node_modules/@fbincon/statusline-cli/dist/src/config/structural-review.d.ts +5 -0
  14. package/node_modules/@fbincon/statusline-cli/dist/src/config/structural-review.js +45 -0
  15. package/node_modules/@fbincon/statusline-cli/dist/src/config/structural-review.js.map +1 -0
  16. package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js +5 -1
  17. package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js.map +1 -1
  18. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.d.ts +1 -0
  19. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.js +41 -0
  20. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.js.map +1 -0
  21. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.d.ts +1 -0
  22. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.js +14 -0
  23. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.js.map +1 -0
  24. package/node_modules/@fbincon/statusline-cli/dist/src/main.js +9 -0
  25. package/node_modules/@fbincon/statusline-cli/dist/src/main.js.map +1 -1
  26. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.d.ts +1 -0
  27. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.js +4 -0
  28. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.js.map +1 -0
  29. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.d.ts +29 -0
  30. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.js +228 -0
  31. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.js.map +1 -0
  32. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.d.ts +4 -0
  33. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.js +150 -0
  34. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.js.map +1 -0
  35. package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.js +30 -13
  36. package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.js.map +1 -1
  37. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js +2 -2
  38. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js.map +1 -1
  39. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.d.ts +1 -0
  40. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.js +11 -6
  41. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.js.map +1 -1
  42. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.d.ts +2 -0
  43. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js +9 -5
  44. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js.map +1 -1
  45. package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js +6 -6
  46. package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js.map +1 -1
  47. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.d.ts +1 -0
  48. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js +6 -6
  49. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js.map +1 -1
  50. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic.js +76 -28
  51. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic.js.map +1 -1
  52. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.d.ts +17 -0
  53. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.js +176 -0
  54. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.js.map +1 -0
  55. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js +11 -3
  56. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js.map +1 -1
  57. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js +26 -8
  58. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js.map +1 -1
  59. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.d.ts +3 -0
  60. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js +54 -14
  61. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js.map +1 -1
  62. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +3 -3
  63. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +50 -0
  64. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js.map +1 -1
  65. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/.claude-plugin/plugin.json +1 -1
  66. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/hooks/register.ts +30 -18
  67. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/backend.ts +4 -0
  68. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +14 -3
  69. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/settings.ts +8 -5
  70. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/alignment-manager.ts +2 -2
  71. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/change-review.ts +109 -0
  72. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/color-manager.ts +1 -1
  73. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +74 -21
  74. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/forms.ts +2 -9
  75. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/group-manager.ts +2 -3
  76. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/groups.ts +2 -2
  77. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/history.ts +33 -0
  78. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/package-manager.ts +164 -291
  79. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/package-validation.ts +10 -1
  80. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/reuse-manager.ts +150 -0
  81. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/reuse.ts +96 -0
  82. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-compatibility.ts +7 -0
  83. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-manager.ts +64 -45
  84. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-summary.ts +22 -0
  85. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-validation.ts +11 -2
  86. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/structure.ts +30 -0
  87. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +49 -6
  88. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +7 -12722
  89. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/en.ts +2291 -0
  90. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/ja.ts +2291 -0
  91. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/ko.ts +2291 -0
  92. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-CN.ts +2291 -0
  93. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-HK.ts +2291 -0
  94. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-TW.ts +2291 -0
  95. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +35 -22
  96. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +4 -1
  97. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/help.ts +3 -2
  98. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/.claude-plugin/plugin.json +1 -1
  99. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/hooks/observe.ts +10 -3
  100. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/resource-manifest.json +4 -4
  101. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +127 -6
  102. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js +2 -2
  103. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js.map +1 -1
  104. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js +2 -2
  105. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js.map +1 -1
  106. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js +6 -0
  107. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js.map +1 -1
  108. package/node_modules/@fbincon/statusline-core/dist/src/editor/change-review.d.ts +32 -0
  109. package/node_modules/@fbincon/statusline-core/dist/src/editor/change-review.js +155 -0
  110. package/node_modules/@fbincon/statusline-core/dist/src/editor/change-review.js.map +1 -0
  111. package/node_modules/@fbincon/statusline-core/dist/src/editor/color-manager.js +1 -1
  112. package/node_modules/@fbincon/statusline-core/dist/src/editor/color-manager.js.map +1 -1
  113. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.d.ts +20 -3
  114. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +121 -23
  115. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
  116. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js +2 -10
  117. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js.map +1 -1
  118. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js +2 -5
  119. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js.map +1 -1
  120. package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.d.ts +1 -1
  121. package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.js +2 -2
  122. package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.js.map +1 -1
  123. package/node_modules/@fbincon/statusline-core/dist/src/editor/history.d.ts +22 -0
  124. package/node_modules/@fbincon/statusline-core/dist/src/editor/history.js +37 -0
  125. package/node_modules/@fbincon/statusline-core/dist/src/editor/history.js.map +1 -0
  126. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.d.ts +12 -4
  127. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.js +302 -85
  128. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.js.map +1 -1
  129. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.js +12 -1
  130. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.js.map +1 -1
  131. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse-manager.d.ts +39 -0
  132. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse-manager.js +271 -0
  133. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse-manager.js.map +1 -0
  134. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse.d.ts +6 -0
  135. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse.js +135 -0
  136. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse.js.map +1 -0
  137. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-compatibility.d.ts +3 -0
  138. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-compatibility.js +7 -0
  139. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-compatibility.js.map +1 -0
  140. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.d.ts +9 -3
  141. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js +85 -30
  142. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js.map +1 -1
  143. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.d.ts +5 -0
  144. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.js +25 -0
  145. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.js.map +1 -0
  146. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.d.ts +1 -0
  147. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js +13 -2
  148. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js.map +1 -1
  149. package/node_modules/@fbincon/statusline-core/dist/src/editor/structure.d.ts +16 -0
  150. package/node_modules/@fbincon/statusline-core/dist/src/editor/structure.js +28 -0
  151. package/node_modules/@fbincon/statusline-core/dist/src/editor/structure.js.map +1 -0
  152. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.d.ts +2 -0
  153. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js +15 -3
  154. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js.map +1 -1
  155. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +1032 -12
  156. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +1038 -18
  157. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
  158. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js +1 -0
  159. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js.map +1 -1
  160. package/node_modules/@fbincon/statusline-core/dist/src/release.d.ts +1 -1
  161. package/node_modules/@fbincon/statusline-core/dist/src/release.js +1 -1
  162. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +173 -3
  163. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +173 -3
  164. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +173 -3
  165. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +173 -3
  166. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +173 -3
  167. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +173 -3
  168. package/node_modules/@fbincon/statusline-platform/dist/src/native.d.ts +2 -0
  169. package/node_modules/@fbincon/statusline-platform/dist/src/native.js +2 -0
  170. package/node_modules/@fbincon/statusline-platform/dist/src/native.js.map +1 -1
  171. package/node_modules/@fbincon/statusline-platform/dist/src/npm.d.ts +2 -0
  172. package/node_modules/@fbincon/statusline-platform/dist/src/npm.js +20 -1
  173. package/node_modules/@fbincon/statusline-platform/dist/src/npm.js.map +1 -1
  174. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.d.ts +3 -0
  175. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.js +53 -0
  176. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.js.map +1 -0
  177. package/node_modules/@fbincon/statusline-platform/dist/src/processes.d.ts +2 -0
  178. package/node_modules/@fbincon/statusline-platform/dist/src/processes.js +45 -0
  179. package/node_modules/@fbincon/statusline-platform/dist/src/processes.js.map +1 -1
  180. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.d.ts +5 -0
  181. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js +8 -1
  182. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js.map +1 -1
  183. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js +6 -0
  184. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js.map +1 -1
  185. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js +3 -0
  186. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js.map +1 -1
  187. package/node_modules/@fbincon/statusline-tui/dist/src/session.d.ts +2 -1
  188. package/node_modules/@fbincon/statusline-tui/dist/src/session.js +26 -6
  189. package/node_modules/@fbincon/statusline-tui/dist/src/session.js.map +1 -1
  190. package/node_modules/@fbincon/statusline-tui/dist/src/state.d.ts +1 -1
  191. package/node_modules/@fbincon/statusline-tui/dist/src/state.js +39 -9
  192. package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
  193. package/package.json +3 -3
@@ -1,8 +1,10 @@
1
+ import { openChanges, performChanges, changePreview } from '../lib/editor/change-review.ts';
2
+ import { performReuse } from '../lib/editor/reuse-manager.ts';
1
3
  import { performPackage, closePackage } from '../lib/editor/package-manager.ts';
2
4
  import { diagnosisRequest } from '../lib/editor/diagnosis-view.ts';
3
5
  import { colorDraft } from '../lib/editor/color-manager.ts';
4
6
  import { previewWidth } from '../lib/editor/preview-settings.ts';
5
- import { performSourceAction, closeSources } from '../lib/editor/source-manager.ts';
7
+ import { performSourceAction, closeSources, closeSourceDraft } from '../lib/editor/source-manager.ts';
6
8
  import { taskViewer, taskViewerView, taskViewerKey, receiveTask, type TaskViewer } from '../lib/editor/task-viewer.ts';
7
9
  import { receivePreset } from '../lib/editor/quick-setup.ts';
8
10
  import { performProfileAction } from '../lib/editor/profile-manager.ts';
@@ -51,12 +53,12 @@ async function callBackend<O extends Operation>(
51
53
  options: PluginOptions,
52
54
  operation: O,
53
55
  payload: unknown = {},
56
+ control?: import('../lib/generated-contracts.ts').PackageControl,
54
57
  ): Promise<ResultFor<O>> {
55
58
  try {
56
- const launch = binding(options, await $.env.get('CLAUDE_STATUSLINE_NATIVE_EXECUTABLE') || undefined);
57
- const directory =
58
- (await $.env.get('CLAUDE_CONFIG_DIR')) ||
59
- (typeof options.configDir === 'string' ? options.configDir : undefined);
59
+ const launch = control ?? binding(options, await $.env.get('CLAUDE_STATUSLINE_NATIVE_EXECUTABLE') || undefined);
60
+ const directory = control?.config_dir ?? ((await $.env.get('CLAUDE_CONFIG_DIR')) ||
61
+ (typeof options.configDir === 'string' ? options.configDir : undefined));
60
62
  const argv = directory
61
63
  ? [launch.executable, ...launch.args, 'ui', '--config-dir', directory]
62
64
  : [launch.executable, ...launch.args, 'ui'];
@@ -168,8 +170,8 @@ async function load(
168
170
  state: Session,
169
171
  options: PluginOptions,
170
172
  ) {
171
- if (state.view.editor?.packages) await closePackage(state.view.editor.packages,{request:(operation,payload)=>callBackend($,options,operation,payload)});
172
- if (state.view.editor?.sources) await closeSources(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});
173
+ if (state.view.editor?.packages) await closePackage(state.view.editor.packages,{request:(operation,payload)=>callBackend($,options,operation,payload),control:(control,operation,payload)=>callBackend($,options,operation,payload,control)});
174
+ if (state.view.editor?.sources && !state.view.editor.packageLocked) {await closeSources(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});await closeSourceDraft(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});}
173
175
  discard(state);
174
176
  const opening = state.epoch;
175
177
  setMessage(state.view, "busy", localizedText("native.hooks.register.loading_configuration"));
@@ -310,6 +312,7 @@ async function save(
310
312
  editor.saveFailed(error.code);
311
313
  state.view.uncertain = editor.saveState === 'unknown';
312
314
  state.saveOutcome = state.view.uncertain ? 'unknown' : 'refused';
315
+ if(error.code==='configuration_conflict'){openChanges(editor);editor.changeReview!.effect='read';await performChanges(editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});}
313
316
  } finally {
314
317
  if (state.epoch === saving) {
315
318
  state.writing = false;
@@ -455,8 +458,8 @@ async function close($: EngineInterface, state: Session, options: PluginOptions)
455
458
  return;
456
459
  }
457
460
  try {
458
- if (state.view.editor?.packages) await closePackage(state.view.editor.packages,{request:(operation,payload)=>callBackend($,options,operation,payload)});
459
- if (state.view.editor?.sources) await closeSources(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});
461
+ if (state.view.editor?.packages) await closePackage(state.view.editor.packages,{request:(operation,payload)=>callBackend($,options,operation,payload),control:(control,operation,payload)=>callBackend($,options,operation,payload,control)});
462
+ if (state.view.editor?.sources && !state.view.editor.packageLocked) {await closeSources(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});await closeSourceDraft(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});}
460
463
  await $.ui.close({ id: PANE });
461
464
  const open = await $.ui.panes();
462
465
  if (!open.some((p) => p.id === PANE)) discard(state);
@@ -645,8 +648,8 @@ export const register: Register = (on, options) => {
645
648
  on('session.start', async ($, e, next) => {
646
649
  await startTaskDetails($, taskDetails, options);
647
650
  state.ownsCommand = false;
648
- if (state.view.editor?.packages) await closePackage(state.view.editor.packages,{request:(operation,payload)=>callBackend($,options,operation,payload)});
649
- if (state.view.editor?.sources) await closeSources(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});
651
+ if (state.view.editor?.packages) await closePackage(state.view.editor.packages,{request:(operation,payload)=>callBackend($,options,operation,payload),control:(control,operation,payload)=>callBackend($,options,operation,payload,control)});
652
+ if (state.view.editor?.sources && !state.view.editor.packageLocked) {await closeSources(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});await closeSourceDraft(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});}
650
653
  discard(state);
651
654
  const open = await $.ui.panes();
652
655
  if (open.some((p) => p.id === PANE)) {
@@ -684,8 +687,8 @@ export const register: Register = (on, options) => {
684
687
  $.ui.invalidate('ui.render');
685
688
  return { deny: state.view.error };
686
689
  }
687
- if (state.view.editor?.packages) await closePackage(state.view.editor.packages,{request:(operation,payload)=>callBackend($,options,operation,payload)});
688
- if (state.view.editor?.sources) await closeSources(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});
690
+ if (state.view.editor?.packages) await closePackage(state.view.editor.packages,{request:(operation,payload)=>callBackend($,options,operation,payload),control:(control,operation,payload)=>callBackend($,options,operation,payload,control)});
691
+ if (state.view.editor?.sources && !state.view.editor.packageLocked) {await closeSources(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});await closeSourceDraft(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});}
689
692
  const result = await next(e);
690
693
  const open = await $.ui.panes();
691
694
  if (!open.some((p) => p.id === PANE)) discard(state);
@@ -755,10 +758,11 @@ export const register: Register = (on, options) => {
755
758
  );
756
759
  if (effect === 'save' || effect === 'finish') {
757
760
  await save($, state, options, effect === 'finish');
761
+ } else if ((effect === 'changes' || effect === 'reuse') && state.view.editor) {
762
+ state.writing=true;try { if(effect==='changes')await performChanges(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)});else await performReuse(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)}); } finally {state.writing=false;state.previewKey='';}
758
763
  } else if (effect === 'close') await close($, state, options);
759
764
  else if (effect === 'reload') {
760
- await load($, state, options);
761
- state.placed = true;
765
+ if(state.view.editor?.modified){openChanges(state.view.editor);state.view.editor.changeReview!.confirm=true;}else {await load($,state,options);state.placed=true;}
762
766
  } else if (effect === 'reconcile') await reconcile($, state, options);
763
767
  else if (effect === 'transfer') await transferDraft($, state, options);
764
768
  else if(effect==='diagnoseFile'&&state.view.editor) {
@@ -777,12 +781,20 @@ export const register: Register = (on, options) => {
777
781
  state.diagnosisTimer=timer;
778
782
  }
779
783
  else if (effect === 'packages' && state.view.editor?.packages) {
780
- const view=state.view.editor.packages;await performPackage(view,{request:(operation,payload)=>callBackend($,options,operation,payload)});
784
+ const view=state.view.editor.packages;state.writing=true;
785
+ try{await performPackage(view,{request:(operation,payload)=>callBackend($,options,operation,payload),control:(control,operation,payload)=>callBackend($,options,operation,payload,control)},state.view.editor);}
786
+ finally{state.writing=false;state.view.uncertain=state.view.editor.saveState==='unknown';if(state.view.uncertain)state.saveOutcome='unknown';}
781
787
  if(view.closed)state.view.editor.packages=null;
782
788
  }
783
789
  else if (effect === 'sources' && state.view.editor) {
784
790
  state.writing=true;
785
- try { await performSourceAction(state.view.editor,{request:(operation,payload)=>callBackend($,options,operation,payload)}); }
791
+ try { await performSourceAction(state.view.editor,{request:async(operation,payload)=>{
792
+ if(operation==='source_context'){
793
+ const context=payload as {project:string|null;session:string|null;agent:string|null};
794
+ try{payload={...context,project:context.project??await $.session.cwd(),session:context.session??await $.session.id()};}catch{/* Preserve unknown ownership when host context is unavailable. */}
795
+ }
796
+ return callBackend($,options,operation,payload);
797
+ }}); }
786
798
  finally {state.writing=false;state.previewKey='';}
787
799
  }
788
800
  else if (effect === 'profiles' && state.view.editor) {
@@ -864,7 +876,7 @@ export const register: Register = (on, options) => {
864
876
  state.columns = width;
865
877
  state.rows = height;
866
878
  const editor = state.view.editor;
867
- const previewDraft = editor?.colors ? colorDraft(editor) : editor?.profiles?.candidate ? { ...editor.draft, display: editor.profiles.candidate } : editor?.quick?.candidate ?? editor?.review?.result.draft ?? editor?.draft;
879
+ const previewDraft = editor?.changeReview ? changePreview(editor) : editor?.reuse?.result && !editor.reuse.result.blocked.length ? editor.reuse.result.draft : editor?.colors ? colorDraft(editor) : editor?.profiles?.candidate ? { ...editor.draft, display: editor.profiles.candidate } : editor?.quick?.candidate ?? editor?.review?.result.draft ?? editor?.draft;
868
880
  const previewColumns = previewWidth(contentColumns(width,height),editor?.previewWidth ?? 'auto');
869
881
  const explanation=editor?.explanation;
870
882
  const key = `${state.epoch}:${previewColumns}:${editor?.previewScenario}:${explanation ? explanation.scope+':'+explanation.id : ''}:${previewDraft ? JSON.stringify(previewDraft) : ''}`;
@@ -475,6 +475,10 @@ export function parseResponse<O extends Operation>(
475
475
  !(result.backup_dir === null || typeof result.backup_dir === 'string'))
476
476
  )
477
477
  fail();
478
+ } else if (operation === 'review_reuse') {
479
+ if (!exact(result, ['draft','changes','mappings','dependencies','unresolved','blocked']) || !isDraft(result.draft) || !Array.isArray(result.changes) || !result.changes.every(isImportChange) ||
480
+ !object(result.mappings) || !exact(result.mappings,['instances','groups','alignments']) || !Object.values(result.mappings).every(m => object(m) && Object.entries(m).every(([key,value]) => /^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/u.test(key) && typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/u.test(value))) ||
481
+ !strings(result.dependencies) || !strings(result.blocked) || !Array.isArray(result.unresolved) || !result.unresolved.every(v => object(v) && exact(v,['scope','id','hint']) && ['main','subagent'].includes(String(v.scope)) && text(v.id) && text(v.hint))) fail();
478
482
  } else if (operation === 'review_import') {
479
483
  if (!exact(result, ['draft','changes']) || !isDraft(result.draft) || !Array.isArray(result.changes) || !result.changes.every(isImportChange)) fail();
480
484
  } else if (operation === 'import' || operation === 'preset') {
@@ -1,4 +1,6 @@
1
- import { packageManager, packageKey } from '../editor/package-manager.ts';
1
+ import { openChanges, changesKey } from '../editor/change-review.ts';
2
+ import { openReuse, reuseKey } from '../editor/reuse-manager.ts';
3
+ import { packageManager, packageKey, packageView } from '../editor/package-manager.ts';
2
4
  import { openDiagnosis, diagnosisKey } from '../editor/diagnosis-view.ts';
3
5
  import { openColors, colorsKey } from '../editor/color-manager.ts';
4
6
  import { SCENARIO_IDS, PREVIEW_WIDTHS, cyclePreview } from '../editor/preview-settings.ts';
@@ -16,12 +18,13 @@ import type { View } from '../session.ts';
16
18
  import { settingRows, adjustSetting } from './settings.ts';
17
19
  import { formRows, setFormValue } from './forms.ts';
18
20
  import { canEdit, validPreferenceValue } from '../preferences.ts';
21
+ import { contentColumns } from '../../ui/layout.ts';
19
22
  import { editorLayout } from '../../ui/client/help.ts';
20
23
  import { formSelection, pageSelection } from '../editor/navigation.ts';
21
24
  import { guidanceLines } from '../editor/guidance.ts';
22
25
  import { navigateReview } from '../editor/import-review.ts';
23
26
 
24
- export type Effect = 'packages' | 'diagnoseFile' | 'save' | 'finish' | 'close' | 'reload' | 'reconcile' | 'retry' | 'applyPreferences' | 'transfer' | 'previewBackground' | 'uiLanguage' | 'reviewPreview' | 'explain' | 'profiles' | 'sources' | null;
27
+ export type Effect = 'changes' | 'reuse' | 'packages' | 'diagnoseFile' | 'save' | 'finish' | 'close' | 'reload' | 'reconcile' | 'retry' | 'applyPreferences' | 'transfer' | 'previewBackground' | 'uiLanguage' | 'reviewPreview' | 'explain' | 'profiles' | 'sources' | null;
25
28
 
26
29
  export function cancelInput(view: View): void {
27
30
  const input = view.input, e = view.editor;
@@ -43,7 +46,13 @@ export function handleKey(view: View, event: NativeKeyEvent, columns: number, ro
43
46
  if (e) e.setSaveState(view.uncertain ? 'unknown' : view.busy ? 'pending' : 'idle');
44
47
  if (!e || view.busy) return null;
45
48
  if (event.overflow) { setMessage(view, 'message', localizedText('input.overflow')); return null; }
46
- if(e.packages)return packageKey(e.packages,event);
49
+ if(e.changeReview)return changesKey(e,event,view.language??'en',contentColumns(columns,rows),editorLayout(view,columns,rows).bodyRows);
50
+ if(e.reuse)return reuseKey(e,event,view.language??'en',contentColumns(columns,rows),editorLayout(view,columns,rows).bodyRows);
51
+ if(event.ctrl&&!event.text&&key.toLowerCase()==='t'&&!view.input){openChanges(e);return null;}
52
+ // Current Unix hosts reserve Ctrl+Z for suspend before Client receives it.
53
+ if(event.ctrl&&!event.text&&['z','_','r'].includes(key.toLowerCase())&&!view.input&&!e.sources&&!e.profiles&&!e.groupManager&&!e.alignmentManager&&!e.quick&&!e.review&&!e.colors&&!e.packages){e.undo(key.toLowerCase()==='r');return null;}
54
+ if(e.packages){packageView(e.packages,view.language??'en',contentColumns(columns,rows),editorLayout(view,columns,rows).bodyRows);return packageKey(e.packages,event);}
55
+ if(e.packageLocked){setMessage(view,'message',localizedText('package.ui.editor_locked'));return key==='escape'||event.ctrl&&key.toLowerCase()==='g'?'close':null;}
47
56
  if(e.diagnosis)return diagnosisKey(e,event);
48
57
  if(e.colors)return colorsKey(e,event,view.language ?? 'en');
49
58
  if(event.ctrl&&key.toLowerCase()==='l'&&!view.input&&!e.sources&&!e.profiles&&!e.groupManager&&!e.alignmentManager&&!e.quick&&!e.review&&!e.explanation){openDiagnosis(e);return null;}
@@ -215,6 +224,8 @@ export function handleKey(view: View, event: NativeKeyEvent, columns: number, ro
215
224
  return isSettings && e.setting === 'preview-background' ? 'previewBackground' : isSettings && e.setting === 'ui-language' ? 'uiLanguage' : null;
216
225
  } else if (key === 'return' || key === ' ' || key === 'space') {
217
226
  if (!isSettings) { if(!e.toggle(scope, selected))setMessage(view,"message",e.compositionError); }
227
+ else if(e.setting==='change-history'){openChanges(e);return null;}
228
+ else if(e.setting==='reuse-style'||e.setting==='reuse-groups'){openReuse(e,e.setting==='reuse-style'?'style':'groups');return null;}
218
229
  else if(e.setting==='diagnose-file'){openDiagnosis(e);return null;}
219
230
  else if(openColors(e,e.setting))return null;
220
231
  else if (e.setting === 'row-alignment') { openAlignments(e); return null; }
@@ -1,3 +1,4 @@
1
+ import { copyDraft } from '../editor/draft.ts';
1
2
  import { SCENARIO_IDS, PREVIEW_WIDTHS, cyclePreview } from '../editor/preview-settings.ts';
2
3
  import { setMessage, failureMessage } from '../i18n/messages.ts';
3
4
  import { text as localizedText } from '../i18n/index.ts';
@@ -16,7 +17,7 @@ export interface SettingRow {
16
17
 
17
18
  export function settingRows(view: View): SettingRow[] {
18
19
  const e = view.editor!;
19
- if (e.detail) return [...(!e.adding ? [{key:'item-explain',label:'Configuration and sample explanation',group:'Item format',value:'Enter',editable:true}] : []), {key:'item-guidance', label:'Sources and requirements', group:'Item format', value:'Enter: read guidance', editable:true},...(!e.adding?[{key:'diagnose-file',label:'Diagnose input file',group:'Item format',value:'Enter',editable:true}]:[]), ...formRows(view)];
20
+ if (e.detail) return [...(!e.adding ? [{key:'item-explain',label:'Configuration and sample explanation',group:'Item format',value:'Enter',editable:true}] : []), {key:'item-guidance', label:'Sources and requirements', group:'Item format', value:'Enter: read guidance', editable:true},...(!e.adding?[{key:'diagnose-file',label:'Diagnose input file',group:'Item format',value:'Enter',editable:true},{key:'reuse-style',label:'Copy / paste visual style',group:'Item format',value:'Enter',editable:true}]:[]), ...formRows(view)];
20
21
  if (e.page === 'layout') {
21
22
  const fields = formRows(view);
22
23
  if (!e.draft.display.instances.length) return fields;
@@ -109,6 +110,8 @@ export function settingRows(view: View): SettingRow[] {
109
110
  { key: 'quick-setup', label: 'Quick setup', group: 'Presets / portable files', value: 'Enter', editable: true },
110
111
  { key: 'preset-select', label: 'Preset', group: 'Presets / portable files', value: e.preset, editable: true },
111
112
  { key: 'preset-apply', label: 'Expand selected preset', group: 'Presets / portable files', value: 'replace draft; save later', editable: true },
113
+ {key:'change-history',label:'Changes and history',group:'Presets / portable files',value:'Enter',editable:true},
114
+ {key:'reuse-groups',label:'Reuse complete groups',group:'Presets / portable files',value:'Enter',editable:true},
112
115
  { key: 'import-file', label: 'Import file', group: 'Presets / portable files', value: 'file path; save later', editable: true },
113
116
  { key: 'export-file', label: 'Export current draft', group: 'Presets / portable files', value: 'new file path (may be unsaved)', editable: true },
114
117
  { key: 'package-management', label: 'Version and installation', group: 'Inspection', value: 'Enter', editable: true },
@@ -130,7 +133,7 @@ export function adjustSetting(view: View, delta: -1 | 1): void {
130
133
  if(e.setting==='preview-scenario'){e.previewScenario=cyclePreview(SCENARIO_IDS,e.previewScenario,delta);e.previewOffset=0;return;}
131
134
  if(e.setting==='preview-width'){e.previewWidth=cyclePreview(PREVIEW_WIDTHS,e.previewWidth as typeof PREVIEW_WIDTHS[number],delta);return;}
132
135
  if (!e.canMutateDraft() && !['ui-language','preview-background'].includes(e.setting) && !e.setting.startsWith('host-')) { setMessage(view, 'message', e.compositionError);return; }
133
- const d = e.draft.display;
136
+ const candidate = copyDraft(e.draft), d = candidate.display;
134
137
  const form = formRows(view).find((row) => row.key === e.setting);
135
138
  if (form) { adjustForm(view, form, delta); return; }
136
139
  if (e.setting === 'preset-select') {
@@ -181,8 +184,7 @@ export function adjustSetting(view: View, delta: -1 | 1): void {
181
184
  ) as typeof d.scope_labels;
182
185
  break;
183
186
  case 'vim-indicator':
184
- e.draft.host.hide_vim_mode_indicator =
185
- !e.draft.host.hide_vim_mode_indicator;
187
+ candidate.host.hide_vim_mode_indicator = !candidate.host.hide_vim_mode_indicator;
186
188
  break;
187
189
  case 'settings-subagent-statusline':
188
190
  d.subagents.enabled = !d.subagents.enabled;
@@ -208,7 +210,7 @@ export function adjustSetting(view: View, delta: -1 | 1): void {
208
210
  ),
209
211
  );
210
212
  e.acceptNumeric(field);
211
- break;
213
+ return;
212
214
  }
213
215
  default: {
214
216
  const p = view.preferences.find((p) => 'host-' + p.row.key === e.setting);
@@ -229,4 +231,5 @@ export function adjustSetting(view: View, delta: -1 | 1): void {
229
231
  p.result = '';
230
232
  }
231
233
  }
234
+ e.commitDraft(candidate);
232
235
  }
@@ -26,7 +26,7 @@ export function alignmentsKey(e:Editor,event:TextKey):null {
26
26
  if(m.page==='list'&&key==='enter') { const value=values[m.cursor];if(value){m.selected=value.id;m.page='actions';m.cursor=0;}else form(e); }
27
27
  else if(m.page==='actions'&&key==='enter') {
28
28
  if(m.cursor===0)form(e,values.find(v=>v.id===m.selected));
29
- else if(e.canMutateDraft()) { e.draft={...e.draft,display:editAlignment(d,m.selected!)};m.page='list';m.cursor=0; }
29
+ else if(e.canMutateDraft()) { e.commitDraft({...e.draft,display:editAlignment(d,m.selected!)});m.page='list';m.cursor=0; }
30
30
  } else if(m.page==='form'&&['left','right','enter','space',' '].includes(key)) {
31
31
  const rows=d.layout.rows.length;
32
32
  if(m.cursor===0)m.column=(m.column+(key==='left'?m.columns.length-1:1))%m.columns.length;
@@ -43,7 +43,7 @@ export function alignmentsKey(e:Editor,event:TextKey):null {
43
43
  if(!e.canMutateDraft())return null;
44
44
  try {
45
45
  let id=m.selected??newInstance('text',d.instances).id;while(!m.selected&&values.some(v=>v.id===id))id=newInstance('text',d.instances).id;
46
- e.draft={...e.draft,display:editAlignment(d,id,m.columns)};m.page='list';m.cursor=0;m.error=false;
46
+ e.commitDraft({...e.draft,display:editAlignment(d,id,m.columns)});m.page='list';m.cursor=0;m.error=false;
47
47
  }catch {m.error=true;}return null;
48
48
  }
49
49
  m.error=false;
@@ -0,0 +1,109 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ /** Shared review/recovery UI. File effects are injected by each editor host. */
3
+ import type { Editor } from './draft.ts';
4
+ import type { Draft, Operation, ReadResult, ResultFor } from '../generated-contracts.ts';
5
+ import { text, t, renderMessage, type Language, type LocalizedText } from '../i18n/index.ts';
6
+ import { createReview, navigateReview, reviewRows, type ReviewState } from './import-review.ts';
7
+ import { differences } from './import-differences.ts';
8
+ import { clone, semantic } from './history.ts';
9
+ import { inputKey, inputView, textInput, type TextInput, type TextKey } from './text-input.ts';
10
+ import { wrapText } from '../../ui/text.ts';
11
+
12
+ export interface ChangeReview {
13
+ kind: 'changes' | 'structure'; generation: number; target: string; comparison: number;
14
+ review: ReviewState; current: ReadResult | null; external: ReviewState | null; replacement: ReviewState | null;
15
+ confirm: boolean; input: TextInput | null; message: LocalizedText | null;
16
+ effect: 'read' | 'export' | 'reload' | null;
17
+ }
18
+ export function targetIdentity(current: ReadResult): string {
19
+ return semantic([current.configuration?.target ?? { kind: 'user' }, current.configuration?.profile_id ?? null, current.installation, current.backend_version, current.installed]);
20
+ }
21
+ export function openChanges(e: Editor, structure = false): void {
22
+ const candidate = structure ? e.structureProposal!.draft : e.draft;
23
+ e.changeReview = { kind: structure ? 'structure' : 'changes', generation: e.mutationGeneration, target: targetIdentity(e.baseline), comparison: 0,
24
+ review: createReview({ draft: clone(candidate), changes: differences(structure ? e.draft : e.baseline.draft, candidate) }),
25
+ current: null, external: null, replacement: null, confirm: false, input: null, message: null, effect: null };
26
+ }
27
+ function active(m: ChangeReview): ReviewState { return m.comparison === 1 ? m.external ?? m.review : m.comparison === 2 ? m.replacement ?? m.review : m.review; }
28
+ export function changePreview(e: Editor): Draft { return e.changeReview ? active(e.changeReview).result.draft : e.draft; }
29
+ export function changesKey(e: Editor, event: TextKey, language: Language, width: number, height: number): 'changes' | null {
30
+ const m = e.changeReview!, key = event.key === 'enter' ? 'return' : event.key;
31
+ if (event.overflow) return null;
32
+ if (!event.text && !event.paste && (key === 'escape' || event.ctrl && key.toLowerCase() === 'g')) {
33
+ if (m.input) m.input = null; else if (m.confirm) m.confirm = false; else { e.changeReview = null; e.structureProposal = null; }
34
+ return null;
35
+ }
36
+ if (m.input) {
37
+ if (key === 'return' && !event.text && !event.paste) { if (m.input.value.trim()) { m.effect = 'export'; return 'changes'; } }
38
+ else m.input = inputKey(m.input.value, m.input, event, 4096).state;
39
+ return null;
40
+ }
41
+ if (event.text || event.paste || event.ctrl || event.meta) return null;
42
+ if (m.confirm) {
43
+ if (key === 'return' && e.canMutateDraft()) { m.effect = 'reload'; return 'changes'; }
44
+ return null;
45
+ }
46
+ if (key.toLowerCase() === 'q') { e.changeReview = null; e.structureProposal = null; return null; }
47
+ if (key.toLowerCase() === 'a' && m.kind === 'structure') {
48
+ if (!e.acceptProposal()) m.message = text('history.stale');
49
+ return null;
50
+ }
51
+ if (m.kind === 'changes') {
52
+ if (['u','r'].includes(key.toLowerCase())) {
53
+ if (e.undo(key.toLowerCase() === 'r')) openChanges(e);
54
+ else m.message = e.compositionError;
55
+ return null;
56
+ }
57
+ if (key.toLowerCase() === 'c') { m.effect = 'read'; return 'changes'; }
58
+ if (key.toLowerCase() === 'e') { m.input = textInput('statusline-draft.json'); return null; }
59
+ if (key.toLowerCase() === 'l') {
60
+ if (!e.canMutateDraft()) m.message = e.compositionError;
61
+ else m.confirm = true;
62
+ return null;
63
+ }
64
+ if (key.toLowerCase() === 'k') {
65
+ if (m.current && e.adoptRevision(m.current, m.generation, m.target)) { e.changeReview = null; e.compositionError = text('history.retry_ready'); }
66
+ else m.message = text('history.retry_blocked');
67
+ return null;
68
+ }
69
+ if (key === 'tab' && m.current) { m.comparison = (m.comparison + 1) % 3; return null; }
70
+ }
71
+ navigateReview(active(m), key, language, width, Math.max(1, height - 3));
72
+ return null;
73
+ }
74
+ export function changesView(e: Editor, language: Language, width: number, height: number): { text: string; selected?: boolean }[] {
75
+ const m = e.changeReview!, title = t(m.kind === 'structure' ? 'history.structure' : 'history.title', language);
76
+ if (m.input) return wrapText([title, t('history.export_path', language), inputView({ ...m.input }, width), t('history.input_help', language)], width).slice(0, height).map(text => ({ text }));
77
+ if (m.confirm) return wrapText([title, t('history.confirm_discard', language)], width).slice(0, height).map(text => ({ text }));
78
+ const view = active(m), rows = reviewRows(view, language, width), capacity = Math.max(1, height - 3);
79
+ const scroll = Math.max(0, Math.min(view.scroll, rows.length - capacity));
80
+ const summary = m.kind === 'structure' ? t('history.repairs', language, { ids: e.structureProposal?.repairs.map(r => r.id).join(', ') ?? '' })
81
+ : t('history.counts', language, { undo: e.history.undo.length, redo: e.history.redo.length }) + ' · ' + t('history.comparison.' + m.comparison, language);
82
+ return [{ text: title }, { text: wrapText([m.message ? renderMessage(m.message, language) : summary], width)[0] ?? '' },
83
+ ...rows.slice(scroll, scroll + capacity).map(row => ({ text: row.text, selected: row.heading && row.section === view.selected })),
84
+ { text: t(m.kind === 'structure' ? 'history.structure_help' : 'history.help', language) + (e.history.trimmed ? ' · ' + t('history.trimmed', language) : '') }].slice(0, height);
85
+ }
86
+ export interface ReviewBackend { request<O extends Operation>(operation: O, payload?: unknown): Promise<ResultFor<O>> | ResultFor<O> }
87
+ export async function performChanges(e: Editor, backend: ReviewBackend): Promise<void> {
88
+ const m = e.changeReview, effect = m?.effect;
89
+ if (!m || !effect) return;
90
+ m.effect = null;
91
+ try {
92
+ const permitted = () => e.changeReview === m && m.generation === e.mutationGeneration && m.target === targetIdentity(e.baseline);
93
+ if (!permitted()) throw new Error('history.stale');
94
+ if (effect === 'export') {
95
+ await backend.request('export', { draft: clone(e.draft), path: m.input!.value, overwrite: false });
96
+ if (permitted()) { m.input = null; m.message = text('history.exported'); }
97
+ return;
98
+ }
99
+ const current = await backend.request('read', e.baseline.configuration ? { target: e.baseline.configuration.target } : {});
100
+ if (!permitted()) throw new Error('history.stale');
101
+ if (effect === 'reload') {
102
+ if (!e.canMutateDraft()) throw new Error('editor.save_locked');
103
+ e.committed(current); e.changeReview = null; return;
104
+ }
105
+ m.current = clone(current); m.external = createReview({ draft: clone(current.draft), changes: differences(e.baseline.draft, current.draft) });
106
+ m.replacement = createReview({ draft: clone(e.draft), changes: differences(current.draft, e.draft) });
107
+ m.comparison = 1; m.message = null;
108
+ } catch (error) { if (e.changeReview === m) m.message = text('history.failed', { detail: error instanceof Error ? error.message : String(error) }); }
109
+ }
@@ -128,7 +128,7 @@ export function colorsKey(e: Editor, event: TextKey, language: Language): null {
128
128
  const selected = rows[m.cursor]!;
129
129
  if (event.ctrl && key.toLowerCase() === 's' || key === 'return' && selected.id === 'apply') {
130
130
  if (e.canMutateDraft(m.generation)) {
131
- e.draft = colorDraft(e);
131
+ e.commitDraft(colorDraft(e));
132
132
  e.colors = null;
133
133
  }
134
134
  return null;
@@ -7,7 +7,9 @@ import type { SourceManager } from './source-manager.ts';
7
7
  import type { ProfileManager } from './profile-manager.ts';
8
8
  import type { QuickSetup } from './quick-setup.ts';
9
9
  import { t, text, type Language } from '../i18n/index.ts';
10
- import { alignmentConflicts } from './alignments.ts';
10
+ import { emptyHistory, remember, snapshot, boundHistory, semantic, type DraftHistory } from './history.ts';
11
+ import { repairStructure, type StructureProposal } from './structure.ts';
12
+ import { openChanges, targetIdentity, type ChangeReview } from './change-review.ts';
11
13
  import { nodes, newInstance, reconcileRows } from './instances.ts';
12
14
  import { isDraft } from '../backend.ts';
13
15
  import type {
@@ -44,6 +46,11 @@ export interface PendingSave {
44
46
  /** Pure tool draft. Persistence and host configuration calls live in the hook. */
45
47
  export class Editor {
46
48
  draft: Draft;
49
+ reuse: import('./reuse-manager.js').ReuseManager | null = null;
50
+ history: DraftHistory = emptyHistory();
51
+ changeReview: ChangeReview | null = null;
52
+ structureProposal: StructureProposal | null = null;
53
+ numericBefore: Draft | null = null;
47
54
  baseline: ReadResult;
48
55
  page: Page = 'main';
49
56
  previewScenario: import('./preview-settings.js').PreviewScenario = 'normal';
@@ -60,6 +67,8 @@ export class Editor {
60
67
  colors: import('./color-manager.js').ColorManager | null = null;
61
68
  explanation: ExplanationView | null = null;
62
69
  profiles: ProfileManager | null = null;
70
+ sourceDraftRegistered = false;
71
+ sourceDraftOwner = 'draft-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2);
63
72
  sources: SourceManager | null = null;
64
73
  taskViewer: import('./task-viewer.js').TaskViewer | null = null;
65
74
  packages: import('./package-manager.js').PackageManager | null = null;
@@ -78,11 +87,13 @@ export class Editor {
78
87
  buffers: Record<NumericField, string>;
79
88
  fieldErrors: Partial<Record<NumericField, string>> = {};
80
89
  fieldErrorMessages: Partial<Record<NumericField, LocalizedText>> = {};
90
+ packageLocked = false;
81
91
  saveState: 'idle' | 'pending' | 'unknown' = 'idle';
82
92
  pendingSave: PendingSave | null = null;
83
93
  mutationGeneration = 0;
84
94
 
85
95
  canMutateDraft(generation = this.mutationGeneration): boolean {
96
+ if (this.packageLocked) { this.compositionError=text('package.ui.editor_locked');return false; }
86
97
  if (this.saveState === 'idle' && generation === this.mutationGeneration) return true;
87
98
  this.compositionError = text('editor.save_locked');
88
99
  return false;
@@ -131,8 +142,7 @@ export class Editor {
131
142
  };
132
143
  }
133
144
 
134
- replaceDraft(draft: Draft): void {
135
- if (!this.canMutateDraft()) return;
145
+ private restoreDraft(draft: Draft): void {
136
146
  this.draft = copyDraft(draft);
137
147
  for (const scope of ['main', 'subagent'] as const) {
138
148
  this.order[scope] = nodes(this.draft,scope).map(i=>i.id);
@@ -148,6 +158,50 @@ export class Editor {
148
158
  this.review = null; this.alignmentManager = null;
149
159
  }
150
160
 
161
+ /** The only accepted draft transition; tentative input and candidates stay separate. */
162
+ commitDraft(draft: Draft, label: LocalizedText = text('history.edit')): boolean {
163
+ if (!this.canMutateDraft() || !isDraft(draft)) return false;
164
+ if (semantic(this.draft) === semantic(draft)) return true;
165
+ remember(this.history, this.draft, label);
166
+ this.draft = copyDraft(draft); this.mutationGeneration++;
167
+ for (const scope of ['main', 'subagent'] as const) {
168
+ this.order[scope] = nodes(this.draft, scope).map(n => n.id);
169
+ if (!this.order[scope].includes(this.selected[scope])) this.selected[scope] = this.order[scope][0] ?? '';
170
+ }
171
+ return true;
172
+ }
173
+ replaceDraft(draft: Draft, label: LocalizedText = text('history.replace')): void {
174
+ if (this.commitDraft(draft, label)) this.restoreDraft(draft);
175
+ }
176
+ undo(redo = false): boolean {
177
+ if (!this.canMutateDraft() || this.numericBefore) return false;
178
+ const source = redo ? this.history.redo : this.history.undo, target = redo ? this.history.undo : this.history.redo;
179
+ const entry = source.pop(); if (!entry) return false;
180
+ target.push(snapshot(this.draft, entry.label)); boundHistory(this.history);
181
+ this.restoreDraft(entry.draft); this.mutationGeneration++;
182
+ this.groupManager = null; this.colors = null; this.structureProposal = null; this.changeReview = null;
183
+ return true;
184
+ }
185
+ applyStructure(draft: Draft): boolean {
186
+ if (!this.canMutateDraft()) return false;
187
+ try {
188
+ const proposal = repairStructure(this.draft, draft);
189
+ if (!proposal.repairs.length) return this.commitDraft(proposal.draft, text('history.structure'));
190
+ this.structureProposal = { ...proposal, generation: this.mutationGeneration, target: targetIdentity(this.baseline) };
191
+ openChanges(this, true); return true;
192
+ } catch { this.compositionError = text('composition.invalid'); return false; }
193
+ }
194
+ acceptProposal(): boolean {
195
+ const proposal = this.structureProposal;
196
+ if (!proposal || !this.canMutateDraft(proposal.generation) || targetIdentity(this.baseline) !== proposal.target || semantic(this.draft) !== semantic(proposal.base)) return false;
197
+ if (!this.commitDraft(proposal.draft, text('history.structure'))) return false;
198
+ this.structureProposal = null; this.changeReview = null; this.groupManager = null; this.alignmentManager = null; return true;
199
+ }
200
+ adoptRevision(current: ReadResult, generation: number, target: string): boolean {
201
+ if (!this.canMutateDraft(generation) || targetIdentity(current) !== target || targetIdentity(this.baseline) !== target || !current.installed) return false;
202
+ this.baseline = { ...current, draft: copyDraft(current.draft) }; this.mutationGeneration++; return true;
203
+ }
204
+
151
205
  get modified(): boolean {
152
206
  return (
153
207
  !sameDraft(this.draft, this.baseline.draft) ||
@@ -220,9 +274,9 @@ export class Editor {
220
274
  const target = scope === 'main' ? draft.display : draft.display.subagents;
221
275
  target.groups = reconcileGroups(target.groups, list);
222
276
  if(scope==='main')reconcileRows(draft);
223
- if(!this.acceptStructure(draft))return false;
277
+ if(!this.applyStructure(draft))return false;
224
278
  if(this.adding){this.closePicker(scope);this.search[scope]='';this.category[scope]='all';}
225
- this.draft=draft;this.order[scope]=list.map(i=>i.id);this.selected[scope]=next;
279
+ if (!this.structureProposal) { this.order[scope]=list.map(i=>i.id);this.selected[scope]=next; }
226
280
  return true;
227
281
  }
228
282
 
@@ -256,7 +310,7 @@ export class Editor {
256
310
  if(!node)return false;
257
311
  node.enabled=!node.enabled;
258
312
  if(!isDraft(draft))return false;
259
- this.draft=draft;return true;
313
+ return this.commitDraft(draft, text('history.edit'));
260
314
  }
261
315
 
262
316
  move(scope: Scope, delta: -1 | 1): boolean {
@@ -274,20 +328,14 @@ export class Editor {
274
328
  const [moving] = ordered.splice(sourceIndex, 1);
275
329
  ordered.splice(ordered.findIndex(node => node.id === target) + (delta > 0 ? 1 : 0), 0, moving!);
276
330
  if (scope === 'main') reconcileRows(draft);
277
- if (!this.acceptStructure(draft)) return false;
278
- this.draft = draft;
279
- this.order[scope] = ordered.map(node => node.id);
331
+ if (!this.applyStructure(draft)) return false;
332
+ if (!this.structureProposal) this.order[scope] = ordered.map(node => node.id);
280
333
  return true;
281
334
  }
282
335
 
283
- private acceptStructure(draft: Draft): boolean {
284
- const ids = alignmentConflicts(draft.display);
285
- if (ids.length) this.compositionError = text('alignment.references', { ids: ids.join(', ') });
286
- return isDraft(draft);
287
- }
288
-
289
336
  setBuffer(field: NumericField, value: string): void {
290
337
  if (!this.canMutateDraft()) return;
338
+ this.numericBefore ??= copyDraft(this.draft);
291
339
  this.activeNumeric = field;
292
340
  this.buffers[field] = value;
293
341
  delete this.fieldErrors[field];
@@ -295,6 +343,7 @@ export class Editor {
295
343
  }
296
344
 
297
345
  cancelNumeric(field?: NumericField): void {
346
+ if (this.numericBefore) { this.draft = copyDraft(this.numericBefore); this.numericBefore = null; }
298
347
  for (const key of field ? [field] : NUMERIC_FIELDS) {
299
348
  this.buffers[key] = String(this.draft.host[key]);
300
349
  delete this.fieldErrors[key];
@@ -303,7 +352,7 @@ export class Editor {
303
352
  if (!field || this.activeNumeric === field) this.activeNumeric = null;
304
353
  }
305
354
 
306
- acceptNumeric(field?: NumericField): boolean {
355
+ acceptNumeric(field?: NumericField, preview = false): boolean {
307
356
  if (!this.canMutateDraft()) return false;
308
357
  const values: Partial<Record<NumericField, number | 'event'>> = {};
309
358
  const fields = field ? [field] : NUMERIC_FIELDS;
@@ -315,18 +364,22 @@ export class Editor {
315
364
  else values[key] = parsed.value;
316
365
  }
317
366
  if (fields.some((key) => this.fieldErrors[key])) return false;
318
- if (values.padding !== undefined)
319
- this.draft.host.padding = values.padding as number;
320
- if (values.refresh_interval !== undefined)
321
- this.draft.host.refresh_interval = values.refresh_interval;
367
+ const candidate = copyDraft(this.draft);
368
+ if (values.padding !== undefined) candidate.host.padding = values.padding as number;
369
+ if (values.refresh_interval !== undefined) candidate.host.refresh_interval = values.refresh_interval;
370
+ if (preview) { this.draft = candidate; return true; }
371
+ if (this.numericBefore) this.draft = copyDraft(this.numericBefore);
372
+ this.numericBefore = null;
373
+ if (!this.commitDraft(candidate)) return false;
322
374
  this.cancelNumeric(field);
323
375
  return true;
324
376
  }
325
377
 
326
378
  committed(current: ReadResult): void {
327
379
  this.pendingSave=null;this.setSaveState('idle');
380
+ this.numericBefore = null; this.history = emptyHistory(); this.structureProposal = null; this.changeReview = null;
328
381
  this.baseline = { ...current, draft: copyDraft(current.draft) };
329
- this.draft = copyDraft(current.draft);
382
+ this.restoreDraft(current.draft); this.mutationGeneration++;
330
383
  this.cancelNumeric();
331
384
  }
332
385
 
@@ -1,6 +1,5 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
2
  import { GRADIENT_KEYS, GRADIENT_DEFAULTS, GRADIENT_PRESETS, parseGradient, gradientName } from './gradients.ts';
3
- import { alignmentConflicts } from './alignments.ts';
4
3
  import { COST_RATE_DEFAULTS } from './cost-rate.ts';
5
4
  import { INDICATOR_DEFAULTS } from './indicators.ts';
6
5
  import { nodes } from './instances.ts';
@@ -154,16 +153,10 @@ export function setFormValue(view: FormView, current: FormRow, raw: string | boo
154
153
  }
155
154
  else
156
155
  write(draft.display, spec.key, value);
157
- const ids = alignmentConflicts(draft.display);
158
- if (!isDraft(draft)) {
159
- if (ids.length) {
160
- setMessage(view, 'message', localizedText('alignment.references', { ids: ids.join(', ') }));
161
- return false;
162
- }
163
- setMessage(view, "message", localizedText("native.lib.client.forms.invalid_value_check_thresholds_text_and_width_constraints"));
156
+ if (!e.applyStructure(draft)) {
157
+ setMessage(view, 'message', e.compositionError.key === 'composition.invalid' ? localizedText('native.lib.client.forms.invalid_value_check_thresholds_text_and_width_constraints') : e.compositionError);
164
158
  return false;
165
159
  }
166
- e.draft = draft;
167
160
  return true;
168
161
  }
169
162
  export function adjustForm(view: FormView, current: FormRow, delta: -1 | 1): boolean {
@@ -34,9 +34,8 @@ function apply(e: Editor, edit: GroupEdit): void {
34
34
  const m = e.groupManager!;
35
35
  if (!e.canMutateDraft()) { m.error=true;m.errorMessage=e.compositionError;return; }
36
36
  try {
37
- const display = editGroup(e.draft.display, m.scope, edit, () => newInstance('text', groupScope(e.draft.display, m.scope).instances).id);
38
- if (!isDraft({ ...e.draft, display })) throw new Error('invalid');
39
- e.draft = { ...e.draft, display }; e.order[m.scope] = groupScope(display, m.scope).instances.map(n => n.id);
37
+ const display = editGroup(e.draft.display, m.scope, edit, () => newInstance('text', groupScope(e.draft.display, m.scope).instances).id, false);
38
+ if (!e.applyStructure({ ...e.draft, display })) throw new Error('invalid');
40
39
  m.page = 'list'; m.cursor = 0; m.error = false;
41
40
  } catch (error) { m.error = true; m.errorMessage = error instanceof AlignmentReferenceError ? text('alignment.references', { ids: error.ids.join(', ') }) : undefined; }
42
41
  }