@x-tech-laboratories/x-app 0.117.0 → 0.119.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +21 -8
  2. package/dist/agent/claude_stream.d.ts +22 -0
  3. package/dist/agent/claude_stream.js +85 -0
  4. package/dist/agent/git.d.ts +37 -0
  5. package/dist/agent/git.js +121 -0
  6. package/dist/agent/github.d.ts +81 -0
  7. package/dist/agent/github.js +185 -0
  8. package/dist/agent/programs.d.ts +17 -0
  9. package/dist/agent/programs.js +62 -0
  10. package/dist/agent/worktree_files.d.ts +20 -0
  11. package/dist/agent/worktree_files.js +69 -0
  12. package/dist/agent_transcript.d.ts +83 -0
  13. package/dist/agent_transcript.js +267 -0
  14. package/dist/app/daemon.js +2 -2
  15. package/dist/app/define.d.ts +7 -2
  16. package/dist/app/define.js +13 -0
  17. package/dist/app/desktop.js +2 -2
  18. package/dist/app/protocol.d.ts +3 -1
  19. package/dist/app/protocol.js +1 -0
  20. package/dist/app/server.d.ts +1 -0
  21. package/dist/app/server.js +13 -2
  22. package/dist/app/web/android.js +8 -1
  23. package/dist/app/web/hosts.d.ts +1 -1
  24. package/dist/app/web/hosts.js +5 -4
  25. package/dist/connection_protocol.d.ts +1 -0
  26. package/dist/connection_protocol.js +11 -0
  27. package/dist/daemon_router.d.ts +2 -2
  28. package/dist/daemon_router.js +3 -2
  29. package/dist/diff_rows.d.ts +78 -0
  30. package/dist/diff_rows.js +158 -0
  31. package/dist/frontmatter.d.ts +10 -0
  32. package/dist/frontmatter.js +57 -0
  33. package/dist/frontmatter_folder.d.ts +24 -0
  34. package/dist/frontmatter_folder.js +54 -0
  35. package/dist/history.js +14 -1
  36. package/dist/server/config.d.ts +2 -0
  37. package/dist/server/config.js +15 -1
  38. package/dist/server/events.d.ts +2 -0
  39. package/dist/server/events.js +3 -1
  40. package/dist/server/github_webhook.d.ts +30 -0
  41. package/dist/server/github_webhook.js +146 -0
  42. package/dist/sync_engine.d.ts +5 -0
  43. package/dist/sync_engine.js +63 -9
  44. package/dist/sync_protocol.d.ts +4 -0
  45. package/dist/sync_protocol.js +11 -0
  46. package/dist/test_helpers.d.ts +7 -0
  47. package/dist/test_helpers.js +44 -0
  48. package/dist/web/react/accounts.js +2 -1
  49. package/dist/web/react/controls.d.ts +3 -2
  50. package/dist/web/react/controls.js +6 -4
  51. package/dist/web/react/copy_button.d.ts +11 -0
  52. package/dist/web/react/copy_button.js +44 -0
  53. package/dist/web/react/dialog.js +2 -2
  54. package/dist/web/react/diff.d.ts +26 -0
  55. package/dist/web/react/diff.js +79 -0
  56. package/dist/web/react/file_tree.d.ts +26 -0
  57. package/dist/web/react/file_tree.js +46 -0
  58. package/dist/web/react/local_mcp_settings.js +2 -1
  59. package/dist/web/react/transcript.d.ts +24 -0
  60. package/dist/web/react/transcript.js +100 -0
  61. package/dist/web/tree.d.ts +3 -1
  62. package/dist/web/tree.js +38 -10
  63. package/package.json +5 -3
@@ -63,7 +63,13 @@ function add_missing_state_columns(database) {
63
63
  }
64
64
  // ── Engine ───────────────────────────────────────────────────────────────────
