@fbincon/claude-code-statusline 3.11.0 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +82 -79
  2. package/candidate.json +356 -254
  3. package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.d.ts +1 -0
  4. package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.js +9 -0
  5. package/node_modules/@fbincon/statusline-cli/dist/src/config/arguments.js.map +1 -1
  6. package/node_modules/@fbincon/statusline-cli/dist/src/config/commands.js +23 -0
  7. package/node_modules/@fbincon/statusline-cli/dist/src/config/commands.js.map +1 -1
  8. package/node_modules/@fbincon/statusline-cli/dist/src/config/profile-command.js +7 -3
  9. package/node_modules/@fbincon/statusline-cli/dist/src/config/profile-command.js.map +1 -1
  10. package/node_modules/@fbincon/statusline-cli/dist/src/config/reuse.d.ts +3 -0
  11. package/node_modules/@fbincon/statusline-cli/dist/src/config/reuse.js +62 -0
  12. package/node_modules/@fbincon/statusline-cli/dist/src/config/reuse.js.map +1 -0
  13. package/node_modules/@fbincon/statusline-cli/dist/src/config/structural-review.d.ts +5 -0
  14. package/node_modules/@fbincon/statusline-cli/dist/src/config/structural-review.js +45 -0
  15. package/node_modules/@fbincon/statusline-cli/dist/src/config/structural-review.js.map +1 -0
  16. package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js +5 -1
  17. package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js.map +1 -1
  18. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.d.ts +1 -0
  19. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.js +41 -0
  20. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.js.map +1 -0
  21. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.d.ts +1 -0
  22. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.js +14 -0
  23. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.js.map +1 -0
  24. package/node_modules/@fbincon/statusline-cli/dist/src/main.js +9 -0
  25. package/node_modules/@fbincon/statusline-cli/dist/src/main.js.map +1 -1
  26. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.d.ts +1 -0
  27. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.js +4 -0
  28. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.js.map +1 -0
  29. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.d.ts +29 -0
  30. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.js +228 -0
  31. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.js.map +1 -0
  32. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.d.ts +4 -0
  33. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.js +150 -0
  34. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.js.map +1 -0
  35. package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.js +30 -13
  36. package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.js.map +1 -1
  37. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js +2 -2
  38. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js.map +1 -1
  39. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.d.ts +1 -0
  40. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.js +11 -6
  41. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.js.map +1 -1
  42. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.d.ts +2 -0
  43. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js +9 -5
  44. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js.map +1 -1
  45. package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js +6 -6
  46. package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js.map +1 -1
  47. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.d.ts +1 -0
  48. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js +6 -6
  49. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js.map +1 -1
  50. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic.js +76 -28
  51. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic.js.map +1 -1
  52. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.d.ts +17 -0
  53. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.js +176 -0
  54. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.js.map +1 -0
  55. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js +11 -3
  56. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js.map +1 -1
  57. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js +26 -8
  58. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js.map +1 -1
  59. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.d.ts +3 -0
  60. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js +54 -14
  61. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js.map +1 -1
  62. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +3 -3
  63. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +50 -0
  64. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js.map +1 -1
  65. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/.claude-plugin/plugin.json +1 -1
  66. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/hooks/register.ts +30 -18
  67. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/backend.ts +4 -0
  68. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +14 -3
  69. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/settings.ts +8 -5
  70. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/alignment-manager.ts +2 -2
  71. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/change-review.ts +109 -0
  72. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/color-manager.ts +1 -1
  73. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +74 -21
  74. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/forms.ts +2 -9
  75. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/group-manager.ts +2 -3
  76. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/groups.ts +2 -2
  77. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/history.ts +33 -0
  78. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/package-manager.ts +164 -291
  79. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/package-validation.ts +10 -1
  80. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/reuse-manager.ts +150 -0
  81. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/reuse.ts +96 -0
  82. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-compatibility.ts +7 -0
  83. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-manager.ts +64 -45
  84. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-summary.ts +22 -0
  85. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-validation.ts +11 -2
  86. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/structure.ts +30 -0
  87. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +49 -6
  88. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +7 -12722
  89. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/en.ts +2291 -0
  90. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/ja.ts +2291 -0
  91. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/ko.ts +2291 -0
  92. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-CN.ts +2291 -0
  93. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-HK.ts +2291 -0
  94. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-TW.ts +2291 -0
  95. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +35 -22
  96. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +4 -1
  97. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/help.ts +3 -2
  98. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/.claude-plugin/plugin.json +1 -1
  99. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/hooks/observe.ts +10 -3
  100. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/resource-manifest.json +4 -4
  101. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +127 -6
  102. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js +2 -2
  103. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js.map +1 -1
  104. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js +2 -2
  105. package/node_modules/@fbincon/statusline-core/dist/src/editor/alignment-manager.js.map +1 -1
  106. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js +6 -0
  107. package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js.map +1 -1
  108. package/node_modules/@fbincon/statusline-core/dist/src/editor/change-review.d.ts +32 -0
  109. package/node_modules/@fbincon/statusline-core/dist/src/editor/change-review.js +155 -0
  110. package/node_modules/@fbincon/statusline-core/dist/src/editor/change-review.js.map +1 -0
  111. package/node_modules/@fbincon/statusline-core/dist/src/editor/color-manager.js +1 -1
  112. package/node_modules/@fbincon/statusline-core/dist/src/editor/color-manager.js.map +1 -1
  113. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.d.ts +20 -3
  114. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +121 -23
  115. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
  116. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js +2 -10
  117. package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js.map +1 -1
  118. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js +2 -5
  119. package/node_modules/@fbincon/statusline-core/dist/src/editor/group-manager.js.map +1 -1
  120. package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.d.ts +1 -1
  121. package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.js +2 -2
  122. package/node_modules/@fbincon/statusline-core/dist/src/editor/groups.js.map +1 -1
  123. package/node_modules/@fbincon/statusline-core/dist/src/editor/history.d.ts +22 -0
  124. package/node_modules/@fbincon/statusline-core/dist/src/editor/history.js +37 -0
  125. package/node_modules/@fbincon/statusline-core/dist/src/editor/history.js.map +1 -0
  126. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.d.ts +12 -4
  127. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.js +302 -85
  128. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.js.map +1 -1
  129. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.js +12 -1
  130. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.js.map +1 -1
  131. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse-manager.d.ts +39 -0
  132. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse-manager.js +271 -0
  133. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse-manager.js.map +1 -0
  134. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse.d.ts +6 -0
  135. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse.js +135 -0
  136. package/node_modules/@fbincon/statusline-core/dist/src/editor/reuse.js.map +1 -0
  137. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-compatibility.d.ts +3 -0
  138. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-compatibility.js +7 -0
  139. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-compatibility.js.map +1 -0
  140. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.d.ts +9 -3
  141. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js +85 -30
  142. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js.map +1 -1
  143. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.d.ts +5 -0
  144. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.js +25 -0
  145. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.js.map +1 -0
  146. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.d.ts +1 -0
  147. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js +13 -2
  148. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js.map +1 -1
  149. package/node_modules/@fbincon/statusline-core/dist/src/editor/structure.d.ts +16 -0
  150. package/node_modules/@fbincon/statusline-core/dist/src/editor/structure.js +28 -0
  151. package/node_modules/@fbincon/statusline-core/dist/src/editor/structure.js.map +1 -0
  152. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.d.ts +2 -0
  153. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js +15 -3
  154. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js.map +1 -1
  155. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +1032 -12
  156. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +1038 -18
  157. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
  158. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js +1 -0
  159. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js.map +1 -1
  160. package/node_modules/@fbincon/statusline-core/dist/src/release.d.ts +1 -1
  161. package/node_modules/@fbincon/statusline-core/dist/src/release.js +1 -1
  162. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +173 -3
  163. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +173 -3
  164. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +173 -3
  165. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +173 -3
  166. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +173 -3
  167. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +173 -3
  168. package/node_modules/@fbincon/statusline-platform/dist/src/native.d.ts +2 -0
  169. package/node_modules/@fbincon/statusline-platform/dist/src/native.js +2 -0
  170. package/node_modules/@fbincon/statusline-platform/dist/src/native.js.map +1 -1
  171. package/node_modules/@fbincon/statusline-platform/dist/src/npm.d.ts +2 -0
  172. package/node_modules/@fbincon/statusline-platform/dist/src/npm.js +20 -1
  173. package/node_modules/@fbincon/statusline-platform/dist/src/npm.js.map +1 -1
  174. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.d.ts +3 -0
  175. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.js +53 -0
  176. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.js.map +1 -0
  177. package/node_modules/@fbincon/statusline-platform/dist/src/processes.d.ts +2 -0
  178. package/node_modules/@fbincon/statusline-platform/dist/src/processes.js +45 -0
  179. package/node_modules/@fbincon/statusline-platform/dist/src/processes.js.map +1 -1
  180. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.d.ts +5 -0
  181. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js +8 -1
  182. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js.map +1 -1
  183. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js +6 -0
  184. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js.map +1 -1
  185. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js +3 -0
  186. package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js.map +1 -1
  187. package/node_modules/@fbincon/statusline-tui/dist/src/session.d.ts +2 -1
  188. package/node_modules/@fbincon/statusline-tui/dist/src/session.js +26 -6
  189. package/node_modules/@fbincon/statusline-tui/dist/src/session.js.map +1 -1
  190. package/node_modules/@fbincon/statusline-tui/dist/src/state.d.ts +1 -1
  191. package/node_modules/@fbincon/statusline-tui/dist/src/state.js +39 -9
  192. package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
  193. package/package.json +3 -3
@@ -0,0 +1,150 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ import type { Draft, ProfilesResult, ReuseRequest, ReuseReviewResult, Scope } from '../generated-contracts.ts';
3
+ import type { Editor } from './draft.ts';
4
+ import type { ReviewBackend } from './change-review.ts';
5
+ import { targetIdentity } from './change-review.ts';
6
+ import { clip } from '../unicode.ts';
7
+ import { clone } from './history.ts';
8
+ import { STYLE_FIELDS, styleFields, reuseDraft } from './reuse.ts';
9
+ import { createReview, navigateReview, reviewRows, type ReviewState } from './import-review.ts';
10
+ import { newInstance } from './instances.ts';
11
+ import { openSources } from './source-manager.ts';
12
+ import { inputKey, inputView, textInput, type TextInput, type TextKey } from './text-input.ts';
13
+ import { text, t, renderMessage, type Language, type LocalizedText } from '../i18n/index.ts';
14
+
15
+ export interface ReuseManager {
16
+ kind: 'style' | 'groups'; page: 'source' | 'path' | 'profiles' | 'select' | 'fields' | 'review' | 'complete';
17
+ generation: number; target: string; scope: Scope; fromScope: Scope; destination: string; incoming: Draft; local: boolean;
18
+ from: string; groups: string[]; fields: string[]; references: 'review' | 'expand' | 'exclude'; explicit: boolean;
19
+ cursor: number; scroll: number; details: boolean; input: TextInput; profileFile: boolean; library: ProfilesResult | null;
20
+ result: ReuseReviewResult | null; review: ReviewState | null; message: LocalizedText | null; effect: 'file' | 'profiles' | null;
21
+ }
22
+ export function openReuse(e: Editor, kind: ReuseManager['kind']): void {
23
+ const scope = e.detail?.scope ?? (e.page === 'subagents' ? 'subagent' : 'main');
24
+ e.reuse = { kind, page: 'source', generation: e.mutationGeneration, target: targetIdentity(e.baseline), scope, fromScope: scope, destination: e.detail?.id ?? e.selected[scope],
25
+ incoming: clone(e.draft), local: true, from: '', groups: [], fields: [], references: 'review', explicit: false, cursor: 0, scroll: 0, details: false,
26
+ input: textInput('statusline.json'), profileFile: false, library: null, result: null, review: null, message: null, effect: null };
27
+ }
28
+ function source(e: Editor) { const m=e.reuse!; return m.fromScope === 'main' ? m.incoming.display : m.incoming.display.subagents; }
29
+ function request(m: ReuseManager): ReuseRequest {
30
+ return m.kind === 'style' ? { kind:'style',scope:m.scope,from_scope:m.fromScope,from_id:m.from,to_ids:[m.destination],fields:[...m.fields] }
31
+ : {kind:'groups',scope:m.scope,group_ids:[...m.groups],references:m.references,explicit:m.explicit};
32
+ }
33
+ function refresh(e: Editor): void {
34
+ const m=e.reuse!;
35
+ try {
36
+ m.result = reuseDraft(e.draft,m.incoming,request(m),()=>newInstance('text',[]).id,e.description.catalog,m.local);
37
+ m.review = createReview(m.result); m.details = m.result.blocked.length > 0; m.scroll=0; m.message = m.result.blocked.length ? text(m.result.blocked[0]!) : null;
38
+ } catch (error) { m.result=null;m.review=null;m.message=text(error instanceof Error && error.message==='reuse.incompatible'?'reuse.incompatible':'reuse.invalid'); }
39
+ }
40
+ function reviewCapacity(m: ReuseManager,height:number):number {
41
+ const headers=1+Number(height>=4)+Number(m.kind==='style'&&height>=5)+Number(m.kind==='groups'&&height>=6)+Number(m.kind==='groups'&&height>=7);
42
+ return Math.max(1,height-headers-1);
43
+ }
44
+ function rows(e: Editor, language: Language): string[] {
45
+ const m=e.reuse!,tr=(key:string)=>t('reuse.'+key,language);
46
+ if(m.page==='source')return ['current','portable','profile_file','profiles'].map(tr);
47
+ if(m.page==='profiles')return m.library?.profiles.map(p=>p.name)??[];
48
+ if(m.page==='complete')return [tr('accepted'),...(m.result?.unresolved.map(u=>`${u.id} · ${u.hint} · ${tr('unbound')}`)??[]),tr('bind_help')];
49
+ if(m.page==='select'){
50
+ const values=m.kind==='style'?source(e).instances.filter(n=>n.type_id!=='spacer').map(n=>`${n.id} · ${n.options.label??t('items.'+m.fromScope+'.'+n.type_id+'.label',language)}`)
51
+ :source(e).groups.map(g=>`[${m.groups.includes(g.id)?'x':' '}] ${g.id} · ${g.member_ids.join(', ')}`);
52
+ return [tr('scope')+': '+m.fromScope,...values,...(m.kind==='groups'?[tr('review')]:[])];
53
+ }
54
+ if(m.page==='fields'){
55
+ const origin=source(e).instances.find(n=>n.id===m.from),destination=e.instance(m.scope,m.destination);
56
+ const available=origin&&destination?styleFields(origin,m.fromScope,e.description.catalog).filter(f=>styleFields(destination,m.scope,e.description.catalog).includes(f)):[];
57
+ return [...STYLE_FIELDS.map(f=>`[${m.fields.includes(f)?'x':' '}] ${t('reuse.field.'+f,language)}${available.includes(f)?'':' · '+tr('unsupported')}`),tr('review')];
58
+ }
59
+ return [];
60
+ }
61
+ export function reuseKey(e: Editor,event:TextKey,language:Language,width:number,height:number):'reuse'|'sources'|null {
62
+ const m=e.reuse!,key=event.key==='enter'?'return':event.key;
63
+ if(event.overflow)return null;
64
+ if(!event.text&&!event.paste&&(key==='escape'||event.ctrl&&key.toLowerCase()==='g')){e.reuse=null;return null;}
65
+ if(m.page==='path'){
66
+ if(key==='return'&&!event.text&&!event.paste){m.effect='file';return 'reuse';}
67
+ m.input=inputKey(m.input.value,m.input,event,4096).state;return null;
68
+ }
69
+ if(event.text||event.paste||event.ctrl||event.meta)return null;
70
+ if(key.toLowerCase()==='q'){e.reuse=null;return null;}
71
+ if(m.page==='complete'){if(key.toLowerCase()==='b'){e.reuse=null;openSources(e);return 'sources';}const total=rows(e,language).length;if(['up','down','pageup','pagedown','home','end'].includes(key))m.cursor=Math.max(0,Math.min(total-1,key==='home'?0:key==='end'?total-1:m.cursor+(key==='up'?-1:key==='down'?1:key==='pageup'?-Math.max(1,height-3):Math.max(1,height-3))));return null;}
72
+ if(m.generation!==e.mutationGeneration||m.target!==targetIdentity(e.baseline)||!e.canMutateDraft()){m.message=text('history.stale');return null;}
73
+ if(m.page==='review'){
74
+ if(key==='tab'&&m.kind==='groups'){m.details=!m.details;m.scroll=0;return null;}
75
+ if(m.details&&['up','down','pageup','pagedown','home','end'].includes(key)) {const capacity=reviewCapacity(m,height),maximum=Math.max(0,detailRows(m,language).length-capacity);m.scroll=Math.max(0,Math.min(maximum,key==='home'?0:key==='end'?maximum:m.scroll+(key==='up'?-1:key==='down'?1:key==='pageup'?-capacity:capacity)));return null;}
76
+ if(key.toLowerCase()==='a'){
77
+ if(m.result&&!m.result.blocked.length&&e.commitDraft(m.result.draft,text('reuse.action'))){m.page='complete';m.cursor=0;m.scroll=0;}
78
+ }else if(key.toLowerCase()==='x'&&m.kind==='groups'){m.references=m.references==='review'?'expand':m.references==='expand'?'exclude':'review';refresh(e);}
79
+ else if(key.toLowerCase()==='l'&&m.kind==='groups'){m.explicit=!m.explicit;refresh(e);}
80
+ else if(key==='backspace'){m.page=m.kind==='style'?'fields':'select';m.cursor=0;}
81
+ else if(m.review)navigateReview(m.review,key,language,width,reviewCapacity(m,height));
82
+ return null;
83
+ }
84
+ const values=rows(e,language),length=values.length;
85
+ if(['up','down','pageup','pagedown','home','end'].includes(key))m.cursor=Math.max(0,Math.min(length-1,key==='home'?0:key==='end'?length-1:m.cursor+(key==='up'?-1:key==='down'?1:key==='pageup'?-Math.max(1,height-3):Math.max(1,height-3))));
86
+ if(!['return',' ','space','left','right'].includes(key))return null;
87
+ if(m.page==='source'){
88
+ if(m.cursor===0){m.page='select';m.cursor=0;}
89
+ else if(m.cursor===3){m.effect='profiles';return 'reuse';}
90
+ else {m.profileFile=m.cursor===2;m.page='path';}
91
+ }else if(m.page==='profiles'){
92
+ const profile=m.library?.profiles[m.cursor];if(profile){m.incoming={display:clone(profile.display),host:clone(e.draft.host)};m.local=false;m.page='select';m.cursor=0;}
93
+ }else if(m.page==='select'){
94
+ if(m.cursor===0){m.fromScope=m.fromScope==='main'?'subagent':'main';if(m.kind==='groups'){m.scope=m.fromScope;m.groups=[];}return null;}
95
+ if(m.kind==='style'){
96
+ const node=source(e).instances.filter(n=>n.type_id!=='spacer')[m.cursor-1];
97
+ if(node){m.from=node.id;const destination=e.instance(m.scope,m.destination);m.fields=destination?STYLE_FIELDS.slice(0,6).filter(f=>styleFields(node,m.fromScope,e.description.catalog).includes(f)&&styleFields(destination,m.scope,e.description.catalog).includes(f)):[];m.page='fields';m.cursor=0;}
98
+ }else{
99
+ const group=source(e).groups[m.cursor-1];
100
+ if(group)m.groups=m.groups.includes(group.id)?m.groups.filter(id=>id!==group.id):[...m.groups,group.id];
101
+ else if(m.groups.length){refresh(e);m.page='review';m.cursor=0;}
102
+ }
103
+ }else if(m.page==='fields'){
104
+ const field=STYLE_FIELDS[m.cursor];
105
+ if(!field){refresh(e);m.page='review';m.cursor=0;}
106
+ else {const origin=source(e).instances.find(n=>n.id===m.from)!,destination=e.instance(m.scope,m.destination);if(destination&&styleFields(origin,m.fromScope,e.description.catalog).includes(field)&&styleFields(destination,m.scope,e.description.catalog).includes(field))m.fields=m.fields.includes(field)?m.fields.filter(f=>f!==field):[...m.fields,field];else m.message=text('reuse.incompatible');}
107
+ }
108
+ return null;
109
+ }
110
+ function detailRows(m:ReuseManager,language:Language):{text:string;heading:boolean;section:string}[]{
111
+ const tr=(key:string)=>t('reuse.'+key,language);
112
+ return [
113
+ ...(m.kind==='groups'?[
114
+ {text:tr(m.references)+' · '+tr('reference_policy'),heading:false,section:''},
115
+ {text:t('values.'+(m.explicit?'on':'off'),language)+': '+tr('layout'),heading:false,section:''}
116
+ ]:[]),
117
+ ...(m.result?.dependencies.map(id=>({text:tr('dependency')+': '+id,heading:false,section:''}))??[]),
118
+ ...Object.entries(m.result?.mappings??{}).flatMap(([kind,map])=>Object.entries(map).map(([a,b])=>({text:kind+': '+a+' → '+b,heading:false,section:''}))),
119
+ ...(m.result?.unresolved.map(u=>({text:tr('unbound')+': '+u.id+' · '+u.hint,heading:false,section:''}))??[])
120
+ ];
121
+ }
122
+ export function reuseView(e:Editor,language:Language,width:number,height:number):{text:string;selected?:boolean}[]{
123
+ const m=e.reuse!,tr=(key:string)=>t('reuse.'+key,language),header=tr(m.kind==='style'?'style':'groups');
124
+ if(m.page==='path')return [{text:header},{text:tr('path')},{text:inputView({...m.input},width)},{text:tr('path_help')}].slice(0,height).map(row=>({...row,text:clip(row.text,width)}));
125
+ if(m.page==='review'){
126
+ const capacity=reviewCapacity(m,height),review=m.review;
127
+ const values=m.details?detailRows(m,language):review?reviewRows(review,language,width):[];
128
+ const offset=m.details?Math.max(0,Math.min(m.scroll,values.length-capacity)):Math.max(0,Math.min(review?.scroll??0,values.length-capacity));
129
+ return [{text:header},...(height>=4?[{text:m.message?renderMessage(m.message,language):tr('draft_only')}]:[]),
130
+ ...(m.kind==='groups'&&height>=6?[{text:tr(m.references)+' · '+tr('reference_policy')}]:[]),
131
+ ...(m.kind==='groups'&&height>=7?[{text:t('values.'+(m.explicit?'on':'off'),language)+': '+tr('layout')}]:[]),
132
+ ...(m.kind==='style'&&height>=5?[{text:tr('scope')+': '+m.fromScope+' · '+m.from+' → '+m.destination}]:[]),
133
+ ...values.slice(offset,offset+capacity).map(r=>({text:r.text,selected:r.heading&&r.section===review?.selected})),{text:tr(m.kind==='groups'?'review_groups_help':'review_style_help')}].slice(0,height).map(row=>({...row,text:clip(row.text,width)}));
134
+ }
135
+ const values=rows(e,language),capacity=Math.max(1,height-3);let start=Math.max(0,Math.min(m.scroll,m.cursor));if(m.cursor>=start+capacity)start=m.cursor-capacity+1;
136
+ return [{text:header},{text:m.message?renderMessage(m.message,language):tr('help')},...values.slice(start,start+capacity).map((value,index)=>({text:(start+index===m.cursor?'› ':' ')+value,selected:start+index===m.cursor})),{text:tr('cancel_help')}].slice(0,height).map(row=>({...row,text:clip(row.text,width)}));
137
+ }
138
+ export async function performReuse(e:Editor,backend:ReviewBackend):Promise<void>{
139
+ const m=e.reuse,effect=m?.effect;if(!m||!effect)return;m.effect=null;
140
+ try{
141
+ if(!e.canMutateDraft(m.generation)||m.target!==targetIdentity(e.baseline))throw new Error('history.stale');
142
+ if(effect==='profiles'){
143
+ const library=await backend.request('profiles_read',{});if(e.reuse!==m||m.generation!==e.mutationGeneration)return;m.library=library;m.page='profiles';m.cursor=0;
144
+ }else{
145
+ const incoming=m.profileFile?{display:(await backend.request('profile_import',{path:m.input.value})).display,host:clone(e.draft.host)}:(await backend.request('review_import',{draft:e.draft,path:m.input.value})).draft;
146
+ if(e.reuse!==m||m.generation!==e.mutationGeneration)return;m.incoming=clone(incoming);m.local=false;m.page='select';m.cursor=0;m.groups=[];
147
+ }
148
+ m.message=null;
149
+ }catch(error){if(e.reuse===m)m.message=text('history.failed',{detail:error instanceof Error?error.message:String(error)});}
150
+ }
@@ -0,0 +1,96 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ /** Pure style selection and whole-group reference closure, shared by all frontends. */
3
+ import type { CatalogItem, Draft, InstanceDraft, ReuseRequest, ReuseReviewResult, Scope } from '../generated-contracts.ts';
4
+ import { FORMAT_CHOICES } from '../generated-contracts.ts';
5
+ import { clone } from './history.ts';
6
+ import { supportedFormats } from './appearance.ts';
7
+ import { alignmentUnits, refKey } from './alignments.ts';
8
+ import { isDraft } from '../backend.ts';
9
+ import { differences } from './import-differences.ts';
10
+
11
+ export const STYLE_FIELDS = ['foreground', 'background', 'foreground_gradient', 'background_gradient', 'label', 'icon', ...Object.keys(FORMAT_CHOICES).map(key => 'formatting.' + key)];
12
+ const area = (draft: Draft, scope: Scope) => scope === 'main' ? draft.display : draft.display.subagents;
13
+ export function styleFields(node: InstanceDraft, scope: Scope, catalog: readonly CatalogItem[] = []): string[] {
14
+ if (node.type_id === 'spacer') return [];
15
+ const formats = supportedFormats(scope, node.type_id, catalog.find(c => c.scope === scope && c.id === node.type_id)?.capabilities);
16
+ return STYLE_FIELDS.filter(field => !field.startsWith('formatting.') || formats.includes(field.slice(11)));
17
+ }
18
+ export function reuseRequest(value: unknown): ReuseRequest {
19
+ if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('reuse.invalid');
20
+ const r = value as Record<string, unknown>, ids = (v: unknown): v is string[] => Array.isArray(v) && v.length <= 10000 && v.every(id => typeof id === 'string' && /^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/u.test(id)) && new Set(v).size === v.length;
21
+ const keys = r.kind === 'style' ? ['kind','scope','from_scope','from_id','to_ids','fields'] : ['kind','scope','group_ids','references','explicit'];
22
+ if (Object.keys(r).length !== keys.length || keys.some(key => !Object.hasOwn(r,key)) || !['main','subagent'].includes(String(r.scope))) throw new Error('reuse.invalid');
23
+ if (r.kind === 'style') {
24
+ if (!['main','subagent'].includes(String(r.from_scope)) || !ids([r.from_id]) || !ids(r.to_ids) || !r.to_ids.length || !Array.isArray(r.fields) || r.fields.some(f => !STYLE_FIELDS.includes(String(f))) || new Set(r.fields).size !== r.fields.length) throw new Error('reuse.invalid');
25
+ } else if (r.kind !== 'groups' || !ids(r.group_ids) || !r.group_ids.length || !['review','expand','exclude'].includes(String(r.references)) || typeof r.explicit !== 'boolean') throw new Error('reuse.invalid');
26
+ return clone(value as ReuseRequest);
27
+ }
28
+ export function reuseDraft(base: Draft, incoming: Draft, raw: ReuseRequest, nextId: () => string, catalog: readonly CatalogItem[] = [], local = false): ReuseReviewResult {
29
+ const request = reuseRequest(raw), draft = clone(base), source = area(incoming, request.kind === 'style' ? request.from_scope : request.scope), target = area(draft, request.scope);
30
+ const mappings: ReuseReviewResult['mappings'] = { instances: {}, groups: {}, alignments: {} }, dependencies: string[] = [], blocked: string[] = [];
31
+ if (request.kind === 'style') {
32
+ const origin = source.instances.find(n => n.id === request.from_id);
33
+ if (!origin) throw new Error('reuse.invalid');
34
+ for (const id of request.to_ids) {
35
+ const destination = target.instances.find(n => n.id === id);
36
+ if (!destination || request.fields.some(field => !styleFields(origin, request.from_scope, catalog).includes(field) || !styleFields(destination, request.scope, catalog).includes(field))) throw new Error('reuse.incompatible');
37
+ for (const field of request.fields) {
38
+ const formatting = field.startsWith('formatting.'), key = formatting ? field.slice(11) : field;
39
+ const from = (formatting ? origin.options.formatting : origin.options) as unknown as Record<string, unknown>;
40
+ const to = (formatting ? destination.options.formatting : destination.options) as unknown as Record<string, unknown>;
41
+ if (Object.hasOwn(from,key)) to[key] = clone(from[key]); else delete to[key];
42
+ }
43
+ }
44
+ } else {
45
+ const selected = new Set<string>(), selectedGroups = new Set(request.group_ids);
46
+ const addGroup = (id: string) => { const group = source.groups.find(g => g.id === id); if (!group) throw new Error('reuse.invalid'); selectedGroups.add(id); group.member_ids.forEach(member => selected.add(member)); };
47
+ request.group_ids.forEach(addGroup);
48
+ const alignments = request.scope === 'main' ? incoming.display.layout.alignments ?? [] : [];
49
+ const included = (ref: { kind: string; id: string }) => ref.kind === 'group' ? selectedGroups.has(ref.id) : selected.has(ref.id);
50
+ let growing = true;
51
+ while (growing) {
52
+ growing = false;
53
+ for (const a of alignments.filter(a => a.columns.flat().some(included))) for (const ref of a.columns.flat().filter(ref => !included(ref))) {
54
+ const dependency = refKey(ref); if (!dependencies.includes(dependency)) dependencies.push(dependency);
55
+ if (request.references === 'expand') {
56
+ if (ref.kind === 'group') addGroup(ref.id);
57
+ else { const group = source.groups.find(g => g.member_ids.includes(ref.id)); if (group) addGroup(group.id); else selected.add(ref.id); }
58
+ growing = true;
59
+ }
60
+ }
61
+ if (request.references !== 'expand') break;
62
+ }
63
+ const retained = alignments.filter(a => a.columns.flat().some(included) && a.columns.flat().every(included));
64
+ if (dependencies.length && request.references === 'review') blocked.push('reuse.references');
65
+ // Alignment side is part of the relationship: retain each necessary row spacer.
66
+ if (request.scope === 'main') for (const unit of alignmentUnits(incoming.display.layout, source.instances, source.groups)) {
67
+ if (unit.side === 'right' && included(unit.ref)) {
68
+ const spacer = incoming.display.layout.rows[unit.row]!.find(id => source.instances.find(n => n.id === id)?.type_id === 'spacer');
69
+ if (spacer) selected.add(spacer);
70
+ }
71
+ }
72
+ const nodes = source.instances.filter(n => selected.has(n.id));
73
+ if (nodes.length !== selected.size) throw new Error('reuse.invalid');
74
+ const occupied = new Set([...target.instances.map(n => n.id), ...target.groups.map(g => g.id), ...(draft.display.layout.alignments ?? []).map(a => a.id)]);
75
+ const fresh = () => { for (let i = 0; i < 100; i++) { const id = nextId(); if (/^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/u.test(id) && !occupied.has(id)) { occupied.add(id); return id; } } throw new Error('reuse.invalid'); };
76
+ for (const node of nodes) mappings.instances[node.id] = fresh();
77
+ for (const id of selectedGroups) mappings.groups[id] = fresh();
78
+ for (const a of retained) mappings.alignments[a.id] = fresh();
79
+ const copies = nodes.map(node => ({ ...clone(node), id: mappings.instances[node.id]!, ...(node.source && !local ? { source: { binding: null, hint: node.source.hint } } : {}) }));
80
+ target.instances.push(...copies);
81
+ target.groups.push(...source.groups.filter(g => selectedGroups.has(g.id)).map(g => ({ ...clone(g), id: mappings.groups[g.id]!, primary_id: mappings.instances[g.primary_id]!, member_ids: g.member_ids.map(id => mappings.instances[id]!) })));
82
+ if (request.scope === 'main') {
83
+ const layout = draft.display.layout, importedRows = (incoming.display.layout.mode === 'explicit' ? incoming.display.layout.rows : [nodes.map(n => n.id)]).map(row => row.filter(id => selected.has(id)).map(id => mappings.instances[id]!)).filter(row => row.length);
84
+ const needsExplicit = importedRows.length > 1 || retained.length > 0 || nodes.some(n => n.type_id === 'spacer');
85
+ if (layout.mode === 'auto' && needsExplicit) {
86
+ if (!request.explicit) blocked.push('reuse.explicit');
87
+ layout.mode = 'explicit'; layout.rows = base.display.instances.length ? [base.display.instances.map(n => n.id)] : [];
88
+ }
89
+ if (layout.mode === 'explicit') layout.rows.push(...importedRows);
90
+ if (retained.length) layout.alignments = [...(layout.alignments ?? []), ...retained.map(a => ({ id: mappings.alignments[a.id]!, columns: a.columns.map(column => column.map(ref => ({ kind: ref.kind, id: mappings[ref.kind === 'group' ? 'groups' : 'instances'][ref.id]! }))) }))];
91
+ }
92
+ }
93
+ if (!blocked.length && !isDraft(draft)) blocked.push('reuse.incompatible');
94
+ const unresolved = (['main','subagent'] as const).flatMap(scope => area(draft, scope).instances.filter(n => n.source && !n.source.binding && Object.values(mappings.instances).includes(n.id)).map(n => ({ scope, id: n.id, hint: n.source!.hint })));
95
+ return { draft: blocked.length ? clone(base) : draft, changes: blocked.length ? [] : differences(base, draft), mappings, dependencies, unresolved, blocked };
96
+ }
@@ -0,0 +1,7 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ import type { InstanceDraft, SourceContext, SourceDefinition } from '../generated-contracts.ts';
3
+ /** Matching a local source never authorizes it or collects an observation. */
4
+ export function compatibleSource(node: InstanceDraft, source: SourceDefinition, context: SourceContext | null): boolean {
5
+ if (node.type_id === 'external-value' ? !['json','command'].includes(source.kind) : !['github-pr','github-ci'].includes(node.type_id) || source.kind !== 'github') return false;
6
+ return (['project','session','agent'] as const).every(key => source.scope[key] === null || source.scope[key] === context?.[key]);
7
+ }
@@ -1,17 +1,24 @@
1
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';
2
+ import { clone } from './history.ts';
3
+ import { compatibleSource } from './source-compatibility.ts';
4
+ import { sourceSummary, sourceReviewLines } from './source-summary.ts';
5
+ import type { Operation, ResultFor, SourcesResult, SourceDefinition, SourceContext, SourceJob, SourceReview, SourceInspection, BindingReview, Scope } from '../generated-contracts.ts';
3
6
  import type { Editor } from './draft.ts';
