Repository navigation
feat(service-segmenter): a segmenter service that cuts a Chinese question into real words for the keyword leg - #38744
Conversation
…apters and the segmenter Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
…a Han run into dictionary words Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
…for the segmenter contract Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 3 package(s): 3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 189 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 0ddc18794a2ecf1a70b615c01863303abae4ef01 && git checkout 0ddc18794a2ecf1a70b615c01863303abae4ef01
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 7625001f9b7918edb08d6413bc24026d692f6e94 ff965718b660afca4bd19665286ff69d28ffa364 && git checkout -B drift-repro 7625001f9b7918edb08d6413bc24026d692f6e94 && git merge --no-ff ff965718b660afca4bd19665286ff69d28ffa364
node scripts/docs-audit/affected-docs.mjs --json 7625001f9b7918edb08d6413bc24026d692f6e94
|
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN Contract-review-claim: session_01RKKVngFfp7HBk6JUUr5vfN · head c1c202d · 2026-11-30T12:36Z |
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN Contract reviewServed-tier: Below, "contract" is ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentThe shape fits the rulings and the step-2 consumers.
Findings:
Findings 1–3 each change jsdoc or one code path and break nothing; this reviewer reads the delta. Implemented-by: VERDICT: PASS |
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN 2026-11-30T12:43Z · L1 verdict: REWORK (round 1 of at most 2) · head The rulings, the declared files, the changeset lines and CI (74 runs, all success or skipped) check out against the tree. The at-tier L2 contract review above is PASS with three should-fix items; they are folded in below, so one round closes both reviews. The L2 reviewer reads the delta. Must-fix
Should-fix (this round)
Nits (carry if cheap, else list in acceptance notes)
The dev's open questions 1–3 are accepted as answered (A, A, A). The |
…ole, supplied words in any script Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN Contract reviewServed-tier: "Contract" is Delta from c1c202d
① Derived judgmentsUnchanged. Under ② Semver levelUnchanged: ③ Boundary flags
④ Design judgmentThe reworked contract still fits both step-2 routes and the rulings. Supplied words survive a jieba load failure because the word pass precedes engine dispatch (service
Implemented-by: VERDICT: PASS |
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN 2026-11-30T16:03Z · L1 verdict: REWORK, round 2 of 2 (final) · head The seat's delta read finds M1, S1 to S5 and the Should-fix (this round)
Not for the dev
After the push: post an updated |
…is not found, and a test pins it Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN Contract reviewServed-tier: "Contract" is Delta from 75fcae7
① Derived judgmentsUnchanged. Under ② Semver levelUnchanged: ③ Boundary flags
④ Design judgmentThe claim is now as narrow as the enforcement (Prime Directive 10). Stating the limit was the right choice over matching: a key normalised like the question would emit a term with a space that the stored text does not hold. An administrator importing policy titles enters them without their marks. No new contract-face problem. Implemented-by: VERDICT: PASS |
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN 2026-12-01T01:45Z · L1 verdict: ACCEPT · head 席位核对
Card-total note: the line threshold counts every PR of #38710 together. PR 2 and step 2 will very likely take the card past 3000, and from then on its PRs are Tier H. |
…after merging main Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN Regen-provenance: 7297824190 · 2026-12-01T03:40Z · The head moved by one clean merge of
The L2 PASS record 7297824190 continues on this head through the regeneration arm. The ACCEPT stands, and landing waits for CI on |
|
repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN 2026-12-01T04:11Z · Landing · head
State change: |
…k-ai#38778) repo:objectstack#3 · os-steve · session_01ADHkmPDtfMCw4FJfyFfQ7v Fixes objectstack-ai#38772 Clause-②: yes (widening) Metadata-protocol: none ## 维护者速读 - 用户无感:开发者在规范包的契约入口里多了一个“重排器”接口和它的服务名,运行时行为不变。 - 属于“知识检索重排”专题,先把重排器的契约立住,后续的知识服务重排步骤按它接入。 - 目前没有任何代码读取它,出错也只影响类型声明,整个改动可直接撤回。 - 无 ## What changes - New `packages/spec/src/contracts/reranker.ts`, mirroring `embedder.ts`: `IReranker { readonly id: string; rerank(query: string, documents: string[], opts?: { signal?: AbortSignal }): Promise<Array<{ index: number; score: number }>> }` and `RERANKER_SERVICE = 'reranker' as const`. - The docblock states the ruled contract and no more: the model always comes from the deployment, never from a knowledge source; the knowledge service resolves it per search, as adapters resolve the embedder; one call per search, at most 50 documents; the caller passes an `AbortSignal` for its time limit; each entry names a document by its position in `documents` plus the reranker's score. No order or completeness guarantee is stated (not ruled). - `packages/spec/src/contracts/index.ts`: one `export * from './reranker.js';` line, placed right after `knowledge-service.js` (not after `embedder.js`, where objectstack-ai#38744 inserts its own line; `overlap-check.mjs` reads both merges clean). - Regenerated by their generators: `packages/spec/api-surface/contracts.json` and `packages/spec/export-origins/contracts.json` (+2 names each). `gen:declaration-map` wrote nothing. - Changeset `.changeset/38772-reranker-contract.md`: `@objectstack/spec` patch (`Metadata-protocol: none` sets patch). - Not here: no `IReranker.model`, no vendor list, no reader, no `core-service-contracts.ts` entry (the embedder has none either), no runtime change. ## Tests - `packages/spec/src/contracts/reranker.test.ts`: type-level pins (exported `Assert<Eq<…>>` aliases compiled by `check:test-typecheck`) for the member set (`id` | `rerank` only), readonly `id`, the exact parameter tuple, the options bag, optional `opts`, the `Promise<Array<{ index; score }>>` answer, the barrel re-export and the `'reranker'` literal; plus two runtime cases. - Reverse verification: adding `model?: string` and a `topK` option to the interface turned `check:test-typecheck` red with 3 type errors in `reranker.test.ts`; restored from HEAD, clean. ## Acceptance notes - `opts.signal` is typed optional (`{ signal?: AbortSignal }`), as `fetch`'s `RequestInit` spells it; the epic's line writes `opts?: { signal }`. The docblock says the caller passes one. - Returned order and count are not defined by the contract (the ruling says index + score per document only); row 2's service orders by position. ## Verification <details><summary>Local gates</summary> At head `7d0eea72`. `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 90 commands; `--ran` reconciliation: 90 derived, 86 run (exit 0), 4 NOT MEASURED, 0 unrun. - Spec package: `pnpm --filter @objectstack/spec typecheck` (tsc, check:scripts-typecheck, check:test-typecheck) exit 0; `vitest run --project local src/contracts/reranker.test.ts src/contracts/core-service-contracts.test.ts` 2 files, 13 tests passed. - `check:api-surface`, `check:export-origins`, `check:generated`, `check:authorable-surface`, `check:dual-source-exports`, `check:entry-nameability`, `check:exported-any`, `check:spec-docblock-symbol-anchors`, `check:changeset-no-major`, `check:empty-changeset`, `check:nul-bytes`: exit 0 (all within the 86). - NOT MEASURED, to CI: `check:doc-formula-expressions`, `check:dual-build-cjs-loads`, `check:lean-entry-closure` (exit 3, prerequisite: other packages' dist not built here); `check:type-check-debt` (whole-workspace ratchet, not reached within the local time cap). - `node scripts/pm/overlap-check.mjs`: clean against origin/main and objectstack-ai#38744. </details> Two-minute check: `pnpm --filter @objectstack/spec exec vitest run --project local src/contracts/reranker.test.ts` prints `2 passed`. Read first: `packages/spec/src/contracts/reranker.ts` (the docblock is the contract text), then `reranker.test.ts`. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmPDtfMCw4FJfyFfQ7v)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmPDtfMCw4FJfyFfQ7v <!-- signed: repo:objectstack#3 · os-steve · session_01ADHkmPDtfMCw4FJfyFfQ7v --> --------- Co-authored-by: Claude <noreply@anthropic.com>
Refs #38710 (step 1, PR 1 of 2)
Clause-②: yes
Metadata-protocol: none
维护者速读
What changes
Step 1, PR 1 of 2 on the segmentation card, under the maintainer's rulings 7272436453 (package
@objectstack/service-segmenter, contractsegmenter-service.ts, registered inServiceSlotContractsonly), 7272452774, 7272455751 and 7272462484, plus 7272241375 item 1 (@node-rs/jieba, HMM off,external).packages/spec/src/contracts/segmenter-service.ts:ISegmenterService(keywordTerms(query, { purpose, entries }),status()),SEGMENTER_SERVICE = 'segmenter', the purpose types (knowledge|record_searchper call, plusbothon an entry), entries (word|stop_word,enabled), and the status shape (engine:dictionary|sliding_window;fallbackReason:not_installed|load_failed). Types and constants only. The slot is registered inServiceSlotContracts(packages/spec/src/contracts/core-service-contracts.ts). It is not aCoreServiceNamemember.packages/services/service-segmenter(new,@objectstack/service-segmenter):SegmenterServicePluginregisters the service on every path. The flow for one question:wordentries are matched by longest match over the whole normalised question, in any script, with an edge guard (soOA审批and5G套餐are protected, and nothing matches insideOAuth). A word that holds a separator other than a single space (R&D, 《员工手册》, 办法(试行)) is not found, because the question is split at its separators first; the contract and README say so, and a test pins it. Matched words are kept whole. Entries are read afresh on every call; absent and empty mean the same.cut, HMM off), shared by every service instance. Stop words are dropped as whole tokens after the cut. Where two or more single characters stand side by side, they are joined into overlapping two-character words.Intl.Segmenter.@objectstack/coresliding windows unchanged: English, figures, codes, and runs holding kana or Hangul.record_searchis refused withNOT_IMPLEMENTED/501.status()reports the same. Nothing about "service absent" is cached: the contract tells consumers to resolve the slot at use time.packages/core/src/keyword-terms.ts, moved verbatim fromknowledge-turso/src/sql.tswithMAX_KEYWORD_TERMSandKEYWORD_SEPARATORS.UNSEGMENTED_RUNis now exported too, so the service splits runs with the same class. The service falls back to this copy, and a consumer with nosegmenterslot uses it too.@node-rs/jieba@2.0.4is an optionalDependency, namedexternalin the package's owntsup.config.ts. The built ESM and CJS bundles import it and do not inline it (checked under plain Node, both formats).Nothing at runtime calls the segmenter yet. No composition mounts the plugin, and both knowledge adapters still cut their own terms. The adapters read the slot in step 2 of the card. Until then, the windowing is a third copy:
@objectstack/coreplus the two adapters'sql.ts. Step 2 removes the adapters' two. Bothsql.tsfiles are held by in-flight PRs, so this PR does not touch them.Landing points beyond the claimed surface, each required by a gate:
.changeset/config.json: the new public package joins thefixedgroup (check:changeset-fixed).packages/spec/llms.txt: the package-count heading 77 → 78 (check:llms-txt).packages/spec/api-surface/contracts.jsonandexport-origins/contracts.json: regenerated (check:generated --fix).Tests
packages/core/src/keyword-terms.test.ts: the adapters'keywordTermscases, ported unchanged, including the separator-class literal pin.service-segmenter/src/segmenter-service.test.ts:keywordTerms(English, codes, kana, Hangul, on both engines);Intl.Segmenter;enabled: false, last-wins, purpose filter);NOT_IMPLEMENTED/501 forrecord_search;isNotInstalledon hand-built errors in Node's not-found shapes, ESM and CJS;pump…valvestays two terms);R&D, 《员工手册》) is not found whole, against a control without the marks.service-segmenter/src/fixture.test.ts: the synthetic fixture (12 policy clauses, 16 colloquial questions, deterministic, keyword-only, substring ranker):segmenter-service-plugin.test.ts: registration, the two fallback logs told apart, and aLiteKernelboot.core-service-contracts.test.ts: thesegmenterslot types through the keyed lookup, and the exact non-core set gains it.Fixture readings (16 questions):
cutcutForSearchcutis picked. It tiescutForSearchon both hit@1 and hit@3 and sends fewer terms.Acceptance notes
enabled: falseentry on 年假 has no effect (pinned). Overriding one to a stop word does work. This narrows the card's §3 ("A record can disable or override" a platform default). It is carried to PR 2 (the 检索词条 object) and step 2 to be settled; nothing calls the service yet.check:llms-txtpackage count is the kind of volatile count AGENTS.md says to delete rather than sync. Deleting it means editing that gate, so this PR bumps the count, as the gate's own remedy prescribes, and leaves the rule question open.Clause-②: yes): PASS atc1c202d2(record on this PR), with three should-fix items closed in the rework; the delta record names the current head.Verification
Read first (riskiest first):
packages/services/service-segmenter/src/segmenter-service.ts:keywordTermsandhanRun(run dispatch, the residual handed to core, the fallback path).packages/spec/src/contracts/segmenter-service.ts: the contract shape under review.packages/services/service-segmenter/src/jieba-loader.ts: the not-installed / load-failed split and the.jsdict subpath (plain Node ESM does no extension search).Two-minute check:
pnpm --filter @objectstack/service-segmenter test. You should see 3 files and 28 tests pass, and a printed linehit@3 {"windows":10,"cut":16,"cutForSearch":16}.The local readings below were taken on head
75fcae78(rework round 1;origin/mainnot merged, no conflict). Round 2 (9556620f) adds the separator sentence and its test only; CI on9556620f: 63 success, 11 skipped.Local gates and tests
node scripts/pm/dispatch-gates.mjs --rangives: 112 derived, 112 run, 0 NOT-MEASURED (a derived zero: every command recorded an exit code, all 0).pnpm --filter @objectstack/core test: 159 files, 3823 tests passed.pnpm --filter @objectstack/service-segmenter test: 3 files, 28 tests passed.core-service-contracts.test.ts: 11 tests passed.typecheckpassed for core, spec and service-segmenter.pnpm --filter @objectstack/spec check:generated: all 14 generated artifacts are up to date.!in the title, no(narrowing)arm).Generated by Claude Code