xtralab 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +27 -11
  2. package/lib/commandBar/index.d.ts +14 -0
  3. package/lib/commandBar/index.js +114 -0
  4. package/lib/fileBrowser/fileBrowser.js +6 -1
  5. package/lib/highlight/index.d.ts +15 -0
  6. package/lib/highlight/index.js +214 -0
  7. package/lib/index.js +13 -1
  8. package/lib/launcher/agents.d.ts +18 -1
  9. package/lib/launcher/agents.js +47 -4
  10. package/lib/launcher/editorRegistry.js +5 -3
  11. package/lib/launcher/editors.d.ts +17 -2
  12. package/lib/launcher/editors.js +31 -5
  13. package/lib/launcher/index.js +7 -1
  14. package/lib/launcher/schemaDefaults.d.ts +15 -0
  15. package/lib/launcher/schemaDefaults.js +44 -0
  16. package/lib/omnibox/files.d.ts +7 -0
  17. package/lib/omnibox/files.js +50 -0
  18. package/lib/omnibox/index.d.ts +14 -0
  19. package/lib/omnibox/index.js +83 -0
  20. package/lib/omnibox/model.d.ts +45 -0
  21. package/lib/omnibox/model.js +142 -0
  22. package/lib/omnibox/tokens.d.ts +23 -0
  23. package/lib/omnibox/tokens.js +11 -0
  24. package/lib/omnibox/widget.d.ts +36 -0
  25. package/lib/omnibox/widget.js +161 -0
  26. package/lib/searchReplace/index.d.ts +25 -0
  27. package/lib/searchReplace/index.js +68 -0
  28. package/lib/showOutput/index.d.ts +17 -0
  29. package/lib/showOutput/index.js +154 -0
  30. package/lib/terminals/index.d.ts +4 -0
  31. package/lib/terminals/index.js +65 -16
  32. package/lib/terminals/model.d.ts +56 -3
  33. package/lib/terminals/model.js +261 -5
  34. package/lib/terminals/widget.d.ts +3 -1
  35. package/lib/terminals/widget.js +11 -3
  36. package/lib/walkthrough/index.d.ts +14 -0
  37. package/lib/walkthrough/index.js +162 -0
  38. package/lib/walkthrough/panel.d.ts +54 -0
  39. package/lib/walkthrough/panel.js +98 -0
  40. package/package.json +1 -1
  41. package/schema/launcher.json +5 -4
  42. package/schema/terminals.json +15 -0
  43. package/src/commandBar/index.ts +165 -0
  44. package/src/fileBrowser/fileBrowser.tsx +8 -1
  45. package/src/highlight/index.ts +251 -0
  46. package/src/index.ts +13 -1
  47. package/src/launcher/agents.ts +53 -3
  48. package/src/launcher/editorRegistry.ts +8 -4
  49. package/src/launcher/editors.ts +37 -4
  50. package/src/launcher/index.ts +7 -1
  51. package/src/launcher/schemaDefaults.ts +53 -0
  52. package/src/omnibox/files.ts +68 -0
  53. package/src/omnibox/index.ts +105 -0
  54. package/src/omnibox/model.ts +210 -0
  55. package/src/omnibox/tokens.ts +29 -0
  56. package/src/omnibox/widget.tsx +322 -0
  57. package/src/searchReplace/index.ts +86 -0
  58. package/src/showOutput/index.ts +199 -0
  59. package/src/terminals/index.ts +79 -16
  60. package/src/terminals/model.ts +304 -3
  61. package/src/terminals/widget.tsx +21 -4
  62. package/src/walkthrough/index.ts +202 -0
  63. package/src/walkthrough/panel.ts +152 -0
  64. package/style/commandBar.css +104 -0
  65. package/style/highlight.css +11 -0
  66. package/style/index.css +5 -0
  67. package/style/index.js +5 -0
  68. package/style/omnibox.css +120 -0
  69. package/style/showOutput.css +11 -0
  70. package/style/terminals.css +54 -10
  71. package/style/walkthrough.css +80 -0
