@fbincon/claude-code-statusline 3.11.0 → 3.12.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 (130) hide show
  1. package/README.md +79 -79
  2. package/candidate.json +247 -196
  3. package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js +5 -1
  4. package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js.map +1 -1
  5. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.d.ts +1 -0
  6. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.js +41 -0
  7. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.js.map +1 -0
  8. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.d.ts +1 -0
  9. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.js +14 -0
  10. package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.js.map +1 -0
  11. package/node_modules/@fbincon/statusline-cli/dist/src/main.js +9 -0
  12. package/node_modules/@fbincon/statusline-cli/dist/src/main.js.map +1 -1
  13. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.d.ts +1 -0
  14. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.js +4 -0
  15. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.js.map +1 -0
  16. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.d.ts +29 -0
  17. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.js +228 -0
  18. package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.js.map +1 -0
  19. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.d.ts +4 -0
  20. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.js +150 -0
  21. package/node_modules/@fbincon/statusline-cli/dist/src/management/history.js.map +1 -0
  22. package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.js +30 -13
  23. package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.js.map +1 -1
  24. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js +2 -2
  25. package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js.map +1 -1
  26. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.d.ts +1 -0
  27. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.js +11 -6
  28. package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.js.map +1 -1
  29. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.d.ts +2 -0
  30. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js +9 -5
  31. package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js.map +1 -1
  32. package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js +6 -6
  33. package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js.map +1 -1
  34. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.d.ts +1 -0
  35. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js +6 -6
  36. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js.map +1 -1
  37. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic.js +76 -28
  38. package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic.js.map +1 -1
  39. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.d.ts +17 -0
  40. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.js +176 -0
  41. package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.js.map +1 -0
  42. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js +11 -3
  43. package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js.map +1 -1
  44. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js +26 -8
  45. package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js.map +1 -1
  46. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.d.ts +3 -0
  47. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js +54 -14
  48. package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js.map +1 -1
  49. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +3 -3
  50. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +36 -0
  51. package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js.map +1 -1
  52. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/.claude-plugin/plugin.json +1 -1
  53. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/hooks/register.ts +23 -15
  54. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +4 -2
  55. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +4 -0
  56. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/package-manager.ts +164 -291
  57. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/package-validation.ts +10 -1
  58. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-manager.ts +53 -41
  59. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-summary.ts +22 -0
  60. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-validation.ts +11 -2
  61. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +42 -6
  62. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +7 -12722
  63. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/en.ts +2220 -0
  64. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/ja.ts +2220 -0
  65. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/ko.ts +2220 -0
  66. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-CN.ts +2220 -0
  67. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-HK.ts +2220 -0
  68. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-TW.ts +2220 -0
  69. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +21 -14
  70. package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +1 -1
  71. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/.claude-plugin/plugin.json +1 -1
  72. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/hooks/observe.ts +10 -3
  73. package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/resource-manifest.json +4 -4
  74. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +98 -6
  75. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js +2 -2
  76. package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js.map +1 -1
  77. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.d.ts +3 -0
  78. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +7 -0
  79. package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
  80. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.d.ts +12 -4
  81. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.js +302 -85
  82. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.js.map +1 -1
  83. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.js +12 -1
  84. package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.js.map +1 -1
  85. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.d.ts +9 -3
  86. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js +74 -26
  87. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js.map +1 -1
  88. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.d.ts +5 -0
  89. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.js +25 -0
  90. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.js.map +1 -0
  91. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.d.ts +1 -0
  92. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js +13 -2
  93. package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js.map +1 -1
  94. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.d.ts +2 -0
  95. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js +15 -3
  96. package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js.map +1 -1
  97. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +606 -12
  98. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +612 -18
  99. package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
  100. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js +1 -0
  101. package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js.map +1 -1
  102. package/node_modules/@fbincon/statusline-core/dist/src/release.d.ts +1 -1
  103. package/node_modules/@fbincon/statusline-core/dist/src/release.js +1 -1
  104. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +102 -3
  105. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +102 -3
  106. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +102 -3
  107. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +102 -3
  108. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +102 -3
  109. package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +102 -3
  110. package/node_modules/@fbincon/statusline-platform/dist/src/native.d.ts +2 -0
  111. package/node_modules/@fbincon/statusline-platform/dist/src/native.js +2 -0
  112. package/node_modules/@fbincon/statusline-platform/dist/src/native.js.map +1 -1
  113. package/node_modules/@fbincon/statusline-platform/dist/src/npm.d.ts +2 -0
  114. package/node_modules/@fbincon/statusline-platform/dist/src/npm.js +20 -1
  115. package/node_modules/@fbincon/statusline-platform/dist/src/npm.js.map +1 -1
  116. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.d.ts +3 -0
  117. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.js +53 -0
  118. package/node_modules/@fbincon/statusline-platform/dist/src/private-state.js.map +1 -0
  119. package/node_modules/@fbincon/statusline-platform/dist/src/processes.d.ts +2 -0
  120. package/node_modules/@fbincon/statusline-platform/dist/src/processes.js +45 -0
  121. package/node_modules/@fbincon/statusline-platform/dist/src/processes.js.map +1 -1
  122. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.d.ts +5 -0
  123. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js +8 -1
  124. package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js.map +1 -1
  125. package/node_modules/@fbincon/statusline-tui/dist/src/session.d.ts +2 -1
  126. package/node_modules/@fbincon/statusline-tui/dist/src/session.js +10 -5
  127. package/node_modules/@fbincon/statusline-tui/dist/src/session.js.map +1 -1
  128. package/node_modules/@fbincon/statusline-tui/dist/src/state.js +4 -0
  129. package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
  130. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
