Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 0 additions & 84 deletions .github/workflows/release-raycast.yml

This file was deleted.

30 changes: 18 additions & 12 deletions docs/raycast.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
- Follow Raycast's Store rules: US English UI, Title Case action titles,
`CHANGELOG.md` with `{PR_MERGE_DATE}`, `package-lock.json` committed,
`npm run lint` and `npm run build` clean before publishing.
- Releases go through `.github/workflows/release-raycast.yml` (tag
`raycast-v*` or manual run, environment `raycast`): GitHub sign-in by device
code approved with the owner's passkey, then `ray publish`. Never store a
GitHub token for it.
- Publish only from the owner's Mac mini (see Releasing). Never from CI or a
fresh machine, and never store a GitHub token.

## Development


```sh
npm install
npm run dev # opens the extension in Raycast
Expand All @@ -34,10 +31,19 @@ npm run lint

## Releasing

The Raycast Store takes extensions as pull requests to `raycast/extensions`.
`.github/workflows/release-raycast.yml` submits this folder: push a tag
`raycast-v<date>` (for example `raycast-v2026.11.03`) or start it from the
Actions tab. After the `raycast` environment approval, the job prints a
one-time GitHub device code; open `https://github.com/login/device`, sign in
with your passkey and enter it. No token is stored. The first run opens a
draft PR; mark it "Ready for review". Later runs update the same submission.
The Raycast Store takes extensions as pull requests to `raycast/extensions`,
and `ray publish` opens or updates that pull request. It keeps its own clone
of the fork in `~/.config/raycast/public-extensions-fork` and updates the open
submission only from the machine holding that clone. A fresh machine (or a CI
runner) rebuilds the `ext/pulse` branch, which closes the open submission and
opens a new one. So publish from the Mac mini only:

```sh
cd raycast
GIT_CONFIG_COUNT=2 \
GIT_CONFIG_KEY_0=user.name GIT_CONFIG_VALUE_0=fatwang2 \
GIT_CONFIG_KEY_1=user.email GIT_CONFIG_VALUE_1=fatwang2@users.noreply.github.com \
GITHUB_ACCESS_TOKEN="$(gh auth token)" npx ray publish
```

The token is gh's existing sign-in and is used for this command only.
24 changes: 23 additions & 1 deletion raycast/src/lib/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,33 @@ export function validCatalog(value: unknown): value is CatalogDocument {
return (
document?.schema === 1 &&
typeof document.generatedAt === "string" &&
Array.isArray(document.markets) &&
Array.isArray(document.securities) &&
Array.isArray(document.markets)
document.securities.every(validSecurity) &&
(document.crypto === undefined || (Array.isArray(document.crypto) && document.crypto.every(validCoin)))
);
}

const isObject = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" && value !== null && !Array.isArray(value);
const optionalNames = (value: unknown) => value === undefined || isObject(value);
const optionalAliases = (value: unknown) => value === undefined || Array.isArray(value);

// Every entry the index reads, so a malformed export never replaces the copy in hand.
function validSecurity(entry: unknown): boolean {
return (
isObject(entry) &&
typeof entry.m === "string" &&
typeof entry.c === "string" &&
optionalNames(entry.n) &&
optionalAliases(entry.a)
);
}

function validCoin(entry: unknown): boolean {
return isObject(entry) && typeof entry.b === "string" && optionalNames(entry.n) && optionalAliases(entry.a);
}

export class CatalogStore {
constructor(
private readonly directory: string,
Expand Down
62 changes: 49 additions & 13 deletions raycast/src/search-symbol.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
MARKET_CURRENCIES,
MARKET_FILTERS,
MARKET_LABELS,
Market,
PULSE_FOR_MAC_URL,
isCryptoPair,
normalizeTypedSymbol,
Expand Down Expand Up @@ -78,9 +79,23 @@ function typedInstrument(query: string, index: SymbolIndex | undefined): Instrum
}
// A typed "^FTSE" is an index whatever its exchange, so the Indices filter keeps it.
if (symbol.startsWith("^")) return { symbol, market: "index", kind: "index", name: symbol, exchange: null };
return { symbol, market: "us", kind: "equity", name: symbol, exchange: null };
const suffix = /\.([A-Z]+)$/.exec(symbol)?.[1];
const market = (suffix && SUFFIX_MARKETS[suffix]) ?? "us";
return { symbol, market, kind: "equity", name: symbol, exchange: null };
}

// The Yahoo suffixes of the markets the filter offers, so a typed `7203.T` stays under Japan.
const SUFFIX_MARKETS: Record<string, Market> = {
HK: "hk",
SS: "sh",
SZ: "sz",
T: "jp",
KS: "kr",
KQ: "kq",
TW: "tw",
TWO: "two",
};

