@fbincon/claude-code-statusline 3.8.0 → 3.9.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 (161) hide show
  1. package/README.md +77 -77
  2. package/candidate.json +294 -231
  3. package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.js +18 -4
  4. package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.js.map +1 -1
  5. package/node_modules/@fbincon/statusline-cli/dist/src/config/commands.js +26 -1
  6. package/node_modules/@fbincon/statusline-cli/dist/src/config/commands.js.map +1 -1
  7. package/node_modules/@fbincon/statusline-cli/dist/src/config/profile-command.js +7 -2
  8. package/node_modules/@fbincon/statusline-cli/dist/src/config/profile-command.js.map +1 -1
  9. package/node_modules/@fbincon/statusline-cli/dist/src/config/selective-import.d.ts +3 -0
  10. package/node_modules/@fbincon/statusline-cli/dist/src/config/selective-import.js +40 -0
  11. package/node_modules/@fbincon/statusline-cli/dist/src/config/selective-import.js.map +1 -0
  12. package/node_modules/@fbincon/statusline-cli/dist/src/help.js +3 -0
  13. package/node_modules/@fbincon/statusline-cli/dist/src/help.js.map +1 -1
  14. package/node_modules/@fbincon/statusline-cli/dist/src/integration/mods.d.ts +4 -3
  15. package/node_modules/@fbincon/statusline-cli/dist/src/integration/mods.js +14 -13
  16. package/node_modules/@fbincon/statusline-cli/dist/src/integration/mods.js.map +1 -1
  17. package/node_modules/@fbincon/statusline-cli/dist/src/integration/resources.d.ts +5 -2
  18. package/node_modules/@fbincon/statusline-cli/dist/src/integration/resources.js +8 -6
  19. package/node_modules/@fbincon/statusline-cli/dist/src/integration/resources.js.map +1 -1
  20. package/node_modules/@fbincon/statusline-cli/dist/src/management/integration.js +12 -1
  21. package/node_modules/@fbincon/statusline-cli/dist/src/management/integration.js.map +1 -1
  22. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition-runner.d.ts +1 -0
  23. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition-runner.js +16 -0
  24. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition-runner.js.map +1 -0
  25. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.d.ts +3 -0
  26. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js +96 -0
  27. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js.map +1 -0
  28. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +1 -1
  29. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +22 -6
  30. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js.map +1 -1
  31. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/.claude-plugin/plugin.json +1 -1
  32. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/hooks/register.ts +1 -1
  33. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/backend.ts +7 -4
  34. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +9 -6
  35. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/settings.ts +5 -1
  36. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/alignment-manager.ts +59 -0
  37. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/alignments.ts +77 -0
  38. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/appearance.ts +3 -2
  39. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +17 -4
  40. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/forms.ts +18 -4
  41. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/gradients.ts +29 -0
  42. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/group-manager.ts +5 -3
  43. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/groups.ts +2 -0
  44. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/import-differences.ts +72 -0
  45. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/import-review.ts +49 -2
  46. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/import-selection.ts +38 -0
  47. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/profile-manager.ts +14 -5
  48. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +9 -3
  49. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +210 -6
  50. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/presentation.ts +2 -0
  51. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/session.ts +3 -1
  52. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +26 -21
  53. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +6 -2
  54. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/help.ts +1 -1
  55. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/.claude-plugin/plugin.json +1 -1
  56. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/resource-manifest.json +3 -3
  57. package/node_modules/@fbincon/statusline-core/dist/src/config/defaults.js +1 -1
  58. package/node_modules/@fbincon/statusline-core/dist/src/config/display.d.ts +1 -1
  59. package/node_modules/@fbincon/statusline-core/dist/src/config/display.js +13 -4
  60. package/node_modules/@fbincon/statusline-core/dist/src/config/display.js.map +1 -1
  61. package/node_modules/@fbincon/statusline-core/dist/src/config/editor-fields.js +1 -1
  62. package/node_modules/@fbincon/statusline-core/dist/src/config/editor-fields.js.map +1 -1
  63. package/node_modules/@fbincon/statusline-core/dist/src/config/formatting.js +11 -4
  64. package/node_modules/@fbincon/statusline-core/dist/src/config/formatting.js.map +1 -1
  65. package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.d.ts +2 -4
  66. package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.js +2 -83
  67. package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.js.map +1 -1
  68. package/node_modules/@fbincon/statusline-core/dist/src/config/instances.js +12 -3
  69. package/node_modules/@fbincon/statusline-core/dist/src/config/instances.js.map +1 -1
  70. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +15 -3
  71. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js +2 -2
  72. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js.map +1 -1
  73. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.d.ts +18 -0
  74. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js +112 -0
  75. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js.map +1 -0
  76. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignments.d.ts +21 -0
  77. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignments.js +117 -0
  78. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignments.js.map +1 -0
  79. package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.js +3 -2
  80. package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.js.map +1 -1
  81. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js +8 -4
  82. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js.map +1 -1
  83. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.d.ts +4 -0
  84. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +16 -3
  85. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
  86. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js +24 -4
  87. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js.map +1 -1
  88. package/node_modules/@fbincon/statusline-core/dist/src/editor/gradients.d.ts +16 -0
  89. package/node_modules/@fbincon/statusline-core/dist/src/editor/gradients.js +31 -0
  90. package/node_modules/@fbincon/statusline-core/dist/src/editor/gradients.js.map +1 -0
  91. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.d.ts +2 -1
  92. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js +5 -3
  93. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js.map +1 -1
  94. package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.js +3 -0
  95. package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.js.map +1 -1
  96. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-differences.d.ts +4 -0
  97. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-differences.js +86 -0
  98. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-differences.js.map +1 -0
  99. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-review.d.ts +8 -2
  100. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-review.js +67 -1
  101. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-review.js.map +1 -1
  102. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-selection.d.ts +7 -0
  103. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-selection.js +42 -0
  104. package/node_modules/@fbincon/statusline-core/dist/src/editor/import-selection.js.map +1 -0
  105. package/node_modules/@fbincon/statusline-core/dist/src/editor/profile-manager.d.ts +4 -1
  106. package/node_modules/@fbincon/statusline-core/dist/src/editor/profile-manager.js +16 -4
  107. package/node_modules/@fbincon/statusline-core/dist/src/editor/profile-manager.js.map +1 -1
  108. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +204 -0
  109. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +210 -6
  110. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
  111. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js +2 -1
  112. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js.map +1 -1
  113. package/node_modules/@fbincon/statusline-core/dist/src/release.d.ts +1 -1
  114. package/node_modules/@fbincon/statusline-core/dist/src/release.js +1 -1
  115. package/node_modules/@fbincon/statusline-core/dist/src/rendering/alignment.d.ts +3 -0
  116. package/node_modules/@fbincon/statusline-core/dist/src/rendering/alignment.js +97 -0
  117. package/node_modules/@fbincon/statusline-core/dist/src/rendering/alignment.js.map +1 -0
  118. package/node_modules/@fbincon/statusline-core/dist/src/rendering/components.d.ts +1 -0
  119. package/node_modules/@fbincon/statusline-core/dist/src/rendering/components.js.map +1 -1
  120. package/node_modules/@fbincon/statusline-core/dist/src/rendering/diagnose.js +2 -3
  121. package/node_modules/@fbincon/statusline-core/dist/src/rendering/diagnose.js.map +1 -1
  122. package/node_modules/@fbincon/statusline-core/dist/src/rendering/explain.js +2 -0
  123. package/node_modules/@fbincon/statusline-core/dist/src/rendering/explain.js.map +1 -1
  124. package/node_modules/@fbincon/statusline-core/dist/src/rendering/gradients.d.ts +13 -0
  125. package/node_modules/@fbincon/statusline-core/dist/src/rendering/gradients.js +68 -0
  126. package/node_modules/@fbincon/statusline-core/dist/src/rendering/gradients.js.map +1 -0
  127. package/node_modules/@fbincon/statusline-core/dist/src/rendering/groups.js +5 -4
  128. package/node_modules/@fbincon/statusline-core/dist/src/rendering/groups.js.map +1 -1
  129. package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.d.ts +4 -1
  130. package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js +41 -15
  131. package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js.map +1 -1
  132. package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.d.ts +1 -0
  133. package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.js +9 -3
  134. package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.js.map +1 -1
  135. package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.d.ts +4 -0
  136. package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.js +15 -1
  137. package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.js.map +1 -1
  138. package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js +7 -5
  139. package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js.map +1 -1
  140. package/node_modules/@fbincon/statusline-core/dist/src/rendering/trace.d.ts +3 -0
  141. package/node_modules/@fbincon/statusline-core/dist/src/rendering/trace.js +3 -0
  142. package/node_modules/@fbincon/statusline-core/dist/src/rendering/trace.js.map +1 -1
  143. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +35 -1
  144. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +35 -1
  145. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +35 -1
  146. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +35 -1
  147. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +35 -1
  148. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +35 -1
  149. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js +5 -0
  150. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js.map +1 -1
  151. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/presentation.js +5 -0
  152. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/presentation.js.map +1 -1
  153. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js +2 -2
  154. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js.map +1 -1
  155. package/node_modules/@fbincon/statusline-tui/dist/src/drawing.js +1 -1
  156. package/node_modules/@fbincon/statusline-tui/dist/src/drawing.js.map +1 -1
  157. package/node_modules/@fbincon/statusline-tui/dist/src/session.js +1 -1
  158. package/node_modules/@fbincon/statusline-tui/dist/src/session.js.map +1 -1
  159. package/node_modules/@fbincon/statusline-tui/dist/src/state.js +12 -5
  160. package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
  161. package/package.json +3 -3