@@ -53,15 +53,30 @@ export interface IEditorSettings {
53
53
  * the editor tile entirely. Defaults to true.
54
54
  */
55
55
  enabled?: boolean;
56
- /** See {@link IEditor.requireAvailable}. */
56
+ /**
57
+ * See {@link IEditor.requireAvailable}. Defaults to true for a built-in
58
+ * editor that still uses its shipped command, and to false once you override
59
+ * the `command` (a user-chosen command — often a shell alias — is trusted and
60
+ * always shown). Set it explicitly to force the check on or off.
61
+ */
57
62
  requireAvailable?: boolean;
58
63
  }
64
+ /**
65
+ * The built-in editors projected into the JSON settings shape
66
+ * ({@link IEditorSettings}), dropping the runtime-only {@link LabIcon}. Mirrors
67
+ * {@link defaultAgentSettings}: {@link registerLauncherSchemaDefaults} injects
68
+ * this as the `editors` setting's schema default so the Settings Editor shows
69
+ * the shipped list.
70
+ */
71
+ export declare function defaultEditorSettings(): IEditorSettings[];
59
72
  /**
60
73
  * Merge xtralab's built-in editors with the user's `editors` settings. Built-in
61
74
  * entries keep their fields unless explicitly overridden; user-only entries are
62
75
  * appended. `enabled: false` filters an entry out of the result entirely (so
63
76
  * callers don't need to re-check the flag). The result is sorted by rank, which
64
- * is also the launcher's tile-preference order. Mirrors `mergeAgents`.
77
+ * is also the launcher's tile-preference order. Mirrors `mergeAgents`, including
78
+ * turning `requireAvailable` off when the user overrides a built-in's `command`
79
+ * so an aliased editor still shows.
65
80
  */
66
81
  export declare function mergeEditors(overrides: IEditorSettings[]): IEditor[];