4
7
  import { t, text, type Language, type LocalizedText } from '../i18n/index.ts';
5
8
  import { inputKey, inputView, textInput, type TextInput, type TextKey } from './text-input.ts';
6
9
  import { wrapText } from '../../ui/text.ts';
7
10
  import { BackendError } from '../backend.ts';
8
- type Action = 'edit' | 'review' | 'disable' | 'remove' | 'bind' | 'unbind' | 'refresh' | 'status' | 'cancel' | 'diagnose' | 'auto-review' | 'auto-off';
11
+ type Action = 'edit' | 'review' | 'disable' | 'remove' | 'bind' | 'unbind' | 'refresh' | 'status' | 'cancel' | 'diagnose' | 'auto-review' | 'auto-off' | 'checks' | 'raw';
9
12
  export interface SourceManager {
10
13
  library: SourcesResult | null;
11
14
  context: SourceContext | null;
12
15
  owner: string;
13
16
  closed: boolean;
14
- page: 'list' | 'actions' | 'kind' | 'form' | 'review' | 'remove' | 'bind' | 'unbind' | 'diagnose' | 'auto-review';
17
+ page: 'list' | 'actions' | 'kind' | 'form' | 'review' | 'remove' | 'bind' | 'unbind' | 'diagnose' | 'auto-review' | 'checks' | 'bindings' | 'binding-cleanup';
18
+ inspection: SourceInspection | null;
19
+ bindingReview: BindingReview | null;
20
+ bindingSelection: string | null;
21
+ offset: number;
15
22
  automaticInterval: number;
16
23
  cursor: number;
17
24
  scroll: number;
@@ -26,7 +33,7 @@ export interface SourceManager {
26
33
  details: string[];
27
34
  jobs: SourceJob[];
28
35
  message: LocalizedText | null;
29
- effect: 'load' | 'save' | 'review' | 'enable' | 'disable' | 'remove' | 'bind' | 'refresh' | 'status' | 'cancel' | 'diagnose' | 'close' | 'auto-review' | 'auto-on' | 'auto-off' | null;
36
+ effect: 'load' | 'save' | 'review' | 'enable' | 'disable' | 'remove' | 'bind' | 'refresh' | 'status' | 'cancel' | 'diagnose' | 'close' | 'auto-review' | 'auto-on' | 'auto-off' | 'checks' | 'raw' | 'bindings' | 'binding-cleanup' | null;
30
37
  target: {
31
38
  scope: Scope;
32
39
  id: string;
@@ -37,14 +44,14 @@ export interface SourceBackend {
37
44
  }
38
45
  const external = ['external-value', 'github-pr', 'github-ci'];
39
46
  export function openSources(editor: Editor): void {
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 };
47
+ editor.sources = { library: null, context: null, owner: 'editor-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2), closed: false, inspection: null, bindingReview: null, bindingSelection: null, offset: 0, 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 };
41
48
  }
42
49
  function source(editor: Editor): SourceDefinition | undefined { return editor.sources!.library?.sources.find(s => s.id === editor.sources!.selected); }
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] : [])]; }
50
+ function actions(editor: Editor): Action[] { return ['edit', 'review', ...(source(editor)?.enabled ? ['disable' as const] : []), 'bind', 'refresh', 'status', 'cancel', 'diagnose', 'remove', 'unbind', ...(['github','command'].includes(source(editor)?.kind ?? '') ? ['auto-review' as const, 'auto-off' as const] : []), 'checks', 'raw']; }
44
51
  function targets(editor: Editor) {
45
52
  const s = source(editor);
46
53
  return (['main', 'subagent'] as const).flatMap(scope => (scope === 'main' ? editor.draft.display.instances : editor.draft.display.subagents.instances)
47
- .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 })));
54
+ .filter(node => external.includes(node.type_id) && (!s || compatibleSource(node, s, editor.sources!.context)) && (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 })));
48
55
  }