65
65
  export function create_sync_engine(options) {
66
- const tables = options.tables.map((table) => ({ ...table, local_columns: table.local_columns ?? [], local_keys: table.local_keys ?? [], map_columns: table.map_columns ?? [] }));
66
+ const tables = options.tables.map((table) => ({
67
+ ...table,
68
+ local_columns: table.local_columns ?? [],
69
+ local_keys: table.local_keys ?? [],
70
+ map_columns: table.map_columns ?? [],
71
+ rows_never_change: table.rows_never_change ?? false,
72
+ }));
67
73
  const tables_by_name = new Map(tables.map((table) => [table.name, table]));
68
74
  // The map column and key a cell names, or null for a cell of a whole value.
69
75
  function split_map_cell(table, cell_name) {
@@ -84,6 +90,10 @@ export function create_sync_engine(options) {
84
90
  function column_names(database, table) {
85
91
  return database.prepare(`PRAGMA table_info("${table.name}")`).all().map((column) => column.name);
86
92
  }
93
+ // The columns that keep a version of their own; a row that never changes keeps only the one saying it exists.
94
+ function stamped_columns(database, table) {
95
+ return table.rows_never_change ? [] : synced_columns(database, table);
96
+ }
87
97
  // The columns that sync as one value each.
88
98
  function synced_columns(database, table) {
89
99
  return column_names(database, table).filter((name) => !table.local_columns.includes(name) && !table.map_columns.includes(name));
@@ -144,8 +154,8 @@ export function create_sync_engine(options) {
144
154
  drop_triggers(database);
145
155
  const is_local = "(SELECT is_applying FROM sync_state) = 0";
146
156
  for (const table of tables) {
147
- const columns = synced_columns(database, table);
148
- const map_columns = synced_map_columns(database, table);
157
+ const columns = stamped_columns(database, table);
158
+ const map_columns = table.rows_never_change ? [] : synced_map_columns(database, table);
149
159
  const new_key = key_sql(table, "NEW");
150
160
  const old_key = key_sql(table, "OLD");
151
161
  database.exec(`CREATE TRIGGER ${trigger_name(table, "insert")} AFTER INSERT ON "${table.name}"
@@ -158,7 +168,8 @@ export function create_sync_engine(options) {
158
168
  ...columns.map((column) => stamp_cell_sql(table, new_key, column, `OLD."${column}" IS NOT NEW."${column}"`)),
159
169
  ...map_columns.map((column) => stamp_map_sql(table, new_key, column, changed_keys_sql(column))),
160
170
  ];
161
- database.exec(`CREATE TRIGGER ${trigger_name(table, "update")} AFTER UPDATE ON "${table.name}"
171
+ if (update_steps.length > 0)
172
+ database.exec(`CREATE TRIGGER ${trigger_name(table, "update")} AFTER UPDATE ON "${table.name}"
162
173
  WHEN ${is_local} AND ${filter_sql(table, "NEW")}
163
174
  BEGIN ${update_steps.join("\n")} END`);
164
175
  database.exec(`CREATE TRIGGER ${trigger_name(table, "delete")} AFTER DELETE ON "${table.name}"
@@ -166,18 +177,34 @@ export function create_sync_engine(options) {
166
177
  BEGIN ${stamp_cell_sql(table, old_key, exists_column)} END`);
167
178
  }
168
179
  backfill_cells(database);
180
+ compact_unchanging_rows(database);
181
+ }
182
+ // A row that never changes needs only its existence cell, which takes the newest version any of its cells had.
183
+ function compact_unchanging_rows(database) {
184
+ for (const table of tables.filter((each) => each.rows_never_change)) {
185
+ const has_extra = database.prepare("SELECT 1 FROM sync_cells WHERE table_name = ? AND column_name != ? LIMIT 1").get(table.name, exists_column);
186
+ if (!has_extra)
187
+ continue;
188
+ database
189
+ .prepare(`UPDATE sync_cells AS row_cell SET
190
+ ts = (SELECT max(ts) FROM sync_cells AS cell WHERE cell.table_name = row_cell.table_name AND cell.row_key = row_cell.row_key),
191
+ seq = (SELECT max(seq) FROM sync_cells AS cell WHERE cell.table_name = row_cell.table_name AND cell.row_key = row_cell.row_key)
192
+ WHERE table_name = ? AND column_name = ?`)
193
+ .run(table.name, exists_column);
194
+ database.prepare("DELETE FROM sync_cells WHERE table_name = ? AND column_name != ?").run(table.name, exists_column);
195
+ }
169
196
  }
170
197
  // Rows written before sync existed, and columns added since, get a version older than any real write.
171
198
  function backfill_cells(database) {
172
199
  for (const table of tables) {
173
- for (const column of [exists_column, ...synced_columns(database, table)]) {
200
+ for (const column of [exists_column, ...stamped_columns(database, table)]) {
174
201
  database
175
202
  .prepare(`INSERT OR IGNORE INTO sync_cells (table_name, row_key, column_name, ts, site, seq)
176
203
  SELECT '${table.name}', ${key_sql(table, "row")}, '${column}', 0, '', 0 FROM "${table.name}" AS row WHERE ${filter_sql(table, "row")}`)
177
204
  .run();
178
205
  }
179
206
  // A column that has just become a map column gives each of its keys the version the whole value had.
180
- for (const column of synced_map_columns(database, table)) {
207
+ for (const column of table.rows_never_change ? [] : synced_map_columns(database, table)) {
181
208
  const row_key = key_sql(table, "row");
182
209
  database
183
210
  .prepare(`INSERT OR IGNORE INTO sync_cells (table_name, row_key, column_name, ts, site, seq)
@@ -254,6 +281,13 @@ export function create_sync_engine(options) {
254
281
  return row.count;
255
282
  }
256
283
  // ── Reading changes ──────────────────────────────────────────────────────
284
+ // The synced tables with a change after the cursor, and how far that reaches; tables with rows kept on one device always count, as those rows' writes leave no version.
285
+ function changed_tables_since(database, cursor) {
286
+ const { last_seq } = read_state(database);
287
+ const stamped = database.prepare("SELECT DISTINCT table_name FROM sync_cells WHERE seq > ? AND seq <= ?").all(cursor, last_seq).map((row) => row.table_name);
288
+ const unstamped = tables.filter((table) => table.local_keys.length > 0).map((table) => table.name);
289
+ return { tables: [...new Set([...stamped, ...unstamped])], up_to_seq: last_seq };
290
+ }
257
291
  function read_row(database, table, row_key) {
258
292
  return database.prepare(`SELECT * FROM "${table.name}" AS row WHERE ${key_sql(table, "row")} = ? AND ${filter_sql(table, "row")}`).get(row_key);
259
293
  }
@@ -271,8 +305,14 @@ export function create_sync_engine(options) {
271
305
  const row = rows.get(row_id);
272
306
  const base = { table: cell.table_name, key: cell.row_key, column: cell.column_name, ts: cell.ts, site: cell.site };
273
307
  const map_cell = split_map_cell(table, cell.column_name);
274
- if (cell.column_name === exists_column)
308
+ if (cell.column_name === exists_column) {
275
309
  changes.push({ ...base, value: row ? 1 : 0 });
310
+ // A row that never changes sends all its values under the version of its existence.
311
+ if (row && table.rows_never_change) {
312
+ for (const column of Object.keys(row).filter((name) => !table.local_columns.includes(name)))
313
+ changes.push({ ...base, column, value: row[column] });
314
+ }
315
+ }
276
316
  else if (map_cell) {
277
317
  if (row && map_cell.column in row)
278
318
  changes.push({ ...base, value: object_of(row[map_cell.column])[map_cell.key] ?? null });
@@ -328,18 +368,30 @@ export function create_sync_engine(options) {
328
368
  if (exists_change.value === 1 && !exists) {
329
369
  const values = [
330
370
  ...changes.filter((change) => change.column !== exists_column && known_columns.includes(change.column)).map((change) => [change.column, change.value]),
331
- ...known_map_columns.map((column) => [column, "{}"]),
371
+ ...known_map_columns.map((column) => [column, table.rows_never_change ? (changes.find((change) => change.column === column)?.value ?? "{}") : "{}"]),
332
372
  ];
333
373
  database
334
374
  .prepare(`INSERT INTO "${table.name}" (${values.map(([column]) => `"${column}"`).join(", ")}) VALUES (${values.map(() => "?").join(", ")})`)
335
375
  .run(...values.map(([, value]) => value));
336
376
  exists = true;
337
377
  }
378
+ // A newer version of a row that never changes replaces its values, so devices that each wrote it end alike.
379
+ else if (exists_change.value === 1 && table.rows_never_change) {
380
+ const values = changes.filter((change) => change.column !== exists_column && known_columns.includes(change.column));
381
+ for (const change of values) {
382
+ database
383
+ .prepare(`UPDATE "${table.name}" SET "${change.column}" = ? WHERE rowid IN (SELECT rowid FROM "${table.name}" AS row WHERE ${where_row})`)
384
+ .run(change.value, row_key);
385
+ }
386
+ }
338
387
  if (exists_change.value === 0 && exists) {
339
388
  database.prepare(`DELETE FROM "${table.name}" WHERE rowid IN (SELECT rowid FROM "${table.name}" AS row WHERE ${where_row})`).run(row_key);
340
389
  exists = false;
341
390
  }
342
391
  }
392
+ // A row that never changes took its values with its existence above.
393
+ if (table.rows_never_change)
394
+ return applied;
343
395
  for (const change of changes) {
344
396
  const map_cell = split_map_cell(table, change.column);
345
397
  const is_known = map_cell ? known_map_columns.includes(map_cell.column) : known_columns.includes(change.column);
@@ -423,7 +475,8 @@ export function create_sync_engine(options) {
423
475
  const add_cell = database.prepare("INSERT OR IGNORE INTO sync_cells (table_name, row_key, column_name, ts, site, seq) VALUES (?, ?, ?, ?, '', 0)");
424
476
  for (const change of theirs) {
425
477
  const table = tables_by_name.get(change.table);
426
- if (table && !table.local_keys.includes(change.key))
478
+ const is_unstamped = table?.rows_never_change && change.column !== exists_column;
479
+ if (table && !table.local_keys.includes(change.key) && !is_unstamped)
427
480
  add_cell.run(change.table, change.key, change.column, change.ts);
428
481
  }
429
482
  const newest_here = database.prepare("SELECT coalesce(max(ts), 0) AS ts FROM sync_cells").get().ts;
@@ -452,6 +505,7 @@ export function create_sync_engine(options) {
452
505
  has_unsent_changes,
453
506
  count_unsent_rows,
454
507
  collect_changes_since,
508
+ changed_tables_since,
455
509
  collect_snapshot,
456
510
  apply_changes,
457
511
  claim_everything,
@@ -180,3 +180,7 @@ export declare const peer_listening_method_names: readonly ["get_peer_listening"
180
180
  export type PeerListeningClient = {
181
181
  [Name in keyof PeerListeningMethods]: (...args: Parameters<PeerListeningMethods[Name]>) => Promise<Awaited<ReturnType<PeerListeningMethods[Name]>>>;
182
182
  };
183
+ export interface DataChange {
184
+ tables: readonly string[];
185
+ }
186
+ export declare function data_change_of(text: string): DataChange | null;
@@ -22,3 +22,14 @@ export const sync_device_method_names = [
22
22
  "sync_now",
23
23
  ];
24
24
  export const peer_listening_method_names = ["get_peer_listening", "set_peer_listening"];
25
+ // A change event's data as sent; anything else, such as an older daemon's empty data, means anything may have changed.
26
+ export function data_change_of(text) {
27
+ try {
28
+ const parsed = JSON.parse(text);
29
+ const tables = parsed?.tables;
30
+ return Array.isArray(tables) && tables.every((table) => typeof table === "string") ? { tables } : null;
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ }
@@ -0,0 +1,7 @@
1
+ export declare function free_port(): Promise<number>;
2
+ export declare function temp_folder(name: string): string;
3
+ export declare function make_checkout(name?: string): string;
4
+ export declare function self_signed_certificate(): {
5
+ certificate_file: string;
6
+ key_file: string;
7
+ };
@@ -0,0 +1,44 @@
1
+ // Helpers an app's tests share when they reach servers and repositories for real, on this machine alone: a free port
2
+ // on the loopback address, throwaway folders, a git checkout with one commit, and a certificate that signs itself for
3
+ // localhost, as a home server's often does. The checkout needs git and the certificate openssl on the PATH.
4
+ // ── Imports ──────────────────────────────────────────────────────────────────
5
+ import { execFileSync } from "node:child_process";
6
+ import { mkdtempSync, writeFileSync } from "node:fs";
7
+ import { createServer } from "node:net";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+ // ── Ports and folders ────────────────────────────────────────────────────────
11
+ // A port nothing listens on, found by asking for any port on the loopback address.
12
+ export function free_port() {
13
+ return new Promise((resolve, reject) => {
14
+ const probe = createServer();
15
+ probe.on("error", reject);
16
+ probe.listen(0, "127.0.0.1", () => {
17
+ const { port } = probe.address();
18
+ probe.close(() => resolve(port));
19
+ });
20
+ });
21
+ }
22
+ // A new empty folder under the system's temporary folder, its name starting with the one given.
23
+ export function temp_folder(name) {
24
+ return mkdtempSync(join(tmpdir(), `${name}-`));
25
+ }
26
+ // A throwaway git checkout on branch main with one commit holding a README, as a test's stand-in repository.
27
+ export function make_checkout(name = "checkout") {
28
+ const folder = temp_folder(name);
29
+ const git = (...args) => execFileSync("git", ["-c", "user.name=Test", "-c", "user.email=test@example.org", ...args], { cwd: folder, stdio: "ignore" });
30
+ git("init", "-q", "-b", "main");
31
+ writeFileSync(join(folder, "README.md"), "# Test\n");
32
+ git("add", ".");
33
+ git("commit", "-q", "-m", "chore: start");
34
+ return folder;
35
+ }
36
+ // ── Certificates ─────────────────────────────────────────────────────────────
37
+ // A certificate that signs itself for localhost and 127.0.0.1, valid for a month, and its key, in a folder of their own.
38
+ export function self_signed_certificate() {
39
+ const folder = temp_folder("certificate");
40
+ const certificate_file = join(folder, "server.pem");
41
+ const key_file = join(folder, "server.key");
42
+ execFileSync("openssl", ["req", "-x509", "-newkey", "ec", "-pkeyopt", "ec_paramgen_curve:P-256", "-nodes", "-keyout", key_file, "-out", certificate_file, "-days", "30", "-subj", "/CN=localhost", "-addext", "subjectAltName=DNS:localhost,IP:127.0.0.1"], { stdio: "ignore" });
43
+ return { certificate_file, key_file };
44
+ }
@@ -14,6 +14,7 @@ import { Facts, FormRow, PageHeading, Section } from "./layout.js";
14
14
  import { Empty, Loaded, use_resource } from "./states.js";
15
15
  import { DataTable } from "./table.js";
16
16
  import { Age } from "./time.js";
17
+ import { CopyButton } from "./copy_button.js";
17
18
  import { toast } from "./toasts.js";
18
19
  const default_access_text = (access) => access === null ? "everything" : "limited";
19
20
  export function AccountView({ client, on_change, ...words }) {
@@ -311,7 +312,7 @@ function reset_totp(client, user, refresh) {
311
312
  // A secret the server hands out once, with a button to copy it.
312
313
  export function show_once(title, note, lines) {
313
314
  const text = lines.join("\n");
314
- open_dialog((close) => (_jsx(Dialog, { title: title, on_close: close, buttons: _jsxs(_Fragment, { children: [_jsx("button", { onClick: () => void navigator.clipboard?.writeText(text).then(() => toast("Copied.")), children: "Copy" }), _jsx("button", { className: "accent solid", onClick: close, children: "I have saved it" })] }), children: _jsxs("div", { children: [_jsx("p", { children: note }), _jsx("pre", { className: "output secret-once", children: text })] }) })));
315
+ open_dialog((close) => (_jsx(Dialog, { title: title, on_close: close, buttons: _jsxs(_Fragment, { children: [_jsx(CopyButton, { text: text }), _jsx("button", { className: "accent solid", onClick: close, children: "I have saved it" })] }), children: _jsxs("div", { children: [_jsx("p", { children: note }), _jsx("pre", { className: "output secret-once", children: text })] }) })));
315
316
  }
316
317
  // The server's words for a refusal, passing on anything else, such as a lapsed session.
317
318
  function refusal_of(error) {
@@ -46,8 +46,9 @@ interface SelectProps<Value extends string | number> {
46
46
  on_change: (value: Value) => void;
47
47
  bare?: boolean;
48
48
  id?: string;
49
+ disabled?: boolean;
49
50
  }
50
- export declare function Select<Value extends string | number>({ label, options, groups, value, on_change, bare, id }: SelectProps<Value>): import("react").JSX.Element;
51
+ export declare function Select<Value extends string | number>({ label, options, groups, value, on_change, bare, id, disabled }: SelectProps<Value>): import("react").JSX.Element;
51
52
  type CommitInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "defaultValue" | "onChange"> & {
52
53
  value: string | number;
53
54
  on_commit: (event: {
@@ -86,7 +87,7 @@ interface PathInputProps {
86
87
  label: string;
87
88
  value: string;
88
89
  on_change: (value: string) => void;
89
- pick: (current: string) => Promise<string | null>;
90
+ pick?: (current: string) => Promise<string | null>;
90
91
  placeholder?: string;
91
92
  disabled?: boolean;
92
93
  browse_label?: string;
@@ -106,14 +106,14 @@ export function SearchBox({ label, value, on_input, on_submit, on_paste, submit_
106
106
  return input;
107
107
  return (_jsxs("form", { className: "search-box", role: "search", onSubmit: (event) => { event.preventDefault(); submit(); }, children: [input, _jsx("button", { type: "submit", className: "accent solid", children: submit_label })] }));
108
108
  }
109
- export function Select({ label, options, groups = [], value, on_change, bare = false, id }) {
109
+ export function Select({ label, options, groups = [], value, on_change, bare = false, id, disabled = false }) {
110
110
  const shown_groups = groups.filter((group) => group.options.length > 0);
111
111
  const change = (event) => {
112
112
  const text = event.currentTarget.value;
113
113
  const every = [...options, ...shown_groups.flatMap((group) => group.options)];
114
114
  on_change((every.find(([option]) => String(option) === text)?.[0] ?? text));
115
115
  };
116
- const select = (_jsxs("select", { id: id, value: value, "aria-label": bare ? label : undefined, onChange: change, children: [options.map(([option, text]) => _jsx("option", { value: option, children: text }, option)), shown_groups.map((group) => (_jsx("optgroup", { label: group.label, children: group.options.map(([option, text]) => _jsx("option", { value: option, children: text }, option)) }, group.label)))] }));
116
+ const select = (_jsxs("select", { id: id, value: value, "aria-label": bare ? label : undefined, disabled: disabled, onChange: change, children: [options.map(([option, text]) => _jsx("option", { value: option, children: text }, option)), shown_groups.map((group) => (_jsx("optgroup", { label: group.label, children: group.options.map(([option, text]) => _jsx("option", { value: option, children: text }, option)) }, group.label)))] }));
117
117
  if (bare)
118
118
  return select;
119
119
  return (_jsxs("label", { className: "field", children: [_jsx("span", { className: "field-label", children: label }), select] }));
@@ -171,10 +171,12 @@ export function PeriodStepper({ label, period, value, on_change, now, locale })
171
171
  };
172
172
  return (_jsxs("div", { className: "stepper", role: "group", "aria-label": label, children: [_jsxs("div", { className: "date-time-inputs", children: [_jsx("button", { type: "button", "aria-label": `Previous ${period}`, onClick: () => shift(-1), children: "\u2039" }), _jsx("input", { type: is_daily ? "date" : "month", "aria-label": `Pick a ${period}`, value: value, onChange: (event) => pick(event.currentTarget.value) }), _jsx("button", { type: "button", "aria-label": `Next ${period}`, onClick: () => shift(1), children: "\u203A" })] }), _jsx("button", { type: "button", disabled: value === current, onClick: () => on_change(current), children: is_daily ? "Today" : "This month" }), _jsx("span", { className: "muted", children: is_daily ? relative_day_label(value, now, locale) : format_month(value, locale) })] }));
173
173
  }
174
- // A path typed by hand or picked through a Browse button.
174
+ // A path typed by hand or picked through a Browse button, when the app has a picker.
175
175
  export function PathInput({ label, value, on_change, pick, placeholder, disabled = false, browse_label = "Browse…" }) {
176
176
  const [picking, set_picking] = useState(false);
177
177
  async function browse() {
178
+ if (!pick)
179
+ return;
178
180
  set_picking(true);
179
181
  try {
180
182
  const chosen = await pick(value);
@@ -185,7 +187,7 @@ export function PathInput({ label, value, on_change, pick, placeholder, disabled
185
187
  set_picking(false);
186
188
  }
187
189
  }
188
- return (_jsxs("span", { className: "path-row", children: [_jsx("input", { type: "text", "aria-label": label, spellCheck: false, placeholder: placeholder, disabled: disabled, value: value, onChange: (event) => on_change(event.currentTarget.value) }), _jsx("button", { type: "button", disabled: disabled || picking, onClick: () => void browse(), children: browse_label })] }));
190
+ return (_jsxs("span", { className: "path-row", children: [_jsx("input", { type: "text", "aria-label": label, spellCheck: false, placeholder: placeholder, disabled: disabled, value: value, onChange: (event) => on_change(event.currentTarget.value) }), pick && _jsx("button", { type: "button", disabled: disabled || picking, onClick: () => void browse(), children: browse_label })] }));
189
191
  }
190
192
  // Swatches, a None choice, and the system colour chooser for any other colour.
191
193
  export function ColorPicker({ label, value, swatches, on_change, allow_none = true }) {
@@ -0,0 +1,11 @@
1
+ export declare function copy_text(text: string | (() => string | Promise<string>), copied_text?: string): Promise<boolean>;
2
+ interface CopyButtonProps {
3
+ text: string | (() => string | Promise<string>);
4
+ label?: string;
5
+ copied_text?: string;
6
+ class_name?: string;
7
+ title?: string;
8
+ disabled?: boolean;
9
+ }
10
+ export declare function CopyButton({ text, label, copied_text, class_name, title, disabled }: CopyButtonProps): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,44 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Copying text to the clipboard with a "Copied." toast: `CopyButton` copies what it is given, or what a function gives
3
+ // back when pressed, such as a secret fetched only then, and `copy_text` does the same from anywhere; a page the browser
4
+ // will not let copy says so instead of failing quietly.
5
+ // ── Imports ──────────────────────────────────────────────────────────────────
6
+ import { useState } from "react";
7
+ import { describe_error } from "../errors.js";
8
+ import { toast } from "./toasts.js";
9
+ // ── Copying ──────────────────────────────────────────────────────────────────
10
+ // Copies the text and says so in a toast; false when the clipboard refused it or getting the text failed.
11
+ export async function copy_text(text, copied_text = "Copied.") {
12
+ let value;
13
+ try {
14
+ value = typeof text === "function" ? await text() : text;
15
+ }
16
+ catch (error) {
17
+ toast(describe_error(error), { tone: "bad" });
18
+ return false;
19
+ }
20
+ try {
21
+ if (!navigator.clipboard)
22
+ throw new Error("no clipboard");
23
+ await navigator.clipboard.writeText(value);
24
+ }
25
+ catch {
26
+ toast("Could not copy; select the text and copy it by hand.", { tone: "bad" });
27
+ return false;
28
+ }
29
+ toast(copied_text);
30
+ return true;
31
+ }
32
+ export function CopyButton({ text, label = "Copy", copied_text = "Copied.", class_name, title, disabled = false }) {
33
+ const [busy, set_busy] = useState(false);
34
+ async function copy() {
35
+ set_busy(true);
36
+ try {
37
+ await copy_text(text, copied_text);
38
+ }
39
+ finally {
40
+ set_busy(false);
41
+ }
42
+ }
43
+ return (_jsx("button", { type: "button", className: class_name, title: title, "aria-label": title, disabled: disabled || busy, onClick: () => void copy(), children: label }));
44
+ }
@@ -2,7 +2,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  // Modal dialogs on the native one: any body and buttons, one that asks before an action, and one that shows a long text.
3
3
  import { Fragment, useEffect, useId, useRef, useState } from "react";
4
4
  import { SettingRow } from "./layout.js";
5
- import { toast } from "./toasts.js";
5
+ import { CopyButton } from "./copy_button.js";
6
6
  // Shown while it is rendered: the page behind it is inert, focus stays inside, Escape calls on_close, and focus goes back to the opener after.
7
7
  export function Dialog({ title, subtitle, actions, on_close, buttons, form, wide = false, full = false, class_name, children }) {
8
8
  const dialog = useRef(null);
@@ -49,7 +49,7 @@ export function ConfirmDialog({ options, on_close }) {
49
49
  }
50
50
  // Shows a long text result, such as a preview, with a button to copy it.
51
51
  export function TextDialog({ title, text, on_close }) {
52
- return (_jsx(Dialog, { title: title, on_close: on_close, wide: true, buttons: _jsxs(_Fragment, { children: [_jsx("button", { onClick: () => void navigator.clipboard?.writeText(text).then(() => toast("Copied.")), children: "Copy" }), _jsx("button", { className: "accent solid", onClick: on_close, children: "Close" })] }), children: _jsx("pre", { className: "output", children: text }) }));
52
+ return (_jsx(Dialog, { title: title, on_close: on_close, wide: true, buttons: _jsxs(_Fragment, { children: [_jsx(CopyButton, { text: text }), _jsx("button", { className: "accent solid", onClick: on_close, children: "Close" })] }), children: _jsx("pre", { className: "output", children: text }) }));
53
53
  }
54
54
  let open = [];
55
55
  let next_id = 1;
@@ -0,0 +1,26 @@
1
+ import { type DiffFile, type DiffFileStatus } from "../../diff_rows.ts";
2
+ import type { Tone } from "./badges.tsx";
3
+ export declare const diff_status_words: Record<DiffFileStatus, [label: string, letter: string, tone: Tone]>;
4
+ export type DiffLayout = "split" | "unified";
5
+ export declare function DiffCounts({ additions, deletions }: {
6
+ additions: number;
7
+ deletions: number;
8
+ }): import("react").JSX.Element;
9
+ interface FileDiffProps {
10
+ file: DiffFile;
11
+ layout: DiffLayout;
12
+ no_lines_text?: string;
13
+ }
14
+ export declare function FileDiff({ file, layout, no_lines_text }: FileDiffProps): import("react").JSX.Element;
15
+ export declare function FileContent({ path, text }: {
16
+ path: string;
17
+ text: string;
18
+ }): import("react").JSX.Element;
19
+ interface EditDiffProps {
20
+ path?: string;
21
+ before: string;
22
+ after: string;
23
+ limit?: number;
24
+ }
25
+ export declare function EditDiff({ path, before, after, limit }: EditDiffProps): import("react").JSX.Element;
26
+ export {};
@@ -0,0 +1,79 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // One file's change drawn from `diff_rows`: side by side with the old lines on the left and the new on the right, or
3
+ // in one column, each line numbered, removed and added lines tinted and the words that changed within them tinted again
4
+ // through Halon's diff classes, and long unchanged stretches folded behind a "show more" row; a file's text read-only
5
+ // with numbered lines; a small diff of one edit's before and after; and the added and removed line counts.
6
+ // ── Imports ──────────────────────────────────────────────────────────────────
7
+ import { Fragment, useState } from "react";
8
+ import { edit_lines, fold_rows, split_rows, unified_rows } from "../../diff_rows.js";
9
+ import { cx } from "../dom.js";
10
+ // ── Words ────────────────────────────────────────────────────────────────────
11
+ // Each status's label, its one-letter mark and its badge tone.
12
+ export const diff_status_words = {
13
+ added: ["Added", "A", "good"],
14
+ removed: ["Deleted", "D", "bad"],
15
+ renamed: ["Renamed", "R", "info"],
16
+ changed: ["Modified", "M", "warn"],
17
+ };
18
+ // ── Pieces ───────────────────────────────────────────────────────────────────
19
+ // A change's added and removed line counts, such as "+3 −1".
20
+ export function DiffCounts({ additions, deletions }) {
21
+ return (_jsxs("span", { className: "diff-counts", "aria-label": `${additions} added, ${deletions} removed`, children: [_jsxs("span", { className: "diff-count-added", children: ["+", additions] }), " ", _jsxs("span", { className: "diff-count-removed", children: ["\u2212", deletions] })] }));
22
+ }
23
+ // A line's text with its changed words marked, inside a removed or added line.
24
+ function Words({ parts, side }) {
25
+ return (_jsx("code", { children: parts.map((part, index) => part.changed && side ? (_jsx("mark", { className: "diff-word", children: part.text }, index)) : (_jsx(Fragment, { children: part.text }, index))) }));
26
+ }
27
+ function FoldRow({ fold, columns, on_open }) {
28
+ return (_jsx("tr", { className: "diff-fold", children: _jsx("td", { colSpan: columns, children: _jsxs("button", { type: "button", className: "link", onClick: () => on_open(fold.start), children: ["Show ", fold.count, " more unchanged lines"] }) }) }));
29
+ }
30
+ function HunkRow({ header, columns }) {
31
+ return (_jsx("tr", { className: "diff-hunk", children: _jsx("td", { colSpan: columns, children: _jsx("code", { children: header }) }) }));
32
+ }
33
+ function SideCells({ cell, side }) {
34
+ if (!cell) {
35
+ return (_jsxs(_Fragment, { children: [_jsx("td", { className: "diff-number diff-empty" }), _jsx("td", { className: "diff-text diff-empty" })] }));
36
+ }
37
+ const tint = side && `diff-${side}`;
38
+ return (_jsxs(_Fragment, { children: [_jsx("td", { className: cx("diff-number", tint), children: cell.number }), _jsx("td", { className: cx("diff-text", tint), "aria-label": side ?? undefined, children: _jsx(Words, { parts: cell.parts, side: side }) })] }));
39
+ }
40
+ export function FileDiff({ file, layout, no_lines_text = "No lines to show: a binary file, a bare rename or a change of mode." }) {
41
+ const [opened, set_opened] = useState(new Set());
42
+ const open = (start) => set_opened((current) => new Set([...current, start]));
43
+ if (file.hunks.length === 0)
44
+ return _jsx("p", { className: "diff-note", children: no_lines_text });
45
+ if (layout === "unified") {
46
+ const rows = fold_rows(unified_rows(file), opened);
47
+ return (_jsx("div", { className: "diff-scroll", children: _jsx("table", { className: "diff-lines diff-unified", "aria-label": `Changes to ${file.path}`, children: _jsx("tbody", { children: rows.map((row, index) => {
48
+ if (row.kind === "fold")
49
+ return _jsx(FoldRow, { fold: row, columns: 4, on_open: open }, `fold-${row.start}`);
50
+ if (row.kind === "hunk")
51
+ return _jsx(HunkRow, { header: row.header, columns: 4 }, index);
52
+ const side = row.kind === "same" ? null : row.kind;
53
+ return (_jsxs("tr", { className: side ? `diff-${side}` : undefined, children: [_jsx("td", { className: "diff-number", children: row.old_number ?? "" }), _jsx("td", { className: "diff-number", children: row.new_number ?? "" }), _jsx("td", { className: "diff-mark", "aria-label": side ?? undefined, children: side === "added" ? "+" : side === "removed" ? "−" : " " }), _jsx("td", { className: "diff-text", children: _jsx(Words, { parts: row.parts, side: side }) })] }, index));
54
+ }) }) }) }));
55
+ }
56
+ const rows = fold_rows(split_rows(file), opened);
57
+ return (_jsx("div", { className: "diff-scroll", children: _jsxs("table", { className: "diff-lines diff-split", "aria-label": `Changes to ${file.path}, old on the left and new on the right`, children: [_jsxs("colgroup", { children: [_jsx("col", { className: "diff-number-column" }), _jsx("col", {}), _jsx("col", { className: "diff-number-column" }), _jsx("col", {})] }), _jsx("tbody", { children: rows.map((row, index) => {
58
+ if (row.kind === "fold")
59
+ return _jsx(FoldRow, { fold: row, columns: 4, on_open: open }, `fold-${row.start}`);
60
+ if (row.kind === "hunk")
61
+ return _jsx(HunkRow, { header: row.header, columns: 4 }, index);
62
+ const changed = row.kind === "change";
63
+ return (_jsxs("tr", { children: [_jsx(SideCells, { cell: row.left, side: changed ? "removed" : null }), _jsx(SideCells, { cell: row.right, side: changed ? "added" : null })] }, index));
64
+ }) })] }) }));
65
+ }
66
+ // ── Plain file ───────────────────────────────────────────────────────────────
67
+ // A file's text read-only, each line numbered, with no diff columns.
68
+ export function FileContent({ path, text }) {
69
+ const lines = text.replace(/\n$/, "").split("\n");
70
+ return (_jsx("div", { className: "diff-scroll", children: _jsx("table", { className: "diff-lines diff-plain", "aria-label": `Contents of ${path}`, children: _jsx("tbody", { children: lines.map((line, index) => (_jsxs("tr", { children: [_jsx("td", { className: "diff-number", children: index + 1 }), _jsx("td", { className: "diff-text", children: _jsx("code", { children: line }) })] }, index))) }) }) }));
71
+ }
72
+ // ── One edit ─────────────────────────────────────────────────────────────────
73
+ const edit_marks = { added: "+", removed: "−", context: " " };
74
+ // The lines one edit takes out and puts in, unchanged lines kept for context, and a long change cut short.
75
+ export function EditDiff({ path = "", before, after, limit = 120 }) {
76
+ const lines = edit_lines(before, after);
77
+ const kept = lines.slice(0, limit);
78
+ return (_jsxs("div", { className: "edit-diff", children: [path && _jsx("code", { className: "diff-path", children: path }), _jsx("div", { className: "diff-scroll", children: _jsx("table", { className: "diff-lines", "aria-label": path ? `Change to ${path}` : "Change", children: _jsx("tbody", { children: kept.map((line, index) => (_jsxs("tr", { className: line.kind === "context" ? undefined : `diff-${line.kind}`, children: [_jsx("td", { className: "diff-mark", "aria-label": line.kind === "context" ? undefined : line.kind, children: edit_marks[line.kind] }), _jsx("td", { className: "diff-text", children: _jsx("code", { children: line.text }) })] }, index))) }) }) }), lines.length > kept.length && _jsxs("p", { className: "diff-note", children: [lines.length - kept.length, " more lines left out."] })] }));
79
+ }
@@ -0,0 +1,26 @@
1
+ import { type ReactNode } from "react";
2
+ import type { DiffFileStatus } from "../../diff_rows.ts";
3
+ import { type TreeItem } from "./tree.tsx";
4
+ export interface TreeFile {
5
+ path: string;
6
+ status?: DiffFileStatus;
7
+ additions?: number;
8
+ deletions?: number;
9
+ }
10
+ export interface FileTreeRow<File extends TreeFile = TreeFile> extends TreeItem {
11
+ name: string;
12
+ file: File | null;
13
+ }
14
+ export declare function file_tree_rows<File extends TreeFile>(files: File[]): FileTreeRow<File>[];
15
+ export declare function file_tree_folders(files: Pick<TreeFile, "path">[]): string[];
16
+ interface FileTreeProps<File extends TreeFile> {
17
+ files: File[];
18
+ selected: string | null;
19
+ on_select: (path: string) => void;
20
+ extra?: (file: File) => ReactNode;
21
+ folded?: (folder: string) => boolean;
22
+ label?: string;
23
+ filter_label?: string;
24
+ }
25
+ export declare function FileTree<File extends TreeFile>({ files, selected, on_select, extra, folded, label, filter_label }: FileTreeProps<File>): import("react").JSX.Element;
26
+ export {};
@@ -0,0 +1,46 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Files as a folder tree on `Tree`: folders first and folding, each changed file with a letter for how it changed and
3
+ // its added and removed lines, walked with the arrow keys and picked with Enter or a click, narrowed by a filter box
4
+ // that keeps the folders of the files it matches.
5
+ // ── Imports ──────────────────────────────────────────────────────────────────
6
+ import { useState } from "react";
7
+ import { Badge } from "./badges.js";
8
+ import { SearchBox } from "./controls.js";
9
+ import { DiffCounts, diff_status_words } from "./diff.js";
10
+ import { Tree } from "./tree.js";
11
+ const folder_id = (path) => `folder:${path}`;
12
+ const folder_of = (path) => (path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "");
13
+ const name_of = (path) => path.slice(path.lastIndexOf("/") + 1);
14
+ // The files and the folders that hold them as tree rows, folders before files and each by name.
15
+ export function file_tree_rows(files) {
16
+ const rows = new Map();
17
+ const add_folder = (path) => {
18
+ if (!path)
19
+ return null;
20
+ const id = folder_id(path);
21
+ if (!rows.has(id))
22
+ rows.set(id, { id, parent_id: add_folder(folder_of(path)), position: 0, name: name_of(path), file: null });
23
+ return id;
24
+ };
25
+ for (const file of files)
26
+ rows.set(`file:${file.path}`, { id: `file:${file.path}`, parent_id: add_folder(folder_of(file.path)), position: 0, name: name_of(file.path), file });
27
+ const sorted = [...rows.values()].sort((first, second) => Number(first.file !== null) - Number(second.file !== null) || first.name.localeCompare(second.name));
28
+ return sorted.map((row, index) => ({ ...row, position: index }));
29
+ }
30
+ // The folders the files sit in, by path.
31
+ export function file_tree_folders(files) {
32
+ const folders = new Set();
33
+ for (const file of files) {
34
+ const parts = file.path.split("/").slice(0, -1);
35
+ parts.forEach((_, index) => folders.add(parts.slice(0, index + 1).join("/")));
36
+ }
37
+ return [...folders];
38
+ }
39
+ export function FileTree({ files, selected, on_select, extra, folded, label = "Changed files", filter_label = "Filter files" }) {
40
+ const [filter, set_filter] = useState("");
41
+ const [collapsed, set_collapsed] = useState(() => new Set(folded ? file_tree_folders(files).filter(folded).map(folder_id) : []));
42
+ const needle = filter.trim().toLowerCase();
43
+ const shown = needle ? files.filter((file) => file.path.toLowerCase().includes(needle)) : files;
44
+ const toggle = (id) => set_collapsed((current) => (current.has(id) ? new Set([...current].filter((each) => each !== id)) : new Set([...current, id])));
45
+ return (_jsxs("div", { className: "file-tree", children: [_jsx(SearchBox, { label: filter_label, value: filter, on_input: set_filter }), shown.length === 0 ? (_jsx("p", { className: "diff-note", children: files.length ? "No file matches." : "No files." })) : (_jsx(Tree, { items: file_tree_rows(shown), label: label, collapsed: collapsed, on_collapsed_change: set_collapsed, selected_id: selected ? `file:${selected}` : null, on_select: (row) => (row.file ? on_select(row.file.path) : toggle(row.id)), name_of: (row) => row.name, render_item: (row) => (row.file ? _jsx("span", { className: "tree-name", children: row.name }) : _jsxs("span", { children: [row.name, "/"] })), render_extra: (row) => row.file?.status && (_jsxs(_Fragment, { children: [extra?.(row.file), _jsx(DiffCounts, { additions: row.file.additions ?? 0, deletions: row.file.deletions ?? 0 }), _jsx(Badge, { tone: diff_status_words[row.file.status][2], title: diff_status_words[row.file.status][0], children: diff_status_words[row.file.status][1] })] })) }))] }));
46
+ }
@@ -6,6 +6,7 @@ import { local_mcp_add_command, local_mcp_client_config } from "../../local_mcp_
6
6
  import { describe_error } from "../errors.js";
7
7
  import { ButtonGroup, NumberField, Switch } from "./controls.js";
8
8
  import { SettingRow } from "./layout.js";
9
+ import { CopyButton } from "./copy_button.js";
9
10
  import { toast } from "./toasts.js";
10
11
  function status_text(status) {
11
12
  if (status.state === "running")
@@ -40,5 +41,5 @@ export function LocalMcpSettings({ device, name, data_name = "read and change th
40
41
  const command = local_mcp_add_command(name, status);
41
42
  const config = local_mcp_client_config(name, status);
42
43
  const config_text = config === null ? "" : JSON.stringify(config, null, 2);
43
- return (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "MCP server", hint: `Lets AI assistants on this computer ${data_name}. Only programs on this computer can reach it${settings.require_token ? ", and only with its token" : ""}.`, as_label: true, children: _jsx(Switch, { label: "MCP server", checked: settings.enabled, on_change: (enabled) => void change({ ...settings, enabled }) }) }), settings.enabled && (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "Port", hint: "Change it if another program already uses this one.", children: _jsx(NumberField, { label: "Port", bare: true, min: 1, max: 65535, value: settings.port, on_change: (port) => port !== null && void change({ ...settings, port: Math.round(port) }) }) }), _jsx(SettingRow, { label: "Require a token", hint: "Callers must send the server's token, so other programs on this computer cannot use it. Turn it off and on again for a new token.", as_label: true, children: _jsx(Switch, { label: "Require a token", checked: settings.require_token === true, on_change: (require_token) => void change({ ...settings, require_token }) }) }), _jsx(SettingRow, { label: "Status", hint: status_text(status), children: null }), command !== null && (_jsx(SettingRow, { label: "Add to Claude Code", hint: _jsx("code", { children: command }), children: null })), config !== null && (_jsx(SettingRow, { label: "Client config", hint: _jsxs(_Fragment, { children: [status.token ? "For .mcp.json or a managed MCP config, under mcpServers. It holds the token, so keep it private." : "For .mcp.json or a managed MCP config, under mcpServers.", config_shown && _jsx("pre", { className: "output", children: config_text })] }), children: _jsxs(ButtonGroup, { label: "Client config", children: [_jsx("button", { onClick: () => set_config_shown(!config_shown), children: config_shown ? "Hide" : "Show" }), _jsx("button", { onClick: () => void navigator.clipboard?.writeText(config_text).then(() => toast("Copied.")), children: "Copy" })] }) }))] }))] }));
44
+ return (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "MCP server", hint: `Lets AI assistants on this computer ${data_name}. Only programs on this computer can reach it${settings.require_token ? ", and only with its token" : ""}.`, as_label: true, children: _jsx(Switch, { label: "MCP server", checked: settings.enabled, on_change: (enabled) => void change({ ...settings, enabled }) }) }), settings.enabled && (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "Port", hint: "Change it if another program already uses this one.", children: _jsx(NumberField, { label: "Port", bare: true, min: 1, max: 65535, value: settings.port, on_change: (port) => port !== null && void change({ ...settings, port: Math.round(port) }) }) }), _jsx(SettingRow, { label: "Require a token", hint: "Callers must send the server's token, so other programs on this computer cannot use it. Turn it off and on again for a new token.", as_label: true, children: _jsx(Switch, { label: "Require a token", checked: settings.require_token === true, on_change: (require_token) => void change({ ...settings, require_token }) }) }), _jsx(SettingRow, { label: "Status", hint: status_text(status), children: null }), command !== null && (_jsx(SettingRow, { label: "Add to Claude Code", hint: _jsx("code", { children: command }), children: null })), config !== null && (_jsx(SettingRow, { label: "Client config", hint: _jsxs(_Fragment, { children: [status.token ? "For .mcp.json or a managed MCP config, under mcpServers. It holds the token, so keep it private." : "For .mcp.json or a managed MCP config, under mcpServers.", config_shown && _jsx("pre", { className: "output", children: config_text })] }), children: _jsxs(ButtonGroup, { label: "Client config", children: [_jsx("button", { onClick: () => set_config_shown(!config_shown), children: config_shown ? "Hide" : "Show" }), _jsx(CopyButton, { text: config_text })] }) }))] }))] }));
44
45
  }