@fbincon/claude-code-statusline 3.5.0 → 3.6.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 (184) hide show
  1. package/README.md +74 -73
  2. package/candidate.json +318 -248
  3. package/node_modules/@fbincon/statusline-cli/dist/src/config/profiles.js +2 -1
  4. package/node_modules/@fbincon/statusline-cli/dist/src/config/profiles.js.map +1 -1
  5. package/node_modules/@fbincon/statusline-cli/dist/src/config/transfer.js +5 -3
  6. package/node_modules/@fbincon/statusline-cli/dist/src/config/transfer.js.map +1 -1
  7. package/node_modules/@fbincon/statusline-cli/dist/src/diagnostics/service.js +24 -0
  8. package/node_modules/@fbincon/statusline-cli/dist/src/diagnostics/service.js.map +1 -1
  9. package/node_modules/@fbincon/statusline-cli/dist/src/help.js +3 -0
  10. package/node_modules/@fbincon/statusline-cli/dist/src/help.js.map +1 -1
  11. package/node_modules/@fbincon/statusline-cli/dist/src/main.js +19 -3
  12. package/node_modules/@fbincon/statusline-cli/dist/src/main.js.map +1 -1
  13. package/node_modules/@fbincon/statusline-cli/dist/src/recovery/journal.js +1 -1
  14. package/node_modules/@fbincon/statusline-cli/dist/src/recovery/journal.js.map +1 -1
  15. package/node_modules/@fbincon/statusline-cli/dist/src/rendering/environment.js +46 -1
  16. package/node_modules/@fbincon/statusline-cli/dist/src/rendering/environment.js.map +1 -1
  17. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.d.ts +3 -0
  18. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js +117 -0
  19. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js.map +1 -0
  20. package/node_modules/@fbincon/statusline-cli/dist/src/sources/context.d.ts +4 -0
  21. package/node_modules/@fbincon/statusline-cli/dist/src/sources/context.js +35 -0
  22. package/node_modules/@fbincon/statusline-cli/dist/src/sources/context.js.map +1 -0
  23. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.d.ts +8 -0
  24. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js +118 -0
  25. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js.map +1 -0
  26. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.d.ts +35 -0
  27. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js +359 -0
  28. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js.map +1 -0
  29. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +2 -2
  30. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +30 -1
  31. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js.map +1 -1
  32. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/.claude-plugin/plugin.json +1 -1
  33. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/hooks/register.ts +15 -5
  34. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/backend.ts +8 -5
  35. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +6 -2
  36. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/settings.ts +1 -0
  37. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/appearance.ts +24 -6
  38. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +2 -0
  39. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/forms.ts +1 -1
  40. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-manager.ts +301 -0
  41. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-validation.ts +45 -0
  42. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +79 -8
  43. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +738 -6
  44. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/session.ts +2 -1
  45. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +18 -16
  46. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +5 -1
  47. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/help.ts +1 -0
  48. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/.claude-plugin/plugin.json +1 -1
  49. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/resource-manifest.json +3 -3
  50. package/node_modules/@fbincon/statusline-core/dist/src/config/catalog-data.d.ts +91 -0
  51. package/node_modules/@fbincon/statusline-core/dist/src/config/catalog-data.js +250 -0
  52. package/node_modules/@fbincon/statusline-core/dist/src/config/catalog-data.js.map +1 -1
  53. package/node_modules/@fbincon/statusline-core/dist/src/config/defaults.js +1 -1
  54. package/node_modules/@fbincon/statusline-core/dist/src/config/defaults.js.map +1 -1
  55. package/node_modules/@fbincon/statusline-core/dist/src/config/display.d.ts +1 -1
  56. package/node_modules/@fbincon/statusline-core/dist/src/config/display.js +13 -6
  57. package/node_modules/@fbincon/statusline-core/dist/src/config/display.js.map +1 -1
  58. package/node_modules/@fbincon/statusline-core/dist/src/config/editor-fields.js +7 -10
  59. package/node_modules/@fbincon/statusline-core/dist/src/config/editor-fields.js.map +1 -1
  60. package/node_modules/@fbincon/statusline-core/dist/src/config/formatting.js +4 -1
  61. package/node_modules/@fbincon/statusline-core/dist/src/config/formatting.js.map +1 -1
  62. package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.js +4 -2
  63. package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.js.map +1 -1
  64. package/node_modules/@fbincon/statusline-core/dist/src/config/instances.js +7 -2
  65. package/node_modules/@fbincon/statusline-core/dist/src/config/instances.js.map +1 -1
  66. package/node_modules/@fbincon/statusline-core/dist/src/config/profiles.js +2 -1
  67. package/node_modules/@fbincon/statusline-core/dist/src/config/profiles.js.map +1 -1
  68. package/node_modules/@fbincon/statusline-core/dist/src/config/transfer.js +5 -3
  69. package/node_modules/@fbincon/statusline-core/dist/src/config/transfer.js.map +1 -1
  70. package/node_modules/@fbincon/statusline-core/dist/src/contracts/generated-catalog.d.ts +2 -2
  71. package/node_modules/@fbincon/statusline-core/dist/src/contracts/generated-catalog.js +2 -2
  72. package/node_modules/@fbincon/statusline-core/dist/src/contracts/generated-catalog.js.map +1 -1
  73. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +134 -6
  74. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js +2 -2
  75. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js.map +1 -1
  76. package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.d.ts +4 -2
  77. package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.js +29 -6
  78. package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.js.map +1 -1
  79. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js +10 -5
  80. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js.map +1 -1
  81. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.d.ts +2 -0
  82. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +1 -0
  83. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
  84. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js +1 -1
  85. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js.map +1 -1
  86. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.d.ts +39 -0
  87. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js +270 -0
  88. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js.map +1 -0
  89. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.d.ts +2 -0
  90. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js +45 -0
  91. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js.map +1 -0
  92. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.d.ts +27 -0
  93. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js +222 -0
  94. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js.map +1 -0
  95. package/node_modules/@fbincon/statusline-core/dist/src/extensions/portable.d.ts +3 -0
  96. package/node_modules/@fbincon/statusline-core/dist/src/extensions/portable.js +6 -0
  97. package/node_modules/@fbincon/statusline-core/dist/src/extensions/portable.js.map +1 -0
  98. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +732 -0
  99. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +738 -6
  100. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
  101. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.d.ts +26 -0
  102. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.js +27 -1
  103. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.js.map +1 -1
  104. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.d.ts +26 -0
  105. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.js +27 -1
  106. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.js.map +1 -1
  107. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.d.ts +26 -0
  108. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.js +27 -1
  109. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.js.map +1 -1
  110. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.d.ts +26 -0
  111. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.js +27 -1
  112. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.js.map +1 -1
  113. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.d.ts +26 -0
  114. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.js +27 -1
  115. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.js.map +1 -1
  116. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.d.ts +26 -0
  117. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.js +27 -1
  118. package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.js.map +1 -1
  119. package/node_modules/@fbincon/statusline-core/dist/src/release.d.ts +1 -1
  120. package/node_modules/@fbincon/statusline-core/dist/src/release.js +1 -1
  121. package/node_modules/@fbincon/statusline-core/dist/src/rendering/appearance.js +1 -1
  122. package/node_modules/@fbincon/statusline-core/dist/src/rendering/appearance.js.map +1 -1
  123. package/node_modules/@fbincon/statusline-core/dist/src/rendering/context.d.ts +3 -0
  124. package/node_modules/@fbincon/statusline-core/dist/src/rendering/diagnose.js +1 -1
  125. package/node_modules/@fbincon/statusline-core/dist/src/rendering/diagnose.js.map +1 -1
  126. package/node_modules/@fbincon/statusline-core/dist/src/rendering/explain.js +2 -0
  127. package/node_modules/@fbincon/statusline-core/dist/src/rendering/explain.js.map +1 -1
  128. package/node_modules/@fbincon/statusline-core/dist/src/rendering/extensions.d.ts +7 -0
  129. package/node_modules/@fbincon/statusline-core/dist/src/rendering/extensions.js +35 -0
  130. package/node_modules/@fbincon/statusline-core/dist/src/rendering/extensions.js.map +1 -0
  131. package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js +8 -2
  132. package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js.map +1 -1
  133. package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.d.ts +3 -0
  134. package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.js +30 -9
  135. package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.js.map +1 -1
  136. package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.js +1 -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/preview.js +3 -1
  139. package/node_modules/@fbincon/statusline-core/dist/src/rendering/preview.js.map +1 -1
  140. package/node_modules/@fbincon/statusline-core/dist/src/rendering/spans.d.ts +1 -0
  141. package/node_modules/@fbincon/statusline-core/dist/src/rendering/spans.js +2 -2
  142. package/node_modules/@fbincon/statusline-core/dist/src/rendering/spans.js.map +1 -1
  143. package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js +12 -1
  144. package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js.map +1 -1
  145. package/node_modules/@fbincon/statusline-core/dist/src/terminal/links.d.ts +6 -0
  146. package/node_modules/@fbincon/statusline-core/dist/src/terminal/links.js +37 -0
  147. package/node_modules/@fbincon/statusline-core/dist/src/terminal/links.js.map +1 -0
  148. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +123 -1
  149. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +123 -1
  150. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +123 -1
  151. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +123 -1
  152. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +123 -1
  153. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +123 -1
  154. package/node_modules/@fbincon/statusline-platform/dist/src/posix-source-exec.d.ts +1 -0
  155. package/node_modules/@fbincon/statusline-platform/dist/src/posix-source-exec.js +26 -0
  156. package/node_modules/@fbincon/statusline-platform/dist/src/posix-source-exec.js.map +1 -0
  157. package/node_modules/@fbincon/statusline-platform/dist/src/source-files.d.ts +2 -0
  158. package/node_modules/@fbincon/statusline-platform/dist/src/source-files.js +37 -0
  159. package/node_modules/@fbincon/statusline-platform/dist/src/source-files.js.map +1 -0
  160. package/node_modules/@fbincon/statusline-platform/dist/src/source-process.d.ts +19 -0
  161. package/node_modules/@fbincon/statusline-platform/dist/src/source-process.js +122 -0
  162. package/node_modules/@fbincon/statusline-platform/dist/src/source-process.js.map +1 -0
  163. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.d.ts +4 -0
  164. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.js +61 -0
  165. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.js.map +1 -0
  166. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-job.d.ts +3 -0
  167. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-job.js +61 -0
  168. package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-job.js.map +1 -0
  169. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/canvas.js +3 -2
  170. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/canvas.js.map +1 -1
  171. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js +5 -0
  172. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js.map +1 -1
  173. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/presentation.js +2 -0
  174. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/presentation.js.map +1 -1
  175. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js +2 -0
  176. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js.map +1 -1
  177. package/node_modules/@fbincon/statusline-tui/dist/src/drawing.js +1 -1
  178. package/node_modules/@fbincon/statusline-tui/dist/src/drawing.js.map +1 -1
  179. package/node_modules/@fbincon/statusline-tui/dist/src/session.js +6 -0
  180. package/node_modules/@fbincon/statusline-tui/dist/src/session.js.map +1 -1
  181. package/node_modules/@fbincon/statusline-tui/dist/src/state.d.ts +1 -1
  182. package/node_modules/@fbincon/statusline-tui/dist/src/state.js +12 -1
  183. package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
  184. package/package.json +1 -1
