diff-chat 0.1.0__py3-none-any.whl

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 (91) hide show
  1. adapters/README.md +28 -0
  2. adapters/__init__.py +48 -0
  3. adapters/_base.py +102 -0
  4. adapters/_cli.py +405 -0
  5. adapters/claude.py +141 -0
  6. adapters/gemini.py +323 -0
  7. adapters/gpt.py +217 -0
  8. adapters/local.py +146 -0
  9. adapters/registry.py +33 -0
  10. api_fallback.py +189 -0
  11. app.py +827 -0
  12. app_preferences.py +205 -0
  13. archive_schema.py +142 -0
  14. attachments.py +129 -0
  15. chat_titles.py +60 -0
  16. connection_handoff.py +64 -0
  17. context_engine.py +256 -0
  18. conversation_actions.py +160 -0
  19. diff_chat-0.1.0.dist-info/METADATA +101 -0
  20. diff_chat-0.1.0.dist-info/RECORD +91 -0
  21. diff_chat-0.1.0.dist-info/WHEEL +4 -0
  22. diff_chat-0.1.0.dist-info/entry_points.txt +2 -0
  23. diff_chat-0.1.0.dist-info/licenses/LICENSE +21 -0
  24. diff_chat_assets/memory.example.md +1 -0
  25. diff_chat_assets/prompts/about_you_export.md +19 -0
  26. diff_chat_assets/settings.json +6 -0
  27. diff_chat_assets/static/about-you-parser.js +46 -0
  28. diff_chat_assets/static/about-you.js +171 -0
  29. diff_chat_assets/static/actions.css +275 -0
  30. diff_chat_assets/static/actions.js +650 -0
  31. diff_chat_assets/static/app.css +345 -0
  32. diff_chat_assets/static/app.js +1344 -0
  33. diff_chat_assets/static/attachments.js +80 -0
  34. diff_chat_assets/static/brand/favicon-32.png +0 -0
  35. diff_chat_assets/static/brand/icon.svg +11 -0
  36. diff_chat_assets/static/brand/wordmark-dark.svg +15 -0
  37. diff_chat_assets/static/brand/wordmark-light.svg +13 -0
  38. diff_chat_assets/static/characters/CREDITS.md +7 -0
  39. diff_chat_assets/static/characters/characters.css +37 -0
  40. diff_chat_assets/static/characters/claude.json +507 -0
  41. diff_chat_assets/static/characters/claude.png +0 -0
  42. diff_chat_assets/static/characters/claude.webp +0 -0
  43. diff_chat_assets/static/characters/gemini.json +54 -0
  44. diff_chat_assets/static/characters/gemini.png +0 -0
  45. diff_chat_assets/static/characters/gemini.webp +0 -0
  46. diff_chat_assets/static/characters/gpt.json +507 -0
  47. diff_chat_assets/static/characters/gpt.png +0 -0
  48. diff_chat_assets/static/characters/gpt.webp +0 -0
  49. diff_chat_assets/static/characters/local.json +387 -0
  50. diff_chat_assets/static/characters/local.png +0 -0
  51. diff_chat_assets/static/characters/local.webp +0 -0
  52. diff_chat_assets/static/characters/player.js +318 -0
  53. diff_chat_assets/static/chat-filing.js +84 -0
  54. diff_chat_assets/static/controls.js +194 -0
  55. diff_chat_assets/static/corners.css +59 -0
  56. diff_chat_assets/static/craft.css +246 -0
  57. diff_chat_assets/static/drafts.js +41 -0
  58. diff_chat_assets/static/index.html +208 -0
  59. diff_chat_assets/static/library.css +30 -0
  60. diff_chat_assets/static/library.js +181 -0
  61. diff_chat_assets/static/memory.js +81 -0
  62. diff_chat_assets/static/preference-dialog.js +21 -0
  63. diff_chat_assets/static/preferences.css +56 -0
  64. diff_chat_assets/static/session.js +46 -0
  65. diff_chat_assets/static/settings.css +111 -0
  66. diff_chat_assets/static/settings.js +463 -0
  67. diff_chat_assets/static/setup.js +238 -0
  68. diff_chat_assets/static/utility.js +64 -0
  69. diff_chat_assets/static/vendor/LICENSES.txt +531 -0
  70. diff_chat_assets/static/vendor/highlight.min.js +1262 -0
  71. diff_chat_assets/static/vendor/markdown-it.min.js +13 -0
  72. diff_chat_assets/static/vendor/plex-mono.woff2 +0 -0
  73. diff_chat_assets/static/vendor/plex-sans.woff2 +0 -0
  74. diff_launcher.py +93 -0
  75. discussion.py +239 -0
  76. history_search.py +68 -0
  77. library_manager.py +251 -0
  78. model_options.py +132 -0
  79. plan_usage.py +72 -0
  80. private_store.py +71 -0
  81. probe.py +195 -0
  82. runtime_paths.py +195 -0
  83. server_security.py +100 -0
  84. setup_status.py +123 -0
  85. shared_memory.py +189 -0
  86. storage.py +185 -0
  87. usage_budget.py +77 -0
  88. usage_claude.py +110 -0
  89. usage_codex.py +170 -0
  90. usage_gemini.py +70 -0
  91. utility_models.py +104 -0
