@fbincon/claude-code-statusline 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -73
- package/candidate.json +318 -248
- package/node_modules/@fbincon/statusline-cli/dist/src/config/profiles.js +2 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/config/profiles.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/config/transfer.js +5 -3
- package/node_modules/@fbincon/statusline-cli/dist/src/config/transfer.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/diagnostics/service.js +24 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/diagnostics/service.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/help.js +3 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/help.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/main.js +19 -3
- package/node_modules/@fbincon/statusline-cli/dist/src/main.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/recovery/journal.js +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/recovery/journal.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/rendering/environment.js +46 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/rendering/environment.js.map +1 -1
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.d.ts +3 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js +117 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/command.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/context.d.ts +4 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/context.js +35 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/context.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.d.ts +8 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js +118 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/providers.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.d.ts +35 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js +359 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/sources/service.js.map +1 -0
- package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.d.ts +2 -2
- package/node_modules/@fbincon/statusline-cli/dist/src/ui/protocol.js +30 -1
- 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 +15 -5
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/backend.ts +8 -5
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/client/keys.ts +6 -2
- 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/appearance.ts +24 -6
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/draft.ts +2 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/forms.ts +1 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-manager.ts +301 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/editor/source-validation.ts +45 -0
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/generated-contracts.ts +79 -8
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/i18n/generated-locales.ts +738 -6
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/lib/session.ts +2 -1
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/resource-manifest.json +18 -16
- package/node_modules/@fbincon/statusline-cli/resources/statusline-native/ui/client/draw.ts +5 -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/resource-manifest.json +3 -3
- package/node_modules/@fbincon/statusline-core/dist/src/config/catalog-data.d.ts +91 -0
- package/node_modules/@fbincon/statusline-core/dist/src/config/catalog-data.js +250 -0
- package/node_modules/@fbincon/statusline-core/dist/src/config/catalog-data.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/defaults.js +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/defaults.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/display.d.ts +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/display.js +13 -6
- package/node_modules/@fbincon/statusline-core/dist/src/config/display.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/editor-fields.js +7 -10
- package/node_modules/@fbincon/statusline-core/dist/src/config/editor-fields.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/formatting.js +4 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/formatting.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.js +4 -2
- package/node_modules/@fbincon/statusline-core/dist/src/config/import-review.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/instances.js +7 -2
- package/node_modules/@fbincon/statusline-core/dist/src/config/instances.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/profiles.js +2 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/profiles.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/config/transfer.js +5 -3
- package/node_modules/@fbincon/statusline-core/dist/src/config/transfer.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/generated-catalog.d.ts +2 -2
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/generated-catalog.js +2 -2
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/generated-catalog.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/contracts/ui.d.ts +134 -6
- 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/appearance.d.ts +4 -2
- package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.js +29 -6
- package/node_modules/@fbincon/statusline-core/dist/src/editor/appearance.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/backend.js +10 -5
- 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 +2 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/draft.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/forms.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.d.ts +39 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js +270 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-manager.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.d.ts +2 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js +45 -0
- package/node_modules/@fbincon/statusline-core/dist/src/editor/source-validation.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.d.ts +27 -0
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js +222 -0
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/model.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/portable.d.ts +3 -0
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/portable.js +6 -0
- package/node_modules/@fbincon/statusline-core/dist/src/extensions/portable.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.d.ts +732 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js +738 -6
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/generated-locales.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.d.ts +26 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.js +27 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/en.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.d.ts +26 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.js +27 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ja.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.d.ts +26 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.js +27 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/ko.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.d.ts +26 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.js +27 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-CN.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.d.ts +26 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.js +27 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-HK.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.d.ts +26 -0
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.js +27 -1
- package/node_modules/@fbincon/statusline-core/dist/src/i18n/statusline/zh-TW.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/dist/src/rendering/appearance.js +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/appearance.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/context.d.ts +3 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/diagnose.js +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/diagnose.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/explain.js +2 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/explain.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/extensions.d.ts +7 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/extensions.js +35 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/extensions.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js +8 -2
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/items.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.d.ts +3 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.js +30 -9
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/layout.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.js +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/powerline.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/preview.js +3 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/preview.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/spans.d.ts +1 -0
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/spans.js +2 -2
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/spans.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js +12 -1
- package/node_modules/@fbincon/statusline-core/dist/src/rendering/subagents.js.map +1 -1
- package/node_modules/@fbincon/statusline-core/dist/src/terminal/links.d.ts +6 -0
- package/node_modules/@fbincon/statusline-core/dist/src/terminal/links.js +37 -0
- package/node_modules/@fbincon/statusline-core/dist/src/terminal/links.js.map +1 -0
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/en.json +123 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ja.json +123 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/ko.json +123 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-CN.json +123 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-HK.json +123 -1
- package/node_modules/@fbincon/statusline-core/resources/i18n/locales/zh-TW.json +123 -1
- package/node_modules/@fbincon/statusline-platform/dist/src/posix-source-exec.d.ts +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/posix-source-exec.js +26 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/posix-source-exec.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/source-files.d.ts +2 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/source-files.js +37 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/source-files.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/source-process.d.ts +19 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/source-process.js +122 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/source-process.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.d.ts +4 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.js +61 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-environment.js.map +1 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-job.d.ts +3 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-job.js +61 -0
- package/node_modules/@fbincon/statusline-platform/dist/src/windows-source-job.js.map +1 -0
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/canvas.js +3 -2
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/canvas.js.map +1 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/drawing/pages.js +5 -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 +2 -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 +2 -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.js +6 -0
- 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 +12 -1
- package/node_modules/@fbincon/statusline-tui/dist/src/state.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { t, text } from '../i18n/messages.js';
|
|
2
|
+
import { inputKey, inputView, textInput } from './text-input.js';
|
|
3
|
+
import { wrapText } from './text.js';
|
|
4
|
+
import { BackendError } from './backend.js';
|
|
5
|
+
const external = ['external-value', 'github-pr', 'github-ci'];
|
|
6
|
+
export function openSources(editor) {
|
|
7
|
+
editor.sources = { library: null, context: null, owner: 'editor-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2), page: 'list', cursor: 0, scroll: 0, selected: null, kind: 'json', editing: false, fields: [], review: null, details: [], jobs: [], message: null, effect: 'load', target: null };
|
|
8
|
+
}
|
|
9
|
+
function source(editor) { return editor.sources.library?.sources.find(s => s.id === editor.sources.selected); }
|
|
10
|
+
function actions(editor) { return ['edit', 'review', ...(source(editor)?.enabled ? ['disable'] : []), 'bind', 'refresh', 'status', 'cancel', 'diagnose', 'remove', 'unbind']; }
|
|
11
|
+
function targets(editor) {
|
|
12
|
+
const s = source(editor);
|
|
13
|
+
return ['main', 'subagent'].flatMap(scope => (scope === 'main' ? editor.draft.display.instances : editor.draft.display.subagents.instances)
|
|
14
|
+
.filter(node => external.includes(node.type_id) && (s?.kind === 'github' || !node.type_id.startsWith('github-')) && (editor.sources.page !== 'unbind' || editor.sources.library?.bindings.some(binding => binding.source_id === s?.id && binding.id === node.source?.binding))).map(node => ({ scope, id: node.id })));
|
|
15
|
+
}
|
|
16
|
+
function form(editor, kind, editing = false) {
|
|
17
|
+
const m = editor.sources, s = editing ? source(editor) : undefined, settings = s?.settings ?? {};
|
|
18
|
+
const common = { id: s?.id ?? '', name: s?.name ?? '', project: s ? s.scope.project ?? '' : m.context?.project ?? '', session: s?.scope.session ?? '', agent: s?.scope.agent ?? '', ttl_seconds: s?.ttl_seconds ?? 300 };
|
|
19
|
+
const extra = kind === 'json' ? { path: settings.path ?? '', pointer: settings.pointer ?? '/value', observed_at_pointer: settings.observed_at_pointer ?? '/observed_at', unit: settings.unit ?? '' }
|
|
20
|
+
: kind === 'github' ? { host: settings.host ?? 'github.com', repository: settings.repository ?? '', branch: settings.branch ?? m.context?.branch ?? '', account: settings.account ?? '', pr: settings.pr ?? '' }
|
|
21
|
+
: { executable: settings.executable ?? '', args: JSON.stringify(settings.args ?? []), cwd: settings.cwd ?? m.context?.project ?? '', input: JSON.stringify(settings.input ?? {}), output: settings.output ?? 'json', timeout_ms: settings.timeout_ms ?? 5000 };
|
|
22
|
+
m.kind = kind;
|
|
23
|
+
m.editing = editing;
|
|
24
|
+
m.page = 'form';
|
|
25
|
+
m.cursor = 0;
|
|
26
|
+
m.scroll = 0;
|
|
27
|
+
m.message = null;
|
|
28
|
+
m.fields = Object.entries({ ...common, ...extra }).map(([key, value]) => ({ key, input: textInput(String(value)) }));
|
|
29
|
+
}
|
|
30
|
+
function count(editor) {
|
|
31
|
+
const m = editor.sources;
|
|
32
|
+
return m.page === 'list' ? (m.library?.sources.length ?? 0) + 1 : m.page === 'actions' ? actions(editor).length : m.page === 'kind' ? 3 : m.page === 'form' ? m.fields.length : m.page === 'bind' || m.page === 'unbind' ? targets(editor).length : 1;
|
|
33
|
+
}
|
|
34
|
+
export function sourcesKey(editor, event) {
|
|
35
|
+
const m = editor.sources;
|
|
36
|
+
if (!m)
|
|
37
|
+
return null;
|
|
38
|
+
const key = event.key === 'return' ? 'enter' : event.key, plain = !event.text && !event.paste && !event.ctrl && !event.meta;
|
|
39
|
+
if (!event.text && !event.paste && (key === 'escape' || event.ctrl && key.toLowerCase() === 'g')) {
|
|
40
|
+
if (m.page === 'list')
|
|
41
|
+
m.effect = 'close';
|
|
42
|
+
else {
|
|
43
|
+
m.page = 'list';
|
|
44
|
+
m.cursor = 0;
|
|
45
|
+
m.scroll = 0;
|
|
46
|
+
m.message = null;
|
|
47
|
+
}
|
|
48
|
+
return m.effect ? 'sources' : null;
|
|
49
|
+
}
|
|
50
|
+
if (m.page === 'form') {
|
|
51
|
+
if (!event.text && (key === 'tab' || plain && ['up', 'down'].includes(key)))
|
|
52
|
+
m.cursor = Math.max(0, Math.min(m.fields.length - 1, m.cursor + (key === 'up' ? -1 : 1)));
|
|
53
|
+
else if (!event.text && (key === 'enter' || event.ctrl && key.toLowerCase() === 's')) {
|
|
54
|
+
if (key === 'enter' && m.cursor < m.fields.length - 1)
|
|
55
|
+
m.cursor++;
|
|
56
|
+
else
|
|
57
|
+
m.effect = 'save';
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const field = m.fields[m.cursor];
|
|
61
|
+
if (!(m.editing && field.key === 'id')) {
|
|
62
|
+
const changed = inputKey(field.input.value, field.input, event, 8192);
|
|
63
|
+
field.input = changed.state;
|
|
64
|
+
m.message = changed.error ? text('input.' + changed.error, { limit: 8192 }) : null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return m.effect ? 'sources' : null;
|
|
68
|
+
}
|
|
69
|
+
if (!plain)
|
|
70
|
+
return null;
|
|
71
|
+
if (['review', 'diagnose'].includes(m.page) && ['up', 'down', 'pageup', 'pagedown', 'home'].includes(key)) {
|
|
72
|
+
m.scroll = key === 'home' ? 0 : Math.max(0, m.scroll + (key === 'up' ? -1 : key === 'pageup' ? -8 : key === 'pagedown' ? 8 : 1));
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (key === 'up' || key === 'down')
|
|
76
|
+
m.cursor = Math.max(0, Math.min(count(editor) - 1, m.cursor + (key === 'up' ? -1 : 1)));
|
|
77
|
+
if (key === 'r' && m.page === 'list')
|
|
78
|
+
m.effect = 'load';
|
|
79
|
+
if (key === 'enter') {
|
|
80
|
+
if (m.page === 'list') {
|
|
81
|
+
const selected = m.library?.sources[m.cursor];
|
|
82
|
+
if (selected) {
|
|
83
|
+
m.selected = selected.id;
|
|
84
|
+
m.page = 'actions';
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
m.page = 'kind';
|
|
88
|
+
m.cursor = 0;
|
|
89
|
+
}
|
|
90
|
+
else if (m.page === 'kind')
|
|
91
|
+
form(editor, ['json', 'github', 'command'][m.cursor]);
|
|
92
|
+
else if (m.page === 'actions') {
|
|
93
|
+
const action = actions(editor)[m.cursor];
|
|
94
|
+
if (action === 'edit')
|
|
95
|
+
form(editor, source(editor).kind, true);
|
|
96
|
+
else if (action === 'bind' || action === 'unbind' || action === 'remove') {
|
|
97
|
+
m.page = action;
|
|
98
|
+
m.cursor = 0;
|
|
99
|
+
}
|
|
100
|
+
else
|
|
101
|
+
m.effect = action;
|
|
102
|
+
}
|
|
103
|
+
else if (m.page === 'review')
|
|
104
|
+
m.effect = 'enable';
|
|
105
|
+
else if (m.page === 'remove')
|
|
106
|
+
m.effect = 'remove';
|
|
107
|
+
else if (m.page === 'unbind') {
|
|
108
|
+
const target = targets(editor)[m.cursor];
|
|
109
|
+
const node = target && editor.instance(target.scope, target.id);
|
|
110
|
+
if (node?.source) {
|
|
111
|
+
node.source = { ...node.source, binding: null };
|
|
112
|
+
m.message = text('sources.bound');
|
|
113
|
+
m.page = 'list';
|
|
114
|
+
m.cursor = 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (m.page === 'bind') {
|
|
118
|
+
m.target = targets(editor)[m.cursor] ?? null;
|
|
119
|
+
if (m.target)
|
|
120
|
+
m.effect = 'bind';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return m.effect ? 'sources' : null;
|
|
124
|
+
}
|
|
125
|
+
export async function closeSources(editor, backend) {
|
|
126
|
+
const m = editor.sources;
|
|
127
|
+
if (!m)
|
|
128
|
+
return;
|
|
129
|
+
let failed;
|
|
130
|
+
for (const job of m.jobs.filter(job => job.state === 'running')) {
|
|
131
|
+
try {
|
|
132
|
+
await backend.request('source_cancel', { id: job.id });
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
failed = error;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (failed)
|
|
139
|
+
throw failed;
|
|
140
|
+
if (editor.sources === m)
|
|
141
|
+
editor.sources = null;
|
|
142
|
+
}
|
|
143
|
+
export async function performSourceAction(editor, backend) {
|
|
144
|
+
const m = editor.sources, effect = m?.effect;
|
|
145
|
+
if (!m || !effect)
|
|
146
|
+
return;
|
|
147
|
+
m.effect = null;
|
|
148
|
+
m.message = null;
|
|
149
|
+
try {
|
|
150
|
+
if (effect === 'close') {
|
|
151
|
+
await closeSources(editor, backend);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (effect === 'load') {
|
|
155
|
+
m.library = await backend.request('sources_read', {});
|
|
156
|
+
const target = editor.baseline.configuration;
|
|
157
|
+
m.context = await backend.request('source_context', { project: target?.project_root ?? (target?.target.kind === 'project' ? target.target.path : null), session: null, agent: null });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (effect === 'review') {
|
|
161
|
+
m.review = await backend.request('source_review', { id: m.selected });
|
|
162
|
+
m.page = 'review';
|
|
163
|
+
m.scroll = 0;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (effect === 'status' || effect === 'cancel') {
|
|
167
|
+
const selected = source(editor);
|
|
168
|
+
const context = await backend.request('source_context', { project: selected.scope.project ?? m.context?.project ?? null, session: selected.scope.session, agent: selected.scope.agent });
|
|
169
|
+
const observed = await backend.request('source_diagnose', { id: m.selected, context });
|
|
170
|
+
const jobs = await Promise.all(observed.jobs.map(job => backend.request(effect === 'cancel' && job.state === 'running' ? 'source_cancel' : 'source_status', { id: job.id })));
|
|
171
|
+
m.jobs = m.jobs.map(job => jobs.find(updated => updated.id === job.id) ?? job);
|
|
172
|
+
m.details = jobs.map(job => `${job.id}: ${job.state} (${job.reason})`);
|
|
173
|
+
m.page = 'diagnose';
|
|
174
|
+
m.scroll = 0;
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (effect === 'refresh' || effect === 'diagnose') {
|
|
178
|
+
const selected = source(editor);
|
|
179
|
+
const context = await backend.request('source_context', { project: selected.scope.project ?? m.context?.project ?? null, session: selected.scope.session, agent: selected.scope.agent });
|
|
180
|
+
if (effect === 'refresh') {
|
|
181
|
+
const job = await backend.request('source_refresh', { id: m.selected, context, owner: m.owner });
|
|
182
|
+
m.jobs.push(job);
|
|
183
|
+
m.message = text('sources.refresh_started');
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const result = await backend.request('source_diagnose', { id: m.selected, context });
|
|
187
|
+
m.details = JSON.stringify(result, null, 2).split('\n');
|
|
188
|
+
m.page = 'diagnose';
|
|
189
|
+
m.scroll = 0;
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const payload = { action: effect, id: m.selected, expected_revision: m.library.revision };
|
|
194
|
+
if (effect === 'save') {
|
|
195
|
+
const values = Object.fromEntries(m.fields.map(field => [field.key, field.input.value]));
|
|
196
|
+
const { id, name, project, session, agent, ttl_seconds, ...settings } = values;
|
|
197
|
+
const parsed = { ...settings };
|
|
198
|
+
for (const key of ['args', 'input'])
|
|
199
|
+
if (key in parsed)
|
|
200
|
+
parsed[key] = JSON.parse(String(parsed[key]));
|
|
201
|
+
if ('timeout_ms' in parsed)
|
|
202
|
+
parsed.timeout_ms = Number(parsed.timeout_ms);
|
|
203
|
+
if ('pr' in parsed)
|
|
204
|
+
parsed.pr = parsed.pr === '' ? null : Number(parsed.pr);
|
|
205
|
+
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 } });
|
|
206
|
+
}
|
|
207
|
+
if (effect === 'enable')
|
|
208
|
+
payload.review_revision = m.review?.review_revision;
|
|
209
|
+
const result = await backend.request('sources_apply', payload);
|
|
210
|
+
m.library = result;
|
|
211
|
+
if (effect === 'bind' && m.target && result.binding) {
|
|
212
|
+
const node = editor.instance(m.target.scope, m.target.id);
|
|
213
|
+
if (node)
|
|
214
|
+
node.source = result.binding;
|
|
215
|
+
m.message = text('sources.bound');
|
|
216
|
+
}
|
|
217
|
+
else
|
|
218
|
+
m.message = text('sources.saved');
|
|
219
|
+
m.page = 'list';
|
|
220
|
+
m.cursor = 0;
|
|
221
|
+
m.scroll = 0;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
m.message = error instanceof BackendError ? error.localization ?? text('sources.failed') : text('sources.failed');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
export function sourcesView(editor, language, width, height) {
|
|
228
|
+
const m = editor.sources;
|
|
229
|
+
const tr = (key) => t('sources.' + key, language), rows = [];
|
|
230
|
+
const add = (value, selected = false) => rows.push({ text: value, selected });
|
|
231
|
+
add(tr('separate_save'));
|
|
232
|
+
if (m.message)
|
|
233
|
+
add(t(m.message.key, language, m.message.params));
|
|
234
|
+
if (m.page === 'list') {
|
|
235
|
+
m.library?.sources.forEach((s, i) => add(`${s.name} · ${s.kind} · ${tr(s.enabled ? 'enabled' : 'disabled')}`, m.cursor === i));
|
|
236
|
+
add('+ ' + tr('add'), m.cursor === (m.library?.sources.length ?? 0));
|
|
237
|
+
}
|
|
238
|
+
else if (m.page === 'actions')
|
|
239
|
+
actions(editor).forEach((action, i) => add(tr(action), m.cursor === i));
|
|
240
|
+
else if (m.page === 'kind')
|
|
241
|
+
['json', 'github', 'command'].forEach((kind, i) => add(tr(kind), m.cursor === i));
|
|
242
|
+
else if (m.page === 'form') {
|
|
243
|
+
m.fields.forEach((field, i) => {
|
|
244
|
+
const label = tr('field.' + field.key) + ': ', space = Math.max(2, width - label.length);
|
|
245
|
+
const view = inputView({ ...field.input }, space);
|
|
246
|
+
add(label + view, m.cursor === i);
|
|
247
|
+
});
|
|
248
|
+
add(tr('form_help'));
|
|
249
|
+
}
|
|
250
|
+
else if (m.page === 'bind' || m.page === 'unbind') {
|
|
251
|
+
const entries = targets(editor);
|
|
252
|
+
if (!entries.length)
|
|
253
|
+
add(tr('no_components'));
|
|
254
|
+
entries.forEach((target, i) => add(`${target.scope}: ${editor.instanceLabel(target.scope, target.id, language)}`, m.cursor === i));
|
|
255
|
+
}
|
|
256
|
+
else if (m.page === 'remove')
|
|
257
|
+
add(tr('remove_confirm') + ' ' + source(editor)?.name, true);
|
|
258
|
+
else {
|
|
259
|
+
const lines = m.page === 'review' ? [tr('enable_review'), ...JSON.stringify(m.review?.source, null, 2).split('\n')] : m.details;
|
|
260
|
+
const wrapped = lines.flatMap(line => wrapText([line], width));
|
|
261
|
+
const capacity = Math.max(1, height - rows.length);
|
|
262
|
+
const start = Math.min(m.scroll, Math.max(0, wrapped.length - capacity));
|
|
263
|
+
wrapped.slice(start, start + capacity).forEach(line => add(line));
|
|
264
|
+
return rows;
|
|
265
|
+
}
|
|
266
|
+
const fixed = rows.slice(0, 1 + Number(!!m.message)), entries = rows.slice(fixed.length), capacity = Math.max(1, height - fixed.length);
|
|
267
|
+
const selected = Math.max(0, entries.findIndex(row => row.selected)), start = Math.max(0, selected - capacity + 1);
|
|
268
|
+
return [...fixed, ...entries.slice(start, start + capacity)];
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=source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,CAAC,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC;IACnH,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Strict response validation shared by the native and external source managers. */
|
|
2
|
+
const object = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
3
|
+
const text = (v) => typeof v === 'string' && v.length <= 16384 && !/[\p{Cc}\p{Cs}]/u.test(v);
|
|
4
|
+
const nullable = (v) => v === null || text(v);
|
|
5
|
+
const scalar = (v) => v === null || text(v) || typeof v === 'boolean' || typeof v === 'number' && Number.isFinite(v);
|
|
6
|
+
const fields = (v, keys) => object(v) && Object.keys(v).length === keys.length && keys.every(key => Object.hasOwn(v, key));
|
|
7
|
+
const id = (v) => text(v) && /^[A-Za-z0-9][A-Za-z0-9_-]{0,95}$/u.test(v);
|
|
8
|
+
const scope = (v) => fields(v, ['project', 'session', 'agent']) && Object.values(v).every(nullable) && (v.agent === null || v.session !== null);
|
|
9
|
+
export const isSourceContext = (v) => fields(v, ['project', 'session', 'agent', 'branch', 'head']) && Object.values(v).every(nullable);
|
|
10
|
+
function definition(v) {
|
|
11
|
+
if (!fields(v, ['id', 'name', 'kind', 'scope', 'ttl_seconds', 'settings', 'enabled', 'revision']) || !id(v.id) || !text(v.name) || !['json', 'github', 'command'].includes(String(v.kind)) || !scope(v.scope) || !id(v.revision) || typeof v.enabled !== 'boolean' || typeof v.ttl_seconds !== 'number' || !Number.isInteger(v.ttl_seconds) || v.ttl_seconds < 1 || v.ttl_seconds > 86400 || !object(v.settings))
|
|
12
|
+
return false;
|
|
13
|
+
const s = v.settings;
|
|
14
|
+
if (v.kind === 'json')
|
|
15
|
+
return fields(s, ['path', 'pointer', 'observed_at_pointer', 'unit']) && Object.values(s).every(text);
|
|
16
|
+
if (v.kind === 'github')
|
|
17
|
+
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);
|
|
18
|
+
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;
|
|
19
|
+
}
|
|
20
|
+
function job(v) {
|
|
21
|
+
return fields(v, ['version', 'id', 'source_id', 'source_revision', 'owner', 'context', 'started_at', 'deadline_at', 'state', 'reason']) && v.version === 1 && ['id', 'source_id', 'source_revision', 'owner'].every(key => id(v[key])) && isSourceContext(v.context) && text(v.started_at) && Number.isFinite(Date.parse(v.started_at)) && text(v.deadline_at) && Number.isFinite(Date.parse(v.deadline_at)) && ['running', 'completed', 'failed', 'cancelled'].includes(String(v.state)) && text(v.reason);
|
|
22
|
+
}
|
|
23
|
+
function view(v) {
|
|
24
|
+
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));
|
|
25
|
+
}
|
|
26
|
+
export function isSourceResult(operation, value) {
|
|
27
|
+
if (!object(value))
|
|
28
|
+
return false;
|
|
29
|
+
if (operation === 'source_context')
|
|
30
|
+
return isSourceContext(value);
|
|
31
|
+
if (operation === 'source_review')
|
|
32
|
+
return fields(value, ['source', 'review_revision']) && definition(value.source) && object(value.source) && value.review_revision === value.source.revision;
|
|
33
|
+
if (['source_refresh', 'source_status', 'source_cancel'].includes(operation))
|
|
34
|
+
return job(value);
|
|
35
|
+
if (operation === 'source_diagnose')
|
|
36
|
+
return fields(value, ['source', 'view', 'jobs']) && definition(value.source) && view(value.view) && Array.isArray(value.jobs) && value.jobs.every(job);
|
|
37
|
+
if (!['sources_read', 'sources_apply'].includes(operation) || !fields(value, ['version', 'sources', 'bindings', 'revision', ...(operation === 'sources_apply' ? ['backup_dir', ...(Object.hasOwn(value, 'binding') ? ['binding'] : [])] : [])]))
|
|
38
|
+
return false;
|
|
39
|
+
if (value.version !== 1 || !text(value.revision) || !Array.isArray(value.sources) || value.sources.length > 128 || !value.sources.every(definition) || !Array.isArray(value.bindings) || value.bindings.length > 4096)
|
|
40
|
+
return false;
|
|
41
|
+
if (!value.bindings.every(b => fields(b, ['id', 'source_id']) && id(b.id) && id(b.source_id)))
|
|
42
|
+
return false;
|
|
43
|
+
return operation === 'sources_read' || nullable(value.backup_dir) && (value.binding === undefined || fields(value.binding, ['binding', 'hint']) && id(value.binding.binding) && text(value.binding.hint));
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=source-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-validation.js","sourceRoot":"","sources":["../../../src/editor/source-validation.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,MAAM,GAAG,CAAC,CAAU,EAAgC,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CA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AAK,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI;QACjN,OAAO,KAAK,CAAC;IACjB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACzF,OAAO,KAAK,CAAC;IACjB,OAAO,SAAS,KAAK,cAAc,IAAI,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9M,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SourceContext, SourceDefinition, SourceObservation, SourceReference, SourceRegistry, SourceScope, SourceSettings, SourceView } from '../contracts/ui.js';
|
|
2
|
+
export declare const SOURCE_FILENAME = "claude-statusline-sources.json";
|
|
3
|
+
export declare const MAX_SOURCE_BYTES = 1048576;
|
|
4
|
+
export declare const SOURCE_TYPES: string[];
|
|
5
|
+
export declare const INPUT_FIELDS: readonly ["project", "session", "agent", "branch", "head"];
|
|
6
|
+
export declare const emptyRegistry: () => SourceRegistry;
|
|
7
|
+
export declare function sourceError(reason: string): never;
|
|
8
|
+
export declare function sourceText(value: unknown, maximum?: number, empty?: boolean): string;
|
|
9
|
+
export declare function sourceId(value: unknown): string;
|
|
10
|
+
export declare function sourceScope(value: unknown): SourceScope;
|
|
11
|
+
export declare function sourceContext(value: unknown): SourceContext;
|
|
12
|
+
export declare function matchesScope(scope: SourceScope, context: SourceScope): boolean;
|
|
13
|
+
export declare function sameContext(a: SourceContext, b: SourceContext): boolean;
|
|
14
|
+
/** Cache only declared scope and supplied input identities; a project source is
|
|
15
|
+
* reusable across sessions unless it explicitly consumes session/agent input. */
|
|
16
|
+
export declare function observationContext(source: SourceDefinition, actual: SourceContext): SourceContext;
|
|
17
|
+
export declare function reference(value: unknown): SourceReference;
|
|
18
|
+
export declare function pointerParts(value: unknown): string[];
|
|
19
|
+
export declare function selectPointer(value: unknown, pointer: string): unknown;
|
|
20
|
+
export declare function settings(kind: SourceDefinition['kind'], value: unknown): SourceSettings;
|
|
21
|
+
export declare function definition(value: unknown): SourceDefinition;
|
|
22
|
+
export declare function registry(value: unknown): SourceRegistry;
|
|
23
|
+
export declare function stamp(value: unknown): string | null;
|
|
24
|
+
export declare function scalar(value: unknown): string | number | boolean;
|
|
25
|
+
export declare function emptyObservation(source: SourceDefinition, context: SourceContext, reason: string, state?: SourceObservation['state']): SourceObservation;
|
|
26
|
+
export declare function parseObservation(raw: unknown, source: SourceDefinition, context: SourceContext, contracted?: boolean): SourceObservation;
|
|
27
|
+
export declare function sourceView(source: SourceDefinition | undefined, context: SourceContext, current: SourceObservation | null, good: SourceObservation | null, now: number): SourceView;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { ConfigError, object, exact, integer, isSchema } from '../config/validation.js';
|
|
2
|
+
import { numeric } from '../runtime/values.js';
|
|
3
|
+
export const SOURCE_FILENAME = 'claude-statusline-sources.json';
|
|
4
|
+
export const MAX_SOURCE_BYTES = 1048576;
|
|
5
|
+
export const SOURCE_TYPES = ['external-value', 'github-pr', 'github-ci'];
|
|
6
|
+
export const INPUT_FIELDS = ['project', 'session', 'agent', 'branch', 'head'];
|
|
7
|
+
export const emptyRegistry = () => ({ version: 1, sources: [], bindings: [] });
|
|
8
|
+
export function sourceError(reason) { throw new ConfigError('sources.error.' + reason, {}, reason); }
|
|
9
|
+
export function sourceText(value, maximum = 4096, empty = false) {
|
|
10
|
+
if (typeof value !== 'string' || (!empty && !value.trim()) || value.length > maximum || /[\p{Cc}\p{Cs}]/u.test(value))
|
|
11
|
+
sourceError('invalid');
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
export function sourceId(value) {
|
|
15
|
+
const id = sourceText(value, 96);
|
|
16
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/u.test(id))
|
|
17
|
+
sourceError('invalid');
|
|
18
|
+
return id;
|
|
19
|
+
}
|
|
20
|
+
export function sourceScope(value) {
|
|
21
|
+
exact(value, ['project', 'session', 'agent'], 'source scope');
|
|
22
|
+
const result = Object.fromEntries(['project', 'session', 'agent'].map(key => [key, value[key] === null ? null : sourceText(value[key])]));
|
|
23
|
+
if (result.agent && !result.session)
|
|
24
|
+
sourceError('scope');
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
export function sourceContext(value) {
|
|
28
|
+
exact(value, ['project', 'session', 'agent', 'branch', 'head'], 'source context');
|
|
29
|
+
return { ...sourceScope({ project: value.project, session: value.session, agent: value.agent }),
|
|
30
|
+
branch: value.branch === null ? null : sourceText(value.branch), head: value.head === null ? null : sourceText(value.head) };
|
|
31
|
+
}
|
|
32
|
+
export function matchesScope(scope, context) {
|
|
33
|
+
return ['project', 'session', 'agent'].every(key => scope[key] === null || scope[key] === context[key]);
|
|
34
|
+
}
|
|
35
|
+
export function sameContext(a, b) {
|
|
36
|
+
return ['project', 'session', 'agent', 'branch', 'head'].every(key => a[key] === b[key]);
|
|
37
|
+
}
|
|
38
|
+
/** Cache only declared scope and supplied input identities; a project source is
|
|
39
|
+
* reusable across sessions unless it explicitly consumes session/agent input. */
|
|
40
|
+
export function observationContext(source, actual) {
|
|
41
|
+
const inputs = Object.values(source.settings.input ?? {});
|
|
42
|
+
const git = source.kind === 'github';
|
|
43
|
+
return {
|
|
44
|
+
project: source.scope.project !== null || git || inputs.some(key => ['project', 'branch', 'head'].includes(key)) ? actual.project : null,
|
|
45
|
+
session: source.scope.session !== null || inputs.includes('session') || inputs.includes('agent') ? actual.session : null,
|
|
46
|
+
agent: source.scope.agent !== null || inputs.includes('agent') ? actual.agent : null,
|
|
47
|
+
branch: git || inputs.includes('branch') ? actual.branch : null,
|
|
48
|
+
head: git || inputs.includes('head') ? actual.head : null,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function reference(value) {
|
|
52
|
+
exact(value, ['binding', 'hint'], 'source reference');
|
|
53
|
+
return { binding: value.binding === null ? null : sourceId(value.binding), hint: sourceText(value.hint, 128, true) };
|
|
54
|
+
}
|
|
55
|
+
export function pointerParts(value) {
|
|
56
|
+
const text = sourceText(value, 512, true);
|
|
57
|
+
if (!text)
|
|
58
|
+
return [];
|
|
59
|
+
if (!text.startsWith('/') || /~(?![01])/u.test(text))
|
|
60
|
+
sourceError('pointer');
|
|
61
|
+
const parts = text.slice(1).split('/').map(part => part.replaceAll('~1', '/').replaceAll('~0', '~'));
|
|
62
|
+
if (parts.length > 32 || parts.some(part => ['__proto__', 'prototype', 'constructor'].includes(part)))
|
|
63
|
+
sourceError('pointer');
|
|
64
|
+
return parts;
|
|
65
|
+
}
|
|
66
|
+
export function selectPointer(value, pointer) {
|
|
67
|
+
for (const key of pointerParts(pointer)) {
|
|
68
|
+
if ((!object(value) && !Array.isArray(value)) || !Object.hasOwn(value, key))
|
|
69
|
+
return undefined;
|
|
70
|
+
value = value[key];
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
function keys(value, allowed) {
|
|
75
|
+
if (Object.keys(value).some(key => !allowed.includes(key)))
|
|
76
|
+
sourceError('invalid');
|
|
77
|
+
}
|
|
78
|
+
export function settings(kind, value) {
|
|
79
|
+
if (!object(value))
|
|
80
|
+
sourceError('invalid');
|
|
81
|
+
if (kind === 'json') {
|
|
82
|
+
keys(value, ['path', 'pointer', 'observed_at_pointer', 'unit']);
|
|
83
|
+
const pointer = sourceText(value.pointer ?? '/value', 512, true);
|
|
84
|
+
pointerParts(pointer);
|
|
85
|
+
const observed = sourceText(value.observed_at_pointer ?? '/observed_at', 512, true);
|
|
86
|
+
pointerParts(observed);
|
|
87
|
+
return { path: sourceText(value.path), pointer, observed_at_pointer: observed, unit: sourceText(value.unit ?? '', 32, true) };
|
|
88
|
+
}
|
|
89
|
+
if (kind === 'github') {
|
|
90
|
+
keys(value, ['host', 'repository', 'branch', 'account', 'pr']);
|
|
91
|
+
const host = sourceText(value.host ?? 'github.com', 253).toLowerCase(), repository = sourceText(value.repository, 256);
|
|
92
|
+
if (!/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/u.test(host) || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(repository))
|
|
93
|
+
sourceError('invalid');
|
|
94
|
+
const branch = sourceText(value.branch, 256), account = sourceText(value.account, 128);
|
|
95
|
+
if (branch.startsWith('-') || !/^[A-Za-z0-9_-]+$/u.test(account))
|
|
96
|
+
sourceError('invalid');
|
|
97
|
+
return { host, repository, branch, account, pr: value.pr == null ? null : integer(value.pr, 1, Number.MAX_SAFE_INTEGER, 'PR') };
|
|
98
|
+
}
|
|
99
|
+
if (kind !== 'command')
|
|
100
|
+
sourceError('invalid');
|
|
101
|
+
keys(value, ['executable', 'args', 'cwd', 'input', 'output', 'timeout_ms']);
|
|
102
|
+
if (!Array.isArray(value.args) || value.args.length > 128 || value.args.some(arg => typeof arg !== 'string' || arg.length > 8192 || arg.includes('\0')))
|
|
103
|
+
sourceError('invalid');
|
|
104
|
+
const input = value.input ?? {};
|
|
105
|
+
if (!object(input) || Object.keys(input).length > 16 || Object.entries(input).some(([key, field]) => !/^[A-Za-z][A-Za-z0-9_]{0,63}$/u.test(key) || !INPUT_FIELDS.includes(field)))
|
|
106
|
+
sourceError('input');
|
|
107
|
+
const output = value.output ?? 'json';
|
|
108
|
+
if (output !== 'json' && output !== 'text')
|
|
109
|
+
sourceError('invalid');
|
|
110
|
+
return { executable: sourceText(value.executable), args: [...value.args], cwd: sourceText(value.cwd), input: { ...input }, output,
|
|
111
|
+
timeout_ms: integer(value.timeout_ms ?? 5000, 100, 30000, 'timeout_ms') };
|
|
112
|
+
}
|
|
113
|
+
export function definition(value) {
|
|
114
|
+
exact(value, ['id', 'name', 'kind', 'scope', 'ttl_seconds', 'settings', 'enabled', 'revision'], 'source');
|
|
115
|
+
if (!['json', 'github', 'command'].includes(value.kind) || typeof value.enabled !== 'boolean')
|
|
116
|
+
sourceError('invalid');
|
|
117
|
+
const kind = value.kind, scope = sourceScope(value.scope);
|
|
118
|
+
if (kind === 'github' && !scope.project)
|
|
119
|
+
sourceError('scope');
|
|
120
|
+
return { id: sourceId(value.id), name: sourceText(value.name, 128), kind, scope, ttl_seconds: integer(value.ttl_seconds, 1, 86400, 'ttl_seconds'),
|
|
121
|
+
settings: settings(kind, value.settings), enabled: value.enabled, revision: sourceId(value.revision) };
|
|
122
|
+
}
|
|
123
|
+
export function registry(value) {
|
|
124
|
+
exact(value, ['version', 'sources', 'bindings'], 'source registry');
|
|
125
|
+
if (!isSchema(value.version, 1) || !Array.isArray(value.sources) || !Array.isArray(value.bindings) || value.sources.length > 128 || value.bindings.length > 4096)
|
|
126
|
+
sourceError('invalid');
|
|
127
|
+
const sources = value.sources.map(definition), ids = new Set(sources.map(source => source.id));
|
|
128
|
+
if (ids.size !== sources.length)
|
|
129
|
+
sourceError('invalid');
|
|
130
|
+
const bindings = value.bindings.map(raw => { exact(raw, ['id', 'source_id'], 'source binding'); return { id: sourceId(raw.id), source_id: sourceId(raw.source_id) }; });
|
|
131
|
+
if (new Set(bindings.map(binding => binding.id)).size !== bindings.length || bindings.some(binding => !ids.has(binding.source_id)))
|
|
132
|
+
sourceError('invalid');
|
|
133
|
+
return { version: 1, sources, bindings };
|
|
134
|
+
}
|
|
135
|
+
export function stamp(value) {
|
|
136
|
+
if (value == null)
|
|
137
|
+
return null;
|
|
138
|
+
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/u.test(value) || !Number.isFinite(Date.parse(value)))
|
|
139
|
+
sourceError('time');
|
|
140
|
+
const [year, month, day, hour, minute, second] = value.match(/\d+/gu).slice(0, 6).map(Number);
|
|
141
|
+
if (month < 1 || month > 12 || day < 1 || day > new Date(Date.UTC(year, month, 0)).getUTCDate() || hour > 23 || minute > 59 || second > 59)
|
|
142
|
+
sourceError('time');
|
|
143
|
+
return new Date(value).toISOString();
|
|
144
|
+
}
|
|
145
|
+
export function scalar(value) {
|
|
146
|
+
if (typeof value === 'boolean')
|
|
147
|
+
return value;
|
|
148
|
+
if (typeof value === 'string')
|
|
149
|
+
return value.replace(/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\))/gu, '').replace(/[\p{Cc}\p{Cs}\p{Zl}\p{Zp}]/gu, ' ').slice(0, 4096);
|
|
150
|
+
const n = numeric(value);
|
|
151
|
+
if (n !== null && Number.isFinite(n))
|
|
152
|
+
return n;
|
|
153
|
+
return sourceError('type');
|
|
154
|
+
}
|
|
155
|
+
export function emptyObservation(source, context, reason, state = 'error') {
|
|
156
|
+
return { version: 1, source_id: source.id, source_revision: source.revision, context, observed_at: null, state, reason, value: null, unit: null };
|
|
157
|
+
}
|
|
158
|
+
export function parseObservation(raw, source, context, contracted = false) {
|
|
159
|
+
const result = emptyObservation(source, context, 'missing', 'missing');
|
|
160
|
+
if (contracted) {
|
|
161
|
+
if (!object(raw) || !isSchema(raw.version, 1))
|
|
162
|
+
sourceError('version');
|
|
163
|
+
exact(raw, ['version', 'source_id', 'scope', 'observed_at', 'state', 'value', 'unit'], 'source output');
|
|
164
|
+
if (raw.source_id !== source.id || !matchesScope(sourceScope(raw.scope), context) || !['project', 'session', 'agent'].every(key => sourceScope(raw.scope)[key] === source.scope[key]))
|
|
165
|
+
sourceError('scope');
|
|
166
|
+
if (!['valid', 'missing', 'partial', 'error', 'unsupported'].includes(raw.state))
|
|
167
|
+
sourceError('invalid');
|
|
168
|
+
result.state = raw.state;
|
|
169
|
+
result.reason = result.state;
|
|
170
|
+
result.value = raw.value === null ? null : scalar(raw.value);
|
|
171
|
+
if (result.state === 'valid' && result.value === null)
|
|
172
|
+
sourceError('type');
|
|
173
|
+
result.observed_at = stamp(raw.observed_at);
|
|
174
|
+
result.unit = raw.unit === null ? null : sourceText(raw.unit, 32, true);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
if (object(raw) && Object.hasOwn(raw, 'version') && !isSchema(raw.version, 1))
|
|
178
|
+
sourceError('version');
|
|
179
|
+
if (object(raw) && Object.hasOwn(raw, 'source_id') && raw.source_id !== source.id)
|
|
180
|
+
sourceError('scope');
|
|
181
|
+
if (object(raw) && Object.hasOwn(raw, 'scope') && (!matchesScope(sourceScope(raw.scope), context) || !['project', 'session', 'agent'].every(key => sourceScope(raw.scope)[key] === source.scope[key])))
|
|
182
|
+
sourceError('scope');
|
|
183
|
+
const value = selectPointer(raw, source.settings.pointer ?? '/value');
|
|
184
|
+
result.observed_at = stamp(selectPointer(raw, source.settings.observed_at_pointer ?? '/observed_at'));
|
|
185
|
+
result.unit = source.settings.unit || null;
|
|
186
|
+
if (value !== undefined && value !== null) {
|
|
187
|
+
result.value = scalar(value);
|
|
188
|
+
result.state = 'valid';
|
|
189
|
+
result.reason = 'valid';
|
|
190
|
+
}
|
|
191
|
+
if (object(raw) && Object.hasOwn(raw, 'state')) {
|
|
192
|
+
if (!['valid', 'missing', 'partial', 'error', 'unsupported'].includes(raw.state))
|
|
193
|
+
sourceError('invalid');
|
|
194
|
+
result.state = raw.state;
|
|
195
|
+
result.reason = result.state;
|
|
196
|
+
if (result.state === 'valid' && result.value === null)
|
|
197
|
+
sourceError('type');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
export function sourceView(source, context, current, good, now) {
|
|
203
|
+
const result = { source_id: source?.id ?? null, name: source?.name ?? '', state: 'unbound', reason: 'unbound', observed_at: null, freshness: 'unknown', value: null, unit: null };
|
|
204
|
+
if (!source)
|
|
205
|
+
return result;
|
|
206
|
+
if (!source.enabled)
|
|
207
|
+
return { ...result, state: 'disabled', reason: 'disabled' };
|
|
208
|
+
if (!matchesScope(source.scope, context))
|
|
209
|
+
return { ...result, state: 'mismatch', reason: 'scope' };
|
|
210
|
+
const valid = (entry) => entry && entry.source_id === source.id && entry.source_revision === source.revision && sameContext(entry.context, context);
|
|
211
|
+
if (current && !valid(current))
|
|
212
|
+
return { ...result, state: 'mismatch', reason: 'identity' };
|
|
213
|
+
if (!current)
|
|
214
|
+
return { ...result, state: 'missing', reason: 'not_refreshed' };
|
|
215
|
+
if (['scope', 'identity', 'account'].includes(current.reason))
|
|
216
|
+
return { ...result, state: 'mismatch', reason: current.reason };
|
|
217
|
+
const latest = current.value !== null && ['valid', 'partial'].includes(current.state) ? current : valid(good) ? good : { ...current, value: null, unit: null, fields: undefined };
|
|
218
|
+
const time = latest.observed_at === null ? null : Date.parse(latest.observed_at), age = time === null ? null : now - time;
|
|
219
|
+
return { ...result, state: current.state, reason: current.reason, value: latest.value, unit: latest.unit, observed_at: latest.observed_at,
|
|
220
|
+
freshness: age === null || age < 0 ? 'unknown' : age > source.ttl_seconds * 1000 ? 'stale' : 'current', ...(latest.fields ? { fields: latest.fields } : {}) };
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=model.js.map
|