- import type { PackageStatus, PackageReviewJob, PackageReviewRequest, Operation, ResultFor } from '../contracts/ui.js';
1
+ import type { PackageStatus, PackageReviewJob, PackageReviewRequest, PackageExecution, PackageCleanupReview, PackageControl, Operation, ResultFor } from '../contracts/ui.js';
2
+ import type { Editor } from './draft.js';
2
3
  import { type Language, type LocalizedText } from '../i18n/messages.js';
3
4
  import { type TextInput, type TextKey } from './text-input.js';
4
5
  interface Row {
@@ -12,6 +13,8 @@ export interface PackageManager {
12
13
  owner: string;
13
14
  status: PackageStatus | null;
14
15
  job: PackageReviewJob | null;
16
+ execution: PackageExecution | null;
17
+ cleanup: PackageCleanupReview | null;
15
18
  prefix: string;
16
19
  target: string;
17
20
  channel: 'latest' | 'beta' | null;
@@ -21,9 +24,13 @@ export interface PackageManager {
21
24
  rows: Row[];
22
25
  capacity: number;
23
26
  input: TextInput | null;
24
- editing: 'prefix' | 'target' | null;
27
+ editing: 'prefix' | 'target' | 'export_path' | null;
28
+ export_path: string;
25
29
  message: LocalizedText | string | null;
26
- effect: 'load' | 'start' | 'status' | 'cancel' | 'close' | null;
30
+ effect: 'load' | 'start' | 'status' | 'cancel' | 'close' | 'execute' | 'save-draft' | 'discard-draft' | 'export-draft' | 'reconcile-draft' | 'cleanup-review' | 'cleanup-apply' | null;
31
+ mode: 'status' | 'draft' | 'execute-confirm' | 'cleanup' | 'cleanup-confirm';
32
+ cleanupId: string | null;
33
+ draftPrepared: boolean;
27
34
  action: PackageReviewRequest['action'];
28
35
  backup: string | null;
29
36
  busy: boolean;
@@ -33,9 +40,10 @@ export interface PackageManager {
33
40
  export declare function packageManager(): PackageManager;
34
41
  export interface PackageBackend {
35
42
  request<O extends Operation>(operation: O, payload?: unknown): ResultFor<O> | Promise<ResultFor<O>>;
43
+ control?<O extends Operation>(control: PackageControl, operation: O, payload?: unknown): ResultFor<O> | Promise<ResultFor<O>>;
36
44
  }
37
45
  export declare function closePackage(view: PackageManager, backend: PackageBackend): Promise<void>;
38
- export declare function performPackage(view: PackageManager, backend: PackageBackend): Promise<void>;
46
+ export declare function performPackage(view: PackageManager, backend: PackageBackend, editor?: Editor): Promise<void>;
39
47
  export declare function packageView(view: PackageManager, language: Language, width: number, height: number): Row[];
40
48
  export declare function packageKey(view: PackageManager, event: TextKey): 'packages' | null;
41
49
  export {};
@@ -1,23 +1,33 @@
1
+ import { closeSourceDraft } from './source-manager.js';
1
2
  import { t, text, renderMessage } from '../i18n/messages.js';
2
3
  import { inputKey, inputView, textInput } from './text-input.js';
3
4
  import { wrapText } from './text.js';
4
5
  import { BackendError } from './backend.js';
5
6
  export function packageManager() {
6
- return { owner: 'viewer-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2), status: null, job: null,
7
- prefix: '', target: '', channel: null, offset: 0, selected: 'prefix', scroll: 0, rows: [], capacity: 1, input: null, editing: null, message: null,
8
- effect: 'load', action: 'check', backup: null, busy: false, closed: false, generation: 0 };
7
+ return { owner: 'viewer-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2), status: null, job: null, execution: null, cleanup: null, prefix: '', target: '', channel: null, offset: 0, selected: 'prefix', scroll: 0, rows: [], capacity: 1, input: null, editing: null, export_path: 'statusline-before-update.json', message: null, effect: 'load', mode: 'status', cleanupId: null, draftPrepared: false, action: 'check', backup: null, busy: false, closed: false, generation: 0 };
8
+ }
9
+ function request(view, backend, operation, payload) {
10
+ return view.execution && backend.control ? backend.control(view.execution.control, operation, payload) : backend.request(operation, payload);
9
11
  }
10
12
  export async function closePackage(view, backend) {
11
13
  view.closed = true;
12
14
  view.generation++;
13
- const job = view.job;
14
- if (job)
15
+ if (view.execution)
16
+ try {
17
+ await request(view, backend, 'package_execute_detach', { id: view.execution.id, owner: view.owner });
18
+ }
19
+ catch { /* Detach never cancels an executor. */ }
20
+ if (view.job)
15
21
  try {
16
- await backend.request('package_review_cancel', { id: job.id, owner: view.owner });
22
+ await request(view, backend, 'package_review_cancel', { id: view.job.id, owner: view.owner });
17
23
  }
18
- catch { /* Worker deadlines still bound a disconnected view. */ }
24
+ catch { /* Review deadlines still bound disconnected views. */ }
19
25
  }
20
- export async function performPackage(view, backend) {
26
+ function verified(view) {
27
+ const job = view.job, review = job?.review;
28
+ return job?.state === 'complete' && !!review?.compatible && job.request.action !== 'check' && (review.artifact_verified || job.request.action === 'restore-config');
29
+ }
30
+ export async function performPackage(view, backend, editor) {
21
31
  const effect = view.effect;
22
32
  if (!effect || view.busy)
23
33
  return;
@@ -31,7 +41,7 @@ export async function performPackage(view, backend) {
31
41
  try {
32
42
  if (effect === 'load') {
33
43
  if (view.job && view.prefix && view.job.request.prefix !== view.prefix) {
34
- const cancelled = await backend.request('package_review_cancel', { id: view.job.id, owner: view.owner });
44
+ const cancelled = await request(view, backend, 'package_review_cancel', { id: view.job.id, owner: view.owner });
35
45
  if (view.closed || generation !== view.generation)
36
46
  return;
37
47
  if (cancelled.state !== 'cancelled') {
@@ -42,7 +52,7 @@ export async function performPackage(view, backend) {
42
52
  }
43
53
  view.job = null;
44
54
  }
45
- const status = await backend.request('package_status', { prefix: view.prefix || null, offset: view.offset });
55
+ const status = await request(view, backend, 'package_status', { prefix: view.prefix || null, offset: view.offset });
46
56
  if (view.closed || generation !== view.generation)
47
57
  return;
48
58
  if (view.job && status.revision !== view.job.request.expected_revision) {
@@ -52,25 +62,27 @@ export async function performPackage(view, backend) {
52
62
  }
53
63
  view.status = status;
54
64
  view.prefix = status.prefix ?? view.prefix;
65
+ if (status.execution) {
66
+ view.execution = status.execution;
67
+ if (editor)
68
+ editor.packageLocked = true;
69
+ view.selected = 'execution';
70
+ }
55
71
  }
56
72
  else if (effect === 'start') {
57
73
  if (!view.status?.prefix)
58
74
  throw new BackendError('prefix', text('package.reason_prefix'));
59
- if (view.job?.state === 'running')
75
+ if (view.job?.state === 'running' || view.execution?.running !== false && view.execution?.state === 'running')
60
76
  return;
61
77
  const previous = view.job;
62
- let target = view.action === 'recover-package' ? view.status.pending?.version ?? view.target : view.target || null;
63
- let integrity = null;
64
- if (view.action === 'update' && previous?.state === 'complete' && previous.request.action === 'check' && previous.request.expected_revision === view.status.revision && previous.review &&
65
- (!target || target === previous.review.target) && (!view.channel || view.channel === previous.review.channel || !!target)) {
78
+ let target = view.action === 'recover-package' ? view.status.pending?.version ?? view.target : view.target || null, integrity = null;
79
+ if (view.action === 'update' && previous?.state === 'complete' && previous.request.action === 'check' && previous.request.expected_revision === view.status.revision && previous.review && (!target || target === previous.review.target) && (!view.channel || view.channel === previous.review.channel || !!target)) {
66
80
  target = previous.review.target;
67
81
  integrity = previous.review.integrity;
68
82
  }
69
- const request = { action: view.action, prefix: view.status.prefix, expected_revision: view.status.revision,
70
- target: view.action === 'restore-config' ? null : target, channel: !target && ['check', 'update'].includes(view.action) ? view.channel : null,
71
- backup_id: view.action === 'restore-config' ? view.backup : null, expected_integrity: integrity };
83
+ const reviewRequest = { action: view.action, prefix: view.status.prefix, expected_revision: view.status.revision, target: view.action === 'restore-config' ? null : target, channel: !target && ['check', 'update'].includes(view.action) ? view.channel : null, backup_id: view.action === 'restore-config' ? view.backup : null, expected_integrity: integrity };
72
84
  if (previous) {
73
- const cancelled = await backend.request('package_review_cancel', { id: previous.id, owner: view.owner });
85
+ const cancelled = await request(view, backend, 'package_review_cancel', { id: previous.id, owner: view.owner });
74
86
  if (view.closed || generation !== view.generation)
75
87
  return;
76
88
  if (cancelled.state !== 'cancelled') {
@@ -81,31 +93,132 @@ export async function performPackage(view, backend) {
81
93
  }
82
94
  view.job = null;
83
95
  }
84
- const job = await backend.request('package_review_start', { request, owner: view.owner });
96
+ const job = await request(view, backend, 'package_review_start', { request: reviewRequest, owner: view.owner });
85
97
  if (view.closed || generation !== view.generation) {
86
- await backend.request('package_review_cancel', { id: job.id, owner: view.owner });
98
+ await request(view, backend, 'package_review_cancel', { id: job.id, owner: view.owner });
87
99
  return;
88
100
  }
89
101
  view.job = job;
102
+ view.mode = 'status';
103
+ view.draftPrepared = false;
90
104
  view.message = null;
91
105
  view.selected = 'job';
92
106
  }
107
+ else if (effect === 'execute') {
108
+ if (!editor || !verified(view))
109
+ throw new BackendError('integrity', text('package.reason_integrity'));
110
+ if (editor.saveState !== 'idle') {
111
+ view.mode = 'draft';
112
+ view.message = text('editor.save_unknown');
113
+ return;
114
+ }
115
+ if (!view.draftPrepared) {
116
+ if (!editor.acceptNumeric()) {
117
+ view.message = text('package.ui.draft_required');
118
+ return;
119
+ }
120
+ view.mode = editor.modified ? 'draft' : 'execute-confirm';
121
+ view.selected = editor.modified ? 'draft-cancel' : 'execute-confirm';
122
+ return;
123
+ }
124
+ editor.packageLocked = true;
125
+ const execution = await request(view, backend, 'package_execute_start', { id: view.job.id, owner: view.owner });
126
+ view.execution = execution;
127
+ view.mode = 'status';
128
+ view.selected = 'execution';
129
+ view.message = text('package.ui.editor_locked');
130
+ await closeSourceDraft(editor, { request: (operation, payload) => request(view, backend, operation, payload) });
131
+ if (view.closed || generation !== view.generation)
132
+ await request(view, backend, 'package_execute_detach', { id: execution.id, owner: view.owner });
133
+ }
134
+ else if (effect === 'discard-draft') {
135
+ if (!editor || editor.saveState !== 'idle')
136
+ throw new BackendError('configuration_conflict', text('editor.save_locked'));
137
+ editor.replaceDraft(editor.baseline.draft);
138
+ view.draftPrepared = true;
139
+ view.mode = 'execute-confirm';
140
+ view.selected = 'execute-confirm';
141
+ }
142
+ else if (effect === 'save-draft') {
143
+ if (!editor || editor.saveState !== 'idle')
144
+ throw new BackendError('configuration_conflict', text('editor.save_locked'));
145
+ if (!editor.acceptNumeric()) {
146
+ view.message = text('package.ui.draft_required');
147
+ return;
148
+ }
149
+ const submitted = editor.beginSave();
150
+ try {
151
+ const saved = await backend.request('apply', { draft: submitted.draft, expected_revision: submitted.revision, ...(submitted.target ? { target: submitted.target } : {}) });
152
+ editor.committed(saved);
153
+ }
154
+ catch (error) {
155
+ editor.saveFailed(error instanceof BackendError ? error.code : '');
156
+ throw error;
157
+ }
158
+ view.mode = 'status';
159
+ view.job = null;
160
+ view.status = null;
161
+ view.effect = 'load';
162
+ view.message = text('package.ui.review_again');
163
+ }
164
+ else if (effect === 'export-draft') {
165
+ if (!editor || editor.saveState !== 'idle')
166
+ throw new BackendError('configuration_conflict', text('editor.save_locked'));
167
+ await backend.request('export', { draft: editor.draft, path: view.export_path, overwrite: false });
168
+ view.draftPrepared = true;
169
+ view.mode = 'execute-confirm';
170
+ view.selected = 'execute-confirm';
171
+ view.message = text('package.ui.exported');
172
+ }
173
+ else if (effect === 'reconcile-draft') {
174
+ if (!editor?.pendingSave)
175
+ return;
176
+ const pending = editor.pendingSave;
177
+ editor.setSaveState('pending');
178
+ try {
179
+ const current = await backend.request('read', pending.target ? { target: pending.target } : {});
180
+ const result = editor.reconcileSave(current);
181
+ view.message = text('editor.' + result);
182
+ view.mode = 'status';
183
+ view.job = null;
184
+ view.status = null;
185
+ view.effect = 'load';
186
+ }
187
+ catch (error) {
188
+ editor.setSaveState('unknown');
189
+ throw error;
190
+ }
191
+ }
192
+ else if (effect === 'cleanup-review') {
193
+ if (!view.prefix)
194
+ throw new BackendError('prefix', text('package.reason_prefix'));
195
+ view.cleanup = await request(view, backend, 'package_cleanup_review', { prefix: view.prefix, offset: view.offset });
196
+ view.mode = 'cleanup';
197
+ view.selected = view.cleanup.rows[0] ? 'cleanup:' + view.cleanup.rows[0].id : 'cleanup-message';
198
+ }
199
+ else if (effect === 'cleanup-apply') {
200
+ view.cleanup = await request(view, backend, 'package_cleanup_apply', { prefix: view.prefix, revision: view.cleanup.revision, ids: [view.cleanupId] });
201
+ view.mode = 'cleanup';
202
+ view.selected = 'cleanup-message';
203
+ view.message = text('package.ui.cleaned');
204
+ }
205
+ else if (effect === 'status' && view.execution) {
206
+ view.execution = await request(view, backend, 'package_execute_status', { id: view.execution.id });
207
+ view.selected = 'execution';
208
+ }
93
209
  else if (view.job) {
94
- const job = await backend.request(effect === 'cancel' ? 'package_review_cancel' : 'package_review_status', { id: view.job.id, owner: view.owner });
210
+ const job = await request(view, backend, effect === 'cancel' ? 'package_review_cancel' : 'package_review_status', { id: view.job.id, owner: view.owner });
95
211
  if (view.closed || generation !== view.generation)
96
212
  return;
97
213
  const cancelled = effect === 'cancel' && job.state === 'cancelled';
98
214
  view.job = cancelled ? null : job;
99
215
  view.message = effect === 'cancel' ? text(cancelled ? 'package.cancelled' : 'package.ui.cancel_requested') : null;
100
- if (effect === 'cancel')
101
- view.selected = 'message';
102
- else if (job.state !== 'running') {
103
- view.selected = job.review ? 'verification' : job.error ? 'job-error' : 'job';
104
- view.scroll = Math.max(0, view.rows.findIndex(row => row.key === 'job'));
105
- }
216
+ view.selected = effect === 'cancel' ? 'message' : job.review ? 'verification' : job.error ? 'job-error' : 'job';
106
217
  }
107
218
  }
108
219
  catch (error) {
220
+ if (effect === 'execute' && editor && !view.execution && error instanceof BackendError && ['arguments', 'conflict', 'integrity', 'identity', 'busy', 'development', 'permission', 'configuration', 'journal'].includes(error.code))
221
+ editor.packageLocked = false;
109
222
  if (!view.closed && generation === view.generation) {
110
223
  view.message = error instanceof BackendError && error.localization ? error.localization : text('package.reason_io_error');
111
224
  view.selected = 'message';
@@ -117,57 +230,102 @@ export async function performPackage(view, backend) {
117
230
  }
118
231
  }
119
232
  export function packageView(view, language, width, height) {
120
- const tr = (key, params = {}) => t(key, language, params), rows = [];
233
+ const tr = (key, params = {}) => t('package.ui.' + key, language, params), rows = [];
121
234
  const add = (key, value, action, backup) => wrapText([value.replace(/[\p{Cc}\p{Cs}]/gu, '')], Math.max(2, width - 2)).forEach((line, index) => rows.push({ key: index ? key + ':' + index : key, text: line, ...(action ? { action } : {}), ...(backup ? { backup } : {}) }));
122
235
  const status = view.status;
123
- add('notice', tr('package.ui.readonly'));
124
- if (status)
125
- add('current', tr('package.ui.current', { value: status.current ?? tr('task.unknown') }));
126
- add('prefix', tr('package.ui.prefix', { value: view.editing === 'prefix' && view.input ? inputView(view.input, Math.max(2, width - 12)) : view.prefix || tr('task.unknown') }));
127
- if (!status)
128
- add('loading', tr(view.busy ? 'profiles.loading' : 'task.unknown'));
236
+ if (view.mode === 'draft') {
237
+ add('notice', tr('draft_required'));
238
+ add('draft-save', tr('draft_save'));
239
+ add('draft-export', tr('draft_export'));
240
+ add('draft-discard', tr('draft_discard'));
241
+ add('draft-cancel', tr('draft_cancel'));
242
+ add('draft-reconcile', tr('draft_reconcile'));
243
+ }
244
+ else if (view.mode === 'execute-confirm') {
245
+ add('notice', tr('execute_notice'));
246
+ add('execute-confirm', tr('execute_confirm'));
247
+ add('draft-cancel', tr('draft_cancel'));
248
+ }
249
+ else if (view.mode === 'cleanup' || view.mode === 'cleanup-confirm') {
250
+ add('cleanup-message', tr(view.cleanup?.uncertain ? 'cleanup_uncertain' : 'cleanup_notice'));
251
+ if (view.mode === 'cleanup-confirm') {
252
+ add('cleanup-confirm', tr('cleanup_confirm'));
253
+ add('cleanup-selected', view.cleanupId ?? '');
254
+ }
255
+ else
256
+ for (const row of view.cleanup?.rows ?? [])
257
+ add('cleanup:' + row.id, `${row.id} · ${row.version ?? '—'} · ${tr(row.removable ? 'cleanup_unused' : 'cleanup_protected')}${row.reasons.map(reason => ' · ' + tr('protect_' + reason)).join('')}`);
258
+ add('previous-page', tr('previous_page'));
259
+ add('next-page', tr('next_page'));
260
+ }
129
261
  else {
130
- add('entry', tr('package.ui.entry', { value: status.entry ?? tr('task.unknown') }));
131
- add('config', tr('package.ui.config', { value: status.config_dir }));
132
- add('previous', tr('package.ui.previous', { value: status.previous ?? tr('task.unknown') }));
133
- add('observed-channel', tr('package.ui.channel', { value: status.channel ?? tr('task.unknown') }));
134
- add('runtime', `Node ${status.node_version} · Claude ${status.host ?? tr('task.unknown')}`);
135
- status.reasons.forEach(reason => add('reason:' + reason, t('package.reason_' + reason, language, {}, reason)));
136
- add('target', tr('package.ui.target', { value: view.editing === 'target' && view.input ? inputView(view.input, Math.max(2, width - 12)) : view.target || tr('package.ui.default_target') }));
137
- add('channel', tr('package.ui.channel', { value: view.channel ?? tr('package.ui.inherit') }));
138
- for (const action of ['check', 'update', 'rollback', 'recover-package'])
139
- add(action, 'Enter · ' + tr('package.ui.' + action), action);
140
- if (status.pending)
141
- add('pending', tr('package.ui.pending', { id: status.pending.id, stage: tr('package.ui.stage_' + status.pending.stage), running: status.pending.running ? tr('task.value.running') : tr('task.unknown') }));
142
- for (const record of status.history) {
143
- add('backup:' + record.id, `${record.id} · ${record.version ?? '—'} · ${tr('package.ui.stage_' + record.stage)} · ${tr('package.ui.backup_' + record.backup)}`, record.backup === 'verified' ? 'restore-config' : undefined, record.id);
262
+ add('notice', tr('local_notice'));
263
+ if (status)
264
+ add('current', tr('current', { value: status.current ?? t('task.unknown', language) }));
265
+ add('prefix', tr('prefix', { value: view.editing === 'prefix' && view.input ? inputView(view.input, Math.max(2, width - 12)) : view.prefix || t('task.unknown', language) }));
266
+ if (!status)
267
+ add('loading', t(view.busy ? 'profiles.loading' : 'task.unknown', language));
268
+ else {
269
+ add('entry', tr('entry', { value: status.entry ?? t('task.unknown', language) }));
270
+ add('config', tr('config', { value: status.config_dir }));
271
+ add('previous', tr('previous', { value: status.previous ?? t('task.unknown', language) }));
272
+ add('observed-channel', tr('channel', { value: status.channel ?? t('task.unknown', language) }));
273
+ add('runtime', `Node ${status.node_version} · Claude ${status.host ?? t('task.unknown', language)}`);
274
+ status.reasons.forEach(reason => add('reason:' + reason, t('package.reason_' + reason, language, {}, reason)));
275
+ if (!view.execution || view.execution.running === false) {
276
+ add('target', tr('target', { value: view.editing === 'target' && view.input ? inputView(view.input, Math.max(2, width - 12)) : view.target || tr('default_target') }));
277
+ add('channel', tr('channel', { value: view.channel ?? tr('inherit') }));
278
+ for (const action of ['check', 'update', 'rollback', 'recover-package'])
279
+ add(action, 'Enter · ' + tr(action), action);
280
+ add('cleanup-review', tr('cleanup_review'));
281
+ }
282
+ if (status.pending)
283
+ add('pending', tr('pending', { id: status.pending.id, stage: tr('stage_' + status.pending.stage), running: status.pending.running ? t('task.value.running', language) : t('task.unknown', language) }));
284
+ for (const record of status.history)
285
+ add('backup:' + record.id, `${record.id} · ${record.version ?? '—'} · ${tr('stage_' + record.stage)} · ${tr('backup_' + record.backup)}`, record.backup === 'verified' ? 'restore-config' : undefined, record.id);
286
+ if (status.total > 16) {
287
+ add('previous-page', tr('previous_page'));
288
+ add('next-page', tr('next_page'));
289
+ }
144
290
  }
145
- if (status.total > 16) {
146
- add('previous-page', tr('package.ui.previous_page'));
147
- add('next-page', tr('package.ui.next_page'));
291
+ if (view.job) {
292
+ const job = view.job;
293
+ add('job', tr('job', { id: job.id, state: tr('state_' + job.state) }));
294
+ if (job.error)
295
+ add('job-error', t('package.reason_' + job.error, language, {}, job.error));
296
+ if (job.review) {
297
+ const review = job.review;
298
+ add('verification', tr(review.action === 'restore-config' ? 'restore_review' : review.artifact_verified ? 'verified' : 'unverified'));
299
+ add('review-target', `${review.current ?? '—'} → ${review.target ?? '—'}`);
300
+ add('review-config', tr('config', { value: review.config_dir }));
301
+ if (review.registry)
302
+ add('registry', review.registry);
303
+ if (review.integrity)
304
+ add('integrity', review.integrity);
305
+ if (review.node_engine)
306
+ add('engine', 'Node ' + review.node_engine);
307
+ review.reasons.forEach(reason => add('review-reason:' + reason, t('package.reason_' + reason, language, {}, reason)));
308
+ review.configuration_conflicts.forEach(file => add('conflict:' + file, file));
309
+ review.files.forEach(file => add('restore:' + file, file));
310
+ if (verified(view))
311
+ add('execute', tr('execute'));
312
+ }
148
313
  }
149
- }
150
- const job = view.job;
151
- if (job) {
152
- add('job', tr('package.ui.job', { id: job.id, state: tr('package.ui.state_' + job.state) }));
153
- if (job.error)
154
- add('job-error', t('package.reason_' + job.error, language, {}, job.error));
155
- if (job.review) {
156
- const review = job.review;
157
- add('verification', tr(review.action === 'restore-config' ? 'package.ui.restore_review' : review.artifact_verified ? 'package.ui.verified' : 'package.ui.unverified'));
158
- add('review-target', `${review.current ?? '—'} → ${review.target ?? '—'}`);
159
- add('review-config', tr('package.ui.config', { value: review.config_dir }));
160
- if (review.registry)
161
- add('registry', review.registry);
162
- if (review.integrity)
163
- add('integrity', review.integrity);
164
- if (review.node_engine)
165
- add('engine', 'Node ' + review.node_engine);
166
- review.reasons.forEach(reason => add('review-reason:' + reason, t('package.reason_' + reason, language, {}, reason)));
167
- review.configuration_conflicts.forEach(file => add('conflict:' + file, file));
168
- review.files.forEach(file => add('restore:' + file, file));
314
+ if (view.execution) {
315
+ const run = view.execution;
316
+ add('execution', tr('execution', { id: run.transaction_id ?? run.id, state: tr('execution_state_' + run.state), stage: t('package.ui.stage_' + run.stage, language, {}, run.stage) }));
317
+ add('execution-results', tr('execution_results', { package: tr(run.results.package === null ? 'result_na' : run.results.package ? 'result_done' : 'result_pending'), integration: tr(run.results.integration === null ? 'result_na' : run.results.integration ? 'result_done' : 'result_pending'), configuration: tr(run.results.configuration === null ? 'result_na' : run.results.configuration ? 'result_done' : 'result_pending') }));
318
+ add('execution-control', tr('control', { executable: run.control.executable, entry: run.control.args[0] ?? '' }));
319
+ add('execution-control-help', tr('control_help', { directory: run.control.config_dir }));
320
+ if (run.error)
321
+ add('execution-error', t('package.reason_' + run.error, language, {}, run.error));
322
+ add('reload-required', tr('editor_locked'));
323
+ if (run.state === 'complete')
324
+ add('reopen', tr('reopen'));
169
325
  }
170
326
  }
327
+ if (view.input && view.editing === 'export_path')
328
+ add('export-path', tr('export_path', { value: inputView(view.input, Math.max(2, width - 16)) }));
171
329
  if (view.message)
172
330
  add('message', renderMessage(view.message, language));
173
331
  let index = rows.findIndex(row => row.key === view.selected);
@@ -194,42 +352,50 @@ export function packageKey(view, event) {
194
352
  view[field] = view.input.value;
195
353
  view.input = null;
196
354
  view.editing = null;
197
- if (field === 'prefix')
198
- view.status = null;
199
- if (field === 'target' && view.job) {
200
- view.effect = 'cancel';
355
+ if (field === 'export_path') {
356
+ view.effect = 'export-draft';
201
357
  return 'packages';
202
358
  }
203
359
  if (field === 'prefix') {
360
+ view.status = null;
204
361
  view.offset = 0;
205
362
  view.effect = 'load';
206
363
  return 'packages';
207
364
  }
365
+ if (field === 'target' && view.job) {
366
+ view.effect = 'cancel';
367
+ return 'packages';
368
+ }
208
369
  return null;
209
370
  }
210
- const result = inputKey(view.input.value, view.input, event, view.editing === 'prefix' ? 4096 : 100);
371
+ const result = inputKey(view.input.value, view.input, event, view.editing === 'target' ? 100 : 4096);
211
372
  view.input = result.state;
212
373
  if (result.error)
213
- view.message = text('input.' + result.error, { limit: view.editing === 'prefix' ? 4096 : 100 });
374
+ view.message = text('input.' + result.error, { limit: view.editing === 'target' ? 100 : 4096 });
214
375
  return null;
215
376
  }
216
377
  if (event.text || event.paste || event.meta)
217
378
  return null;
218
379
  if (cancel || !event.ctrl && key.toLowerCase() === 'q') {
380
+ if (view.mode !== 'status') {
381
+ view.mode = 'status';
382
+ view.draftPrepared = false;
383
+ return null;
384
+ }
219
385
  view.effect = 'close';
220
386
  return 'packages';
221
387
  }
222
388
  if (event.ctrl || view.busy)
223
389
  return null;
224
390
  if (key.toLowerCase() === 'r') {
225
- view.effect = view.job ? 'status' : 'load';
391
+ view.effect = view.mode === 'cleanup' ? 'cleanup-review' : view.execution || view.job ? 'status' : 'load';
226
392
  return 'packages';
227
393
  }
228
394
  if (key.toLowerCase() === 'l') {
229
395
  view.effect = 'load';
230
396
  return 'packages';
231
397
  }
232
- if (key.toLowerCase() === 'c' && view.job) {
398
+ if (key.toLowerCase() === 'c' && view.job && !view.execution) {
233
399
  view.effect = 'cancel';
234
400
  return 'packages';
235
401
  }
@@ -250,12 +416,62 @@ export function packageKey(view, event) {
250
416
  if (key !== 'enter')
251
417
  return null;
252
418
  const selectedKey = view.selected.replace(/:\d+$/u, '');
253
- if (selectedKey === 'prefix' || selectedKey === 'target') {
419
+ if (selectedKey === 'draft-cancel') {
420
+ view.mode = 'status';
421
+ view.draftPrepared = false;
422
+ return null;
423
+ }
424
+ if (selectedKey === 'draft-save') {
425
+ view.effect = 'save-draft';
426
+ return 'packages';
427
+ }
428
+ if (selectedKey === 'draft-reconcile') {
429
+ view.effect = 'reconcile-draft';
430
+ return 'packages';
431
+ }
432
+ if (selectedKey === 'draft-export') {
433
+ view.editing = 'export_path';
434
+ view.input = textInput(view.export_path);
435
+ return null;
436
+ }
437
+ if (selectedKey === 'draft-discard') {
438
+ view.effect = 'discard-draft';
439
+ return 'packages';
440
+ }
441
+ if (selectedKey === 'execute') {
442
+ view.draftPrepared = false;
443
+ view.effect = 'execute';
444
+ return 'packages';
445
+ }
446
+ if (selectedKey === 'execute-confirm') {
447
+ view.draftPrepared = true;
448
+ view.effect = 'execute';
449
+ return 'packages';
450
+ }
451
+ if (selectedKey === 'cleanup-review') {
452
+ view.offset = 0;
453
+ view.effect = 'cleanup-review';
454
+ return 'packages';
455
+ }
456
+ if (selectedKey === 'cleanup-confirm') {
457
+ view.effect = 'cleanup-apply';
458
+ return 'packages';
459
+ }
460
+ if (selectedKey.startsWith('cleanup:')) {
461
+ const row = view.cleanup?.rows.find(row => 'cleanup:' + row.id === selectedKey);
462
+ if (row?.removable) {
463
+ view.cleanupId = row.id;
464
+ view.mode = 'cleanup-confirm';
465
+ view.selected = 'cleanup-confirm';
466
+ }
467
+ return null;
468
+ }
469
+ if ((selectedKey === 'prefix' || selectedKey === 'target') && !view.execution) {
254
470
  view.editing = selectedKey;
255
- view.input = textInput(view[view.editing]);
471
+ view.input = textInput(view[selectedKey]);
256
472
  return null;
257
473
  }
258
- if (selectedKey === 'channel') {
474
+ if (selectedKey === 'channel' && !view.execution) {
259
475
  const channels = [null, 'latest', 'beta'];
260
476
  view.channel = channels[(channels.indexOf(view.channel) + 1) % 3];
261
477
  if (view.job) {
@@ -265,8 +481,9 @@ export function packageKey(view, event) {
265
481
  return null;
266
482
  }
267
483
  if (['next-page', 'previous-page'].includes(selectedKey)) {
268
- view.offset = Math.max(0, Math.min(view.offset + (selectedKey === 'next-page' ? 16 : -16), Math.max(0, Math.floor(((view.status?.total ?? 1) - 1) / 16) * 16)));
269
- view.effect = 'load';
484
+ const total = view.mode === 'cleanup' ? view.cleanup?.total : view.status?.total;
485
+ view.offset = Math.max(0, Math.min(view.offset + (selectedKey === 'next-page' ? 16 : -16), Math.max(0, Math.floor(((total ?? 1) - 1) / 16) * 16)));
486
+ view.effect = view.mode === 'cleanup' ? 'cleanup-review' : 'load';
270
487
  return 'packages';
271
488
  }
272
489
  const selected = view.rows.find(row => row.key === view.selected);