@x-tech-laboratories/x-app 0.105.0 → 0.106.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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ an app moves over by changing the package name in its imports and its `x-libs-*`
13
13
  | `app/server`, `app/daemon` | `run_server(app, { web_folder })`: the web server from `<PREFIX>_CONFIG` with accounts in `accounts.db` (moved there once from the data's own file, tokens starting with the app's `token_prefix`), the calls, OpenAPI, MCP, the server's backups and its sync peer, a token or MCP client refused the app's `page_only` calls and the `user_only_backup_calls` (restore, remove, schedule) and its calls run as the `program` caller; `run_daemon(app)`: the desktop daemon from `<PREFIX>_DB` with sync, letting devices connect, backups, certificates and the desktop settings; Both take the app's `services` (see `app/services`), `run_daemon(app, env, { services })`. `build_server`, `start_daemon`, `open_app_database` (with `on_restore` hooks) and `register_app_calls` for tests and apps that add their own. |
14
14
  | `app/services` | An app's own work beside its calls, run by both hosts: `StartServices` gets a `HostContext` (`kind`, `database()`, `profile`, `device_name`, the server's raw `config`, `plugins_folder`, `declared_file` from `<PREFIX>_DECLARED_FILE` or `/etc/<id>/declared.json`, `announce`, `emit(event, data)` for the page's `on_event`, `side_database(name)` for a never-backed-up file such as `<base>-index.db`, `back_up`) and returns `HostServices` (`before_restore`, `after_restore`, `stop`), stopped before sync and the database. |
15
15
  | `app/links` | `app_link(scheme, route)` and `route_of_link(scheme, link)`: an app's links such as `x-notes://note/<id>` and the page route they open. |
