aegiscode 7.0.14 → 7.0.15

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 (109) hide show
  1. package/SOURCE-OFFER.txt +9 -0
  2. package/package.json +3 -2
  3. package/scripts/check.mjs +1 -52
  4. package/scripts/demo.mjs +1 -94
  5. package/scripts/predist.mjs +1 -75
  6. package/scripts/runtests.mjs +1 -56
  7. package/scripts/seal-gate.mjs +1 -74
  8. package/src/agents.js +1 -139
  9. package/src/app.js +1 -2932
  10. package/src/art.js +1 -289
  11. package/src/chatflow.js +1 -3020
  12. package/src/checkpoint.js +1 -90
  13. package/src/clipboard.js +1 -424
  14. package/src/cloudsync.js +1 -528
  15. package/src/commands.js +1 -4003
  16. package/src/config.js +1 -581
  17. package/src/connect.js +1 -349
  18. package/src/credentials.js +1 -33
  19. package/src/deps.js +1 -232
  20. package/src/devrun.js +1 -187
  21. package/src/diff.js +1 -333
  22. package/src/diffview.js +1 -296
  23. package/src/engine.js +1 -297
  24. package/src/entitlement.js +1 -355
  25. package/src/events.js +1 -707
  26. package/src/export.js +1 -67
  27. package/src/fingerprint.js +1 -592
  28. package/src/format.js +1 -259
  29. package/src/fuzzy.js +1 -119
  30. package/src/history.js +1 -401
  31. package/src/init.js +1 -175
  32. package/src/input.js +1 -139
  33. package/src/keys.js +1 -183
  34. package/src/markdown.js +1 -306
  35. package/src/models.js +1 -487
  36. package/src/naming.js +1 -229
  37. package/src/overlays.js +1 -461
  38. package/src/panels.js +1 -1418
  39. package/src/ping.js +1 -226
  40. package/src/presence.js +1 -238
  41. package/src/render.js +1 -515
  42. package/src/screen.js +1 -518
  43. package/src/screens.js +1 -896
  44. package/src/secret.js +1 -59
  45. package/src/securefs.js +1 -359
  46. package/src/settings.js +1 -155
  47. package/src/shared.js +1 -52
  48. package/src/sharedpaths.js +1 -53
  49. package/src/signup.js +1 -156
  50. package/src/summarize.js +1 -95
  51. package/src/sysdiag.js +1 -585
  52. package/src/system.js +1 -40
  53. package/src/theme.js +1 -570
  54. package/src/title.js +1 -220
  55. package/src/todos.js +1 -115
  56. package/src/tokens.js +1 -263
  57. package/src/topup.js +1 -210
  58. package/src/update.js +1 -181
  59. package/vendor/client/aegis.js +1 -2179
  60. package/vendor/client/attest.js +1 -442
  61. package/vendor/client/authorship-key.js +1 -410
  62. package/vendor/client/auto-provision.js +1 -134
  63. package/vendor/client/brain-catalog.js +1 -268
  64. package/vendor/client/byok-catalog.js +1 -230
  65. package/vendor/client/credentials.js +1 -494
  66. package/vendor/client/device-fingerprint.js +1 -141
  67. package/vendor/client/drive-connect.js +1 -110
  68. package/vendor/client/drive-upload.js +1 -174
  69. package/vendor/client/env-file.js +1 -1273
  70. package/vendor/client/fingerprint.js +1 -1064
  71. package/vendor/client/foreign-memory.js +1 -669
  72. package/vendor/client/google-signin.js +1 -133
  73. package/vendor/client/hooks.js +1 -430
  74. package/vendor/client/model-discovery.js +1 -373
  75. package/vendor/client/platform.js +1 -937
  76. package/vendor/client/prefs.js +1 -351
  77. package/vendor/client/presence-constants.js +1 -107
  78. package/vendor/client/presence.js +1 -438
  79. package/vendor/client/record-vault.js +3 -1055
  80. package/vendor/client/session-store.js +1 -548
  81. package/vendor/client/topup.js +1 -297
  82. package/vendor/client/touch.js +1 -458
  83. package/vendor/client/update.js +1 -704
  84. package/vendor/client/user-models.js +1 -381
  85. package/vendor/desktop/lib/local/agents.js +1 -105
  86. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  87. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  88. package/vendor/desktop/lib/local/context.js +1 -95
  89. package/vendor/desktop/lib/local/engine.js +1 -3301
  90. package/vendor/desktop/lib/local/entitlement.js +1 -660
  91. package/vendor/desktop/lib/local/git-scope.js +1 -228
  92. package/vendor/desktop/lib/local/local.js +1 -2135
  93. package/vendor/desktop/lib/local/prompt.js +1 -275
  94. package/vendor/desktop/lib/local/queue.js +1 -560
  95. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  96. package/vendor/desktop/lib/local/shell.js +1 -680
  97. package/vendor/desktop/lib/local/tools.js +1 -1238
  98. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  99. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  100. package/vendor/desktop/lib/settings.js +1 -890
  101. package/vendor/desktop/renderer/usage.js +1 -1239
  102. package/vendor/hosts/install.js +1 -638
  103. package/vendor/hosts/openai-shim.js +1 -515
  104. package/vendor/hosts/spec.js +1 -164
  105. package/vendor/hosts/targets.js +1 -346
  106. package/vendor/mcp/server.js +1 -221
  107. package/vendor/mcp/tools.js +1 -408
  108. package/vendor/one/src/child.js +1 -285
  109. package/vendor/one/src/permissions.js +1 -369
