Skip to content

feat(service-segmenter): a segmenter service that cuts a Chinese question into real words for the keyword leg - #38744

Merged
objectstack-fleet[bot] merged 10 commits into
mainfrom
claude/issue-38710-analyzer-jieba
Dec 1, 2026
Merged

objectstack-fleet[bot] merged 10 commits into
mainfrom
claude/issue-38710-analyzer-jieba

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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, contract segmenter-service.ts, registered in ServiceSlotContracts only), 7272452774, 7272455751 and 7272462484, plus 7272241375 item 1 (@node-rs/jieba, HMM off, external).

  • Contract packages/spec/src/contracts/segmenter-service.ts: ISegmenterService (keywordTerms(query, { purpose, entries }), status()), SEGMENTER_SERVICE = 'segmenter', the purpose types (knowledge | record_search per call, plus both on 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 in ServiceSlotContracts (packages/spec/src/contracts/core-service-contracts.ts). It is not a CoreServiceName member.
  • Service packages/services/service-segmenter (new, @objectstack/service-segmenter): SegmenterServicePlugin registers the service on every path. The flow for one question:
    • NFKC normalisation first.
    • The caller's supplied word entries are matched by longest match over the whole normalised question, in any script, with an edge guard (so OA审批 and 5G套餐 are protected, and nothing matches inside OAuth). 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.
    • The platform's supplementary words are loaded into jieba's own dictionary, not matched ahead of it.
    • The rest of a pure Han run is cut by one jieba instance per process and cut mode (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.
    • Thai, Lao, Khmer and Myanmar runs are cut by Intl.Segmenter.
    • Everything else goes through the @objectstack/core sliding windows unchanged: English, figures, codes, and runs holding kana or Hangul.
    • record_search is refused with NOT_IMPLEMENTED/501.
    • The boot log tells "not installed" (warn, install hint) apart from "failed to load" (warn, the error), and status() reports the same. Nothing about "service absent" is cached: the contract tells consumers to resolve the slot at use time.
  • One sliding-window copy in packages/core/src/keyword-terms.ts, moved verbatim from knowledge-turso/src/sql.ts with MAX_KEYWORD_TERMS and KEYWORD_SEPARATORS. UNSEGMENTED_RUN is now exported too, so the service splits runs with the same class. The service falls back to this copy, and a consumer with no segmenter slot uses it too.
  • @node-rs/jieba@2.0.4 is an optionalDependency, named external in the package's own tsup.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/core plus the two adapters' sql.ts. Step 2 removes the adapters' two. Both sql.ts files 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 the fixed group (check:changeset-fixed).
  • packages/spec/llms.txt: the package-count heading 77 → 78 (check:llms-txt).
  • packages/spec/api-surface/contracts.json and export-origins/contracts.json: regenerated (check:generated --fix).

Tests

  • packages/core/src/keyword-terms.test.ts: the adapters' keywordTerms cases, ported unchanged, including the separator-class literal pin.
  • service-segmenter/src/segmenter-service.test.ts:
    • dictionary cuts and stop words;
    • platform words kept whole;
    • single-character joining;
    • NFKC;
    • non-Han equality with core keywordTerms (English, codes, kana, Hangul, on both engines);
    • kana-holding runs left to the windows;
    • Thai via Intl.Segmenter;
    • entry layering (supplied word and stop word, enabled: false, last-wins, purpose filter);
    • a supplied word survives a simulated jieba load failure;
    • the fallback equals the windows when no layered word is present;
    • NOT_IMPLEMENTED/501 for record_search;
    • isNotInstalled on hand-built errors in Node's not-found shapes, ESM and CJS;
    • one jieba per process: two services share one segmenter;
    • the three cross-boundary sentences 去年假期多少天 → 去年, 假期; 设备归还是否需要审批 → 设备, 归还, 审批; 办公场所以外 → 办公, 场所, 以外;
    • supplied words in any script (OA审批, 5G套餐, a kana word, a spaced phrase) and no match inside OAuth;
    • an entries array changed in place between calls is read afresh;
    • NFKC runs between separators (pump…valve stays two terms);
    • a supplied word holding a separator (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):
    • 年假, 脱密, 应急采购 and 超预算 come out whole;
    • no three-character term is a window (every Han term of three or more is a jieba or platform word);
    • hit@3 rises over the windows;
    • the jieba cut is pinned as the measured pick.
  • segmenter-service-plugin.test.ts: registration, the two fallback logs told apart, and a LiteKernel boot.
  • core-service-contracts.test.ts: the segmenter slot types through the keyed lookup, and the exact non-core set gains it.

Fixture readings (16 questions):

Cut hit@1 hit@3 Terms per question
Sliding windows (today) 10 10 16
jieba cut 16 16 4.8
jieba cutForSearch 16 16 5.5

cut is picked. It ties cutForSearch on both hit@1 and hit@3 and sends fewer terms.

Acceptance notes

  • The fixture is optimistic by construction. The platform word list holds the fixture's key words, as the card's own supplementary dictionary held its 20 questions'. The BrightRule question set and the hybrid-against-vector acceptance stay on the card and 知识库混合检索在中文口语问题上比只用向量更差:关键词一路的滑动窗口切词 + 等权 RRF #38671.
  • Choices made inside the rulings, recorded for the contract review:
    • "Other unspaced scripts" is read as Thai, Lao, Khmer and Myanmar. A run holding kana or Hangul, including its Han characters (Japanese text), keeps today's windows, per card §2 and the maintainer's 07:47Z deferral of Japanese and Korean.
    • Three or more adjacent single characters join as overlapping pairs.
    • Segmented words come before figures and codes in the answer. This only matters at the 16-term cap.
    • On the fallback, supplied words and stop words still apply; the stop-word longest-match pass runs only here. Platform words are not kept whole on the fallback (fixture fallback hit@3 14 → 13 after the rework, seat L1 probe). With neither a supplied word nor a stop word in the question, the answer equals the windows byte for byte.
  • For E1 and step 2 (from the seat's L1 and L2 reviews):
    • Platform words cannot be disabled by an administrator record. They live in jieba's dictionary, so an enabled: false entry 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.
    • Administrators importing policy titles (ruling 7272436453 item 2) should enter them without 《》 or () marks; a word holding a separator is not found.
    • A supplied word still matches across a word boundary: entry 年假 on 去年假期多少天 gives 年假. This is the longest-match protection the ruling asks for; measure it at E1.
    • A multi-character supplied stop word that jieba cuts into pieces is not dropped.
    • A jieba token that contains a stop word survives whole (设备坏了,应急采购怎么弄 → 设备, 应急采购, 怎么弄).
  • The check:llms-txt package 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.
  • jieba's process memory (+~53 MB measured on the card) is paid only where the plugin is mounted. No composition mounts it in this PR.
  • L2 contract review (Clause-②: yes): PASS at c1c202d2 (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):

  1. packages/services/service-segmenter/src/segmenter-service.ts: keywordTerms and hanRun (run dispatch, the residual handed to core, the fallback path).
  2. packages/spec/src/contracts/segmenter-service.ts: the contract shape under review.
  3. packages/services/service-segmenter/src/jieba-loader.ts: the not-installed / load-failed split and the .js dict 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 line hit@3 {"windows":10,"cut":16,"cutForSearch":16}.

The local readings below were taken on head 75fcae78 (rework round 1; origin/main not merged, no conflict). Round 2 (9556620f) adds the separator sentence and its test only; CI on 9556620f: 63 success, 11 skipped.

Local gates and tests
  • node scripts/pm/dispatch-gates.mjs --ran gives: 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.
  • typecheck passed for core, spec and service-segmenter.
  • pnpm --filter @objectstack/spec check:generated: all 14 generated artifacts are up to date.
  • Two ablations went red and were restored:
    • Dropping the single-character join reds 2 pins.
    • Dropping fallback word protection reds the "survives jieba load failure" pin.
    • Restoring the stop-word pre-pass before jieba reds the whole-word pin.
    • Dropping the per-mode segmenter cache reds the one-jieba pin.
  • Dogfood: not owed (no ! in the title, no (narrowing) arm).

Generated by Claude Code

@github-actions github-actions Bot added size/xl dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/core, @objectstack/service-segmenter, @objectstack/spec, touching 65 documentable anchor(s). ⚠️ 12 changed file(s) yielded no anchor (packages/core/src/index.ts, packages/services/service-segmenter/LICENSE, packages/services/service-segmenter/README.md, …), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

3 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/kernel/services-checklist.mdx (via providesServices (symbol, a field of class SegmenterServicePlugin))
  • content/docs/plugins/anatomy.mdx (via providesServices (symbol, a field of class SegmenterServicePlugin))
  • content/docs/protocol/kernel/lifecycle.mdx (via providesServices (symbol, a field of class SegmenterServicePlugin))
What this run could not see
  • 12 changed file(s) yielded no anchor (packages/core/src/index.ts, packages/services/service-segmenter/LICENSE, packages/services/service-segmenter/README.md, …) — pages documenting those are invisible to this run
  • 22 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 189 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 7625001f9b7918edb08d6413bc24026d692f6e94 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 0ddc18794a2ecf1a70b615c01863303abae4ef01 — the merge of head ff965718b660afca4bd19665286ff69d28ffa364 into base 7625001f9b7918edb08d6413bc24026d692f6e94, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# 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

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 7625001f9b7918edb08d6413bc24026d692f6e94 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

Contract-review-claim: session_01RKKVngFfp7HBk6JUUr5vfN · head c1c202d · 2026-11-30T12:36Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: c1c202d2c178fca557cf2044e68da37b8c268521
Local-runs: none
Scope: packages/spec/src/contracts/segmenter-service.ts, packages/spec/src/contracts/core-service-contracts.ts, packages/spec/src/contracts/index.ts + packages/services/service-segmenter/src/**, packages/core/src/keyword-terms.ts
Security-touching: no
Rule-change-verified: none

Below, "contract" is packages/spec/src/contracts/segmenter-service.ts and "service" is packages/services/service-segmenter/src/segmenter-service.ts. No must-fix; three should-fix to close before landing.

① Derived judgments

  • Clause-②: yes is correct. The public surface widens: 11 new @objectstack/spec/contracts exports, a new ServiceSlotContracts key, 4 new @objectstack/core exports and a new package. Nothing is narrowed, so no arm is owed.
  • Metadata-protocol: none is correct. The spec diff is TypeScript interfaces and two constants under contracts/ plus generated lists. No Zod schema, authorable key, value or metadata type moves; the 检索词条 object is PR 2.
  • The slot is registered as ruled (7272436453 item 1). segmenter sits inside ServiceSlotContracts (core-service-contracts.ts:133, :225-232). system/core-services.zod.ts is not in the diff. core-service-contracts.test.ts:156 and :167 pin it in the non-core set and assert it is not a CoreServiceName.
  • Generated files match. api-surface/contracts.json and export-origins/contracts.json each gain exactly the contract's 11 exports. Every check-run that ran on this head concluded success (the opt-in and queue runs were skipped).
  • The core copy is a verbatim move. The keywordTerms body in packages/core/src/keyword-terms.ts:66-97 equals knowledge-turso/src/sql.ts on origin/main line for line; only UNSEGMENTED_RUN gains export.

② Semver level

patch on spec, core and service-segmenter is the level AGENTS.md prescribes (Post-Task Checklist step 3: none takes patch, and a non-protocol widening ships patch). Both declaration lines open their lines in the changeset body. The new package joins the fixed group at 19.0.0-next.2, the group's version. No finding.

③ Boundary flags

  • Security: no hunk teaches permission, credential or sharing behaviour. Note for step 2: SegmenterStatus.error carries the raw loader message, which may hold install paths, so surface it only behind the administrator door.
  • record_search refused with NOT_IMPLEMENTED/501: acceptable reservation, not declared ≠ enforced.
    • It is ruled: 「接口带"用途"参数,本期只实现知识检索」.
    • The jsdoc says reserved (contract :23-31).
    • The refusal is loud and carries a stable code (service :132, :63-71), the pattern api/batch.zod.ts:77 already uses.
    • status().purposes says what is served, and a test pins the refusal.
    • It is a call parameter, not an authorable metadata value.
  • Business logic in spec: none. The contract holds types plus DEFAULT_SEGMENTER_PURPOSE (:34) and SEGMENTER_SERVICE (:109).
  • SQL push-down: the diff reads no data. No finding.
  • Dev open questions:
    1. Script dispatch: A accepted. Only pure Han runs go to jieba; kana and Hangul runs keep the windows, per card §2 and the 07:47Z deferral.
    2. Overlapping pairs: A accepted; re-measure at E1.
    3. llms.txt count: the bump is accepted here. Changing the gate is escalated to the seat; it is not a contract matter.
  • Deviations: the files beyond the claimed surface are gate-required config and generated output. The third window copy until step 2 is as the claim amendment (7272545883) records. Accepted.

④ Design judgment

The shape fits the rulings and the step-2 consumers.

  • Both step-2 routes stay open. keywordTerms(query, { purpose, entries }) depends only on its inputs, and entries are plain data with no storage. The entries can ride AdapterSearchOptions, or the service can cut and pass terms. This PR adds no adapter member, so K8 rules 1, 2 and 5 stay step 2's.
  • The visibility and caching rulings are met. status() answers 「当前在用哪种切法要能看到」, and resolve-at-use (contract :8-11) answers 「不要把服务不存在缓存下来」.
  • Naming follows the i18n-service precedent, departing only where ruled (not a CoreServiceName).
  • The fallback behaves as ruled. There is one core copy, and supplied words survive a jieba load failure (service :187-195, pinned in segmenter-service.test.ts).

Findings:

  1. should-fix — word over-claims.
    • Claim: contract :40 says a word entry "is kept whole, never cut".
    • Enforcement: the longest match runs only inside a pure Han run (service :149-150, :186, :246-273).
    • Consequence: an entry such as OA审批, A类合同 or 5G套餐, any kana or Hangul word, or a spaced phrase is silently never protected. A mixed-script stop_word never matches either (:156 compares whole emitted terms).
    • Fix: narrow the jsdoc and README to "within a run of Han characters", or match layered words over the normalised text before run dispatch (Prime Directive 10). Pin whichever with a test. Administrators will enter such terms in PR 2.
  2. should-fix — entries hides an immutability clause. The service caches the layered lexicon by array identity (:108, :169-178); contract :63-67 does not say so. A step-2 cache that refreshes its array in place gets stale terms for the life of the process, against card §4 「改了立即生效」. Fix: state that the array is read as an immutable snapshot (pass a new array on change), or drop the identity cache. Also state that absent and empty mean the same.
  3. should-fix — stop words are removed by substring on the dictionary engine.
    • Mechanism: stop words of two or more characters are cut out by longest match before jieba runs (service :255, :268), across word boundaries.
    • Examples, with the platform list (platform-words.ts:40-46): 「设备归还是否需要审批」 yields only 审批 (归还 lost to 还是); 「办公场所以外」 loses 场所 and 以外 (所以).
    • The contract says the term is dropped (:41), and the ruling asks for longest-match protection for the administrator's words only.
    • Fix: token equality at :209 already drops stop words after the cut, so keep the stop-word pre-pass on the sliding-window fallback only.
  4. nit — NFKC can join two terms. … is a separator today (keyword-terms.ts:47), but NFKC folds it to ..., which stays inside a term: pump…valve becomes one term. "Exactly as today" (service :95-97) holds only for the normalised text.
  5. nit — the cap and fallback are defined in core. Contract :10-15 names MAX_KEYWORD_TERMS and keywordTerms, which live in @objectstack/core, downstream of spec; the number 16 is not in the contract. Accepted.
  6. nit — status presence rules are prose. The rules for fallbackReason, error and segmenter (contract :86-96) could be a union discriminated on engine. Accepted.
  7. nit — both stops reading true at a third purpose (contract :37). It matches the ruled 用途 values. Accepted.

Findings 1–3 each change jsdoc or one code path and break nothing; this reviewer reads the delta.

Implemented-by: claude/issue-38710-analyzer-jieba
Reviewed-by: session_01RKKVngFfp7HBk6JUUr5vfN

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

2026-11-30T12:43Z · L1 verdict: REWORK (round 1 of at most 2) · head c1c202d2 · card #38710 step 1, PR 1 of 2.

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

  • M1 — one jieba per process, not per service. jieba-loader.ts:69-85 builds a new Jieba.withDict(...) on every loader call; probe: two loads return different objects.
    • Ruling 7272436453 says 「jieba 只加载一个实例:进程级、只读」.
    • Fix: keep one load promise per cut mode at module scope, and pin that two createSegmenterService() calls share one segmenter.
    • Make the changeset (line 12) and the class doc (segmenter-service.ts:77-79) true.

Should-fix (this round)

  • S1 — the pre-jieba longest-match pass breaks real words (L1 Implement ObjectStack protocol specification with Zod schemas and TypeScript interfaces #3 + L2 Implement ObjectStack protocol specification with Zod schemas and TypeScript interfaces #3).
    • Examples: 「去年假期多少天」 → ["年假"]; 「设备归还是否需要审批」 → 审批 only (还是 eats 归还); 「办公场所以外」 loses 场所 and 以外.
    • The ruling asks longest-match protection for the administrator's words only. So:
      • (a) the platform supplementary words go into jieba's own dictionary;
      • (b) stop words are dropped by token equality after the cut (:209 already does this), and the stop-word pre-pass stays on the sliding-window fallback only;
      • (c) the pre-pass protects supplied word entries only.
    • Pin the three sentences above. The residual cross-boundary risk for administrator words goes in ## Acceptance notes for E1.
  • S2 — the word contract over-claims (L2 Add metamodel interfaces for ObjectQL/ObjectUI contract #1). The contract (:40) says a word "is kept whole, never cut", but matching runs only inside pure Han runs: OA审批, 5G套餐 and kana or Hangul entries are never protected. Either match supplied words on the normalised text before run dispatch, or narrow the jsdoc and README to "within a run of Han characters". Pin whichever you choose.
  • S3 — entries identity cache (L2 ✨ Set up Copilot instructions #2). :108 and :169-178 cache by array identity, which a step-2 in-place refresh would break (「改了立即生效」). Either drop the identity cache or have the contract say the array is an immutable snapshot (pass a new array on change). Also state that absent and empty mean the same.
  • S4 — restore the \uXXXX escapes in packages/core/src/keyword-terms.ts:35,47, its test :70 and segmenter-service.ts:32. The move has to be byte-verbatim as the PR body says, and the separator-class pin has to compare against the escaped literal again, not against the core copy itself.
  • S5 — the vacuous test at segmenter-service.test.ts:48-49: fragments excludes terms, so the assertion cannot fail. Assert against the windows directly.

Nits (carry if cheap, else list in acceptance notes)

  • List core/src/keyword-terms.test.ts among the files.
  • The PR body's "real not-found error shapes" are hand-built Errors; say so.
  • The plugin version = '1.0.0' vs the package's 19.0.0-next.2.
  • NFKC folds … into ..., which joins two terms (L2 Add Changesets and GitHub Actions automation #4); note it.

The dev's open questions 1–3 are accepted as answered (A, A, A). The llms.txt count gate goes to the seat as a separate matter, not this PR. After the push: post an updated os-dev-report on #38710, keep the PR draft, and do not knock any review seat.

…ole, supplied words in any script

Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 75fcae78fcc4c1b7890b4ad73770bf4fbe8574fb
Local-runs: none
Scope: packages/spec/src/contracts/segmenter-service.ts, packages/spec/src/contracts/core-service-contracts.ts, packages/spec/src/contracts/index.ts + packages/services/service-segmenter/src/**, packages/core/src/keyword-terms.ts
Security-touching: no
Rule-change-verified: none

"Contract" is packages/spec/src/contracts/segmenter-service.ts; "service" is packages/services/service-segmenter/src/segmenter-service.ts. Delta read of c1c202d2..75fcae78 (one commit, 11 files). No must-fix; one new should-fix.

Delta from c1c202d

  • S1(b), stop words by substring: closed.
    • On the dictionary engine, stop words are dropped only by token equality after the cut (service :259-268).
    • The longest-match stop pass runs on the sliding-window fallback only (:249-251).
    • Contract :48-51 now says "compared whole", and names the fallback exception.
    • Pinned: 「设备归还是否需要审批」 gives 设备, 归还, 审批; 「办公场所以外」 gives 办公, 场所, 以外.
  • S3, identity cache: closed.
    • The WeakMap is gone; the lexicon is built per call (service :200-201).
    • Contract :75-80 states entries are read afresh, in-place changes included, and that absent and empty mean the same.
    • Pinned with one array changed in place across three calls.
  • S2, word over-claims: partly closed.
    • Closed for what was raised: supplied words are taken out of the whole normalised question before run dispatch, in any script (service :119-143, :204-208), with the edge rule of contract :44-47 at :128-129.
    • Pinned: OA审批, 5G套餐, a kana word, a spaced phrase, and the OAuth non-match.
    • A residue remains; see finding 1.

① Derived judgments

Unchanged. Under packages/spec/src the delta touches only the contract, and only its jsdoc: no export, type or slot moves, so the generated lists stand. Clause-②: yes and Metadata-protocol: none remain correct. Check-runs on this head: 63 success, 11 skipped. The core constants now equal origin/main's knowledge-turso copy byte for byte, apart from the export on UNSEGMENTED_RUN.

② Semver level

Unchanged: patch on the three packages is correct. The changeset body was reworded to match the new behaviour and keeps both declaration lines.

③ Boundary flags

  • Security, the record_search refusal, spec logic and SQL push-down: unchanged, no finding.
  • Escalated to the seat (nit for this PR): a platform word can no longer be disabled.
    • Platform words now live in jieba's dictionary, so enabled: false withdraws only a platform stop word or an earlier entry (service :76-88).
    • Contract :63-66 says so truthfully.
    • Card §3 still reads "A record can disable or override a platform default". That now holds for stop words only.
    • The dev report does not list this as a deviation. The card line needs amending or a ruling before PR 2 builds the object.

④ Design judgment

The 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 :204-208; contract :85-90). Running NFKC between separators (:205) keeps today's separators, which closes the earlier … nit.

  1. should-fix — a word holding a separator is never found.
    • Claim: contract :42-44 says the term is kept whole "wherever the question spells it".
    • Enforcement: the question is split at KEYWORD_SEPARATORS before matching (service :205), while the key keeps its separators (:43).
    • Consequence: R&D, Q&A, 「差旅费管理办法(试行)」 and 「《员工手册》」 silently match nothing. Ruling 7272436453 item 2 sends policy titles in through administrator entries, and titles carry such marks.
    • Fix: one sentence in the contract and README stating that a term holding a separator other than a single space is not found. Matching the key the same way would emit a term with a space that the stored text does not hold.
    • No test pins either behaviour.
  2. nit — carried from the first record, accepted: the cap is defined in core, the status presence rules are prose, and both stops reading true at a third purpose.

Implemented-by: claude/issue-38710-analyzer-jieba
Reviewed-by: session_01RKKVngFfp7HBk6JUUr5vfN

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

2026-11-30T16:03Z · L1 verdict: REWORK, round 2 of 2 (final) · head 75fcae78 · card #38710 step 1, PR 1 of 2.

The seat's delta read finds M1, S1 to S5 and the … nit fixed at 75fcae78, inside the declared files. CI on this head: 63 success, 11 skipped. The L2 delta record above is PASS with one new should-fix, and that is this round's only code item.

Should-fix (this round)

  • R2-1: a supplied word holding a separator is never found.
    • Contract segmenter-service.ts:42-44 says the word is kept whole "wherever the question spells it".
    • But the service splits the question at KEYWORD_SEPARATORS before matching (service :205), while the key keeps its separators (:43).
    • So R&D, Q&A, 「差旅费管理办法(试行)」 and 「《员工手册》」 silently match nothing. Ruling 7272436453 item 2 sends policy titles in through administrator entries, and titles carry such marks.
    • Fix, as L2 recommends:
      • add one sentence to the contract jsdoc and to the README: a term that holds a separator other than a single space is not found;
      • add one test that pins this, e.g. R&D and 「《员工手册》」 as supplied words produce no whole-term match.
    • ⛔ Do not change the matching. Matching the key the same way would emit a term with a space that the stored text does not hold.

Not for the dev

  • The seat refreshes the PR body after this round: the stale sentences, the new pins and the E1 acceptance notes.
  • The platform-word disable limitation (contract :63-66 versus card §3) goes to the maintainer before PR 2. Leave the code as it is.

After the push: post an updated os-dev-report on #38710. Keep the PR draft. Do not knock any review seat.

…is not found, and a test pins it

Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 9556620f39a3db21ec9373242bab795bb6b40ef7
Local-runs: none
Scope: packages/spec/src/contracts/segmenter-service.ts, packages/spec/src/contracts/core-service-contracts.ts, packages/spec/src/contracts/index.ts + packages/services/service-segmenter/src/**, packages/core/src/keyword-terms.ts
Security-touching: no
Rule-change-verified: none

"Contract" is packages/spec/src/contracts/segmenter-service.ts; "service" is packages/services/service-segmenter/src/segmenter-service.ts. Delta read of 75fcae78..9556620f (one commit, three files). Finding 1 is closed; only nits remain, so this is the final round.

Delta from 75fcae7

  • Finding 1, a word holding a separator: closed.
    • Contract :47-49 now says such a term "is not found", with R&D, 《员工手册》 and 办法(试行) as examples. That matches the code: the question is split at KEYWORD_SEPARATORS before the word pass (service :205), and the key keeps its separators (:43).
    • The README rule 2 says the same.
    • The new test (segmenter-service.test.ts:151-166) asserts R&D is absent and the answer equals the no-entries answer. That pin fails if matching is ever added, whatever jieba's dictionary holds.
  • nit — the control is weaker than it reads. The control (員工手册 without its marks is found whole) and the 《员工手册》 half only discriminate if jieba's own dictionary splits 员工手册. I could not check that read-only, because jieba is not installed in this checkout. A line asserting the term is absent without the entry would settle it, as the 明规条款 test already does. Accepted.
  • nit — one rare exception to "is not found". NFKC runs after the split, so a compatibility character can fold into a separator-holding string: an entry (株) is found where the question writes ㈱. Accepted.
  • nit — "separator" is not defined in the contract. The class lives in KEYWORD_SEPARATORS in @objectstack/core. Accepted, with the earlier nit about the cap.

① Derived judgments

Unchanged. Under packages/spec/src the delta is three jsdoc lines in the contract: no export, type or slot moves, so the generated lists stand. Clause-②: yes and Metadata-protocol: none remain correct. Check-runs on this head: 63 success, 11 skipped.

② Semver level

Unchanged: patch on the three packages is correct. The changeset is untouched.

③ Boundary flags

  • Security, the record_search refusal, spec logic and SQL push-down: unchanged, no finding.
  • Still open with the seat, not this PR: card §3 says a record can "disable or override a platform default", but a platform word can no longer be disabled (contract :65-68). The card line needs amending or a ruling before PR 2.

④ Design judgment

The 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: claude/issue-38710-analyzer-jieba
Reviewed-by: session_01RKKVngFfp7HBk6JUUr5vfN

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

2026-12-01T01:45Z · L1 verdict: ACCEPT · head 9556620f39a3db21ec9373242bab795bb6b40ef7 · card #38710 step 1, PR 1 of 2.

席位核对

Check Result
Form Draft against main. First line Refs #38710 (step 1, PR 1 of 2), no closing keyword. Clause-②: yes and Metadata-protocol: none lines in both the body and the changeset. No Skills-docs: line owed.
Premise measured keywordTerms() duplicated at turso sql.ts:432 and pgvector sql.ts:184 on origin/main. The core copy's regexes and separator pin are byte-identical to the originals (seat delta probe).
Gate check-runs Head 9556620f: 63 success, 11 skipped, 0 failing. check-governed-merges --pr 38744: NOT governed, 1891 changed lines.
Rulings 7272436453, 7272452774, 7272455751, 7272462484, 7272241375 item 1, 7272383831.
Contract only in ServiceSlotContracts, not CoreServiceName. NFKC. Han runs → jieba (HMM off, external, one instance per process and mode). Other unspaced scripts → Intl.Segmenter. Supplied words longest-matched before jieba, and they survive a jieba load failure. not_installed and load_failed kept apart. Slot absence is not cached. record_search → 501.
L2 contract review PASS at c1c202d2, 75fcae78 and 9556620f (records above, Served-tier: CONTRACT_REVIEW_TIER). Final round; only nits remain.
Rework Round 1 (7278858876): M1 and S1–S5 fixed at 75fcae78.
Round 2 (7284066295): the separator sentence and its pin at 9556620f; seat read the delta.
Pins test the risk Spot-checked by seat probe:
• the four words come out whole;
• 去年假期多少天 → 去年, 假期; 设备归还是否需要审批 → 设备, 归还, 审批; 办公场所以外 → 办公, 场所, 以外;
• two services share one jieba;
• hit@3 is 16 vs 10 for the windows (platform words off: still 16);
• ablations went red then green, as reported.
Accepted deviations All gate-required:
• .changeset/config.json (check:changeset-fixed);
• packages/spec/llms.txt (check:llms-txt count 77→78);
• generated api-surface / export-origins;
• core-service-contracts.test.ts beside the slot file;
• core/src/keyword-terms.test.ts beside its source;
• the plugin version follows the service-i18n precedent.
Out of scope, where it goes • Platform words cannot be disabled by an administrator record, against the card's §3: put to the maintainer before PR 2. Recorded in ## Acceptance notes.
• The check:llms-txt volatile count against the AGENTS.md rule: seat item, not this PR.
• E1 notes (cross-boundary supplied words, split stop words, stop-word-holding tokens, separator-holding titles) are in ## Acceptance notes.
Landing clause landing-k: K = 0. The branch is 45 behind main, and #38778 and #38720 touched the merge=os-regen files this PR regenerates (packages/spec/api-surface/contracts.json, packages/spec/export-origins/contracts.json). So rule A applies before arming: the dev runs bash scripts/pm/os-regen-merge.sh, pushes, and the seat lands that head once CI is green. A clean main-merge keeps this ACCEPT. Not governed: ordinary queue landing by this seat.

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>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

Regen-provenance: 7297824190 · 9556620f39a3db21ec9373242bab795bb6b40ef7 → ff965718b660afca4bd19665286ff69d28ffa364 · git diff of the PR's own changes (merge-base → head, minus packages/spec/api-surface/**, packages/spec/export-origins/** and pnpm-lock.yaml), compared before and after → (empty)

2026-12-01T03:40Z · The head moved by one clean merge of main (0a78bfc9) and one regeneration commit (ff965718), per this PR's ACCEPT (7297870669) landing clause.

  • The PR's own changed lines are identical at both heads; the patch-ids differ only by context offsets.
  • The regenerated files carry the same additions as before: contracts.json +11 in each of the two generated directories, pnpm-lock.yaml +165.
  • Both sides survived the merge: each regenerated contracts.json holds the segmenter exports (SEGMENTER_SERVICE, ISegmenterService) and main's IReranker / RERANKER_SERVICE from feat(spec): IReranker contract and RERANKER_SERVICE token #38778.
  • Branch position: behind 0, ahead 10.

The L2 PASS record 7297824190 continues on this head through the regeneration arm. The ACCEPT stands, and landing waits for CI on ff965718.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack@baozhoutao · baozhoutao · session_01RKKVngFfp7HBk6JUUr5vfN

2026-12-01T04:11Z · Landing · head ff965718b660afca4bd19665286ff69d28ffa364 · ACCEPT 7297870669 · L2 PASS 7297824190, carried to this head by 7299955205

Reading Value
Check-runs on ff965718 63 success, 11 skipped, 0 failing or pending; mergeable_state clean, behind main 0
check-governed-merges.mjs --pr 38744 NOT governed (0 of 28 paths), 1891 changed lines ≤ 3000: ordinary queue landing by the seat

State change: pr_ready + automerge_enable (squash) in this stroke. The PR carries Refs #38710 (step 1, PR 1 of 2), so #38710 stays open for PR 2 and step 2. On merge, the seat releases the PR-1 part of the claim and files E0 under topic #38711.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review December 1, 2026 04:12
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit d7d4605 Dec 1, 2026
75 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-38710-analyzer-jieba branch December 1, 2026 04:41
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants