diff --git a/packages/schema/schemas/care-event.schema.json b/packages/schema/schemas/care-event.schema.json index b1c91e9..67019e5 100644 --- a/packages/schema/schemas/care-event.schema.json +++ b/packages/schema/schemas/care-event.schema.json @@ -5,27 +5,102 @@ "description": "One act of care, append-only and never edited (CLAUDE.md §6.2). The other event kinds arrive with docs/GAMEPLAY.md.", "type": "object", "additionalProperties": false, - "required": ["kind", "ts", "localDay", "from", "to", "act", "trace", "messageId", "clientVersion"], + "required": [ + "kind", + "ts", + "localDay", + "from", + "to", + "act", + "trace", + "messageId", + "clientVersion" + ], "properties": { - "kind": { "const": "care" }, - "ts": { "description": "Epoch milliseconds. Stays on the device; never part of a trace.", "type": "integer", "minimum": 0 }, + "kind": { + "const": "care" + }, + "ts": { + "description": "Epoch milliseconds. Stays on the device; never part of a trace.", + "type": "integer", + "minimum": 0 + }, "localDay": { "description": "The player's local day, from engine/src/time/localDay.ts and nowhere else.", "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" }, - "from": { "$ref": "#/definitions/publicKey" }, - "to": { "$ref": "#/definitions/publicKey" }, - "act": { "type": "string", "enum": ["water", "shade", "weed", "petals"] }, - "trace": { "type": "string", "pattern": "^petal:[a-z]+(-[a-z]+)*$" }, + "from": { + "$ref": "#/definitions/publicKey" + }, + "to": { + "$ref": "#/definitions/publicKey" + }, + "act": { + "type": "string", + "enum": [ + "water", + "shade", + "weed", + "petals" + ] + }, + "trace": { + "type": "string", + "pattern": "^petal:[a-z]+(-[a-z]+)*$" + }, "messageId": { "description": "A hope-library id or null. Never text: the pattern admits no space, so no sentence fits (CLAUDE.md §5.6 rule 1).", "oneOf": [ - { "type": "string", "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$", "maxLength": 64 }, - { "type": "null" } + { + "type": "string", + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$", + "maxLength": 64 + }, + { + "type": "null" + } ] }, - "clientVersion": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" } + "clientVersion": { + "type": "string", + "pattern": "^\\d+\\.\\d+\\.\\d+$" + }, + "amount": { + "description": "How much was poured, 0 to 1 of a full can. Water only: the skill of watering by feel is replayed from it (.agents/features/rose.md R1).", + "type": "number", + "minimum": 0, + "maximum": 1 + } + }, + "if": { + "properties": { + "act": { + "const": "water" + } + } + }, + "then": { + "properties": { + "amount": { + "type": "number" + } + }, + "required": [ + "amount" + ] + }, + "else": { + "not": { + "properties": { + "amount": { + "type": "number" + } + }, + "required": [ + "amount" + ] + } }, "definitions": { "publicKey": { diff --git a/packages/schema/test/schemas.test.ts b/packages/schema/test/schemas.test.ts index 3faf8d1..049252a 100644 --- a/packages/schema/test/schemas.test.ts +++ b/packages/schema/test/schemas.test.ts @@ -10,7 +10,7 @@ const careEvent = { localDay: '2026-10-24', from: KEY_A, to: KEY_B, - act: 'water', + act: 'shade', trace: 'petal:pale-pink', messageId: 'ps-23-4', clientVersion: '0.1.0' @@ -64,9 +64,19 @@ describe('hope sentence', () => { describe('care event', () => { it('accepts every act the rose has', () => { - for (const act of ['water', 'shade', 'weed', 'petals']) { + for (const act of ['shade', 'weed', 'petals']) { expect(validateCareEvent({ ...careEvent, act }), act).toMatchObject({ ok: true }); } + expect(validateCareEvent({ ...careEvent, act: 'water', amount: 0.5 })).toMatchObject({ ok: true }); + }); + + it('water carries how much was poured, 0 to 1; no other act carries it (rose.md R1)', () => { + expect(validateCareEvent({ ...careEvent, act: 'water' }).ok, 'water without amount').toBe(false); + expect(validateCareEvent({ ...careEvent, act: 'water', amount: 0 }).ok).toBe(true); + expect(validateCareEvent({ ...careEvent, act: 'water', amount: 1 }).ok).toBe(true); + expect(validateCareEvent({ ...careEvent, act: 'water', amount: 1.01 }).ok).toBe(false); + expect(validateCareEvent({ ...careEvent, act: 'water', amount: -0.1 }).ok).toBe(false); + expect(validateCareEvent({ ...careEvent, act: 'weed', amount: 0.5 }).ok, 'weeds are pulled, not poured').toBe(false); }); it('rejects the acts §6.2 used to list by mistake', () => {