@@ -0,0 +1,77 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ /** Stable references to whole units; row positions are resolved from the current explicit layout. */
3
+ import type { AlignmentRef, DisplayDraft, GroupDraft, InstanceDraft, LayoutDraft } from '../generated-contracts.ts';
4
+ export interface AlignmentUnit { ref: AlignmentRef; ids: string[]; row: number; side: 'left' | 'right'; position: number }
5
+ export const refKey = (ref: AlignmentRef): string => ref.kind + ':' + ref.id;
6
+ const object = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);
7
+ const identifier = (v: unknown): v is string => typeof v === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/u.test(v);
8
+ export function alignmentUnits(layout: LayoutDraft, nodes: readonly InstanceDraft[], groups: readonly GroupDraft[]): AlignmentUnit[] {
9
+ const byId = new Map(nodes.map(n => [n.id,n])), membership = new Map(groups.flatMap(g=>g.member_ids.map(id=>[id,g] as const)));
10
+ return layout.rows.flatMap((ids,row) => {
11
+ const seen = new Set<string>(), units: AlignmentUnit[] = []; let side: 'left' | 'right' = 'left';
12
+ for (const id of ids) {
13
+ if (byId.get(id)?.type_id === 'spacer') { side='right';continue; }
14
+ const group=membership.get(id); if(group && seen.has(group.id))continue;
15
+ if(group)seen.add(group.id);
16
+ units.push({ref:{kind:group?'group':'instance',id:group?.id??id},ids:group?[...group.member_ids]:[id],row,side,position:units.length});
17
+ }
18
+ return units;
19
+ });
20
+ }
21
+ export function validAlignments(value: unknown, layout: LayoutDraft, nodes: readonly InstanceDraft[], groups: readonly GroupDraft[]): boolean {
22
+ if(value === undefined)return true;
23
+ if(!Array.isArray(value)||value.length>nodes.length)return false;
24
+ if(!value.length)return true;
25
+ if(layout.mode!=='explicit')return false;
26
+ const units=new Map(alignmentUnits(layout,nodes,groups).map(u=>[refKey(u.ref),u])), used=new Set<string>(), ids=new Set<string>(), ownership=new Map<string,string>();
27
+ return value.every(alignment=>{
28
+ if(!object(alignment)||Object.keys(alignment).sort().join(',')!=='columns,id'||!identifier(alignment.id)||ids.has(alignment.id)||
29
+ !Array.isArray(alignment.columns)||!alignment.columns.length||alignment.columns.length>nodes.length)return false;
30
+ ids.add(alignment.id);const positions=new Map<string,number>();
31
+ return alignment.columns.every(column=>{
32
+ if(!Array.isArray(column)||column.length<2||column.length>layout.rows.length)return false;
33
+ const rows=new Set<number>();let side: string|undefined;
34
+ return column.every(ref=>{
35
+ if(!object(ref)||Object.keys(ref).sort().join(',')!=='id,kind'||!['instance','group'].includes(String(ref.kind))||!identifier(ref.id))return false;
36
+ const key=refKey(ref as unknown as AlignmentRef), unit=units.get(key);
37
+ if(!unit||used.has(key)||rows.has(unit.row)||side!==undefined&&unit.side!==side)return false;
38
+ const owner=unit.row+':'+unit.side, previous=positions.get(owner);
39
+ if(ownership.has(owner)&&ownership.get(owner)!==alignment.id||previous!==undefined&&previous>=unit.position)return false;
40
+ ownership.set(owner,alignment.id as string);positions.set(owner,unit.position);rows.add(unit.row);used.add(key);side=unit.side;return true;
41
+ });
42
+ });
43
+ });
44
+ }
45
+ export function editAlignment(display: DisplayDraft, id: string, columns?: AlignmentRef[][]): DisplayDraft {
46
+ const result=JSON.parse(JSON.stringify(display)) as DisplayDraft, values=result.layout.alignments??[];
47
+ if(!identifier(id))throw new Error('alignment.invalid');
48
+ const index=values.findIndex(v=>v.id===id);
49
+ if(columns===undefined) { if(index<0)throw new Error('alignment.invalid');values.splice(index,1); }
50
+ else { const value={id,columns};if(index<0)values.push(value);else values[index]=value; }
51
+ result.layout.alignments=values;
52
+ if(!validAlignments(values,result.layout,result.instances,result.groups))throw new Error('alignment.invalid');
53
+ return result;
54
+ }
55
+ /** Identify relationships that a proposed structural edit would invalidate. */
56
+ export function alignmentConflicts(display: DisplayDraft): string[] {
57
+ const values = display.layout.alignments;
58
+ if (validAlignments(values, display.layout, display.instances, display.groups)) return [];
59
+ if (!Array.isArray(values)) return [];
60
+ const named = values.filter(value => object(value) && identifier(value.id));
61
+ const invalid = named.filter(value => !validAlignments([value], display.layout, display.instances, display.groups));
62
+ return (invalid.length ? invalid : named).map(value => value.id);
63
+ }
64
+ export function requireAlignments(display: DisplayDraft): void {
65
+ const ids = alignmentConflicts(display);
66
+ if (ids.length) throw new AlignmentReferenceError(ids);
67
+ }
68
+ export class AlignmentReferenceError extends Error {
69
+ constructor(readonly ids: string[]) { super('alignment.references'); }
70
+ }
71
+ export function parseAlignmentColumns(raw: string): AlignmentRef[][] {
72
+ return raw.split(';').map(column=>column.split(',').map(token=>{
73
+ const match=/^(instance|group):([A-Za-z0-9][A-Za-z0-9_-]{0,95})$/u.exec(token.trim());
74
+ if(!match)throw new Error('alignment.invalid');
75
+ return {kind:match[1] as AlignmentRef['kind'],id:match[2]!};
76
+ }));
77
+ }
@@ -1,4 +1,5 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
+ import { GRADIENT_FIELDS } from './gradients.ts';
2
3
  import { COST_RATE_FIELD } from './cost-rate.ts';
