@fbincon/claude-code-statusline 3.9.0 → 3.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/README.md +92 -80
  2. package/candidate.json +310 -247
  3. package/node_modules/@fbincon/statusline-cli/dist/src/diagnostics/service.js +17 -7
  4. package/node_modules/@fbincon/statusline-cli/dist/src/diagnostics/service.js.map +1 -1
  5. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js +7 -0
  6. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js.map +1 -1
  7. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.d.ts +1 -0
  8. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js +3 -2
  9. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js.map +1 -1
  10. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js +14 -5
  11. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js.map +1 -1
  12. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.d.ts +3 -1
  13. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js +56 -22
  14. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js.map +1 -1
  15. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +438 -2
  16. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +9 -3
  17. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js.map +1 -1
  18. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/.claude-plugin/plugin.json +1 -1
  19. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/hooks/register.ts +160 -86
  20. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/backend.ts +3 -3
  21. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +1 -0
  22. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/settings.ts +1 -0
  23. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/alignment-manager.ts +2 -1
  24. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +45 -0
  25. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/forms.ts +1 -0
  26. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/group-manager.ts +1 -0
  27. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/profile-manager.ts +14 -5
  28. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/quick-setup.ts +1 -0
  29. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-manager.ts +15 -4
  30. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-validation.ts +2 -2
  31. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +6 -3
  32. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +96 -6
  33. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/session.ts +28 -90
  34. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +25 -24
  35. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +7 -4
  36. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/surface.ts +16 -13
  37. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/components/preview.ts +9 -5
  38. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/components/section.ts +11 -7
  39. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/components/shortcuts.ts +5 -1
  40. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/frame.ts +72 -0
  41. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/.claude-plugin/plugin.json +1 -1
  42. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/resource-manifest.json +3 -3
  43. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +9 -3
  44. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js +2 -1
  45. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js.map +1 -1
  46. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js +3 -1
  47. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js.map +1 -1
  48. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js +3 -3
  49. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js.map +1 -1
  50. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.d.ts +16 -1
  51. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +56 -0
  52. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
  53. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js +4 -0
  54. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js.map +1 -1
  55. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js +5 -0
  56. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js.map +1 -1
  57. package/node_modules/@fbincon/statusline-core/dist/src/editor/profile-manager.js +32 -3
  58. package/node_modules/@fbincon/statusline-core/dist/src/editor/profile-manager.js.map +1 -1
  59. package/node_modules/@fbincon/statusline-core/dist/src/editor/quick-setup.js +2 -0
  60. package/node_modules/@fbincon/statusline-core/dist/src/editor/quick-setup.js.map +1 -1
  61. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.d.ts +1 -0
  62. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js +24 -4
  63. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js.map +1 -1
  64. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js +2 -2
  65. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js.map +1 -1
  66. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.d.ts +3 -1
  67. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js +15 -1
  68. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js.map +1 -1
  69. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +90 -0
  70. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +96 -6
  71. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
  72. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.d.ts +2 -0
  73. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.js +3 -1
  74. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.js.map +1 -1
  75. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.d.ts +2 -0
  76. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.js +3 -1
  77. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.js.map +1 -1
  78. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.d.ts +2 -0
  79. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.js +3 -1
  80. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.js.map +1 -1
  81. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.d.ts +2 -0
  82. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.js +3 -1
  83. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.js.map +1 -1
  84. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.d.ts +2 -0
  85. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.js +3 -1
  86. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.js.map +1 -1
  87. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.d.ts +2 -0
  88. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.js +3 -1
  89. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.js.map +1 -1
  90. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js +2 -1
  91. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js.map +1 -1
  92. package/node_modules/@fbincon/statusline-core/dist/src/release.d.ts +1 -1
  93. package/node_modules/@fbincon/statusline-core/dist/src/release.js +1 -1
  94. package/node_modules/@fbincon/statusline-core/dist/src/rendering/indicators.js +5 -4
  95. package/node_modules/@fbincon/statusline-core/dist/src/rendering/indicators.js.map +1 -1
  96. package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js +1 -1
  97. package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js.map +1 -1
  98. package/node_modules/@fbincon/statusline-core/dist/src/rendering/preferences.d.ts +4 -1
  99. package/node_modules/@fbincon/statusline-core/dist/src/rendering/preferences.js +6 -2
  100. package/node_modules/@fbincon/statusline-core/dist/src/rendering/preferences.js.map +1 -1
  101. package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js +1 -1
  102. package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js.map +1 -1
  103. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +16 -1
  104. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +16 -1
  105. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +16 -1
  106. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +16 -1
  107. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +16 -1
  108. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +16 -1
  109. package/node_modules/@fbincon/statusline-platform/dist/src/darwin-process.d.ts +8 -0
  110. package/node_modules/@fbincon/statusline-platform/dist/src/darwin-process.js +33 -0
  111. package/node_modules/@fbincon/statusline-platform/dist/src/darwin-process.js.map +1 -0
  112. package/node_modules/@fbincon/statusline-platform/dist/src/npm.js +47 -16
  113. package/node_modules/@fbincon/statusline-platform/dist/src/npm.js.map +1 -1
  114. package/node_modules/@fbincon/statusline-platform/dist/src/package-copy.js +10 -0
  115. package/node_modules/@fbincon/statusline-platform/dist/src/package-copy.js.map +1 -1
  116. package/node_modules/@fbincon/statusline-platform/dist/src/performance.d.ts +2 -0
  117. package/node_modules/@fbincon/statusline-platform/dist/src/performance.js +17 -0
  118. package/node_modules/@fbincon/statusline-platform/dist/src/performance.js.map +1 -0
  119. package/node_modules/@fbincon/statusline-platform/dist/src/processes.js +7 -3
  120. package/node_modules/@fbincon/statusline-platform/dist/src/processes.js.map +1 -1
  121. package/node_modules/@fbincon/statusline-platform/dist/src/source-process.js +6 -12
  122. package/node_modules/@fbincon/statusline-platform/dist/src/source-process.js.map +1 -1
  123. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/launchers.d.ts +1 -1
  124. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/launchers.js +2 -5
  125. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/launchers.js.map +1 -1
  126. package/node_modules/@fbincon/statusline-platform/dist/src/windows-command.d.ts +2 -0
  127. package/node_modules/@fbincon/statusline-platform/dist/src/windows-command.js +7 -0
  128. package/node_modules/@fbincon/statusline-platform/dist/src/windows-command.js.map +1 -0
  129. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-exec.d.ts +1 -0
  130. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-exec.js +65 -0
  131. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-exec.js.map +1 -0
  132. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js +4 -0
  133. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js.map +1 -1
  134. package/node_modules/@fbincon/statusline-tui/dist/src/session.d.ts +1 -0
  135. package/node_modules/@fbincon/statusline-tui/dist/src/session.js +33 -6
  136. package/node_modules/@fbincon/statusline-tui/dist/src/session.js.map +1 -1
  137. package/node_modules/@fbincon/statusline-tui/dist/src/state.d.ts +1 -1
  138. package/node_modules/@fbincon/statusline-tui/dist/src/state.js +12 -0
  139. package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
  140. package/package.json +2 -2
