Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(search): correctly search channel names to be agnostic of order (#1021)

Will Hutchinson40802e442e2f
diff --git a/js/app/flake.lock b/js/app/flake.lock
index ea01204cee..24f6872fa9 100644
--- a/js/app/flake.lock
+++ b/js/app/flake.lock
@@ -55,11 +55,28 @@
"type": "github"
}
},
+ "nixpkgs-biome": {
+ "locked": {
+ "lastModified": 1760405615,
+ "narHash": "sha256-x8dOnMBX0X9L62O5J2Q/uweOROie/cmjg+Tzq+j2Ezw=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "af70ad706db919d644586e8f95c1d8d3d0a1ac56",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "af70ad706db919d644586e8f95c1d8d3d0a1ac56",
+ "type": "github"
+ }
+ },
"root": {
"inputs": {
"fenix": "fenix",
"flake-utils": "flake-utils",
- "nixpkgs": "nixpkgs"
+ "nixpkgs": "nixpkgs",
+ "nixpkgs-biome": "nixpkgs-biome"
}
},
"rust-analyzer-src": {
diff --git a/js/app/flake.nix b/js/app/flake.nix
index a7bc18a0dd..4c3fc1ca59 100644
--- a/js/app/flake.nix
+++ b/js/app/flake.nix
@@ -4,12 +4,14 @@
flake-utils.url = "github:numtide/flake-utils";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
+ nixpkgs-biome.url = "github:NixOS/nixpkgs/af70ad706db919d644586e8f95c1d8d3d0a1ac56";
};
outputs =
{
self,
nixpkgs,
+ nixpkgs-biome,
flake-utils,
fenix,
}:
@@ -21,6 +23,7 @@
config.allowUnfree = true;
config.android_sdk.accept_license = true;
};
+ pkgs-biome = nixpkgs-biome.legacyPackages.${system};
isDarwin = pkgs.stdenv.isDarwin;
isLinux = pkgs.stdenv.isLinux;
@@ -52,7 +55,7 @@
pkg-config
just
bun
- biome
+ pkgs-biome.biome
nodejs_24
typescript-language-server
cargo-tauri
@@ -61,22 +64,26 @@
pulumi
pulumiPackages.pulumi-nodejs
pulumiPackages.pulumi-aws-native
-
+ playwright
+ playwright-mcp
(
with fenix.packages.${system};
- combine ([
- complete.rustc
- complete.rust-src
- complete.cargo
- complete.clippy
- complete.rustfmt
- complete.rust-analyzer
- ] ++ pkgs.lib.optionals isLinux [
- targets.aarch64-linux-android.latest.rust-std
- targets.armv7-linux-androideabi.latest.rust-std
- targets.i686-linux-android.latest.rust-std
- targets.x86_64-linux-android.latest.rust-std
- ])
+ combine (
+ [
+ complete.rustc
+ complete.rust-src
+ complete.cargo
+ complete.clippy
+ complete.rustfmt
+ complete.rust-analyzer
+ ]
+ ++ pkgs.lib.optionals isLinux [
+ targets.aarch64-linux-android.latest.rust-std
+ targets.armv7-linux-androideabi.latest.rust-std
+ targets.i686-linux-android.latest.rust-std
+ targets.x86_64-linux-android.latest.rust-std
+ ]
+ )
)
];
@@ -88,8 +95,7 @@
jdk
];
- packages = basePackages
- ++ pkgs.lib.optionals isLinux (linuxPackages ++ [ android_sdk ]);
+ packages = basePackages ++ pkgs.lib.optionals isLinux (linuxPackages ++ [ android_sdk ]);
linuxLibraries = with pkgs; [
gtk3
@@ -112,17 +118,20 @@
libraries = if isDarwin then darwinLibraries else linuxLibraries;
in
{
- devShell = pkgs.mkShell ({
- buildInputs = packages ++ libraries;
- PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
- } // pkgs.lib.optionalAttrs isLinux {
- LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH";
- XDG_DATA_DIRS = "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS";
- ANDROID_HOME = "${android_sdk}/libexec/android-sdk";
- NDK_HOME = "${android_sdk}/libexec/android-sdk/ndk/26.3.11579264";
- GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${android_sdk}/libexec/android-sdk/build-tools/35.0.0/aapt2";
- GIO_MODULE_DIR = "${pkgs.glib-networking}/lib/gio/modules/";
- });
+ devShell = pkgs.mkShell (
+ {
+ buildInputs = packages ++ libraries;
+ PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
+ }
+ // pkgs.lib.optionalAttrs isLinux {
+ LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH";
+ XDG_DATA_DIRS = "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS";
+ ANDROID_HOME = "${android_sdk}/libexec/android-sdk";
+ NDK_HOME = "${android_sdk}/libexec/android-sdk/ndk/26.3.11579264";
+ GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${android_sdk}/libexec/android-sdk/build-tools/35.0.0/aapt2";
+ GIO_MODULE_DIR = "${pkgs.glib-networking}/lib/gio/modules/";
+ }
+ );
}
);
}
diff --git a/js/app/packages/app/component/command/Konsole.tsx b/js/app/packages/app/component/command/Konsole.tsx
index 484389b941..b809b651a4 100644
--- a/js/app/packages/app/component/command/Konsole.tsx
+++ b/js/app/packages/app/component/command/Konsole.tsx
@@ -135,6 +135,7 @@ export function KommandMenuInner(props: {
fuzzyWeight: hasQuery ? 0.7 : 0.1,
timeWeight: hasQuery ? 0.3 : 0.9,
minFuzzyThreshold: hasQuery ? 0.1 : 0,
+ commaSeparatedChannelMatch: true,
};
});
diff --git a/js/app/packages/core/util/freshSort.test.ts b/js/app/packages/core/util/freshSort.test.ts
index 35cc7c3dda..1cf8d83075 100644
--- a/js/app/packages/core/util/freshSort.test.ts
+++ b/js/app/packages/core/util/freshSort.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import { createFreshSearch } from './freshSort';
+import { fuzzyScoreCommaSeparated, fuzzyTestCommaSeparated } from './fuzzy';
interface MockItem {
id: string;
@@ -68,3 +69,134 @@ describe('freshSort ordering', () => {
expect(results.map((r) => r.item.id)).toEqual(['2', '1', '3']);
});
});
+
+describe('fuzzyTestCommaSeparated', () => {
+ it('matches when all query parts match text parts', () => {
+ expect(fuzzyTestCommaSeparated('nick,hutch', 'Nick Noble,teo,hutch')).toBe(
+ true
+ );
+ });
+
+ it('matches regardless of order', () => {
+ expect(fuzzyTestCommaSeparated('teo,nick', 'Nick Noble,teo,hutch')).toBe(
+ true
+ );
+ });
+
+ it('matches single query term against multi-part name', () => {
+ expect(fuzzyTestCommaSeparated('teo', 'Nick Noble,teo,hutch')).toBe(true);
+ });
+
+ it('does not match when a query part is missing', () => {
+ expect(fuzzyTestCommaSeparated('nick,alice', 'Nick Noble,teo,hutch')).toBe(
+ false
+ );
+ });
+
+ it('handles fuzzy matching within parts', () => {
+ expect(fuzzyTestCommaSeparated('nob,teo', 'Nick Noble,teo,hutch')).toBe(
+ true
+ );
+ });
+
+ it('handles whitespace around commas', () => {
+ expect(
+ fuzzyTestCommaSeparated('nick , hutch', 'Nick Noble , teo , hutch')
+ ).toBe(true);
+ });
+
+ it('returns true for empty query', () => {
+ expect(fuzzyTestCommaSeparated('', 'Nick Noble,teo,hutch')).toBe(true);
+ });
+});
+
+describe('fuzzyScoreCommaSeparated', () => {
+ it('returns score between 0 and 1', () => {
+ const score = fuzzyScoreCommaSeparated('nick,teo', 'Nick Noble,teo,hutch');
+ expect(score).toBeGreaterThan(0);
+ expect(score).toBeLessThanOrEqual(1);
+ });
+
+ it('returns -1 when no match', () => {
+ const score = fuzzyScoreCommaSeparated('alice,bob', 'Nick Noble,teo,hutch');
+ expect(score).toBe(-1);
+ });
+
+ it('returns 1 for empty query', () => {
+ const score = fuzzyScoreCommaSeparated('', 'Nick Noble,teo,hutch');
+ expect(score).toBe(1);
+ });
+});
+
+describe('createFreshSearch with comma-separated channel matching', () => {
+ function createCommaSeparatedSearch() {
+ return createFreshSearch<MockItem>(
+ {
+ commaSeparatedChannelMatch: true,
+ fuzzyWeight: 0.9,
+ timeWeight: 0.1,
+ },
+ (item) => item.name
+ );
+ }
+
+ it('matches channel with comma-separated query', () => {
+ const now = Date.now();
+ const items: MockItem[] = [
+ { id: '1', name: 'Nick Noble,teo,hutch', type: 'channel', viewedAt: now },
+ { id: '2', name: 'Alice,Bob', type: 'channel', viewedAt: now },
+ ];
+
+ const search = createCommaSeparatedSearch();
+ const results = search(items, 'nick,hutch');
+
+ expect(results.length).toBe(1);
+ expect(results[0].item.id).toBe('1');
+ });
+
+ it('matches channel regardless of query order', () => {
+ const now = Date.now();
+ const items: MockItem[] = [
+ { id: '1', name: 'Nick Noble,teo,hutch', type: 'channel', viewedAt: now },
+ ];
+
+ const search = createCommaSeparatedSearch();
+ const results = search(items, 'teo,nick');
+
+ expect(results.length).toBe(1);
+ expect(results[0].item.id).toBe('1');
+ });
+
+ it('uses regular fuzzy search when query has no commas', () => {
+ const now = Date.now();
+ const items: MockItem[] = [
+ { id: '1', name: 'Nick Noble,teo,hutch', type: 'channel', viewedAt: now },
+ { id: '2', name: 'Design Doc', type: 'item', viewedAt: now },
+ ];
+
+ const search = createCommaSeparatedSearch();
+ const results = search(items, 'Nick');
+
+ expect(results.length).toBe(1);
+ expect(results[0].item.id).toBe('1');
+ });
+
+ it('still matches non-channel items with comma queries', () => {
+ const now = Date.now();
+ const items: MockItem[] = [
+ { id: '1', name: 'Nick Noble,teo,hutch', type: 'channel', viewedAt: now },
+ {
+ id: '2',
+ name: 'nick,hutch meeting notes',
+ type: 'item',
+ viewedAt: now,
+ },
+ ];
+
+ const search = createCommaSeparatedSearch();
+ const results = search(items, 'nick,hutch');
+
+ // Both should match - channel via comma-separated, item via regular fuzzy
+ expect(results.length).toBe(2);
+ });
+});
diff --git a/js/app/packages/core/util/freshSort.ts b/js/app/packages/core/util/freshSort.ts
index 085c9ad1f8..1be2e119f4 100644
--- a/js/app/packages/core/util/freshSort.ts
+++ b/js/app/packages/core/util/freshSort.ts
@@ -4,6 +4,7 @@
*/
import type { FilterResult } from 'fuzzy';
import fuzzy from 'fuzzy';
+import { fuzzyScoreCommaSeparated } from './fuzzy';
export interface FreshSortConfig {
/** Weight for fuzzy match (0-1). Higher values prioritize search relevance. Default: 0.7 */
@@ -22,6 +23,8 @@ export interface FreshSortConfig {
useViewedAt?: boolean;
/** Boost multiplier for channel items when query is present. Default: 1.0 (no boost) */
channelBoost?: number;
+ /** Enable comma-separated matching for channel names. When enabled, query "a,b" matches channel name "a,c,b". Default: false */
+ commaSeparatedChannelMatch?: boolean;
}
export interface TimestampedItem {
@@ -53,6 +56,7 @@ const DEFAULT_CONFIG: Required<FreshSortConfig> = {
minFuzzyThreshold: 0.1,
useViewedAt: false,
channelBoost: 1.0,
+ commaSeparatedChannelMatch: false,
};
function extractTimestamp(
@@ -193,6 +197,42 @@ export function createFreshSearch<T extends TimestampedItem>(
extractor: (item: T) => string
) {
return (items: T[], query: string): FreshSortResult<T>[] => {
+ const finalConfig = { ...DEFAULT_CONFIG, ...config };
+ const useCommaSeparated =
+ finalConfig.commaSeparatedChannelMatch && query.includes(',');
+
+ if (useCommaSeparated) {
+ // For comma-separated queries, handle channel items specially
+ const channelResults: FilterResult<T>[] = [];
+ const nonChannelItems: T[] = [];
+
+ for (const item of items) {
+ if (isChannelItem(item)) {
+ const name = extractor(item);
+ const score = fuzzyScoreCommaSeparated(query, name);
+ if (score >= 0) {
+ channelResults.push({
+ original: item,
+ string: name,
+ score: score * 100, // Scale to match fuzzy library scoring
+ index: 0,
+ });
+ }
+ } else {
+ nonChannelItems.push(item);
+ }
+ }
+
+ // Get fuzzy results for non-channel items using regular matching
+ const nonChannelResults = fuzzy.filter(query, nonChannelItems, {
+ extract: extractor,
+ });
+
+ // Combine results
+ const allResults = [...channelResults, ...nonChannelResults];
+ return freshSort(allResults, config);
+ }
+
const fuzzyResults = fuzzy.filter(query, items, {
extract: extractor,
});
diff --git a/js/app/packages/core/util/fuzzy.ts b/js/app/packages/core/util/fuzzy.ts
index 6d40ce10dd..72b5c961bd 100644
--- a/js/app/packages/core/util/fuzzy.ts
+++ b/js/app/packages/core/util/fuzzy.ts
@@ -96,3 +96,77 @@ export function fuzzyTest(query: string, text: string): boolean {
return idxs !== null && idxs.length > 0;
}
+
+/**
+ * Tests if a comma-separated query matches against a comma-separated text.
+ * Each query part must fuzzy-match at least one text part.
+ * e.g., query "nick,hutch" matches text "Nick Noble,teo,hutch"
+ */
+export function fuzzyTestCommaSeparated(query: string, text: string): boolean {
+ if (!query) return true;
+
+ const queryParts = query
+ .split(',')
+ .map((p) => p.trim())
+ .filter((p) => p.length > 0);
+ const textParts = text
+ .split(',')
+ .map((p) => p.trim())
+ .filter((p) => p.length > 0);
+
+ if (queryParts.length === 0) return true;
+ if (textParts.length === 0) return false;
+
+ // Every query part must match at least one text part
+ for (const queryPart of queryParts) {
+ let matchFound = false;
+ for (const textPart of textParts) {
+ if (fuzzyTest(queryPart, textPart)) {
+ matchFound = true;
+ break;
+ }
+ }
+ if (!matchFound) return false;
+ }
+
+ return true;
+}
+
+/**
+ * Calculates a score for comma-separated fuzzy matching.
+ * Returns the average of best match scores for each query part.
+ * Returns -1 if any query part fails to match (can be used instead of fuzzyTestCommaSeparated).
+ */
+export function fuzzyScoreCommaSeparated(query: string, text: string): number {
+ if (!query) return 1;
+
+ const queryParts = query
+ .split(',')
+ .map((p) => p.trim())
+ .filter((p) => p.length > 0);
+ const textParts = text
+ .split(',')
+ .map((p) => p.trim())
+ .filter((p) => p.length > 0);
+
+ if (queryParts.length === 0) return 1;
+ if (textParts.length === 0) return -1;
+
+ let totalScore = 0;
+
+ for (const queryPart of queryParts) {
+ let bestScore = -1;
+ for (const textPart of textParts) {
+ // Simple scoring: ratio of query length to text length when it matches
+ if (fuzzyTest(queryPart, textPart)) {
+ // Score based on how much of the text part the query covers
+ const score = queryPart.length / textPart.length;
+ bestScore = Math.max(bestScore, Math.min(1, score));
+ }
+ }
+ if (bestScore < 0) return -1;
+ totalScore += bestScore;
+ }
+
+ return totalScore / queryParts.length;
+}