@fbincon/claude-code-statusline 3.10.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.
- package/README.md +79 -78
- package/candidate.json +325 -221
- package/node_modules/@fbincon/statusline-cli/dist/src/help.js +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/help.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.d.ts +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js +7 -3
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/configure.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.js +41 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-bootstrap.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.js +14 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/integration/editor-worker-entry.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/main.js +14 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/main.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.js +4 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/execution-worker-entry.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.d.ts +29 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.js +228 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/execution.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/history.d.ts +4 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/history.js +150 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/history.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.d.ts +8 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.js +164 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/inspection.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js +2 -2
- package/node_modules/@fbincon/statusline-cli/dist/src/management/mod-transition.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/management/restore.d.ts +14 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/management/restore.js +2 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/management/restore.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.d.ts +16 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.js +95 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review-jobs.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review-worker-entry.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review-worker-entry.js +33 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review-worker-entry.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review.d.ts +5 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review.js +44 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/review.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/service.d.ts +6 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js +19 -8
- package/node_modules/@fbincon/statusline-cli/dist/src/management/service.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js +6 -6
- package/node_modules/@fbincon/statusline-cli/dist/src/management/store.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js +6 -6
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic-state.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic.js +76 -28
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/automatic.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.d.ts +17 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.js +176 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/bindings.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js +11 -3
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js +26 -8
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.d.ts +3 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js +54 -14
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/tasks/command.d.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/tasks/command.js +11 -4
- package/node_modules/@fbincon/statusline-cli/dist/src/tasks/command.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/tasks/view.d.ts +3 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/tasks/view.js +25 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/tasks/view.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +3 -3
- package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +59 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/.claude-plugin/plugin.json +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/hooks/register.ts +92 -59
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/backend.ts +3 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +6 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/settings.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +6 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/package-manager.ts +187 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/package-validation.ts +52 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-manager.ts +53 -41
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-summary.ts +22 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-validation.ts +11 -2
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/task-viewer.ts +319 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +113 -5
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +7 -12392
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/en.ts +2220 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/ja.ts +2220 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/ko.ts +2220 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-CN.ts +2220 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-HK.ts +2220 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/locales/zh-TW.ts +2220 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +25 -15
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +3 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/help.ts +1 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/.claude-plugin/plugin.json +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/hooks/observe.ts +10 -3
- package/node_modules/@fbincon/statusline-cli/resources/statusline-runtime/resource-manifest.json +4 -4
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +169 -5
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js +2 -2
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js +5 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.d.ts +5 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +9 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.d.ts +49 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.js +498 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/package-manager.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.d.ts +3 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.js +53 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/package-validation.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.d.ts +9 -3
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js +74 -26
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.d.ts +5 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.js +25 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-summary.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.d.ts +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js +13 -2
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/task-viewer.d.ts +46 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/task-viewer.js +279 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/task-viewer.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.d.ts +2 -0
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js +15 -3
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +936 -12
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +942 -18
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/management/compatibility.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/release.d.ts +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/release.js +1 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +157 -3
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +157 -3
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +157 -3
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +157 -3
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +157 -3
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +157 -3
- package/node_modules/@fbincon/statusline-platform/dist/src/native.d.ts +2 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/native.js +2 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/native.js.map +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/npm.d.ts +2 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/npm.js +20 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/npm.js.map +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/private-state.d.ts +3 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/private-state.js +53 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/private-state.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/processes.d.ts +2 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/processes.js +45 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/processes.js.map +1 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/review-worker.d.ts +4 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/review-worker.js +22 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/review-worker.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.d.ts +5 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js +8 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/terminal/windows-modes.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js +10 -0
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/presentation.js +4 -0
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/presentation.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js +4 -0
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/shortcuts.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing.js +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/session.d.ts +5 -3
- package/node_modules/@fbincon/statusline-tui/dist/src/session.js +31 -8
- package/node_modules/@fbincon/statusline-tui/dist/src/session.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/state.d.ts +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/state.js +24 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/task-viewer.d.ts +6 -0
- package/node_modules/@fbincon/statusline-tui/dist/src/task-viewer.js +34 -0
- package/node_modules/@fbincon/statusline-tui/dist/src/task-viewer.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// Generated by tools/generation/resources.ts; do not edit.
|
|
2
|
+
import type { PackageStatus, PackageReviewJob, PackageReviewRequest, PackageExecution, PackageCleanupReview, PackageControl, Operation, ResultFor } from '../generated-contracts.ts';
|
|
3
|
+
import type { Editor } from './draft.ts';
|
|
4
|
+
import { closeSourceDraft } from './source-manager.ts';
|
|
5
|
+
import { t, text, renderMessage, type Language, type LocalizedText } from '../i18n/index.ts';
|
|
6
|
+
import { inputKey, inputView, textInput, type TextInput, type TextKey } from './text-input.ts';
|
|
7
|
+
import { wrapText } from '../../ui/text.ts';
|
|
8
|
+
import { BackendError } from '../backend.ts';
|
|
9
|
+
interface Row { key:string; text:string; action?:PackageReviewRequest['action']; backup?:string; selected?:boolean }
|
|
10
|
+
export interface PackageManager {
|
|
11
|
+
owner:string;status:PackageStatus|null;job:PackageReviewJob|null;execution:PackageExecution|null;cleanup:PackageCleanupReview|null;
|
|
12
|
+
prefix:string;target:string;channel:'latest'|'beta'|null;offset:number;selected:string;scroll:number;rows:Row[];capacity:number;
|
|
13
|
+
input:TextInput|null;editing:'prefix'|'target'|'export_path'|null;export_path:string;
|
|
14
|
+
message:LocalizedText|string|null;
|
|
15
|
+
effect:'load'|'start'|'status'|'cancel'|'close'|'execute'|'save-draft'|'discard-draft'|'export-draft'|'reconcile-draft'|'cleanup-review'|'cleanup-apply'|null;
|
|
16
|
+
mode:'status'|'draft'|'execute-confirm'|'cleanup'|'cleanup-confirm';cleanupId:string|null;draftPrepared:boolean;
|
|
17
|
+
action:PackageReviewRequest['action'];backup:string|null;busy:boolean;closed:boolean;generation:number;
|
|
18
|
+
}
|
|
19
|
+
export function packageManager():PackageManager {
|
|
20
|
+
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};
|
|
21
|
+
}
|
|
22
|
+
export interface PackageBackend {
|
|
23
|
+
request<O extends Operation>(operation:O,payload?:unknown):ResultFor<O>|Promise<ResultFor<O>>;
|
|
24
|
+
control?<O extends Operation>(control:PackageControl,operation:O,payload?:unknown):ResultFor<O>|Promise<ResultFor<O>>;
|
|
25
|
+
}
|
|
26
|
+
function request<O extends Operation>(view:PackageManager,backend:PackageBackend,operation:O,payload:unknown):ResultFor<O>|Promise<ResultFor<O>> {
|
|
27
|
+
return view.execution&&backend.control?backend.control(view.execution.control,operation,payload):backend.request(operation,payload);
|
|
28
|
+
}
|
|
29
|
+
export async function closePackage(view:PackageManager,backend:PackageBackend):Promise<void>{
|
|
30
|
+
view.closed=true;view.generation++;
|
|
31
|
+
if(view.execution)try{await request(view,backend,'package_execute_detach',{id:view.execution.id,owner:view.owner});}catch{/* Detach never cancels an executor. */}
|
|
32
|
+
if(view.job)try{await request(view,backend,'package_review_cancel',{id:view.job.id,owner:view.owner});}catch{/* Review deadlines still bound disconnected views. */}
|
|
33
|
+
}
|
|
34
|
+
function verified(view:PackageManager):boolean {
|
|
35
|
+
const job=view.job,review=job?.review;
|
|
36
|
+
return job?.state==='complete'&&!!review?.compatible&&job.request.action!=='check'&&(review.artifact_verified||job.request.action==='restore-config');
|
|
37
|
+
}
|
|
38
|
+
export async function performPackage(view:PackageManager,backend:PackageBackend,editor?:Editor):Promise<void>{
|
|
39
|
+
const effect=view.effect;if(!effect||view.busy)return;view.effect=null;
|
|
40
|
+
if(effect==='close'){await closePackage(view,backend);return;}
|
|
41
|
+
view.busy=true;const generation=view.generation;
|
|
42
|
+
try{
|
|
43
|
+
if(effect==='load'){
|
|
44
|
+
if(view.job&&view.prefix&&view.job.request.prefix!==view.prefix){
|
|
45
|
+
const cancelled=await request(view,backend,'package_review_cancel',{id:view.job.id,owner:view.owner});
|
|
46
|
+
if(view.closed||generation!==view.generation)return;
|
|
47
|
+
if(cancelled.state!=='cancelled'){view.job=cancelled;view.message=text('package.ui.cancel_requested');view.selected='message';return;}view.job=null;
|
|
48
|
+
}
|
|
49
|
+
const status=await request(view,backend,'package_status',{prefix:view.prefix||null,offset:view.offset});
|
|
50
|
+
if(view.closed||generation!==view.generation)return;
|
|
51
|
+
if(view.job&&status.revision!==view.job.request.expected_revision){view.job={...view.job,state:'failed',review:null,error:'conflict'};view.message=text('package.ui.changed');view.selected='message';}
|
|
52
|
+
view.status=status;view.prefix=status.prefix??view.prefix;
|
|
53
|
+
if(status.execution){view.execution=status.execution;if(editor)editor.packageLocked=true;view.selected='execution';}
|
|
54
|
+
}else if(effect==='start'){
|
|
55
|
+
if(!view.status?.prefix)throw new BackendError('prefix',text('package.reason_prefix'));
|
|
56
|
+
if(view.job?.state==='running'||view.execution?.running!==false&&view.execution?.state==='running')return;
|
|
57
|
+
const previous=view.job;
|
|
58
|
+
let target=view.action==='recover-package'?view.status.pending?.version??view.target:view.target||null,integrity:string|null=null;
|
|
59
|
+
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)){target=previous.review.target;integrity=previous.review.integrity;}
|
|
60
|
+
const reviewRequest:PackageReviewRequest={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};
|
|
61
|
+
if(previous){const cancelled=await request(view,backend,'package_review_cancel',{id:previous.id,owner:view.owner});if(view.closed||generation!==view.generation)return;if(cancelled.state!=='cancelled'){view.job=cancelled;view.message=text('package.ui.cancel_requested');view.selected='message';return;}view.job=null;}
|
|
62
|
+
const job=await request(view,backend,'package_review_start',{request:reviewRequest,owner:view.owner});
|
|
63
|
+
if(view.closed||generation!==view.generation){await request(view,backend,'package_review_cancel',{id:job.id,owner:view.owner});return;}
|
|
64
|
+
view.job=job;view.mode='status';view.draftPrepared=false;view.message=null;view.selected='job';
|
|
65
|
+
}else if(effect==='execute'){
|
|
66
|
+
if(!editor||!verified(view))throw new BackendError('integrity',text('package.reason_integrity'));
|
|
67
|
+
if(editor.saveState!=='idle'){view.mode='draft';view.message=text('editor.save_unknown');return;}
|
|
68
|
+
if(!view.draftPrepared){
|
|
69
|
+
if(!editor.acceptNumeric()){view.message=text('package.ui.draft_required');return;}
|
|
70
|
+
view.mode=editor.modified?'draft':'execute-confirm';view.selected=editor.modified?'draft-cancel':'execute-confirm';return;
|
|
71
|
+
}
|
|
72
|
+
editor.packageLocked=true;
|
|
73
|
+
const execution=await request(view,backend,'package_execute_start',{id:view.job!.id,owner:view.owner});
|
|
74
|
+
view.execution=execution;view.mode='status';view.selected='execution';view.message=text('package.ui.editor_locked');
|
|
75
|
+
await closeSourceDraft(editor,{request:(operation,payload)=>request(view,backend,operation,payload)});
|
|
76
|
+
if(view.closed||generation!==view.generation)await request(view,backend,'package_execute_detach',{id:execution.id,owner:view.owner});
|
|
77
|
+
}else if(effect==='discard-draft'){
|
|
78
|
+
if(!editor||editor.saveState!=='idle')throw new BackendError('configuration_conflict',text('editor.save_locked'));
|
|
79
|
+
editor.replaceDraft(editor.baseline.draft);view.draftPrepared=true;view.mode='execute-confirm';view.selected='execute-confirm';
|
|
80
|
+
}else if(effect==='save-draft'){
|
|
81
|
+
if(!editor||editor.saveState!=='idle')throw new BackendError('configuration_conflict',text('editor.save_locked'));
|
|
82
|
+
if(!editor.acceptNumeric()){view.message=text('package.ui.draft_required');return;}
|
|
83
|
+
const submitted=editor.beginSave();
|
|
84
|
+
try{const saved=await backend.request('apply',{draft:submitted.draft,expected_revision:submitted.revision,...(submitted.target?{target:submitted.target}:{})});editor.committed(saved);}catch(error){editor.saveFailed(error instanceof BackendError?error.code:'');throw error;}
|
|
85
|
+
view.mode='status';view.job=null;view.status=null;view.effect='load';view.message=text('package.ui.review_again');
|
|
86
|
+
}else if(effect==='export-draft'){
|
|
87
|
+
if(!editor||editor.saveState!=='idle')throw new BackendError('configuration_conflict',text('editor.save_locked'));
|
|
88
|
+
await backend.request('export',{draft:editor.draft,path:view.export_path,overwrite:false});view.draftPrepared=true;view.mode='execute-confirm';view.selected='execute-confirm';view.message=text('package.ui.exported');
|
|
89
|
+
}else if(effect==='reconcile-draft'){
|
|
90
|
+
if(!editor?.pendingSave)return;
|
|
91
|
+
const pending=editor.pendingSave;editor.setSaveState('pending');
|
|
92
|
+
try{const current=await backend.request('read',pending.target?{target:pending.target}:{});const result=editor.reconcileSave(current);view.message=text('editor.'+result);view.mode='status';view.job=null;view.status=null;view.effect='load';}catch(error){editor.setSaveState('unknown');throw error;}
|
|
93
|
+
}else if(effect==='cleanup-review'){
|
|
94
|
+
if(!view.prefix)throw new BackendError('prefix',text('package.reason_prefix'));
|
|
95
|
+
view.cleanup=await request(view,backend,'package_cleanup_review',{prefix:view.prefix,offset:view.offset});view.mode='cleanup';view.selected=view.cleanup.rows[0]?'cleanup:'+view.cleanup.rows[0].id:'cleanup-message';
|
|
96
|
+
}else if(effect==='cleanup-apply'){
|
|
97
|
+
view.cleanup=await request(view,backend,'package_cleanup_apply',{prefix:view.prefix,revision:view.cleanup!.revision,ids:[view.cleanupId]});view.mode='cleanup';view.selected='cleanup-message';view.message=text('package.ui.cleaned');
|
|
98
|
+
}else if(effect==='status'&&view.execution){
|
|
99
|
+
view.execution=await request(view,backend,'package_execute_status',{id:view.execution.id});view.selected='execution';
|
|
100
|
+
}else if(view.job){
|
|
101
|
+
const job=await request(view,backend,effect==='cancel'?'package_review_cancel':'package_review_status',{id:view.job.id,owner:view.owner});
|
|
102
|
+
if(view.closed||generation!==view.generation)return;
|
|
103
|
+
const cancelled=effect==='cancel'&&job.state==='cancelled';view.job=cancelled?null:job;view.message=effect==='cancel'?text(cancelled?'package.cancelled':'package.ui.cancel_requested'):null;
|
|
104
|
+
view.selected=effect==='cancel'?'message':job.review?'verification':job.error?'job-error':'job';
|
|
105
|
+
}
|
|
106
|
+
}catch(error){
|
|
107
|
+
if(effect==='execute'&&editor&&!view.execution&&error instanceof BackendError&&['arguments','conflict','integrity','identity','busy','development','permission','configuration','journal'].includes(error.code))editor.packageLocked=false;
|
|
108
|
+
if(!view.closed&&generation===view.generation){view.message=error instanceof BackendError&&error.localization?error.localization:text('package.reason_io_error');view.selected='message';}
|
|
109
|
+
}finally{if(generation===view.generation)view.busy=false;}
|
|
110
|
+
}
|
|
111
|
+
export function packageView(view:PackageManager,language:Language,width:number,height:number):Row[]{
|
|
112
|
+
const tr=(key:string,params:Record<string,unknown>={})=>t('package.ui.'+key,language,params),rows:Row[]=[];
|
|
113
|
+
const add=(key:string,value:string,action?:Row['action'],backup?:string)=>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}:{})}));
|
|
114
|
+
const status=view.status;
|
|
115
|
+
if(view.mode==='draft'){
|
|
116
|
+
add('notice',tr('draft_required'));add('draft-save',tr('draft_save'));add('draft-export',tr('draft_export'));add('draft-discard',tr('draft_discard'));add('draft-cancel',tr('draft_cancel'));add('draft-reconcile',tr('draft_reconcile'));
|
|
117
|
+
}else if(view.mode==='execute-confirm'){
|
|
118
|
+
add('notice',tr('execute_notice'));add('execute-confirm',tr('execute_confirm'));add('draft-cancel',tr('draft_cancel'));
|
|
119
|
+
}else if(view.mode==='cleanup'||view.mode==='cleanup-confirm'){
|
|
120
|
+
add('cleanup-message',tr(view.cleanup?.uncertain?'cleanup_uncertain':'cleanup_notice'));
|
|
121
|
+
if(view.mode==='cleanup-confirm'){add('cleanup-confirm',tr('cleanup_confirm'));add('cleanup-selected',view.cleanupId??'');}
|
|
122
|
+
else for(const row of view.cleanup?.rows??[])add('cleanup:'+row.id,`${row.id} · ${row.version??'—'} · ${tr(row.removable?'cleanup_unused':'cleanup_protected')}${row.reasons.map(reason=>' · '+tr('protect_'+reason)).join('')}`);
|
|
123
|
+
add('previous-page',tr('previous_page'));add('next-page',tr('next_page'));
|
|
124
|
+
}else{
|
|
125
|
+
add('notice',tr('local_notice'));if(status)add('current',tr('current',{value:status.current??t('task.unknown',language)}));
|
|
126
|
+
add('prefix',tr('prefix',{value:view.editing==='prefix'&&view.input?inputView(view.input,Math.max(2,width-12)):view.prefix||t('task.unknown',language)}));
|
|
127
|
+
if(!status)add('loading',t(view.busy?'profiles.loading':'task.unknown',language));
|
|
128
|
+
else{
|
|
129
|
+
add('entry',tr('entry',{value:status.entry??t('task.unknown',language)}));add('config',tr('config',{value:status.config_dir}));add('previous',tr('previous',{value:status.previous??t('task.unknown',language)}));add('observed-channel',tr('channel',{value:status.channel??t('task.unknown',language)}));add('runtime',`Node ${status.node_version} · Claude ${status.host??t('task.unknown',language)}`);
|
|
130
|
+
status.reasons.forEach(reason=>add('reason:'+reason,t('package.reason_'+reason,language,{},reason)));
|
|
131
|
+
if(!view.execution||view.execution.running===false){
|
|
132
|
+
add('target',tr('target',{value:view.editing==='target'&&view.input?inputView(view.input,Math.max(2,width-12)):view.target||tr('default_target')}));add('channel',tr('channel',{value:view.channel??tr('inherit')}));
|
|
133
|
+
for(const action of ['check','update','rollback','recover-package'] as const)add(action,'Enter · '+tr(action),action);
|
|
134
|
+
add('cleanup-review',tr('cleanup_review'));
|
|
135
|
+
}
|
|
136
|
+
if(status.pending)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)}));
|
|
137
|
+
for(const record of status.history)add('backup:'+record.id,`${record.id} · ${record.version??'—'} · ${tr('stage_'+record.stage)} · ${tr('backup_'+record.backup)}`,record.backup==='verified'?'restore-config':undefined,record.id);
|
|
138
|
+
if(status.total>16){add('previous-page',tr('previous_page'));add('next-page',tr('next_page'));}
|
|
139
|
+
}
|
|
140
|
+
if(view.job){const job=view.job;add('job',tr('job',{id:job.id,state:tr('state_'+job.state)}));if(job.error)add('job-error',t('package.reason_'+job.error,language,{},job.error));
|
|
141
|
+
if(job.review){const review=job.review;add('verification',tr(review.action==='restore-config'?'restore_review':review.artifact_verified?'verified':'unverified'));add('review-target',`${review.current??'—'} → ${review.target??'—'}`);add('review-config',tr('config',{value:review.config_dir}));if(review.registry)add('registry',review.registry);if(review.integrity)add('integrity',review.integrity);if(review.node_engine)add('engine','Node '+review.node_engine);review.reasons.forEach(reason=>add('review-reason:'+reason,t('package.reason_'+reason,language,{},reason)));review.configuration_conflicts.forEach(file=>add('conflict:'+file,file));review.files.forEach(file=>add('restore:'+file,file));if(verified(view))add('execute',tr('execute'));}
|
|
142
|
+
}
|
|
143
|
+
if(view.execution){const run=view.execution;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)}));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')}));add('execution-control',tr('control',{executable:run.control.executable,entry:run.control.args[0]??''}));add('execution-control-help',tr('control_help',{directory:run.control.config_dir}));if(run.error)add('execution-error',t('package.reason_'+run.error,language,{},run.error));add('reload-required',tr('editor_locked'));if(run.state==='complete')add('reopen',tr('reopen'));}
|
|
144
|
+
}
|
|
145
|
+
if(view.input&&view.editing==='export_path')add('export-path',tr('export_path',{value:inputView(view.input,Math.max(2,width-16))}));
|
|
146
|
+
if(view.message)add('message',renderMessage(view.message,language));
|
|
147
|
+
let index=rows.findIndex(row=>row.key===view.selected);if(index<0)index=0;view.rows=rows;view.selected=rows[index]?.key??'';view.capacity=Math.max(1,height);view.scroll=Math.max(0,Math.min(view.scroll,index,Math.max(0,rows.length-view.capacity)));if(index>=view.scroll+view.capacity)view.scroll=index-view.capacity+1;
|
|
148
|
+
return rows.slice(view.scroll,view.scroll+view.capacity).map(row=>({...row,text:(row.key===view.selected?'› ':' ')+row.text,selected:row.key===view.selected}));
|
|
149
|
+
}
|
|
150
|
+
export function packageKey(view:PackageManager,event:TextKey):'packages'|null{
|
|
151
|
+
const key=event.key==='return'?'enter':event.key,cancel=!event.text&&!event.paste&&(key==='escape'||event.ctrl&&key.toLowerCase()==='g');
|
|
152
|
+
if(view.input&&view.editing){
|
|
153
|
+
if(cancel){view.input=null;view.editing=null;return null;}
|
|
154
|
+
if(!event.text&&!event.paste&&key==='enter'){
|
|
155
|
+
const field=view.editing;view[field]=view.input.value;view.input=null;view.editing=null;
|
|
156
|
+
if(field==='export_path'){view.effect='export-draft';return 'packages';}
|
|
157
|
+
if(field==='prefix'){view.status=null;view.offset=0;view.effect='load';return 'packages';}
|
|
158
|
+
if(field==='target'&&view.job){view.effect='cancel';return 'packages';}return null;
|
|
159
|
+
}
|
|
160
|
+
const result=inputKey(view.input.value,view.input,event,view.editing==='target'?100:4096);view.input=result.state;if(result.error)view.message=text('input.'+result.error,{limit:view.editing==='target'?100:4096});return null;
|
|
161
|
+
}
|
|
162
|
+
if(event.text||event.paste||event.meta)return null;
|
|
163
|
+
if(cancel||!event.ctrl&&key.toLowerCase()==='q'){
|
|
164
|
+
if(view.mode!=='status'){view.mode='status';view.draftPrepared=false;return null;}
|
|
165
|
+
view.effect='close';return 'packages';
|
|
166
|
+
}
|
|
167
|
+
if(event.ctrl||view.busy)return null;
|
|
168
|
+
if(key.toLowerCase()==='r'){view.effect=view.mode==='cleanup'?'cleanup-review':view.execution||view.job?'status':'load';return 'packages';}
|
|
169
|
+
if(key.toLowerCase()==='l'){view.effect='load';return 'packages';}
|
|
170
|
+
if(key.toLowerCase()==='c'&&view.job&&!view.execution){view.effect='cancel';return 'packages';}
|
|
171
|
+
let index=Math.max(0,view.rows.findIndex(row=>row.key===view.selected));if(key==='up')index--;if(key==='down')index++;if(key==='pageup')index-=view.capacity;if(key==='pagedown')index+=view.capacity;if(key==='home')index=0;if(key==='end')index=view.rows.length-1;view.selected=view.rows[Math.max(0,Math.min(index,view.rows.length-1))]?.key??'';
|
|
172
|
+
if(key!=='enter')return null;const selectedKey=view.selected.replace(/:\d+$/u,'');
|
|
173
|
+
if(selectedKey==='draft-cancel'){view.mode='status';view.draftPrepared=false;return null;}
|
|
174
|
+
if(selectedKey==='draft-save'){view.effect='save-draft';return 'packages';}
|
|
175
|
+
if(selectedKey==='draft-reconcile'){view.effect='reconcile-draft';return 'packages';}
|
|
176
|
+
if(selectedKey==='draft-export'){view.editing='export_path';view.input=textInput(view.export_path);return null;}
|
|
177
|
+
if(selectedKey==='draft-discard'){view.effect='discard-draft';return 'packages';}
|
|
178
|
+
if(selectedKey==='execute'){view.draftPrepared=false;view.effect='execute';return 'packages';}
|
|
179
|
+
if(selectedKey==='execute-confirm'){view.draftPrepared=true;view.effect='execute';return 'packages';}
|
|
180
|
+
if(selectedKey==='cleanup-review'){view.offset=0;view.effect='cleanup-review';return 'packages';}
|
|
181
|
+
if(selectedKey==='cleanup-confirm'){view.effect='cleanup-apply';return 'packages';}
|
|
182
|
+
if(selectedKey.startsWith('cleanup:')){const row=view.cleanup?.rows.find(row=>'cleanup:'+row.id===selectedKey);if(row?.removable){view.cleanupId=row.id;view.mode='cleanup-confirm';view.selected='cleanup-confirm';}return null;}
|
|
183
|
+
if((selectedKey==='prefix'||selectedKey==='target')&&!view.execution){view.editing=selectedKey;view.input=textInput(view[selectedKey]);return null;}
|
|
184
|
+
if(selectedKey==='channel'&&!view.execution){const channels=[null,'latest','beta']as const;view.channel=channels[(channels.indexOf(view.channel)+1)%3]!;if(view.job){view.effect='cancel';return 'packages';}return null;}
|
|
185
|
+
if(['next-page','previous-page'].includes(selectedKey)){const total=view.mode==='cleanup'?view.cleanup?.total:view.status?.total;view.offset=Math.max(0,Math.min(view.offset+(selectedKey==='next-page'?16:-16),Math.max(0,Math.floor(((total??1)-1)/16)*16)));view.effect=view.mode==='cleanup'?'cleanup-review':'load';return 'packages';}
|
|
186
|
+
const selected=view.rows.find(row=>row.key===view.selected);if(selected?.action){view.action=selected.action;view.backup=selected.backup??null;view.effect='start';return 'packages';}return null;
|
|
187
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Generated by tools/generation/resources.ts; do not edit.
|
|
2
|
+
import type { PackageReviewRequest } from '../generated-contracts.ts';
|
|
3
|
+
const object = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
4
|
+
const string = (value: unknown): value is string => typeof value === 'string' && value.length <= 8192 && !/[\p{Cc}\p{Cs}]/u.test(value);
|
|
5
|
+
const nullable = (value: unknown) => value === null || string(value);
|
|
6
|
+
const exact = (value: Record<string, unknown>, keys: string[]) => Object.keys(value).sort().join(',') === keys.sort().join(',');
|
|
7
|
+
const strings = (value: unknown) => Array.isArray(value) && value.length <= 128 && value.every(string);
|
|
8
|
+
const channel = (value: unknown) => value === null || value === 'latest' || value === 'beta';
|
|
9
|
+
export function isPackageRequest(value: unknown): value is PackageReviewRequest {
|
|
10
|
+
return object(value) && exact(value, ['action', 'prefix', 'expected_revision', 'target', 'channel', 'backup_id', 'expected_integrity']) &&
|
|
11
|
+
['check', 'update', 'rollback', 'recover-package', 'restore-config'].includes(String(value.action)) && string(value.prefix) && !!value.prefix &&
|
|
12
|
+
typeof value.expected_revision === 'string' && /^[0-9a-f]{64}$/u.test(value.expected_revision) && nullable(value.target) &&
|
|
13
|
+
(value.target === null || /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/u.test(String(value.target))) && channel(value.channel) &&
|
|
14
|
+
nullable(value.backup_id) && (value.backup_id === null || /^pkg-[0-9a-f-]{36}$/u.test(String(value.backup_id))) &&
|
|
15
|
+
nullable(value.expected_integrity) && (value.expected_integrity === null || /^sha512-[A-Za-z0-9+/]{86}==$/u.test(String(value.expected_integrity))) &&
|
|
16
|
+
!(value.target && value.channel) &&
|
|
17
|
+
(value.action !== 'restore-config' || !!value.backup_id && value.target === null && value.channel === null) &&
|
|
18
|
+
(['check', 'update'].includes(String(value.action)) || value.channel === null);
|
|
19
|
+
}
|
|
20
|
+
function history(value: unknown): boolean {
|
|
21
|
+
return object(value) && exact(value, ['id', 'version', 'created', 'stage', 'backup', 'running']) && string(value.id) && nullable(value.version) &&
|
|
22
|
+
nullable(value.created) && string(value.stage) && ['verified', 'missing', 'invalid'].includes(String(value.backup)) && typeof value.running === 'boolean';
|
|
23
|
+
}
|
|
24
|
+
function review(value: unknown): boolean {
|
|
25
|
+
return object(value) && exact(value, ['action', 'current', 'target', 'prefix', 'entry', 'config_dir', 'channel', 'registry', 'integrity', 'node_engine', 'host', 'artifact_verified', 'compatible', 'reasons', 'configuration_conflicts', 'backup_id', 'files']) &&
|
|
26
|
+
['check', 'update', 'rollback', 'recover-package', 'restore-config'].includes(String(value.action)) &&
|
|
27
|
+
['current', 'target', 'entry', 'registry', 'integrity', 'node_engine', 'host', 'backup_id'].every(key => nullable(value[key])) &&
|
|
28
|
+
string(value.prefix) && string(value.config_dir) && channel(value.channel) && typeof value.artifact_verified === 'boolean' && typeof value.compatible === 'boolean' &&
|
|
29
|
+
strings(value.reasons) && strings(value.configuration_conflicts) && strings(value.files);
|
|
30
|
+
}
|
|
31
|
+
function execution(value:unknown):boolean {
|
|
32
|
+
return object(value)&&exact(value,['version','id','transaction_id','action','prefix','state','stage','started_at','updated_at','finished_at','error','running','results','control'])&&value.version===1&&string(value.id)&&/^execution-[0-9a-f-]{36}$/u.test(value.id)&&nullable(value.transaction_id)&&['check','update','rollback','recover-package','restore-config'].includes(String(value.action))&&string(value.prefix)&&['running','complete','failed','interrupted'].includes(String(value.state))&&['stage','started_at','updated_at'].every(k=>string(value[k]))&&nullable(value.finished_at)&&nullable(value.error)&&(value.running===null||typeof value.running==='boolean')&&object(value.results)&&exact(value.results,['package','integration','configuration'])&&Object.values(value.results).every(v=>v===null||typeof v==='boolean')&&object(value.control)&&exact(value.control,['executable','args','config_dir'])&&string(value.control.executable)&&string(value.control.config_dir)&&Array.isArray(value.control.args)&&value.control.args.length===1&&value.control.args.every(string);
|
|
33
|
+
}
|
|
34
|
+
function cleanup(value:Record<string,unknown>):boolean {
|
|
35
|
+
return exact(value,['version','revision','prefix','offset','total','uncertain','rows'])&&value.version===1&&string(value.revision)&&/^[a-f0-9]{64}$/u.test(value.revision)&&string(value.prefix)&&Number.isSafeInteger(value.offset)&&Number(value.offset)>=0&&Number.isSafeInteger(value.total)&&Number(value.total)>=0&&typeof value.uncertain==='boolean'&&Array.isArray(value.rows)&&value.rows.length<=16&&value.rows.every(row=>object(row)&&exact(row,['id','removable','reasons','version'])&&string(row.id)&&typeof row.removable==='boolean'&&strings(row.reasons)&&nullable(row.version));
|
|
36
|
+
}
|
|
37
|
+
export function isPackageResult(operation: string, value: unknown): boolean {
|
|
38
|
+
if (!object(value) || value.version !== 1)
|
|
39
|
+
return false;
|
|
40
|
+
if(operation.startsWith('package_execute_'))return execution(value);
|
|
41
|
+
if(operation.startsWith('package_cleanup_'))return cleanup(value);
|
|
42
|
+
if (operation === 'package_status')
|
|
43
|
+
return exact(value, ['version', ...(Object.hasOwn(value,'execution')?['execution']:[]), 'backend_version', 'captured_at', 'revision', 'prefix', 'entry', 'config_dir', 'current', 'previous', 'channel', 'node_version', 'host', 'compatible', 'reasons', 'pending', 'history', 'offset', 'total']) &&
|
|
44
|
+
(value.execution===undefined||value.execution===null||execution(value.execution))&&
|
|
45
|
+
['backend_version', 'captured_at', 'revision', 'config_dir', 'node_version'].every(key => string(value[key])) && /^[0-9a-f]{64}$/u.test(String(value.revision)) &&
|
|
46
|
+
['prefix', 'entry', 'current', 'previous', 'host'].every(key => nullable(value[key])) && channel(value.channel) && typeof value.compatible === 'boolean' && strings(value.reasons) &&
|
|
47
|
+
(value.pending === null || history(value.pending)) && Array.isArray(value.history) && value.history.length <= 16 && value.history.every(history) &&
|
|
48
|
+
Number.isSafeInteger(value.offset) && Number(value.offset) >= 0 && Number.isSafeInteger(value.total) && Number(value.total) >= 0;
|
|
49
|
+
return exact(value, ['version', 'id', 'owner', 'state', 'started_at', 'finished_at', 'request', 'review', 'error']) &&
|
|
50
|
+
['id', 'owner', 'started_at'].every(key => string(value[key])) && ['running', 'complete', 'failed', 'cancelled'].includes(String(value.state)) &&
|
|
51
|
+
nullable(value.finished_at) && nullable(value.error) && isPackageRequest(value.request) && (value.review === null || review(value.review));
|
|
52
|
+
}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
// Generated by tools/generation/resources.ts; do not edit.
|
|
2
|
-
import
|
|
2
|
+
import { sourceSummary, sourceReviewLines } from './source-summary.ts';
|
|
3
|
+
import type { Operation, ResultFor, SourcesResult, SourceDefinition, SourceContext, SourceJob, SourceReview, SourceInspection, BindingReview, Scope } from '../generated-contracts.ts';
|
|
3
4
|
import type { Editor } from './draft.ts';
|
|
4
5
|
import { t, text, type Language, type LocalizedText } from '../i18n/index.ts';
|
|
5
6
|
import { inputKey, inputView, textInput, type TextInput, type TextKey } from './text-input.ts';
|
|
6
7
|
import { wrapText } from '../../ui/text.ts';
|
|
7
8
|
import { BackendError } from '../backend.ts';
|
|
8
|
-
type Action = 'edit' | 'review' | 'disable' | 'remove' | 'bind' | 'unbind' | 'refresh' | 'status' | 'cancel' | 'diagnose' | 'auto-review' | 'auto-off';
|
|
9
|
+
type Action = 'edit' | 'review' | 'disable' | 'remove' | 'bind' | 'unbind' | 'refresh' | 'status' | 'cancel' | 'diagnose' | 'auto-review' | 'auto-off' | 'checks' | 'raw';
|
|
9
10
|
export interface SourceManager {
|
|
10
11
|
library: SourcesResult | null;
|
|
11
12
|
context: SourceContext | null;
|
|
12
13
|
owner: string;
|
|
13
14
|
closed: boolean;
|
|
14
|
-
page: 'list' | 'actions' | 'kind' | 'form' | 'review' | 'remove' | 'bind' | 'unbind' | 'diagnose' | 'auto-review';
|
|
15
|
+
page: 'list' | 'actions' | 'kind' | 'form' | 'review' | 'remove' | 'bind' | 'unbind' | 'diagnose' | 'auto-review' | 'checks' | 'bindings' | 'binding-cleanup';
|
|
16
|
+
inspection: SourceInspection | null;
|
|
17
|
+
bindingReview: BindingReview | null;
|
|
18
|
+
bindingSelection: string | null;
|
|
19
|
+
offset: number;
|
|
15
20
|
automaticInterval: number;
|
|
16
21
|
cursor: number;
|
|
17
22
|
scroll: number;
|
|
@@ -26,7 +31,7 @@ export interface SourceManager {
|
|
|
26
31
|
details: string[];
|
|
27
32
|
jobs: SourceJob[];
|
|
28
33
|
message: LocalizedText | null;
|
|
29
|
-
effect: 'load' | 'save' | 'review' | 'enable' | 'disable' | 'remove' | 'bind' | 'refresh' | 'status' | 'cancel' | 'diagnose' | 'close' | 'auto-review' | 'auto-on' | 'auto-off' | null;
|
|
34
|
+
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
35
|
target: {
|
|
31
36
|
scope: Scope;
|
|
32
37
|
id: string;
|
|
@@ -37,10 +42,10 @@ export interface SourceBackend {
|
|
|
37
42
|
}
|
|
38
43
|
const external = ['external-value', 'github-pr', 'github-ci'];
|
|
39
44
|
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 };
|
|
45
|
+
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
46
|
}
|
|
42
47
|
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
|
|
48
|
+
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
49
|
function targets(editor: Editor) {
|
|
45
50
|
const s = source(editor);
|
|
46
51
|
return (['main', 'subagent'] as const).flatMap(scope => (scope === 'main' ? editor.draft.display.instances : editor.draft.display.subagents.instances)
|
|
@@ -62,7 +67,7 @@ function form(editor: Editor, kind: SourceDefinition['kind'], editing = false):
|
|
|
62
67
|
}
|
|
63
68
|
function count(editor: Editor): number {
|
|
64
69
|
const m = editor.sources!;
|
|
65
|
-
return m.page === 'list' ? (m.library?.sources.length ?? 0) +
|
|
70
|
+
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
71
|
}
|
|
67
72
|
export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
|
|
68
73
|
const m = editor.sources;
|
|
@@ -101,10 +106,14 @@ export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
|
|
|
101
106
|
}
|
|
102
107
|
if (!plain)
|
|
103
108
|
return null;
|
|
104
|
-
if (['review', 'diagnose', 'auto-review'].includes(m.page) && ['up', 'down', 'pageup', 'pagedown', 'home'].includes(key)) {
|
|
109
|
+
if (['review', 'diagnose', 'auto-review', 'checks', 'binding-cleanup'].includes(m.page) && ['up', 'down', 'pageup', 'pagedown', 'home'].includes(key)) {
|
|
105
110
|
m.scroll = key === 'home' ? 0 : Math.max(0, m.scroll + (key === 'up' ? -1 : key === 'pageup' ? -8 : key === 'pagedown' ? 8 : 1));
|
|
106
111
|
return null;
|
|
107
112
|
}
|
|
113
|
+
if (['checks','bindings'].includes(m.page) && ['left','right'].includes(key)) {
|
|
114
|
+
const total=m.page==='checks'?m.inspection?.total:m.bindingReview?.total;
|
|
115
|
+
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';
|
|
116
|
+
}
|
|
108
117
|
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
118
|
if (key === 'up' || key === 'down')
|
|
110
119
|
m.cursor = Math.max(0, Math.min(count(editor) - 1, m.cursor + (key === 'up' ? -1 : 1)));
|
|
@@ -117,14 +126,17 @@ export function sourcesKey(editor: Editor, event: TextKey): 'sources' | null {
|
|
|
117
126
|
m.selected = selected.id;
|
|
118
127
|
m.page = 'actions';
|
|
119
128
|
}
|
|
129
|
+
else if(m.cursor === (m.library?.sources.length??0)+1){m.offset=0;m.effect='bindings';}
|
|
120
130
|
else
|
|
121
131
|
m.page = 'kind';
|
|
122
132
|
m.cursor = 0;
|
|
123
133
|
}
|
|
134
|
+
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;}}
|
|
135
|
+
else if(m.page==='binding-cleanup')m.effect='binding-cleanup';
|
|
124
136
|
else if (m.page === 'kind')
|
|
125
137
|
form(editor, (['json', 'github', 'command'] as const)[m.cursor]!);
|
|
126
138
|
else if (m.page === 'actions') {
|
|
127
|
-
const action = actions(editor)[m.cursor]!;
|
|
139
|
+
const action = actions(editor)[m.cursor]!;m.offset=0;
|
|
128
140
|
if (action === 'edit')
|
|
129
141
|
form(editor, source(editor)!.kind, true);
|
|
130
142
|
else if (action === 'bind' || action === 'unbind' || action === 'remove') {
|
|
@@ -188,46 +200,36 @@ export async function performSourceAction(editor: Editor, backend: SourceBackend
|
|
|
188
200
|
m.library = await backend.request('sources_read', {});
|
|
189
201
|
const target = editor.baseline.configuration;
|
|
190
202
|
m.context = await backend.request('source_context', { project: target?.project_root ?? (target?.target.kind === 'project' ? target.target.path : null), session: null, agent: null });
|
|
203
|
+
if(!m.closed){editor.sourceDraftRegistered=true;await backend.request('source_draft',{owner:editor.sourceDraftOwner,bindings:draftBindings(editor),close:false});}
|
|
191
204
|
return;
|
|
192
205
|
}
|
|
206
|
+
if(effect==='bindings'||effect==='binding-cleanup'){
|
|
207
|
+
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]});
|
|
208
|
+
m.page='bindings';m.cursor=0;m.scroll=0;return;
|
|
209
|
+
}
|
|
193
210
|
if (effect === 'review' || effect === 'auto-review') {
|
|
194
211
|
m.review = await backend.request('source_review', { id: m.selected });
|
|
195
212
|
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));
|
|
213
|
+
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)));
|
|
197
214
|
m.scroll = 0;
|
|
198
215
|
return;
|
|
199
216
|
}
|
|
200
|
-
if (
|
|
201
|
-
const selected
|
|
202
|
-
const context
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
m.scroll = 0;
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
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');
|
|
217
|
+
if (['status','cancel','refresh','diagnose','checks','raw'].includes(effect)) {
|
|
218
|
+
const selected=source(editor)!;
|
|
219
|
+
const context=await backend.request('source_context',{project:selected.scope.project??m.context?.project??null,session:selected.scope.session,agent:selected.scope.agent});
|
|
220
|
+
if(m.closed||editor.sources!==m)return;
|
|
221
|
+
if(effect==='refresh'){
|
|
222
|
+
const job=await backend.request('source_refresh',{id:m.selected,context,owner:m.owner});
|
|
223
|
+
if(m.closed||editor.sources!==m){await backend.request('source_release',{id:job.id,owner:m.owner});return;}
|
|
224
|
+
m.jobs=[...m.jobs.filter(previous=>previous.id!==job.id),job];m.message=text('sources.refresh_started');return;
|
|
223
225
|
}
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
m.page = 'diagnose';
|
|
228
|
-
m.scroll = 0;
|
|
226
|
+
if(effect==='cancel'){
|
|
227
|
+
const report=await backend.request('source_diagnose',{id:m.selected,context});
|
|
228
|
+
for(const job of report.jobs.filter(j=>j.state==='running'))await backend.request('source_cancel',{id:job.id});
|
|
229
229
|
}
|
|
230
|
-
|
|
230
|
+
const report=await backend.request('source_inspect',{id:m.selected,context,offset:m.offset});
|
|
231
|
+
if(m.closed||editor.sources!==m)return;
|
|
232
|
+
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
233
|
}
|
|
232
234
|
const payload: Record<string, unknown> = { action: effect, id: m.selected, expected_revision: m.library!.revision };
|
|
233
235
|
if (effect === 'save') {
|
|
@@ -243,6 +245,7 @@ export async function performSourceAction(editor: Editor, backend: SourceBackend
|
|
|
243
245
|
parsed.pr = parsed.pr === '' ? null : Number(parsed.pr);
|
|
244
246
|
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
247
|
}
|
|
248
|
+
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
249
|
if (effect === 'enable' || effect === 'auto-on') payload.review_revision = m.review?.review_revision;
|
|
247
250
|
if (effect === 'auto-on') payload.interval_seconds = m.automaticInterval;
|
|
248
251
|
const result = await backend.request('sources_apply', payload);
|
|
@@ -278,8 +281,13 @@ export function sourcesView(editor: Editor, language: Language, width: number, h
|
|
|
278
281
|
if (m.message)
|
|
279
282
|
add(t(m.message.key, language, m.message.params));
|
|
280
283
|
if (m.page === 'list') {
|
|
281
|
-
m.library?.sources.forEach((s, i) => add(`${s.name} · ${s.kind} · ${tr(s.enabled ? 'enabled' : 'disabled')}${s.kind
|
|
284
|
+
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
285
|
add('+ ' + tr('add'), m.cursor === (m.library?.sources.length ?? 0));
|
|
286
|
+
add(tr('bindings'),m.cursor===(m.library?.sources.length??0)+1);
|
|
287
|
+
}
|
|
288
|
+
else if(m.page==='bindings'){
|
|
289
|
+
add(tr(m.bindingReview?.uncertain?'bindings_uncertain':'bindings_help'));
|
|
290
|
+
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
291
|
}
|
|
284
292
|
else if (m.page === 'actions')
|
|
285
293
|
actions(editor).forEach((action, i) => add(tr(action), m.cursor === i));
|
|
@@ -302,7 +310,8 @@ export function sourcesView(editor: Editor, language: Language, width: number, h
|
|
|
302
310
|
else if (m.page === 'remove')
|
|
303
311
|
add(tr('remove_confirm') + ' ' + source(editor)?.name, true);
|
|
304
312
|
else {
|
|
305
|
-
const
|
|
313
|
+
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;
|
|
314
|
+
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
315
|
const wrapped = lines.flatMap(line => wrapText([line], width));
|
|
307
316
|
const capacity = Math.max(1, height - rows.length);
|
|
308
317
|
const start = Math.min(m.scroll, Math.max(0, wrapped.length - capacity));
|
|
@@ -313,3 +322,6 @@ export function sourcesView(editor: Editor, language: Language, width: number, h
|
|
|
313
322
|
const selected = Math.max(0, entries.findIndex(row => row.selected)), start = Math.max(0, selected - capacity + 1);
|
|
314
323
|
return [...fixed, ...entries.slice(start, start + capacity)];
|
|
315
324
|
}
|
|
325
|
+
|
|
326
|
+
export function draftBindings(editor:Editor):string[]{return [...new Set([...editor.draft.display.instances,...editor.draft.display.subagents.instances].flatMap(n=>n.source?.binding?[n.source.binding]:[]))];}
|
|
327
|
+
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 ===
|
|
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
|
|
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)))
|