package/src/format.js CHANGED
@@ -1,261 +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
- * Number/text formatting for the CLI — one place, so the transcript, the status
10
- * bar and the headless `--print` output always agree.
11
- *
12
- * The sub-cent rule mirrors the server-side ledger: AEGIS pooled calls settle
13
- * around €0.0007, so a 2dp rendering shows a real charge as "€0.00" next to its
14
- * token count and reads as free usage.
15
- */
16
-
17
- /** Group digits: 1562 -> "1,562". */
18
- function fmtTokens(n) {
19
- const v = Number(n);
20
- if (!Number.isFinite(v) || v <= 0) return '0';
21
- return Math.round(v)
22
- .toString()
23
- .replace(/\B(?=(\d{3})+(?!\d))/g, ',');
24
- }
25
-
26
- /** € amount, 4dp below a cent (per-call spend) and 2dp above it (top-ups). */
27
- function fmtEur(n) {
28
- const v = Number(n);
29
- if (!Number.isFinite(v)) return '€?';
30
- const abs = Math.abs(v);
31
- return `€${abs < 0.01 ? abs.toFixed(4) : abs.toFixed(2)}`;
32
- }
33
-
34
- /** Signed € amount, from the user's side: -€0.0007 spent, +€5.00 added. */
35
- function fmtEurSigned(n) {
36
- const v = Number(n);
37
- if (!Number.isFinite(v)) return '€?';
38
- return `${v < 0 ? '-' : '+'}${fmtEur(Math.abs(v))}`;
39
- }
40
-
41
- /**
42
- * The per-turn token figure the accounting rows report: `312 tokens` — the
43
- * OUTPUT half only.
44
- *
45
- * The input half is gone deliberately, not by omission. It is the prompt
46
- * restated, on a cached turn it is the larger number by an order of magnitude,
47
- * and it is the one figure in the row nobody can act on: you change what a turn
48
- * costs by changing what it PRODUCES, while the input count grows on its own as
49
- * the session does. Both meta rows printed it, so the same turn showed
50
- * `156,189 tok · 151,175 in · 5,014 tokens` and read as a runaway — the eye landed
51
- * on 151,175, which is the prompt, not the spend. The rows now report what the
52
- * turn produced. `/cost` still carries the full miss/hit breakdown for anyone
53
- * who wants it: that is a panel you open, not a line painted under every
54
- * answer.
55
- *
56
- * The labels remain part of the job — both rows once printed the bare pair
57
- * `1,250/312` in one colour, and an unlabelled figure only states what it
58
- * measures to a reader who already knows the convention.
59
- *
60
- * The wording lives here, not in the two renderers that call it, because those
61
- * two are documented as never drifting apart and this is the only part of the
62
- * row they both spell out identically.
63
- *
64
- * Returns `null` when the output is not a number, so a caller falls back to the
65
- * total it does have rather than print a figure it never measured — an absent
66
- * half is omitted rather than rendered as `0`, because `0 tokens` states a figure
67
- * the provider never reported and this codebase refuses that shape elsewhere:
68
- * `fmtRoll` will not put `0 tokens` on a meter that never took a reading, for the
69
- * same reason.
70
- *
71
- * The name is left over from when this returned both halves: it is re-exported
72
- * to the desktop's renderer, and a rename for a wording change would be a
73
- * compatibility break for nothing.
74
- *
75
- * @param {object} [usage] flat `{ input, output }`, or an object carrying them
76
- * @returns {{output: string}|null}
77
- */
78
- function fmtUsageSplit(usage) {
79
- const src = usage && typeof usage === 'object' ? usage : {};
80
- if (!Number.isFinite(src.output)) return null;
81
- return { output: `${fmtTokens(src.output || 0)} tokens` };
82
- }
83
-
84
- /**
85
- * The OUTPUT half of a usage record, or `null` — never the wire's total.
86
- *
87
- * The twin of `desktop/renderer/usage.js`'s `displayTokens`, and here for the
88
- * reason that file states at length: the row under a turn reports what the turn
89
- * PRODUCED. `tokens` is input + output, and on a cached or long-context turn the
90
- * prompt restated is the larger half — falling back to it printed `3,145 tokens`
91
- * for a turn that wrote 145, which is the input half back on the screen with no
92
- * label. Both CLI renderers (`renderMeta` in render.js, `metaBits` in
93
- * chatflow.js) used to do exactly that once `output` was missing, and it was the
94
- * last surviving place the input half reached a row: the split had been dropped,
95
- * and the total they fell back to still carried it.
96
- *
97
- * `null` rather than `0` when no output figure arrived — `0 tokens` states a
98
- * figure no provider sent, the rule `fmtUsageSplit` and `fmtRoll` already hold.
99
- * A turn the wire priced but did not itemise has no output figure, and inventing
100
- * one from the total would be a number that provider never sent.
101
- *
102
- * @param {object} [source] flat `{output}`, or a record carrying `tokens:{output}`
103
- * @returns {number|null}
104
- */
105
- function displayTokens(source) {
106
- const src = source && typeof source === 'object' ? source : {};
107
- const nested = src.tokens && typeof src.tokens === 'object' ? src.tokens : null;
108
- const candidates = [src.output];
109
- if (nested) candidates.push(nested.output, nested.output_tokens, nested.completion_tokens);
110
- else candidates.push(src.output_tokens, src.completion_tokens);
111
- for (const c of candidates) {
112
- if (typeof c === 'number' && isFinite(c) && c > 0) return c;
113
- }
114
- return null;
115
- }
116
-
117
- /**
118
- * The account's tier, as the host last read it off the server. Held here
119
- * because the RENDERERS need it and they run synchronously, on a path that
120
- * cannot await a probe: `cli/src/entitlement.js` publishes every reading it
121
- * takes (`noteTier`), and the money rule below spends it.
122
- */
123
- let tierSnapshot = null;
124
-
125
- /**
126
- * Publish the entitlement snapshot for the renderers. Called by the host's
127
- * entitlement gate on every `current()`/`refresh()`, so the waiver rule and the
128
- * gate the host enforces can never read two different tiers.
129
- */
130
- function noteTier(entitlement) {
131
- tierSnapshot = entitlement && typeof entitlement === 'object' ? entitlement : null;
132
- return tierSnapshot;
133
- }
134
-
135
- /**
136
- * True when this account's tier means AEGIS bills no per-turn fee, so no money
137
- * figure belongs on a turn row or a session total.
138
- *
139
- * The CLI's half of the desktop's rule (`desktop/renderer/usage.js`), and it is
140
- * the same rule deliberately: the two hosts render the same turn from the same
141
- * engine, so a row that shows a fee on one and waives it on the other is a
142
- * disagreement about what the user owes. The desktop had this gate and the CLI
143
- * did not, which is why a trial account saw `€0.0031` under every answer here
144
- * and no money there.
145
- *
146
- * The fee is the BYOK handling fee, waived by aegis1 on Unlimited — and the tier
147
- * a 30-day welcome trial grants IS Unlimited (`subscriptions` row), so a trial
148
- * account resolves here exactly like a paying one. Matching is on the resolved
149
- * tier rather than `pro`, and a funded bank on a free plan is NOT waived: that
150
- * account pays from its bank, and hiding the number would leave it with no meter
151
- * for the only money it spends.
152
- *
153
- * @param {{tier?: string|null, plan?: string|null, planRaw?: string|null,
154
- * subscription?: string|null, item?: string|null, sku?: string|null,
155
- * unlimited?: boolean}} [entitlement] the snapshot to read; omitted, the last
156
- * one the host published (see `noteTier`).
157
- * @returns {boolean}
158
- */
159
- function feeWaived(entitlement) {
160
- const ent = entitlement === undefined ? tierSnapshot : entitlement;
161
- if (!ent || typeof ent !== 'object') return false;
162
- if (ent.unlimited === true) return true;
163
- const named = [
164
- ent.tier,
165
- ent.plan,
166
- ent.planRaw,
167
- ent.subscription,
168
- ent.subscriptionTier,
169
- ent.product,
170
- ent.item,
171
- ent.sku,
172
- ]
173
- .filter((v) => typeof v === 'string')
174
- .map((v) => v.trim().toLowerCase());
175
- if (named.some((v) => v === 'unlimited' || v === 'trial')) return true;
176
- // A tier string that merely CONTAINS the word — `unlimited_trial`,
177
- // `plan.unlimited` — so a server that decorates the name cannot put the fee
178
- // back on an account whose tier is Unlimited.
179
- return named.some((v) => /(^|[^a-z])unlimited([^a-z]|$)/.test(v));
180
- }
181
-
182
- /**
183
- * Whether a money figure belongs on this account's turn row or session total.
184
- *
185
- * A price is printed UNLESS AEGIS either waives it or has not proven it owed:
186
- *
187
- * - a tier AEGIS waives (`feeWaived`) → no price. Unlimited, paid or on the
188
- * 30-day welcome trial, has no per-turn charge and no bank draw;
189
- * - a snapshot that asserts a plan it cannot prove (`degraded`, i.e. the
190
- * entitlement module's unresolved placeholder, whose `plan` reads `free`
191
- * before any probe has answered) → no price. That placeholder says "no
192
- * verdict yet", not "this account is free", and reading it as a verdict is
193
- * what put `€0.0031` under a trial account's answers before its probe had
194
- * replied — a fee charged in writing to the one account that does not pay it;
195
- * - everything else → the price stands, including when NOTHING was claimed at
196
- * all. A cost figure is a measurement of the turn, and silently dropping a
197
- * real number because no tier was published would leave a BYO-key or offline
198
- * run with no meter for money it actually spent.
199
- *
200
- * The token figure is never gated by this, on any branch: what a turn produced
201
- * is not a price, and hiding it would leave an Unlimited account with no meter.
202
- *
203
- * @param {{tier?: string|null, plan?: string|null, planRaw?: string|null,
204
- * degraded?: boolean, source?: string|null, unlimited?: boolean}} [entitlement]
205
- * @returns {boolean}
206
- */
207
- function feeBillable(entitlement) {
208
- const ent = entitlement === undefined ? tierSnapshot : entitlement;
209
- if (!ent || typeof ent !== 'object') return true;
210
- if (feeWaived(ent)) return false;
211
- return ent.degraded !== true;
212
- }
213
-
214
- /** Compact duration: 850 -> "0.9s", 65000 -> "1m05s". */function fmtElapsed(ms) {
215
- const s = Math.max(0, Number(ms) || 0) / 1000;
216
- if (s < 10) return `${s.toFixed(1)}s`;
217
- if (s < 60) return `${Math.round(s)}s`;
218
- const m = Math.floor(s / 60);
219
- const rest = Math.round(s - m * 60);
220
- return `${m}m${String(rest).padStart(2, '0')}s`;
221
- }
222
-
223
- /** Mask an API key for display: never echo enough to be useful if leaked. */
224
- function maskKey(key) {
225
- const s = String(key || '');
226
- if (!s) return 'not set';
227
- if (s.length <= 8) return '•'.repeat(s.length);
228
- return `${s.slice(0, 6)}${'•'.repeat(4)}${s.slice(-4)}`;
229
- }
230
-
231
- // ── Paths, as the CLI labels them ───────────────────────────────────────────
232
- //
233
- // One home for "what do we call this directory", because the answer was
234
- // `p.split('/').filter(Boolean).pop() || '~'` in five files — commands.js,
235
- // history.js (twice), panels.js and init.js — and that is wrong on win32, where
236
- // the separator is `\`: the status line, the session list and the resume picker
237
- // each showed the WHOLE path where linux and darwin showed the leaf. Same class
238
- // of bug as the tool layer's, so it is fixed the same way: the shared platform
239
- // module owns the rule and the CLI calls it rather than spelling it again.
240
-
241
- const sharedPlatform = require(require('./shared.js').resolveClientModule('platform.js'));
242
-
243
- /**
244
- * The name of a path — the leaf segment, whatever separator it arrived with.
245
- * `''` when there is no leaf to name (empty, `/`, `C:\`).
246
- */
247
- function pathName(p) {
248
- return sharedPlatform.baseName(p);
249
- }
250
-
251
- /** The leaf of a recorded cwd, or `~` when nothing was recorded. */
252
- function cwdName(p) {
253
- return pathName(p) || '~';
254
- }
255
-
256
- /** The leaf of THIS process's cwd — the status line's own label. */
257
- function shortCwd() {
258
- return cwdName(process.cwd());
259
- }
260
-
261
- module.exports = { fmtTokens, fmtEur, fmtEurSigned, fmtElapsed, fmtUsageSplit, displayTokens, feeWaived, feeBillable, noteTier, maskKey, pathName, cwdName, shortCwd };
3
+ "use strict";function fmtTokens(t){const e=Number(t);return!Number.isFinite(e)||e<=0?"0":Math.round(e).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}function fmtEur(t){const e=Number(t);if(!Number.isFinite(e))return"€?";const n=Math.abs(e);return`€${n<.01?n.toFixed(4):n.toFixed(2)}`}function fmtEurSigned(t){const e=Number(t);return Number.isFinite(e)?`${e<0?"-":"+"}${fmtEur(Math.abs(e))}`:"€?"}function fmtUsageSplit(t){const e=t&&"object"==typeof t?t:{};return Number.isFinite(e.output)?{output:`${fmtTokens(e.output||0)} tokens`}:null}function displayTokens(t){const e=t&&"object"==typeof t?t:{},n=e.tokens&&"object"==typeof e.tokens?e.tokens:null,o=[e.output];n?o.push(n.output,n.output_tokens,n.completion_tokens):o.push(e.output_tokens,e.completion_tokens);for(const t of o)if("number"==typeof t&&isFinite(t)&&t>0)return t;return null}let tierSnapshot=null;function noteTier(t){return tierSnapshot=t&&"object"==typeof t?t:null,tierSnapshot}function feeWaived(t){const e=void 0===t?tierSnapshot:t;if(!e||"object"!=typeof e)return!1;if(!0===e.unlimited)return!0;const n=[e.tier,e.plan,e.planRaw,e.subscription,e.subscriptionTier,e.product,e.item,e.sku].filter((t=>"string"==typeof t)).map((t=>t.trim().toLowerCase()));return!!n.some((t=>"unlimited"===t||"trial"===t))||n.some((t=>/(^|[^a-z])unlimited([^a-z]|$)/.test(t)))}function feeBillable(t){const e=void 0===t?tierSnapshot:t;return!e||"object"!=typeof e||!feeWaived(e)&&!0!==e.degraded}function fmtElapsed(t){const e=Math.max(0,Number(t)||0)/1e3;if(e<10)return`${e.toFixed(1)}s`;if(e<60)return`${Math.round(e)}s`;const n=Math.floor(e/60),o=Math.round(e-60*n);return`${n}m${String(o).padStart(2,"0")}s`}function maskKey(t){const e=String(t||"");return e?e.length<=8?"•".repeat(e.length):`${e.slice(0,6)}${"•".repeat(4)}${e.slice(-4)}`:"not set"}const sharedPlatform=require(require("./shared.js").resolveClientModule("platform.js"));function pathName(t){return sharedPlatform.baseName(t)}function cwdName(t){return pathName(t)||"~"}function shortCwd(){return cwdName(process.cwd())}module.exports={fmtTokens:fmtTokens,fmtEur:fmtEur,fmtEurSigned:fmtEurSigned,fmtElapsed:fmtElapsed,fmtUsageSplit:fmtUsageSplit,displayTokens:displayTokens,feeWaived:feeWaived,feeBillable:feeBillable,noteTier:noteTier,maskKey:maskKey,pathName:pathName,cwdName:cwdName,shortCwd:shortCwd};
package/src/fuzzy.js CHANGED
@@ -1,121 +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
- // Fuzzy command matching for the "/" palette (and anything else that needs it).
9
- //
10
- // The real Claude Code palette ranks matches by relevance rather than plain
11
- // prefix: an exact match beats a prefix, a prefix beats a substring, and a
12
- // substring beats characters scattered through the name. Ties fall back to
13
- // the source (registry) order so the palette stays stable for empty queries.
14
- //
15
- // Scoring tiers (deliberately spaced so no position/length detail in a lower
16
- // tier can overtake a higher tier):
17
- // exact match 1000
18
- // prefix match 900
19
- // substring 700 − position (earlier substring wins)
20
- // scattered 50 + bonuses (consecutive runs, name-start hits)
21
- //
22
- // Ported verbatim from the upstream engine reference (ESM → CommonJS). The tier
23
- // numbers are a contract: cli-fuzzy.test.mjs asserts the ordering they encode.
24
-
25
- function fuzzyScore(query, name) {
26
- const q = String(query).toLowerCase();
27
- const n = String(name).toLowerCase();
28
- if (!q) return { matched: true, score: 0 };
29
- if (n === q) return { matched: true, score: 1000 };
30
- if (n.startsWith(q)) return { matched: true, score: 900 };
31
- const at = n.indexOf(q);
32
- if (at !== -1) return { matched: true, score: 700 - at };
33
-
34
- // Scattered subsequence: every query char must appear in order.
35
- let score = 50;
36
- let prev = -2;
37
- let last = -1;
38
- for (const ch of q) {
39
- const k = n.indexOf(ch, last + 1);
40
- if (k === -1) return { matched: false, score: 0 };
41
- if (k === prev + 1) score += 15; // consecutive run — strong signal
42
- else score += 5;
43
- if (k === 0) score += 10; // starts at the name — weak signal
44
- prev = k;
45
- last = k;
46
- }
47
- return { matched: true, score };
48
- }
49
-
50
- /**
51
- * The indices (in the original `name`) of the characters that matched
52
- * `query`, mirroring fuzzyScore's tiers — exact = every index, prefix =
53
- * leading run, substring = that run, scattered = the scattered picks.
54
- * Returns [] for an empty query and null when nothing matches.
55
- * Drives the palette's bold-matched-chars rendering.
56
- */
57
- function fuzzyMatchPositions(query, name) {
58
- const q = String(query).toLowerCase();
59
- const n = String(name).toLowerCase();
60
- if (!q) return [];
61
- if (n === q) return Array.from({ length: q.length }, (_, i) => i);
62
- if (n.startsWith(q)) return Array.from({ length: q.length }, (_, i) => i);
63
- const at = n.indexOf(q);
64
- if (at !== -1) return Array.from({ length: q.length }, (_, i) => at + i);
65
- const pos = [];
66
- let last = -1;
67
- for (const ch of q) {
68
- const k = n.indexOf(ch, last + 1);
69
- if (k === -1) return null;
70
- pos.push(k);
71
- last = k;
72
- }
73
- return pos;
74
- }
75
-
76
- /**
77
- * Rank `items` by how well `nameOf(item)` matches `query`.
78
- * Empty query returns the items unchanged (preserves registry/palette order).
79
- * Non-matches are dropped; matches sort by score desc, then source order.
80
- */
81
- function fuzzyRank(query, items, nameOf) {
82
- const q = String(query || '');
83
- if (!q) return items;
84
- return items
85
- .map((item, idx) => ({ item, idx, m: fuzzyScore(q, nameOf(item)) }))
86
- .filter((x) => x.m.matched)
87
- .sort((a, b) => b.m.score - a.m.score || a.idx - b.idx)
88
- .map((x) => x.item);
89
- }
90
-
91
- /**
92
- * Alias-aware ranking. The reference palette searches the command name and its
93
- * aliases (name weight 3, aliases weight 2.5 — Fuse.js in the reference; here
94
- * the best fuzzy score across both wins). An item matches when the query scores
95
- * against at least one of its names; ties keep source order so the palette
96
- * stays stable.
97
- */
98
- function fuzzyRankWithAliases(query, items, nameOf, aliasesOf) {
99
- const q = String(query || '');
100
- if (!q) return items;
101
- return items
102
- .map((item, idx) => {
103
- const names = [nameOf(item), ...((aliasesOf && aliasesOf(item)) || [])];
104
- let best = null;
105
- for (const n of names) {
106
- const m = fuzzyScore(q, n);
107
- if (m.matched && (!best || m.score > best.score)) best = m;
108
- }
109
- return { item, idx, m: best };
110
- })
111
- .filter((x) => x.m)
112
- .sort((a, b) => b.m.score - a.m.score || a.idx - b.idx)
113
- .map((x) => x.item);
114
- }
115
-
116
- module.exports = {
117
- fuzzyScore,
118
- fuzzyMatchPositions,
119
- fuzzyRank,
120
- fuzzyRankWithAliases,
121
- };
3
+ "use strict";function fuzzyScore(t,r){const e=String(t).toLowerCase(),n=String(r).toLowerCase();if(!e)return{matched:!0,score:0};if(n===e)return{matched:!0,score:1e3};if(n.startsWith(e))return{matched:!0,score:900};const o=n.indexOf(e);if(-1!==o)return{matched:!0,score:700-o};let s=50,i=-2,c=-1;for(const t of e){const r=n.indexOf(t,c+1);if(-1===r)return{matched:!1,score:0};s+=r===i+1?15:5,0===r&&(s+=10),i=r,c=r}return{matched:!0,score:s}}function fuzzyMatchPositions(t,r){const e=String(t).toLowerCase(),n=String(r).toLowerCase();if(!e)return[];if(n===e)return Array.from({length:e.length},((t,r)=>r));if(n.startsWith(e))return Array.from({length:e.length},((t,r)=>r));const o=n.indexOf(e);if(-1!==o)return Array.from({length:e.length},((t,r)=>o+r));const s=[];let i=-1;for(const t of e){const r=n.indexOf(t,i+1);if(-1===r)return null;s.push(r),i=r}return s}function fuzzyRank(t,r,e){const n=String(t||"");return n?r.map(((t,r)=>({item:t,idx:r,m:fuzzyScore(n,e(t))}))).filter((t=>t.m.matched)).sort(((t,r)=>r.m.score-t.m.score||t.idx-r.idx)).map((t=>t.item)):r}function fuzzyRankWithAliases(t,r,e,n){const o=String(t||"");return o?r.map(((t,r)=>{const s=[e(t),...n&&n(t)||[]];let i=null;for(const t of s){const r=fuzzyScore(o,t);r.matched&&(!i||r.score>i.score)&&(i=r)}return{item:t,idx:r,m:i}})).filter((t=>t.m)).sort(((t,r)=>r.m.score-t.m.score||t.idx-r.idx)).map((t=>t.item)):r}module.exports={fuzzyScore:fuzzyScore,fuzzyMatchPositions:fuzzyMatchPositions,fuzzyRank:fuzzyRank,fuzzyRankWithAliases:fuzzyRankWithAliases};