@@ -16,6 +16,7 @@ import type {
16
16
  Draft,
17
17
  ReadResult,
18
18
  Scope,
19
+ ConfigTarget,
19
20
  } from '../generated-contracts.ts';
20
21
  import { NUMERIC_FIELDS, numericValue, numericDiagnostic } from './numeric.ts';
21
22
  import { bestMatch, fields, normalize } from './search.ts';
@@ -35,6 +36,10 @@ export function copyDraft(draft: Draft): Draft {
35
36
  export function sameDraft(left: Draft, right: Draft): boolean {
36
37
  return JSON.stringify(left) === JSON.stringify(right);
37
38
  }
39
+ export const definitiveSaveRefusal = (code: string): boolean => ['invalid_request','invalid_configuration','configuration_conflict','not_installed','ownership_mismatch','unsupported_protocol','unsupported_operation'].includes(code);
40
+ export interface PendingSave {
41
+ draft: Draft; revision: string; target?: ConfigTarget; installation: ReadResult['installation'];
42
+ }
38
43
 
39
44
  /** Pure tool draft. Persistence and host configuration calls live in the hook. */
40
45
  export class Editor {
@@ -66,6 +71,39 @@ export class Editor {
66
71
  buffers: Record<NumericField, string>;
67
72
  fieldErrors: Partial<Record<NumericField, string>> = {};
68
73
  fieldErrorMessages: Partial<Record<NumericField, LocalizedText>> = {};
74
+ saveState: 'idle' | 'pending' | 'unknown' = 'idle';
75
+ pendingSave: PendingSave | null = null;
76
+ mutationGeneration = 0;
77
+
78
+ canMutateDraft(generation = this.mutationGeneration): boolean {
79
+ if (this.saveState === 'idle' && generation === this.mutationGeneration) return true;
80
+ this.compositionError = text('editor.save_locked');
81
+ return false;
82
+ }
83
+ setSaveState(value: Editor['saveState']): void {
84
+ if (this.saveState !== value) this.mutationGeneration++;
85
+ this.saveState = value;
86
+ }
87
+ beginSave(): PendingSave {
88
+ if (!this.canMutateDraft()) throw new Error('A display save is already unresolved');
89
+ this.pendingSave = {draft:copyDraft(this.draft),revision:this.baseline.revision,installation:JSON.parse(JSON.stringify(this.baseline.installation)) as ReadResult['installation'],
90
+ ...(this.baseline.configuration ? {target:JSON.parse(JSON.stringify(this.baseline.configuration.target)) as ConfigTarget} : {})};
91
+ this.setSaveState('pending');
92
+ return this.pendingSave;
93
+ }
94
+ saveFailed(code: string): void {
95
+ const refused = definitiveSaveRefusal(code);
96
+ this.setSaveState(refused ? 'idle' : 'unknown');
97
+ if (refused) this.pendingSave = null;
98
+ }
99
+ reconcileSave(current: ReadResult): 'saved' | 'not_committed' | 'conflict' {
100
+ const submitted = this.pendingSave;
101
+ if (!submitted) throw new Error('No pending display save');
102
+ const outcome = sameDraft(current.draft,submitted.draft) && current.installed && JSON.stringify(current.installation) === JSON.stringify(submitted.installation) ? 'saved' : current.revision === submitted.revision ? 'not_committed' : 'conflict';
103
+ if (outcome === 'saved') this.committed(current);
104
+ else { this.pendingSave=null;this.setSaveState('idle'); }
105
+ return outcome;
106
+ }
69
107
 
70
108
  constructor(
71
109
  public readonly description: DescribeResult,
@@ -87,6 +125,7 @@ export class Editor {
87
125
  }
88
126
 
89
127
  replaceDraft(draft: Draft): void {
128
+ if (!this.canMutateDraft()) return;
90
129
  this.draft = copyDraft(draft);
91
130
  for (const scope of ['main', 'subagent'] as const) {
92
131
  this.order[scope] = nodes(this.draft,scope).map(i=>i.id);
@@ -157,6 +196,7 @@ export class Editor {
157
196
  this.adding=false;this.pickerSaved=null;
158
197
  }
159
198
  instanceAction(scope: Scope, action:'add'|'copy'|'remove', typeId?:string): boolean {
199
+ if (!this.canMutateDraft()) return false;
160
200
  this.compositionError = text('composition.invalid');
161
201
  const draft=copyDraft(this.draft), list=nodes(draft,scope);
162
202
  const selected=this.adding ? this.pickerSaved?.selected : this.selected[scope];
@@ -202,6 +242,7 @@ export class Editor {
202
242
  }
203
243
 
204
244
  toggle(scope: Scope, id: string): boolean {
245
+ if (!this.canMutateDraft()) return false;
205
246
  this.compositionError = text('composition.invalid');
206
247
  if(this.adding)return this.instanceAction(scope,'add',id);
207
248
  const draft=copyDraft(this.draft),node=nodes(draft,scope).find(i=>i.id===id);
@@ -212,6 +253,7 @@ export class Editor {
212
253
  }
213
254
 
214
255
  move(scope: Scope, delta: -1 | 1): boolean {
256
+ if (!this.canMutateDraft()) return false;
215
257
  this.compositionError = text('composition.invalid');
216
258
  if (this.adding || this.filtered(scope)) return false;
217
259
  const visible = this.visible(scope).map((item) => item.id as string);
@@ -238,6 +280,7 @@ export class Editor {
238
280
  }
239
281
 
240
282
  setBuffer(field: NumericField, value: string): void {
283
+ if (!this.canMutateDraft()) return;
241
284
  this.activeNumeric = field;
242
285
  this.buffers[field] = value;
243
286
  delete this.fieldErrors[field];
@@ -254,6 +297,7 @@ export class Editor {
254
297
  }
255
298
 
256
299
  acceptNumeric(field?: NumericField): boolean {
300
+ if (!this.canMutateDraft()) return false;
257
301
  const values: Partial<Record<NumericField, number | 'event'>> = {};
258
302
  const fields = field ? [field] : NUMERIC_FIELDS;
259
303
  for (const key of fields) {
@@ -273,6 +317,7 @@ export class Editor {
273
317
  }
274
318
 
275
319
  committed(current: ReadResult): void {
320
+ this.pendingSave=null;this.setSaveState('idle');
276
321
  this.baseline = { ...current, draft: copyDraft(current.draft) };
277
322
  this.draft = copyDraft(current.draft);
278
323
  this.cancelNumeric();
@@ -95,6 +95,7 @@ function options(draft: Draft, scope: 'main' | 'subagent', id: string) {
95
95
  }
96
96
  export function setFormValue(view: FormView, current: FormRow, raw: string | boolean): boolean {
97
97
  const e = view.editor!;
98
+ if (!e.canMutateDraft()) { setMessage(view, 'message', e.compositionError); return false; }
98
99
  const spec = current.spec;
99
100
  let value: unknown = raw;
100
101
  if (spec.kind === 'integer') {
@@ -32,6 +32,7 @@ function form(e: Editor, g?: GroupDraft): void {
32
32
  }
33
33
  function apply(e: Editor, edit: GroupEdit): void {
34
34
  const m = e.groupManager!;
35
+ if (!e.canMutateDraft()) { m.error=true;m.errorMessage=e.compositionError;return; }
35
36
  try {
36
37
  const display = editGroup(e.draft.display, m.scope, edit, () => newInstance('text', groupScope(e.draft.display, m.scope).instances).id);
37
38
  if (!isDraft({ ...e.draft, display })) throw new Error('invalid');
@@ -162,7 +162,11 @@ export async function performProfileAction(e: Editor, backend: ProfileBackend):
162
162
  if (!m || !effect) return;
163
163
  m.effect = null;
164
164
  let writing = false;
165
+ let savingDisplay = false;
165
166
  try {
167
+ let generation=e.mutationGeneration;
168
+ const permitted=()=>e.profiles===m && e.canMutateDraft(generation);
169
+ if (!['load','export'].includes(effect.kind) && !e.canMutateDraft()) { m.message=e.compositionError;return; }
166
170
  if (effect.kind === 'load') {
167
171
  const copy = m.action === 'save' && m.candidate !== null;
168
172
  m.library = await backend.request('profiles_read'); m.page = 'list'; m.cursor = 0;
@@ -172,12 +176,13 @@ export async function performProfileAction(e: Editor, backend: ProfileBackend):
172
176
  if (effect.kind === 'switch') {
173
177
  if (effect.save) {
174
178
  if (!e.acceptNumeric()) throw new BackendError('invalid_draft', text('profiles.invalid_draft'));
175
- writing = true;
176
- const saved = await backend.request('apply', { draft: e.draft, expected_revision: e.baseline.revision,
177
- ...(e.baseline.configuration ? { target: e.baseline.configuration.target } : {}) });
178
- e.committed(saved); writing = false;
179
+ const submitted=e.beginSave();writing = true;savingDisplay=true;
180
+ const saved = await backend.request('apply', { draft: submitted.draft, expected_revision: submitted.revision,
181
+ ...(submitted.target ? { target: submitted.target } : {}) });
182
+ e.committed(saved); writing = false;savingDisplay=false;generation=e.mutationGeneration;
179
183
  }
180
184
  const current = await backend.request('read', { target: effect.next.target });
185
+ if(!permitted()) {m.message=e.compositionError;return;}
181
186
  e.committed(current);
182
187
  e.replaceDraft(current.draft);
183
188
  if (effect.next.display) e.replaceDraft({ ...current.draft, display: JSON.parse(JSON.stringify(effect.next.display)) as DisplayDraft });
@@ -186,6 +191,7 @@ export async function performProfileAction(e: Editor, backend: ProfileBackend):
186
191
  if (effect.kind === 'import' || effect.kind === 'reuse') {
187
192
  const original = JSON.stringify(e.draft);
188
193
  const result = await backend.request('profile_import', { path: effect.path });
194
+ if(!permitted()) {m.message=e.compositionError;return;}
189
195
  if (effect.kind === 'reuse') {
190
196
  if (JSON.stringify(e.draft) !== original || e.profiles !== m) throw new BackendError('stale_import', text('review.stale'));
191
197
  const draft = { display: result.display, host: e.draft.host };
@@ -204,10 +210,12 @@ export async function performProfileAction(e: Editor, backend: ProfileBackend):
204
210
  if (effect.payload.bind_path && typeof effect.payload.bind_path === 'string') {
205
211
  const host = e.draft.host;
206
212
  const current = await backend.request('read', { target: { kind: 'project', path: effect.payload.bind_path } });
213
+ if(!permitted()) {m.message=e.compositionError;return;}
207
214
  e.committed(current); e.replaceDraft({ ...current.draft, host });
208
215
  } else if (e.baseline.configuration && (e.baseline.configuration.target.kind !== 'profile' ||
209
216
  m.library.profiles.some(p=>p.id===e.baseline.configuration!.profile_id))) {
210
217
  const current = await backend.request('read', { target: e.baseline.configuration.target });
218
+ if(!permitted()) {m.message=e.compositionError;return;}
211
219
  if (current.configuration?.profile_id === e.baseline.configuration.profile_id &&
212
220
  JSON.stringify(current.draft) === JSON.stringify(e.baseline.draft)) e.baseline = current;
213
221
  }
@@ -215,12 +223,13 @@ export async function performProfileAction(e: Editor, backend: ProfileBackend):
215
223
  m.page = 'list'; m.cursor = 0; m.candidate = null; m.confirmation = null; m.message = text('profiles.saved');
216
224
  } catch (error) {
217
225
  const code = error instanceof BackendError ? error.code : '';
226
+ if(savingDisplay)e.saveFailed(code);
218
227
  if (code === 'profile_duplicate' || code === 'profile_bound' || effect.kind === 'export' && code === 'io_error' && /EEXIST/u.test(String(error))) {
219
228
  m.confirmation = effect.kind === 'mutation' ? { ...effect, payload: { ...effect.payload, overwrite: true } }
220
229
  : effect.kind === 'export' ? { ...effect, overwrite: true } : null;
221
230
  m.page = 'confirm'; m.cursor = 1; m.message = text('profiles.overwrite');
222
231
  } else {
223
- m.uncertain = writing && !['profile_conflict','profile_referenced','profile_invalid','profile_name','profile_path','ownership_mismatch','configuration_conflict','invalid_request','profile_size'].includes(code);
232
+ m.uncertain = !savingDisplay && writing && !['profile_conflict','profile_referenced','profile_invalid','profile_name','profile_path','ownership_mismatch','configuration_conflict','invalid_request','profile_size'].includes(code);
224
233
  m.message = error instanceof BackendError && error.localization ? error.localization : text('profiles.failed', { value: error instanceof Error ? error.message : String(error) });
225
234
  }
226
235
  }
@@ -76,6 +76,7 @@ export function quickView(quick: QuickSetup, language: Language, width: number,
76
76
  export function controlQuick(editor: Editor, key: string): 'transfer' | 'save' | 'profiles' | null {
77
77
  const quick = editor.quick;
78
78
  if (!quick) return null;
79
+ if (!editor.canMutateDraft() && !['cancel','escape','tab','up','down','home','end','pageup','pagedown'].includes(key)) return null;
79
80
  const effect = quickKey(quick,key);
80
81
  if (effect === 'cancel') editor.quick = null;
81
82
  if (effect === 'preset') { editor.preset=quick.preset; editor.pendingTransfer='preset'; return 'transfer'; }
@@ -10,6 +10,7 @@ export interface SourceManager {
10
10
  library: SourcesResult | null;
11
11
  context: SourceContext | null;
12
12
  owner: string;
13
+ closed: boolean;
13
14
  page: 'list' | 'actions' | 'kind' | 'form' | 'review' | 'remove' | 'bind' | 'unbind' | 'diagnose' | 'auto-review';
14
15
  automaticInterval: number;
15
16
  cursor: number;
@@ -36,7 +37,7 @@ export interface SourceBackend {
36
37
  }
37
38
  const external = ['external-value', 'github-pr', 'github-ci'];
38
39
  export function openSources(editor: Editor): void {
39
- editor.sources = { library: null, context: null, owner: 'editor-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2), page: 'list', automaticInterval: 300, cursor: 0, scroll: 0, selected: null, kind: 'json', editing: false, fields: [], review: null, details: [], jobs: [], message: null, effect: 'load', target: null };
40
+ editor.sources = { library: null, context: null, owner: 'editor-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2), closed: false, page: 'list', automaticInterval: 300, cursor: 0, scroll: 0, selected: null, kind: 'json', editing: false, fields: [], review: null, details: [], jobs: [], message: null, effect: 'load', target: null };
40
41
  }
41
42
  function source(editor: Editor): SourceDefinition | undefined { return editor.sources!.library?.sources.find(s => s.id === editor.sources!.selected); }
42
43
  function actions(editor: Editor): Action[] { return ['edit', 'review', ...(source(editor)?.enabled ? ['disable' as const] : []), 'bind', 'refresh', 'status', 'cancel', 'diagnose', 'remove', 'unbind', ...(source(editor)?.kind === 'github' ? ['auto-review' as const, 'auto-off' as const] : [])]; }
@@ -138,6 +139,7 @@ export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
138
139
  else if (m.page === 'remove')
139
140
  m.effect = 'remove';
140
141
  else if (m.page === 'unbind') {
142
+ if (!editor.canMutateDraft()) { m.message=editor.compositionError;return null; }
141
143
  const target = targets(editor)[m.cursor];
142
144
  const node = target && editor.instance(target.scope, target.id);
143
145
  if (node?.source) {
@@ -159,9 +161,10 @@ export async function closeSources(editor: Editor, backend: SourceBackend): Prom
159
161
  const m = editor.sources;
160
162
  if (!m)
161
163
  return;
164
+ m.closed = true;
162
165
  let failed: unknown;
163
- for (const job of m.jobs.filter(job => job.state === 'running' && job.owner === m.owner && job.trigger === 'manual')) {
164
- try { await backend.request('source_cancel', { id: job.id }); }
166
+ for (const job of m.jobs.filter(job => job.state === 'running')) {
167
+ try { await backend.request('source_release', { id: job.id, owner:m.owner }); }
165
168
  catch (error) { failed = error; }
166
169
  }
167
170
  if (failed) throw failed;
@@ -175,6 +178,8 @@ export async function performSourceAction(editor: Editor, backend: SourceBackend
175
178
  m.effect = null;
176
179
  m.message = null;
177
180
  try {
181
+ const generation=editor.mutationGeneration;
182
+ if (effect === 'bind' && !editor.canMutateDraft()) { m.message=editor.compositionError;return; }
178
183
  if (effect === 'close') {
179
184
  await closeSources(editor, backend);
180
185
  return;
@@ -207,8 +212,13 @@ export async function performSourceAction(editor: Editor, backend: SourceBackend
207
212
  const selected = source(editor)!;
208
213
  const context = await backend.request('source_context', { project: selected.scope.project ?? m.context?.project ?? null, session: selected.scope.session, agent: selected.scope.agent });
209
214
  if (effect === 'refresh') {
215
+ if (m.closed || editor.sources !== m) return;
210
216
  const job = await backend.request('source_refresh', { id: m.selected, context, owner: m.owner });
211
- m.jobs.push(job);
217
+ if (m.closed || editor.sources !== m) {
218
+ await backend.request('source_release', { id: job.id, owner: m.owner });
219
+ return;
220
+ }
221
+ m.jobs = [...m.jobs.filter(previous=>previous.id!==job.id),job];
212
222
  m.message = text('sources.refresh_started');
213
223
  }
214
224
  else {
@@ -238,6 +248,7 @@ export async function performSourceAction(editor: Editor, backend: SourceBackend
238
248
  const result = await backend.request('sources_apply', payload);
239
249
  m.library = result;
240
250
  if (effect === 'bind' && m.target && result.binding) {
251
+ if (!editor.canMutateDraft(generation) || editor.sources !== m) { m.message=editor.compositionError;return; }
241
252
  const node = editor.instance(m.target.scope, m.target.id);
242
253
  if (node)
243
254
  node.source = result.binding;
@@ -19,7 +19,7 @@ function definition(v: unknown): boolean {
19
19
  return fields(s, ['executable', 'args', 'cwd', 'input', 'output', 'timeout_ms']) && text(s.executable) && text(s.cwd) && Array.isArray(s.args) && s.args.length <= 128 && s.args.every(arg => typeof arg === 'string' && arg.length <= 8192 && !arg.includes('\0')) && object(s.input) && Object.entries(s.input).every(([key, value]) => /^[A-Za-z][A-Za-z0-9_]{0,63}$/u.test(key) && ['project', 'session', 'agent', 'branch', 'head'].includes(String(value))) && ['json', 'text'].includes(String(s.output)) && typeof s.timeout_ms === 'number' && Number.isInteger(s.timeout_ms) && s.timeout_ms >= 100 && s.timeout_ms <= 30000;
20
20
  }
21
21
  function job(v: unknown): boolean {
22
- return fields(v, ['version', 'id', 'source_id', 'source_revision', 'owner', 'context', 'started_at', 'deadline_at', 'state', 'reason', 'trigger', 'identity']) && v.version === 2 && ['manual', 'automatic'].includes(String(v.trigger)) && typeof v.identity === 'string' && /^[a-f0-9]{64}$/.test(v.identity) && ['id', 'source_id', 'source_revision', 'owner'].every(key => id(v[key])) && isSourceContext(v.context) && text(v.started_at) && Number.isFinite(Date.parse(v.started_at)) && text(v.deadline_at) && Number.isFinite(Date.parse(v.deadline_at)) && ['running', 'completed', 'failed', 'cancelled'].includes(String(v.state)) && text(v.reason);
22
+ return fields(v, ['version', 'id', 'source_id', 'source_revision', 'owner', 'context', 'started_at', 'deadline_at', 'state', 'reason', 'trigger', 'identity', 'consumers']) && v.version === 3 && Array.isArray(v.consumers) && v.consumers.length <= 128 && new Set(v.consumers.map(c=>object(c)?c.owner:null)).size === v.consumers.length && v.consumers.every(c=>fields(c,['owner','expires_at']) && id(c.owner) && text(c.expires_at) && Number.isFinite(Date.parse(c.expires_at)) && typeof v.deadline_at==='string' && Date.parse(c.expires_at)<=Date.parse(v.deadline_at)) && ['manual', 'automatic'].includes(String(v.trigger)) && typeof v.identity === 'string' && /^[a-f0-9]{64}$/.test(v.identity) && ['id', 'source_id', 'source_revision', 'owner'].every(key => id(v[key])) && isSourceContext(v.context) && text(v.started_at) && Number.isFinite(Date.parse(v.started_at)) && text(v.deadline_at) && Number.isFinite(Date.parse(v.deadline_at)) && ['running', 'completed', 'failed', 'cancelled'].includes(String(v.state)) && text(v.reason);
23
23
  }
24
24
  function view(v: unknown): boolean {
25
25
  return object(v) && nullable(v.source_id) && text(v.name) && ['valid', 'missing', 'partial', 'error', 'unsupported', 'disabled', 'unbound', 'mismatch'].includes(String(v.state)) && text(v.reason) && nullable(v.observed_at) && ['current', 'stale', 'unknown'].includes(String(v.freshness)) && scalar(v.value) && nullable(v.unit) && (v.fields === undefined || object(v.fields) && Object.values(v.fields).every(scalar));
@@ -31,7 +31,7 @@ export function isSourceResult(operation: string, value: unknown): boolean {
31
31
  return isSourceContext(value);
32
32
  if (operation === 'source_review')
33
33
  return fields(value, ['source', 'review_revision']) && definition(value.source) && object(value.source) && value.review_revision === value.source.revision;
34
- if (['source_refresh', 'source_status', 'source_cancel'].includes(operation))
34
+ if (['source_refresh', 'source_status', 'source_release', 'source_cancel'].includes(operation))
35
35
  return job(value);
36
36
  if (operation === 'source_diagnose')
37
37
  return fields(value, ['source', 'view', 'jobs', 'automatic']) && object(value.automatic) && ['off', 'waiting', 'running', 'backoff', 'paused'].includes(String(value.automatic.state)) && text(value.automatic.reason) && ['next_at', 'last_attempt', 'last_success'].every(k => value.automatic && nullable((value.automatic as Record<string, unknown>)[k])) && typeof value.automatic.interval_seconds === 'number' && value.automatic.interval_seconds >= 60 && value.automatic.interval_seconds <= 86400 && definition(value.source) && view(value.view) && Array.isArray(value.jobs) && value.jobs.every(job);
@@ -1,5 +1,5 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
- export const PROTOCOL_VERSION = 24 as const;
2
+ export const PROTOCOL_VERSION = 25 as const;
3
3
  export const ITEM_DEFAULTS = {"label": null, "icon": null, "priority": 50, "max_width": null, "formatting": {}, "foreground": null, "background": null, "visibility": "always", "visibility_threshold": 70};
4
4
  export const VISIBILITY_ITEMS = {"main": {"git": "git-dirty", "git-changes": "git-dirty", "active-agents": "nonzero", "task-progress": "nonzero", "context-used": "used-at-least", "context-remaining": "used-at-least", "five-hour-limit": "used-at-least", "weekly-limit": "used-at-least", "spend-limit": "used-at-least"}, "subagent": {"context-used": "used-at-least", "context-remaining": "used-at-least"}} as const;
5
5
  export const GUIDANCE_KEYS = {"source_kinds": ["configuration", "official_input", "local_git", "local_system", "transcript", "local_state", "lifecycle", "native_timing", "live_metrics", "telemetry"], "scopes": ["main", "main_context", "session", "all_sessions", "task", "subagent", "subagent_context", "repository", "local", "latest_request"], "requirements": ["observed_field", "subagent_rows", "agent_context", "configured_effort", "agent_effort_optional", "git_repository", "git_upstream", "git_base", "pull_request", "worktree_session", "usage_records", "task_observation", "native_timing", "complete_waits", "live_metrics", "owned_agents", "checklist_events", "tool_events", "complete_stream", "request_coverage", "existing_telemetry", "gateway", "gateway_284", "valid_window", "warm_cache", "fast_mode", "thinking", "agent_mode", "vim_mode", "context_observation", "cost_rate"]} as const;
@@ -509,7 +509,8 @@ export const SEPARATORSTYLE_VALUES = ["classic", "compact", "powerline"] as cons
509
509
  export const SCOPELABELS_VALUES = ["off", "when-subagents", "always"] as const;
510
510
  export const STATUSLINELANGUAGE_VALUES = ["en", "zh-CN", "zh-TW", "zh-HK", "ja", "ko"] as const;
511
511
  export const UNAVAILABLEREASON_VALUES = ["not_observed", "unsupported_host", "unknown_host_version", "source_unavailable", "condition_not_met", "runtime_disabled", "native_timing_disabled", "wait_coverage_missing", "stale", "incomplete", "ambiguous_owner", "observed_only", "missing_stream", "synthetic_response", "abnormal_clock", "inconsistent_request", "request_join_unavailable"] as const;
512
- export type Operation = "sources_read" | "sources_apply" | "source_review" | "source_context" | "source_refresh" | "source_status" | "source_cancel" | "source_diagnose" | "describe" | "read" | "preview" | "apply" | "import" | "export" | "preset" | "read_ui_preferences" | "set_ui_language" | "review_import" | "explain" | "diagnose" | "profiles_read" | "profiles_apply" | "profile_import" | "profile_export" | "task_details";
512
+ export const OPERATIONS = ['sources_read', 'sources_apply', 'source_review', 'source_context', 'source_refresh', 'source_status', 'source_release', 'source_cancel', 'source_diagnose', 'describe', 'read', 'preview', 'apply', 'import', 'export', 'preset', 'read_ui_preferences', 'set_ui_language', 'review_import', 'explain', 'diagnose', 'profiles_read', 'profiles_apply', 'profile_import', 'profile_export', 'task_details'] as const;
513
+ export type Operation = typeof OPERATIONS[number];
513
514
  export interface ItemGuidance {
514
515
  source_kinds: string[];
515
516
  measurement_scope: string;
@@ -741,7 +742,8 @@ export interface SourceView {
741
742
  fields?: Record<string, string | number | boolean | null>;
742
743
  }
743
744
  export interface SourceJob {
744
- version: 2; id: string; source_id: string; source_revision: string; owner: string; trigger: 'manual' | 'automatic'; identity: string;
745
+ version: 3; id: string; source_id: string; source_revision: string; owner: string; trigger: 'manual' | 'automatic'; identity: string;
746
+ consumers: { owner: string; expires_at: string }[];
745
747
  context: SourceContext; started_at: string; deadline_at: string;
746
748
  state: 'running' | 'completed' | 'failed' | 'cancelled'; reason: string;
747
749
  }
@@ -941,6 +943,7 @@ export interface ResultMap {
941
943
  source_context: SourceContext;
942
944
  source_refresh: SourceJob;
943
945
  source_status: SourceJob;
946
+ source_release: SourceJob;
944
947
  source_cancel: SourceJob;
945
948
  source_diagnose: { source: SourceDefinition; view: SourceView; jobs: SourceJob[]; automatic: AutomaticStatus };
946
949
  describe: DescribeResult;
@@ -1973,7 +1973,22 @@ export const LOCALES = {
1973
1973
  "alignment.references": "Adjust these alignment relationships before changing the layout: {ids}.",
1974
1974
  "gradients.preset.ocean": "Ocean",
1975
1975
  "gradients.preset.sunset": "Sunset",
1976
- "gradients.preset.aurora": "Aurora"
1976
+ "gradients.preset.aurora": "Aurora",
1977
+ "native.capacity.reduced": "View limited to {columns}×{rows}; use paging.",
1978
+ "native.capacity.failed": "The editor cannot draw this view.",
1979
+ "native.capacity.saved": "The last save succeeded. Retry only redraws the editor.",
1980
+ "native.capacity.unknown": "Save outcome unknown. Check saved state before retrying.",
1981
+ "native.capacity.retained": "Received draft retained; retry does not save or discard it.",
1982
+ "statusline.indicator.remaining": "{percentage}% left",
1983
+ "statusline.indicator.used": "{percentage}% used",
1984
+ "editor.save_locked": "Check the pending save before changing the display draft.",
1985
+ "editor.save_unknown": "Save outcome unknown. Ctrl+K checks saved state without saving again.",
1986
+ "editor.check_saved": "Check saved state",
1987
+ "editor.saved": "The submitted display configuration is saved.",
1988
+ "editor.not_committed": "No display changes were committed. The retained draft can be edited.",
1989
+ "editor.conflict": "Configuration conflict. The draft is retained; cancel and reopen to load the saved configuration.",
1990
+ "editor.still_unknown": "Save outcome remains unknown: {detail}",
1991
+ "task.language_unavailable": "Interface preferences are unavailable; using English."
1977
1992
  },
1978
1993
  "zh-CN": {
1979
1994
  "preferences.read_failed": "无法读取 {path} 的界面偏好,使用英文:{detail}",
@@ -3940,7 +3955,22 @@ export const LOCALES = {
3940
3955
  "alignment.references": "请先调整这些对齐关系,再更改布局:{ids}。",
3941
3956
  "gradients.preset.ocean": "海洋 (ocean)",
3942
3957
  "gradients.preset.sunset": "落日 (sunset)",
3943
- "gradients.preset.aurora": "极光 (aurora)"
3958
+ "gradients.preset.aurora": "极光 (aurora)",
3959
+ "native.capacity.reduced": "展示范围缩至 {columns}×{rows},可继续翻页。",
3960
+ "native.capacity.failed": "编辑器暂时无法绘制此视图。",
3961
+ "native.capacity.saved": "上次保存已成功;重试只会重新绘制界面。",
3962
+ "native.capacity.unknown": "保存结果未知,请先核对已保存状态。",
3963
+ "native.capacity.retained": "已接收的草稿仍保留;重试不会保存或丢弃草稿。",
3964
+ "statusline.indicator.remaining": "剩余 {percentage}%",
3965
+ "statusline.indicator.used": "已用 {percentage}%",
3966
+ "editor.save_locked": "修改显示草稿前,请先核对尚未确定的保存结果。",
3967
+ "editor.save_unknown": "保存结果未知。Ctrl+K 只读核对已保存状态,不会再次保存。",
3968
+ "editor.check_saved": "核对保存状态",
3969
+ "editor.saved": "提交的显示配置已保存。",
3970
+ "editor.not_committed": "未提交显示更改,可以继续编辑保留的草稿。",
3971
+ "editor.conflict": "配置冲突。草稿已保留;取消并重新打开可加载已保存配置。",
3972
+ "editor.still_unknown": "保存结果仍未知:{detail}",
3973
+ "task.language_unavailable": "无法读取界面偏好,使用英语。"
3944
3974
  },
3945
3975
  "zh-TW": {
3946
3976
  "preferences.read_failed": "無法讀取 {path} 的介面偏好,使用英文:{detail}",
@@ -5907,7 +5937,22 @@ export const LOCALES = {
5907
5937
  "alignment.references": "請先調整這些對齊關係,再變更配置:{ids}。",
5908
5938
  "gradients.preset.ocean": "海洋 (ocean)",
5909
5939
  "gradients.preset.sunset": "落日 (sunset)",
5910
- "gradients.preset.aurora": "極光 (aurora)"
5940
+ "gradients.preset.aurora": "極光 (aurora)",
5941
+ "native.capacity.reduced": "顯示範圍縮至 {columns}×{rows},可繼續翻頁。",
5942
+ "native.capacity.failed": "編輯器暫時無法繪製此檢視。",
5943
+ "native.capacity.saved": "上次儲存已成功;重試只會重新繪製介面。",
5944
+ "native.capacity.unknown": "儲存結果未知,請先核對已儲存狀態。",
5945
+ "native.capacity.retained": "已接收的草稿仍保留;重試不會儲存或捨棄草稿。",
5946
+ "statusline.indicator.remaining": "剩餘 {percentage}%",
5947
+ "statusline.indicator.used": "已用 {percentage}%",
5948
+ "editor.save_locked": "修改顯示草稿前,請先核對尚未確定的儲存結果。",
5949
+ "editor.save_unknown": "儲存結果未知。Ctrl+K 唯讀核對已儲存狀態,不會再次儲存。",
5950
+ "editor.check_saved": "核對儲存狀態",
5951
+ "editor.saved": "提交的顯示設定已儲存。",
5952
+ "editor.not_committed": "未提交顯示變更,可以繼續編輯保留的草稿。",
5953
+ "editor.conflict": "設定衝突。草稿已保留;取消並重新開啟可載入已儲存設定。",
5954
+ "editor.still_unknown": "儲存結果仍未知:{detail}",
5955
+ "task.language_unavailable": "無法讀取介面偏好,使用英語。"
5911
5956
  },
5912
5957
  "zh-HK": {
5913
5958
  "preferences.read_failed": "無法讀取 {path} 的介面偏好,使用英文:{detail}",
@@ -7874,7 +7919,22 @@ export const LOCALES = {
7874
7919
  "alignment.references": "請先調整這些對齊關係,再更改佈局:{ids}。",
7875
7920
  "gradients.preset.ocean": "海洋 (ocean)",
7876
7921
  "gradients.preset.sunset": "落日 (sunset)",
7877
- "gradients.preset.aurora": "極光 (aurora)"
7922
+ "gradients.preset.aurora": "極光 (aurora)",
7923
+ "native.capacity.reduced": "顯示範圍縮至 {columns}×{rows},可繼續翻頁。",
7924
+ "native.capacity.failed": "編輯器暫時無法繪製此畫面。",
7925
+ "native.capacity.saved": "上次儲存已成功;重試只會重新繪製介面。",
7926
+ "native.capacity.unknown": "儲存結果未知,請先核對已儲存狀態。",
7927
+ "native.capacity.retained": "已接收的草稿仍保留;重試不會儲存或捨棄草稿。",
7928
+ "statusline.indicator.remaining": "剩餘 {percentage}%",
7929
+ "statusline.indicator.used": "已用 {percentage}%",
7930
+ "editor.save_locked": "修改顯示草稿前,請先核對尚未確定的儲存結果。",
7931
+ "editor.save_unknown": "儲存結果未知。Ctrl+K 唯讀核對已儲存狀態,不會再次儲存。",
7932
+ "editor.check_saved": "核對儲存狀態",
7933
+ "editor.saved": "提交的顯示設定已儲存。",
7934
+ "editor.not_committed": "未提交顯示變更,可以繼續編輯保留的草稿。",
7935
+ "editor.conflict": "設定衝突。草稿已保留;取消並重新開啟可載入已儲存設定。",
7936
+ "editor.still_unknown": "儲存結果仍未知:{detail}",
7937
+ "task.language_unavailable": "無法讀取介面偏好,使用英語。"
7878
7938
  },
7879
7939
  "ja": {
7880
7940
  "preferences.read_failed": "{path} の UI 設定を読み込めません。英語を使用します: {detail}",
@@ -9841,7 +9901,22 @@ export const LOCALES = {
9841
9901
  "alignment.references": "レイアウトを変更する前に、次の整列関係を調整してください:{ids}。",
9842
9902
  "gradients.preset.ocean": "海 (ocean)",
9843
9903
  "gradients.preset.sunset": "夕日 (sunset)",
9844
- "gradients.preset.aurora": "オーロラ (aurora)"
9904
+ "gradients.preset.aurora": "オーロラ (aurora)",
9905
+ "native.capacity.reduced": "表示を {columns}×{rows} に制限しました。ページ移動できます。",
9906
+ "native.capacity.failed": "この画面を描画できません。",
9907
+ "native.capacity.saved": "前回の保存は成功しました。再試行は再描画のみです。",
9908
+ "native.capacity.unknown": "保存結果が不明です。再試行前に保存状態を確認してください。",
9909
+ "native.capacity.retained": "受信済みの下書きは保持されています。再試行では保存も破棄もしません。",
9910
+ "statusline.indicator.remaining": "残り {percentage}%",
9911
+ "statusline.indicator.used": "使用 {percentage}%",
9912
+ "editor.save_locked": "表示の下書きを変更する前に、未確定の保存結果を確認してください。",
9913
+ "editor.save_unknown": "保存結果は不明です。Ctrl+K で再保存せずに保存状態を確認します。",
9914
+ "editor.check_saved": "保存状態を確認",
9915
+ "editor.saved": "送信した表示設定は保存されています。",
9916
+ "editor.not_committed": "表示の変更は保存されていません。保持された下書きを編集できます。",
9917
+ "editor.conflict": "設定が競合しています。下書きは保持されています。キャンセルして開き直すと保存済み設定を読み込みます。",
9918
+ "editor.still_unknown": "保存結果はまだ不明です: {detail}",
9919
+ "task.language_unavailable": "インターフェース設定を読み込めないため、英語を使用します。"
9845
9920
  },
9846
9921
  "ko": {
9847
9922
  "preferences.read_failed": "{path}의 UI 환경설정을 읽을 수 없어 영어를 사용합니다: {detail}",
@@ -11808,7 +11883,22 @@ export const LOCALES = {
11808
11883
  "alignment.references": "레이아웃을 변경하기 전에 다음 정렬 관계를 조정하세요: {ids}.",
11809
11884
  "gradients.preset.ocean": "바다 (ocean)",
11810
11885
  "gradients.preset.sunset": "노을 (sunset)",
11811
- "gradients.preset.aurora": "오로라 (aurora)"
11886
+ "gradients.preset.aurora": "오로라 (aurora)",
11887
+ "native.capacity.reduced": "표시 영역을 {columns}×{rows}로 줄였습니다. 페이지를 이동할 수 있습니다.",
11888
+ "native.capacity.failed": "이 화면을 그릴 수 없습니다.",
11889
+ "native.capacity.saved": "마지막 저장이 완료되었습니다. 재시도는 화면만 다시 그립니다.",
11890
+ "native.capacity.unknown": "저장 결과를 알 수 없습니다. 재시도 전에 저장 상태를 확인하세요.",
11891
+ "native.capacity.retained": "받은 초안은 유지됩니다. 재시도는 초안을 저장하거나 버리지 않습니다.",
11892
+ "statusline.indicator.remaining": "{percentage}% 남음",
11893
+ "statusline.indicator.used": "{percentage}% 사용",
11894
+ "editor.save_locked": "표시 초안을 변경하기 전에 미확정 저장 결과를 확인하세요.",
11895
+ "editor.save_unknown": "저장 결과를 알 수 없습니다. Ctrl+K로 다시 저장하지 않고 저장 상태를 확인합니다.",
11896
+ "editor.check_saved": "저장 상태 확인",
11897
+ "editor.saved": "제출한 표시 설정이 저장되었습니다.",
11898
+ "editor.not_committed": "표시 변경 사항이 저장되지 않았습니다. 보존된 초안을 편집할 수 있습니다.",
11899
+ "editor.conflict": "설정 충돌입니다. 초안이 보존되었습니다. 취소하고 다시 열면 저장된 설정을 불러옵니다.",
11900
+ "editor.still_unknown": "저장 결과를 아직 알 수 없습니다: {detail}",
11901
+ "task.language_unavailable": "인터페이스 환경설정을 읽을 수 없어 영어를 사용합니다。"
11812
11902
  }
11813
11903
  } as const;
11814
11904
  export type MessageKey = keyof typeof LOCALES.en;
@@ -1,10 +1,14 @@
1
1
  import type { TextInput } from './editor/text-input.ts';
2
- import { Editor } from './editor/draft.ts';
2
+ import type { Editor } from './editor/draft.ts';
3
3
  import type { Scope, PreviewResult } from './generated-contracts.ts';
4
4
  import type { Preference } from './preferences.ts';
5
5
  import type { PreviewBackground } from './preview-preferences.ts';
6
6
  import type { Language, LocalizedText } from './i18n/index.ts';
7
7
  import type { MessageSlot } from './i18n/messages.ts';
8
+ import { t } from './i18n/index.ts';
9
+ import { draw } from '../ui/client/draw.ts';
10
+ import { CapacityError, frameElements, frameTree, withinBudget } from '../ui/frame.ts';
11
+ import type { Frame } from '../ui/frame.ts';
8
12
 
9
13
  export type InputMode = (
10
14
  | { kind: 'search'; scope: Scope; original: string; selected: string }
@@ -31,101 +35,35 @@ export interface View {
31
35
  uncertain: boolean;
32
36
  }
33
37
 
34
- type EditorData = Pick<
35
- Editor,
36
- | 'description'
37
- | 'baseline'
38
- | 'draft'
39
- | 'page'
40
- | 'advanced'
41
- | 'adding'
42
- | 'pickerSaved'
43
- | 'detail'
44
- | 'guidanceScroll'
45
- | 'explanation'
46
- | 'profiles'
47
- | 'sources'
48
- | 'quick'
49
- | 'groupManager'
50
- | 'alignmentManager'
51
- | 'review'
52
- | 'preset'
53
- | 'path'
54
- | 'pendingTransfer'
55
- | 'setting'
56
- | 'activeNumeric'
57
- | 'selected'
58
- | 'order'
59
- | 'search'
60
- | 'category'
61
- | 'buffers'
62
- | 'fieldErrors'
63
- | 'fieldErrorMessages'
64
- >;
38
+ /** Private host-to-Client presentation contract; unrelated to the backend protocol. */
65
39
  export interface ClientProps {
66
40
  epoch: number;
67
41
  ack: number;
68
42
  generation: number;
69
43
  columns: number;
70
44
  rows: number;
71
- view: Omit<View, 'editor'> & { editor: EditorData | null };
45
+ displayColumns: number;
46
+ displayRows: number;
47
+ language: Language;
48
+ busy: boolean;
49
+ frame: Frame;
72
50
  }
73
51
 
74
- export function clientProps(
75
- view: View,
76
- epoch: number,
77
- ack: number,
78
- generation: number,
79
- columns: number,
80
- rows: number,
81
- ): ClientProps {
82
- const e = view.editor;
83
- // The host freezes port data recursively. Never expose live editor arrays or
84
- // preference rows: subsequent keys must still mutate our own draft.
85
- return JSON.parse(
86
- JSON.stringify({
87
- epoch,
88
- ack,
89
- generation,
90
- columns,
91
- rows,
92
- view: {
93
- ...view,
94
- editor: e
95
- ? {
96
- description: e.description,
97
- baseline: e.baseline,
98
- draft: e.draft,
99
- page: e.page,
100
- advanced: e.advanced,
101
- adding: e.adding,
102
- pickerSaved: e.pickerSaved,
103
- detail: e.detail, preset: e.preset, path: e.path, pendingTransfer: e.pendingTransfer,
104
- guidanceScroll: e.guidanceScroll,
105
- groupManager: e.groupManager, alignmentManager: e.alignmentManager, review: e.review, quick: e.quick, explanation:e.explanation, profiles:e.profiles, sources:e.sources,
106
- setting: e.setting,
107
- activeNumeric: e.activeNumeric,
108
- selected: e.selected,
109
- order: e.order,
110
- search: e.search,
111
- category: e.category,
112
- buffers: e.buffers,
113
- fieldErrors: e.fieldErrors,
114
- fieldErrorMessages: e.fieldErrorMessages,
115
- }
116
- : null,
117
- },
118
- }),
119
- ) as ClientProps;
120
- }
121
-
122
- /** Rendering uses the same editor model, with only plain data crossing ports. */
123
- export function clientView(props: ClientProps): View {
124
- const data = props.view.editor;
125
- return {
126
- ...props.view,
127
- editor: data
128
- ? Object.assign(new Editor(data.description, data.baseline), data)
129
- : null,
130
- };
52
+ export function clientProps(view: View, epoch: number, ack: number, generation: number, columns: number, rows: number): ClientProps {
53
+ let width = Math.max(2, Math.min(10000, columns));
54
+ let height = Math.max(0, Math.min(10000, rows));
55
+ for (;;) {
56
+ try {
57
+ const { elements, frame } = frameElements();
58
+ const reduced = width !== columns || height !== rows;
59
+ draw(elements, view, width, height, reduced ? t('native.capacity.reduced', view.language ?? 'en', {columns: width, rows: height}) : '');
60
+ const result: ClientProps = { epoch, ack, generation, columns, rows, displayColumns: width, displayRows: height, language: view.language ?? 'en', busy: !!view.busy, frame };
61
+ if (withinBudget(result) && withinBudget(frameTree(frame))) return result;
62
+ } catch (error) {
63
+ if (!(error instanceof CapacityError)) throw error;
64
+ }
65
+ if (height > 12) height = Math.max(12, Math.floor(height * 0.75));
66
+ else if (width > 32) width = Math.max(32, Math.floor(width * 0.75));
67
+ else throw new CapacityError();
68
+ }
131
69
  }