16
- | `app/desktop`, `app/preload` | `run_desktop(app, electron, { main_dir })`: Electron's main process as a portal onto this computer's daemon or a server, with the window (`default_size` fixed or from the screen's free area, the daemon told while one is in front for its services' `window_in_front`), the tray (`show_tray_icon`, the app's own `tray` rows above Show, Quit and Quit completely, closing the last window leaving the app in it, `--hidden` starting there), the app's `link_scheme` links opening the window on their page (`route_of_link` to map them its own way; the page follows the `open` event), the login entry, a second launch and `--daemon`; the app's own `desktop_settings` switches sit in Settings → Desktop app beside the base's; `run_preload(app, electron)` puts every bridge on the page. Electron is handed in, so neither imports it. |
16
+ | `app/desktop`, `app/preload` | `run_desktop(app, electron, { main_dir })`: Electron's main process as a portal onto this computer's daemon or a server, with the window (`default_size` fixed or from the screen's free area, the daemon told while one is in front for its services' `window_in_front`), the tray (`show_tray_icon`, the app's own `tray` rows above Show, Quit and Quit completely, closing the last window leaving the app in it, `--hidden` starting there), the app's `link_scheme` links opening the window on their page (`route_of_link` to map them its own way; the page follows the `open` event), the login entry, a second launch and `--daemon`; the app's own `desktop_settings` switches sit in Settings → Desktop app beside the base's; `run_preload(app, electron)` puts every bridge on the page. Electron is handed in, so neither imports it. An app with `local_mcp: { default_port }` serves its calls as MCP on 127.0.0.1 from the desktop daemon (`electron/mcp`, page-only calls left out, calls run as `program`), turned on under Settings → MCP server. |
17
17
  | `app/web/app_page`, `app/web/page` | `render_app({ app, pages, general_settings })`: the page on the web, the desktop or Android in the `Shell`, with sign-in in a browser, Your account, Settings (the app's general sections, each page's own, Connections, Desktop app, Sync and Backups) and `SyncButton`; `page_hooks<Methods>()` gives the app's typed `calls`, `use_data` and `use_settings`. The phone's host (`app/web/android`) loads only on Android. The page API's `on_event(name, listener)` hears the named events the app's services `emit`, on the web and the desktop. A page may have an `icon` (the sidebar then shows icon rows), a `use_badge` hook ("Inbox · 3"), `in_sidebar: false` with `active_as` for a page reached only by its route; `default_page` names the page an empty route opens, and the `use_chrome(parts)` hook gives the `sidebar` content under the rows, header `tools` and a `side_pane`. |
18
18
  | `config/vite`, `config/electron_vite`, `config/vitest`, `config/tsconfig/*.json` | An X-app's configs as presets: `web_vite_config({ port })` and `android_vite_config()` for the page, `desktop_vite_config()` for electron-vite's window, daemon, preload and page, `vitest_config()` for tests in `tests/` in UTC with coverage of `src/` to the terminal, merged with the app's own floor so `autoUpdate` still raises it, and `base`, `node`, `web` and `tests` tsconfigs to extend. |
19
19
  | `app_new` | The `x-app-new <X-Name>` command: a new X-app's files written once, laid out as the Application Standard asks, on the base app, the presets, X-App's Nix lib and its CI actions, with an example notes feature; `--port`, `--folder`, `--no-desktop` and `--no-android`. |
@@ -7,6 +7,7 @@ import { hostname } from "node:os";
7
7
  import { dirname, join } from "node:path";
8
8
  import fastify from "fastify";
9
9
  import { create_certificate_trust } from "../certificates.js";
10
+ import { create_local_mcp } from "../electron/mcp.js";
10
11
  import { DaemonRunningError, daemon_socket_path, listen_on_socket } from "../local_daemon.js";
11
12
  import { register_call_table } from "../server/call_table.js";
12
13
  import { EventStream } from "../server/events.js";
@@ -57,6 +58,20 @@ export async function start_daemon(app, options) {
57
58
  stop_daemon: () => void setTimeout(() => void shut_down(), 0),
58
59
  set_window_in_front: (in_front) => void (window_in_front = in_front === true),
59
60
  };
61
+ // Off until turned on in Settings; a change made through it reaches the open windows and syncs like any other.
62
+ const local_mcp = app.local_mcp
63
+ ? create_local_mcp({
64
+ name: app.id,
65
+ version: app.version,
66
+ instructions: app.instructions,
67
+ api: app.api_spec,
68
+ is_read_only: app.is_read_only,
69
+ page_only: app.page_only,
70
+ settings_file: join(profile, "mcp.json"),
71
+ default_port: app.local_mcp.default_port,
72
+ call: (method, args) => app.bridges.calls.dispatch(app.bind_methods(opened.database, () => changes.announce_change(), "program"), method, args),
73
+ })
74
+ : null;
60
75
  // ── Calls ──────────────────────────────────────────────────────────
61
76
  const daemon = fastify({ bodyLimit: call_body_limit, forceCloseConnections: true });
62
77
  register_lenient_json_body(daemon);
@@ -71,6 +86,8 @@ export async function start_daemon(app, options) {
71
86
  register_call_table(api, "/device", sync_device_methods(sync), { is_read_only, on_change: tell_others });
72
87
  register_call_table(api, "/peer_listening", listening.methods, { is_read_only });
73
88
  register_call_table(api, "/certificates", certificates.methods, { is_read_only });
89
+ if (local_mcp)
90
+ register_call_table(api, "/local_mcp", local_mcp.methods, { is_read_only });
74
91
  register_call_table(api, "/daemon", daemon_methods, { is_read_only, on_change: tell_others });
75
92
  }, { prefix: "/api" });
76
93
  // ── Lifecycle ──────────────────────────────────────────────────────
@@ -83,6 +100,7 @@ export async function start_daemon(app, options) {
83
100
  clearInterval(unused_timer);
84
101
  await services.stop();
85
102
  sync.stop();
103
+ await local_mcp?.stop();
86
104
  await daemon.close();
87
105
  await listening.stop();
88
106
  sides.close_all();
@@ -104,6 +122,7 @@ export async function start_daemon(app, options) {
104
122
  }
105
123
  await listening.start();
106
124
  sync.start();
125
+ await local_mcp?.start();
107
126
  if (options.services) {
108
127
  services = await options.services({
109
128
  kind: "desktop",
@@ -7,6 +7,7 @@ import { type ConnectionMethods } from "../connection_protocol.ts";
7
7
  import { type Bridge } from "../electron/bridge.ts";
8
8
  import { type EventsBridge } from "../electron/events.ts";
9
9
  import type { History } from "../history.ts";
10
+ import { type LocalMcpMethods } from "../local_mcp_protocol.ts";
10
11
  import { type SettingSpec, type SettingsMethods, type SettingsStore, type SettingsStoreOptions } from "../settings.ts";
11
12
  import { type MigrationStep, type SqlDatabase } from "../sql.ts";
12
13
  import { type SyncedTable } from "../sync_engine.ts";
@@ -56,6 +57,9 @@ export interface AppOptions<Features extends readonly Feature[]> {
56
57
  token_prefix?: string;
57
58
  desktop_settings?: Readonly<Record<string, DesktopSettingSpec>>;
58
59
  link_scheme?: string;
60
+ local_mcp?: {
61
+ default_port: number;
62
+ };
59
63
  }
60
64
  export declare const base_setting_defaults: {
61
65
  history_days: number;
@@ -81,6 +85,7 @@ export interface AppBridges<Methods extends Record<keyof Methods, (...args: neve
81
85
  certificates: Bridge<CertificateMethods>;
82
86
  desktop: Bridge<DesktopMethods>;
83
87
  connections: Bridge<ConnectionMethods>;
88
+ local_mcp: Bridge<LocalMcpMethods>;
84
89
  events: EventsBridge<AppEvents>;
85
90
  }
86
91
  export declare function define_app<const Features extends readonly Feature[]>(options: AppOptions<Features>): {
@@ -105,6 +110,9 @@ export declare function define_app<const Features extends readonly Feature[]>(op
105
110
  token_prefix?: string;
106
111
  desktop_settings?: Readonly<Record<string, DesktopSettingSpec>>;
107
112
  link_scheme?: string;
113
+ local_mcp?: {
114
+ default_port: number;
115
+ };
108
116
  features: readonly Feature<Record<string, StoreMethod>>[];
109
117
  settings_store: SettingsStore;
110
118
  setting_defaults: Readonly<import("../settings.ts").Settings>;
@@ -10,6 +10,7 @@ import { certificate_method_names } from "../certificate_protocol.js";
10
10
  import { connection_method_names } from "../connection_protocol.js";
11
11
  import { define_bridge } from "../electron/bridge.js";
12
12
  import { define_events } from "../electron/events.js";
13
+ import { local_mcp_method_names } from "../local_mcp_protocol.js";
13
14
  import { create_settings_store, read_setting, settings_of, write_setting } from "../settings.js";
14
15
  import { migrate } from "../sql.js";
15
16
  import { create_sync_engine } from "../sync_engine.js";
@@ -158,6 +159,8 @@ export function define_app(options) {
158
159
  desktop: define_bridge(`${prefix}_desktop`, desktop_method_names),
159
160
  // The daemons the desktop app can work on: this computer's, or a server signed in to as this device.
160
161
  connections: define_bridge(`${prefix}_connections`, connection_method_names),
162
+ // The desktop app's own MCP endpoint, for AI clients on the same computer.
163
+ local_mcp: define_bridge(`${prefix}_local_mcp`, local_mcp_method_names),
161
164
  events: define_events(`${prefix}_events`),
162
165
  };
163
166
  return {
@@ -2,7 +2,7 @@ import { type AutostartOptions } from "../autostart.ts";
2
2
  import { type AppLike, type FocusableWindowLike } from "../electron/app.ts";
3
3
  import type { IpcMainLike } from "../electron/bridge.ts";
4
4
  import type { WindowLike } from "../electron/events.ts";
5
- import { type TrayElectronLike, type TrayRow } from "../electron/tray.ts";
5
+ import { type TrayElectronLike, type TrayLike, type TrayRow } from "../electron/tray.ts";
6
6
  import { type BrowserWindowLike, type BrowserWindowOptionsLike, type NativeThemeLike, type ScreenLike, type ShellLike } from "../electron/window.ts";
7
7
  import { call_daemon, start_daemon } from "../local_daemon.ts";
8
8
  import type { App } from "./define.ts";
@@ -41,9 +41,16 @@ export interface ElectronLike {
41
41
  };
42
42
  };
43
43
  shell: ShellLike;
44
- Tray?: TrayElectronLike<unknown>["Tray"];
44
+ Tray?: new (image: never) => TrayLike;
45
45
  Menu?: TrayElectronLike<unknown>["Menu"];
46
- nativeImage?: TrayElectronLike<unknown>["nativeImage"];
46
+ nativeImage?: {
47
+ createFromPath(path: string): {
48
+ resize(size: {
49
+ width: number;
50
+ height: number;
51
+ }): unknown;
52
+ };
53
+ };
47
54
  }
48
55
  export interface TrayTools {
49
56
  call: (method: string, args?: unknown[]) => Promise<unknown>;
@@ -4,10 +4,11 @@
4
4
  // ── Imports ──────────────────────────────────────────────────────────────────
5
5
  import { unwatchFile, watchFile } from "node:fs";
6
6
  import { hostname } from "node:os";
7
- import { join } from "node:path";
7
+ import { join, resolve } from "node:path";
8
8
  import { launch_command, set_autostart } from "../autostart.js";
9
9
  import { backup_method_names } from "../backups.js";
10
10
  import { certificate_method_names } from "../certificate_protocol.js";
11
+ import { local_mcp_method_names } from "../local_mcp_protocol.js";
11
12
  import { create_certificate_trust } from "../certificates.js";
12
13
  import { connection_file_storage } from "../connection_file_storage.js";
13
14
  import { create_connections } from "../connections.js";
@@ -33,7 +34,7 @@ export function run_desktop(app, electron, options) {
33
34
  const own_profile = env[`${prefix}_USER_DATA`];
34
35
  const is_own_profile = own_profile === undefined;
35
36
  if (!is_own_profile)
36
- electron.app.setPath("userData", join(options.cwd ?? process.cwd(), own_profile));
37
+ electron.app.setPath("userData", resolve(options.cwd ?? process.cwd(), own_profile));
37
38
  const profile = electron.app.getPath("userData");
38
39
  const database_path = join(profile, app.database_file);
39
40
  // Any other profile gets a daemon, socket and log of its own, so a dev or test run never reaches the user's daemon.
@@ -186,6 +187,8 @@ export function run_desktop(app, electron, options) {
186
187
  bridges.peer_listening.handle(ipcMain, forwarded(peer_listening_method_names, "peer_listening"), handle_options);
187
188
  bridges.certificates.handle(ipcMain, forwarded(certificate_method_names, "certificates"), handle_options);
188
189
  bridges.connections.handle(ipcMain, connections.methods, handle_options);
190
+ if (app.local_mcp)
191
+ bridges.local_mcp.handle(ipcMain, forwarded(local_mcp_method_names, "local_mcp"), handle_options);
189
192
  const desktop = {
190
193
  get_desktop_settings,
191
194
  set_desktop_setting: async (key, value) => {
@@ -6,5 +6,7 @@ export function run_preload(app, { contextBridge, ipcRenderer }) {
6
6
  for (const bridge of [bridges.calls, bridges.device, bridges.backups, bridges.certificates, bridges.peer_listening, bridges.desktop, bridges.connections]) {
7
7
  bridge.expose(contextBridge, ipcRenderer, { envelopes: true });
8
8
  }
9
+ if (app.local_mcp)
10
+ bridges.local_mcp.expose(contextBridge, ipcRenderer, { envelopes: true });
9
11
  bridges.events.expose(contextBridge, ipcRenderer);
10
12
  }
@@ -1,6 +1,7 @@
1
1
  import type { BackupClient } from "../backups.ts";
2
2
  import type { CertificateClient } from "../certificate_protocol.ts";
3
3
  import type { ConnectionClient } from "../connection_protocol.ts";
4
+ import type { LocalMcpClient } from "../local_mcp_protocol.ts";
4
5
  import type { Client } from "../electron/bridge.ts";
5
6
  import type { PeerListeningClient, SyncDeviceClient } from "../sync_protocol.ts";
6
7
  export interface DesktopSettings {
@@ -43,6 +44,7 @@ export interface PageApi<Methods extends Record<keyof Methods, (...args: never[]
43
44
  connections?: ConnectionClient;
44
45
  peer_listening?: PeerListeningClient;
45
46
  desktop?: Client<DesktopMethods>;
47
+ local_mcp?: LocalMcpClient;
46
48
  on_change: (listener: () => void) => () => void;
47
49
  on_event?: (event: string, listener: (data: unknown) => void) => () => void;
48
50
  }
@@ -2,5 +2,5 @@ import type { App } from "../define.ts";
2
2
  import type { PageApi } from "../protocol.ts";
3
3
  export declare function web_api(app: Pick<App, "bridges">): PageApi;
4
4
  export declare function is_desktop(app: Pick<App, "bridges">): boolean;
5
- export declare function desktop_api(app: Pick<App, "bridges">): Promise<PageApi>;
5
+ export declare function desktop_api(app: Pick<App, "bridges"> & Partial<Pick<App, "local_mcp">>): Promise<PageApi>;
6
6
  export declare function is_android(): boolean;
@@ -109,6 +109,7 @@ export async function desktop_api(app) {
109
109
  // Sync belongs to this computer's own daemon, so it shows only while that daemon is in use.
110
110
  device: is_here ? exposed[bridges.device.api_name] : null,
111
111
  ...(is_here ? { peer_listening: exposed[bridges.peer_listening.api_name] } : {}),
112
+ ...(is_here && app.local_mcp ? { local_mcp: exposed[bridges.local_mcp.api_name] } : {}),
112
113
  backups: exposed[bridges.backups.api_name],
113
114
  certificates: exposed[bridges.certificates.api_name],
114
115
  connections,
@@ -6,6 +6,7 @@ import { useEffect, useState } from "react";
6
6
  import { BackupSettings } from "../../web/react/backup_settings.js";
7
7
  import { TrustedCertificates } from "../../web/react/certificates.js";
8
8
  import { ConnectionSettings } from "../../web/react/connections.js";
9
+ import { LocalMcpSettings } from "../../web/react/local_mcp_settings.js";
9
10
  import { Switch } from "../../web/react/controls.js";
10
11
  import { PageHeading, SettingRow, SettingsPage } from "../../web/react/layout.js";
11
12
  import { Loaded } from "../../web/react/states.js";
@@ -36,7 +37,7 @@ function Desktop({ app_name, own }) {
36
37
  }
37
38
  // A desktop window on a server's daemon works on the server's data, as a browser does.
38
39
  function storage_category(app, is_admin) {
39
- const { backups, backup_folder, certificates, connections, desktop, device, host, peer_listening } = page();
40
+ const { backups, backup_folder, certificates, connections, desktop, device, host, local_mcp, peer_listening } = page();
40
41
  const { data_name, name } = app;
41
42
  const on_server = host === "web" || (host === "desktop" && !device);
42
43
  const sections = [];
@@ -45,6 +46,8 @@ function storage_category(app, is_admin) {
45
46
  }
46
47
  if (desktop)
47
48
  sections.push({ id: "desktop", heading: "Desktop app", content: _jsx(Desktop, { app_name: name, own: app.desktop_settings ?? {} }) });
49
+ if (local_mcp)
50
+ sections.push({ id: "mcp", heading: "MCP server", hint: `Let AI assistants such as Claude Code reach this computer's ${data_name} without the server.`, content: _jsx(LocalMcpSettings, { device: local_mcp, name: name }) });
48
51
  if (device && (!on_server || is_admin)) {
49
52
  const hint = on_server ? `Keep the server's ${data_name} alike with the devices paired with it.` : `Keep this device's ${data_name} alike with your other devices and your ${name} server.`;
50
53
  sections.push({ id: "sync", heading: "Sync", hint, content: _jsx(SyncSettings, { device: device, subscribe: (listener) => data_watch.subscribe(listener), data_name: data_name, extra: peer_listening && _jsx(PeerListeningSettings, { listening: peer_listening }) }) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-tech-laboratories/x-app",
3
- "version": "0.105.0",
3
+ "version": "0.106.1",
4
4
  "description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {