aegisone 1.0.30 → 1.0.32

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.
@@ -373,8 +373,37 @@
373
373
  <p class="hint" id="confirm-mode-hint"></p>
374
374
  </section>
375
375
 
376
- <section class="card">
377
- <h2>Sessions</h2>
376
+ <!-- Sessions and Memory are panes behind one strip now, not two
377
+ always-on cards stacked in the column. `role=tab`/`aria-selected`
378
+ rather than styled buttons: the strip has to be a real tablist for
379
+ a screen reader to announce which pane is up. The Memory tab ships
380
+ `hidden` because its usefulness is not known until the first memory
381
+ read answers — renderMemoryResults() un-hides it only when there is
382
+ something above the importance floor to show. -->
383
+ <div class="pane-tabs" id="pane-tabs" role="tablist" aria-label="Sidebar sections">
384
+ <button
385
+ type="button"
386
+ class="pane-tab"
387
+ id="tab-sessions"
388
+ role="tab"
389
+ aria-selected="true"
390
+ aria-controls="pane-sessions"
391
+ >Sessions</button>
392
+ <button
393
+ type="button"
394
+ class="pane-tab"
395
+ id="tab-memory"
396
+ role="tab"
397
+ aria-selected="false"
398
+ aria-controls="pane-memory"
399
+ hidden
400
+ >Memory</button>
401
+ </div>
402
+
403
+ <section class="card" id="pane-sessions" role="tabpanel" aria-labelledby="tab-sessions">
404
+ <!-- No <h2> here: the tab above already names this pane, and the strip
405
+ is what a reader orients by. A second heading repeating "Sessions"
406
+ one line below the tab spends a line to say nothing new. -->
378
407
  <button type="button" id="sessions-refresh" class="ghost-btn">Refresh</button>
379
408
  <button type="button" id="sync-now" class="ghost-btn">Sync now</button>
380
409
  <button type="button" id="sessions-export" class="ghost-btn">Export</button>
@@ -383,7 +412,7 @@
383
412
  <p class="hint" id="sync-status"></p>
384
413
  </section>
385
414
 
386
- <section class="card">
415
+ <section class="card" id="pane-memory" role="tabpanel" aria-labelledby="tab-memory" hidden>
387
416
  <!-- The heading is the click target for the full memory inspector.
388
417
  The button lives *inside* the h2 (not the reverse) because a
389
418
  <button> may only contain phrasing content, and <h2> is not. -->
@@ -398,25 +427,36 @@
398
427
  <span class="ctb-expand" aria-hidden="true">⤢</span>
399
428
  </button>
400
429
  </h2>
401
- <form id="memory-search-form" class="memory-search">
402
- <input
403
- type="text"
404
- id="memory-query"
405
- placeholder="Search memory…"
406
- autocomplete="off"
407
- />
408
- <button type="submit" id="memory-search-btn">Search</button>
409
- </form>
410
- <ul class="memory-results" id="memory-results"></ul>
411
- <textarea
412
- id="memory-entry"
413
- rows="2"
414
- placeholder="Save a note to memory…"
415
- ></textarea>
416
- <button type="button" id="memory-save-btn" class="btn-block">Save to memory</button>
417
- <button type="button" id="memory-import-btn" class="btn-block">
418
- Import from other AI tools…
419
- </button>
430
+ <!-- The box below the heading is the *quick* surface: search, save,
431
+ import. It is omitted (renderMemoryResults) when memory holds
432
+ nothing above IMPORTANCE_FLOOR, because a panel that lists four
433
+ low-salience scraps is noise in a column the user reads every
434
+ turn. The heading's button still opens the full inspector, so
435
+ nothing becomes unreachable when the box is gone. -->
436
+ <p class="hint" id="memory-quiet" hidden>
437
+ Nothing above importance <span id="memory-quiet-floor">5</span> yet.
438
+ </p>
439
+ <div id="memory-box">
440
+ <form id="memory-search-form" class="memory-search">
441
+ <input
442
+ type="text"
443
+ id="memory-query"
444
+ placeholder="Search memory…"
445
+ autocomplete="off"
446
+ />
447
+ <button type="submit" id="memory-search-btn">Search</button>
448
+ </form>
449
+ <ul class="memory-results" id="memory-results"></ul>
450
+ <textarea
451
+ id="memory-entry"
452
+ rows="2"
453
+ placeholder="Save a note to memory…"
454
+ ></textarea>
455
+ <button type="button" id="memory-save-btn" class="btn-block">Save to memory</button>
456
+ <button type="button" id="memory-import-btn" class="btn-block">
457
+ Import from other AI tools…
458
+ </button>
459
+ </div>
420
460
  <p class="hint" id="memory-hint"></p>
421
461
  </section>
422
462
 
@@ -755,6 +795,14 @@
755
795
  one text field, and the mode chip (which changes whether tools run
756
796
  unattended) was the furthest from the thing it governs. -->
757
797
  <div class="composer-row">
798
+ <!-- Which provider answers the next send. This is the one place in
799
+ the window where that fact is shown: messages used to carry an
800
+ author line (`You` / `AEGIS`), and `AEGIS` was wrong on every
801
+ byok and local turn — the reply came from Anthropic or from a
802
+ localhost daemon. Painted by provider-mark.js from the picker
803
+ selection via updateBudgetControls(), so it cannot disagree
804
+ with the model actually selected above. -->
805
+ <span class="provider-mark-slot" id="provider-mark"></span>
758
806
  <label
759
807
  class="flow-toggle"
760
808
  for="explore-toggle"
@@ -1083,10 +1131,15 @@
1083
1131
  <script src="transcript-view.js"></script>
1084
1132
  <script src="diff.js"></script>
1085
1133
  <script src="diffview.js"></script>
1134
+ <script src="filepreview.js"></script>
1086
1135
  <script src="vendor/marked.umd.js"></script>
