aegisone 1.0.21 → 1.0.23

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 (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -2
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -939
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -369
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/bin/aegiscode.js +2 -914
  17. package/vendor/cli/package.json +3 -2
  18. package/vendor/cli/scripts/check.mjs +1 -52
  19. package/vendor/cli/scripts/demo.mjs +1 -94
  20. package/vendor/cli/scripts/predist.mjs +1 -75
  21. package/vendor/cli/scripts/runtests.mjs +1 -56
  22. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  23. package/vendor/cli/src/agents.js +1 -139
  24. package/vendor/cli/src/app.js +1 -2932
  25. package/vendor/cli/src/art.js +1 -289
  26. package/vendor/cli/src/autonomous.js +1 -515
  27. package/vendor/cli/src/caps.js +1 -879
  28. package/vendor/cli/src/chatflow.js +1 -3008
  29. package/vendor/cli/src/checkpoint.js +1 -90
  30. package/vendor/cli/src/clipboard.js +1 -424
  31. package/vendor/cli/src/cloudsync.js +1 -528
  32. package/vendor/cli/src/commands.js +1 -3987
  33. package/vendor/cli/src/config.js +1 -581
  34. package/vendor/cli/src/connect.js +1 -349
  35. package/vendor/cli/src/credentials.js +1 -33
  36. package/vendor/cli/src/deps.js +1 -232
  37. package/vendor/cli/src/devrun.js +1 -187
  38. package/vendor/cli/src/diff.js +1 -333
  39. package/vendor/cli/src/diffview.js +1 -296
  40. package/vendor/cli/src/engine.js +1 -297
  41. package/vendor/cli/src/entitlement.js +1 -355
  42. package/vendor/cli/src/events.js +1 -707
  43. package/vendor/cli/src/export.js +1 -67
  44. package/vendor/cli/src/fingerprint.js +1 -592
  45. package/vendor/cli/src/format.js +1 -259
  46. package/vendor/cli/src/fuzzy.js +1 -119
  47. package/vendor/cli/src/gate.js +1 -55
  48. package/vendor/cli/src/history.js +1 -401
  49. package/vendor/cli/src/init.js +1 -175
  50. package/vendor/cli/src/input.js +1 -139
  51. package/vendor/cli/src/keys.js +1 -183
  52. package/vendor/cli/src/limits.js +1 -190
  53. package/vendor/cli/src/markdown.js +1 -306
  54. package/vendor/cli/src/mcp.js +1 -694
  55. package/vendor/cli/src/models.js +1 -487
  56. package/vendor/cli/src/naming.js +1 -229
  57. package/vendor/cli/src/overlays.js +1 -461
  58. package/vendor/cli/src/panels.js +1 -1418
  59. package/vendor/cli/src/permissions.js +1 -290
  60. package/vendor/cli/src/ping.js +1 -226
  61. package/vendor/cli/src/presence.js +1 -238
  62. package/vendor/cli/src/provenance.js +2 -182
  63. package/vendor/cli/src/render.js +1 -515
  64. package/vendor/cli/src/screen.js +1 -518
  65. package/vendor/cli/src/screens.js +1 -896
  66. package/vendor/cli/src/secret.js +1 -59
  67. package/vendor/cli/src/securefs.js +1 -359
  68. package/vendor/cli/src/settings.js +1 -155
  69. package/vendor/cli/src/shared.js +1 -52
  70. package/vendor/cli/src/sharedpaths.js +1 -53
  71. package/vendor/cli/src/signup.js +1 -156
  72. package/vendor/cli/src/summarize.js +1 -95
  73. package/vendor/cli/src/sysdiag.js +1 -585
  74. package/vendor/cli/src/system.js +1 -40
  75. package/vendor/cli/src/theme.js +1 -570
  76. package/vendor/cli/src/title.js +1 -220
  77. package/vendor/cli/src/todos.js +1 -115
  78. package/vendor/cli/src/tokens.js +1 -263
  79. package/vendor/cli/src/topup.js +1 -210
  80. package/vendor/cli/src/update.js +1 -181
  81. package/vendor/cli/vendor/client/aegis.js +1 -2054
  82. package/vendor/cli/vendor/client/attest.js +1 -442
  83. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  84. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  85. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  86. package/vendor/cli/vendor/client/byok-catalog.js +1 -230
  87. package/vendor/cli/vendor/client/credentials.js +1 -494
  88. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  89. package/vendor/cli/vendor/client/drive-connect.js +1 -85
  90. package/vendor/cli/vendor/client/drive-upload.js +1 -174
  91. package/vendor/cli/vendor/client/env-file.js +1 -1273
  92. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  93. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  94. package/vendor/cli/vendor/client/google-signin.js +1 -125
  95. package/vendor/cli/vendor/client/hooks.js +1 -430
  96. package/vendor/cli/vendor/client/model-discovery.js +1 -330
  97. package/vendor/cli/vendor/client/platform.js +1 -937
  98. package/vendor/cli/vendor/client/prefs.js +1 -351
  99. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  100. package/vendor/cli/vendor/client/presence.js +1 -438
  101. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  102. package/vendor/cli/vendor/client/session-store.js +1 -548
  103. package/vendor/cli/vendor/client/topup.js +1 -297
  104. package/vendor/cli/vendor/client/touch.js +1 -458
  105. package/vendor/cli/vendor/client/update.js +1 -704
  106. package/vendor/cli/vendor/client/user-models.js +1 -381
  107. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  108. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  109. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -993
  110. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -95
  111. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3228
  112. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -654
  113. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  114. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2135
  115. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -275
  116. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  117. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -208
  118. package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -680
  119. package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1238
  120. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  121. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  122. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  123. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  124. package/vendor/cli/vendor/hosts/install.js +1 -638
  125. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  126. package/vendor/cli/vendor/hosts/spec.js +1 -164
  127. package/vendor/cli/vendor/hosts/targets.js +1 -346
  128. package/vendor/cli/vendor/mcp/server.js +1 -221
  129. package/vendor/cli/vendor/mcp/tools.js +1 -408
  130. package/vendor/cli/vendor/one/src/child.js +1 -285
  131. package/vendor/cli/vendor/one/src/permissions.js +1 -369
  132. package/vendor/desktop/bin/aegis.js +1 -32
  133. package/vendor/desktop/lib/account-key.js +1 -56
  134. package/vendor/desktop/lib/auto.js +1 -430
  135. package/vendor/desktop/lib/avatar/companion.js +1 -698
  136. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  137. package/vendor/desktop/lib/avatar/events.js +1 -344
  138. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  139. package/vendor/desktop/lib/avatar/holders.js +1 -612
  140. package/vendor/desktop/lib/avatar/identity.js +1 -641
  141. package/vendor/desktop/lib/avatar/level.js +1 -368
  142. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  143. package/vendor/desktop/lib/avatar/persona.js +1 -388
  144. package/vendor/desktop/lib/avatar/profile.js +1 -977
  145. package/vendor/desktop/lib/avatar/register.js +1 -307
  146. package/vendor/desktop/lib/avatar/store.js +1 -472
  147. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  148. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  149. package/vendor/desktop/lib/avatar/turn.js +1 -216
  150. package/vendor/desktop/lib/avatar/voice.js +1 -328
  151. package/vendor/desktop/lib/avatar/xp.js +1 -404
  152. package/vendor/desktop/lib/deep-link.js +1 -120
  153. package/vendor/desktop/lib/fingerprint.js +2 -347
  154. package/vendor/desktop/lib/google-connect.js +1 -169
  155. package/vendor/desktop/lib/local/agents.js +1 -105
  156. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  157. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  158. package/vendor/desktop/lib/local/context.js +1 -95
  159. package/vendor/desktop/lib/local/engine.js +1 -3228
  160. package/vendor/desktop/lib/local/entitlement.js +1 -654
  161. package/vendor/desktop/lib/local/git-scope.js +1 -228
  162. package/vendor/desktop/lib/local/local.js +1 -2135
  163. package/vendor/desktop/lib/local/prompt.js +1 -275
  164. package/vendor/desktop/lib/local/queue.js +1 -560
  165. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  166. package/vendor/desktop/lib/local/shell.js +1 -680
  167. package/vendor/desktop/lib/local/telemetry.js +1 -470
  168. package/vendor/desktop/lib/local/tools.js +1 -1238
  169. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  170. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  171. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  172. package/vendor/desktop/lib/quick-launcher.js +1 -84
  173. package/vendor/desktop/lib/settings.js +1 -890
  174. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  175. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  176. package/vendor/desktop/lib/sync/sessions.js +1 -106
  177. package/vendor/desktop/lib/window-state.js +1 -66
  178. package/vendor/desktop/main.js +1 -4390
  179. package/vendor/desktop/package.json +3 -5
  180. package/vendor/desktop/preload.js +1 -628
  181. package/vendor/desktop/renderer/app.js +1 -6560
  182. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  183. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  184. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  185. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  186. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  187. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  188. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  189. package/vendor/desktop/renderer/budget.js +1 -168
  190. package/vendor/desktop/renderer/companion.js +1 -223
  191. package/vendor/desktop/renderer/diff.js +1 -359
  192. package/vendor/desktop/renderer/diffview.js +1 -336
  193. package/vendor/desktop/renderer/fingerprint.js +3 -720
  194. package/vendor/desktop/renderer/markdown.js +1 -168
  195. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  196. package/vendor/desktop/renderer/providers.js +1 -259
  197. package/vendor/desktop/renderer/quick.js +1 -191
  198. package/vendor/desktop/renderer/stream-policy.js +1 -306
  199. package/vendor/desktop/renderer/transcript-view.js +1 -323
  200. package/vendor/desktop/renderer/usage.js +1 -1239
  201. package/vendor/desktop/vendor/aegis.js +1 -2054
  202. package/vendor/desktop/vendor/attest.js +1 -442
  203. package/vendor/desktop/vendor/authorship-key.js +1 -410
  204. package/vendor/desktop/vendor/auto-provision.js +1 -134
  205. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  206. package/vendor/desktop/vendor/byok-catalog.js +1 -230
  207. package/vendor/desktop/vendor/credentials.js +1 -494
  208. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  209. package/vendor/desktop/vendor/drive-connect.js +1 -85
  210. package/vendor/desktop/vendor/drive-upload.js +1 -174
  211. package/vendor/desktop/vendor/env-file.js +1 -1273
  212. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  213. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  214. package/vendor/desktop/vendor/google-signin.js +1 -125
  215. package/vendor/desktop/vendor/hooks.js +1 -430
  216. package/vendor/desktop/vendor/model-discovery.js +1 -330
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -548
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -704
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,231 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
- // Conveying a modified copy, or running one as a network service, owes the
5
- // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
- 'use strict';
7
-
8
- /**
9
- * Naming a conversation, with the model — the CLI's half of what the engine
10
- * ships as `generateTitle()` in `aegiscodex-dev/src/backend.js`.
11
- *
12
- * What the CLI had before this module: `title.js`, which derives the terminal
13
- * title *locally* from the user's own words (`topicFrom`), and `/resume`, which
14
- * lists sessions by `(e.prompt || '').slice(0, 60)` — the raw first message,
15
- * truncated. So a session was called "heey" in the tab bar and "heey" in the
16
- * picker, which is a prompt, not a name.
17
- *
18
- * This is the ladder the engine settled on, in order:
19
- *
20
- * 1. topicless first message (a greeting) → GENERIC_TITLE, and NO model call.
21
- * Asking just makes the model echo the prompt back ("heey" → "Heey
22
- * There"), so it is both cheaper and more deterministic to answer locally.
23
- * 2. the session's own model, one no-tool round, asked to name the
24
- * conversation (2–6 words, never the user's words verbatim).
25
- * 3. a purely local derivation from the prompt (capitalized head, stopwords
26
- * trimmed) when no model answered.
27
- *
28
- * Two guarantees carry over from the engine, and both are load-bearing:
29
- *
30
- * · a title that merely echoes the prompt ("fix bug" → "Fix The Bug") is not a
31
- * name — it is replaced by GENERIC_TITLE, and the caller keeps re-asking on
32
- * later turns until a real topic lands. That is what makes a session named
33
- * after a greeting get its real name once the user says what they want.
34
- * · naming is best-effort and never on the critical path: `nameConversation`
35
- * resolves (never throws) and its caller is free to ignore the result.
36
- *
37
- * The model round is *injected* (`callModel`), not spawned here: the CLI's own
38
- * turn path already knows how to talk to whichever backend the session uses
39
- * (pooled, BYOK or the reference CLI), and a naming round must not become a
40
- * second, differently-authenticated client.
41
- *
42
- * Ported from aegiscodex-dev/src/backend.js (TITLE_SYSTEM, isTopicless,
43
- * looksLikeEcho, deriveTitle, titleModelChain) so a terminal session and a
44
- * desktop thread are named by the same rules.
45
- */
46
-
47
- /** The name a conversation gets before it has a topic. Deliberately generic and
48
- * deliberately NOT the raw prompt — the whole point is that "heey" is not a
49
- * name, and the caller re-asks until a real one lands. */
50
- const GENERIC_TITLE = 'New conversation';
51
-
52
- const TITLE_SYSTEM =
53
- '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.';
54
-
55
- const isGenericTitle = (t) => !t || String(t).trim().toLowerCase() === GENERIC_TITLE.toLowerCase();
56
-
57
- // A greeting / topicless first message has no topic to name — asking the model
58
- // just makes it echo the prompt back ("heey" -> "Heey There"). Detect those up
59
- // front and skip the round entirely: it is cheaper and deterministic.
60
- const GREETINGS = new Set([
61
- 'hey', 'heey', 'heyy', 'heyyy', 'hi', 'hii', 'hello', 'hej', 'hejj', 'yo',
62
- 'sup', 'hola', 'howdy', 'hai', 'heyo', 'hiya', 'wassup', 'greetings',
63
- 'namaste', 'ahoy', 'hallo',
64
- ]);
65
-
66
- function isTopicless(raw) {
67
- const p = String(raw).trim().toLowerCase().replace(/[^a-z0-9\s]/g, ' ').replace(/\s+/g, ' ').trim();
68
- if (!p) return true;
69
- const words = p.split(' ');
70
- if (/^(good (morning|afternoon|evening)|whats up|wassup|hey there|hello there|hi there|how are you)\b/.test(p)) return true;
71
- // A lone greeting word, or a short greeting phrase (<=2 words, <=12 chars)
72
- // whose first word is a greeting, has no discernible topic.
73
- return words.length <= 2 && p.length <= 12 && GREETINGS.has(words[0]);
74
- }
75
-
76
- /** The model sometimes still echoes a short prompt despite the instruction
77
- * ("fix bug" -> "Fix The Bug"). That is not a rename; treat it as topicless. */
78
- function looksLikeEcho(title, prompt) {
79
- const norm = (s) => String(s).toLowerCase().replace(/[^a-z0-9\s]/g, '').replace(/\s+/g, ' ').trim();
80
- const t = norm(title);
81
- const p = norm(prompt);
82
- if (!t || !p) return false;
83
- if (t === p) return true;
84
- // Short prompt that the title merely prefixes with a trivial continuation.
85
- if (p.length <= 14 && (t.startsWith(p) || p.startsWith(t))) return true;
86
- // …and the rule the engine's own comment names but its test misses. The
87
- // engine compares raw prefixes, so its documented example — "fix bug" ->
88
- // "Fix The Bug" — slips through: the model inserted "the", `t.startsWith(p)`
89
- // is false, and the session keeps a title that is just the prompt again.
90
- // Compare the CONTENT words instead (function words dropped on both sides),
91
- // for short prompts only, where the risk of discarding a genuine title is
92
- // negligible and the benefit is the case the rule exists for.
93
- if (p.length <= 24) {
94
- const words = (s) => new Set((String(s).toLowerCase().match(/[a-z0-9]+/g) || []).filter((w) => !ECHO_STOP.has(w)));
95
- const a = words(title);
96
- const b = words(prompt);
97
- if (a.size && a.size === b.size && [...a].every((w) => b.has(w))) return true;
98
- }
99
- return false;
100
- }
101
-
102
- /** Function words that carry no topic, dropped before the echo comparison. */
103
- const ECHO_STOP = new Set([
104
- 'the', 'a', 'an', 'to', 'of', 'in', 'on', 'at', 'for', 'and', 'or', 'is',
105
- 'are', 'be', 'it', 'its', 'my', 'our', 'please', 'can', 'you', 'just', 'do',
106
- 'that', 'this',
107
- ]);
108
-
109
- /** One-line cleanup of whatever the model answered: no quotes, no markdown, no
110
- * trailing punctuation, clipped. '' means "unusable".
111
- *
112
- * Order matters: a model asked not to quote often answers `"Title: Fixing the
113
- * slow request."` anyway, and stripping the label prefix BEFORE the quotes
114
- * leaves it in place (the `^` never sees past the opening quote) — measured.
115
- * Quotes and markdown come off first, then the label. */
116
- function cleanTitle(raw) {
117
- return String(raw == null ? '' : raw)
118
- .replace(/\s+/g, ' ')
119
- .trim()
120
- .replace(/["'`“”‘’]/g, '')
121
- .replace(/[*_#]/g, '')
122
- .replace(/^\s*(?:title|name)\s*[:\-–]\s*/i, '')
123
- .replace(/[.\s]+$/g, '')
124
- .slice(0, 60)
125
- .trim();
126
- }
127
-
128
- /** The naming instruction the model is asked to answer (never the user's task). */
129
- const titlePromptOf = (prompt) =>
130
- `Write a short title for a conversation that begins with: "${String(prompt).slice(0, 500)}"`;
131
-
132
- /**
133
- * Politeness and throat-clearing, stripped from the front of a prompt, so the
134
- * fallback name says "Do the thing" instead of "Please Can You Just Do". Same
135
- * list `title.js` uses for the terminal topic — one habit, stripped once.
136
- */
137
- const FILLER =
138
- /^(?: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;
139
-
140
- /** Words that carry no topic when trimming the tail of a derived name. */
141
- const TRAILING_STOP = new Set([
142
- 'the', 'a', 'an', 'in', 'on', 'at', 'to', 'for', 'of', 'and', 'or', 'with',
143
- 'is', 'are', 'my', 'our', 'this', 'that', 'please', 'can', 'you', 'could',
144
- 'would', 'i', 'we', 'just', 'do', 'it',
145
- ]);
146
-
147
- /**
148
- * Last rung: a name derived from the prompt, used only when no model answered.
149
- * Never the bare product name, and never the raw prompt verbatim.
150
- *
151
- * Sentence case, not Title Case: that is what TITLE_SYSTEM asks the model for,
152
- * so the fallback matches the names around it. (The engine's derivation
153
- * capitalizes every word — "Add A Retry To The Fetcher" — which reads like a
154
- * heading next to the model's own answers.)
155
- */
156
- function deriveTitle(prompt) {
157
- let body = String(prompt == null ? '' : prompt).trim().replace(/\s+/g, ' ');
158
- if (!body) return GENERIC_TITLE;
159
- for (let i = 0; i < 6; i++) {
160
- const next = body.replace(FILLER, '').trim();
161
- if (next === body) break;
162
- body = next;
163
- }
164
- const words = body.split(' ').filter(Boolean);
165
- if (!words.length) return GENERIC_TITLE;
166
- const head = words.slice(0, 6);
167
- while (head.length > 2 && TRAILING_STOP.has(head[head.length - 1].toLowerCase().replace(/[^a-z0-9]/g, ''))) head.pop();
168
- let out = head.join(' ').replace(/[.,!?;:]+$/, '').trim();
169
- if (!out) return GENERIC_TITLE;
170
- out = out[0].toUpperCase() + out.slice(1);
171
- return out.slice(0, 60).trim() || GENERIC_TITLE;
172
- }
173
-
174
- /**
175
- * Name a conversation from its first user prompt.
176
- *
177
- * `callModel(prompt)` (async) is the caller's own model seam and must return a
178
- * string (or null). With no `callModel` — demo mode, or a caller that has no
179
- * backend — it answers from the local derivation, exactly like the engine's
180
- * `generateTitle` falls back through its chain. Never throws; resolves '' only
181
- * when there was no prompt at all (the caller keeps whatever it had).
182
- *
183
- * `{ signal }` is honoured between rounds and passed through, so aborting a turn
184
- * abandons a naming round in flight rather than leaving it running.
185
- */
186
- async function nameConversation(prompt, { callModel, signal } = {}) {
187
- const raw = prompt == null ? '' : String(prompt);
188
- if (!raw.trim()) return '';
189
- if (isTopicless(raw)) return GENERIC_TITLE;
190
- if (typeof callModel === 'function' && !(signal && signal.aborted)) {
191
- let answer = null;
192
- try {
193
- answer = await callModel(titlePromptOf(raw), { system: TITLE_SYSTEM, signal, naming: true });
194
- } catch {
195
- answer = null;
196
- }
197
- const title = cleanTitle(answer);
198
- if (title) return looksLikeEcho(title, raw) ? GENERIC_TITLE : title;
199
- }
200
- return deriveTitle(raw);
201
- }
202
-
203
- /**
204
- * The title a session should carry after a later prompt, given the one it has.
205
- *
206
- * While the session is still wearing GENERIC_TITLE (the user opened with "heey"
207
- * and has now said what they actually want) the next real ask renames it; once a
208
- * real title exists it is kept, so a follow-up does not rename a session away
209
- * from its topic. `null` means "no opinion, keep what you have".
210
- */
211
- async function refineTitle(currentTitle, prompt, opts = {}) {
212
- if (!isGenericTitle(currentTitle)) return null;
213
- if (!String(prompt || '').trim() || isTopicless(prompt)) return null;
214
- const next = await nameConversation(prompt, opts);
215
- const cleaned = cleanTitle(next);
216
- if (!cleaned || isGenericTitle(cleaned)) return null;
217
- return cleaned;
218
- }
219
-
220
- module.exports = {
221
- GENERIC_TITLE,
222
- TITLE_SYSTEM,
223
- isGenericTitle,
224
- isTopicless,
225
- looksLikeEcho,
226
- cleanTitle,
227
- titlePromptOf,
228
- deriveTitle,
229
- nameConversation,
230
- refineTitle,
231
- };
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={}){if(!isGenericTitle(e))return null;if(!String(t||"").trim()||isTopicless(t))return null;const n=cleanTitle(await nameConversation(t,i));return!n||isGenericTitle(n)?null:n}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};