const changeColor = (value: number | null | undefined) =>
value === null || value === undefined ? Color.SecondaryText : value >= 0 ? Color.Green : Color.Red;

Expand Down Expand Up @@ -115,14 +130,7 @@ export default function Command() {
error: indexError,
revalidate: reloadIndex,
} = usePromise(loadIndex, [], {
onError: (error) => {
showToast({
style: Toast.Style.Failure,
title: "Could not load the symbol list",
message: error.message,
primaryAction: { title: "Retry", onAction: () => reloadIndex() },
});
},
failureToastOptions: { title: "Could not load the symbol list" },
});

const language: Language = readerLanguage(preferences.nameLanguage ?? "auto", searchText, SYSTEM_LOCALE);
Expand Down Expand Up @@ -160,7 +168,11 @@ export default function Command() {

const visible = useMemo(() => sections.flatMap((section) => section.items.map((item) => item.symbol)), [sections]);
// List rows carry a price only while the detail pane is hidden; the pane prices the selected row itself.
const { data: rows, isLoading: rowsLoading } = useCachedPromise(
const {
data: priced,
isLoading: rowsLoading,
revalidate: repriceRows,
} = useCachedPromise(
async (symbols: string[]) => {
const crypto = symbols.filter(isCryptoPair);
const stocks = symbols.filter((symbol) => !isCryptoPair(symbol));
Expand All @@ -172,14 +184,39 @@ export default function Command() {
return Object.assign({}, ...each.map((result) => (result.status === "fulfilled" ? result.value : {})));
}),
]);
return {
const failed = [
...(stockRows.status === "rejected" ? ["Yahoo Finance"] : []),
...(cryptoRows.status === "rejected" ? ["Binance"] : []),
];
const quotes = {
...(stockRows.status === "fulfilled" ? stockRows.value : {}),
...(cryptoRows.status === "fulfilled" ? cryptoRows.value : {}),
} as Record<string, RowQuote>;
// Nothing priced: fail outright, and the hook's toast offers Retry.
if (failed.length && Object.keys(quotes).length === 0) {
throw new Error(`${failed.join(" and ")} did not answer.`);
}
return { quotes, failed };
},
[visible],
{ execute: !showingDetail && visible.length > 0, keepPreviousData: true },
{
execute: !showingDetail && visible.length > 0,
keepPreviousData: true,
failureToastOptions: { title: "Could not load prices" },
},
);
const rows = priced?.quotes;
// Some rows priced and some not: keep the priced ones, and say which source failed.
const failedSources = priced?.failed.join(" and ");
useEffect(() => {
if (!failedSources) return;
showToast({
style: Toast.Style.Failure,
title: "Some prices could not be loaded",
message: `${failedSources} did not answer.`,
primaryAction: { title: "Retry", onAction: () => repriceRows() },
});
}, [priced]);

const remember = (symbol: string) =>
setRecent((current) => [symbol, ...current.filter((item) => item !== symbol)].slice(0, RECENT_LIMIT));
Expand Down Expand Up @@ -304,7 +341,6 @@ function InstrumentActions(props: {
<Action.CopyToClipboard
title="Copy Symbol"
content={instrument.symbol}
shortcut={Keyboard.Shortcut.Common.Copy}
onCopy={() => remember(instrument.symbol)}
/>
{instrument.name !== instrument.symbol && (
Expand Down
16 changes: 16 additions & 0 deletions raycast/tests/catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ test("refuses a truncated or older file and keeps the copy in hand", async () =>
assert.equal(onDisk.generatedAt, "2026-11-02T00:00:00Z");
});

test("refuses an export whose entries are malformed", async () => {
const directory = await mkdtemp(join(tmpdir(), "pulse-raycast-"));
const good = JSON.parse(catalog("2026-11-03T00:00:00Z", 100));
const { fetcher } = fakeFetch([
new Response(catalog("2026-11-02T00:00:00Z", 100), { headers: { etag: '"a"' } }),
new Response(JSON.stringify({ ...good, securities: [...good.securities, null] })),
new Response(JSON.stringify({ ...good, crypto: "BTC" })),
new Response(JSON.stringify({ ...good, securities: [...good.securities, { m: "us", c: 7 }] })),
]);
const store = new CatalogStore(directory, fetcher);
const first = await store.refreshCatalog(null);
for (let attempt = 0; attempt < 3; attempt += 1) await assert.rejects(store.refreshCatalog(first));
const onDisk = JSON.parse(await readFile(join(directory, "symbols-v1.json"), "utf8"));
assert.equal(onDisk.generatedAt, "2026-11-02T00:00:00Z");
});

test("keeps Binance's trading pairs as base and quote", async () => {
const directory = await mkdtemp(join(tmpdir(), "pulse-raycast-"));
const symbols = Array.from({ length: 150 }, (_, i) => ({
Expand Down
Loading