1087
1136
  <script src="vendor/purify.min.js"></script>
1088
1137
  <script src="vendor/aegis-highlight.js"></script>
1089
1138
  <script src="markdown.js"></script>
1139
+ <!-- Paints the provider glyph in the composer row from the selected model
1140
+ id. Loaded before app.js, which calls window.aegisProviderMark.paint
1141
+ through updateBudgetControls(). -->
1142
+ <script src="provider-mark.js"></script>
1090
1143
  <!-- Loaded before app.js: app.js's init() calls window.aegisFingerprint.mount
1091
1144
  and composes its overlay into the Escape policy, and the orphan check in
1092
1145
  test/renderer-wiring.test.mjs fails if this tag goes missing. -->
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ "use strict";const VENDOR_MATCHERS=Object.freeze(["azure-openai","huggingface","openrouter","together-ai","anthropic","deepseek","fireworks","voyage-ai","together","gemini","google","mistral","openai","grok","x-ai","xai","groq"]),PROVIDER_LABELS=Object.freeze({openai:"OpenAI",anthropic:"Anthropic",deepseek:"DeepSeek",google:"Gemini",gemini:"Gemini",groq:"Groq",mistral:"Mistral",openrouter:"OpenRouter",together:"Together","together-ai":"Together",xai:"xAI","x-ai":"xAI",grok:"xAI",huggingface:"Hugging Face",fireworks:"Fireworks","voyage-ai":"Voyage AI","azure-openai":"Azure OpenAI"});function providerOfModel(e){const r=String(null==e?"":e).toLowerCase();if(!r)return"";const t=r.indexOf(":");if(t>0){const e=r.slice(0,t);if(PROVIDER_LABELS[e])return e}const i=r.indexOf("/");if(i>0){const e=r.slice(0,i);if(PROVIDER_LABELS[e])return e}if(r.startsWith("claude"))return"anthropic";if(/^gpt([-.\d]|$)/.test(r))return"openai";for(const e of VENDOR_MATCHERS)if(new RegExp(`(^|[/_.\\-])${e}($|[/_.\\-])`).test(r))return e;return""}function providerGlyph(e){switch(e){case"openai":return[["circle",{cx:"8",cy:"8",r:"5.4"}],["path",{d:"M8 2.6v10.8"}]];case"anthropic":return[["path",{d:"M8 2.2 12.6 13.8H10.2L9.2 11H6.8L5.8 13.8H3.4Z"}]];case"deepseek":return[["path",{d:"M2 10.4c2.2 0 3-3.2 5-3.2s2.6 2.4 4.4 2.4 1.8-1.6 2.6-1.6"}]];case"google":case"gemini":return[["path",{d:"M8 1.8 9.6 6.4 14.2 8 9.6 9.6 8 14.2 6.4 9.6 1.8 8 6.4 6.4Z"}]];case"groq":return[["path",{d:"M9.4 1.6 3.6 9.2h3.6L6 14.4l6.4-8.2H8.6Z"}]];case"mistral":return[["path",{d:"M2 13V7h3v6Z"}],["path",{d:"M6.5 13V4.6h3V13Z"}],["path",{d:"M11 13V8h3v5Z"}]];case"openrouter":return[["path",{d:"M2 8h4.4c1.2 0 1.8-.8 2.4-1.6"}],["path",{d:"M2 8h4.4c1.2 0 1.8.8 2.4 1.6"}],["path",{d:"M8.4 5.4 11.6 8 8.4 10.6"}]];case"together":case"together-ai":return[["circle",{cx:"4.6",cy:"8",r:"2.5"}],["circle",{cx:"11.4",cy:"8",r:"2.5"}]];case"xai":case"x-ai":case"grok":return[["path",{d:"M3 3l10 10M13 3L3 13"}]];case"huggingface":return[["path",{d:"M8 2.4 13.4 5.4 8 8.4 2.6 5.4Z"}],["path",{d:"M2.6 8 8 11l5.4-3"}]];case"fireworks":case"voyage-ai":return[["path",{d:"M2 8h2.4l1.4-4 2.4 8 2.4-6 1.4 2h2"}]];case"azure-openai":return[["rect",{x:"2.4",y:"2.4",width:"11.2",height:"11.2",rx:"2"}],["circle",{cx:"8",cy:"8",r:"2.8"}]];default:return[["circle",{cx:"8",cy:"8",r:"3.2"}]]}}function buildProviderMark(e,r,t){const i=providerOfModel(r),o=PROVIDER_LABELS[i]||String(t||""),n=e.createElement("span");n.className="provider-mark"+(i?` provider-${i}`:" provider-unknown"),n.setAttribute("role","img"),n.setAttribute("aria-label",o||"unknown provider"),n.title=o?`This model is served by ${o}`:"Provider unknown for this model";const a="http://www.w3.org/2000/svg",d=e.createElementNS(a,"svg");d.setAttribute("viewBox","0 0 16 16"),d.setAttribute("width","14"),d.setAttribute("height","14"),d.setAttribute("aria-hidden","true"),d.setAttribute("focusable","false");for(const[r,t]of providerGlyph(i)){const i=e.createElementNS(a,r);for(const e of Object.keys(t))i.setAttribute(e,t[e]);d.appendChild(i)}return n.appendChild(d),{el:n,provider:i,label:o}}function paintProviderMark(e,r,t){if(!e||"undefined"==typeof document)return!1;const i=buildProviderMark(document,r,t);return e.textContent="",e.appendChild(i.el),!0}"undefined"!=typeof window&&(window.aegisProviderMark={paint:paintProviderMark,build:buildProviderMark,providerOfModel:providerOfModel,providerGlyph:providerGlyph,PROVIDER_LABELS:PROVIDER_LABELS}),"undefined"!=typeof module&&module.exports&&(module.exports={providerOfModel:providerOfModel,providerGlyph:providerGlyph,buildProviderMark:buildProviderMark,PROVIDER_LABELS:PROVIDER_LABELS,VENDOR_MATCHERS:VENDOR_MATCHERS});
@@ -951,10 +951,12 @@ body.memory-open {
951
951
  no-boxes rule the sidebar adopted, applied to the transcript. The
952
952
  reader's eye then has exactly one left edge to return to.
953
953
 
954
- 3. AUTHOR LINE, NOT A CHAT HEADER. `.who` was 11px uppercase with 0.7
955
- opacity sitting *inside* the bubble; it is now a quiet line above the
956
- prose in the body colour, so it labels the turn without competing
957
- with it.
954
+ 3. NO AUTHOR LINE. `.who` (`You` / `AEGIS`) is gone. A turn's role is
955
+ already carried by its bubble, its alignment and its background, and
956
+ `AEGIS` mislabelled every byok and local turn — the reply came from
957
+ Anthropic or a localhost daemon. The provider is now stated once, in the
958
+ composer row, where it describes the next send and is always true
959
+ (provider-mark.js). A turn's own marker is the hairline above it.
958
960
  */
959
961
  .messages {
960
962
  flex: 1;
@@ -1098,24 +1100,45 @@ body.memory-open {
1098
1100
  display: none;
1099
1101
  }
1100
1102
 
1101
- /* The author line. Uppercase micro-type at 600 weight is the one place this
1102
- sheet uses it, because it is a label and not prose — but it now sits in
1103
- --text2 on the page background instead of inside a bubble, and the user's
1104
- is tinted rather than right-aligned: in a single reading column a ragged
1105
- right edge on one turn's header breaks the column the whole layout exists
1106
- to establish. */
1107
- .who {
1108
- font-size: 11px;
1109
- font-weight: 600;
1110
- text-transform: uppercase;
1111
- letter-spacing: 0.07em;
1103
+ /* The composer's provider glyph. Replaces the per-message author line: this
1104
+ says which provider serves the NEXT send, which is the version of the fact
1105
+ that is always true (see provider-mark.js). Sized to the row's other chips
1106
+ so it reads as one of them, and in --text2 because it is a label, not the
1107
+ selection itself — the model dropdown next to it carries that weight. */
1108
+ .provider-mark-slot {
1109
+ display: inline-flex;
1110
+ align-items: center;
1111
+ justify-content: center;
1112
+ flex: none;
1113
+ width: 22px;
1114
+ height: 22px;
1115
+ border-radius: 5px;
1112
1116
  color: var(--text2);
1113
- margin-bottom: var(--s-2);
1114
- font-family: var(--font-display);
1115
1117
  }
1116
1118
 
1117
- .msg.user .who {
1118
- color: var(--purple);
1119
+ .provider-mark {
1120
+ display: inline-flex;
1121
+ align-items: center;
1122
+ justify-content: center;
1123
+ line-height: 0;
1124
+ }
1125
+
1126
+ /* Stroked, not filled: the glyphs are silhouettes traced in currentColor, so
1127
+ they need a stroke to exist at all at 14px. */
1128
+ .provider-mark svg {
1129
+ stroke: currentColor;
1130
+ stroke-width: 1.4;
1131
+ stroke-linejoin: round;
1132
+ stroke-linecap: round;
1133
+ fill: none;
1134
+ }
1135
+
1136
+ /* An unknown provider gets the neutral dot dimmed rather than hidden: the
1137
+ slot must keep its width, or the row shifts every time a model is picked
1138
+ across two classes. */
1139
+ .provider-unknown {
1140
+ color: var(--text2);
1141
+ opacity: 0.55;
1119
1142
  }
1120
1143
 
1121
1144
  /* Prose. 15px/1.65 is a touch larger than the 14px body default because this
@@ -2011,6 +2034,72 @@ label {
2011
2034
  }
2012
2035
 
2013
2036
  /* ------------------------------------------------------- sessions pane */
2037
+ /* Same reason `.session-meter[hidden]` exists: the rule above sets a display,
2038
+ which is an author declaration and therefore outranks the UA
2039
+ `[hidden] { display: none }`. Without these the tabs of the pane strip and
2040
+ the panes themselves would ignore the `hidden` attribute entirely. */
2041
+ .pane-tab[hidden],
2042
+ #pane-sessions[hidden],
2043
+ #pane-memory[hidden],
2044
+ #memory-box[hidden] {
2045
+ display: none;
2046
+ }
2047
+
2048
+ /* The strip above the two panes. A hairline underline on the active tab rather
2049
+ than a filled pill: same no-boxes rule as `.card`, and the active tab is
2050
+ already marked by aria-selected for anyone not reading the colour. */
2051
+ .pane-tabs {
2052
+ display: flex;
2053
+ align-items: center;
2054
+ gap: 4px;
2055
+ border-bottom: 1px solid var(--border);
2056
+ }
2057
+
2058
+ .pane-tab {
2059
+ appearance: none;
2060
+ background: none;
2061
+ border: 0;
2062
+ border-bottom: 2px solid transparent;
2063
+ border-radius: 0;
2064
+ padding: 6px 8px;
2065
+ margin-bottom: -1px;
2066
+ font: inherit;
2067
+ font-size: 11px;
2068
+ letter-spacing: 0.08em;
2069
+ text-transform: uppercase;
2070
+ color: var(--text2);
2071
+ cursor: pointer;
2072
+ font-family: var(--font-display);
2073
+ }
2074
+
2075
+ .pane-tab:hover {
2076
+ color: var(--text);
2077
+ }
2078
+
2079
+ .pane-tab.is-active,
2080
+ .pane-tab[aria-selected="true"] {
2081
+ color: var(--text);
2082
+ border-bottom-color: var(--teal);
2083
+ }
2084
+
2085
+ /* A tab strip directly above a card means the card's own top divider would
2086
+ double the strip's underline. `.side .card + .card` (style.css:329) still
2087
+ matches these panes — a hidden sibling is still a sibling in the DOM — so the
2088
+ rule has to be stated with equal specificity and later in the file, and it
2089
+ must cover BOTH panes, not just the first: when Sessions is hidden the
2090
+ Memory pane is the one sitting under the strip. */
2091
+ .side .pane-tabs ~ .card {
2092
+ border-top: 0;
2093
+ padding-top: 8px;
2094
+ }
2095
+
2096
+ /* The strip is the sidebar's first element, so it must not inherit the
2097
+ gap-plus-rule treatment the cards below it use. */
2098
+ .pane-tabs + .card {
2099
+ border-top: 0;
2100
+ padding-top: 8px;
2101
+ }
2102
+
2014
2103
  .sessions-list {
2015
2104
  list-style: none;
2016
2105
  margin: 8px 0 0;
@@ -2833,6 +2922,130 @@ body.is-scrolled .composer {
2833
2922
  white-space: pre;
2834
2923
  }
2835
2924
 
2925
+ /* ---------------------------------------------------------- file preview cards
2926
+ Similar to diff blocks but showing a preview of the new file content instead
2927
+ of a comparison. Useful for Write operations. */
2928
+
2929
+ .file-preview-card {
2930
+ font-family: var(--font-mono);
2931
+ font-size: 11px;
2932
+ line-height: 1.45;
2933
+ width: 100%;
2934
+ overflow-x: auto;
2935
+ margin: 1px 0 2px;
2936
+ background: var(--surface2);
2937
+ border: 1px solid var(--border);
2938
+ border-radius: var(--r-md);
2939
+ }
2940
+
2941
+ .file-preview-header {
2942
+ padding: 8px 12px;
2943
+ border-bottom: 1px solid var(--border2);
2944
+ background: var(--surface3);
2945
+ display: flex;
2946
+ align-items: center;
2947
+ justify-content: space-between;
2948
+ }
2949
+
2950
+ .file-preview-path {
2951
+ display: flex;
2952
+ align-items: center;
2953
+ gap: 8px;
2954
+ flex: 1;
2955
+ min-width: 0;
2956
+ }
2957
+
2958
+ .file-preview-icon {
2959
+ flex-shrink: 0;
2960
+ font-size: 14px;
2961
+ }
2962
+
2963
+ .file-preview-name {
2964
+ color: var(--text);
2965
+ font-weight: 500;
2966
+ white-space: nowrap;
2967
+ overflow: hidden;
2968
+ text-overflow: ellipsis;
2969
+ }
2970
+
2971
+ .file-preview-meta {
2972
+ color: var(--text3);
2973
+ font-size: 10px;
2974
+ flex-shrink: 0;
2975
+ margin-left: 8px;
2976
+ }
2977
+
2978
+ .file-preview-content {
2979
+ padding: 4px 0;
2980
+ background: #0d0f14;
2981
+ max-height: 200px;
2982
+ overflow-y: auto;
2983
+ }
2984
+
2985
+ .file-preview-line {
2986
+ display: flex;
2987
+ white-space: pre;
2988
+ padding: 2px 8px;
2989
+ width: 100%;
2990
+ }
2991
+
2992
+ .file-preview-line:hover {
2993
+ background: var(--surface2);
2994
+ }
2995
+
2996
+ .file-preview-gutter {
2997
+ color: #787878;
2998
+ user-select: none;
2999
+ margin-right: 8px;
3000
+ text-align: right;
3001
+ min-width: 3em;
3002
+ }
3003
+
3004
+ .file-preview-line-text {
3005
+ color: #f8f8f2;
3006
+ white-space: pre;
3007
+ flex: 1;
3008
+ overflow: hidden;
3009
+ text-overflow: ellipsis;
3010
+ }
3011
+
3012
+ .file-preview-footer {
3013
+ padding: 8px 12px;
3014
+ border-top: 1px solid var(--border2);
3015
+ background: var(--surface3);
3016
+ display: flex;
3017
+ align-items: center;
3018
+ justify-content: space-between;
3019
+ gap: 8px;
3020
+ }
3021
+
3022
+ .file-preview-notice {
3023
+ color: var(--text3);
3024
+ font-size: 10px;
3025
+ flex: 1;
3026
+ }
3027
+
3028
+ .file-preview-button {
3029
+ padding: 4px 12px;
3030
+ background: var(--accent);
3031
+ color: var(--bg);
3032
+ border: none;
3033
+ border-radius: var(--r-sm);
3034
+ font-size: 11px;
3035
+ font-weight: 500;
3036
+ cursor: pointer;
3037
+ white-space: nowrap;
3038
+ flex-shrink: 0;
3039
+ }
3040
+
3041
+ .file-preview-button:hover {
3042
+ filter: brightness(1.1);
3043
+ }
3044
+
3045
+ .file-preview-button:active {
3046
+ filter: brightness(0.95);
3047
+ }
3048
+
2836
3049
  /* ---------------------------------------------------------- the keys pop-up
2837
3050
  The two-key sheet (#keys-overlay, markup in index.html, driven by
2838
3051
  applyKeysPopup() in app.js). It reuses the memory inspector's translucent
@@ -0,0 +1,3 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
+ "use strict";const GENERIC_TITLE="New conversation",TITLE_SYSTEM='You name conversations. Write a short descriptive title (2 to 6 words) that captures the topic of the conversation. Never repeat the user\'s words verbatim — if the message is just a greeting or has no clear topic, name it something like "New conversation". Sentence case, no quotes, no markdown, no trailing punctuation, no explanation.',isGenericTitle=e=>!e||String(e).trim().toLowerCase()===GENERIC_TITLE.toLowerCase(),GREETINGS=new Set(["hey","heey","heyy","heyyy","hi","hii","hello","hej","hejj","yo","sup","hola","howdy","hai","heyo","hiya","wassup","greetings","namaste","ahoy","hallo"]);function isTopicless(e){const t=String(e).trim().toLowerCase().replace(/[^a-z0-9\s]/g," ").replace(/\s+/g," ").trim();if(!t)return!0;const i=t.split(" ");return!!/^(good (morning|afternoon|evening)|whats up|wassup|hey there|hello there|hi there|how are you)\b/.test(t)||i.length<=2&&t.length<=12&&GREETINGS.has(i[0])}function looksLikeEcho(e,t){const i=e=>String(e).toLowerCase().replace(/[^a-z0-9\s]/g,"").replace(/\s+/g," ").trim(),n=i(e),o=i(t);if(!n||!o)return!1;if(n===o)return!0;if(o.length<=14&&(n.startsWith(o)||o.startsWith(n)))return!0;if(o.length<=24){const i=e=>new Set((String(e).toLowerCase().match(/[a-z0-9]+/g)||[]).filter((e=>!ECHO_STOP.has(e)))),n=i(e),o=i(t);if(n.size&&n.size===o.size&&[...n].every((e=>o.has(e))))return!0}return!1}const ECHO_STOP=new Set(["the","a","an","to","of","in","on","at","for","and","or","is","are","be","it","its","my","our","please","can","you","just","do","that","this"]);function cleanTitle(e){return String(null==e?"":e).replace(/\s+/g," ").trim().replace(/["'`“”‘’]/g,"").replace(/[*_#]/g,"").replace(/^\s*(?:title|name)\s*[:\-–]\s*/i,"").replace(/[.\s]+$/g,"").slice(0,60).trim()}const titlePromptOf=e=>`Write a short title for a conversation that begins with: "${String(e).slice(0,500)}"`,FILLER=/^(?:please|pls|plz|hey|hi|hello|ok(?:ay)?|so|now|just|also|and|then|maybe|well|um|uh|can you|could you|would you|will you|i want you to|i want to|i need you to|i need to|i'?d like you to|i would like you to|i'?d like to|help me|help|let'?s|lets|go ahead and)\b[\s,:;-]*/i,TRAILING_STOP=new Set(["the","a","an","in","on","at","to","for","of","and","or","with","is","are","my","our","this","that","please","can","you","could","would","i","we","just","do","it"]);function deriveTitle(e){let t=String(null==e?"":e).trim().replace(/\s+/g," ");if(!t)return GENERIC_TITLE;for(let e=0;e<6;e++){const e=t.replace(FILLER,"").trim();if(e===t)break;t=e}const i=t.split(" ").filter(Boolean);if(!i.length)return GENERIC_TITLE;const n=i.slice(0,6);for(;n.length>2&&TRAILING_STOP.has(n[n.length-1].toLowerCase().replace(/[^a-z0-9]/g,""));)n.pop();let o=n.join(" ").replace(/[.,!?;:]+$/,"").trim();return o?(o=o[0].toUpperCase()+o.slice(1),o.slice(0,60).trim()||GENERIC_TITLE):GENERIC_TITLE}async function nameConversation(e,{callModel:t,signal:i}={}){const n=null==e?"":String(e);if(!n.trim())return"";if(isTopicless(n))return GENERIC_TITLE;if(!("function"!=typeof t||i&&i.aborted)){let e=null;try{e=await t(titlePromptOf(n),{system:TITLE_SYSTEM,signal:i,naming:!0})}catch{e=null}const o=cleanTitle(e);if(o)return looksLikeEcho(o,n)?GENERIC_TITLE:o}return deriveTitle(n)}async function refineTitle(e,t,i={}){const n=i&&!0===i.named,o=i&&!0===i.seeded;if(n)return null;if(!o&&!isGenericTitle(e))return null;if(!String(t||"").trim()||isTopicless(t))return null;const r=cleanTitle(await nameConversation(t,i));return!r||isGenericTitle(r)?null:r}async function nameSession(e,t,i,n,o={}){if(!e||"function"!=typeof e.setTitle)return null;if(!i)return null;const r="function"==typeof e.getSession?e.getSession(t,i):null,s=r&&r.title,l={...o,seeded:!(!r||r.named)},a=await refineTitle(s,n,l);if(a){try{e.setTitle(t,i,a,{named:!0})}catch{return null}return a}if(isTopicless(n)&&r&&!r.named&&!isGenericTitle(s)){try{e.setTitle(t,i,GENERIC_TITLE)}catch{return null}return GENERIC_TITLE}return null}module.exports={GENERIC_TITLE:GENERIC_TITLE,TITLE_SYSTEM:TITLE_SYSTEM,isGenericTitle:isGenericTitle,isTopicless:isTopicless,looksLikeEcho:looksLikeEcho,cleanTitle:cleanTitle,titlePromptOf:titlePromptOf,deriveTitle:deriveTitle,nameConversation:nameConversation,refineTitle:refineTitle,nameSession:nameSession};
@@ -1,3 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- "use strict";const fs=require("node:fs"),path=require("node:path"),{aegisHome:aegisHome}=require("./credentials.js"),STORE_FILE="sessions.json",STORE_VERSION=2,MAX_MESSAGES_PER_SESSION=2e3;function storeDir(e){return e||aegisHome()}function storeFile(e){return path.join(storeDir(e),STORE_FILE)}function nextSeq(e){const t=("number"==typeof e.__seq?e.__seq:0)+1;return e.__seq=t,t}function toEpochMs(e){if("number"==typeof e&&Number.isFinite(e))return e;if("string"==typeof e&&e.trim()){const t=Date.parse(e);if(Number.isFinite(t))return t}return 0}function load(e){try{const t=JSON.parse(fs.readFileSync(storeFile(e),"utf8"));if(t&&"object"==typeof t&&!Array.isArray(t))return t}catch{}return{}}function atomicWrite(e,t){fs.mkdirSync(path.dirname(e),{recursive:!0});const n=`${e}.tmp-${process.pid}`;fs.writeFileSync(n,JSON.stringify(t,null,2),{mode:384}),fs.renameSync(n,e);try{fs.chmodSync(e,384)}catch{}}const LOCK_STALE_MS=2e3,LOCK_WAIT_MS=500;function lockFile(e){return`${storeFile(e)}.lock`}function acquireLock(e){const t=lockFile(e);try{fs.mkdirSync(path.dirname(t),{recursive:!0})}catch{return!1}const n=Date.now()+LOCK_WAIT_MS;for(let e=0;e<200;e++)try{const e=fs.openSync(t,"wx");return fs.writeSync(e,String(process.pid)),fs.closeSync(e),!0}catch{let e=null;try{e=Date.now()-fs.statSync(t).mtimeMs}catch{continue}if(e>LOCK_STALE_MS){try{fs.unlinkSync(t)}catch{}continue}if(Date.now()>=n)return!1;const s=Date.now()+5;for(;Date.now()<s;);}return!1}function releaseLock(e){try{fs.unlinkSync(lockFile(e))}catch{}}function mutate(e,t){const n=acquireLock(e);try{const n=load(e),s=t(n);return save(e,n),s}finally{n&&releaseLock(e)}}function save(e,t){atomicWrite(storeFile(e),t)}function trimMessages(e){return Array.isArray(e)?e.length<=MAX_MESSAGES_PER_SESSION?e:e.slice(e.length-MAX_MESSAGES_PER_SESSION):[]}function upsertSession(e,t){const n=t&&t.id;if(!n)throw new Error("session.id is required");return mutate(e,(e=>{const s=e[n]||{messages:[]};return e[n]={...s,...t,id:n,version:2},!1!==t.pending&&(e[n].pending=!0),e[n].updatedAt||(e[n].updatedAt=Date.now()),e[n].seq=nextSeq(e),e[n]}))}function appendMessage(e,t,n){if(!t)throw new Error("sessionId is required");return mutate(e,(e=>{const s=e[t]||{id:t,messages:[]},r=Array.isArray(s.messages)?s.messages:[];return s.messages=trimMessages(r.concat(n)),s.updatedAt=Date.now(),s.pending=!0,s.seq=nextSeq(e),e[t]=s,s}))}function recordExchange(e,t){const n=t||{};if(!n.sessionId)return null;const s=n.sessionId;return mutate(e,(e=>{const t=e[s]||{id:s,messages:[]},r=Array.isArray(t.messages)?t.messages:[],o=n.ts||(new Date).toISOString(),i={role:"user",content:null==n.prompt?"":String(n.prompt),ts:o},a={role:"assistant",content:null==n.reply?"":String(n.reply),ts:o};return n.tokens&&(a.tokens=n.tokens),"number"==typeof n.costUsd&&(a.costUsd=n.costUsd),n.status&&(a.status=n.status),n.model&&(a.model=n.model),n.provider&&(a.provider=n.provider),n.origin&&(i.origin=n.origin,a.origin=n.origin),t.messages=trimMessages(r.concat([i,a])),t.title=t.title||String(n.prompt||"").slice(0,60),n.cwd&&(t.cwd=n.cwd),t.origin=n.origin||t.origin||"unknown",t.updatedAt=Date.now(),t.pending=!0===n.pending,t.seq=nextSeq(e),e[s]=t,t}))}function setTitle(e,t,n){const s=String(null==n?"":n).trim().slice(0,200);return t&&s?mutate(e,(e=>{const n=e[t];return n?(n.title=s,n.updatedAt=Date.now(),n.seq=nextSeq(e),n):null})):null}function listSessions(e){const t=load(e);return Object.values(t).filter((e=>e&&e.id)).sort(((e,t)=>(t.updatedAt||0)-(e.updatedAt||0)||(t.seq||0)-(e.seq||0)))}function getSession(e,t){return load(e)[t]||null}function deleteSession(e,t){return mutate(e,(e=>(delete e[t],{ok:!0})))}function markSynced(e,t,n){return mutate(e,(e=>{const s=e[t];return s?(s.pending=!1,s.lastSyncedAt=Date.now(),n&&n.remoteId&&(s.remoteId=n.remoteId),s.seq=nextSeq(e),s):null}))}function markPending(e,t){return mutate(e,(e=>{const n=e[t];return n?(n.pending=!0,n.seq=nextSeq(e),n):null}))}function listPending(e){return listSessions(e).filter((e=>!1!==e.pending))}function mergeRemoteSessions(e,t){const n=Array.isArray(t)?t:[];return n.length?mutate(e,(e=>{let t=0;for(const s of n){const n=s&&(s.session_id||s.id);if(!n)continue;const r=e[n],o=toEpochMs(s.updated_at??s.updatedAt);r&&(r.pending||(r.updatedAt||0)>=o)||(e[n]={id:n,title:s.title||r&&r.title||"",messages:Array.isArray(s.messages)?s.messages:[],updatedAt:o||Date.now(),pending:!1,lastSyncedAt:Date.now(),remoteId:s.session_id||s.id,origin:s.source||r&&r.origin||"cloud",version:2},e[n].seq=nextSeq(e),t+=1)}return t})):0}function listSummaries(e,t=8){return listSessions(e).slice(0,t).map((e=>{const t=Array.isArray(e.messages)?e.messages:[],n=t.find((e=>e&&"user"===e.role));return{id:e.id,cwd:(e.cwd||"").split(/[\\/]/).filter(Boolean).pop()||"~",summary:String(e.title||n&&n.content||"").slice(0,60),time:new Date(e.updatedAt||Date.now()).toISOString(),own:!0,origin:e.origin||"unknown",messages:t.length,pending:!0===e.pending,dir:String(e.cwd||"")}}))}function readTranscript(e,t){const n=getSession(e,t);return n?(Array.isArray(n.messages)?n.messages:[]).filter((e=>e&&("user"===e.role||"assistant"===e.role))).map((e=>({role:e.role,text:null==e.content?"":String(e.content)}))):[]}function adopt(e,t){const n=storeFile(t);if(!(()=>{try{return fs.existsSync(n)}catch{return!1}})())return{adopted:!1,sessions:0,from:n,reason:"no legacy store"};const s=(()=>{try{const e=JSON.parse(fs.readFileSync(n,"utf8"));return e&&"object"==typeof e&&!Array.isArray(e)?e:{}}catch{return{}}})(),r=Object.values(s).filter((e=>e&&e.id));return r.length?listSessions(e).length?{adopted:!1,sessions:0,from:n,reason:"store already has sessions"}:(mutate(e,(e=>{for(const t of r)e[t.id]={...t,adoptedFrom:n,version:2},e[t.id].seq=nextSeq(e);return e.__seq=Math.max(e.__seq||0,s.__seq||0),e.version=2,null})),{adopted:!0,sessions:r.length,from:n}):{adopted:!1,sessions:0,from:n,reason:"legacy store empty"}}function toMarkdown(e){const t=e&&(e.title||e.id)||"session",n=e&&Array.isArray(e.messages)?e.messages:[],s=[`# ${t}`,""];for(const e of n){const t=e&&e.role||"unknown",n=t.charAt(0).toUpperCase()+t.slice(1),r=e&&(e.content||e.text)||"";s.push(`## ${n}`,"",r,"")}return s.join("\n")}function toJson(e){return JSON.stringify(e,null,2)}module.exports={STORE_FILE:STORE_FILE,STORE_VERSION:2,MAX_MESSAGES_PER_SESSION:MAX_MESSAGES_PER_SESSION,storeDir:storeDir,storeFile:storeFile,lockFile:lockFile,LOCK_STALE_MS:LOCK_STALE_MS,LOCK_WAIT_MS:LOCK_WAIT_MS,toEpochMs:toEpochMs,load:load,save:save,upsertSession:upsertSession,appendMessage:appendMessage,recordExchange:recordExchange,setTitle:setTitle,listSessions:listSessions,getSession:getSession,deleteSession:deleteSession,markSynced:markSynced,markPending:markPending,listPending:listPending,mergeRemoteSessions:mergeRemoteSessions,listSummaries:listSummaries,readTranscript:readTranscript,adopt:adopt,toMarkdown:toMarkdown,toJson:toJson};
3
+ "use strict";const fs=require("node:fs"),path=require("node:path"),{aegisHome:aegisHome}=require("./credentials.js"),STORE_FILE="sessions.json",STORE_VERSION=2,MAX_MESSAGES_PER_SESSION=2e3;function storeDir(e){return e||aegisHome()}function storeFile(e){return path.join(storeDir(e),STORE_FILE)}function nextSeq(e){const t=("number"==typeof e.__seq?e.__seq:0)+1;return e.__seq=t,t}function toEpochMs(e){if("number"==typeof e&&Number.isFinite(e))return e;if("string"==typeof e&&e.trim()){const t=Date.parse(e);if(Number.isFinite(t))return t}return 0}function load(e){try{const t=JSON.parse(fs.readFileSync(storeFile(e),"utf8"));if(t&&"object"==typeof t&&!Array.isArray(t))return t}catch{}return{}}function atomicWrite(e,t){fs.mkdirSync(path.dirname(e),{recursive:!0});const n=`${e}.tmp-${process.pid}`;fs.writeFileSync(n,JSON.stringify(t,null,2),{mode:384}),fs.renameSync(n,e);try{fs.chmodSync(e,384)}catch{}}const LOCK_STALE_MS=2e3,LOCK_WAIT_MS=500;function lockFile(e){return`${storeFile(e)}.lock`}function acquireLock(e){const t=lockFile(e);try{fs.mkdirSync(path.dirname(t),{recursive:!0})}catch{return!1}const n=Date.now()+LOCK_WAIT_MS;for(let e=0;e<200;e++)try{const e=fs.openSync(t,"wx");return fs.writeSync(e,String(process.pid)),fs.closeSync(e),!0}catch{let e=null;try{e=Date.now()-fs.statSync(t).mtimeMs}catch{continue}if(e>LOCK_STALE_MS){try{fs.unlinkSync(t)}catch{}continue}if(Date.now()>=n)return!1;const s=Date.now()+5;for(;Date.now()<s;);}return!1}function releaseLock(e){try{fs.unlinkSync(lockFile(e))}catch{}}function mutate(e,t){const n=acquireLock(e);try{const n=load(e),s=t(n);return save(e,n),s}finally{n&&releaseLock(e)}}function save(e,t){atomicWrite(storeFile(e),t)}function trimMessages(e){return Array.isArray(e)?e.length<=MAX_MESSAGES_PER_SESSION?e:e.slice(e.length-MAX_MESSAGES_PER_SESSION):[]}function upsertSession(e,t){const n=t&&t.id;if(!n)throw new Error("session.id is required");return mutate(e,(e=>{const s=e[n]||{messages:[]};return e[n]={...s,...t,id:n,version:2},!0===s.named&&"string"==typeof s.title&&s.title&&(e[n].title=s.title,e[n].named=!0),!1!==t.pending&&(e[n].pending=!0),e[n].updatedAt||(e[n].updatedAt=Date.now()),e[n].seq=nextSeq(e),e[n]}))}function appendMessage(e,t,n){if(!t)throw new Error("sessionId is required");return mutate(e,(e=>{const s=e[t]||{id:t,messages:[]},r=Array.isArray(s.messages)?s.messages:[];return s.messages=trimMessages(r.concat(n)),s.updatedAt=Date.now(),s.pending=!0,s.seq=nextSeq(e),e[t]=s,s}))}function recordExchange(e,t){const n=t||{};if(!n.sessionId)return null;const s=n.sessionId;return mutate(e,(e=>{const t=e[s]||{id:s,messages:[]},r=Array.isArray(t.messages)?t.messages:[],o=n.ts||(new Date).toISOString(),i={role:"user",content:null==n.prompt?"":String(n.prompt),ts:o},a={role:"assistant",content:null==n.reply?"":String(n.reply),ts:o};return n.tokens&&(a.tokens=n.tokens),"number"==typeof n.costUsd&&(a.costUsd=n.costUsd),n.status&&(a.status=n.status),n.model&&(a.model=n.model),n.provider&&(a.provider=n.provider),n.origin&&(i.origin=n.origin,a.origin=n.origin),t.messages=trimMessages(r.concat([i,a])),t.title=t.title||String(n.prompt||"").slice(0,60),n.cwd&&(t.cwd=n.cwd),t.origin=n.origin||t.origin||"unknown",t.updatedAt=Date.now(),t.pending=!0===n.pending,t.seq=nextSeq(e),e[s]=t,t}))}function setTitle(e,t,n,s){const r=String(null==n?"":n).trim().slice(0,200);if(!t||!r)return null;const o=s&&!0===s.named;return mutate(e,(e=>{const n=e[t];return n?(n.title=r,o&&(n.named=!0),n.updatedAt=Date.now(),n.seq=nextSeq(e),n):null}))}function listSessions(e){const t=load(e);return Object.values(t).filter((e=>e&&e.id)).sort(((e,t)=>(t.updatedAt||0)-(e.updatedAt||0)||(t.seq||0)-(e.seq||0)))}function getSession(e,t){return load(e)[t]||null}function deleteSession(e,t){return mutate(e,(e=>(delete e[t],{ok:!0})))}function markSynced(e,t,n){return mutate(e,(e=>{const s=e[t];return s?(s.pending=!1,s.lastSyncedAt=Date.now(),n&&n.remoteId&&(s.remoteId=n.remoteId),s.seq=nextSeq(e),s):null}))}function markPending(e,t){return mutate(e,(e=>{const n=e[t];return n?(n.pending=!0,n.seq=nextSeq(e),n):null}))}function listPending(e){return listSessions(e).filter((e=>!1!==e.pending))}function mergeRemoteSessions(e,t){const n=Array.isArray(t)?t:[];return n.length?mutate(e,(e=>{let t=0;for(const s of n){const n=s&&(s.session_id||s.id);if(!n)continue;const r=e[n],o=toEpochMs(s.updated_at??s.updatedAt);r&&(r.pending||(r.updatedAt||0)>=o)||(e[n]={id:n,title:s.title||r&&r.title||"",messages:Array.isArray(s.messages)?s.messages:[],updatedAt:o||Date.now(),pending:!1,lastSyncedAt:Date.now(),remoteId:s.session_id||s.id,origin:s.source||r&&r.origin||"cloud",version:2},e[n].seq=nextSeq(e),t+=1)}return t})):0}function listSummaries(e,t=8){return listSessions(e).slice(0,t).map((e=>{const t=Array.isArray(e.messages)?e.messages:[],n=t.find((e=>e&&"user"===e.role));return{id:e.id,cwd:(e.cwd||"").split(/[\\/]/).filter(Boolean).pop()||"~",summary:String(e.title||n&&n.content||"").slice(0,60),time:new Date(e.updatedAt||Date.now()).toISOString(),own:!0,origin:e.origin||"unknown",messages:t.length,pending:!0===e.pending,dir:String(e.cwd||"")}}))}function readTranscript(e,t){const n=getSession(e,t);return n?(Array.isArray(n.messages)?n.messages:[]).filter((e=>e&&("user"===e.role||"assistant"===e.role))).map((e=>({role:e.role,text:null==e.content?"":String(e.content)}))):[]}function adopt(e,t){const n=storeFile(t);if(!(()=>{try{return fs.existsSync(n)}catch{return!1}})())return{adopted:!1,sessions:0,from:n,reason:"no legacy store"};const s=(()=>{try{const e=JSON.parse(fs.readFileSync(n,"utf8"));return e&&"object"==typeof e&&!Array.isArray(e)?e:{}}catch{return{}}})(),r=Object.values(s).filter((e=>e&&e.id));return r.length?listSessions(e).length?{adopted:!1,sessions:0,from:n,reason:"store already has sessions"}:(mutate(e,(e=>{for(const t of r)e[t.id]={...t,adoptedFrom:n,version:2},e[t.id].seq=nextSeq(e);return e.__seq=Math.max(e.__seq||0,s.__seq||0),e.version=2,null})),{adopted:!0,sessions:r.length,from:n}):{adopted:!1,sessions:0,from:n,reason:"legacy store empty"}}function toMarkdown(e){const t=e&&(e.title||e.id)||"session",n=e&&Array.isArray(e.messages)?e.messages:[],s=[`# ${t}`,""];for(const e of n){const t=e&&e.role||"unknown",n=t.charAt(0).toUpperCase()+t.slice(1),r=e&&(e.content||e.text)||"";s.push(`## ${n}`,"",r,"")}return s.join("\n")}function toJson(e){return JSON.stringify(e,null,2)}module.exports={STORE_FILE:STORE_FILE,STORE_VERSION:2,MAX_MESSAGES_PER_SESSION:MAX_MESSAGES_PER_SESSION,storeDir:storeDir,storeFile:storeFile,lockFile:lockFile,LOCK_STALE_MS:LOCK_STALE_MS,LOCK_WAIT_MS:LOCK_WAIT_MS,toEpochMs:toEpochMs,load:load,save:save,upsertSession:upsertSession,appendMessage:appendMessage,recordExchange:recordExchange,setTitle:setTitle,listSessions:listSessions,getSession:getSession,deleteSession:deleteSession,markSynced:markSynced,markPending:markPending,listPending:listPending,mergeRemoteSessions:mergeRemoteSessions,listSummaries:listSummaries,readTranscript:readTranscript,adopt:adopt,toMarkdown:toMarkdown,toJson:toJson};