aegisone 1.0.34 → 1.0.35

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 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  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 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  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 -575
  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 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,285 +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 — the ONE implementation, for every host.
10
- *
11
- * `cli/src/naming.js` documented the ladder and the desktop face never got it:
12
- * the window named a thread with `prompt.slice(0, 60)` (renderer/app.js
13
- * `sync.save`) and `session-store.js`'s `recordExchange` seeds every CLI
14
- * session the same way. So a desktop thread called its first message a name —
15
- * "heey" in the sidebar, "can you fix the binaries for aegis-desktop. why is
16
- * old version kicking in" clipped mid-word — while the same conversation in a
17
- * terminal was named "Fix the desktop binaries". Same conversation, two names,
18
- * depending on which host you opened it in.
19
- *
20
- * This module is that ladder moved to `client/` so both faces share one
21
- * implementation instead of the desktop re-deriving it:
22
- *
23
- * 1. topicless first message (a greeting) → GENERIC_TITLE, and NO model call.
24
- * Asking just makes the model echo the prompt back ("heey" → "Heey
25
- * There"), so it is both cheaper and more deterministic to answer locally.
26
- * 2. the session's own model, one no-tool round, asked to name the
27
- * conversation (2–6 words, never the user's words verbatim).
28
- * 3. a purely local derivation from the prompt (capitalized head, stopwords
29
- * trimmed) when no model answered.
30
- *
31
- * Two guarantees carry over, and both are load-bearing:
32
- *
33
- * · a title that merely echoes the prompt ("fix bug" → "Fix The Bug") is not a
34
- * name — it is replaced by GENERIC_TITLE, and the caller keeps re-asking on
35
- * later turns until a real topic lands.
36
- * · naming is best-effort and never on the critical path: `nameConversation`
37
- * resolves (never throws) and its caller is free to ignore the result.
38
- *
39
- * The model round is *injected* (`callModel`), not spawned here: each host's
40
- * turn path already knows how to talk to whichever backend the session uses
41
- * (pooled, BYOK or the reference CLI), and a naming round must not become a
42
- * second, differently-authenticated client.
43
- *
44
- * `cli/src/naming.js` is now a thin re-export of this file, so the CLI's
45
- * existing callers and its test keep working while there is exactly one copy
46
- * of the rules. A fork here is how the two hosts' names would drift apart
47
- * again.
48
- */
49
-
50
- /** The name a conversation gets before it has a topic. Deliberately generic and
51
- * deliberately NOT the raw prompt — the whole point is that "heey" is not a
52
- * name, and the caller re-asks until a real one lands. */
53
- const GENERIC_TITLE = 'New conversation';
54
-
55
- const TITLE_SYSTEM =
56
- '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.';
57
-
58
- const isGenericTitle = (t) => !t || String(t).trim().toLowerCase() === GENERIC_TITLE.toLowerCase();
59
-
60
- // A greeting / topicless first message has no topic to name — asking the model
61
- // just makes it echo the prompt back ("heey" -> "Heey There"). Detect those up
62
- // front and skip the round entirely: it is cheaper and deterministic.
63
- const GREETINGS = new Set([
64
- 'hey', 'heey', 'heyy', 'heyyy', 'hi', 'hii', 'hello', 'hej', 'hejj', 'yo',
65
- 'sup', 'hola', 'howdy', 'hai', 'heyo', 'hiya', 'wassup', 'greetings',
66
- 'namaste', 'ahoy', 'hallo',
67
- ]);
68
-
69
- function isTopicless(raw) {
70
- const p = String(raw).trim().toLowerCase().replace(/[^a-z0-9\s]/g, ' ').replace(/\s+/g, ' ').trim();
71
- if (!p) return true;
72
- const words = p.split(' ');
73
- if (/^(good (morning|afternoon|evening)|whats up|wassup|hey there|hello there|hi there|how are you)\b/.test(p)) return true;
74
- // A lone greeting word, or a short greeting phrase (<=2 words, <=12 chars)
75
- // whose first word is a greeting, has no discernible topic.
76
- return words.length <= 2 && p.length <= 12 && GREETINGS.has(words[0]);
77
- }
78
-
79
- /** The model sometimes still echoes a short prompt despite the instruction
80
- * ("fix bug" -> "Fix The Bug"). That is not a rename; treat it as topicless. */
81
- function looksLikeEcho(title, prompt) {
82
- const norm = (s) => String(s).toLowerCase().replace(/[^a-z0-9\s]/g, '').replace(/\s+/g, ' ').trim();
83
- const t = norm(title);
84
- const p = norm(prompt);
85
- if (!t || !p) return false;
86
- if (t === p) return true;
87
- // Short prompt that the title merely prefixes with a trivial continuation.
88
- if (p.length <= 14 && (t.startsWith(p) || p.startsWith(t))) return true;
89
- // …and the rule the engine's own comment names but its test misses. The
90
- // engine compares raw prefixes, so its documented example — "fix bug" ->
91
- // "Fix The Bug" — slips through: the model inserted "the", `t.startsWith(p)`
92
- // is false, and the session keeps a title that is just the prompt again.
93
- // Compare the CONTENT words instead (function words dropped on both sides),
94
- // for short prompts only, where the risk of discarding a genuine title is
95
- // negligible and the benefit is the case the rule exists for.
96
- if (p.length <= 24) {
97
- const words = (s) => new Set((String(s).toLowerCase().match(/[a-z0-9]+/g) || []).filter((w) => !ECHO_STOP.has(w)));
98
- const a = words(title);
99
- const b = words(prompt);
100
- if (a.size && a.size === b.size && [...a].every((w) => b.has(w))) return true;
101
- }
102
- return false;
103
- }
104
-
105
- /** Function words that carry no topic, dropped before the echo comparison. */
106
- const ECHO_STOP = new Set([
107
- 'the', 'a', 'an', 'to', 'of', 'in', 'on', 'at', 'for', 'and', 'or', 'is',
108
- 'are', 'be', 'it', 'its', 'my', 'our', 'please', 'can', 'you', 'just', 'do',
109
- 'that', 'this',
110
- ]);
111
-
112
- /** One-line cleanup of whatever the model answered: no quotes, no markdown, no
113
- * trailing punctuation, clipped. '' means "unusable".
114
- *
115
- * Order matters: a model asked not to quote often answers `"Title: Fixing the
116
- * slow request."` anyway, and stripping the label prefix BEFORE the quotes
117
- * leaves it in place (the `^` never sees past the opening quote) — measured.
118
- * Quotes and markdown come off first, then the label. */
119
- function cleanTitle(raw) {
120
- return String(raw == null ? '' : raw)
121
- .replace(/\s+/g, ' ')
122
- .trim()
123
- .replace(/["'`“”‘’]/g, '')
124
- .replace(/[*_#]/g, '')
125
- .replace(/^\s*(?:title|name)\s*[:\-–]\s*/i, '')
126
- .replace(/[.\s]+$/g, '')
127
- .slice(0, 60)
128
- .trim();
129
- }
130
-
131
- /** The naming instruction the model is asked to answer (never the user's task). */
132
- const titlePromptOf = (prompt) =>
133
- `Write a short title for a conversation that begins with: "${String(prompt).slice(0, 500)}"`;
134
-
135
- /**
136
- * Politeness and throat-clearing, stripped from the front of a prompt, so the
137
- * fallback name says "Do the thing" instead of "Please Can You Just Do". Same
138
- * list the terminal title uses for its topic — one habit, stripped once.
139
- */
140
- const FILLER =
141
- /^(?: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;
142
-
143
- /** Words that carry no topic when trimming the tail of a derived name. */
144
- const TRAILING_STOP = new Set([
145
- 'the', 'a', 'an', 'in', 'on', 'at', 'to', 'for', 'of', 'and', 'or', 'with',
146
- 'is', 'are', 'my', 'our', 'this', 'that', 'please', 'can', 'you', 'could',
147
- 'would', 'i', 'we', 'just', 'do', 'it',
148
- ]);
149
-
150
- /**
151
- * Last rung: a name derived from the prompt, used only when no model answered.
152
- * Never the bare product name, and never the raw prompt verbatim.
153
- *
154
- * Sentence case, not Title Case: that is what TITLE_SYSTEM asks the model for,
155
- * so the fallback matches the names around it. (The engine's derivation
156
- * capitalizes every word — "Add A Retry To The Fetcher" — which reads like a
157
- * heading next to the model's own answers.)
158
- */
159
- function deriveTitle(prompt) {
160
- let body = String(prompt == null ? '' : prompt).trim().replace(/\s+/g, ' ');
161
- if (!body) return GENERIC_TITLE;
162
- for (let i = 0; i < 6; i++) {
163
- const next = body.replace(FILLER, '').trim();
164
- if (next === body) break;
165
- body = next;
166
- }
167
- const words = body.split(' ').filter(Boolean);
168
- if (!words.length) return GENERIC_TITLE;
169
- const head = words.slice(0, 6);
170
- while (head.length > 2 && TRAILING_STOP.has(head[head.length - 1].toLowerCase().replace(/[^a-z0-9]/g, ''))) head.pop();
171
- let out = head.join(' ').replace(/[.,!?;:]+$/, '').trim();
172
- if (!out) return GENERIC_TITLE;
173
- out = out[0].toUpperCase() + out.slice(1);
174
- return out.slice(0, 60).trim() || GENERIC_TITLE;
175
- }
176
-
177
- /**
178
- * Name a conversation from its first user prompt.
179
- *
180
- * `callModel(prompt, { system, signal, naming })` (async) is the caller's own
181
- * model seam and must return a string (or null). With no `callModel` — demo
182
- * mode, or a caller that has no backend — it answers from the local
183
- * derivation. Never throws; resolves '' only when there was no prompt at all
184
- * (the caller keeps whatever it had).
185
- *
186
- * `{ signal }` is honoured between rounds and passed through, so aborting a turn
187
- * abandons a naming round in flight rather than leaving it running.
188
- */
189
- async function nameConversation(prompt, { callModel, signal } = {}) {
190
- const raw = prompt == null ? '' : String(prompt);
191
- if (!raw.trim()) return '';
192
- if (isTopicless(raw)) return GENERIC_TITLE;
193
- if (typeof callModel === 'function' && !(signal && signal.aborted)) {
194
- let answer = null;
195
- try {
196
- answer = await callModel(titlePromptOf(raw), { system: TITLE_SYSTEM, signal, naming: true });
197
- } catch {
198
- answer = null;
199
- }
200
- const title = cleanTitle(answer);
201
- if (title) return looksLikeEcho(title, raw) ? GENERIC_TITLE : title;
202
- }
203
- return deriveTitle(raw);
204
- }
205
-
206
- /**
207
- * The title a session should carry after a later prompt, given the one it has.
208
- *
209
- * While the session is still wearing GENERIC_TITLE (the user opened with "heey"
210
- * and has now said what they actually want) the next real ask renames it; once
211
- * a real title exists it is kept, so a follow-up does not rename a session away
212
- * from its topic. `null` means "no opinion, keep what you have".
213
- *
214
- * `{ seeded: true }` covers the other way a session can still be unnamed: the
215
- * desktop's `prompt.slice(0, 60)` seed and `recordExchange`'s, which are
216
- * neither GENERIC_TITLE nor a name. The store records that distinction
217
- * (`session.named`), so the caller passes it rather than this module guessing
218
- * from the string.
219
- */
220
- async function refineTitle(currentTitle, prompt, opts = {}) {
221
- const named = opts && opts.named === true;
222
- const seeded = opts && opts.seeded === true;
223
- if (named) return null;
224
- if (!seeded && !isGenericTitle(currentTitle)) return null;
225
- if (!String(prompt || '').trim() || isTopicless(prompt)) return null;
226
- const next = await nameConversation(prompt, opts);
227
- const cleaned = cleanTitle(next);
228
- if (!cleaned || isGenericTitle(cleaned)) return null;
229
- return cleaned;
230
- }
231
-
232
- /**
233
- * Name a session in place, through the store both hosts read.
234
- *
235
- * This is the ONE entry point a host needs: it derives the name from the
236
- * prompt, skips a session that already has a real name, writes it to
237
- * `sessions.json` with `named: true`, and returns the name (or null when it
238
- * had no opinion). Best-effort — a store that cannot be written costs a label,
239
- * never a turn. `store` is injected so this module stays free of the store's
240
- * own locking and so a test can pass a stub.
241
- */
242
- async function nameSession(store, dir, sessionId, prompt, opts = {}) {
243
- if (!store || typeof store.setTitle !== 'function') return null;
244
- if (!sessionId) return null;
245
- const session = typeof store.getSession === 'function' ? store.getSession(dir, sessionId) : null;
246
- const current = session && session.title;
247
- const structured = { ...opts, seeded: !!(session && !session.named) };
248
- const next = await refineTitle(current, prompt, structured);
249
- if (next) {
250
- try {
251
- store.setTitle(dir, sessionId, next, { named: true });
252
- } catch {
253
- return null;
254
- }
255
- return next;
256
- }
257
- // A greeting names nothing, but the row should still say so instead of
258
- // wearing the raw prompt. The CLI does this too: `nameConversation` answers
259
- // GENERIC_TITLE and `setSessionTitle` writes it. Marked unnamed (`setTitle`
260
- // without `named`), so the next real ask still renames it — which is the
261
- // whole point of the ladder's first rung.
262
- if (isTopicless(prompt) && session && !session.named && !isGenericTitle(current)) {
263
- try {
264
- store.setTitle(dir, sessionId, GENERIC_TITLE);
265
- } catch {
266
- return null;
267
- }
268
- return GENERIC_TITLE;
269
- }
270
- return null;
271
- }
272
-
273
- module.exports = {
274
- GENERIC_TITLE,
275
- TITLE_SYSTEM,
276
- isGenericTitle,
277
- isTopicless,
278
- looksLikeEcho,
279
- cleanTitle,
280
- titlePromptOf,
281
- deriveTitle,
282
- nameConversation,
283
- refineTitle,
284
- nameSession,
285
- };
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};