3
4
  import { supportsIndicator, INDICATOR_FIELDS } from './indicators.ts';
4
5
  /** Pure controls/validation from Python's scoped visibility capabilities. */
@@ -27,13 +28,13 @@ export function supportedFormats(scope: Scope, id: string, capability?: ItemCapa
27
28
 
28
29
  export function itemFields(fields: EditorField[], scope: Scope, id: string, capability?: ItemCapability): EditorField[] {
29
30
  if(id==='spacer')return [];
30
- if(id==='text')return [{key:'text',label:'Literal text',group:'Item format',kind:'text',choices:[],minimum:0,maximum:256,nullable:false},
31
+ if(id==='text')return [...GRADIENT_FIELDS,{key:'text',label:'Literal text',group:'Item format',kind:'text',choices:[],minimum:0,maximum:256,nullable:false},
31
32
  ...fields.filter(f=>['label','icon','foreground','background','priority','max_width'].includes(f.key))];
32
33
  const choices = capability?.visibility ?? visibilityChoices(scope, id);
33
34
  const links: EditorField[] = capability?.link ? [{key:'link',label:'Links',group:'Item format',kind:'choice',choices:['off','auto','on'],minimum:0,maximum:0,nullable:false}] : [];
34
35
  const formats = supportedFormats(scope, id, capability);
35
36
  fields = fields.filter(field => !Object.hasOwn(FORMAT_CHOICES,field.key) || formats.includes(field.key));
36
- return [...(scope === 'main' && id === 'session-cost-rate' ? [COST_RATE_FIELD] : []), ...(supportsIndicator(scope, id) ? INDICATOR_FIELDS : []), ...links, ...fields.filter(spec => (spec.key !== 'visibility' || choices.length > 1) &&
37
+ return [...GRADIENT_FIELDS, ...(scope === 'main' && id === 'session-cost-rate' ? [COST_RATE_FIELD] : []), ...(supportsIndicator(scope, id) ? INDICATOR_FIELDS : []), ...links, ...fields.filter(spec => (spec.key !== 'visibility' || choices.length > 1) &&
37
38
  (spec.key !== 'visibility_threshold' || choices.includes('used-at-least')))
38
39
  .map(spec => spec.key === 'visibility' ? {...spec, choices} : spec)];
39
40
  }
@@ -1,11 +1,13 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
+ import type { AlignmentManager } from './alignment-manager.ts';
2
3
  import type { GroupManager } from './group-manager.ts';
3
4
  import { reconcileGroups, insertionAfter } from './groups.ts';
4
5
  import type { ExplanationView } from './explanation.ts';
5
6
  import type { SourceManager } from './source-manager.ts';
6
7
  import type { ProfileManager } from './profile-manager.ts';
7
8
  import type { QuickSetup } from './quick-setup.ts';
8
- import { t, type Language } from '../i18n/index.ts';
9
+ import { t, text, type Language } from '../i18n/index.ts';
10
+ import { alignmentConflicts } from './alignments.ts';
9
11
  import { nodes, newInstance, reconcileRows } from './instances.ts';
10
12
  import { isDraft } from '../backend.ts';
11
13
  import type {
@@ -50,6 +52,8 @@ export class Editor {
50
52
  profiles: ProfileManager | null = null;
51
53
  sources: SourceManager | null = null;
52
54
  groupManager: GroupManager | null = null;
55
+ alignmentManager: AlignmentManager | null = null;
56
+ compositionError: LocalizedText = text('composition.invalid');
53
57
  preset = 'minimal';
54
58
  path = 'statusline.json';
55
59
  pendingTransfer: 'import' | 'export' | 'preset' | null = null;
@@ -95,7 +99,7 @@ export class Editor {
95
99
  this.detail = null;
96
100
  this.guidanceScroll = null;
97
101
  this.explanation = null;
98
- this.review = null;
102
+ this.review = null; this.alignmentManager = null;
99
103
  }
100
104
 
101
105
  get modified(): boolean {
@@ -153,6 +157,7 @@ export class Editor {
153
157
  this.adding=false;this.pickerSaved=null;
154
158
  }
155
159
  instanceAction(scope: Scope, action:'add'|'copy'|'remove', typeId?:string): boolean {
160
+ this.compositionError = text('composition.invalid');
156
161
  const draft=copyDraft(this.draft), list=nodes(draft,scope);
157
162
  const selected=this.adding ? this.pickerSaved?.selected : this.selected[scope];
158
163
  const index=list.findIndex(i=>i.id===selected);
@@ -168,7 +173,7 @@ export class Editor {
168
173
  const target = scope === 'main' ? draft.display : draft.display.subagents;
169
174
  target.groups = reconcileGroups(target.groups, list);
170
175
  if(scope==='main')reconcileRows(draft);
171
- if(!isDraft(draft))return false;
176
+ if(!this.acceptStructure(draft))return false;
172
177
  if(this.adding){this.closePicker(scope);this.search[scope]='';this.category[scope]='all';}
173
178
  this.draft=draft;this.order[scope]=list.map(i=>i.id);this.selected[scope]=next;
174
179
  return true;
@@ -197,6 +202,7 @@ export class Editor {
197
202
  }
198
203
 
199
204
  toggle(scope: Scope, id: string): boolean {
205
+ this.compositionError = text('composition.invalid');
200
206
  if(this.adding)return this.instanceAction(scope,'add',id);
201
207
  const draft=copyDraft(this.draft),node=nodes(draft,scope).find(i=>i.id===id);
202
208
  if(!node)return false;
@@ -206,6 +212,7 @@ export class Editor {
206
212
  }
207
213
 
208
214
  move(scope: Scope, delta: -1 | 1): boolean {
215
+ this.compositionError = text('composition.invalid');
209
216
  if (this.adding || this.filtered(scope)) return false;
210
217
  const visible = this.visible(scope).map((item) => item.id as string);
211
218
  const id = this.selected[scope];
@@ -218,12 +225,18 @@ export class Editor {
218
225
  const [moving] = ordered.splice(sourceIndex, 1);
219
226
  ordered.splice(ordered.findIndex(node => node.id === target) + (delta > 0 ? 1 : 0), 0, moving!);
220
227
  if (scope === 'main') reconcileRows(draft);
221
- if (!isDraft(draft)) return false;
228
+ if (!this.acceptStructure(draft)) return false;
222
229
  this.draft = draft;
223
230
  this.order[scope] = ordered.map(node => node.id);
224
231
  return true;
225
232
  }
226
233
 
234
+ private acceptStructure(draft: Draft): boolean {
235
+ const ids = alignmentConflicts(draft.display);
236
+ if (ids.length) this.compositionError = text('alignment.references', { ids: ids.join(', ') });
237
+ return isDraft(draft);
238
+ }
239
+
227
240
  setBuffer(field: NumericField, value: string): void {
228
241
  this.activeNumeric = field;
229
242
  this.buffers[field] = value;
@@ -1,4 +1,6 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
+ import { GRADIENT_KEYS, GRADIENT_DEFAULTS, GRADIENT_PRESETS, parseGradient, gradientName } from './gradients.ts';
3
+ import { alignmentConflicts } from './alignments.ts';
2
4
  import { COST_RATE_DEFAULTS } from './cost-rate.ts';
3
5
  import { INDICATOR_DEFAULTS } from './indicators.ts';
4
6
  import { nodes } from './instances.ts';
@@ -57,7 +59,7 @@ function format(raw: unknown): string {
57
59
  return raw === null ? 'inherit' : typeof raw === 'boolean' ? raw ? 'on' : 'off' : String(raw);
58
60
  }
59
61
  function row(spec: EditorField, key: string, valueRaw: unknown): FormRow {
60
- return { ...spec, spec, key, valueRaw, value: format(valueRaw), editable: true };
62
+ return { ...spec, spec, key, valueRaw, value: (GRADIENT_KEYS as readonly string[]).includes(spec.key) ? gradientName(valueRaw) : format(valueRaw), editable: true };
61
63
  }
62
64
  export function formRows(view: FormView): FormRow[] {
63
65
  const e = view.editor!;
@@ -66,7 +68,7 @@ export function formRows(view: FormView): FormRow[] {
66
68
  const node = e.instance(e.detail.scope, e.detail.id)!;
67
69
  const options = node.options;
68
70
  return itemFields(e.description.editor_fields.item!, e.detail.scope, node.type_id, e.definition(e.detail.scope,node.id)?.capabilities).map((spec) => row(spec, 'item:' + spec.key, spec.key === 'text' ? node.text : spec.key === 'link' ? options.link ?? 'off' : spec.key in e.description.formatting_options ? options.formatting[spec.key] ?? 'inherit' :
69
- options[spec.key as keyof typeof options] ?? INDICATOR_DEFAULTS[spec.key as keyof typeof INDICATOR_DEFAULTS] ?? COST_RATE_DEFAULTS[spec.key as keyof typeof COST_RATE_DEFAULTS] ?? ITEM_DEFAULTS[spec.key as keyof typeof ITEM_DEFAULTS]))
71
+ options[spec.key as keyof typeof options] ?? INDICATOR_DEFAULTS[spec.key as keyof typeof INDICATOR_DEFAULTS] ?? COST_RATE_DEFAULTS[spec.key as keyof typeof COST_RATE_DEFAULTS] ?? GRADIENT_DEFAULTS[spec.key as keyof typeof GRADIENT_DEFAULTS] ?? ITEM_DEFAULTS[spec.key as keyof typeof ITEM_DEFAULTS]))
70
72
  .sort((a, b) => ['Item format', 'Conditional visibility', 'Item colors', 'Item fitting'].indexOf(a.group) - ['Item format', 'Conditional visibility', 'Item colors', 'Item fitting'].indexOf(b.group));
71
73
  }
72
74
  if (e.page === 'layout') {
@@ -109,9 +111,12 @@ export function setFormValue(view: FormView, current: FormRow, raw: string | boo
109
111
  return false;
110
112
  if (spec.key === "foreground" || spec.key === "background")
111
113
  value = normalizeColor(value);
114
+ if ((GRADIENT_KEYS as readonly string[]).includes(spec.key)) {
115
+ try { value = parseGradient(value); } catch { setMessage(view, 'message', localizedText('gradients.invalid')); return false; }
116
+ }
112
117
  const draft = copyDraft(e.draft);
113
118
  if (current.key === 'layout.mode') {
114
- draft.display.layout = { mode: value as 'auto' | 'explicit', rows: value === 'explicit' && draft.display.instances.length ? [draft.display.instances.map(i => i.id)] : [] };
119
+ draft.display.layout = { ...draft.display.layout, mode: value as 'auto' | 'explicit', rows: value === 'explicit' && draft.display.instances.length ? [draft.display.instances.map(i => i.id)] : [] };
115
120
  }
116
121
  else if (current.key.startsWith('break:')) {
117
122
  const starts = new Set(draft.display.layout.rows.slice(1).map((r) => r[0]));
@@ -126,7 +131,7 @@ export function setFormValue(view: FormView, current: FormRow, raw: string | boo
126
131
  rows.push([]);
127
132
  rows[rows.length - 1]!.push(item);
128
133
  }
129
- draft.display.layout = { mode: 'explicit', rows };
134
+ draft.display.layout = { ...draft.display.layout, mode: 'explicit', rows };
130
135
  }
131
136
  else if (current.key.startsWith('fit:')) {
132
137
  const [, id, key] = current.key.split(':');
@@ -148,7 +153,12 @@ export function setFormValue(view: FormView, current: FormRow, raw: string | boo
148
153
  }
149
154
  else
150
155
  write(draft.display, spec.key, value);
156
+ const ids = alignmentConflicts(draft.display);
151
157
  if (!isDraft(draft)) {
158
+ if (ids.length) {
159
+ setMessage(view, 'message', localizedText('alignment.references', { ids: ids.join(', ') }));
160
+ return false;
161
+ }
152
162
  setMessage(view, "message", localizedText("native.lib.client.forms.invalid_value_check_thresholds_text_and_width_constraints"));
153
163
  return false;
154
164
  }
@@ -157,6 +167,10 @@ export function setFormValue(view: FormView, current: FormRow, raw: string | boo
157
167
  }
158
168
  export function adjustForm(view: FormView, current: FormRow, delta: -1 | 1): boolean {
159
169
  const spec = current.spec;
170
+ if ((GRADIENT_KEYS as readonly string[]).includes(spec.key)) {
171
+ const choices = ['off', ...Object.keys(GRADIENT_PRESETS)], index = choices.indexOf(gradientName(current.valueRaw));
172
+ return setFormValue(view, current, choices[(index + delta + choices.length) % choices.length]!);
173
+ }
160
174
  if (spec.kind === 'boolean')
161
175
  return setFormValue(view, current, !current.valueRaw);
162
176
  else if (spec.kind === 'choice') {
@@ -0,0 +1,29 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ /** Presets are expanded into portable colors; saved gradients do not depend on a preset registry. */
3
+ import type { EditorField, GradientDraft } from '../generated-contracts.ts';
4
+ export const GRADIENT_PRESETS = {
5
+ ocean: ['#22d3ee', '#3b82f6'],
6
+ sunset: ['#fb923c', '#f472b6', '#a78bfa'],
7
+ aurora: ['#34d399', '#22d3ee', '#a78bfa'],
8
+ } as const;
9
+ export const GRADIENT_KEYS = ['foreground_gradient', 'background_gradient'] as const;
10
+ export const GRADIENT_DEFAULTS = { foreground_gradient: null, background_gradient: null };
11
+ export const GRADIENT_FIELDS: EditorField[] = GRADIENT_KEYS.map(key => ({
12
+ key, label: key === 'foreground_gradient' ? 'Foreground gradient' : 'Powerline background gradient',
13
+ group: 'Item colors', kind: 'text', choices: [], minimum: 0, maximum: 256, nullable: true,
14
+ }));
15
+ export function validGradient(value: unknown): value is GradientDraft | null {
16
+ return value === null || Array.isArray(value) && value.length >= 2 && value.length <= 5 &&
17
+ [...value].every(color => typeof color === 'string' && /^#[0-9a-f]{6}$/iu.test(color));
18
+ }
19
+ export function parseGradient(value: unknown): GradientDraft | null {
20
+ if (value === null || value === 'off' || value === 'inherit' || value === 'none') return null;
21
+ if (typeof value === 'string') value = Object.hasOwn(GRADIENT_PRESETS, value)
22
+ ? [...GRADIENT_PRESETS[value as keyof typeof GRADIENT_PRESETS]] : value.split(',').map(color => color.trim());
23
+ if (!validGradient(value)) throw new Error('gradients.invalid');
24
+ return value?.map(color => color.toLowerCase()) ?? null;
25
+ }
26
+ export function gradientName(value: unknown): string {
27
+ if (value == null) return 'off';
28
+ return Object.entries(GRADIENT_PRESETS).find(([, colors]) => JSON.stringify(colors) === JSON.stringify(value))?.[0] ?? String(value);
29
+ }
@@ -3,7 +3,8 @@
3
3
  import type { Editor } from './draft.ts';
4
4
  import type { GroupDraft, Scope } from '../generated-contracts.ts';
5
5
  import type { TextKey } from './text-input.ts';
6
- import { t, type Language } from '../i18n/index.ts';
6
+ import { t, text, renderMessage, type LocalizedText, type Language } from '../i18n/index.ts';
7
+ import { AlignmentReferenceError } from './alignments.ts';
7
8
  import { editGroup, groupScope, type GroupEdit } from './groups.ts';
8
9
  import { newInstance } from './instances.ts';
9
10
  import { isDraft } from '../backend.ts';
@@ -12,6 +13,7 @@ import { wrapText } from '../../ui/text.ts';
12
13
  export interface GroupManager {
13
14
  scope: Scope; page: 'list' | 'actions' | 'form'; cursor: number; selected: string | null;
14
15
  first: string; last: string; primary: string; linked: boolean; shared: boolean; error: boolean;
16
+ errorMessage?: LocalizedText;
15
17
  }
16
18
  export function openGroups(e: Editor): void {
17
19
  e.groupManager = { scope: e.detail?.scope ?? (e.page === 'subagents' ? 'subagent' : 'main'), page: 'list', cursor: 0, selected: null,
@@ -35,7 +37,7 @@ function apply(e: Editor, edit: GroupEdit): void {
35
37
  if (!isDraft({ ...e.draft, display })) throw new Error('invalid');
36
38
  e.draft = { ...e.draft, display }; e.order[m.scope] = groupScope(display, m.scope).instances.map(n => n.id);
37
39
  m.page = 'list'; m.cursor = 0; m.error = false;
38
- } catch { m.error = true; }
40
+ } catch (error) { m.error = true; m.errorMessage = error instanceof AlignmentReferenceError ? text('alignment.references', { ids: error.ids.join(', ') }) : undefined; }
39
41
  }
40
42
  export function groupsKey(e: Editor, event: TextKey): null {
41
43
  const m = e.groupManager!;
@@ -96,7 +98,7 @@ export function groupsView(e: Editor, language: Language, width: number, height:
96
98
  : m.page === 'actions' ? actions.map(tr)
97
99
  : [tr('first') + ': ' + label(m.first), tr('last') + ': ' + label(m.last), tr('primary') + ': ' + label(m.primary),
98
100
  tr('linked') + ': ' + t('values.' + (m.linked ? 'on' : 'off'), language), tr('shared') + ': ' + t('values.' + (m.shared ? 'on' : 'off'), language), tr('apply')];
99
- const note = wrapText([tr(m.error ? 'invalid' : 'help')], width), capacity = Math.max(1, height - Math.min(2, note.length));
101
+ const note = wrapText([m.error && m.errorMessage ? renderMessage(m.errorMessage, language) : tr(m.error ? 'invalid' : 'help')], width), capacity = Math.max(1, height - Math.min(2, note.length));
100
102
  const start = Math.max(0, m.cursor - capacity + 1);
101
103
  return [...values.slice(start, start + capacity).map((text, i) => ({ text: (start + i === m.cursor ? '› ' : ' ') + text, selected: start + i === m.cursor })), ...note.slice(0, Math.max(0, height - Math.min(capacity, values.length))).map(text => ({ text }))];
102
104
  }
@@ -1,6 +1,7 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
2
  /** Pure grouping rules shared by configuration services and both editors. */
3
3
  import type { DisplayDraft, GroupDraft, InstanceDraft, LayoutDraft, Scope } from '../generated-contracts.ts';
4
+ import { requireAlignments } from './alignments.ts';
4
5
 
5
6
  const object = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);
6
7
  const id = (v: unknown): v is string => typeof v === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/.test(v);
@@ -85,5 +86,6 @@ export function editGroup(original: DisplayDraft, scope: Scope, edit: GroupEdit,
85
86
  } else invalid();
86
87
  }
87
88
  if (!validGroups(target.groups, target.instances, scope === 'main' ? display.layout : undefined)) invalid();
89
+ if (scope === 'main') requireAlignments(display);
88
90
  return display;
89
91
  }
@@ -0,0 +1,72 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ import type { Draft, ImportChange, Scope } from '../generated-contracts.ts';
3
+ import { text, t } from '../i18n/index.ts';
4
+ const clone = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T;
5
+ const object = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);
6
+ const scalarCompare = (a: string, b: string) => a < b ? -1 : a > b ? 1 : 0;
7
+ const canonical = (value: unknown): string => Array.isArray(value) ? '[' + value.map(canonical).join(',') + ']' : object(value) ? '{' + Object.keys(value).sort(scalarCompare).map(key => JSON.stringify(key) + ':' + canonical(value[key])).join(',') + '}' : JSON.stringify(value);
8
+
9
+ export const SECTIONS = ['main', 'subagent', 'formatting', 'layout', 'language', 'host'] as const;
10
+ export const KINDS = ['add', 'remove', 'enable', 'disable', 'reorder', 'change'] as const;
11
+
12
+ function fieldMessage(path: string[]) {
13
+ if (path.includes('groups')) return text('composition.groups.title');
14
+ if (path.includes('source')) return text('sources.title');
15
+ let key: string;
16
+ if (path.includes('options')) {
17
+ const tail = path.slice(path.indexOf('options') + 1), name = tail.at(-1) ?? 'overrides';
18
+ key = name === 'overrides' ? 'review.overrides' : 'fields.item.' + name + '.label';
19
+ } else if (path[0] === 'host') key = 'review.fields.' + path.at(-1);
20
+ else if (path.length === 2 && ['use_colors', 'palette', 'directory_style', 'separator_style', 'scope_labels', 'layout'].includes(path[1]!)) key = 'review.fields.' + path[1];
21
+ else if (path.join('.') === 'display.subagents.enabled') key = 'review.fields.subagents_enabled';
22
+ else key = 'fields.global.' + path.slice(1).join('.') + '.label';
23
+ return t(key) === key ? text('review.field', { path: path.join('.') }) : text(key);
24
+ }
25
+
26
+ export function differences(before: Draft, after: Draft): ImportChange[] {
27
+ const changes: ImportChange[] = [];
28
+ function add(section: ImportChange['section'], kind: ImportChange['kind'], scope: Scope | null, identifier: string | null,
29
+ path: string[], old: unknown, next: unknown, typeId?: string) {
30
+ let label = text('review.component', { item: identifier || path.join('.') });
31
+ if (identifier && typeId) {
32
+ const item = text(`items.${scope}.${typeId}.label`);
33
+ label = ['enable', 'disable', 'add', 'remove'].includes(kind) ? text('review.' + kind, { item }) : text('review.item_field', { item, field: fieldMessage(path) });
34
+ } else if (kind === 'reorder') label = text('review.reorder');
35
+ else if (kind === 'change') label = fieldMessage(path);
36
+ changes.push({ section, kind, scope, item_id: identifier, path, before: clone(old), after: clone(next), label });
37
+ }
38
+ function walk(old: unknown, next: unknown, path: string[], section: ImportChange['section'], scope: Scope | null = null, identifier: string | null = null, typeId?: string) {
39
+ if (canonical(old) === canonical(next)) return;
40
+ if (object(old) && object(next)) {
41
+ for (const key of [...new Set([...Object.keys(old), ...Object.keys(next)])].sort(scalarCompare)) {
42
+ walk(old[key] ?? null, next[key] ?? null, [...path, key], section, scope, identifier, typeId);
43
+ }
44
+ } else add(section, 'change', scope, identifier, path, old, next, typeId);
45
+ }
46
+ const old = before.display, next = after.display;
47
+ for (const scope of ['main', 'subagent'] as const) {
48
+ const left = scope === 'main' ? old : old.subagents, right = scope === 'main' ? next : next.subagents;
49
+ const root = scope === 'main' ? ['display'] : ['display', 'subagents'];
50
+ const a = new Map(left.instances.map(node => [node.id, node])), b = new Map(right.instances.map(node => [node.id, node]));
51
+ for (const id of new Set([...a.keys(), ...b.keys()])) {
52
+ const previous = a.get(id), following = b.get(id), node = following ?? previous!;
53
+ const path = [...root, 'instances', id];
54
+ if (!previous || !following) { add(scope, following ? 'add' : 'remove', scope, id, path, previous ?? null, following ?? null, node.type_id); continue; }
55
+ if (previous.enabled !== following.enabled) add(scope, following.enabled ? 'enable' : 'disable', scope, id, [...path, 'enabled'], previous.enabled, following.enabled, node.type_id);
56
+ for (const key of ['type_id', 'options', 'text', 'source'] as const) walk(previous[key] ?? null, following[key] ?? null, [...path, key], key === 'options' ? 'formatting' : scope, scope, id, node.type_id);
57
+ }
58
+ const leftOrder = [...a.keys()].filter(id => b.has(id)), rightOrder = [...b.keys()].filter(id => a.has(id));
59
+ if (canonical(leftOrder) !== canonical(rightOrder)) add(scope, 'reorder', scope, null, [...root, 'instances'], leftOrder, rightOrder);
60
+ }
61
+ for (const key of Object.keys(old).filter(key => !['schema_version', 'instances', 'subagents', 'layout', 'statusline_language', 'metrics'].includes(key)).sort(scalarCompare)) {
62
+ walk(old[key as keyof typeof old], next[key as keyof typeof next], ['display', key], 'formatting');
63
+ }
64
+ for (const key of Object.keys(old.subagents).filter(key => key !== 'instances').sort(scalarCompare)) {
65
+ walk(old.subagents[key as keyof typeof old.subagents], next.subagents[key as keyof typeof next.subagents], ['display', 'subagents', key], 'subagent');
66
+ }
67
+ walk(old.metrics, next.metrics, ['display', 'metrics'], 'main');
68
+ walk(old.layout, next.layout, ['display', 'layout'], 'layout');
69
+ walk(old.statusline_language, next.statusline_language, ['display', 'statusline_language'], 'language');
70
+ walk(before.host, after.host, ['host'], 'host');
71
+ return changes.sort((a, b) => SECTIONS.indexOf(a.section) - SECTIONS.indexOf(b.section));
72
+ }
@@ -1,5 +1,7 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
- import type { ImportReviewResult, Scope } from '../generated-contracts.ts';
2
+ import type { Draft, ImportReviewResult, Scope } from '../generated-contracts.ts';
3
+ import { IMPORT_FIELDS, selectImport, type ImportField } from './import-selection.ts';
4
+ import { differences } from './import-differences.ts';
3
5
  import type { Language } from '../i18n/index.ts';
4
6
  import { renderMessage, t } from '../i18n/index.ts';
5
7
  import { wrapText } from '../../ui/text.ts';
@@ -11,17 +13,25 @@ export interface ReviewState {
11
13
  expanded: string[];
12
14
  scroll: number;
13
15
  previewScope: Scope;
16
+ base?: Draft;
17
+ incoming?: ImportReviewResult;
18
+ choosing?: boolean;
19
+ selection?: ImportField[];
20
+ cursor?: number;
14
21
  }
15
22
  export interface ReviewRow { text: string; section: string; heading: boolean }
16
23
  export function sections(review: ReviewState): string[] {
17
24
  return REVIEW_SECTIONS.filter(section => review.result.changes.some(change => change.section === section));
18
25
  }
19
- export function createReview(result: ImportReviewResult): ReviewState {
26
+ export function createReview(result: ImportReviewResult, base?: Draft): ReviewState {
20
27
  const review: ReviewState = {result, selected:'', expanded:[], scroll:0, previewScope:'main'};
28
+ if (base) Object.assign(review, { base: JSON.parse(JSON.stringify(base)), incoming: result, selection: [], cursor: 0 });
21
29
  review.selected = sections(review)[0] ?? '';
22
30
  return review;
23
31
  }
24
32
  export function reviewRows(review: ReviewState, language: Language, width: number): ReviewRow[] {
33
+ if (review.choosing) return IMPORT_FIELDS.map((key, index) => ({ heading: true, section: key,
34
+ text: `${review.cursor === index ? '› ' : ' '}[${review.selection?.includes(key) ? 'x' : ' '}] ${selectionLabel(key, language)}` }));
25
35
  const rows: ReviewRow[] = [];
26
36
  for (const section of sections(review)) {
27
37
  const changes = review.result.changes.filter(change => change.section === section);
@@ -36,6 +46,32 @@ export function reviewRows(review: ReviewState, language: Language, width: numbe
36
46
  return rows.length ? rows : [{text:t('review.empty', language),section:'',heading:false}];
37
47
  }
38
48
  export function navigateReview(review: ReviewState, key: string, language: Language, width: number, capacity: number): void {
49
+ if (review.base && review.incoming && key.toLowerCase() === 's') {
50
+ review.choosing = true; review.scroll = 0; review.cursor = 0; review.selected = IMPORT_FIELDS[0];
51
+ updateSelection(review); return;
52
+ }
53
+ if (review.base && review.incoming && key.toLowerCase() === 'f') {
54
+ review.choosing = false; review.result = review.incoming; review.selected = sections(review)[0] ?? ''; review.scroll = 0; return;
55
+ }
56
+ if (review.choosing) {
57
+ let cursor = review.cursor ?? 0;
58
+ if (key === 'up') cursor--;
59
+ if (key === 'down') cursor++;
60
+ if (key === 'home') cursor = 0;
61
+ if (key === 'end') cursor = IMPORT_FIELDS.length - 1;
62
+ if (key === 'pageup') cursor -= capacity;
63
+ if (key === 'pagedown') cursor += capacity;
64
+ review.cursor = Math.max(0, Math.min(IMPORT_FIELDS.length - 1, cursor));
65
+ review.selected = IMPORT_FIELDS[review.cursor]!;
66
+ if (key === 'space' || key === ' ') {
67
+ const field = IMPORT_FIELDS[review.cursor]!, values = review.selection ?? [];
68
+ review.selection = values.includes(field) ? values.filter(v => v !== field) : [...values, field]; updateSelection(review);
69
+ }
70
+ if (key === 'return' || key === 'enter') { review.choosing = false; review.selected = sections(review)[0] ?? ''; review.scroll = 0; }
71
+ else review.scroll = Math.max(0, Math.min(review.scroll, review.cursor));
72
+ if (review.choosing && review.cursor >= review.scroll + capacity) review.scroll = review.cursor - capacity + 1;
73
+ return;
74
+ }
39
75
  const groups = sections(review);
40
76
  let follow = false;
41
77
  if (key === 'up' || key === 'down') {
@@ -53,3 +89,14 @@ export function navigateReview(review: ReviewState, key: string, language: Langu
53
89
  if (follow) review.scroll = Math.max(0, rows.findIndex(row => row.heading && row.section === review.selected));
54
90
  review.scroll = Math.max(0, Math.min(Math.max(0, rows.length - capacity), review.scroll));
55
91
  }
92
+
93
+ function updateSelection(review: ReviewState): void {
94
+ const draft = selectImport(review.base!, review.incoming!.draft, review.selection ?? []);
95
+ review.result = { draft, changes: differences(review.base!, draft) };
96
+ }
97
+ function selectionLabel(key: ImportField, language: Language): string {
98
+ if (key === 'main' || key === 'subagent') return t('review.selection.' + key, language);
99
+ if (key === 'formatting.thresholds') return t('review.selection.thresholds', language);
100
+ const message = ['use_colors','palette','directory_style','separator_style','scope_labels'].includes(key) ? 'review.fields.' + key : 'fields.global.' + key + '.label';
101
+ return t(message, language);
102
+ }
@@ -0,0 +1,38 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ /** Frozen selection vocabulary. New display fields require an explicit selection decision. */
3
+ import type { Draft } from '../generated-contracts.ts';
4
+
5
+ export const IMPORT_FIELDS = [
6
+ 'main', 'subagent', 'use_colors', 'palette', 'theme', 'directory_style', 'separator_style', 'scope_labels',
7
+ 'powerline_glyph', 'powerline.padding', 'powerline.separator', 'powerline.start_cap', 'powerline.end_cap', 'powerline.color_mode',
8
+ 'statusline_language', 'formatting.model_name', 'formatting.number_format', 'formatting.labels', 'formatting.icons',
9
+ 'formatting.allowance', 'formatting.reset_format', 'formatting.reset_timezone', 'formatting.thresholds',
10
+ ] as const;
11
+ export type ImportField = typeof IMPORT_FIELDS[number];
12
+ export function importSelection(value: unknown): ImportField[] {
13
+ if (!Array.isArray(value) || value.some(key => !IMPORT_FIELDS.includes(key)) || new Set(value).size !== value.length)
14
+ throw new Error('review.selection.invalid');
15
+ return IMPORT_FIELDS.filter(key => value.includes(key));
16
+ }
17
+ const copy = <T>(value: T): T => JSON.parse(JSON.stringify(value)) as T;
18
+
19
+ /** Inputs have already passed full schema/reference validation. Scopes own independent ID namespaces. */
20
+ export function selectImport(base: Draft, incoming: Draft, requested: unknown): Draft {
21
+ const selection = importSelection(requested), result = copy(base), source = copy(incoming.display);
22
+ // Only imported scopes lose local bindings; retained scopes remain untouched.
23
+ for (const area of [source, source.subagents]) for (const node of area.instances)
24
+ if (node.source) node.source.binding = null;
25
+ for (const key of selection) {
26
+ if (key === 'main') {
27
+ result.display.instances = source.instances; result.display.groups = source.groups;
28
+ result.display.layout = source.layout; result.display.metrics = source.metrics;
29
+ } else if (key === 'subagent') result.display.subagents = source.subagents;
30
+ else {
31
+ const parts = key.split('.');
32
+ let target = result.display as unknown as Record<string, unknown>, origin = source as unknown as Record<string, unknown>;
33
+ for (const part of parts.slice(0, -1)) { target = target[part] as Record<string, unknown>; origin = origin[part] as Record<string, unknown>; }
34
+ target[parts.at(-1)!] = origin[parts.at(-1)!];
35
+ }
36
+ }
37
+ return result;
38
+ }
@@ -1,4 +1,6 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
+ import { createReview, navigateReview } from './import-review.ts';
3
+ import { differences } from './import-differences.ts';
2
4
  import type { ConfigTarget, DisplayDraft, Operation, ProfilesResult, ResultFor } from '../generated-contracts.ts';
3
5
  import { t, text, type Language, type LocalizedText } from '../i18n/index.ts';
4
6
  import type { Editor } from './draft.ts';
@@ -6,10 +8,10 @@ import { inputKey, inputView, textInput, type TextInput, type TextKey } from './
6
8
  import { wrapText } from '../../ui/text.ts';
7
9
  import { BackendError } from '../backend.ts';
8
10
 
9
- type Action = 'edit' | 'activate' | 'save' | 'save_bind' | 'rename' | 'delete' | 'bind' | 'unbind' | 'import' | 'export';
11
+ type Action = 'edit' | 'activate' | 'save' | 'save_bind' | 'rename' | 'delete' | 'bind' | 'unbind' | 'import' | 'reuse' | 'export';
10
12
  type Switch = { target: ConfigTarget; display?: DisplayDraft };
11
13
  type Effect = { kind: 'load' } | { kind: 'switch'; next: Switch; save: boolean } |
12
- { kind: 'mutation'; payload: Record<string, unknown> } | { kind: 'import'; path: string } |
14
+ { kind: 'mutation'; payload: Record<string, unknown> } | { kind: 'import'; path: string } | { kind: 'reuse'; path: string } |
13
15
  { kind: 'export'; path: string; name: string; display: DisplayDraft; overwrite: boolean };
14
16
  export interface ProfileManager {
15
17
  library: ProfilesResult | null;
@@ -49,7 +51,7 @@ function entries(m: ProfileManager): { key: string; label: string; raw?: boolean
49
51
  if (m.page === 'actions') return ['edit','activate','rename','delete','bind','export'].map(key => ({ key, label: 'profiles.action.' + key }));
50
52
  return [{ key: 'user', label: 'profiles.user' }, ...(m.library?.profiles ?? []).map(p => ({ key: p.id, label: p.name, raw: true })),
51
53
  ...(m.library?.bindings ?? []).map(b=>({key:'binding:'+b.root,label:b.root+' → '+(m.library!.profiles.find(p=>p.id===b.profile_id)?.name ?? b.profile_id),raw:true})),
52
- ...['save','save_bind','import','unbind'].map(key => ({ key: 'action:' + key, label: 'profiles.action.' + key }))];
54
+ ...['save','save_bind','import','unbind','reuse'].map(key => ({ key: 'action:' + key, label: 'profiles.action.' + key }))];
53
55
  }
54
56
  function startForm(e: Editor, action: Action): void {
55
57
  const m = e.profiles!, profile = m.library?.profiles.find(p => p.id === m.selected), project = e.baseline.configuration;
@@ -67,7 +69,7 @@ function submitForm(e: Editor): void {
67
69
  const m = e.profiles!, values = Object.fromEntries(m.fields.map(f => [f.key, f.input.value]));
68
70
  const profile = m.library?.profiles.find(p => p.id === m.selected);
69
71
  if (m.fields.some(f => !f.input.value.trim())) { m.message = text('profiles.required'); return; }
70
- if (m.action === 'import') { m.effect = { kind: 'import', path: values.path! }; return; }
72
+ if (m.action === 'import' || m.action === 'reuse') { m.effect = { kind: m.action, path: values.path! }; return; }
71
73
  if (m.action === 'export' && profile) {
72
74
  m.confirmation = { kind: 'export', path: values.path!, name: profile.name, display: profile.display, overwrite: false };
73
75
  } else {
@@ -181,8 +183,15 @@ export async function performProfileAction(e: Editor, backend: ProfileBackend):
181
183
  if (effect.next.display) e.replaceDraft({ ...current.draft, display: JSON.parse(JSON.stringify(effect.next.display)) as DisplayDraft });
182
184
  e.profiles = null; return;
183
185
  }
184
- if (effect.kind === 'import') {
186
+ if (effect.kind === 'import' || effect.kind === 'reuse') {
187
+ const original = JSON.stringify(e.draft);
185
188
  const result = await backend.request('profile_import', { path: effect.path });
189
+ if (effect.kind === 'reuse') {
190
+ if (JSON.stringify(e.draft) !== original || e.profiles !== m) throw new BackendError('stale_import', text('review.stale'));
191
+ const draft = { display: result.display, host: e.draft.host };
192
+ e.review = createReview({ draft, changes: differences(e.draft, draft) }, e.draft);
193
+ navigateReview(e.review, 's', 'en', 80, 20); e.profiles = null; return;
194
+ }
186
195
  m.candidate = result.display; startForm(e, 'save'); m.fields[0]!.input = textInput(result.name);
187
196
  m.message = text('profiles.import_review'); return;
188
197
  }