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
65 changes: 65 additions & 0 deletions packages/retrieval/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# @journal/retrieval — remember & retrieve (read-only, synthetic data)

Bounded read-only query path for scoped natural-language history questions:
plans compiled from a fixed phrase inventory, executed against a deterministic
synthetic corpus, answered with citations, coverage, and disclosed gaps.

**This package is the executable form of a rule-2 proposal.** The query
contracts in `src/queryContracts.ts` (`HistoryQueryInput`, `HistoryQueryPlan`,
`HistoryQueryAnswer` and their parts) are PROPOSALS for the canonical contract
— promotion into `packages/domain` is owned by the contract v0.3 fold thread
and is deliberately not self-landed here. Boundaries that keep the canonical
contract authoritative:

- Entry/Event decoding goes through `@journal/domain`; nothing here redefines
those shapes. The corpus fail-fasts at generation time if it ever drifts.
- `category` fields reuse the canonical `EventFields.category` — the
six-literal taxonomy is never restated.
- Id fields reuse `convexId()` annotations so a later promotion derives
identical Convex validators.

## Invariants

- **Read-only.** No write path of any kind; queries do not mutate the corpus
(tested).
- **Synthetic data only.** The 30-day corpus (`src/corpus.ts`) is pure
constants — no clock reads, no randomness; two runs are byte-identical
(tested).
- **Never serve superseded events.** Append-only corrections exclude the
superseded event from answers and disclose the correction as a notice
(tested).
- **Disclose, don't pretend.** Answers carry `AnswerCoverage` (confirmed /
inferred / total, per contract v0.2 T2), correction notices, conflicting-
author notices, and missing-log gap notices instead of an inferred story.
- **Clarify, don't guess.** Unknown activities, unresolved persons, and
missing time windows return structured `clarify` answers; multi-child
questions without a pinned child return `ambiguous` with per-child
candidates.
- **Honest not-found.** An empty match set is `not-found` — never answered
from another child's data, even when the question used a pronoun under a
pinned scope (tested: `hq-14`).

## Layout

- `src/queryContracts.ts` — the rule-2 proposal schemas (input, plan, answer).
- `src/corpus.ts` — deterministic 30-day synthetic corpus (timeline documented
inline: gaps Aug 22–23, correction Aug 20, conflicting pasta Aug 17,
shared dinner Aug 30, confirmed school Sep 5).
- `src/resolve.ts` — bounded NL question → `HistoryQueryPlan` compiler with
zone-aware window parsing (`today`/`yesterday`/`this week`/`last week`/
`on <date>`/`between <a> and <b>`/`since <date>`).
- `src/engine.ts` — plan executor: matching, supersession filtering, notices,
citations, coverage, statements; `resolveEntrySource` navigates a citation's
`entryId` back to the verbatim record.

## Verify

```sh
pnpm test # bun: 14 hand-derived fixtures + determinism + navigation
pnpm typecheck # strict TS over src and test
pnpm build # tsc emit
```

The fixtures in `test/expectedAnswers.ts` are hand-derived from the corpus
timeline, NOT generated by running the implementation — a failing fixture
test is either an implementation bug or a fixture arithmetic bug; both matter.
26 changes: 26 additions & 0 deletions packages/retrieval/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@journal/retrieval",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "Read-only remember-and-retrieve query path over the deterministic synthetic history corpus (slots 15/17 groundwork; query contracts are rule-2 proposals, not self-landed)",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"scripts": {
"build": "tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig.test.json --noEmit",
"test": "bun test"
},
"dependencies": {
"@journal/domain": "workspace:*",
"effect": "4.0.0-rc.115"
},
"devDependencies": {
"@types/bun": "^1.3.14",
"typescript": "~6.0.3"
}
}
Loading
Loading