49
56
  function form(editor: Editor, kind: SourceDefinition['kind'], editing = false): void {
50
57
  const m = editor.sources!, s = editing ? source(editor) : undefined, settings = s?.settings ?? {};
@@ -62,7 +69,7 @@ function form(editor: Editor, kind: SourceDefinition['kind'], editing = false):
62
69
  }
63
70
  function count(editor: Editor): number {
64
71
  const m = editor.sources!;
65
- 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;
72
+ return m.page === 'list' ? (m.library?.sources.length ?? 0) + 2 : m.page === 'actions' ? actions(editor).length : m.page === 'kind' ? 3 : m.page === 'bindings' ? (m.bindingReview?.rows.length ?? 0) : m.page === 'form' ? m.fields.length : m.page === 'bind' || m.page === 'unbind' ? targets(editor).length : 1;
66
73
  }
67
74
  export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
68
75
  const m = editor.sources;
@@ -101,10 +108,14 @@ export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
101
108
  }
102
109
  if (!plain)
103
110
  return null;
104
- if (['review', 'diagnose', 'auto-review'].includes(m.page) && ['up', 'down', 'pageup', 'pagedown', 'home'].includes(key)) {
111
+ if (['review', 'diagnose', 'auto-review', 'checks', 'binding-cleanup'].includes(m.page) && ['up', 'down', 'pageup', 'pagedown', 'home'].includes(key)) {
105
112
  m.scroll = key === 'home' ? 0 : Math.max(0, m.scroll + (key === 'up' ? -1 : key === 'pageup' ? -8 : key === 'pagedown' ? 8 : 1));
106
113
  return null;
107
114
  }
115
+ if (['checks','bindings'].includes(m.page) && ['left','right'].includes(key)) {
116
+ const total=m.page==='checks'?m.inspection?.total:m.bindingReview?.total;
117
+ m.offset=Math.max(0,Math.min(m.offset+(key==='left'?-16:16),Math.max(0,Math.floor(((total??1)-1)/16)*16)));m.cursor=0;m.effect=m.page==='checks'?'checks':'bindings';return 'sources';
118
+ }
108
119
  if (m.page === 'auto-review' && ['left', 'right'].includes(key)) { m.automaticInterval = Math.max(60, Math.min(86400, m.automaticInterval + (key === 'left' ? -60 : 60))); return null; }
109
120
  if (key === 'up' || key === 'down')
110
121
  m.cursor = Math.max(0, Math.min(count(editor) - 1, m.cursor + (key === 'up' ? -1 : 1)));
@@ -117,14 +128,17 @@ export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
117
128
  m.selected = selected.id;
118
129
  m.page = 'actions';
119
130
  }