@@ -24,6 +24,7 @@ import type {
24
24
  Span,
25
25
  } from './generated-contracts.ts';
26
26
  import { validColor, visibilityChoices } from './editor/appearance.ts';
27
+ import { isSourceResult } from './editor/source-validation.ts';
27
28
  import { isLocalizedText } from './i18n/index.ts';
28
29
  import type { LocalizedText } from './i18n/index.ts';
29
30
 
@@ -104,7 +105,7 @@ function formatOverrides(value: unknown): boolean {
104
105
  function itemOptions(value: unknown, ids: readonly string[], scope: "main" | "subagent"): boolean {
105
106
  if (!object(value)) return false;
106
107
  return Object.entries(value).every(([id, option]) => ids.includes(id) && object(option) &&
107
- exact(option, ['label', 'icon', 'priority', 'max_width', 'formatting', 'foreground', 'background', 'visibility', 'visibility_threshold']) &&
108
+ exact(option, ['label', 'icon', 'priority', 'max_width', 'formatting', 'foreground', 'background', 'visibility', 'visibility_threshold', ...(option.link !== undefined ? ['link'] : [])]) && (option.link === undefined || ['off','auto','on'].includes(String(option.link))) &&
108
109
  (option.label === null || (text(option.label) && [...option.label].length <= 256)) &&
109
110
  (option.icon === null || (text(option.icon) && [...option.icon].length <= 256)) &&
110
111
  range(option.priority, 0, 100) && range(option.max_width, 2, 10000, true) &&
@@ -126,7 +127,7 @@ function instanceList(value: unknown, ids: readonly string[], scope: "main" | "s
126
127
  if (!Array.isArray(value)) return false;
127
128
  const seen = new Set<string>();
128
129
  return value.every(node => {
129
- if (!object(node) || !exact(node,['id','type_id','enabled','options','text']) ||
130
+ if (!object(node) || !exact(node,['id','type_id','enabled','options','text', ...(node.source !== undefined ? ['source'] : [])]) || node.source !== undefined && (!object(node.source) || !exact(node.source,['binding','hint']) || !(node.source.binding === null || text(node.source.binding)) || !text(node.source.hint)) ||
130
131
  typeof node.id !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/.test(node.id) || seen.has(node.id) ||
131
132
  typeof node.type_id !== 'string' || !ids.includes(node.type_id) || typeof node.enabled !== 'boolean' ||
132
133
  !itemOptions({[node.type_id]: node.options},ids,scope)) return false;
@@ -169,7 +170,7 @@ export function isDraft(value: unknown): value is Draft {
169
170
  )
170
171
  return false;
171
172
  if (
172
- d.schema_version !== 9 ||
173
+ d.schema_version !== 10 ||
173
174
  !object(d.powerline) || !exact(d.powerline, POWERLINE_FIELDS.map(f => f.key.slice(10))) ||
174
175
  !POWERLINE_FIELDS.every(f => f.kind === 'boolean' ? typeof (d.powerline as Record<string, unknown>)[f.key.slice(10)] === 'boolean' :
175
176
  (f.choices as readonly unknown[]).includes((d.powerline as Record<string, unknown>)[f.key.slice(10)])) ||
@@ -469,6 +470,8 @@ export function parseResponse<O extends Operation>(
469
470
  if (!exact(result, ['draft','changes']) || !isDraft(result.draft) || !Array.isArray(result.changes) || !result.changes.every(isImportChange)) fail();
470
471
  } else if (operation === 'import' || operation === 'preset') {
471
472
  if (!isDraft(result.draft)) fail();
473
+ } else if (operation.startsWith('source')) {
474
+ if (!isSourceResult(operation,result)) fail();
472
475
  } else if (operation === 'profiles_read' || operation === 'profiles_apply') {
473
476
  if (!isProfiles(result) || operation === 'profiles_apply' && (typeof result.changed !== 'boolean' || !(result.backup_dir === null || text(result.backup_dir)))) fail();
474
477
  } else if (operation === 'profile_import') {
@@ -508,8 +511,8 @@ export function parseResponse<O extends Operation>(
508
511
  !result.backend_version ||
509
512
  !isOptions(result.options) ||
510
513
  !isCapabilities(result.capabilities) ||
511
- !selection(result.operations, ['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
- result.operations.length !== 17 ||
514
+ !selection(result.operations, ['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']) ||
515
+ result.operations.length !== 25 ||
513
516
  JSON.stringify(result.editor_fields) !== JSON.stringify(EDITOR_FIELDS) ||
514
517
  JSON.stringify(result.presets) !== JSON.stringify(PRESETS) ||
515
518
  !object(result.formatting_options) ||
@@ -1,3 +1,4 @@
1
+ import { openSources, sourcesKey } from '../editor/source-manager.ts';
1
2
  import { openExplanation, explanationKey } from '../editor/explanation.ts';
2
3
  import { openQuick, controlQuick } from '../editor/quick-setup.ts';
3
4
  import { openProfiles, profilesKey } from '../editor/profile-manager.ts';
@@ -14,7 +15,7 @@ import { formSelection, pageSelection } from '../editor/navigation.ts';
14
15
  import { guidanceLines } from '../editor/guidance.ts';
15
16
  import { navigateReview } from '../editor/import-review.ts';
16
17
 
17
- export type Effect = 'save' | 'finish' | 'close' | 'reload' | 'reconcile' | 'retry' | 'applyPreferences' | 'transfer' | 'previewBackground' | 'uiLanguage' | 'reviewPreview' | 'explain' | 'profiles' | null;
18
+ export type Effect = 'save' | 'finish' | 'close' | 'reload' | 'reconcile' | 'retry' | 'applyPreferences' | 'transfer' | 'previewBackground' | 'uiLanguage' | 'reviewPreview' | 'explain' | 'profiles' | 'sources' | null;
18
19
 
19
20
  export function cancelInput(view: View): void {
20
21
  const input = view.input, e = view.editor;
@@ -35,6 +36,8 @@ export function handleKey(view: View, event: NativeKeyEvent, columns: number, ro
35
36
  const shortcut = /^[A-Z]$/.test(key) ? key.toLowerCase() : key;
36
37
  if (!e || view.busy) return null;
37
38
  if (event.overflow) { setMessage(view, 'message', localizedText('input.overflow')); return null; }
39
+ if (e.sources) return sourcesKey(e,event);
40
+ if (event.ctrl && key.toLowerCase()==='y' && !view.input && !e.review && !e.quick && !e.explanation) {openSources(e);return 'sources';}
38
41
  if (e.profiles) return profilesKey(e, { ...event, key: key === 'return' ? 'enter' : key });
39
42
  if (event.ctrl && key.toLowerCase() === 'o' && !view.input && !e.detail && !e.adding && !e.review && !e.quick && !e.explanation && !view.uncertain) {
40
43
  if (e.acceptNumeric()) { openProfiles(e); return 'profiles'; }
@@ -143,7 +146,7 @@ export function handleKey(view: View, event: NativeKeyEvent, columns: number, ro
143
146
  return null;
144
147
  }
145
148
  if(e.adding&&!event.ctrl&&!event.meta&&shortcut==='q'){e.closePicker(scope);return null;}
146
- if(e.adding&&event.ctrl&&key.toLowerCase()==='e'){e.detail={scope,id:e.selected[scope]};e.guidanceScroll=0;return null;}
149
+ if(e.adding&&event.ctrl&&key.toLowerCase()==='y'){e.detail={scope,id:e.selected[scope]};e.guidanceScroll=0;return null;}
147
150
  if(e.adding&&['tab','1','2','3','4'].includes(key))return null;
148
151
  }
149
152
  if (event.ctrl && key.toLowerCase() === 'e' && (e.page === 'main' || e.page === 'subagents')) {
@@ -197,6 +200,7 @@ export function handleKey(view: View, event: NativeKeyEvent, columns: number, ro
197
200
  return isSettings && e.setting === 'preview-background' ? 'previewBackground' : isSettings && e.setting === 'ui-language' ? 'uiLanguage' : null;
198
201
  } else if (key === 'return' || key === ' ' || key === 'space') {
199
202
  if (!isSettings) { if(!e.toggle(scope, selected))setMessage(view,"message",localizedText("composition.invalid")); }
203
+ else if (e.setting === 'sources') {openSources(e);return 'sources';}
200
204
  else if (e.setting === 'profiles') { if (e.acceptNumeric()) { openProfiles(e); return 'profiles'; } }
201
205
  else if (e.setting === 'quick-setup') { if (e.acceptNumeric()) e.quick=openQuick(e.draft); }
202
206
  else if(e.setting==='item-explain' && e.detail) { e.explanation=openExplanation(e.detail.scope,e.detail.id); return 'explain'; }
@@ -97,6 +97,7 @@ export function settingRows(view: View): SettingRow[] {
97
97
  rows.push(...fields.filter(row => row.group !== 'Appearance'));
98
98
  rows.push(
99
99
  { key: 'ui-language', label: 'Interface language (saved immediately)', group: 'Interface', value: LANGUAGE_NAMES[view.language ?? 'en'], editable: true },
100
+ { key: 'sources', label: 'Data sources', group: 'Presets / portable files', value: 'Enter', editable: true },
100
101
  { key: 'profiles', label: 'Display schemes and projects', group: 'Presets / portable files', value: 'Enter', editable: true },
101
102
  { key: 'quick-setup', label: 'Quick setup', group: 'Presets / portable files', value: 'Enter', editable: true },
102
103
  { key: 'preset-select', label: 'Preset', group: 'Presets / portable files', value: e.preset, editable: true },
@@ -1,21 +1,39 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
2
  /** Pure controls/validation from Python's scoped visibility capabilities. */
3
- import { VISIBILITY_ITEMS } from '../generated-contracts.ts';
4
- import type { Scope, EditorField } from '../generated-contracts.ts';
3
+ import { VISIBILITY_ITEMS, FORMAT_CHOICES } from '../generated-contracts.ts';
4
+ import type { Scope, EditorField, ItemCapability } from '../generated-contracts.ts';
5
5
 
6
6
  export function visibilityChoices(scope: Scope, id: string): string[] {
7
7
  const rule = (VISIBILITY_ITEMS[scope] as Record<string, string>)[id];
8
8
  return rule ? ['always', rule] : ['always'];
9
9
  }
10
10
 
11
- export function itemFields(fields: EditorField[], scope: Scope, id: string): EditorField[] {
11
+ /** Existing rendering rules remain compatible; editors expose only effective overrides. */
12
+ export function supportedFormats(scope: Scope, id: string, capability?: ItemCapability): string[] {
13
+ if (capability) return capability.formats;
14
+ if (id === 'text' || id === 'spacer') return [];
15
+ const fields = ['labels', 'icons'];
16
+ if (['model', 'model-with-effort'].includes(id)) fields.push('model_name');
17
+ const numbers = scope === 'main'
18
+ ? ['context-window-size', 'context-tokens', 'tokens', 'input-tokens', 'output-tokens', 'cost', 'prompt-cache', 'session-cost', 'lines-changed', 'cache-misses', 'api-requests', 'spend-amount', 'active-agents', 'prompt-input-tokens', 'prompt-output-tokens', 'prompt-cost']
19
+ : ['context-window-size', 'context-tokens', 'tokens'];
20
+ if (numbers.includes(id)) fields.push('number_format');
21
+ if (scope === 'main' && ['five-hour-limit', 'weekly-limit', 'spend-limit'].includes(id)) fields.push('allowance');
22
+ if (scope === 'main' && ['five-hour-reset', 'weekly-reset'].includes(id)) fields.push('reset_format', 'reset_timezone');
23
+ return fields;
24
+ }
25
+
26
+ export function itemFields(fields: EditorField[], scope: Scope, id: string, capability?: ItemCapability): EditorField[] {
12
27
  if(id==='spacer')return [];
13
28
  if(id==='text')return [{key:'text',label:'Literal text',group:'Item format',kind:'text',choices:[],minimum:0,maximum:256,nullable:false},
14
29
  ...fields.filter(f=>['label','icon','foreground','background','priority','max_width'].includes(f.key))];
15
- const choices = visibilityChoices(scope, id);
16
- return fields.filter(spec => (spec.key !== 'visibility' || choices.length > 1) &&
30
+ const choices = capability?.visibility ?? visibilityChoices(scope, id);
31
+ const links: EditorField[] = capability?.link ? [{key:'link',label:'Links',group:'Item format',kind:'choice',choices:['off','auto','on'],minimum:0,maximum:0,nullable:false}] : [];
32
+ const formats = supportedFormats(scope, id, capability);
33
+ fields = fields.filter(field => !Object.hasOwn(FORMAT_CHOICES,field.key) || formats.includes(field.key));
34
+ return [...links, ...fields.filter(spec => (spec.key !== 'visibility' || choices.length > 1) &&
17
35
  (spec.key !== 'visibility_threshold' || choices.includes('used-at-least')))
18
- .map(spec => spec.key === 'visibility' ? {...spec, choices} : spec);
36
+ .map(spec => spec.key === 'visibility' ? {...spec, choices} : spec)];
19
37
  }
20
38
 
21
39
  export function validColor(value: unknown): boolean {
@@ -1,5 +1,6 @@
1
1
  // Generated by tools/generation/resources.ts; do not edit.
2
2
  import type { ExplanationView } from './explanation.ts';
3
+ import type { SourceManager } from './source-manager.ts';
3
4
  import type { ProfileManager } from './profile-manager.ts';
4
5
  import type { QuickSetup } from './quick-setup.ts';
5
6
  import { t, type Language } from '../i18n/index.ts';
@@ -45,6 +46,7 @@ export class Editor {
45
46
  quick: QuickSetup | null = null;
46
47
  explanation: ExplanationView | null = null;
47
48
  profiles: ProfileManager | null = null;
49
+ sources: SourceManager | null = null;
48
50
  preset = 'minimal';
49
51
  path = 'statusline.json';
50
52
  pendingTransfer: 'import' | 'export' | 'preset' | null = null;
@@ -63,7 +63,7 @@ export function formRows(view: FormView): FormRow[] {
63
63
  if (e.detail) {
64
64
  const node = e.instance(e.detail.scope, e.detail.id)!;
65
65
  const options = node.options;
66
- return itemFields(e.description.editor_fields.item!, e.detail.scope, node.type_id).map((spec) => row(spec, 'item:' + spec.key, spec.key === 'text' ? node.text : spec.key in e.description.formatting_options ? options.formatting[spec.key] ?? 'inherit' :
66
+ 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' :
67
67
  options[spec.key as keyof typeof options] ?? ITEM_DEFAULTS[spec.key as keyof typeof ITEM_DEFAULTS]))
68
68
  .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));
69
69
  }
@@ -0,0 +1,301 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ import type { Operation, ResultFor, SourcesResult, SourceDefinition, SourceContext, SourceJob, SourceReview, Scope } from '../generated-contracts.ts';
3
+ import type { Editor } from './draft.ts';
4
+ import { t, text, type Language, type LocalizedText } from '../i18n/index.ts';
5
+ import { inputKey, inputView, textInput, type TextInput, type TextKey } from './text-input.ts';
6
+ import { wrapText } from '../../ui/text.ts';
7
+ import { BackendError } from '../backend.ts';
8
+ type Action = 'edit' | 'review' | 'disable' | 'remove' | 'bind' | 'unbind' | 'refresh' | 'status' | 'cancel' | 'diagnose';
9
+ export interface SourceManager {
10
+ library: SourcesResult | null;
11
+ context: SourceContext | null;
12
+ owner: string;
13
+ page: 'list' | 'actions' | 'kind' | 'form' | 'review' | 'remove' | 'bind' | 'unbind' | 'diagnose';
14
+ cursor: number;
15
+ scroll: number;
16
+ selected: string | null;
17
+ kind: SourceDefinition['kind'];
18
+ editing: boolean;
19
+ fields: {
20
+ key: string;
21
+ input: TextInput;
22
+ }[];
23
+ review: SourceReview | null;
24
+ details: string[];
25
+ jobs: SourceJob[];
26
+ message: LocalizedText | null;
27
+ effect: 'load' | 'save' | 'review' | 'enable' | 'disable' | 'remove' | 'bind' | 'refresh' | 'status' | 'cancel' | 'diagnose' | 'close' | null;
28
+ target: {
29
+ scope: Scope;
30
+ id: string;
31
+ } | null;
32
+ }
33
+ export interface SourceBackend {
34
+ request<O extends Operation>(operation: O, payload?: unknown): ResultFor<O> | Promise<ResultFor<O>>;
35
+ }
36
+ const external = ['external-value', 'github-pr', 'github-ci'];
37
+ export function openSources(editor: Editor): void {
38
+ editor.sources = { library: null, context: null, owner: 'editor-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2), page: 'list', cursor: 0, scroll: 0, selected: null, kind: 'json', editing: false, fields: [], review: null, details: [], jobs: [], message: null, effect: 'load', target: null };
39
+ }
40
+ function source(editor: Editor): SourceDefinition | undefined { return editor.sources!.library?.sources.find(s => s.id === editor.sources!.selected); }
41
+ function actions(editor: Editor): Action[] { return ['edit', 'review', ...(source(editor)?.enabled ? ['disable' as const] : []), 'bind', 'refresh', 'status', 'cancel', 'diagnose', 'remove', 'unbind']; }
42
+ function targets(editor: Editor) {
43
+ const s = source(editor);
44
+ return (['main', 'subagent'] as const).flatMap(scope => (scope === 'main' ? editor.draft.display.instances : editor.draft.display.subagents.instances)
45
+ .filter(node => external.includes(node.type_id) && (s?.kind === 'github' || !node.type_id.startsWith('github-')) && (editor.sources!.page !== 'unbind' || editor.sources!.library?.bindings.some(binding => binding.source_id === s?.id && binding.id === node.source?.binding))).map(node => ({ scope, id: node.id })));
46
+ }
47
+ function form(editor: Editor, kind: SourceDefinition['kind'], editing = false): void {
48
+ const m = editor.sources!, s = editing ? source(editor) : undefined, settings = s?.settings ?? {};
49
+ const common: Record<string, unknown> = { id: s?.id ?? '', name: s?.name ?? '', project: s ? s.scope.project ?? '' : m.context?.project ?? '', session: s?.scope.session ?? '', agent: s?.scope.agent ?? '', ttl_seconds: s?.ttl_seconds ?? 300 };
50
+ const extra = kind === 'json' ? { path: settings.path ?? '', pointer: settings.pointer ?? '/value', observed_at_pointer: settings.observed_at_pointer ?? '/observed_at', unit: settings.unit ?? '' }
51
+ : kind === 'github' ? { host: settings.host ?? 'github.com', repository: settings.repository ?? '', branch: settings.branch ?? m.context?.branch ?? '', account: settings.account ?? '', pr: settings.pr ?? '' }
52
+ : { executable: settings.executable ?? '', args: JSON.stringify(settings.args ?? []), cwd: settings.cwd ?? m.context?.project ?? '', input: JSON.stringify(settings.input ?? {}), output: settings.output ?? 'json', timeout_ms: settings.timeout_ms ?? 5000 };
53
+ m.kind = kind;
54
+ m.editing = editing;
55
+ m.page = 'form';
56
+ m.cursor = 0;
57
+ m.scroll = 0;
58
+ m.message = null;
59
+ m.fields = Object.entries({ ...common, ...extra }).map(([key, value]) => ({ key, input: textInput(String(value)) }));
60
+ }
61
+ function count(editor: Editor): number {
62
+ const m = editor.sources!;
63
+ return m.page === 'list' ? (m.library?.sources.length ?? 0) + 1 : m.page === 'actions' ? actions(editor).length : m.page === 'kind' ? 3 : m.page === 'form' ? m.fields.length : m.page === 'bind' || m.page === 'unbind' ? targets(editor).length : 1;
64
+ }
65
+ export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
66
+ const m = editor.sources;
67
+ if (!m)
68
+ return null;
69
+ const key = event.key === 'return' ? 'enter' : event.key, plain = !event.text && !event.paste && !event.ctrl && !event.meta;
70
+ if (!event.text && !event.paste && (key === 'escape' || event.ctrl && key.toLowerCase() === 'g')) {
71
+ if (m.page === 'list')
72
+ m.effect = 'close';
73
+ else {
74
+ m.page = 'list';
75
+ m.cursor = 0;
76
+ m.scroll = 0;
77
+ m.message = null;
78
+ }
79
+ return m.effect ? 'sources' : null;
80
+ }
81
+ if (m.page === 'form') {
82
+ if (!event.text && (key === 'tab' || plain && ['up', 'down'].includes(key)))
83
+ m.cursor = Math.max(0, Math.min(m.fields.length - 1, m.cursor + (key === 'up' ? -1 : 1)));
84
+ else if (!event.text && (key === 'enter' || event.ctrl && key.toLowerCase() === 's')) {
85
+ if (key === 'enter' && m.cursor < m.fields.length - 1)
86
+ m.cursor++;
87
+ else
88
+ m.effect = 'save';
89
+ }
90
+ else {
91
+ const field = m.fields[m.cursor]!;
92
+ if (!(m.editing && field.key === 'id')) {
93
+ const changed = inputKey(field.input.value, field.input, event, 8192);
94
+ field.input = changed.state;
95
+ m.message = changed.error ? text('input.' + changed.error, { limit: 8192 }) : null;
96
+ }
97
+ }
98
+ return m.effect ? 'sources' : null;
99
+ }
100
+ if (!plain)
101
+ return null;
102
+ if (['review', 'diagnose'].includes(m.page) && ['up', 'down', 'pageup', 'pagedown', 'home'].includes(key)) {
103
+ m.scroll = key === 'home' ? 0 : Math.max(0, m.scroll + (key === 'up' ? -1 : key === 'pageup' ? -8 : key === 'pagedown' ? 8 : 1));
104
+ return null;
105
+ }
106
+ if (key === 'up' || key === 'down')
107
+ m.cursor = Math.max(0, Math.min(count(editor) - 1, m.cursor + (key === 'up' ? -1 : 1)));
108
+ if (key === 'r' && m.page === 'list')
109
+ m.effect = 'load';
110
+ if (key === 'enter') {
111
+ if (m.page === 'list') {
112
+ const selected = m.library?.sources[m.cursor];
113
+ if (selected) {
114
+ m.selected = selected.id;
115
+ m.page = 'actions';
116
+ }
117
+ else
118
+ m.page = 'kind';
119
+ m.cursor = 0;
120
+ }
121
+ else if (m.page === 'kind')
122
+ form(editor, (['json', 'github', 'command'] as const)[m.cursor]!);
123
+ else if (m.page === 'actions') {
124
+ const action = actions(editor)[m.cursor]!;
125
+ if (action === 'edit')
126
+ form(editor, source(editor)!.kind, true);
127
+ else if (action === 'bind' || action === 'unbind' || action === 'remove') {
128
+ m.page = action;
129
+ m.cursor = 0;
130
+ }
131
+ else
132
+ m.effect = action;
133
+ }
134
+ else if (m.page === 'review')
135
+ m.effect = 'enable';
136
+ else if (m.page === 'remove')
137
+ m.effect = 'remove';
138
+ else if (m.page === 'unbind') {
139
+ const target = targets(editor)[m.cursor];
140
+ const node = target && editor.instance(target.scope, target.id);
141
+ if (node?.source) {
142
+ node.source = { ...node.source, binding: null };
143
+ m.message = text('sources.bound');
144
+ m.page = 'list';
145
+ m.cursor = 0;
146
+ }
147
+ }
148
+ else if (m.page === 'bind') {
149
+ m.target = targets(editor)[m.cursor] ?? null;
150
+ if (m.target)
151
+ m.effect = 'bind';
152
+ }
153
+ }
154
+ return m.effect ? 'sources' : null;
155
+ }
156
+ export async function closeSources(editor: Editor, backend: SourceBackend): Promise<void> {
157
+ const m = editor.sources;
158
+ if (!m)
159
+ return;
160
+ let failed: unknown;
161
+ for (const job of m.jobs.filter(job => job.state === 'running')) {
162
+ try { await backend.request('source_cancel', { id: job.id }); }
163
+ catch (error) { failed = error; }
164
+ }
165
+ if (failed) throw failed;
166
+ if (editor.sources === m)
167
+ editor.sources = null;
168
+ }
169
+ export async function performSourceAction(editor: Editor, backend: SourceBackend): Promise<void> {
170
+ const m = editor.sources, effect = m?.effect;
171
+ if (!m || !effect)
172
+ return;
173
+ m.effect = null;
174
+ m.message = null;
175
+ try {
176
+ if (effect === 'close') {
177
+ await closeSources(editor, backend);
178
+ return;
179
+ }
180
+ if (effect === 'load') {
181
+ m.library = await backend.request('sources_read', {});
182
+ const target = editor.baseline.configuration;
183
+ m.context = await backend.request('source_context', { project: target?.project_root ?? (target?.target.kind === 'project' ? target.target.path : null), session: null, agent: null });
184
+ return;
185
+ }
186
+ if (effect === 'review') {
187
+ m.review = await backend.request('source_review', { id: m.selected });
188
+ m.page = 'review';
189
+ m.scroll = 0;
190
+ return;
191
+ }
192
+ if (effect === 'status' || effect === 'cancel') {
193
+ const selected = source(editor)!;
194
+ const context = await backend.request('source_context', { project: selected.scope.project ?? m.context?.project ?? null, session: selected.scope.session, agent: selected.scope.agent });
195
+ const observed = await backend.request('source_diagnose', { id: m.selected, context });
196
+ const jobs = await Promise.all(observed.jobs.map(job => backend.request(effect === 'cancel' && job.state === 'running' ? 'source_cancel' : 'source_status', { id: job.id })));
197
+ m.jobs = m.jobs.map(job => jobs.find(updated => updated.id === job.id) ?? job);
198
+ m.details = jobs.map(job => `${job.id}: ${job.state} (${job.reason})`);
199
+ m.page = 'diagnose';
200
+ m.scroll = 0;
201
+ return;
202
+ }
203
+ if (effect === 'refresh' || effect === 'diagnose') {
204
+ const selected = source(editor)!;
205
+ const context = await backend.request('source_context', { project: selected.scope.project ?? m.context?.project ?? null, session: selected.scope.session, agent: selected.scope.agent });
206
+ if (effect === 'refresh') {
207
+ const job = await backend.request('source_refresh', { id: m.selected, context, owner: m.owner });
208
+ m.jobs.push(job);
209
+ m.message = text('sources.refresh_started');
210
+ }
211
+ else {
212
+ const result = await backend.request('source_diagnose', { id: m.selected, context });
213
+ m.details = JSON.stringify(result, null, 2).split('\n');
214
+ m.page = 'diagnose';
215
+ m.scroll = 0;
216
+ }
217
+ return;
218
+ }
219
+ const payload: Record<string, unknown> = { action: effect, id: m.selected, expected_revision: m.library!.revision };
220
+ if (effect === 'save') {
221
+ const values = Object.fromEntries(m.fields.map(field => [field.key, field.input.value]));
222
+ const { id, name, project, session, agent, ttl_seconds, ...settings } = values;
223
+ const parsed: Record<string, unknown> = { ...settings };
224
+ for (const key of ['args', 'input'])
225
+ if (key in parsed)
226
+ parsed[key] = JSON.parse(String(parsed[key]));
227
+ if ('timeout_ms' in parsed)
228
+ parsed.timeout_ms = Number(parsed.timeout_ms);
229
+ if ('pr' in parsed)
230
+ parsed.pr = parsed.pr === '' ? null : Number(parsed.pr);
231
+ Object.assign(payload, { action: m.editing ? 'edit' : 'add', id, source: { name: name || id, kind: m.kind, scope: { project: project || null, session: session || null, agent: agent || null }, ttl_seconds: Number(ttl_seconds), settings: parsed } });
232
+ }
233
+ if (effect === 'enable')
234
+ payload.review_revision = m.review?.review_revision;
235
+ const result = await backend.request('sources_apply', payload);
236
+ m.library = result;
237
+ if (effect === 'bind' && m.target && result.binding) {
238
+ const node = editor.instance(m.target.scope, m.target.id);
239
+ if (node)
240
+ node.source = result.binding;
241
+ m.message = text('sources.bound');
242
+ }
243
+ else
244
+ m.message = text('sources.saved');
245
+ m.page = 'list';
246
+ m.cursor = 0;
247
+ m.scroll = 0;
248
+ }
249
+ catch (error) {
250
+ m.message = error instanceof BackendError ? error.localization ?? text('sources.failed') : text('sources.failed');
251
+ }
252
+ }
253
+ export function sourcesView(editor: Editor, language: Language, width: number, height: number): {
254
+ text: string;
255
+ selected: boolean;
256
+ }[] {
257
+ const m = editor.sources!;
258
+ const tr = (key: string) => t('sources.' + key, language), rows: {
259
+ text: string;
260
+ selected: boolean;
261
+ }[] = [];
262
+ const add = (value: string, selected = false) => rows.push({ text: value, selected });
263
+ add(tr('separate_save'));
264
+ if (m.message)
265
+ add(t(m.message.key, language, m.message.params));
266
+ if (m.page === 'list') {
267
+ m.library?.sources.forEach((s, i) => add(`${s.name} · ${s.kind} · ${tr(s.enabled ? 'enabled' : 'disabled')}`, m.cursor === i));
268
+ add('+ ' + tr('add'), m.cursor === (m.library?.sources.length ?? 0));
269
+ }
270
+ else if (m.page === 'actions')
271
+ actions(editor).forEach((action, i) => add(tr(action), m.cursor === i));
272
+ else if (m.page === 'kind')
273
+ ['json', 'github', 'command'].forEach((kind, i) => add(tr(kind), m.cursor === i));
274
+ else if (m.page === 'form') {
275
+ m.fields.forEach((field, i) => {
276
+ const label = tr('field.' + field.key) + ': ', space = Math.max(2, width - label.length);
277
+ const view = inputView({ ...field.input }, space);
278
+ add(label + view, m.cursor === i);
279
+ });
280
+ add(tr('form_help'));
281
+ }
282
+ else if (m.page === 'bind' || m.page === 'unbind') {
283
+ const entries = targets(editor);
284
+ if (!entries.length)
285
+ add(tr('no_components'));
286
+ entries.forEach((target, i) => add(`${target.scope}: ${editor.instanceLabel(target.scope, target.id, language)}`, m.cursor === i));
287
+ }
288
+ else if (m.page === 'remove')
289
+ add(tr('remove_confirm') + ' ' + source(editor)?.name, true);
290
+ else {
291
+ const lines = m.page === 'review' ? [tr('enable_review'), ...JSON.stringify(m.review?.source, null, 2).split('\n')] : m.details;
292
+ const wrapped = lines.flatMap(line => wrapText([line], width));
293
+ const capacity = Math.max(1, height - rows.length);
294
+ const start = Math.min(m.scroll, Math.max(0, wrapped.length - capacity));
295
+ wrapped.slice(start, start + capacity).forEach(line => add(line));
296
+ return rows;
297
+ }
298
+ const fixed = rows.slice(0, 1 + Number(!!m.message)), entries = rows.slice(fixed.length), capacity = Math.max(1, height - fixed.length);
299
+ const selected = Math.max(0, entries.findIndex(row => row.selected)), start = Math.max(0, selected - capacity + 1);
300
+ return [...fixed, ...entries.slice(start, start + capacity)];
301
+ }
@@ -0,0 +1,45 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ /** Strict response validation shared by the native and external source managers. */
3
+ const object = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v);
4
+ const text = (v: unknown): v is string => typeof v === 'string' && v.length <= 16384 && !/[\p{Cc}\p{Cs}]/u.test(v);
5
+ const nullable = (v: unknown) => v === null || text(v);
6
+ const scalar = (v: unknown) => v === null || text(v) || typeof v === 'boolean' || typeof v === 'number' && Number.isFinite(v);
7
+ const fields = (v: unknown, keys: string[]): v is Record<string, unknown> => object(v) && Object.keys(v).length === keys.length && keys.every(key => Object.hasOwn(v, key));
8
+ const id = (v: unknown) => text(v) && /^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/u.test(v);
9
+ const scope = (v: unknown) => fields(v, ['project', 'session', 'agent']) && Object.values(v).every(nullable) && (v.agent === null || v.session !== null);
10
+ export const isSourceContext = (v: unknown) => fields(v, ['project', 'session', 'agent', 'branch', 'head']) && Object.values(v).every(nullable);
11
+ function definition(v: unknown): boolean {
12
+ if (!fields(v, ['id', 'name', 'kind', 'scope', 'ttl_seconds', 'settings', 'enabled', 'revision']) || !id(v.id) || !text(v.name) || !['json', 'github', 'command'].includes(String(v.kind)) || !scope(v.scope) || !id(v.revision) || typeof v.enabled !== 'boolean' || typeof v.ttl_seconds !== 'number' || !Number.isInteger(v.ttl_seconds) || v.ttl_seconds < 1 || v.ttl_seconds > 86400 || !object(v.settings))
13
+ return false;
14
+ const s = v.settings;
15
+ if (v.kind === 'json')
16
+ return fields(s, ['path', 'pointer', 'observed_at_pointer', 'unit']) && Object.values(s).every(text);
17
+ if (v.kind === 'github')
18
+ return fields(s, ['host', 'repository', 'branch', 'account', 'pr']) && ['host', 'repository', 'branch', 'account'].every(key => text(s[key])) && (s.pr === null || typeof s.pr === 'number' && Number.isSafeInteger(s.pr) && s.pr > 0);
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
+ }
21
+ function job(v: unknown): boolean {
22
+ return fields(v, ['version', 'id', 'source_id', 'source_revision', 'owner', 'context', 'started_at', 'deadline_at', 'state', 'reason']) && v.version === 1 && ['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
+ }
24
+ function view(v: unknown): boolean {
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));
26
+ }
27
+ export function isSourceResult(operation: string, value: unknown): boolean {
28
+ if (!object(value))
29
+ return false;
30
+ if (operation === 'source_context')
31
+ return isSourceContext(value);
32
+ if (operation === 'source_review')
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))
35
+ return job(value);
36
+ if (operation === 'source_diagnose')
37
+ return fields(value, ['source', 'view', 'jobs']) && definition(value.source) && view(value.view) && Array.isArray(value.jobs) && value.jobs.every(job);
38
+ if (!['sources_read', 'sources_apply'].includes(operation) || !fields(value, ['version', 'sources', 'bindings', 'revision', ...(operation === 'sources_apply' ? ['backup_dir', ...(Object.hasOwn(value, 'binding') ? ['binding'] : [])] : [])]))
39
+ return false;
40
+ if (value.version !== 1 || !text(value.revision) || !Array.isArray(value.sources) || value.sources.length > 128 || !value.sources.every(definition) || !Array.isArray(value.bindings) || value.bindings.length > 4096)
41
+ return false;
42
+ if (!value.bindings.every(b => fields(b, ['id', 'source_id']) && id(b.id) && id(b.source_id)))
43
+ return false;
44
+ return operation === 'sources_read' || nullable(value.backup_dir) && (value.binding === undefined || fields(value.binding, ['binding', 'hint']) && id(value.binding.binding) && text(value.binding.hint));
45
+ }