fix(mcp): keep budget categories to the Costs keys, and say what a journal entry's visibility does

An assistant writing expenses through the MCP was told "e.g. Accommodation, Food,
Transport" and stored exactly that, so "Food" and "food" sat side by side in the
MCP totals while the Costs tab already read both as one. A typed category in any
case, or a common name like Hotel or Flight, is now stored as its fixed key on
every path (REST, MCP, linked booking costs), the totals the MCP reads group by
that key, and the tools name the real keys. The client reads categories through
the same shared mapping. Any other text is still kept as given.

The journal tools said that a private entry stays off the share link. It never
did: the share link shows every entry that is not a draft, whatever its
visibility, and the web editor has no visibility at all. The tools now say so
and point to is_draft, which is what keeps an entry to the contributors.

The wiki explains why the location button needs HTTPS and how to run TREK behind
an HTTPS tunnel while still using it over plain HTTP at home, and that Android's
photo picker drops a photo's location while Immich and Synology keep it.
This commit is contained in:
Maurice
2026-11-04 14:09:31 +01:00
parent 82295a1d3f
commit 50ea9a74c9
15 changed files with 153 additions and 49 deletions
+26
View File
@@ -0,0 +1,26 @@
// COST-CATEGORY-001 to COST-CATEGORY-003: a typed category read as one of the fixed keys.
import { costCategoryOf } from './cost-category';
import { describe, expect, it } from 'vitest';
describe('costCategoryOf', () => {
it('COST-CATEGORY-001: a key stays itself', () => {
expect(costCategoryOf('food')).toBe('food');
expect(costCategoryOf('accommodation')).toBe('accommodation');
});
it('COST-CATEGORY-002: another case or a common name reads as its key', () => {
expect(costCategoryOf('Food')).toBe('food');
expect(costCategoryOf(' FOOD ')).toBe('food');
expect(costCategoryOf('Flight')).toBe('flights');
expect(costCategoryOf('Hotel')).toBe('accommodation');
expect(costCategoryOf('Car park')).toBe('parking');
});
it('COST-CATEGORY-003: anything else is no key', () => {
expect(costCategoryOf('Comida')).toBeNull();
expect(costCategoryOf('')).toBeNull();
expect(costCategoryOf(null)).toBeNull();
expect(costCategoryOf(undefined)).toBeNull();
});
});
+78
View File
@@ -0,0 +1,78 @@
import { COST_CATEGORIES, type CostCategory } from './budget.schema';
/**
* Free-text and legacy categories (and booking type labels) mapped to the fixed
* keys. Bookings used to store labels like "Flight"/"Train"/"Other", and an
* assistant writing through the MCP says "Food" where the key is "food".
*/
const CATEGORY_ALIASES: Record<string, CostCategory> = {
flight: 'flights',
flights: 'flights',
plane: 'flights',
flug: 'flights',
train: 'transport',
bus: 'transport',
car: 'transport',
'car rental': 'transport',
ferry: 'transport',
boat: 'transport',
taxi: 'transport',
transfer: 'transport',
cable_car: 'transport',
transport: 'transport',
transportation: 'transport',
hotel: 'accommodation',
accommodation: 'accommodation',
lodging: 'accommodation',
hostel: 'accommodation',
restaurant: 'food',
food: 'food',
dining: 'food',
meal: 'food',
meals: 'food',
grocery: 'groceries',
groceries: 'groceries',
activity: 'activities',
activities: 'activities',
sightseeing: 'sightseeing',
sights: 'sightseeing',
shop: 'shopping',
shopping: 'shopping',
fee: 'fees',
fees: 'fees',
health: 'health',
medical: 'health',
tip: 'tips',
tips: 'tips',
gas: 'fuel',
fuel: 'fuel',
petrol: 'fuel',
parking: 'parking',
parkings: 'parking',
'car park': 'parking',
other: 'other',
misc: 'other',
};
const KEYS: ReadonlySet<string> = new Set(COST_CATEGORIES);
/**
* The fixed key a stored or typed category stands for, whatever its case, or
* null for a category that is none of them.
*/
export function costCategoryOf(category: string | null | undefined): CostCategory | null {
if (!category) return null;
if (KEYS.has(category)) return category as CostCategory;
return CATEGORY_ALIASES[category.trim().toLowerCase()] ?? null;
}
/**
* The category an expense is stored under: the fixed key when the text names one,
* so "Food" and "food" are one category, and the text itself otherwise.
*/
export function storedCostCategory(category: string | null | undefined): string {
return costCategoryOf(category) ?? (category || 'other');
}
/** What the MCP tells an assistant about the category field. */
export const COST_CATEGORY_HINT = `One of the Costs categories: ${COST_CATEGORIES.join(', ')}. Another case or a common name (Hotel, Flight, Food) is stored as its key; any other text is kept as given and shows as other`;
+1
View File
@@ -38,6 +38,7 @@ export * from './packing/packed-count';
export * from './packing/packing-placeholder';
export * from './todo/todo.schema';
export * from './budget/budget.schema';
export * from './budget/cost-category';
export * from './budget/receipt-scan.schema';
export * from './reservation/reservation.schema';
export * from './reservation/reservation-types';
+5 -1
View File
@@ -293,7 +293,11 @@ export const journeyEntryUpdateToolSchema = z.strictObject({
weather: z.string().max(100).nullable().optional(),
tags: z.array(z.string()).nullable().optional(),
pros_cons: journeyEntryProsConsSchema.nullable().optional().describe('Replaces the whole verdict; null clears it'),
visibility: journeyEntryVisibilitySchema.optional(),
visibility: journeyEntryVisibilitySchema
.optional()
.describe(
'Stored with the entry. It does not decide the share link: every entry that is not a draft shows there. Use is_draft to keep an entry to the contributors',
),
type: journeyEntryTypeSchema
.optional()
.describe('Promote a trip-derived "skeleton" to a real "entry" once it has been written up'),