From 2fa1728e26ae65613ace4511084da615ceaa6551 Mon Sep 17 00:00:00 2001 From: Akos Orban Date: Tue, 3 Nov 2026 00:13:21 +0100 Subject: [PATCH 1/2] feat(options): set stay details, photos and the trip budget from flags `options add` and `options edit` take --details and --photos, and `trips edit` takes --budget. Each takes JSON, and null clears the field. The mna skill now tells models to record a stay detail only when it helps choose between a trip's options, never to state what is equally true of all of them, never to invent a fact, and to say where a fact came from when that is not obvious. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R6BF2tkLhdyAHNtHx1mtCK --- README.md | 6 +-- skills/mna/SKILL.md | 12 +++++ skills/mna/references/cli-and-schemas.md | 45 ++++++++++++++++++- src/commands/options/add.ts | 12 +++++ src/commands/options/edit.test.ts | 22 +++++++++ src/commands/options/edit.ts | 24 +++++++++- src/commands/options/stay-details.test.ts | 54 +++++++++++++++++++++++ src/commands/options/stay-details.ts | 30 +++++++++++++ src/commands/trips/edit.test.ts | 50 +++++++++++++++++++++ src/commands/trips/edit.ts | 11 ++++- src/util/json-flag.test.ts | 26 +++++++++++ src/util/json-flag.ts | 18 ++++++++ 12 files changed, 302 insertions(+), 8 deletions(-) create mode 100644 src/commands/options/stay-details.test.ts create mode 100644 src/commands/options/stay-details.ts create mode 100644 src/commands/trips/edit.test.ts create mode 100644 src/util/json-flag.test.ts create mode 100644 src/util/json-flag.ts diff --git a/README.md b/README.md index 51b89f1..7d6f344 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ Every command supports `--json` for piping into `jq` or Claude. | `mna trips list [--status=planning\|ready\|finished\|cancelled] [--include-example]` | List trips. | | `mna trips show [--all-options]` | Show one trip in detail: each variant's party, plus an accommodation table per variant (cost, guest rating in its source scale, facilities). By default only the selected variant and its selected options; `--all-options` adds the unselected variants and options. | | `mna trips create --name [--cover-photo ]` | Create a new trip. | -| `mna trips edit [--name=...] [--cover-photo=...] [--status=...]` | Update trip-level fields. | +| `mna trips edit [--name=...] [--cover-photo=...] [--status=...] [--budget=]` | Update trip-level fields. `--budget` is owner only, and `--budget null` clears it. | | `mna trips delete [--yes]` | Delete a trip permanently. | | `mna trips share ` | Generate a shareable link for the trip. | | `mna trips unshare ` | Revoke all share links. | @@ -268,8 +268,8 @@ selected variant; add `--all-options` to include the other variants. | Command | Description | |---|---| -| `mna options add --from-json= [--free-cancellation-until=]` | Add an option from JSON. `--free-cancellation-until` (accommodation only) merges into the body. | -| `mna options edit [--from-json=] [--free-cancellation-until=]` | Edit an option. For accommodation, `--free-cancellation-until` alone updates the date without a JSON file. | +| `mna options add --from-json= [--free-cancellation-until=] [--details=] [--photos=]` | Add an option from JSON. `--free-cancellation-until`, `--details` and `--photos` (accommodation only) merge into the body. | +| `mna options edit [--from-json=] [--free-cancellation-until=] [--details=] [--photos=]` | Edit an option. For accommodation, each flag works alone, without a JSON file. `--details` changes only the properties it names; `--photos` replaces the list. | | `mna options delete [--yes]` | Delete an option. | | `mna options select ` | Select an option. | | `mna options deselect ` | Deselect the current option. | diff --git a/skills/mna/SKILL.md b/skills/mna/SKILL.md index 5f5de13..e44f7ae 100644 --- a/skills/mna/SKILL.md +++ b/skills/mna/SKILL.md @@ -155,6 +155,18 @@ The app renders and totals these fields; misuse degrades the plan quietly. independently, and can't be sorted or compared. - **Ratings keep their source's scale.** Store `externalRating.scale` beside the score (out of 10, out of 5) and quote the pair. Never normalise, and never rank a /10 score against a /5 one. +- **`stayDetails` exists to help the group choose between this trip's options.** Add a property + only when it separates this option from the others. Never record what is equally true of all + of them: if every option is central, say nothing about being central. Never invent or infer a + fact: leave it out when unknown, and put what still needs confirming in `worthChecking`. Say + where a fact came from in `sourceNote` when that isn't obvious, and set `author` to `agent`. + `skiBack` needs the listing, the owner or a piste map behind it, never a guess from distance. + Keep prices out of these fields, because they appear on share links that hide prices. +- **`photos` are only images the owner may use**: their own, or ones the property allows to be + reused. Don't copy a gallery from a booking site or from search results. +- **`budget` is the owner's number.** Set it only when the owner has stated one. +- **`priceOptions` on an event are real alternatives** with real prices, such as 4-day and 6-day + ski passes. `totalCost` stays the price the totals use. - **The user's edits are authoritative.** A hand-corrected price, a fixed location or spelling — keep it, and don't revert to the scraped value on the next sync. diff --git a/skills/mna/references/cli-and-schemas.md b/skills/mna/references/cli-and-schemas.md index 0c967aa..c7fd803 100644 --- a/skills/mna/references/cli-and-schemas.md +++ b/skills/mna/references/cli-and-schemas.md @@ -13,8 +13,8 @@ variants add --name [--adults --child-ages --no-children - destinations add --place [--start-date --end-date --notes --return-to-home] edit [--place --notes --start-date --end-date --return-to-home/--no-…] reorder --order=k1,k2,k3 | delete -options add --from-json [--free-cancellation-until ] - edit [--from-json ] [--free-cancellation-until ] +options add --from-json [--free-cancellation-until ] [--details ] [--photos ] + edit [--from-json ] [--free-cancellation-until ] [--details ] [--photos ] select | deselect delete events add --from-json | edit --from-json @@ -65,6 +65,38 @@ property level, which is not what a user means by "an apartment with a kitchen". Put ratings and facilities in these fields rather than in `notes` — `mna trips show` renders them, and `notes` should carry what no field covers. `type` and `roomDetails` come back on read too. +#### `stayDetails` and `photos` + +Set these inside the `--from-json` body, or with the flags on `options add` and `options edit`: + +```bash +mna options edit accommodation \ + --details '{"highlight":"Only one with a private sauna","kitchen":"private","parking":"Garage, book ahead","sourceNote":"Listing page, Oct 2026","author":"agent"}' \ + --photos '[{"url":"https://…/balcony.jpg","credit":"Owner"}]' +``` + +All `stayDetails` properties are optional. Add one only when it helps choose between this trip's +options, and leave out anything equally true of all of them, or unknown. + +| Property | Value | +|---|---| +| `highlight` | one line, up to 160 characters | +| `worthChecking` | list of up to 10 things to confirm before booking; hidden on share links that hide notes | +| `kitchen` | `private` \| `shared` \| `none` | +| `breakfast` | `included` \| `available` \| `none` | +| `skiBack` | `yes` \| `partly` \| `no`, only when confirmed | +| `bookability` | `bookable` \| `on_request` \| `price_unconfirmed` | +| `author` | `owner` \| `agent` \| `sonnet`; agents set `agent` | +| `bedrooms`, `bathrooms`, `maxGuests`, `sizeInM2` | numbers | +| `dinner`, `bedLayout`, `skiBackNote`, `mainLiftName`, `skiStorage`, `kidsFacilities`, `wellness`, `pool`, `beach`, `parking`, `noise`, `view`, `airConditioning`, `laundry`, `accessibility`, `pets`, `sourceNote` | text, up to 300 characters | + +On an edit, only the `stayDetails` properties you send change. `null` clears one, and +`--details null` clears them all. `--photos` replaces the whole list, up to 12 photos, and +`--photos null` clears it. Unknown properties are rejected. + +`photos` take `{ "url", "credit"?, "creditUrl"? }`. Each URL must be a directly linkable http or +https image that the owner may use. + ### transport ```json { @@ -93,6 +125,15 @@ home-return drive on the `--return-to-home` destination so the per-variant total "location": { "name": "Old Town", "formattedAddress": "…", "coordinates": { "lat": 0.0, "lng": 0.0 } } } ``` +When the group has a real choice of price, add `"priceOptions": [{ "label": "4-day pass", "totalCost": 200 }, { "label": "6-day pass", "totalCost": 280 }]`, +up to 10, in the event's `currency`. On `events edit`, the list is replaced, and `null` clears it. + +## Trip budget + +`mna trips edit --budget '{"amount":4000,"currency":"EUR","appliesTo":"stay"}'`. `appliesTo` +is `stay` or `total`. Only the trip owner can change it, `--budget null` clears it, and it never +appears on share links. Set it only when the owner has stated a budget. + ## Location shape — a non-obvious gotcha Option locations are **written flat and read back nested**. Send `address` / `latitude` / diff --git a/src/commands/options/add.ts b/src/commands/options/add.ts index 0c6b68b..d894c6b 100644 --- a/src/commands/options/add.ts +++ b/src/commands/options/add.ts @@ -6,6 +6,7 @@ import { colors } from '../../render/colors' import { reportAndExit, requireApiKey } from '../../util/errors' import { readJsonObject } from '../../util/json-file' import { applyFreeCancellation } from './free-cancellation' +import { applyStayFlags } from './stay-details' const KINDS = ['accommodation', 'transport', 'getting-around'] as const type Kind = (typeof KINDS)[number] @@ -40,6 +41,16 @@ export const optionsAddCommand = defineCommand({ description: 'Accommodation only: free-cancellation deadline (YYYY-MM-DD or ISO date-time). Merged into the body.', }, + details: { + type: 'string', + description: + "Accommodation only: stayDetails as JSON, e.g. '{\"highlight\":\"...\",\"kitchen\":\"private\"}'. Only facts that help choose between this trip's options.", + }, + photos: { + type: 'string', + description: + 'Accommodation only: photos as a JSON array of { "url", "credit"? }. Only images the owner may use.', + }, json: { type: 'boolean', default: false, description: 'Output as JSON.' }, }, async run({ args }) { @@ -47,6 +58,7 @@ export const optionsAddCommand = defineCommand({ assertKind(args.kind) const body = await readJsonObject(args['from-json']) applyFreeCancellation(body, args['free-cancellation-until'], args.kind) + applyStayFlags(body, { details: args.details, photos: args.photos }, args.kind) const creds = await loadCredentials() const apiKey = resolveApiKey(creds) diff --git a/src/commands/options/edit.test.ts b/src/commands/options/edit.test.ts index 4f2927f..e537439 100644 --- a/src/commands/options/edit.test.ts +++ b/src/commands/options/edit.test.ts @@ -45,3 +45,25 @@ describe('options edit — free-cancellation flag', () => { expect(captured?.body).toEqual({ freeCancellationUntil: '2026-07-02T00:00:00.000Z' }) }) }) + +describe('options edit — stay details flags', () => { + test('builds the body from --details and --photos alone', async () => { + await run({ + tripId: 't', + variantId: 'v', + destinationKey: 'd', + kind: 'accommodation', + optionKey: 'o1', + details: '{"parking":"Garage","noise":null}', + photos: '[{"url":"https://example.com/a.jpg"}]', + json: false, + }) + + expect(captured?.method).toBe('PATCH') + expect(captured?.url).toContain('/options/accommodation/o1') + expect(captured?.body).toEqual({ + stayDetails: { parking: 'Garage', noise: null }, + photos: [{ url: 'https://example.com/a.jpg' }], + }) + }) +}) diff --git a/src/commands/options/edit.ts b/src/commands/options/edit.ts index 4801a0a..54849d5 100644 --- a/src/commands/options/edit.ts +++ b/src/commands/options/edit.ts @@ -6,6 +6,7 @@ import { colors } from '../../render/colors' import { reportAndExit, requireApiKey } from '../../util/errors' import { readJsonObject } from '../../util/json-file' import { applyFreeCancellation } from './free-cancellation' +import { applyStayFlags } from './stay-details' const KINDS = ['accommodation', 'transport', 'getting-around'] as const type Kind = (typeof KINDS)[number] @@ -40,17 +41,36 @@ export const optionsEditCommand = defineCommand({ description: 'Accommodation only: free-cancellation deadline (YYYY-MM-DD or ISO date-time). Lets you skip --from-json.', }, + details: { + type: 'string', + description: + "Accommodation only: stayDetails changes as JSON. Only the properties you send change; null clears one, and --details null clears them all. Only facts that help choose between this trip's options.", + }, + photos: { + type: 'string', + description: + 'Accommodation only: photos as a JSON array of { "url", "credit"? }, replacing the list; null clears it. Only images the owner may use.', + }, json: { type: 'boolean', default: false, description: 'Output as JSON.' }, }, async run({ args }) { try { assertKind(args.kind) - if (args['from-json'] === undefined && args['free-cancellation-until'] === undefined) { - throw new Error('Specify --from-json and/or --free-cancellation-until.') + const hasFlag = [ + args['from-json'], + args['free-cancellation-until'], + args.details, + args.photos, + ].some((flag) => flag !== undefined) + if (!hasFlag) { + throw new Error( + 'Specify at least one of --from-json, --free-cancellation-until, --details, --photos.', + ) } const body = args['from-json'] !== undefined ? await readJsonObject(args['from-json']) : {} applyFreeCancellation(body, args['free-cancellation-until'], args.kind) + applyStayFlags(body, { details: args.details, photos: args.photos }, args.kind) const creds = await loadCredentials() const apiKey = resolveApiKey(creds) diff --git a/src/commands/options/stay-details.test.ts b/src/commands/options/stay-details.test.ts new file mode 100644 index 0000000..d4a1805 --- /dev/null +++ b/src/commands/options/stay-details.test.ts @@ -0,0 +1,54 @@ +import { describe, expect, test } from 'bun:test' +import { applyStayFlags } from './stay-details' + +describe('applyStayFlags', () => { + test('leaves the body alone without the flags', () => { + const body = { name: 'Villa' } + applyStayFlags(body, {}, 'transport') + expect(body).toEqual({ name: 'Villa' }) + }) + + test('sets stayDetails and photos', () => { + const body: Record = {} + applyStayFlags( + body, + { + details: '{"highlight":"Ski to the door","kitchen":"private"}', + photos: '[{"url":"https://example.com/a.jpg","credit":"Anna"}]', + }, + 'accommodation', + ) + expect(body).toEqual({ + stayDetails: { highlight: 'Ski to the door', kitchen: 'private' }, + photos: [{ url: 'https://example.com/a.jpg', credit: 'Anna' }], + }) + }) + + test('a flag wins over the same field from the JSON file', () => { + const body: Record = { stayDetails: { noise: 'Bar nearby' } } + applyStayFlags(body, { details: '{"parking":"Garage"}' }, 'accommodation') + expect(body.stayDetails).toEqual({ parking: 'Garage' }) + }) + + test('passes null through, which clears the field', () => { + const body: Record = {} + applyStayFlags(body, { details: 'null', photos: 'null' }, 'accommodation') + expect(body).toEqual({ stayDetails: null, photos: null }) + }) + + test.each(['transport', 'getting-around'])('rejects the %s kind', (kind) => { + expect(() => applyStayFlags({}, { details: '{}' }, kind)).toThrow('only valid for the "accommodation" kind') + }) + + test('rejects malformed details', () => { + expect(() => applyStayFlags({}, { details: '{oops' }, 'accommodation')).toThrow('Invalid JSON in --details') + }) + + test('rejects details that are not an object', () => { + expect(() => applyStayFlags({}, { details: '["x"]' }, 'accommodation')).toThrow('--details must be a JSON object') + }) + + test('rejects photos that are not a list', () => { + expect(() => applyStayFlags({}, { photos: '{"url":"x"}' }, 'accommodation')).toThrow('--photos must be a JSON array') + }) +}) diff --git a/src/commands/options/stay-details.ts b/src/commands/options/stay-details.ts new file mode 100644 index 0000000..d3d177b --- /dev/null +++ b/src/commands/options/stay-details.ts @@ -0,0 +1,30 @@ +import { parseJsonFlag, parseJsonObjectFlag } from '../../util/json-flag' + +/** + * Merge the `--details` and `--photos` flags into an option body. Both fields + * exist only on accommodation, so any other kind is rejected. A flag overrides + * the same field in the `--from-json` file. + */ +export function applyStayFlags( + body: Record, + flags: { details?: string; photos?: string }, + kind: string, +): void { + if (flags.details === undefined && flags.photos === undefined) return + if (kind !== 'accommodation') { + throw new Error('--details and --photos are only valid for the "accommodation" kind.') + } + + if (flags.details !== undefined) { + body.stayDetails = parseJsonObjectFlag(flags.details, '--details') + } + if (flags.photos !== undefined) { + const photos = parseJsonFlag(flags.photos, '--photos') + if (photos !== null && !Array.isArray(photos)) { + throw new Error( + '--photos must be a JSON array of { "url": ..., "credit"?: ... }, or null to clear it.', + ) + } + body.photos = photos + } +} diff --git a/src/commands/trips/edit.test.ts b/src/commands/trips/edit.test.ts new file mode 100644 index 0000000..f5380c2 --- /dev/null +++ b/src/commands/trips/edit.test.ts @@ -0,0 +1,50 @@ +import { afterEach, beforeEach, describe, expect, test } from 'bun:test' +import { tripsEditCommand } from './edit' + +type RunFn = (ctx: { args: Record }) => Promise +const run = (args: Record) => + (tripsEditCommand.run as unknown as RunFn)({ args }) + +let originalFetch: typeof fetch +let originalKey: string | undefined +let captured: { method: string; body: unknown } | undefined + +beforeEach(() => { + originalFetch = global.fetch + originalKey = process.env.MNA_API_KEY + process.env.MNA_API_KEY = 'mna_test' + captured = undefined + global.fetch = (async (input: Request | URL | string, init?: RequestInit) => { + const req = input instanceof Request ? input : new Request(String(input), init) + const text = await req.text() + captured = { method: req.method, body: text ? JSON.parse(text) : undefined } + return new Response(null, { status: 200 }) + }) as unknown as typeof fetch +}) + +afterEach(() => { + global.fetch = originalFetch + process.env.MNA_API_KEY = originalKey + if (originalKey === undefined) Reflect.deleteProperty(process.env, 'MNA_API_KEY') +}) + +describe('trips edit — budget flag', () => { + test('sends the parsed budget', async () => { + await run({ + tripId: 't', + budget: '{"amount":4000,"currency":"EUR","appliesTo":"stay"}', + json: false, + }) + + expect(captured?.method).toBe('PATCH') + expect(captured?.body).toEqual({ + budget: { amount: 4000, currency: 'EUR', appliesTo: 'stay' }, + }) + }) + + test('--budget null clears it', async () => { + await run({ tripId: 't', budget: 'null', json: false }) + + expect(captured?.body).toEqual({ budget: null }) + }) +}) diff --git a/src/commands/trips/edit.ts b/src/commands/trips/edit.ts index b10c14e..eafb37a 100644 --- a/src/commands/trips/edit.ts +++ b/src/commands/trips/edit.ts @@ -4,6 +4,7 @@ import { loadCredentials, resolveApiKey, resolveBaseUrl } from '../../auth/crede import { renderJson } from '../../render/json' import { colors } from '../../render/colors' import { reportAndExit, requireApiKey } from '../../util/errors' +import { parseJsonObjectFlag } from '../../util/json-flag' const VALID_STATUSES = ['planning', 'ready', 'finished', 'cancelled'] as const type TripStatus = (typeof VALID_STATUSES)[number] @@ -19,6 +20,11 @@ export const tripsEditCommand = defineCommand({ name: { type: 'string', description: 'New name.' }, 'cover-photo': { type: 'string', description: 'New cover photo URL.' }, status: { type: 'string', description: `New status (${VALID_STATUSES.join('|')}).` }, + budget: { + type: 'string', + description: + 'Owner only: budget as JSON, e.g. \'{"amount":4000,"currency":"EUR","appliesTo":"stay"}\' (appliesTo: stay|total), or null to clear it.', + }, json: { type: 'boolean', default: false, description: 'Output as JSON.' }, }, async run({ args }) { @@ -32,8 +38,11 @@ export const tripsEditCommand = defineCommand({ } updates.status = args.status } + if (args.budget !== undefined) { + updates.budget = parseJsonObjectFlag(args.budget, '--budget') + } if (Object.keys(updates).length === 0) { - throw new Error('Specify at least one of --name, --cover-photo, --status.') + throw new Error('Specify at least one of --name, --cover-photo, --status, --budget.') } const creds = await loadCredentials() diff --git a/src/util/json-flag.test.ts b/src/util/json-flag.test.ts new file mode 100644 index 0000000..0b9fece --- /dev/null +++ b/src/util/json-flag.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, test } from 'bun:test' +import { parseJsonFlag, parseJsonObjectFlag } from './json-flag' + +describe('parseJsonFlag', () => { + test('parses a value', () => { + expect(parseJsonFlag('[1,2]', '--x')).toEqual([1, 2]) + }) + + test('names the flag when the JSON is malformed', () => { + expect(() => parseJsonFlag('{oops', '--details')).toThrow('Invalid JSON in --details') + }) +}) + +describe('parseJsonObjectFlag', () => { + test('accepts an object', () => { + expect(parseJsonObjectFlag('{"a":1}', '--x')).toEqual({ a: 1 }) + }) + + test('accepts null, which clears the field', () => { + expect(parseJsonObjectFlag('null', '--x')).toBeNull() + }) + + test.each(['[1]', '"text"', '5'])('rejects %s', (value) => { + expect(() => parseJsonObjectFlag(value, '--budget')).toThrow('--budget must be a JSON object') + }) +}) diff --git a/src/util/json-flag.ts b/src/util/json-flag.ts new file mode 100644 index 0000000..6a5b773 --- /dev/null +++ b/src/util/json-flag.ts @@ -0,0 +1,18 @@ +/** Parse a JSON value passed directly on the command line, naming the flag when it is malformed. */ +export function parseJsonFlag(value: string, flag: string): unknown { + try { + return JSON.parse(value) + } catch (err) { + throw new Error(`Invalid JSON in ${flag}: ${(err as Error).message}`) + } +} + +/** An object, or null where the API treats null as "clear this". */ +export function parseJsonObjectFlag(value: string, flag: string): Record | null { + const parsed = parseJsonFlag(value, flag) + + if (parsed !== null && (typeof parsed !== 'object' || Array.isArray(parsed))) { + throw new Error(`${flag} must be a JSON object, or null to clear it.`) + } + return parsed as Record | null +} From 33edf6c9ac45af8690499cdec4230315a1e6a057 Mon Sep 17 00:00:00 2001 From: Akos Orban Date: Tue, 3 Nov 2026 13:30:45 +0100 Subject: [PATCH 2/2] feat(options): add --website for a stay's official site Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R6BF2tkLhdyAHNtHx1mtCK --- README.md | 4 ++-- skills/mna/references/cli-and-schemas.md | 6 +++--- src/commands/options/add.ts | 7 ++++++- src/commands/options/edit.ts | 10 ++++++++-- src/commands/options/stay-details.test.ts | 14 ++++++++++++++ src/commands/options/stay-details.ts | 16 +++++++++++----- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 7d6f344..2378e36 100644 --- a/README.md +++ b/README.md @@ -268,8 +268,8 @@ selected variant; add `--all-options` to include the other variants. | Command | Description | |---|---| -| `mna options add --from-json= [--free-cancellation-until=] [--details=] [--photos=]` | Add an option from JSON. `--free-cancellation-until`, `--details` and `--photos` (accommodation only) merge into the body. | -| `mna options edit [--from-json=] [--free-cancellation-until=] [--details=] [--photos=]` | Edit an option. For accommodation, each flag works alone, without a JSON file. `--details` changes only the properties it names; `--photos` replaces the list. | +| `mna options add --from-json= [--free-cancellation-until=] [--details=] [--photos=] [--website=]` | Add an option from JSON. `--free-cancellation-until`, `--details` and `--photos` (accommodation only) merge into the body. | +| `mna options edit [--from-json=] [--free-cancellation-until=] [--details=] [--photos=] [--website=]` | Edit an option. For accommodation, each flag works alone, without a JSON file. `--details` changes only the properties it names; `--photos` replaces the list. | | `mna options delete [--yes]` | Delete an option. | | `mna options select ` | Select an option. | | `mna options deselect ` | Deselect the current option. | diff --git a/skills/mna/references/cli-and-schemas.md b/skills/mna/references/cli-and-schemas.md index c7fd803..759c7f9 100644 --- a/skills/mna/references/cli-and-schemas.md +++ b/skills/mna/references/cli-and-schemas.md @@ -13,8 +13,8 @@ variants add --name [--adults --child-ages --no-children - destinations add --place [--start-date --end-date --notes --return-to-home] edit [--place --notes --start-date --end-date --return-to-home/--no-…] reorder --order=k1,k2,k3 | delete -options add --from-json [--free-cancellation-until ] [--details ] [--photos ] - edit [--from-json ] [--free-cancellation-until ] [--details ] [--photos ] +options add --from-json [--free-cancellation-until ] [--details ] [--photos ] [--website ] + edit [--from-json ] [--free-cancellation-until ] [--details ] [--photos ] [--website ] select | deselect delete events add --from-json | edit --from-json @@ -91,7 +91,7 @@ options, and leave out anything equally true of all of them, or unknown. | `dinner`, `bedLayout`, `skiBackNote`, `mainLiftName`, `skiStorage`, `kidsFacilities`, `wellness`, `pool`, `beach`, `parking`, `noise`, `view`, `airConditioning`, `laundry`, `accessibility`, `pets`, `sourceNote` | text, up to 300 characters | On an edit, only the `stayDetails` properties you send change. `null` clears one, and -`--details null` clears them all. `--photos` replaces the whole list, up to 12 photos, and +`--website` is the place's own official site, never a booking or listing site; leave it out if you can't confirm it. Photos from it may then be linked automatically, credited to the site. `--website null` clears it. `--details null` clears them all. `--photos` replaces the whole list, up to 12 photos, and `--photos null` clears it. Unknown properties are rejected. `photos` take `{ "url", "credit"?, "creditUrl"? }`. Each URL must be a directly linkable http or diff --git a/src/commands/options/add.ts b/src/commands/options/add.ts index d894c6b..bd2181d 100644 --- a/src/commands/options/add.ts +++ b/src/commands/options/add.ts @@ -51,6 +51,11 @@ export const optionsAddCommand = defineCommand({ description: 'Accommodation only: photos as a JSON array of { "url", "credit"? }. Only images the owner may use.', }, + website: { + type: 'string', + description: + "Accommodation only: the place's own official website, not a booking site. Photos from it may be linked automatically, credited to the site.", + }, json: { type: 'boolean', default: false, description: 'Output as JSON.' }, }, async run({ args }) { @@ -58,7 +63,7 @@ export const optionsAddCommand = defineCommand({ assertKind(args.kind) const body = await readJsonObject(args['from-json']) applyFreeCancellation(body, args['free-cancellation-until'], args.kind) - applyStayFlags(body, { details: args.details, photos: args.photos }, args.kind) + applyStayFlags(body, { details: args.details, photos: args.photos, website: args.website }, args.kind) const creds = await loadCredentials() const apiKey = resolveApiKey(creds) diff --git a/src/commands/options/edit.ts b/src/commands/options/edit.ts index 54849d5..634d66c 100644 --- a/src/commands/options/edit.ts +++ b/src/commands/options/edit.ts @@ -51,6 +51,11 @@ export const optionsEditCommand = defineCommand({ description: 'Accommodation only: photos as a JSON array of { "url", "credit"? }, replacing the list; null clears it. Only images the owner may use.', }, + website: { + type: 'string', + description: + "Accommodation only: the place's own official website, not a booking site. Photos from it may be linked automatically, credited to the site. null clears it.", + }, json: { type: 'boolean', default: false, description: 'Output as JSON.' }, }, async run({ args }) { @@ -61,16 +66,17 @@ export const optionsEditCommand = defineCommand({ args['free-cancellation-until'], args.details, args.photos, + args.website, ].some((flag) => flag !== undefined) if (!hasFlag) { throw new Error( - 'Specify at least one of --from-json, --free-cancellation-until, --details, --photos.', + 'Specify at least one of --from-json, --free-cancellation-until, --details, --photos, --website.', ) } const body = args['from-json'] !== undefined ? await readJsonObject(args['from-json']) : {} applyFreeCancellation(body, args['free-cancellation-until'], args.kind) - applyStayFlags(body, { details: args.details, photos: args.photos }, args.kind) + applyStayFlags(body, { details: args.details, photos: args.photos, website: args.website }, args.kind) const creds = await loadCredentials() const apiKey = resolveApiKey(creds) diff --git a/src/commands/options/stay-details.test.ts b/src/commands/options/stay-details.test.ts index d4a1805..b6769c8 100644 --- a/src/commands/options/stay-details.test.ts +++ b/src/commands/options/stay-details.test.ts @@ -8,6 +8,20 @@ describe('applyStayFlags', () => { expect(body).toEqual({ name: 'Villa' }) }) + test('sets and clears the website', () => { + const body: Record = {} + applyStayFlags(body, { website: 'https://hotel.example/' }, 'accommodation') + expect(body.website).toBe('https://hotel.example/') + + applyStayFlags(body, { website: 'null' }, 'accommodation') + expect(body.website).toBeNull() + }) + + test('refuses a website that is not a web address, and other kinds', () => { + expect(() => applyStayFlags({}, { website: 'javascript:alert(1)' }, 'accommodation')).toThrow('--website') + expect(() => applyStayFlags({}, { website: 'https://hotel.example/' }, 'transport')).toThrow('accommodation') + }) + test('sets stayDetails and photos', () => { const body: Record = {} applyStayFlags( diff --git a/src/commands/options/stay-details.ts b/src/commands/options/stay-details.ts index d3d177b..e48c813 100644 --- a/src/commands/options/stay-details.ts +++ b/src/commands/options/stay-details.ts @@ -1,18 +1,18 @@ import { parseJsonFlag, parseJsonObjectFlag } from '../../util/json-flag' /** - * Merge the `--details` and `--photos` flags into an option body. Both fields - * exist only on accommodation, so any other kind is rejected. A flag overrides + * Merge the `--details`, `--photos` and `--website` flags into an option body. These + * fields exist only on accommodation, so any other kind is rejected. A flag overrides * the same field in the `--from-json` file. */ export function applyStayFlags( body: Record, - flags: { details?: string; photos?: string }, + flags: { details?: string; photos?: string; website?: string }, kind: string, ): void { - if (flags.details === undefined && flags.photos === undefined) return + if (flags.details === undefined && flags.photos === undefined && flags.website === undefined) return if (kind !== 'accommodation') { - throw new Error('--details and --photos are only valid for the "accommodation" kind.') + throw new Error('--details, --photos and --website are only valid for the "accommodation" kind.') } if (flags.details !== undefined) { @@ -27,4 +27,10 @@ export function applyStayFlags( } body.photos = photos } + if (flags.website !== undefined) { + if (flags.website !== 'null' && !/^https?:\/\/\S+$/.test(flags.website)) { + throw new Error('--website must be an http or https URL, or null to clear it.') + } + body.website = flags.website === 'null' ? null : flags.website + } }