@@ -0,0 +1,111 @@
1
+ #settings-window {
2
+ width: min(760px, calc(100vw - 32px)); height: min(560px, calc(100dvh - 32px)); max-width: none; max-height: none;
3
+ padding: 0; border: 1px solid var(--edge); --corner-radius: 16px; color: var(--ink); background: var(--paper);
4
+ font: 400 13px/1.5 var(--ui); box-shadow: 0 12px 48px rgb(0 0 0 / .12);
5
+ }
6
+ #settings-window::backdrop, .filing-dialog::backdrop {background: rgb(0 0 0 / .24);}
7
+ .settings-shell {height: 100%; display: grid; grid-template-columns: 176px minmax(0,1fr);}
8
+ .settings-nav {background:var(--library); padding:24px 12px; overflow-y:auto;}
9
+ .settings-nav h2 {font-size:13px; font-weight:500; margin:4px 12px 24px;}
10
+ .settings-nav button {text-align:left; width:100%; justify-content:flex-start; padding:8px 12px; margin:0 0 4px; color:var(--secondary);}
11
+ .settings-nav button[aria-current=true] {background:var(--selected);color:var(--ink);}
12
+ .settings-right {min-width:0; display:grid; grid-template-rows:auto minmax(0,1fr);}
13
+ .settings-title {display:flex; align-items:center; gap:12px; padding:24px 28px 16px;}
14
+ .settings-title h3 {font:500 20px/1.4 var(--ui); letter-spacing:-.025em; margin:0; flex:1;}
15
+ .settings-title button {padding:8px;}
16
+ .settings-pane {overflow:auto; overscroll-behavior:contain; padding:0 28px 24px;}
17
+ .settings-group {margin:8px 0 24px; min-width:0;}
18
+ .settings-group h4,.settings-kicker,.settings-saved,.filing-dialog .short-label {font:400 11px/1.5 "IBM Plex Mono", monospace; color:var(--muted);text-transform:uppercase; letter-spacing:.04em; margin:0 0 8px;}
19
+ .settings-saved {margin:0;}
20
+ .settings-row {display:flex; align-items:center; gap:16px; justify-content:space-between; min-height:40px; padding:4px 0;}
21
+ .settings-row>label,.settings-row>.row-caption {min-width:0;flex:1;}
22
+ .settings-row small,.settings-hint,.settings-feedback {display:block;color:var(--muted);font:400 13px/1.5 var(--ui);margin:4px 0;}
23
+ .settings-row>input,.settings-row>select,.settings-row>.select-wrap,.settings-row>button[aria-haspopup=listbox] {max-width:55%;min-width:0;}
24
+ .settings-pane input:not([type=checkbox]),.settings-pane textarea,.filing-dialog input,.role-custom {
25
+ appearance:none; padding:8px 12px; border:1px solid var(--rule); --corner-radius:8px; font:inherit; color:var(--ink); background:var(--surface); min-width:0;
26
+ }
27
+ .settings-pane input[type=number] {width:84px; appearance:textfield;}
28
+ .settings-pane input[type=number]::-webkit-inner-spin-button {appearance:none;}
29
+ .settings-pane textarea {width:100%;resize:vertical;min-height:148px;line-height:1.6;}
30
+ .settings-pane .settings-inset {background:var(--library); --corner-radius:8px; padding:8px 12px; color:var(--secondary); overflow-wrap:anywhere;}
31
+ .settings-pane .settings-actions {display:flex;flex-wrap:wrap;gap:8px;align-items:center; margin:8px 0 12px;}
32
+ .settings-pane .settings-action,.filing-dialog .settings-action {display:inline-flex;align-items:center;background:var(--inset); color:var(--ink); text-decoration:none; --corner-radius:8px; padding:8px 12px; cursor:pointer;}
33
+ .settings-pane .settings-action:enabled:hover,.settings-pane a.settings-action:hover,.filing-dialog .settings-action:enabled:hover {background:var(--selected);}
34
+ .settings-pane .settings-path {font:400 11px/1.6 "IBM Plex Mono",monospace; word-break:break-all; margin-bottom:8px;}
35
+ .settings-pane details {margin:12px 0;} .settings-pane summary {display:flex;align-items:center;gap:8px;cursor:pointer;list-style:none;}
36
+ .settings-pane summary::-webkit-details-marker {display:none;}
37
+ .settings-pane details:not([open]) summary .icon {transform:rotate(-90deg);}
38
+ .settings-pane summary .icon {color:var(--muted);transition:transform 150ms ease-out;}
39
+ @media(prefers-reduced-motion:reduce){.settings-pane summary .icon {transition:none;}}
40
+ .settings-pane .settings-rule {display:flex; align-items:baseline; justify-content:space-between; gap:8px; padding:8px 0;}
41
+ .settings-pane .usage-window {margin:12px 0;}
42
+ .settings-pane progress {width:100%;}
43
+ .settings-pane .warning-input {display:block;margin:8px 0;}
44
+ .settings-pane a {color:var(--ink);}
45
+ .settings-pane kbd {background:var(--inset);padding:0 4px;--corner-radius:4px;font:400 11px/1.6 "IBM Plex Mono",monospace;}
46
+ #settings-error {margin:0 28px 8px;color:var(--secondary);overflow-wrap:anywhere;}
47
+ #settings-error:empty {display:none;}
48
+ .role-custom {width:100%;margin:4px 0 8px;}
49
+ .chat-file-row {position:relative; min-width:0;}
50
+ .chat-file-row .chat-link {width:100%;}
51
+ .chat-file-row:has(.chat-menu-button:hover) .chat-link,.chat-file-row:focus-within .chat-link {background:var(--inset);}
52
+ .chat-menu-button {position:absolute;right:4px;top:50%;transform:translateY(-50%); opacity:0; color:var(--muted);background:var(--library);width:28px;height:24px;padding:4px;}
53
+ .chat-file-row:hover .chat-menu-button,.chat-file-row:focus-within .chat-menu-button,.chat-menu-button[aria-expanded=true] {opacity:1;}
54
+ .chat-file-row:hover .list-time,.chat-file-row:focus-within .list-time {visibility:hidden;}
55
+ .chat-menu {padding:4px; min-width:144px; background:var(--surface); color:var(--ink); border:1px solid var(--rule); --corner-radius:8px; box-shadow:0 1px 2px #0002; position:fixed; margin:0; inset:auto; z-index:90;}
56
+ .chat-menu button {display:flex;width:100%;justify-content:flex-start;padding:8px; font-size:13px;}
57
+ .filing-dialog {min-width:min(304px,90vw);max-width:min(420px,92vw);padding:20px;background:var(--surface);color:var(--ink);border:1px solid var(--edge);--corner-radius:12px;}
58
+ .filing-dialog h2 {margin:0 0 12px;font-size:20px;font-weight:500;}
59
+ .filing-dialog input {width:100%;margin-bottom:12px;}
60
+ .filing-dialog .dialog-actions {display:flex;gap:8px;justify-content:flex-end;margin-top:16px;}
61
+ .filing-toast {position:fixed;z-index:10;left:16px;bottom:16px;background:var(--surface);border:1px solid var(--edge);--corner-radius:8px;box-shadow:0 1px 4px #0001;padding:8px 12px;color:var(--ink);display:flex;align-items:center;gap:16px;}
62
+ #connections-panel .setup-controls {margin-top:16px;display:flex;flex-wrap:wrap;gap:8px;align-items:center;}
63
+ @media (max-width:599px) {
64
+ #settings-window {width:calc(100vw - 16px);height:min(680px,calc(100dvh - 16px));}
65
+ .settings-shell {grid-template-columns:minmax(0,1fr); grid-template-rows:auto minmax(0,1fr);}
66
+ .settings-nav {display:flex;gap:4px;padding:12px;overflow-x:auto;align-items:center;}
67
+ .settings-nav h2 {display:none;}
68
+ .settings-nav button {width:auto;flex:none;margin:0;padding:8px;}
69
+ .settings-title {padding:16px;}
70
+ .settings-pane {padding:0 16px 16px;}
71
+ #settings-error {margin-inline:16px;}
72
+ .settings-row {gap:8px;}
73
+ .chat-menu-button {opacity:1;}
74
+ .chat-file-row .list-time {margin-right:20px;}
75
+ }
76
+ .preference-dialog {padding:24px; font:400 13px/1.5 var(--ui);}
77
+ .preference-dialog h2 {font:500 20px/1.4 var(--ui);}
78
+ .preference-dialog .preference-description {margin:12px 0 24px;}
79
+ .preference-dialog :is(label,.connection-row h3,.preference-save) {font:500 13px/1.5 var(--ui);}
80
+ .preference-dialog .preference-save {padding:8px 12px; --corner-radius:8px;}
81
+ .preference-dialog .connection-row {border:0; padding:8px 0;}
82
+ .preference-dialog .connection-command {padding:8px; margin-top:8px; gap:8px;}
83
+ .preference-dialog .preference-hint {font-size:13px;}
84
+ .preference-dialog form {gap:8px;}
85
+ .preference-dialog .setup-controls .settings-action {padding:8px 12px;background:var(--inset);}
86
+ .preference-dialog .setup-controls .preference-save {margin-left:auto;}
87
+ #connections-panel .connection-command {background:var(--library);}
88
+ .connection-title {display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px;min-height:32px;}
89
+ .connection-title .connection-ready {margin-right:auto;}
90
+ .connection-action {display:inline-flex;align-items:center;justify-content:center;min-height:32px;padding:4px 12px;
91
+ font:500 13px/1.5 var(--ui);color:var(--ink);background:var(--inset);border:1px solid var(--rule);
92
+ border-radius:6px;text-decoration:none;cursor:pointer;}
93
+ .connection-action:is(:hover,:focus-visible) {background:var(--selected);}
94
+ #connect-models {align-self:flex-start;margin:0 0 12px;}
95
+ .connection-ready,.connection-manual summary {font-size:13px;color:var(--secondary);}
96
+ .connection-manual {margin-top:8px;}
97
+ .connection-manual summary {width:fit-content;cursor:pointer;}
98
+ .connection-manual summary:hover {color:var(--ink);}
99
+ .connection-notice:empty {display:none;}
100
+ #connections-panel .connection-row {padding:12px 0;}
101
+ #connections-panel .connection-row p {margin-top:4px;}
102
+
103
+ .settings-mobile-nav {display:none;}
104
+ @media(max-width:599px) {
105
+ .settings-shell {grid-template-rows:minmax(0,1fr);}
106
+ .settings-nav {display:none;}
107
+ .settings-title h3 {position:absolute;clip-path:inset(50%);overflow:hidden;width:1px;height:1px;}
108
+ .settings-mobile-nav {display:block; flex:1;min-width:0;}
109
+ .settings-mobile-nav .select-trigger {font:500 20px/1.4 var(--ui);letter-spacing:-.025em;padding:4px 8px;margin-left:-8px;background:transparent;}
110
+ .settings-mobile-nav .select-trigger:hover {background:var(--inset);}
111
+ }
@@ -0,0 +1,463 @@
1
+ "use strict";
2
+
3
+ (() => {
4
+ const sections = ["General", "Models", "Conversation", "Memory", "Usage", "Data", "Shortcuts", "About"];
5
+ const dialog = element("dialog");
6
+ dialog.id = "settings-window";
7
+ dialog.setAttribute("aria-labelledby", "settings-heading");
8
+ dialog.innerHTML = `<div class="settings-shell"><nav class="settings-nav" aria-label="Settings sections"><h2>Settings</h2></nav>
9
+ <div class="settings-right"><div><div class="settings-title"><h3 id="settings-heading"></h3>
10
+ <span class="settings-saved" role="status"></span><button type="button" aria-label="Close settings" id="settings-close"><svg aria-hidden="true" class="icon"><use href="#i-x"/></svg></button></div>
11
+ <p id="settings-error" role="alert"></p></div><div class="settings-pane"></div></div></div>`;
12
+ document.body.append(dialog);
13
+ const nav = dialog.querySelector("nav"), pane = dialog.querySelector(".settings-pane");
14
+ const saved = dialog.querySelector(".settings-saved"), errorNode = byId("settings-error");
15
+ const sectionPicker = element("select");
16
+ sectionPicker.setAttribute("aria-label", "Settings section");
17
+ sectionPicker.replaceChildren(...sections.map(name => new Option(name, name)));
18
+ const mobileNavigation = element("div", "settings-mobile-nav");
19
+ mobileNavigation.append(sectionPicker);
20
+ byId("settings-heading").after(mobileNavigation);
21
+ sectionPicker.addEventListener("change", () => { currentSection = sectionPicker.value; render(); });
22
+ let info, currentSection = "General", sectionVersion = 0, saveTimer;
23
+ let writes = Promise.resolve();
24
+ let snapshot = {};
25
+
26
+ function showError(error) {
27
+ errorNode.textContent = error?.message || String(error);
28
+ saved.textContent = "";
29
+ }
30
+ function success() {
31
+ errorNode.textContent = "";
32
+ saved.textContent = "Saved";
33
+ clearTimeout(saveTimer);
34
+ saveTimer = setTimeout(() => {saved.textContent = "";}, 1800);
35
+ }
36
+ function apply(data) {
37
+ info = data;
38
+ window.diffSettings = data.value;
39
+ if (chat && data.value.display_name && names.me !== data.value.display_name) {
40
+ names.me = data.value.display_name;
41
+ renderTranscript();
42
+ }
43
+ for (const key of ["theme", "font", "accent"]) {
44
+ const chosen = data.customized.includes(key) ? data.value[key] : setting(key, data.value[key]);
45
+ window.diffSettings[key] = chosen;
46
+ if (key === "theme") applyTheme(chosen);
47
+ else document.documentElement.dataset[key] = chosen;
48
+ remember(key, chosen);
49
+ }
50
+ window.DiffCharacters?.setEnabled(data.value.characters);
51
+ const hint = document.querySelector(".key-hint");
52
+ if (hint) hint.textContent = data.value.send_shortcut === "enter" ? "Shift+Enter for a new line" : (macKeyboard ? "⌘" : "Ctrl+") + "Enter to send";
53
+ document.dispatchEvent(new CustomEvent("diff:settings", {detail: data.value}));
54
+ }
55
+ async function fetchSettings() {apply(await api("/api/settings"));}
56
+ const initial = fetchSettings().catch(error => feedback(error.message));
57
+ function save(change) {
58
+ const request = writes.then(async () => {apply(await api("/api/settings", change, "PATCH")); success();});
59
+ writes = request.catch(showError);
60
+ return request;
61
+ }
62
+ function action(label, callback, className = "settings-action") {
63
+ const button = element("button", className, label); button.type = "button";
64
+ button.onclick = async () => {
65
+ button.disabled = true;
66
+ try {await callback(button);} catch (error) {showError(error);} finally {button.disabled = false;}
67
+ };
68
+ return button;
69
+ }
70
+ function group(title) {
71
+ const section = element("section", "settings-group");
72
+ if (title) section.append(element("h4", "", title));
73
+ pane.append(section); return section;
74
+ }
75
+ function hint(parent, text) {const p = element("p", "settings-hint", text); parent.append(p); return p;}
76
+ function row(parent, label, control, description) {
77
+ const div = element("div", "settings-row");
78
+ const caption = element("div", "row-caption");
79
+ const name = element("label", "", label);
80
+ if (!control.id) control.id = "settings-" + crypto.randomUUID();
81
+ name.htmlFor = control.id; control.setAttribute("aria-label", label);
82
+ caption.append(name);
83
+ if (description) caption.append(element("small", "", description));
84
+ div.append(caption, control); parent.append(div); return div;
85
+ }
86
+ function choose(parent, label, options, value, change, description) {
87
+ const select = element("select");
88
+ for (const item of options) {
89
+ const [key, name] = Array.isArray(item) ? item : [item, item];
90
+ select.add(new Option(name, key));
91
+ }
92
+ select.value = value;
93
+ select.onchange = async () => {
94
+ const next = select.value;
95
+ try {await change(next); value = next;}
96
+ catch (error) {
97
+ select.value = value; select.setAttribute("aria-label", label);
98
+ if (dialog.open) showError(error); else feedback(error.message);
99
+ }
100
+ };
101
+ row(parent, label, select, description); return select;
102
+ }
103
+ function input(parent, label, type, value, change, options={}) {
104
+ const control = element("input"); control.type = type; control.value = value;
105
+ Object.assign(control, options);
106
+ control.onchange = async () => {
107
+ if (!control.reportValidity()) return;
108
+ const next = type === "number" ? control.valueAsNumber : control.value.trim();
109
+ try {await change(next); value = next;} catch (error) {control.value = value; showError(error);}
110
+ };
111
+ row(parent, label, control); return control;
112
+ }
113
+ function toggle(parent, label, value, change, description) {
114
+ const button = element("button", "participant-switch");
115
+ button.type = "button"; button.setAttribute("role", "switch");
116
+ button.setAttribute("aria-checked", String(value));
117
+ const track = element("span", "track"); track.setAttribute("aria-hidden", "true"); button.append(track);
118
+ button.onclick = async () => {
119
+ button.disabled = true;
120
+ const next = button.getAttribute("aria-checked") !== "true";
121
+ try {await change(next); button.setAttribute("aria-checked", String(next));} catch (error) {showError(error);}
122
+ finally {button.disabled = false;}
123
+ };
124
+ row(parent, label, button, description); return button;
125
+ }
126
+ function actions(parent, ...buttons) {
127
+ const wrap = element("div", "settings-actions"); wrap.append(...buttons); parent.append(wrap); return wrap;
128
+ }
129
+ const providerOptions = () => models.map(id => [id, names[id]]);
130
+ const roleOptions = [["none","None"],["for","Argue for"],["against","Argue against"],["custom","Custom"]];
131
+ function roles(parent, label, value, change) {
132
+ let current = value || {mode:"none",text:""};
133
+ let custom;
134
+ const select = choose(parent, label, roleOptions, current.mode, async mode => {
135
+ const next = {...current, mode};
136
+ await change(next); current = next; custom.hidden = mode !== "custom";
137
+ if (!custom.hidden) custom.focus();
138
+ });
139
+ custom = element("input", "role-custom"); custom.type="text"; custom.maxLength=1200;
140
+ custom.placeholder="Describe this participant’s role"; custom.value=current.text || "";
141
+ custom.setAttribute("aria-label", label + " instructions"); custom.hidden=current.mode !== "custom";
142
+ custom.onchange=async () => {
143
+ try {await change({...current,text:custom.value}); current={...current,text:custom.value};}
144
+ catch (error) {custom.value=current.text; (dialog.open ? showError : feedback)(error.message);}
145
+ };
146
+ parent.append(custom); return select;
147
+ }
148
+
149
+ function general() {
150
+ const s = window.diffSettings;
151
+ const app = group("Appearance");
152
+ choose(app,"Theme",[["system","Follow system"],["light","Light"],["dark","Dark"],["codex","Codex dark"]],s.theme,theme=>save({theme}));
153
+ choose(app,"Conversation font",[["theme","Theme default"],["system","System sans"],["mono","System mono"],["serif","Book serif"],["plex","IBM Plex Sans"]],s.font,font=>save({font}));
154
+ choose(app,"Accent",[["neutral","Graphite"],["blue","Blue"],["teal","Teal"],["violet","Violet"],["amber","Amber"]],s.accent,accent=>save({accent}));
155
+ toggle(app,"Characters",s.characters,characters=>save({characters}),"Show character portraits beside replies.");
156
+ const behavior = group("Behavior");
157
+ input(behavior, "Your name", "text", s.display_name || "you", display_name => save({display_name:display_name || "you"}), {maxLength:60, placeholder:"you"});
158
+ choose(behavior,"Send messages with",[["enter","Enter"],["mod-enter",macKeyboard?"⌘ Enter":"Ctrl Enter"]],s.send_shortcut,send_shortcut=>save({send_shortcut}));
159
+ const startup = toggle(behavior,"Open at login",s.open_at_login,async open_at_login=>{
160
+ await window.diffNative.setOpenAtLogin(open_at_login); await save({open_at_login});
161
+ },window.diffNative ? undefined : "Available in the Mac app.");
162
+ startup.disabled=!window.diffNative?.setOpenAtLogin;
163
+ if (window.diffNative?.getOpenAtLogin) window.diffNative.getOpenAtLogin().then(value=>{
164
+ if (typeof value === "boolean") startup.setAttribute("aria-checked",String(value));
165
+ }).catch(()=>{});
166
+ toggle(behavior,"Background notifications",s.notify_background,async notify_background=>{
167
+ if (notify_background) {
168
+ if (window.diffNative?.requestNotifications) {
169
+ if (await window.diffNative.requestNotifications() === false) throw Error("Allow notifications for diff in System Settings.");
170
+ } else if (!window.Notification || await Notification.requestPermission() !== "granted") {
171
+ throw Error("Allow notifications for this site in your browser.");
172
+ }
173
+ }
174
+ await save({notify_background});
175
+ },"Notify when a run finishes while diff is in the background.");
176
+ }
177
+
178
+ function defaultsFor(provider, section, pref) {
179
+ const available = catalog[provider]?.models || [];
180
+ const choices = [["","App default"],...available.filter(m=>m.id!=="default").map(m=>[m.id,m.label])];
181
+ const native = id => available.find(m=>m.id === (id || catalog[provider]?.default_model));
182
+ let activeId = pref.model;
183
+ const model = choose(section,"Default model",choices,activeId,async id=>{
184
+ const item = native(id), level = id ? item?.default_effort || "" : "";
185
+ await save({[provider]:{model:id,effort:level}}); activeId=id;
186
+ if (registry.get(provider).capabilities.reasoning_levels) levels(level);
187
+ });
188
+ if (!registry.get(provider).capabilities.reasoning_levels) { model.disabled = !available.length; return; }
189
+ const effort = choose(section,"Default reasoning",[],"",async value=>{
190
+ const id = activeId || native(activeId)?.id;
191
+ if (id) {
192
+ await save({[provider]:{model:id,effort:value}});
193
+ activeId=id; model.value=id;
194
+ }
195
+ });
196
+ function levels(level) {
197
+ const item=native(activeId);
198
+ effort.replaceChildren(...(item?.efforts || ["default"]).map(e=>new Option(effortLabel(e),e)));
199
+ effort.value=level || item?.default_effort || "default"; effort.disabled=effort.options.length<2;
200
+ }
201
+ levels(pref.effort);
202
+ }
203
+ function modelSection(provider, status) {
204
+ const pref = window.diffSettings[provider];
205
+ const section = participantStyle(group(names[provider]), provider);
206
+ const participant = registry.get(provider);
207
+ const statusLine = hint(section, status?.hint || "Checking connection…");
208
+ if (status?.version) statusLine.append(" · ", status.version);
209
+ if (participant.kind === "cli") input(section,"CLI path","text",pref.cli_path,path=>save({[provider]:{cli_path:path}}),
210
+ {placeholder:status?.path || "Auto-detect",spellcheck:false});
211
+ actions(section,action("Test connection",async () => {
212
+ statusLine.textContent="Checking…";
213
+ const result=await api("/api/settings/test/"+provider, {});
214
+ snapshot[provider] = result;
215
+ statusLine.textContent=[result.hint,result.version].filter(Boolean).join(" · ");
216
+ if (result.status === "ready") {
217
+ const state = await api("/api/state");
218
+ catalog = state.model_options;
219
+ if (chat) loadPreferences(preferences);
220
+ await render();
221
+ }
222
+ }));
223
+ if (participant.kind === "http" && Number.isFinite(pref.context_length)) {
224
+ input(section,"Context length (tokens)","number",pref.context_length,context_length=>save({[provider]:{context_length}}),{min:512,max:131072});
225
+ hint(section,"Small local models can have short context windows. A larger context uses more memory.");
226
+ }
227
+ defaultsFor(provider,section,pref);
228
+ input(section,"Timeout (seconds)","number",pref.timeout,timeout=>save({[provider]:{timeout}}),{min:1,max:3600});
229
+ if (!participant.capabilities.api_fallback) return;
230
+ const fallback = element("details");
231
+ const summary = element("summary"); summary.append(window.diffIcon("chevron"),"API fallback"); fallback.append(summary); section.append(fallback);
232
+ hint(fallback,"Use a separately billed provider API key if the subscription is unavailable.");
233
+ const key = element("input"); key.type="password"; key.autocomplete="new-password"; key.spellcheck=false;
234
+ key.placeholder="Enter a key"; row(fallback,"API key",key);
235
+ actions(fallback,action("Save to keychain",async ()=>{
236
+ try {await api("/api/settings/keys/"+provider,{key:key.value}); success();} finally {key.value="";}
237
+ }),action("Remove key",async ()=>{
238
+ await api("/api/settings/keys/"+provider+"/remove",{}); key.value="";
239
+ await fetchSettings(); success(); render();
240
+ }));
241
+ toggle(fallback,"Use API fallback",pref.api_fallback,api_fallback=>save({[provider]:{api_fallback}}));
242
+ input(fallback,"API model ID","text",pref.api_model,api_model=>save({[provider]:{api_model}}),
243
+ {placeholder:"Use the selected model",spellcheck:false});
244
+ }
245
+ async function modelSettings(version) {
246
+ const connect = action("Connect models", () => window.openDiffConnections());
247
+ connect.setAttribute("aria-haspopup", "dialog");
248
+ actions(group(), connect);
249
+ providerOptions().forEach(([p])=>modelSection(p,snapshot[p]));
250
+ try {
251
+ const rows=await api("/api/setup");
252
+ snapshot=rows; if (version!==sectionVersion) return;
253
+ for (const section of pane.querySelectorAll("[data-participant]")) {
254
+ const data = rows[section.dataset.participant];
255
+ if (!data) continue;
256
+ section.querySelector(".settings-hint").textContent = [data.hint,data.version].filter(Boolean).join(" · ");
257
+ const path = section.querySelector('input[aria-label="CLI path"]');
258
+ if (path) path.placeholder = data.path || "Auto-detect";
259
+ }
260
+ } catch (error) {if(version===sectionVersion) showError(error);}
261
+ }
262
+ async function conversation(version) {
263
+ const s=window.diffSettings;
264
+ const rounds=group("Find agreement");
265
+ input(rounds,"Rounds","number",s.agreement_rounds,agreement_rounds=>save({agreement_rounds}),{min:2,max:6});
266
+ input(rounds,"Maximum replies","number",s.max_replies,max_replies=>save({max_replies}),{min:2,max:Math.max(2, 6 * models.length)});
267
+ const defaults=group("New conversations");
268
+ choose(defaults,"Combine with",providerOptions(),s.default_combiner,default_combiner=>save({default_combiner}));
269
+ toggle(defaults,"Web search",s.web_search,web_search=>save({web_search}));
270
+ providerOptions().forEach(([p,n])=>roles(defaults,n+"’s role",s[p].role,role=>save({[p]:{role}})));
271
+ const summaries=group("Summaries and comparisons");
272
+ input(summaries,"Summarize after (characters)","number",s.summary_threshold,summary_threshold=>save({summary_threshold}),{min:1,max:2000000});
273
+ let utility=await api("/api/utility-model"); if(version!==sectionVersion) return;
274
+ const items=[["auto","Automatic · lightweight"]];
275
+ for(const [p] of providerOptions()) for(const m of catalog[p]?.models || []) items.push([p+"/"+m.id,m.label]);
276
+ const key=utility.value.provider === "auto" ? "auto" : utility.value.provider+"/"+utility.value.model;
277
+ choose(summaries,"Summary model",items,key,async id=>{
278
+ const [provider, ...rest]=id.split("/"), model=rest.join("/"), m=catalog[provider]?.models.find(item=>item.id===model);
279
+ const effort=m?.efforts.includes("low") ? "low" : m?.default_effort;
280
+ utility=await api("/api/utility-model",{provider,model:model || "",effort:effort || "",revision:utility.revision},"PATCH");
281
+ byId("utility-choice").textContent=m?.label || "Automatic"; success();
282
+ });
283
+ }
284
+ async function memory(version) {
285
+ const section=group("Shared memory");
286
+ hint(section,"Participants receive these notes at the start of their turns.");
287
+ let note=await api("/api/settings/memory"); if(version!==sectionVersion) return;
288
+ const field=element("textarea"); field.maxLength=4000;field.setAttribute("aria-label","memory.md");field.value=note.value;
289
+ section.append(field);
290
+ const meter=element("p","settings-kicker"); section.append(meter);
291
+ const updateMeter=()=>{meter.textContent=number.format(Array.from(field.value).length)+" / 4,000 characters";};
292
+ let chain=Promise.resolve(), timer;
293
+ function persist() {
294
+ clearTimeout(timer);
295
+ const value=field.value;
296
+ chain=chain.then(async ()=>{
297
+ if (value===note.value) return;
298
+ note=await api("/api/settings/memory",{text:value,revision:note.revision},"PATCH");success();
299
+ }).catch(showError);
300
+ return chain;
301
+ }
302
+ field.oninput=()=>{updateMeter();clearTimeout(timer);timer=setTimeout(persist,400);};
303
+ field.onblur=persist;updateMeter();
304
+ actions(section,action("Import from another AI",async ()=>{
305
+ await persist();
306
+ if (field.value!==note.value || version!==sectionVersion) return;
307
+ const saved=await window.openDiffAboutYou();
308
+ if (saved && version===sectionVersion) {
309
+ note=saved; field.value=saved.value; updateMeter(); success();
310
+ }
311
+ }),action("Clear all memory",async ()=>{
312
+ if (!await window.diffConfirm("Clear all memory?","Remove memory.md and the shared notes saved for every chat.","Clear memory")) return;
313
+ clearTimeout(timer); await chain; note=await api("/api/settings/memory/clear",{confirmation:"CLEAR MEMORY"});
314
+ field.value="";updateMeter();success();
315
+ }));
316
+ }
317
+ async function usageSettings(version) {
318
+ const s=window.diffSettings;
319
+ const controls=group("Limits");
320
+ input(controls,"Warn above (% of remaining 5-hour limit)","number",s.usage_warning,usage_warning=>save({usage_warning}),{min:0,max:100});
321
+ hint(controls,"Estimates use observed changes in plan usage per reply. A threshold of 0 turns warnings off.");
322
+ choose(controls,"Refresh usage",[[30,"Every 30 seconds"],[60,"Every minute"],[120,"Every 2 minutes"],[300,"Every 5 minutes"],[900,"Every 15 minutes"]],s.usage_refresh,v=>save({usage_refresh:Number(v)}));
323
+ const plans=group("Plan remaining");
324
+ const refresh=action("Refresh now",()=>load(true)); actions(plans,refresh);
325
+ const list=element("div");plans.append(list);
326
+ async function load(force) {
327
+ const data=await api("/api/usage"+(force?"?refresh=true":""));
328
+ if(version!==sectionVersion)return;
329
+ usage=data;list.replaceChildren();
330
+ for (const [p,n] of providerOptions()) {
331
+ renderUsage(p);
332
+ const section=participantStyle(element("section","settings-group "+p),p);section.append(element("h4","",n),fields.get(p).readings.cloneNode(true));list.append(section);
333
+ }
334
+ }
335
+ await load(false);
336
+ }
337
+ function dataSettings() {
338
+ const location=group("Chats folder");
339
+ location.append(element("p","settings-inset settings-path",info.folder_label || info.folder));
340
+ actions(location,action(info.platform==="darwin" ? "Reveal in Finder" : "Open chats folder",()=>api("/api/data/reveal",{})));
341
+ const transfer=group("Transfer");
342
+ hint(transfer,"JSON preserves chat structure and attachments for importing. Markdown exports a readable file for each chat.");
343
+ function download(label, format) {
344
+ return action(label, () => window.diffSession.download("/api/data/export?format=" + format,
345
+ format === "json" ? "diff-chats.json" : "diff-markdown.zip"));
346
+ }
347
+ const file=element("input");file.type="file";file.accept=".json,application/json";file.hidden=true;
348
+ file.onchange=async ()=>{
349
+ if(!file.files.length)return;
350
+ try {
351
+ const result=await api("/api/data/import",JSON.parse(await file.files[0].text()));
352
+ await refreshLibrary(); saved.textContent="Imported "+result.count;
353
+ } catch(error){showError(error);} finally{file.value="";}
354
+ };
355
+ actions(transfer,download("Export JSON","json"),download("Export Markdown","markdown"),action("Import JSON",()=>file.click()));transfer.append(file);
356
+ const erase=group("Delete library");
357
+ hint(erase,"Remove all chats, attachments, private sessions and chat-specific notes from this library.");
358
+ actions(erase,action("Delete all chats…",async ()=>{
359
+ if(!await window.diffConfirm("Delete all chats?","Type DELETE ALL CHATS to permanently remove this library.","Delete all","DELETE ALL CHATS"))return;
360
+ await api("/api/data/delete-all",{confirmation:"DELETE ALL CHATS"});
361
+ for (const item of chatList) drafts.delete(item.id,drafts.get(item.id));
362
+ await openChat();saved.textContent="Deleted";
363
+ }));
364
+ }
365
+ function shortcuts() {
366
+ const s=window.diffSettings,mod=macKeyboard?"⌘":"Ctrl + ";
367
+ const section=group("Keyboard");
368
+ for(const [key,label] of [[mod+"K","Commands and chat search"],[mod+",","Settings"],[s.send_shortcut==="enter"?"Enter":mod+"Enter","Send message"],["Shift + Enter","New line"],[mod+"Enter","Save an edited message"],[mod+"1","Continue (empty composer)"],[mod+"2","Find agreement (empty composer)"],[mod+"3","Combine (empty composer)"],["/","Show conversation commands"],["↑ ↓","Navigate options"],["Enter","Choose selected option"],["Esc","Dismiss a menu or window"]]) {
369
+ const line=element("div","settings-rule");line.append(element("span","",label),element("kbd","",key));section.append(line);
370
+ }
371
+ const desktop = group("Mac app");
372
+ for (const [key, label] of [["⌘N", "New chat"], ["⇧⌘B", "Open in browser"], ["⌘R", "Reload chat"], ["⌘W", "Close window"], ["⌘M", "Minimize window"], ["⌘H", "Hide diff"], ["⌥⌘H", "Hide other apps"], ["⌘Q", "Quit diff"]]) {
373
+ const line=element("div","settings-rule");line.append(element("span","",label),element("kbd","",key));desktop.append(line);
374
+ }
375
+ }
376
+ function about() {
377
+ const section=group("diff");
378
+ const version=element("div","settings-rule"); version.append(element("span","","Version"),element("span","",info.version));section.append(version);
379
+ const license=element("div","settings-rule");license.append(element("span","","License"),element("span","","MIT"));section.append(license);
380
+ const releases=group("Project");
381
+ const repo=input(releases,"GitHub repository","text",window.diffSettings.repository,async repository=>{await save({repository});render();},{placeholder:"owner/repository",spellcheck:false});
382
+ const status=hint(releases,repo.value?"":"Enter the published repository to check its releases.");
383
+ const update=action("Check for updates",async ()=>{
384
+ const update=await api("/api/settings/update");status.replaceChildren(document.createTextNode(update.message));
385
+ if (update.url) {const a=element("a",""," View release");a.href=update.url;a.target="_blank";a.rel="noopener";status.append(a);}
386
+ });
387
+ update.disabled=!repo.value;
388
+ const links=[update];
389
+ if(repo.value) {const a=element("a","settings-action","View on GitHub");a.href="https://github.com/"+repo.value;a.target="_blank";a.rel="noopener";links.unshift(a);}
390
+ actions(releases,...links);
391
+ const credits=group("Credits");hint(credits,"Icons by Lucide. Type by IBM Plex. The characters are original art for diff.");
392
+ }
393
+ const renderers={General:general,Models:modelSettings,Conversation:conversation,Memory:memory,Usage:usageSettings,Data:dataSettings,Shortcuts:shortcuts,About:about};
394
+ async function render() {
395
+ const version=++sectionVersion;
396
+ if(sectionPicker.value!==currentSection){sectionPicker.value=currentSection;sectionPicker.setAttribute("aria-label","Settings section");}
397
+ byId("settings-heading").textContent=currentSection; pane.replaceChildren();pane.scrollTop=0;errorNode.textContent="";
398
+ for (const button of nav.querySelectorAll("button"))button.setAttribute("aria-current",String(button.textContent===currentSection));
399
+ try {await renderers[currentSection](version);}catch(error){if(version===sectionVersion)showError(error);}
400
+ }
401
+ async function open(section="General") {
402
+ currentSection=sections.includes(section)?section:"General";
403
+ if(!dialog.open)dialog.showModal();
404
+ try {await initial;await writes;await fetchSettings();await render();}catch(error){showError(error);}
405
+ }
406
+ for(const section of sections)nav.append(action(section,()=>{currentSection=section;return render();},"settings-tab"));
407
+ window.openDiffSettings=open;byId("open-settings").onclick=()=>open();
408
+ document.addEventListener("diff:connections", event => {
409
+ snapshot = event.detail;
410
+ if (dialog.open && currentSection === "Models") {
411
+ for (const section of pane.querySelectorAll("[data-participant]")) {
412
+ const item = snapshot[section.dataset.participant];
413
+ if (item) section.querySelector(".settings-hint").textContent = [item.hint, item.version].filter(Boolean).join(" · ");
414
+ }
415
+ }
416
+ });
417
+ byId("connections-panel").addEventListener("close", async () => {
418
+ if (!dialog.open || currentSection !== "Models") return;
419
+ await render();
420
+ pane.querySelector('[aria-haspopup="dialog"]')?.focus({preventScroll:true});
421
+ });
422
+ byId("settings-close").onclick=()=>dialog.close();
423
+ dialog.addEventListener("click",event=>{
424
+ if(event.target!==dialog)return;
425
+ const r=dialog.getBoundingClientRect();
426
+ if(event.clientX<r.left||event.clientX>r.right||event.clientY<r.top||event.clientY>r.bottom)dialog.close();
427
+ });
428
+ document.addEventListener("keydown",event=>{
429
+ if((event.metaKey||event.ctrlKey)&&event.key===","&&!event.isComposing){event.preventDefault();open();}
430
+ });
431
+ function notifyFinished(event) {
432
+ if(!window.diffSettings?.notify_background || (document.hasFocus()&&!document.hidden))return;
433
+ if(window.diffNative?.notifyFinished)window.diffNative.notifyFinished().catch(()=>{});
434
+ else if(window.Notification && Notification.permission==="granted") {
435
+ try {new Notification("diff",{body:"Your conversation has a new reply.",tag:"diff-"+event.detail.chatId});} catch {}
436
+ }
437
+ }
438
+ document.addEventListener("transcript:turn-finished", notifyFinished);
439
+ document.addEventListener("diff:background-finished", notifyFinished);
440
+ function installRoles() {
441
+ const here=chat?.id;
442
+ if(!here)return;
443
+ for (const [p,n] of providerOptions()) {
444
+ const section=document.querySelector(".model-section."+p);
445
+ if (!section) continue;
446
+ section.querySelector(".chat-role")?.remove();
447
+ const wrap=element("div","chat-role");
448
+ const choice=roles(wrap,"Role",chat.roles?.[p],async role=>{
449
+ if(chat?.id!==here)throw Error("This chat is no longer open.");
450
+ const updated=await api("/api/chats/"+here+"/details",{roles:{[p]:role}},"PATCH");
451
+ if(chat?.id===here)chat.roles=updated.roles;
452
+ });
453
+ choice.setAttribute("aria-label",n+" role");
454
+ section.querySelector(".account-usage")?.before(wrap);
455
+ }
456
+ }
457
+ document.addEventListener("transcript:chat-opened", installRoles);
458
+ document.addEventListener("transcript:turn-finished", installRoles);
459
+ async function refreshLibrary() {
460
+ const state=await api("/api/state");chatList=state.chats;renderChatList();
461
+ }
462
+ window.refreshDiffLibrary=refreshLibrary;
463
+ })();