Repository navigation
feat(service-analytics): list_datasets and query_dataset, the dataset AI tools (ADR-0149 D2–D4) - #31772
Conversation
…ataset) createDatasetTools / getDatasetToolDefinitions, the term matcher, the catalogue admission on AnalyticsService and member descriptions on the compiled Cube. Tests follow. Claude-Session: https://claude.ai/code/session_01ADHkmRZxiPAWdpf7vuSUcH Co-authored-by: Claude <noreply@anthropic.com>
…et tools to itself The bridge hosts reach the tools through the kernel's analytics service, so neither imports this package. Claude-Session: https://claude.ai/code/session_01ADHkmRZxiPAWdpf7vuSUcH Co-authored-by: Claude <noreply@anthropic.com>
…compiled member descriptions Claude-Session: https://claude.ai/code/session_01ADHkmRZxiPAWdpf7vuSUcH Co-authored-by: Claude <noreply@anthropic.com>
… service call Claude-Session: https://claude.ai/code/session_01ADHkmRZxiPAWdpf7vuSUcH Co-authored-by: Claude <noreply@anthropic.com>
…dd the changeset The four dataset member rows (synonyms and description on dimensions and measures) move planned -> live now that their readers landed; the two Cube member-description notes say a compiled dataset cube carries one. Claude-Session: https://claude.ai/code/session_01ADHkmRZxiPAWdpf7vuSUcH Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 12 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 9 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 171 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e7c2f98f85e203691e2a0cc6af89af0f41ad97a2 && git checkout e7c2f98f85e203691e2a0cc6af89af0f41ad97a2
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin c2bb879fe71c16bd1d0b42708109efb7f6543d5d 7aaedcd2d662a86138ad32955e47f79a03859a9a && git checkout -B drift-repro c2bb879fe71c16bd1d0b42708109efb7f6543d5d && git merge --no-ff 7aaedcd2d662a86138ad32955e47f79a03859a9a
node scripts/docs-audit/affected-docs.mjs --json c2bb879fe71c16bd1d0b42708109efb7f6543d5d
|
|
domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flagsThe os-dev-report's open questions (6731447318) are all answered in the seat ACCEPT: names kept, Implemented-by: VERDICT: PASS |
|
domain:server#2 · os-steve · session_01ADHkmQKZzp4DLtqiCkZZRM 维护者速读
席位核对 — ACCEPT · domain:server#2 · Head-sha
|
Requested by Steve · project thread
Fixes #31589
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
list_datasets(列出调用者能查的数据集、指标与维度、业务说明和同义词,并标出提问用词命中了哪个指标)和query_dataset(按数据集查数,答案附带 provenance 来源块);一份定义、一个执行器;数据集成员的业务说明写进 Cube,/analytics/meta可见。queryDataset并带调用者上下文,不加门也不绕门;未经 AnalyticsServicePlugin 装配权限钩子的服务一律拒绝(503)。纯新增,回滚即 revert 本 PR。packages/services/service-analytics/src/dataset-tools.ts(执行器与 provenance)、analytics-service.ts的admitDatasetCatalogEntry(目录复用查询的同一套门)、packages/rest/src/analytics-dataset-ai-tools-parity.test.ts(三个入口同行同拒)。pnpm --filter @objectstack/service-analytics build && pnpm --filter @objectstack/rest exec vitest run src/analytics-dataset-ai-tools-parity.test.ts,应见 6 个测试全过。What changes
The tools (ADR-0149 D2). New
packages/services/service-analytics/src/dataset-tools.ts:getDatasetToolDefinitions(): the twoAIToolDefinitions,list_datasetsthenquery_dataset.parametersandoutputSchemaare the spec'sgetDatasetToolJsonSchemas()projections (by reference, no copy); the descriptions carry the D3 selection rule (one match wins, several ask, none falls back labelled 非指标口径, the recommended dataset-hint line, a dimension match alone is no answer).createDatasetTools(deps)andAnalyticsService.datasetTools(deps)(seat ruling C on the bridge seam: the bridge hosts cannot import this package, so they reach the tools through the kernel'sanalyticsservice). deps:loadDatasets(ctx)(the saveddatasetitems of the caller's environment, localized at the metadata boundary like the REST door),maxQueryLimit?(default 50),diagnoseDelegation?(object, ctx). The answer:{ definitions, execute({ toolName, input }, ctx), listDatasets(input, ctx), queryDataset(input, ctx) }. Refusals throw an ADR-0112-shaped error (code+status).SERVICE_UNAVAILABLE/ 503 unless the service is anAnalyticsServicewhose four admission hooks are wired (hasPluginWiredAdmission():getObjectDeclaration,admitObjectRead,getReadableFields,getQueryableFields, all always wired byAnalyticsServicePlugin). Without them the exposure gate warns once and passes and the read admission returns silently.The catalogue (seat ruling 1).
AnalyticsService.admitDatasetCatalogEntry(dataset, ctx)asks the gates a query of the dataset passes, through the service's own private methods (no copy):assertDatasetFieldsJudgeableandcompile, thenassertQueryObjectsExposedandassertReadAdmittedover the base object and everyincludetarget (cubeObjects). Refused: the dataset is absent, theCUBE_NOT_FOUND/cube-visibility.tsshape.DatasetExecutorwould issue (a derived measure as its base measures viaexpandSelectedMeasures), with the dataset filter and the measure filter on the dataset-scope channel:assertStoredMetadataBodyNotQueriedandassertNoInternalFieldsQueriedrefuse for every caller, so the member is omitted unstated and logged once atwarn(reportDatasetCatalogDefect);assertFieldsReadable(field-read-admission.ts) refuses for this caller, so the member is omitted andmembersWithheld: trueis set.partialwith a warning.The term matcher (D3). New
dataset-term-matcher.ts,matchDatasetTerms(terms, members): equality after the spec's ownnormalizeDatasetTerm, over the member's name, every locale of its label, and each synonym; never a substring. Only admitted members are matched.query_dataset. Validates the input with the spec's strictQueryDatasetInputSchema(validation only; the caller's own selection reaches the service, as on the REST door). Resolves the saved dataset aslist_datasetswould: missing and hidden are oneNOT_FOUND/ 404. ThenqueryDataset(dataset, selection, ctx)with the caller's context, nothing added and nothing skipped. Row cap: the caller'slimitwhen under the cap, else the cap; one row more is asked sotruncatedis a fact. The answer dropssqland addsrowCount,truncated, the delegation statement when the probe reports one, andprovenance(seat ruling 3) composed after the query from the resolved dataset: dataset name and label, the selected measures with label and description, the selected dimensions, and the caller'sruntimeFilteras sent. The dataset's ownfilteris never echoed. Aprovenancekey in the input, at the top or insideselection, is refusedVALIDATION_FAILED/ 400 by the strict parse.Member descriptions on the Cube (D1, M1 ruled A).
compileDatasetresolves a dimension's and a measure'sdescriptionlike their labels and writes it onto the Cube member, sogetMetapublishes it for a registered dataset cube.dimensionTypeis now exported fromdataset-compiler.ts(not from the package index) so the catalogue names the same dimension type the cube carries.Liveness ledger (seat ruling on this card: these rows only).
packages/spec/liveness/dataset.json: the foursynonyms/descriptionrows on dimensions and measures moveplanned→live, citing their readers.packages/spec/liveness/analytics_cube.json: the two memberdescriptionnotes now say a compiled dataset cube carries one (carry note 6726684547).packages/spec/liveness/state-counts/dataset.mdis regenerated bygen:liveness-counts(check:livenessrefuses a stale count shard; generator output, not a hand edit).Four-face parity (seat ruling 4). The MCP face is #31590's (bridge members and
registerDatasetTools), in flight beside this card. This PR lands the REST, chat-tool and direct-service faces; #31590 adds the MCP row topackages/rest/src/analytics-dataset-ai-tools-parity.test.ts. Nopackages/mcpedit here.Tests
packages/services/service-analytics/src/__tests__/dataset-tools.test.ts(new, 15 tests): definitions; D4 unwired refused (both tools, nothing loaded, nothing read) and plugin-wired served; absent / withheld / internal-omitted catalogue for two callers;matches; input refusal and partial reads; oneNOT_FOUNDfor missing, read-denied and not-exposed datasets with nothing read;queryDatasetcalled with the caller's context and provenance composed; the provenance forgery refused at both levels; a field refusal carrying the service's own envelope; row cap,truncatedand the delegation statement; 503 on a failed read;executedispatch.packages/services/service-analytics/src/__tests__/dataset-term-matcher.test.ts(new, 5 tests).packages/services/service-analytics/src/__tests__/cube-meta-description-format.test.ts: one new case in the existingdescribe(a declared member description is published, synonyms are not). Forced test edit: the neighbouring case's title and comment said a dataset member "has nodescriptionkey to copy"; that is no longer true, so they now say these members declare none. The assertions are unchanged.packages/rest/src/analytics-dataset-ai-tools-parity.test.ts(new, 6 tests): a realObjectQLengine over SQLite, the serviceAnalyticsServicePluginregisters, asecuritydouble whose read filter folds tenant ∧ (owner ∨ sharing grant). For three callers the REST door, the chat tool andqueryDatasetreturn the same rows; a field the caller may not read is refused403 PERMISSION_DENIEDon all three; an object the caller may not read is refused on all three (403 on REST and direct, 404 on the tool, by the one-answer contract);list_datasetslists exactly what is served.Red first and ablations (7 legs, each restored to HEAD,
git diff HEADempty)Red on main: the three new test files import modules that do not exist on
origin/main; the Cube description case is A1, which is main's compiler line.Every leg through
scripts/ablation-replace.mjs(anchor must hit, replacement marker counted on disk, restore verified against the HEAD blob):dataset-compiler.ts: drop the measuredescriptionwrite →cube-meta-description-format.test.ts1 failed / 5 passed.dataset-tools.ts: drophasPluginWiredAdmission()from the wired check → "REFUSES both tools on a hand-built service" red, 1 failed / 14 passed.analytics-service.ts: skipassertFieldsReadablein the catalogue → withheld and match cases red, 2 failed / 13 passed.dataset-tools.ts: skip thequery_datasetinput refusal → provenance-forgery case red, 1 failed / 14 passed.dataset-tools.ts: skip the dataset-level admission inquery_dataset→ one-NOT_FOUND case red, 1 failed / 14 passed.dataset-term-matcher.ts: synonym match by substring → "does not hit on a substring" red, 1 failed / 4 passed.dataset-tools.ts: callqueryDatasetwithout the caller's context, rebuilt,ablation-dist-preflight.mjssaw the marker indist/→ parity 4 failed / 2 passed. Restore leg: rebuilt, preflight--absent, 6 passed.The first A2 and A3 attempts were refused by the tool (the replacement text already occurred in the file, so no rise could be counted); nothing ran. Re-run with a marker comment.
Acceptance notes
query_datasetasks the dataset-level gates (exposure, object read) once to resolve the dataset, so a hidden dataset answersNOT_FOUNDlike a missing one (specQueryDatasetInputSchema.datasetNameand ADR-0149 D2), thenqueryDatasetasks them again incallCtx. Same gate, same methods, asked twice; no rule of its own.query_datasetwith 503SERVICE_UNAVAILABLE, notNOT_FOUND;list_datasetsanswerspartialwith the reason. The REST door's own.catch(() => null)on the same read answers 404 for a failed read; noted, not changed here.VALIDATION_FAILED/ 400 withdetails.fields, the REST dataset door's code for the same parse.Verification
Head
7aaedcd2(origin/main merged atf65c36fcc):pnpm turbo run build --filter='@objectstack/service-analytics...' --filter=@objectstack/rest·pnpm --filter @objectstack/service-analytics test→ Test Files 214 passed, Tests 5119 passed / 330 skipped ·pnpm --filter @objectstack/service-analytics typecheckandpnpm --filter @objectstack/rest typecheck→ exit 0 · restanalytics-dataset-ai-tools-parity,analytics-dataset-refusal-envelope,analytics-routes→ 3 files, 29 passed. Lock VERDICT command-exit 0.--no-inline-configover the nine changed source and test files → exit 0.pnpm --filter @objectstack/spec check:liveness→ exit 0.node scripts/pm/dispatch-gates.mjs --ran→ 78 derived, 78 run, 0 NOT-MEASURED, 0 UNRUN, every exit 0. Three first ran red on container prerequisites, not the diff, and were rerun green:check-plugin-teardown-shape --self-test(shallow clone; fetched the pinned fixture commit),spec check:generated(tscforcheck:test-typecheckdied without diagnostics under the parallel sweep; green alone at a 6 GB heap, no artifact regenerated),check:dual-build-cjs-loads(needs everydist/; fullpnpm build, 119 tasks, under the verify lock, then 122 entries load).Generated by Claude Code