131
+ else if(m.cursor === (m.library?.sources.length??0)+1){m.offset=0;m.effect='bindings';}
120
132
  else
121
133
  m.page = 'kind';
122
134
  m.cursor = 0;
123
135
  }
136
+ else if(m.page==='bindings'){const row=m.bindingReview?.rows[m.cursor];if(row?.removable){m.bindingSelection=row.id;m.page='binding-cleanup';m.scroll=0;}}
137
+ else if(m.page==='binding-cleanup')m.effect='binding-cleanup';
124
138
  else if (m.page === 'kind')
125
139
  form(editor, (['json', 'github', 'command'] as const)[m.cursor]!);
126
140
  else if (m.page === 'actions') {
127
- const action = actions(editor)[m.cursor]!;
141
+ const action = actions(editor)[m.cursor]!;m.offset=0;
128
142
  if (action === 'edit')
129
143
  form(editor, source(editor)!.kind, true);
130
144
  else if (action === 'bind' || action === 'unbind' || action === 'remove') {
@@ -143,7 +157,9 @@ export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
143
157
  const target = targets(editor)[m.cursor];
144
158
  const node = target && editor.instance(target.scope, target.id);
145
159
  if (node?.source) {
146
- node.source = { ...node.source, binding: null };
160
+ const draft = clone(editor.draft);
161
+ (target!.scope === 'main' ? draft.display : draft.display.subagents).instances.find(n => n.id === target!.id)!.source = { ...node.source, binding: null };
162
+ editor.commitDraft(draft);
147
163
  m.message = text('sources.bound');
148
164
  m.page = 'list';
149
165
  m.cursor = 0;
@@ -188,46 +204,36 @@ export async function performSourceAction(editor: Editor, backend: SourceBackend
188
204
  m.library = await backend.request('sources_read', {});
189
205
  const target = editor.baseline.configuration;
190
206
  m.context = await backend.request('source_context', { project: target?.project_root ?? (target?.target.kind === 'project' ? target.target.path : null), session: null, agent: null });
207
+ if(!m.closed){editor.sourceDraftRegistered=true;await backend.request('source_draft',{owner:editor.sourceDraftOwner,bindings:draftBindings(editor),close:false});}
191
208
  return;
192
209
  }
210
+ if(effect==='bindings'||effect==='binding-cleanup'){
211
+ m.bindingReview=effect==='bindings'?await backend.request('source_bindings_review',{offset:m.offset}):await backend.request('source_bindings_cleanup',{revision:m.bindingReview!.revision,ids:[m.bindingSelection]});
212
+ m.page='bindings';m.cursor=0;m.scroll=0;return;
213
+ }
193
214
  if (effect === 'review' || effect === 'auto-review') {
194
215
  m.review = await backend.request('source_review', { id: m.selected });
195
216
  m.page = effect;
196
- m.automaticInterval = m.library?.automatic.find(p => p.source_id === m.selected)?.interval_seconds ?? Math.max(60, Math.min(86400, m.review.source.ttl_seconds));
197
- m.scroll = 0;
198
- return;
199
- }
200
- if (effect === 'status' || effect === 'cancel') {
201
- const selected = source(editor)!;
202
- const context = await backend.request('source_context', { project: selected.scope.project ?? m.context?.project ?? null, session: selected.scope.session, agent: selected.scope.agent });
203
- const observed = await backend.request('source_diagnose', { id: m.selected, context });
204
- const jobs = await Promise.all(observed.jobs.map(job => backend.request(effect === 'cancel' && job.state === 'running' ? 'source_cancel' : 'source_status', { id: job.id })));
205
- m.jobs = m.jobs.map(job => jobs.find(updated => updated.id === job.id) ?? job);
206
- m.details = [JSON.stringify(observed.automatic, null, 2), ...jobs.map(job => `${job.id}: ${job.state} (${job.reason})`)];
207
- m.page = 'diagnose';
217
+ m.automaticInterval = m.library?.automatic.find(p => p.source_id === m.selected)?.interval_seconds ?? (m.review.source.kind === 'command' ? 300 : Math.max(60, Math.min(86400, m.review.source.ttl_seconds)));
208
218
  m.scroll = 0;
209
219
  return;
210
220
  }
211
- if (effect === 'refresh' || effect === 'diagnose') {
212
- const selected = source(editor)!;
213
- const context = await backend.request('source_context', { project: selected.scope.project ?? m.context?.project ?? null, session: selected.scope.session, agent: selected.scope.agent });
214
- if (effect === 'refresh') {
215
- if (m.closed || editor.sources !== m) return;
216
- const job = await backend.request('source_refresh', { id: m.selected, context, owner: m.owner });
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];
222
- m.message = text('sources.refresh_started');
221
+ if (['status','cancel','refresh','diagnose','checks','raw'].includes(effect)) {
222
+ const selected=source(editor)!;
223
+ const context=await backend.request('source_context',{project:selected.scope.project??m.context?.project??null,session:selected.scope.session,agent:selected.scope.agent});
224
+ if(m.closed||editor.sources!==m)return;
225
+ if(effect==='refresh'){
226
+ const job=await backend.request('source_refresh',{id:m.selected,context,owner:m.owner});
227
+ if(m.closed||editor.sources!==m){await backend.request('source_release',{id:job.id,owner:m.owner});return;}
228
+ m.jobs=[...m.jobs.filter(previous=>previous.id!==job.id),job];m.message=text('sources.refresh_started');return;
223
229
  }
224
- else {
225
- const result = await backend.request('source_diagnose', { id: m.selected, context });
226
- m.details = JSON.stringify(result, null, 2).split('\n');
227
- m.page = 'diagnose';
228
- m.scroll = 0;
230
+ if(effect==='cancel'){
231
+ const report=await backend.request('source_diagnose',{id:m.selected,context});
232
+ for(const job of report.jobs.filter(j=>j.state==='running'))await backend.request('source_cancel',{id:job.id});
229
233
  }
230
- return;
234
+ const report=await backend.request('source_inspect',{id:m.selected,context,offset:m.offset});
235
+ if(m.closed||editor.sources!==m)return;
236
+ m.inspection=report;m.jobs=m.jobs.map(j=>report.jobs.find(updated=>updated.id===j.id)??j);m.details=effect==='raw'?JSON.stringify(report,null,2).split('\n'):[];m.page=effect==='checks'?'checks':'diagnose';m.scroll=0;return;
231
237
  }
232
238
  const payload: Record<string, unknown> = { action: effect, id: m.selected, expected_revision: m.library!.revision };
233
239
  if (effect === 'save') {
@@ -243,6 +249,7 @@ export async function performSourceAction(editor: Editor, backend: SourceBackend
243
249
  parsed.pr = parsed.pr === '' ? null : Number(parsed.pr);
244
250
  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 } });
245
251
  }
252
+ if(effect==='bind'){payload.binding=m.target?editor.instance(m.target.scope,m.target.id)?.source?.binding:null;payload.draft_owner=editor.sourceDraftOwner;editor.sourceDraftRegistered=true;await backend.request('source_draft',{owner:editor.sourceDraftOwner,bindings:draftBindings(editor),close:false});}
246
253
  if (effect === 'enable' || effect === 'auto-on') payload.review_revision = m.review?.review_revision;
247
254
  if (effect === 'auto-on') payload.interval_seconds = m.automaticInterval;
248
255
  const result = await backend.request('sources_apply', payload);
@@ -250,8 +257,11 @@ export async function performSourceAction(editor: Editor, backend: SourceBackend
250
257
  if (effect === 'bind' && m.target && result.binding) {
251
258
  if (!editor.canMutateDraft(generation) || editor.sources !== m) { m.message=editor.compositionError;return; }
252
259
  const node = editor.instance(m.target.scope, m.target.id);
253
- if (node)
254
- node.source = result.binding;
260
+ if (node) {
261
+ const draft = clone(editor.draft);
262
+ (m.target.scope === 'main' ? draft.display : draft.display.subagents).instances.find(n => n.id === m.target!.id)!.source = result.binding;
263
+ editor.commitDraft(draft);
264
+ }
255
265
  m.message = text('sources.bound');
256
266
  }
257
267
  else
@@ -278,8 +288,13 @@ export function sourcesView(editor: Editor, language: Language, width: number, h
278
288
  if (m.message)
279
289
  add(t(m.message.key, language, m.message.params));
280
290
  if (m.page === 'list') {
281
- m.library?.sources.forEach((s, i) => add(`${s.name} · ${s.kind} · ${tr(s.enabled ? 'enabled' : 'disabled')}${s.kind === 'github' ? ' · ' + tr(m.library!.automatic.some(p => p.source_id === s.id && p.enabled) ? 'automatic_on' : 'automatic_off') : ''}`, m.cursor === i));
291
+ m.library?.sources.forEach((s, i) => add(`${s.name} · ${tr(s.kind)} · ${tr(s.enabled ? 'enabled' : 'disabled')}${['github','command'].includes(s.kind) ? ' · ' + tr(m.library!.automatic.some(p => p.source_id === s.id && p.enabled) ? 'automatic_on' : 'automatic_off') : ''}`, m.cursor === i));
282
292
  add('+ ' + tr('add'), m.cursor === (m.library?.sources.length ?? 0));
293
+ add(tr('bindings'),m.cursor===(m.library?.sources.length??0)+1);
294
+ }
295
+ else if(m.page==='bindings'){
296
+ add(tr(m.bindingReview?.uncertain?'bindings_uncertain':'bindings_help'));
297
+ m.bindingReview?.rows.forEach((row,i)=>add(`${row.id} · ${row.source_id} · ${tr(row.removable?'binding_unused':'binding_protected')}${row.duplicate?' · '+tr('binding_duplicate'):''} · ${row.references.join(', ')}`,m.cursor===i));
283
298
  }
284
299
  else if (m.page === 'actions')
285
300
  actions(editor).forEach((action, i) => add(tr(action), m.cursor === i));
@@ -302,7 +317,8 @@ export function sourcesView(editor: Editor, language: Language, width: number, h
302
317
  else if (m.page === 'remove')
303
318
  add(tr('remove_confirm') + ' ' + source(editor)?.name, true);
304
319
  else {
305
- const lines = ['review', 'auto-review'].includes(m.page) ? [tr(m.page === 'auto-review' ? 'automatic_review' : 'enable_review'), ...(m.page === 'auto-review' ? [tr('interval') + ': ' + m.automaticInterval + ' s (←/→)'] : []), ...JSON.stringify(m.review?.source, null, 2).split('\n')] : m.details;
320
+ const readable=m.page==='checks'?[tr('checks_help'),...(m.inspection?[[m.inspection.source.settings.repository,m.inspection.source.settings.branch,m.inspection.checks_context?.head].filter(Boolean).join(' · ')]:[]),m.inspection?.checks_observed_at??t('task.unknown',language),...(m.inspection?.checks.flatMap(c=>[`${c.name} · ${c.state} · ${tr('check.'+c.bucket)}`,...(c.url?[c.url]:[])])??[])]:m.page==='binding-cleanup'?[tr('binding_cleanup_confirm'),m.bindingSelection??'']:m.inspection?sourceSummary(m.inspection,language):m.details;
321
+ const lines = ['review', 'auto-review'].includes(m.page) ? [tr(m.page === 'auto-review' ? 'automatic_review' : 'enable_review'), ...(m.page === 'auto-review' ? [tr('interval') + ': ' + m.automaticInterval + ' s (←/→)'] : []), ...(m.review?sourceReviewLines(m.review.source,language):[])] : m.details.length?m.details:readable;
306
322
  const wrapped = lines.flatMap(line => wrapText([line], width));
307
323
  const capacity = Math.max(1, height - rows.length);
308
324
  const start = Math.min(m.scroll, Math.max(0, wrapped.length - capacity));
@@ -313,3 +329,6 @@ export function sourcesView(editor: Editor, language: Language, width: number, h
313
329
  const selected = Math.max(0, entries.findIndex(row => row.selected)), start = Math.max(0, selected - capacity + 1);
314
330
  return [...fixed, ...entries.slice(start, start + capacity)];
315
331
  }
332
+
333
+ export function draftBindings(editor:Editor):string[]{return [...new Set([editor.draft,editor.baseline.draft,...editor.history.undo.map(e=>e.draft),...editor.history.redo.map(e=>e.draft)].flatMap(d=>[...d.display.instances,...d.display.subagents.instances].flatMap(n=>n.source?.binding?[n.source.binding]:[])))];}
334
+ export async function closeSourceDraft(editor:Editor,backend:SourceBackend):Promise<void>{if(editor.sourceDraftRegistered){await backend.request('source_draft',{owner:editor.sourceDraftOwner,bindings:[],close:true});editor.sourceDraftRegistered=false;}}
@@ -0,0 +1,22 @@
1
+ // Generated by tools/generation/resources.ts; do not edit.
2
+ import type { SourceInspection, SourceDefinition } from '../generated-contracts.ts';
3
+ import { t, type Language } from '../i18n/index.ts';
4
+ /** Shared readable presentation; raw observations remain available separately. */
5
+ export function sourceSummary(report:SourceInspection,language:Language):string[] {
6
+ const tr=(key:string,params:Record<string,unknown>={})=>t('sources.'+key,language,params),unknown=t('task.unknown',language);
7
+ const {source,view,automatic}=report;
8
+ const reason=(value:string)=>t('sources.error.'+value,language,{},t('sources.reason.'+value,language,{},value));
9
+ const lines=[source.name+' · '+tr(source.enabled?'enabled':'disabled'),tr('summary_state',{state:tr('reason.'+automatic.state),reason:reason(automatic.reason)}),tr('summary_scope',{project:source.scope.project??tr('scope_all'),session:source.scope.session??tr('scope_all'),agent:source.scope.agent??tr('scope_all')}),tr('summary_value',{value:view.value===null?unknown:String(view.value),state:tr('reason.'+view.state),freshness:tr('reason.'+view.freshness)}),tr('summary_reason',{reason:reason(view.reason)}),tr('summary_success',{value:report.last_success??automatic.last_success??unknown}),tr('summary_next',{value:automatic.next_at??unknown,interval:automatic.interval_seconds})];
10
+ for(const job of report.jobs){
11
+ lines.push(tr('summary_job',{id:job.id,state:tr('reason.'+job.state),reason:reason(job.reason)}));
12
+ lines.push(tr('summary_scope',{project:job.context.project??unknown,session:job.context.session??unknown,agent:job.context.agent??unknown}));
13
+ if(job.context.branch||job.context.head)lines.push((job.context.branch??unknown)+' · '+(job.context.head??unknown));
14
+ if(job.result){lines.push(tr('summary_result',{duration:job.result.duration_ms,code:job.result.exit_code??unknown,time:job.result.finished_at}));if(job.result.summary)lines.push(job.result.summary);}
15
+ }
16
+ return lines;
17
+ }
18
+
19
+ export function sourceReviewLines(source:SourceDefinition,language:Language):string[]{
20
+ const tr=(key:string)=>t('sources.'+key,language),all=tr('scope_all');
21
+ return [tr('field.id')+': '+source.id,tr('field.name')+': '+source.name,tr(source.kind),tr('field.project')+': '+(source.scope.project??all),tr('field.session')+': '+(source.scope.session??all),tr('field.agent')+': '+(source.scope.agent??all),tr('field.ttl_seconds')+': '+source.ttl_seconds,...Object.entries(source.settings).map(([key,value])=>tr('field.'+key)+': '+(typeof value==='object'?JSON.stringify(value):String(value??'')))];
22
+ }
@@ -18,8 +18,11 @@ function definition(v: unknown): boolean {
18
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
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
+ export function validSourceExecution(v:unknown):boolean {
22
+ return fields(v,['finished_at','duration_ms','exit_code','reason','summary']) && text(v.finished_at) && Number.isFinite(Date.parse(v.finished_at)) && typeof v.duration_ms==='number' && Number.isFinite(v.duration_ms) && v.duration_ms>=0 && (v.exit_code===null||Number.isSafeInteger(v.exit_code)) && text(v.reason) && text(v.summary) && v.summary.length<=4096;
23
+ }
21
24
  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', '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);
25
+ return fields(v, ['version', 'id', 'source_id', 'source_revision', 'owner', 'context', 'started_at', 'deadline_at', 'state', 'reason', 'trigger', 'identity', 'consumers', ...(object(v)&&Object.hasOwn(v,'result')?['result']:[])]) && [3,4].includes(Number(v.version)) && (v.result===undefined||v.result===null||validSourceExecution(v.result)) && 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
26
  }
24
27
  function view(v: unknown): boolean {
25
28
  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));
@@ -27,6 +30,12 @@ function view(v: unknown): boolean {
27
30
  export function isSourceResult(operation: string, value: unknown): boolean {
28
31
  if (!object(value))
29
32
  return false;
33
+ if(operation==='source_draft')return fields(value,['revision'])&&text(value.revision);
34
+ if(operation==='source_bindings_review'||operation==='source_bindings_cleanup')return fields(value,['revision','rows','offset','total','uncertain'])&&text(value.revision)&&typeof value.uncertain==='boolean'&&Number.isSafeInteger(value.offset)&&Number(value.offset)>=0&&Number.isSafeInteger(value.total)&&Number(value.total)>=0&&Array.isArray(value.rows)&&value.rows.length<=16&&value.rows.every(r=>fields(r,['id','source_id','references','duplicate','removable'])&&id(r.id)&&id(r.source_id)&&Array.isArray(r.references)&&r.references.length<=16&&r.references.every(text)&&typeof r.duplicate==='boolean'&&typeof r.removable==='boolean');
35
+ if(operation==='source_inspect'){
36
+ const {last_success,checks,checks_observed_at,checks_context,offset,total,...diagnosis}=value;
37
+ return fields(value,['source','view','jobs','automatic','last_success','checks','checks_observed_at','checks_context','offset','total'])&&isSourceResult('source_diagnose',diagnosis)&&nullable(last_success)&&nullable(checks_observed_at)&&(checks_context===null||isSourceContext(checks_context))&&Number.isSafeInteger(offset)&&Number(offset)>=0&&Number.isSafeInteger(total)&&Number(total)>=0&&Array.isArray(checks)&&checks.length<=16&&checks.every(c=>fields(c,['name','state','bucket','url'])&&text(c.name)&&text(c.state)&&text(c.bucket)&&nullable(c.url)&&(c.url===null||/^https?:\/\//u.test(String(c.url))));
38
+ }
30
39
  if (operation === 'source_context')
31
40
  return isSourceContext(value);
32
41
  if (operation === 'source_review')
@@ -37,7 +46,7 @@ export function isSourceResult(operation: string, value: unknown): boolean {
37
46
  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);
38
47
  if (!['sources_read', 'sources_apply'].includes(operation) || !fields(value, ['version', 'sources', 'bindings', 'automatic', 'revision', ...(operation === 'sources_apply' ? ['backup_dir', ...(Object.hasOwn(value, 'binding') ? ['binding'] : [])] : [])]))
39
48
  return false;
40
- if (value.version !== 2 || !text(value.revision) || !Array.isArray(value.sources) || value.sources.length > 128 || !value.sources.every(definition) || !Array.isArray(value.bindings) || value.bindings.length > 4096)
49
+ if (![2,3].includes(Number(value.version)) || !text(value.revision) || !Array.isArray(value.sources) || value.sources.length > 128 || !value.sources.every(definition) || !Array.isArray(value.bindings) || value.bindings.length > 4096)
41
50
  return false;
42
51
  if (!Array.isArray(value.automatic) || value.automatic.length > value.sources.length || !value.automatic.every(p => fields(p, ['source_id', 'enabled', 'review_revision', 'interval_seconds', 'auth_revision']) && id(p.source_id) && typeof p.enabled === 'boolean' && id(p.review_revision) && typeof p.interval_seconds === 'number' && Number.isInteger(p.interval_seconds) && p.interval_seconds >= 60 && p.interval_seconds <= 86400 && typeof p.auth_revision === 'string' && /^[a-f0-9]{64}$/.test(p.auth_revision))) return false;
43
52
  if (!value.bindings.every(b => fields(b, ['id', 'source_id']) && id(b.id) && id(b.source_id)))