67
82
  /**
@@ -26,6 +26,23 @@ const DEFAULTS = [
26
26
  requireAvailable: true
27
27
  }
28
28
  ];
29
+ /**
30
+ * The built-in editors projected into the JSON settings shape
31
+ * ({@link IEditorSettings}), dropping the runtime-only {@link LabIcon}. Mirrors
32
+ * {@link defaultAgentSettings}: {@link registerLauncherSchemaDefaults} injects
33
+ * this as the `editors` setting's schema default so the Settings Editor shows
34
+ * the shipped list.
35
+ */
36
+ export function defaultEditorSettings() {
37
+ return DEFAULTS.map(editor => ({
38
+ id: editor.id,
39
+ label: editor.label,
40
+ caption: editor.caption,
41
+ command: editor.command,
42
+ rank: editor.rank,
43
+ requireAvailable: editor.requireAvailable
44
+ }));
45
+ }
29
46
  function resolveEditorIcon(id, iconSvg) {
30
47
  var _a;
31
48
  if (iconSvg) {
@@ -41,7 +58,9 @@ function resolveEditorIcon(id, iconSvg) {
41
58
  * entries keep their fields unless explicitly overridden; user-only entries are
42
59
  * appended. `enabled: false` filters an entry out of the result entirely (so
43
60
  * callers don't need to re-check the flag). The result is sorted by rank, which
44
- * is also the launcher's tile-preference order. Mirrors `mergeAgents`.
61
+ * is also the launcher's tile-preference order. Mirrors `mergeAgents`, including
62
+ * turning `requireAvailable` off when the user overrides a built-in's `command`
63
+ * so an aliased editor still shows.
45
64
  */
46
65
  export function mergeEditors(overrides) {
47
66
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -57,16 +76,23 @@ export function mergeEditors(overrides) {
57
76
  if (override.enabled === false) {
58
77
  continue;
59
78
  }
79
+ const command = (_a = override.command) !== null && _a !== void 0 ? _a : base.command;
60
80
  merged.push({
61
81
  id: base.id,
62
- label: (_a = override.label) !== null && _a !== void 0 ? _a : base.label,
63
- caption: (_b = override.caption) !== null && _b !== void 0 ? _b : base.caption,
64
- command: (_c = override.command) !== null && _c !== void 0 ? _c : base.command,
82
+ label: (_b = override.label) !== null && _b !== void 0 ? _b : base.label,
83
+ caption: (_c = override.caption) !== null && _c !== void 0 ? _c : base.caption,
84
+ command,
65
85
  icon: override.iconSvg
66
86
  ? resolveEditorIcon(base.id, override.iconSvg)
67
87
  : base.icon,
68
88
  rank: (_d = override.rank) !== null && _d !== void 0 ? _d : base.rank,
69
- requireAvailable: (_e = override.requireAvailable) !== null && _e !== void 0 ? _e : base.requireAvailable
89
+ // See `mergeAgents`: once the user points a built-in editor at their own
90
+ // command (e.g. a shell alias `which` can't resolve), stop requiring
91
+ // availability so the tile still shows. The check stays on only while the
92
+ // command is xtralab's default.
93
+ requireAvailable: command === base.command
94
+ ? ((_e = override.requireAvailable) !== null && _e !== void 0 ? _e : base.requireAvailable)
95
+ : false
70
96
  });
71
97
  }
72
98
  // What remains in `overrideById` are ids that don't match a built-in — treat
@@ -11,6 +11,7 @@ import { CREATE_LAUNCHER_COMMAND, registerAgentCommands } from './commands';
11
11
  import { LauncherDashboard } from './dashboard';
12
12
  import { editorRegistryPlugin, IEditorRegistry } from './editorRegistry';
13
13
  import { AgentRegistry } from './registry';
14
+ import { registerLauncherSchemaDefaults } from './schemaDefaults';
14
15
  import { IAgentRegistry } from './tokens';
15
16
  const PLUGIN_ID = 'xtralab:launcher';
16
17
  /**
@@ -26,7 +27,9 @@ const PLUGIN_ID = 'xtralab:launcher';
26
27
  * The agent list is the merge of xtralab's defaults with the user's
27
28
  * `xtralab:launcher` settings, then filtered by a server-side `which`
28
29
  * check so users only see agents that are actually installed. Agents with
29
- * `requireAvailable: false` (e.g. shell aliases) skip the filter.
30
+ * `requireAvailable: false` skip the filter, as does any built-in whose
31
+ * `command` the user has overridden (a user-chosen command — often a shell
32
+ * alias the server can't resolve — is trusted and always shown).
30
33
  *
31
34
  * The plugin deliberately does NOT provide the `ILauncher` token: other
32
35
  * extensions register notebook/console/terminal cards on it as a side
@@ -77,6 +80,9 @@ const plugin = {
77
80
  return Array.isArray(raw) ? raw : [];
78
81
  };
79
82
  if (settingRegistry) {
83
+ // Must precede the first `load`: the schema defers loading until a
84
+ // transform is registered.
85
+ registerLauncherSchemaDefaults(settingRegistry);
80
86
  try {
81
87
  const settings = await settingRegistry.load(PLUGIN_ID);
82
88
  await applyAgents(readOverrides(settings));
@@ -0,0 +1,15 @@
1
+ import type { ISettingRegistry } from '@jupyterlab/settingregistry';
2
+ /** Schema id the launcher's `agents`/`editors` settings live under. */
3
+ export declare const LAUNCHER_PLUGIN_ID = "xtralab:launcher";
4
+ /**
5
+ * Register a `fetch` transform that injects xtralab's built-in agent and
6
+ * editor lists as the schema defaults for the `xtralab:launcher` settings, so
7
+ * the Settings Editor shows the shipped list.
8
+ *
9
+ * The schema declares `jupyter.lab.transform: true`, so the registry defers
10
+ * loading the plugin until a transform is registered: callers must invoke this
11
+ * before their first `settingRegistry.load(LAUNCHER_PLUGIN_ID)`. Idempotent, so
12
+ * the two plugins that load these settings can both call it regardless of
13
+ * activation order.
14
+ */
15
+ export declare function registerLauncherSchemaDefaults(settingRegistry: ISettingRegistry): void;
@@ -0,0 +1,44 @@
1
+ import { defaultAgentSettings } from './agents';
2
+ import { defaultEditorSettings } from './editors';
3
+ /** Schema id the launcher's `agents`/`editors` settings live under. */
4
+ export const LAUNCHER_PLUGIN_ID = 'xtralab:launcher';
5
+ /**
6
+ * Setting registries that already have the transform, so both callers skip
7
+ * re-registering (the registry rejects a duplicate transformer).
8
+ */
9
+ const registered = new WeakSet();
10
+ /**
11
+ * Register a `fetch` transform that injects xtralab's built-in agent and
12
+ * editor lists as the schema defaults for the `xtralab:launcher` settings, so
13
+ * the Settings Editor shows the shipped list.
14
+ *
15
+ * The schema declares `jupyter.lab.transform: true`, so the registry defers
16
+ * loading the plugin until a transform is registered: callers must invoke this
17
+ * before their first `settingRegistry.load(LAUNCHER_PLUGIN_ID)`. Idempotent, so
18
+ * the two plugins that load these settings can both call it regardless of
19
+ * activation order.
20
+ */
21
+ export function registerLauncherSchemaDefaults(settingRegistry) {
22
+ if (registered.has(settingRegistry)) {
23
+ return;
24
+ }
25
+ registered.add(settingRegistry);
26
+ settingRegistry.transform(LAUNCHER_PLUGIN_ID, {
27
+ fetch: plugin => {
28
+ const properties = plugin.schema.properties;
29
+ if (properties) {
30
+ // The settings shapes are plain JSON by construction, but their named
31
+ // interfaces lack an index signature, so cast at this TS→JSON boundary.
32
+ if (properties.agents) {
33
+ properties.agents.default =
34
+ defaultAgentSettings();
35
+ }
36
+ if (properties.editors) {
37
+ properties.editors.default =
38
+ defaultEditorSettings();
39
+ }
40
+ }
41
+ return plugin;
42
+ }
43
+ });
44
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The workspace file list, cached briefly so reopening the omnibox in quick
3
+ * succession reuses one scan. A failed fetch (e.g. quickopen's server
4
+ * extension is absent) resolves to an empty list so file search degrades to
5
+ * "no results" instead of surfacing an error.
6
+ */
7
+ export declare function loadWorkspaceFiles(): Promise<string[]>;
@@ -0,0 +1,50 @@
1
+ import { URLExt } from '@jupyterlab/coreutils';
2
+ import { ServerConnection } from '@jupyterlab/services';
3
+ /**
4
+ * Fetch and flatten the workspace file list from `jupyterlab-quickopen`'s
5
+ * server endpoint (`GET {base}/jupyterlab-quickopen/api/files`).
6
+ *
7
+ * We reuse quickopen's endpoint rather than walking the contents API so the
8
+ * listing honors the same server-side `.gitignore` filtering quickopen does
9
+ * (xtralab ships `respectGitignore: true`) in a single request. The endpoint
10
+ * only exists when quickopen's server extension is installed and the server
11
+ * reads a local filesystem; callers treat a rejection as "no file results".
12
+ */
13
+ async function fetchWorkspaceFiles(respectGitignore = true) {
14
+ const settings = ServerConnection.makeSettings();
15
+ const params = new URLSearchParams();
16
+ if (respectGitignore) {
17
+ params.append('respect_gitignore', '1');
18
+ }
19
+ // The handler requires a `path` argument; `""` scans from the root.
20
+ params.append('path', '');
21
+ const url = URLExt.join(settings.baseUrl, 'jupyterlab-quickopen', 'api', 'files') +
22
+ `?${params.toString()}`;
23
+ const response = await ServerConnection.makeRequest(url, { method: 'GET' }, settings);
24
+ if (response.status !== 200) {
25
+ throw new ServerConnection.ResponseError(response);
26
+ }
27
+ const data = (await response.json());
28
+ const paths = [];
29
+ for (const dir in data.contents) {
30
+ for (const name of data.contents[dir]) {
31
+ paths.push(dir ? `${dir}/${name}` : name);
32
+ }
33
+ }
34
+ return paths;
35
+ }
36
+ const CACHE_TTL_MS = 15000;
37
+ let cache = null;
38
+ /**
39
+ * The workspace file list, cached briefly so reopening the omnibox in quick
40
+ * succession reuses one scan. A failed fetch (e.g. quickopen's server
41
+ * extension is absent) resolves to an empty list so file search degrades to
42
+ * "no results" instead of surfacing an error.
43
+ */
44
+ export function loadWorkspaceFiles() {
45
+ const now = Date.now();
46
+ if (!cache || now - cache.at > CACHE_TTL_MS) {
47
+ cache = { at: now, files: fetchWorkspaceFiles().catch(() => []) };
48
+ }
49
+ return cache.files;
50
+ }
@@ -0,0 +1,14 @@
1
+ import { JupyterFrontEndPlugin } from '@jupyterlab/application';
2
+ import { IOmnibox } from './tokens';
3
+ /**
4
+ * The omnibox: a single launcher overlay that fuzzy-searches workspace files
5
+ * (via jupyterlab-quickopen's gitignore-aware endpoint) and JupyterLab
6
+ * commands, and routes a typed prompt to one of the configured agents (running
7
+ * it in a fresh terminal through the launcher's `xtralab:start-agent:<id>`
8
+ * commands). It is opened by the top-bar command bar.
9
+ *
10
+ * The agent rows come from the launcher's `IAgentRegistry`; when the launcher
11
+ * is disabled the omnibox still searches files and commands.
12
+ */
13
+ declare const plugin: JupyterFrontEndPlugin<IOmnibox>;
14
+ export default plugin;
@@ -0,0 +1,83 @@
1
+ import { ICommandPalette } from '@jupyterlab/apputils';
2
+ import { ITranslator, nullTranslator } from '@jupyterlab/translation';
3
+ import { Widget } from '@lumino/widgets';
4
+ import { IAgentRegistry } from '../launcher/tokens';
5
+ import { IOmnibox, OMNIBOX_OPEN_COMMAND } from './tokens';
6
+ import { OmniboxWidget } from './widget';
7
+ const PLUGIN_ID = 'xtralab:omnibox';
8
+ /**
9
+ * The omnibox: a single launcher overlay that fuzzy-searches workspace files
10
+ * (via jupyterlab-quickopen's gitignore-aware endpoint) and JupyterLab
11
+ * commands, and routes a typed prompt to one of the configured agents (running
12
+ * it in a fresh terminal through the launcher's `xtralab:start-agent:<id>`
13
+ * commands). It is opened by the top-bar command bar.
14
+ *
15
+ * The agent rows come from the launcher's `IAgentRegistry`; when the launcher
16
+ * is disabled the omnibox still searches files and commands.
17
+ */
18
+ const plugin = {
19
+ id: PLUGIN_ID,
20
+ description: 'A launcher overlay that searches files and commands and prompts agents.',
21
+ autoStart: true,
22
+ provides: IOmnibox,
23
+ optional: [IAgentRegistry, ICommandPalette, ITranslator],
24
+ activate: (app, agentRegistry, palette, translator) => {
25
+ const { commands, docRegistry } = app;
26
+ const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
27
+ const placeholder = trans.__('Search files and commands, or ask an agent…');
28
+ let current = null;
29
+ const close = () => {
30
+ const widget = current;
31
+ current = null;
32
+ widget === null || widget === void 0 ? void 0 : widget.dispose();
33
+ };
34
+ const open = (query) => {
35
+ // Reopen fresh each time so the input resets and the agent snapshot is
36
+ // current; the file list is cached separately (see files.ts).
37
+ close();
38
+ const widget = new OmniboxWidget({
39
+ commands,
40
+ docRegistry,
41
+ agents: agentRegistry ? agentRegistry.agents : [],
42
+ placeholder,
43
+ initialQuery: query !== null && query !== void 0 ? query : '',
44
+ trans,
45
+ onClose: close
46
+ });
47
+ current = widget;
48
+ widget.disposed.connect(() => {
49
+ if (current === widget) {
50
+ current = null;
51
+ }
52
+ });
53
+ Widget.attach(widget, document.body);
54
+ };
55
+ commands.addCommand(OMNIBOX_OPEN_COMMAND, {
56
+ label: trans.__('Search…'),
57
+ caption: trans.__('Search files and commands, or ask an agent'),
58
+ execute: args => {
59
+ // Toggle: a second press (e.g. of the keyboard shortcut) closes it.
60
+ if (current && !current.isDisposed) {
61
+ close();
62
+ return;
63
+ }
64
+ const query = args['query'];
65
+ open(typeof query === 'string' ? query : undefined);
66
+ }
67
+ });
68
+ // Open the omnibox with Cmd/Ctrl+K, the common "command center" chord.
69
+ commands.addKeyBinding({
70
+ command: OMNIBOX_OPEN_COMMAND,
71
+ keys: ['Accel K'],
72
+ selector: 'body'
73
+ });
74
+ if (palette) {
75
+ palette.addItem({
76
+ command: OMNIBOX_OPEN_COMMAND,
77
+ category: trans.__('Other')
78
+ });
79
+ }
80
+ return { open, close };
81
+ }
82
+ };
83
+ export default plugin;
@@ -0,0 +1,45 @@
1
+ import type { DocumentRegistry } from '@jupyterlab/docregistry';
2
+ import type { TranslationBundle } from '@jupyterlab/translation';
3
+ import { LabIcon } from '@jupyterlab/ui-components';
4
+ import type { CommandRegistry } from '@lumino/commands';
5
+ import type { IAgent } from '../launcher/agents';
6
+ /** The source a result row came from, used to group rows under a header. */
7
+ export type OmniboxItemKind = 'command' | 'file' | 'agent';
8
+ /** A single result row, with the action it runs when chosen. */
9
+ export interface IOmniboxItem {
10
+ kind: OmniboxItemKind;
11
+ /** Stable React key. */
12
+ key: string;
13
+ /** Primary text shown on the row. */
14
+ label: string;
15
+ /** Indices of matched characters in `label`, for highlighting. May be empty. */
16
+ matchIndices: readonly number[];
17
+ /** Optional secondary text shown trailing the label. */
18
+ caption?: string;
19
+ /** Optional leading icon. */
20
+ icon?: LabIcon;
21
+ /** Run the row's action. */
22
+ execute: () => void;
23
+ }
24
+ /** Results grouped by source; each group is already capped and sorted. */
25
+ export interface IOmniboxSections {
26
+ commands: IOmniboxItem[];
27
+ files: IOmniboxItem[];
28
+ agents: IOmniboxItem[];
29
+ }
30
+ export interface IComputeOptions {
31
+ query: string;
32
+ commands: CommandRegistry;
33
+ docRegistry: DocumentRegistry;
34
+ agents: IAgent[];
35
+ files: string[];
36
+ trans: TranslationBundle;
37
+ }
38
+ /**
39
+ * Build the grouped result set for a query. A leading `>` searches only
40
+ * commands and a leading `/` only files; otherwise commands and files are
41
+ * fuzzy-matched and every prompt-capable agent is offered an "Ask" row
42
+ * carrying the query as its prompt. An empty term yields no rows (the widget
43
+ * shows a hint instead).
44
+ */
45
+ export declare function computeSections(options: IComputeOptions): IOmniboxSections;
@@ -0,0 +1,142 @@
1
+ import { fileIcon } from '@jupyterlab/ui-components';
2
+ import { StringExt } from '@lumino/algorithm';
3
+ import { agentCommandId } from '../launcher/tokens';
4
+ const COMMAND_LIMIT = 7;
5
+ const FILE_LIMIT = 10;
6
+ /**
7
+ * Prefixes that narrow the search to a single source: a leading `>` to
8
+ * commands, a leading `/` to files (relative paths never start with `/`, so it
9
+ * is unambiguous). Without a prefix, every source is searched.
10
+ */
11
+ const COMMAND_PREFIX = '>';
12
+ const FILE_PREFIX = '/';
13
+ /**
14
+ * Build the grouped result set for a query. A leading `>` searches only
15
+ * commands and a leading `/` only files; otherwise commands and files are
16
+ * fuzzy-matched and every prompt-capable agent is offered an "Ask" row
17
+ * carrying the query as its prompt. An empty term yields no rows (the widget
18
+ * shows a hint instead).
19
+ */
20
+ export function computeSections(options) {
21
+ const { query, commands, docRegistry, agents, files, trans } = options;
22
+ const trimmed = query.trim();
23
+ let mode = 'all';
24
+ let term = trimmed;
25
+ if (trimmed.startsWith(COMMAND_PREFIX)) {
26
+ mode = 'commands';
27
+ term = trimmed.slice(COMMAND_PREFIX.length).trim();
28
+ }
29
+ else if (trimmed.startsWith(FILE_PREFIX)) {
30
+ mode = 'files';
31
+ term = trimmed.slice(FILE_PREFIX.length).trim();
32
+ }
33
+ if (!term) {
34
+ return { commands: [], files: [], agents: [] };
35
+ }
36
+ return {
37
+ commands: mode === 'files' ? [] : matchCommands(commands, term),
38
+ files: mode === 'commands' ? [] : matchFiles(commands, docRegistry, files, term),
39
+ // Agents only in the unprefixed view; the prompt is the full typed query.
40
+ agents: mode === 'all' ? buildAgentItems(commands, agents, term, trans) : []
41
+ };
42
+ }
43
+ function matchCommands(commands, term) {
44
+ const query = term.toLowerCase();
45
+ const scored = [];
46
+ for (const id of commands.listCommands()) {
47
+ let label = '';
48
+ let visible = true;
49
+ let caption = '';
50
+ try {
51
+ // A command's accessors can throw if they assume a context (e.g. an
52
+ // active notebook) the omnibox doesn't provide; skip those.
53
+ label = commands.label(id);
54
+ visible = commands.isVisible(id);
55
+ caption = commands.caption(id);
56
+ }
57
+ catch (_a) {
58
+ continue;
59
+ }
60
+ if (!label || !visible) {
61
+ continue;
62
+ }
63
+ const match = StringExt.matchSumOfSquares(label.toLowerCase(), query);
64
+ if (!match) {
65
+ continue;
66
+ }
67
+ scored.push({
68
+ score: match.score,
69
+ item: {
70
+ kind: 'command',
71
+ key: `command:${id}`,
72
+ label,
73
+ matchIndices: match.indices,
74
+ caption: caption || undefined,
75
+ execute: () => {
76
+ void commands.execute(id).catch(reason => {
77
+ console.error(`xtralab omnibox: command "${id}" failed`, reason);
78
+ });
79
+ }
80
+ }
81
+ });
82
+ }
83
+ scored.sort((a, b) => a.score - b.score);
84
+ return scored.slice(0, COMMAND_LIMIT).map(entry => entry.item);
85
+ }
86
+ function matchFiles(commands, docRegistry, files, term) {
87
+ const query = term.toLowerCase();
88
+ const scored = [];
89
+ for (const path of files) {
90
+ const match = StringExt.matchSumOfSquares(path.toLowerCase(), query);
91
+ if (match) {
92
+ scored.push({ score: match.score, path, indices: match.indices });
93
+ }
94
+ }
95
+ scored.sort((a, b) => a.score - b.score);
96
+ return scored.slice(0, FILE_LIMIT).map(({ path, indices }) => ({
97
+ kind: 'file',
98
+ key: `file:${path}`,
99
+ label: path,
100
+ matchIndices: indices,
101
+ icon: fileIconForPath(docRegistry, path),
102
+ execute: () => {
103
+ void commands.execute('docmanager:open', { path }).catch(reason => {
104
+ console.error(`xtralab omnibox: failed to open "${path}"`, reason);
105
+ });
106
+ }
107
+ }));
108
+ }
109
+ function fileIconForPath(docRegistry, path) {
110
+ for (const fileType of docRegistry.getFileTypesForPath(path)) {
111
+ if (fileType.icon) {
112
+ return fileType.icon;
113
+ }
114
+ }
115
+ return fileIcon;
116
+ }
117
+ function buildAgentItems(commands, agents, prompt, trans) {
118
+ const items = [];
119
+ for (const agent of agents) {
120
+ // Agents without `promptArgs` can't take an inline prompt (the launcher
121
+ // would drop it), so they don't belong in an "Ask …" row.
122
+ if (agent.promptArgs === undefined) {
123
+ continue;
124
+ }
125
+ items.push({
126
+ kind: 'agent',
127
+ key: `agent:${agent.id}`,
128
+ label: trans.__('Ask %1', agent.label),
129
+ matchIndices: [],
130
+ caption: trans.__('Run prompt in a new terminal'),
131
+ icon: agent.icon,
132
+ execute: () => {
133
+ void commands
134
+ .execute(agentCommandId(agent.id), { prompt })
135
+ .catch(reason => {
136
+ console.error(`xtralab omnibox: failed to start agent "${agent.id}"`, reason);
137
+ });
138
+ }
139
+ });
140
+ }
141
+ return items;
142
+ }
@@ -0,0 +1,23 @@
1
+ import { Token } from '@lumino/coreutils';
2
+ /**
3
+ * A launcher overlay that fuzzy-searches across multiple sources — workspace
4
+ * files, JupyterLab commands — and routes a typed prompt to one of the
5
+ * configured agents. Provided by `xtralab:omnibox` and consumed (optionally)
6
+ * by the top-bar command bar, which opens it on click.
7
+ */
8
+ export interface IOmnibox {
9
+ /** Open the overlay, optionally seeding the input with `query`. */
10
+ open(query?: string): void;
11
+ /** Close the overlay if it is open. */
12
+ close(): void;
13
+ }
14
+ /**
15
+ * DI token for {@link IOmnibox}. Provided by `xtralab:omnibox`; consumed by
16
+ * `xtralab:command-bar` so the top-bar pill opens the omnibox.
17
+ */
18
+ export declare const IOmnibox: Token<IOmnibox>;
19
+ /**
20
+ * Command id that opens the omnibox (registered by `xtralab:omnibox`). Shared
21
+ * here so the command bar can look up its keybinding and show a shortcut hint.
22
+ */
23
+ export declare const OMNIBOX_OPEN_COMMAND = "xtralab:omnibox:open";
@@ -0,0 +1,11 @@
1
+ import { Token } from '@lumino/coreutils';
2
+ /**
3
+ * DI token for {@link IOmnibox}. Provided by `xtralab:omnibox`; consumed by
4
+ * `xtralab:command-bar` so the top-bar pill opens the omnibox.
5
+ */
6
+ export const IOmnibox = new Token('xtralab:IOmnibox', 'Opens the omnibox overlay that searches files and commands and prompts agents.');
7
+ /**
8
+ * Command id that opens the omnibox (registered by `xtralab:omnibox`). Shared
9
+ * here so the command bar can look up its keybinding and show a shortcut hint.
10
+ */
11
+ export const OMNIBOX_OPEN_COMMAND = 'xtralab:omnibox:open';
@@ -0,0 +1,36 @@
1
+ import type { DocumentRegistry } from '@jupyterlab/docregistry';
2
+ import type { TranslationBundle } from '@jupyterlab/translation';
3
+ import { ReactWidget } from '@jupyterlab/ui-components';
4
+ import type { CommandRegistry } from '@lumino/commands';
5
+ import type { IAgent } from '../launcher/agents';
6
+ /**
7
+ * The omnibox overlay widget. Hosts {@link OmniboxComponent} in a React root
8
+ * attached to `document.body`. It carries `jp-ThemedContainer` so JupyterLab's
9
+ * theme CSS variables resolve outside the shell, and its own `jp-xtralab-Omnibox`
10
+ * class for the overlay/panel styling (style/omnibox.css).
11
+ */
12
+ export declare class OmniboxWidget extends ReactWidget {
13
+ constructor(options: OmniboxWidget.IOptions);
14
+ render(): JSX.Element;
15
+ private _options;
16
+ }
17
+ /**
18
+ * A namespace for `OmniboxWidget` statics.
19
+ */
20
+ export declare namespace OmniboxWidget {
21
+ /** Construction options for {@link OmniboxWidget}. */
22
+ interface IOptions {
23
+ commands: CommandRegistry;
24
+ docRegistry: DocumentRegistry;
25
+ /** Snapshot of the available agents, read once when the overlay opens. */
26
+ agents: IAgent[];
27
+ /** Placeholder text for the input. */
28
+ placeholder: string;
29
+ /** Seed text for the input. */
30
+ initialQuery: string;
31
+ /** Translation bundle for the overlay's own labels. */
32
+ trans: TranslationBundle;
33
+ /** Dismiss the overlay (the plugin disposes the widget). */
34
+ onClose: () => void;
35
+ }
36
+ }