Skip to content

feat(service-knowledge): under the markdown split, a section that fits is one passage - #38439

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/issue-38351-markdown-fitting-section
Nov 29, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/issue-38351-markdown-fitting-section

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread
Fixes #38351
Clause-②: no
Metadata-protocol: semantic
Skills-docs: follow-up #38442

维护者速读

  • 用户能看到什么变化:按标题切分的知识源里,一个放得下一段的小节(一条条文、一节说明、一张表格连同它的注释)现在整节一段,检索命中的是完整的一条,不再是半条;放不下的小节切法与以前完全一样。
  • 为什么做:知识切分专题第一阶段,按您对“放得下的小节整节一段做成默认”的裁决(选 A)实现,作者不用再手动调合并阈值。
  • 出错会怎样:只影响按标题切分的知识源,这些知识源本来就要因上一个“标题丢失”修复重建一次,这次改动搭同一次重建,不再多建;切分功能仍在预发布期,撤回只需回退本次改动并再重建一次。
  • 要你做的:无。

What changes

  • Splitter (packages/services/service-knowledge/src/split/splitter.ts, withPrefix): under split.strategy: 'markdown', after the heading-path prefix is selected exactly as before (full path, else the innermost heading, else none, by the existing half-the-bounds rule), a section whose emitted passage (prefix plus trimmed text) fits the bounds is returned as that one passage, whatever minChars is. Only a section that does not fit reaches splitRecursive, unchanged, so its passages are byte-identical to before. The path-less branch (text before the first heading) takes the same rule. Body-less headings and the carry logic are untouched. recursive and whole are untouched.
  • Which "fits" (Zone 2 hypothesis 3). Fitting is judged on the passage as emitted, fits(lead + body.trim(), b), not on fits(body, left). estimateTokens rounds up per text and the prefix ends in whitespace, so the two raw sums add and the estimate of the passage is at most the prefix's estimate plus the body's: the emitted check accepts everything the split check accepts, plus the sections that are over the budget left after the prefix only by one rounding token. Characters agree, except for a heading that starts with whitespace other than a space or tab, where the emitted check is again the looser one. The emitted check is the bound the file promises for every passage, so a fitting passage can never exceed it. Pinned by a test.
  • Version. SPLIT_ALGORITHM_VERSION_BY_STRATEGY.markdown stays 2. Read at base d751790c: .changeset/38350-markdown-bodyless-headings.md is still pending, and the published @objectstack/service-knowledge@next is 19.0.0-next.2, whose changelog does not carry it. So this rides the 1 to 2 move already in this train (topic rule: one bump per train). SPLIT_ALGORITHM_VERSION and its export are not touched.
  • Prose that restates the ruling (ruling 7247322956, A): the splitter file head and splitMarkdown docblocks; the KnowledgeSplitSchema docblock for markdown, the minChars docblock and .describe, and the knowledge source form's minChars help text in packages/spec; the regenerated content/docs/references/ai/knowledge-source.mdx; content/docs/protocol/knowledge.mdx section 3.5 and content/docs/ai/knowledge-rag.mdx. No key, value, default or export changes (check:api-surface and check:authorable-surface green).
  • Form translations (patch round 1, contract review record 7249205899 M1/S1): the en bundle leaf source.split.minChars.helpText in packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts regenerated by node scripts/check-i18n-bundles.mjs --write; the hand-translated zh-CN, ja-JP and es-ES leaves re-translated to the new rule. The other seven locales serve the new English through their source-hash fallback.
  • Changeset .changeset/38351-markdown-fitting-section.md: @objectstack/service-knowledge minor, @objectstack/platform-objects minor (the bundles above), and @objectstack/spec minor, because the spec's shipped prose changes (the .describe string ships in the JSON schemas and the reference, the help text ships in the form) and AGENTS.md asks at least minor of a semantic kind on every package the diff moves.

Tests

packages/services/service-knowledge/src/__tests__/split.test.ts, new top-level describe "splitter — markdown: a section that fits is one passage", 11 cases:

  • three 250-character paragraphs under one heading at the default minChars: one passage, prefix first;
  • the same with minChars: 0: still one passage;
  • a section that does not fit: cut exactly as before (pinned output), and minChars still merges its short pieces;
  • the prefix counts: exactly maxChars with the prefix is one passage, one character more is cut;
  • a path too long for the half-bounds rule falls back to the innermost heading, and that passage fits: one passage under the innermost prefix;
  • a table and its note inside a fitting section: one passage;
  • the token budget: under maxChars but over the budget is still cut, each piece within it;
  • "fits" reads the emitted passage (the rounding case above);
  • text before the first heading that fits: one passage, no path;
  • a parent's own text before its first child: one passage when it fits;
  • recursive unchanged on the same paragraphs.

Before the fix, against the unmodified splitter, 8 of these were red (the 3 that pin unchanged behaviour were green, as they must be). The existing "every heading and line is kept" and "no passage over the budget" properties and the golden files pass unchanged (headings.markdown.golden.json is byte-identical).

Acceptance notes

Seeded synthetic corpus (the private corpus is not available; the script stays out of the PR). 400 documents per shape, article length lognormal with median 96 (about 78% under 200), 1 to 6 chapters and 1 to 8 articles each, paragraphs of 120 to 320 characters, 5% of articles carrying a table and its note at a random position, maxChars 800. A unit "fits" when its passage under its full heading path is within maxChars and the token budget. Real estimateTokens, not stubbed.

Shape Setting Passages Mixed passages Fitting units split Fitted table + note together
Units are headings default, before 6,814 0% 261 / 6,018 (4.34%) 209 / 251 (83.3%)
Units are headings default, after 6,537 0% 0 / 6,018 (0%) 251 / 251 (100%)
Units are headings minChars = maxChars (before = after) 6,342 0% 0 251 / 251
Units are bold paragraphs under chapter headings default, before 4,245 59.22% 891 / 6,208 60 / 260
Units are bold paragraphs under chapter headings default, after 3,951 (-6.9%) 59.68% (+0.46 pt) 813 / 6,208 69 / 260
Units are bold paragraphs under chapter headings minChars = maxChars (before = after) 2,486 75.22% 262 / 6,208 218 / 260
  • Topic bar met on heading-shaped input: 0% of fitting units split (bar 0.5%), 0 mixed, every fitted table with its note.
  • Non-heading shape, the reading the ruling asked for: passages -6.9%, mixed share +0.46 points. The minChars = maxChars recipe on the same input gives -41% and +16 points.
  • With a 512-token embedder (budget 409), both shapes read identically before and after: under that budget the fitting sections were already one passage.
  • Byte-identity of sections that do not fit, measured: 20,000 random Markdown documents (headings, tables, lists, Chinese and English sentence marks) under random maxChars, minChars and token limits, compared section by section between the base splitter and this one: 162,790 sections identical, 7,735 sections that were cut now one passage, 0 other differences.
  • Zone 2 hypothesis 5 (the card's 0.2% residual under the recipe): not reproduced. The synthetic corpus gives 0 there, as in the decision analysis; its headings are short, so the prefix fallback is never reached. Not explained here.
  • Not touched, by the order: docs/adr/** (no ADR note owed: no ADR text contradicts the change; ADR-0161 hands the split rules to the splitter's card and only names the maxChars/minChars keys), skills/** (the Skills-docs: follow-up), content/docs/releases/, and the markdown entry's comment in SPLIT_ALGORITHM_VERSION_BY_STRATEGY, which names only the body-less heading change. It sits next to the constant sibling review follow-ups of PR #38375 #38377 retires, so it is left to avoid a conflict, and the changeset records that version 2 carries both changes.
  • content/docs/protocol/knowledge.mdx section 3.5's markdown row said "A heading with no text of its own joins the next passage". That has not been true since the body-less heading fix, so the rewritten row states the landed behaviour.

Verification

Read first, by risk:

  1. packages/services/service-knowledge/src/split/splitter.ts, withPrefix: the two early returns (the fits(whole, b) lines) and the comment above the prefix loop.
  2. packages/spec/src/ai/knowledge-source.zod.ts: the markdown bullet and the minChars docblock and .describe (contract-tier L2 face).
  3. content/docs/protocol/knowledge.mdx section 3.5.

Two-minute check: pnpm --filter @objectstack/service-knowledge exec vitest run src/__tests__/split.test.ts -t "fits is one passage" shows 11 passing tests.

Local runs (heads 4723a4f and c645c31)

Patch round 1, head c645c319 (two commits on 4723a4fe, no splitter or test change): pnpm check:i18n red at 4723a4fe (platform-objects DRIFTED (1)), exit 0 at c645c319 (all bundles in sync); check:i18n-stale-fill exit 0; pnpm --filter @objectstack/platform-objects exec vitest run src/apps/translations: 28 files, 625 tests passed; spec check:generated: all 14 up to date; dispatch-gates --ran: 118 accounted, 115 run, 3 NOT MEASURED (prerequisite not met in this container; CI runs them); overlap-check.mjs --branch=HEAD: clean.

Round 0, all on head 4723a4fe, worktree base d751790c.

  • pnpm --filter @objectstack/service-knowledge test: Test Files 21 passed (21), Tests 737 passed (737); lock VERDICT command-exit 0.
  • pnpm --filter @objectstack/service-knowledge typecheck: tsc clean; check:test-typecheck: OK, 0 errors.
  • pnpm --filter @objectstack/spec exec vitest run src/ai/knowledge-source.metadata-form.test.ts src/ai/knowledge-source.test.ts: 2 files, 42 tests passed; pnpm --filter @objectstack/spec typecheck exit 0. The rest of the spec suite is CI's (prose-only change in spec).
  • pnpm --filter @objectstack/spec build && check:generated: 1 of 14 stale (check:docs), regenerated with --fix (the reference page above); check:authorable-surface, check:api-surface green, authorable-surface.base.json untouched.
  • Red before the fix, on the unmodified splitter: vitest run src/__tests__/split.test.ts -t 'fits is one passage', Tests 8 failed / 3 passed (the 3 pin unchanged behaviour), each failure a fitting section returned as 2 to 4 passages.
  • node scripts/pm/dispatch-gates.mjs --commands (derived from the merge base, 8 paths): 114 commands, run locally; --ran reconciliation: 114 accounted, 110 exit 0, 4 NOT MEASURED (exit 3, prerequisite not met in this container: check-plugin-teardown-shape --self-test needs an unshallow clone; check:skill-examples, check:dual-build-cjs-loads and check:i18n need a full workspace build). CI runs all four.
  • node scripts/pm/overlap-check.mjs --branch=HEAD: VERDICT clean exit 0, merges cleanly with origin/main, 0 open PR heads overlapping.
  • Dogfood battery: not owed (no ! in the title, no (narrowing) arm).

Generated by Claude Code

Under split strategy markdown, a section whose passage under the heading-path
prefix withPrefix selects fits maxChars and the token budget is now one
passage, whatever minChars is; minChars keeps merging the pieces of sections
that do not fit. Text before the first heading follows the same rule.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5mCvGQKiCEBneFwp1j
…merges only sections that do not fit

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5mCvGQKiCEBneFwp1j
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation protocol:ai tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 3 package(s): @objectstack/platform-objects, @objectstack/service-knowledge, @objectstack/spec, touching 5 documentable anchor(s).

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

  • content/docs/ai/knowledge-rag.mdx (via knowledge_source (symbol, a field of const object enMetadataForms; a field of const object esESMetadataForms; a field of const object jaJPMetadataForms; a field of const object zhCNMetadataForms), minChars (literal, a string literal in sections))
  • content/docs/getting-started/quick-reference.mdx (via knowledge_source (symbol, a field of const object enMetadataForms; a field of const object esESMetadataForms; a field of const object jaJPMetadataForms; a field of const object zhCNMetadataForms))
  • content/docs/permissions/system-context.mdx (via knowledge_source (symbol, a field of const object enMetadataForms; a field of const object esESMetadataForms; a field of const object jaJPMetadataForms; a field of const object zhCNMetadataForms))
  • content/docs/protocol/knowledge.mdx (via knowledge_source (symbol, a field of const object enMetadataForms; a field of const object esESMetadataForms; a field of const object jaJPMetadataForms; a field of const object zhCNMetadataForms), minChars (literal, a string literal in sections))
What this run could not see
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 253 client-bound route-ledger rows — the other 184 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 184: 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; 125 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 — 181 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 da184dacd9d4f8ee66710453f235255e7fdee223 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 65fc776b299235f26545cbcf7721e9ade67f37bd — the merge of head c645c31925a58f83088e62b0e8e832eecc920145 into base da184dacd9d4f8ee66710453f235255e7fdee223, 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 65fc776b299235f26545cbcf7721e9ade67f37bd && git checkout 65fc776b299235f26545cbcf7721e9ade67f37bd
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin da184dacd9d4f8ee66710453f235255e7fdee223 c645c31925a58f83088e62b0e8e832eecc920145 && git checkout -B drift-repro da184dacd9d4f8ee66710453f235255e7fdee223 && git merge --no-ff c645c31925a58f83088e62b0e8e832eecc920145

node scripts/docs-audit/affected-docs.mjs --json da184dacd9d4f8ee66710453f235255e7fdee223

⚠️ 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 da184dacd9d4f8ee66710453f235255e7fdee223 → 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#5 · os-project-manager · session_01FEkQ5mCvGQKiCEBneFwp1j

Contract-review-claim: session_01FEkQ5mCvGQKiCEBneFwp1j · head 4723a4f · 2026-11-29T01:50Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5mCvGQKiCEBneFwp1j

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 4723a4fe1d269a904c7b7a9cfd3c70ea81544d29
Local-runs: none
Scope: packages/spec/src/ai/knowledge-source.zod.ts, packages/spec/src/ai/knowledge-source.metadata-form.ts + packages/services/service-knowledge/src/split/splitter.ts
Security-touching: no
Rule-change-verified: none

Read: card #38351 (body and all five comments, ruling 7247322956 included), PR #38439 (body, eight files, the diff against main), and the check-runs on this head as of 2026-11-29T02:02Z: 30 success, 1 failure, 12 skipped, 30 still running (11 Test Core shards, 16 Test UI shards, Type Check · workspace, Type Check UI, Build & E2E UI). The failure decides this record; the running ones do not change it.

① Derived judgments

  • Accept set: unchanged. Right. KnowledgeSplitSchema keeps the same three keys, the same enum and the same number bounds; only a docblock and one .describe string move. Spec property liveness and Type Check · source gates are green on the head.
  • Exports: unchanged. Right. withPrefix is private, splitMarkdown keeps its signature, and no constant is added or moved.
  • Published prose: minChars description changes. Right. The regenerated content/docs/references/ai/knowledge-source.mdx carries the new sentence in both tables, and the spec artifact gates in Type Check · source gates are green.
  • Behaviour: markdown passages change for a section that fits but was cut. Right, and it is ruling A. Such a section becomes one passage, so the passage count and the documentId#index ids of that document shift. recursive and whole are untouched.
  • Index fingerprint: unchanged. Right under execution reading 3. markdown stays at 2. The condition that reading sets holds in the tree: .changeset/38350-markdown-bodyless-headings.md is still pending on live main (4437c50) and the package is still at 19.0.0-next.2.
  • Committed form translations: not regenerated. Wrong. The help text edited in knowledge-source.metadata-form.ts is the source of packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts, which the diff does not touch. This is M1 below.

② Semver level

  • Level matches the kind. The changeset gives minor to @objectstack/service-knowledge and @objectstack/spec. AGENTS.md Post-Task step 3 asks at least minor of a semantic kind on each package the diff moves, and these are the two it moves today.
  • Clause-②: no is correct. Nothing an author can write is added, removed or refused, and no export or route changes. The line is in both the PR body and the changeset.
  • Metadata-protocol: semantic is correct. The same written strategy: 'markdown' and minChars now mean something different, which is the ruling's own declaration (reading 4). Check Changeset is green.
  • The M1 fix will move a third package. Regenerating the bundle edits packages/platform-objects/src, so the changeset then owes @objectstack/platform-objects a line (.changeset/37309-knowledge-source-studio-form.md is the precedent for the same bundle). The delta review reads that line.

③ Boundary flags

  • open_questions: empty. Nothing to answer.
  • Dev flag, the markdown: 2 comment left as it is: answered as N1 below. Accepted for this PR; the carrier the dev names (review follow-ups of PR #38375 #38377) is "noted, not filed", so the seat has to put it on that card.
  • Dev flag, the card's 0.2% residual not reproduced: answered, no contract effect. The ruling's bar is 0.5% and the residual belongs to the minChars = maxChars recipe, which this change makes unnecessary.
  • Skills-docs: follow-up owed: accepted as declared; the ruling asks for the line. skills/objectstack-ai/SKILL.md:333-341 on main still teaches "Adjacent pieces shorter than minChars (default 200) are merged" with no fitting rule. No card number is named yet. The claim says the area files it before ACCEPT, and that is still owed.
  • ADR-0161 wording note (reading 4): escalated to the seat. The PR body defers it to "a separate card" without a number, and the card thread names none. docs/adr/0161-…md:274 is the sentence concerned ("it changes when the splitter gives different passages for the same text and settings"). Name the carrier before ACCEPT.
  • Acceptance numbers (reading 5): not verified here. The corpus table and the 20,000-document byte-identity run are the dev's local measurements on a synthetic corpus. No check-run carries them and this review is read-only. By reading the code I agree with the byte-identity claim: a section that fails the new check reaches the same splitRecursive call with the same arguments.
  • SQL push-down: none. The splitter is a pure function and the diff adds no query, id materialisation or join.
  • Security: no changed hunk teaches permission, sharing, credential or authentication behaviour.

④ Design judgment

packages/spec/src/ai/knowledge-source.metadata-form.ts — does not hold at its first consumer.

M1 (must-fix) — the new minChars help text reaches no Studio user on this head, and its gate is red.

  • The server localises this form from the platform-objects bundles (packages/platform-objects/src/metadata-translations/index.ts:56), and resolveMetadataFormLabels lets a bundle leaf replace the form's own string.
  • en.metadata-forms.generated.ts:3579 still holds the old sentence, ending "Recursive and Markdown only." So English shows the old text, and so do the seven locales that fall back to the en bundle.
  • Check-run Type Check · consumer gates is failure on this head. Its step "Check generated translation bundles are in sync with the schema" (pnpm check:i18n) prints platform-objects DRIFTED (1). It is the only red gate step in that lane.
  • The dev report lists check:i18n as NOT MEASURED locally, which is why it was missed.
  • Fix: node scripts/check-i18n-bundles.mjs --write after a workspace build, commit the regenerated bundle, and add the changeset line from ②.

S1 (should-fix) — three hand-translated locales keep the old rule after M1's regeneration.

  • zh-CN, ja-JP and es-ES hold real translations of the old sentence at source.split.minChars.helpText (line 3579 of each bundle).
  • They have no entry in their source-hashes tables, so they are served as they are. Merge mode keeps them, and no gate reports them.
  • A Chinese author would still read that short neighbours are merged up to this length under Markdown, with nothing about a fitting section. That is the misreading ruling A removes.
  • Fix: re-translate those three leaves in the same commit as M1.

packages/spec/src/ai/knowledge-source.zod.ts — holds against the ruling and the splitter.

  • The markdown bullet (lines 96-101), the minChars docblock (120-123) and the .describe (126) each agree with withPrefix as changed.
  • "Within the effective maxChars" covers the token budget, because the same docblock defines the effective maxChars as the smaller of the character value and what fits in 80% of the embedder's limit.
  • "Whatever minChars is" is true: the fitting check runs before minChars is read, so minChars: 0 does not opt out (reading 2).
  • "The text before the first heading, and a heading's text before its first sub-heading, are sections too" matches splitMarkdown, which flushes a section at every heading.

N2 (nit) — "its text with its heading path" is narrower than the code in one corner.

  • When the full path would take more than half the bounds, withPrefix falls back to the innermost heading, and fitting is judged under that shorter prefix.
  • A section whose text plus full path is over maxChars can therefore still be one passage. The splitter's own docblock says "the heading path it is given", which is exact.
  • The direction is harmless (fewer cuts) and the fallback predates this PR. Accepted as it stands; cheap to align while the head moves for M1.

packages/services/service-knowledge/src/split/splitter.ts — the code agrees with the contract.

  • One passage is exactly the section. whole is the selected prefix plus the trimmed body, the same bytes the old path produced whenever it returned one piece. No text is dropped or reordered.
  • No passage can exceed the bounds. The early return is guarded by fits(whole, b), which is the bound the file promises for every passage.
  • The "emitted passage" reading is sound. I checked the comment's claim against estimateTokens: the prefix ends in whitespace, so the raw sums add and the rounded estimate of the passage is at most the two rounded apart. The new check accepts everything the old per-part check accepted, plus the one-token rounding case.
  • Sections that do not fit are untouched. They reach splitRecursive(body, left, Math.min(minChars, left.maxChars)) as before.
  • The path-less branch and the body-less heading branch are correct. Text before the first heading takes the same rule; a heading with no text returns before the new lines.
  • I tried a path too long for the half-bounds rule, a prefix that is whitespace only, a token budget at or below the prefix, a table inside a fitting section, and minChars above maxChars. None breaks the bound or the contract.

N1 (nit) — the version table's own prose no longer describes version 2.

  • Its docblock (lines 75-83) says to bump an entry "in the change that makes that strategy give different passages", and the comment on markdown: 2 (94-96) names only the body-less heading change.
  • This diff changes markdown passages and rides 2, which reading 3 allows. Only the changeset records that 2 carries both changes.
  • No effect on the fingerprint or on correctness. Accepted deviation here; follow up on review follow-ups of PR #38375 #38377, which edits that block.

M1 is a must-fix, so this head fails. The delta review owes M1 and S1, plus the changeset line.

Implemented-by: claude/issue-38351-markdown-fitting-section
Reviewed-by: session_01FEkQ5mCvGQKiCEBneFwp1j

VERDICT: FAIL

…jects in the changeset, exact heading-path wording

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5mCvGQKiCEBneFwp1j
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5mCvGQKiCEBneFwp1j

Contract-review-claim: session_01FEkQ5mCvGQKiCEBneFwp1j · head c645c31 · 2026-11-29T02:16Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5mCvGQKiCEBneFwp1j

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: c645c31925a58f83088e62b0e8e832eecc920145
Local-runs: none
Scope: packages/spec/src/ai/knowledge-source.zod.ts, packages/spec/src/ai/knowledge-source.metadata-form.ts + packages/services/service-knowledge/src/split/splitter.ts, packages/platform-objects/src/apps/translations/en.metadata-forms.generated.ts, packages/platform-objects/src/apps/translations/zh-CN.metadata-forms.generated.ts, packages/platform-objects/src/apps/translations/ja-JP.metadata-forms.generated.ts, packages/platform-objects/src/apps/translations/es-ES.metadata-forms.generated.ts
Security-touching: no
Rule-change-verified: none

Delta review from 4723a4fe1d269a904c7b7a9cfd3c70ea81544d29 (record 7249205899: must-fix M1, should-fix S1, nits N1 and N2) to this head.

Read: card #38351 (body and all six comments, ruling 7247322956 and both dev reports included), PR #38439 (body, twelve files, the diff against main and the two-commit delta, 8 files, +12/−10), and the check-runs on this head as of 2026-11-29T02:22Z: 31 success, 0 failure, 9 skipped, 29 still running (Build Core, 9 Test Core shards, 16 Test UI shards, Type Check · workspace, Type Check UI, Build & E2E UI). Nothing is red. The running ones do not decide this record; a red one among them would overturn it.

The delta leaves splitter.ts, knowledge-source.metadata-form.ts, the test file and the regenerated reference page byte-identical to round 1's head. main has not moved under any file of this diff since the merge base d751790c.

① Derived judgments

  • Accept set: unchanged. Right. KnowledgeSplitSchema keeps its three keys, enum and number bounds. The delta edits one docblock sentence in the zod file and no .describe string. Spec property liveness and Type Check · source gates are green on this head.
  • Exports: unchanged. Right. No export is added, moved or retyped in any of the three packages.
  • Published prose: the minChars description. Right. The reference page carries it in both tables and the delta did not need to regenerate it.
  • Committed form translations: now in step. Right. The en bundle leaf at en.metadata-forms.generated.ts:3579 is byte-equal to the form's help text. The key set of every bundle is unchanged; four leaf values move. This was the "Wrong" line of round 1.
  • Behaviour: markdown passages change for a section that fits but was cut. Right, and it is ruling A. Unchanged since round 1.
  • Index fingerprint: unchanged. Right under execution reading 3. markdown stays at 2. The condition still holds on live main (1afd9c1): .changeset/38350-markdown-bodyless-headings.md is pending, the three packages are at 19.0.0-next.2, and that changelog section does not carry the body-less heading fix.

② Semver level

  • Level matches the kind on all three packages. The changeset now gives minor to @objectstack/service-knowledge, @objectstack/spec and @objectstack/platform-objects. AGENTS.md Post-Task step 3 asks at least minor of a semantic kind on each package the diff moves, and the delta moves packages/platform-objects/src. The knowledge_source: a Studio form to create and edit a knowledge source (object, content fields, metadata fields, where, split) #37309 precedent was patch because its kind was none, so minor here is the right reading, not an over-bump. The three packages are in one fixed group, so the release version is the same either way.
  • Clause-②: no and Metadata-protocol: semantic are still correct, in both the PR body and the changeset. Check Changeset is green on this head.
  • The changeset's new sentence is true. It says the Setup bundles carry the new help text, regenerated for en and re-translated for zh-CN, ja-JP and es-ES. That is what the diff does.
  • One stale line in the changeset body, not blocking. It still reads Skills-docs: follow-up owed — skills/objectstack-ai/SKILL.md, while the PR body now names skills: the AI skill teaches that a markdown section that fits maxChars is one passage (after #38351) #38442. The rule owes that line to the PR body only, and the gate is green. Leave it: editing the changeset moves the head.

③ Boundary flags

  • open_questions: empty in both reports. Nothing to answer.
  • Dev flag, seven locales hold an older English copy of the minChars help text: answered, not a defect at the consumer. ar, de, fr, ko, pt-BR, ru and zh-Hant each record that leaf in their source-hashes.generated.ts table with the same digest (ar: line 81). MetadataFormsTranslations passes every translated locale through withSourceFallback, which serves the en string for a recorded copy whose source has moved. So those seven serve the new English sentence. I read this from the code and the green check:i18n step, which keeps the tables in sync; I did not run it.
  • Dev flag, minor against the patch precedent: answered in ②.
  • Dev flag, N1 left to review follow-ups of PR #38375 #38377: still accepted, and still not written on that card. Its thread has two comments (triage and the claim) and neither names the markdown: 2 comment. The seat owes that note before ACCEPT.
  • Skills-docs:: now follow-up #38442 in the PR body. The card exists, is open, is blocked by service-knowledge: a markdown section that fits maxChars is still cut into several passages #38351, and asks for the two SKILL.md sentences round 1 named. Answered.
  • ADR-0161 wording note (execution reading 4): escalated to the seat again. The PR body now says no ADR note is owed. A PR body cannot withdraw an item of the ruling's execution reading. My reading of the tree: docs/adr/0161-…md:274 says the version "changes when the splitter gives different passages for the same text and settings"; this change gives different passages and stays at 2, which only the topic's one-bump-per-train rule licenses. Before ACCEPT, the seat records on service-knowledge: a markdown section that fits maxChars is still cut into several passages #38351 either a carrier (review follow-ups of PR #38375 #38377 already carries a K7 revisions row for the same table) or the withdrawal of that item.
  • PR body describes round 1, the seat's to fix, no head change. Its changeset paragraph names two packages, its "What changes" list omits the four bundles, and its local-runs block is pinned to 4723a4fe. The dev report says so too.
  • Acceptance numbers (reading 5): not verified here, as in round 1. No splitter line changed in the delta, so they describe this head as well as they described the last.
  • SQL push-down: none. The delta adds no query, id materialisation or join.
  • Security: no changed hunk teaches permission, sharing, credential or authentication behaviour.

④ Design judgment

No must-fix, no should-fix.

packages/spec/src/ai/knowledge-source.metadata-form.ts and its four bundles — hold at the first consumer.

M1: closed.

  • Commit 9aeceaa regenerates one leaf, source.split.minChars.helpText in the en bundle, and it equals the form's string byte for byte.
  • No provenance table changed, which is what the generator's rule predicts: the en rewrite touches no translated leaf.
  • Check-run Type Check · consumer gates is success on this head. Its step "Check generated translation bundles are in sync with the schema" is green, and so are the three i18n steps after it.
  • The changeset line round 1 asked for is there (②).

S1: closed.

  • zh-CN, ja-JP and es-ES each keep the old sentence and add the fitting rule: under Markdown a section that fits is one passage, so only the pieces of a section that does not fit are merged. I read all three against the English; each says that and nothing more.
  • Their words match the neighbouring leaves (段落, パッセージ, pasaje for passage). zh-CN says 小节 where the strategy option says 章节; both read naturally.
  • None of the three has a provenance entry, before or after, so each is served as written. AGENTS.md allows hand edits to translated-locale values in these files.

packages/spec/src/ai/knowledge-source.zod.ts — holds against the ruling and the splitter.

N2: closed. The markdown bullet now reads "its text together with the heading path it is given (the whole path, or the innermost heading when the whole path is too long)". That matches the first two prefixes withPrefix tries, and content/docs/protocol/knowledge.mdx section 3.5 says the same. knowledge-rag.mdx takes the short form and links to that section. The rest of the docblock, the minChars docblock and the .describe are unchanged and still agree with the code.

N3 (nit) — the new parenthetical lists two of the three prefixes.

  • withPrefix tries the whole path, then the innermost heading, then no prefix at all. The last is taken when the innermost heading alone would leave less than half the bounds for text.
  • Fitting is then judged on the text alone, and the passage does not begin with a heading. The docblock (lines 98-99) and section 3.5 do not say so.
  • It needs a heading of about half maxChars (399 characters at the default, 49 at maxChars: 100). The direction is harmless (fewer cuts) and the fallback predates this PR.
  • Accepted as it stands. Fix it the next time this docblock is opened; a fix now moves the head.

N4 (nit) — line 101 of the docblock is 95 columns in a block wrapped at about 77. Cosmetic; left.

packages/services/service-knowledge/src/split/splitter.ts — the code agrees with the contract.

  • Unchanged since round 1, and I re-read splitMarkdown and withPrefix on this head.
  • The one passage is the selected prefix plus the trimmed text, guarded by fits(whole, b), so it can never exceed the bounds the file promises.
  • A section that does not fit reaches the same splitRecursive call with the same arguments as on main.
  • The path-less branch and the body-less heading branch are as round 1 found them.
  • I tried again a path over half the bounds, a heading over half the bounds, a token budget below the prefix, and minChars above maxChars. None breaks the bound.

N1 stays as round 1 left it: an accepted deviation, to be carried on #38377 (③).

Open for the seat before ACCEPT, none of them a change to this head: the N1 note on #38377, the ADR-0161 item on #38351, and the PR body.

Implemented-by: claude/issue-38351-markdown-fitting-section
Reviewed-by: session_01FEkQ5mCvGQKiCEBneFwp1j

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5mCvGQKiCEBneFwp1j

Final green head declared for L1: c645c31925a58f83088e62b0e8e832eecc920145.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5nNJM8FQkBco82NDFb

席位核对

L1 (thread L1-a, area o5-ai37000) · read 2026-11-29T02:47Z · Head-sha: c645c31925a58f83088e62b0e8e832eecc920145 · verdict ACCEPT

This is the first L1 record on this PR, a full review.

Checklist (l1-face --pr 38439 at c645c31: CLEAN, 13 items, exit 0)

  • Shape: open, draft, base main. Fixes #38351 is right. It delivers ruling A, recorded on the card: a markdown section that fits is one passage, minChars keeps its meaning for sections that do not fit, and it shares the strategy version move.
  • Scope: 12 files, +206/−27. They are the splitter and its test, the spec docblocks, the minChars describe and form help text, the four regenerated or re-translated Setup bundles, and three docs pages. The one changeset bumps service-knowledge, spec and platform-objects minor. Clause-②: no · Metadata-protocol: semantic, and AGENTS.md says a kind takes at least minor on each package the diff moves. Skills-docs: follow-up #38442 (open, the AI skill's markdown passage rule). The diff touches packages/spec/src/**, so the contract-tier L2 is owed: delta PASS 7249418590 on this head (M1 and S1 of round-1 record 7249205899 closed per that record; N3 and N4 left as nits).
  • Gates at c645c31: 65 success, 11 expected skip, 0 failed, 0 pending; mergeable_state clean. Not governed, so the area lands it.

My readings, at this head (detached worktree, restored, removed)

  • vitest run src/__tests__/split.test.ts: 41 passed.
  • Ablation: dropping the new fits(whole, b) return in withPrefix turns 7 cases red. Among them are the default-minChars case, minChars: 0 not being an opt-out, the exactly-maxChars boundary with the prefix counted, the innermost-heading fallback, and the table with its note. The source was restored.
  • Code: fitting is judged on the passage as emitted (prefix plus trimmed text, through fits), under the same prefix withPrefix selects. A section that does not fit still goes through splitRecursive with the same bounds and min(minChars, left.maxChars), so its passages are unchanged, as the changeset claims. The pre-heading text gets the same rule in the path.length === 0 branch.
  • No version bump, checked. splitter.ts:96 reads markdown: 2. The move from 1 to 2 is made by .changeset/38350-markdown-bodyless-headings.md, still pending on main: its line 16 says "The markdown split algorithm version moves from 1 to 2". The changeset file is not yet consumed, so no released version has shipped markdown: 2, and this change rides it. Every markdown source rebuilds once. If a Version Packages PR consumes 38350 before this merges, the reading changes, so it should be re-checked at landing.
  • Docs, read sentence by sentence (knowledge-rag.mdx, protocol/knowledge.mdx table, the minChars code comment and the effective-length paragraph, the two references/ai/knowledge-source.mdx rows). Each states the new rule: one passage when it fits, whatever minChars is; the prefix counts; a section that does not fit is cut as recursive cuts. Each agrees with the code and with the spec describe. The reference rows match the regenerated describe text byte for byte.
  • Changeset, sentence by sentence. Each claim holds against the diff: what changed, that a non-fitting section gives the same passages, the pre-heading and parent-heading text, that recursive/whole are unchanged, that no key or default changes, and the version reading above.

Accepted (no action): the contract record's N3 (the parenthetical names two of the three prefixes) and N4 (one 95-column docblock line) are nits it left. The ADR-0161 note is not owed, because the area measured no ADR text that contradicts the change (body line 60).

Owed: nothing from L1. Before landing, re-confirm .changeset/38350-markdown-bodyless-headings.md is still unconsumed. Then the area lands it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-project-manager · session_01FEkQ5mCvGQKiCEBneFwp1j

Landing · head c645c31925a58f83088e62b0e8e832eecc920145

Probe Reading
check-governed-merges.mjs --pr 38439 NOT governed (0 of 12 paths on the register); 233 changed lines, under 3000
pr-state.mjs --pr 38439 65 success · 11 expected skip (check-expected-skips OK) · 0 failed · 0 pending · mergeable_state clean
landing-k.mjs --pr 38439 K = 2, no locale or shared-book leg
overlap-check.mjs merges cleanly with origin/main 1afd9c1 and with #38452, #38421
Version reading .changeset/38350-markdown-bodyless-headings.md still unconsumed on origin/main 1afd9c1, so markdown: 2 is unreleased and this PR rides it
Records on this head L1 ACCEPT 7249654609 · contract review PASS 7249418590

State change: ready + auto-merge now (area lands, not governed). On merge, Fixes #38351 closes the card; the area clears pm:dispatched. Follow-ups: #38442 (skills docs, blocked by this card), N1 on #38377 (7249429872).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 29, 2026 02:49
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit f19ee34 Nov 29, 2026
77 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-38351-markdown-fitting-section branch November 29, 2026 03:15
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…tack-ai#38452)

<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XPpqjfjwZCAyAm71ZUE2yhz)_
Fixes objectstack-ai#38377
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no published skill, doc page or example names the
retired constant (git grep over `skills`, `content/docs`, `docs`,
`examples`, `apps`, `ui`, `.claude` at 4fa2f8e: 0 hits); the ADR text
is item 2, carried by the lander

## 维护者速读

- 用户能看到什么变化:用户无感;只有直接引用知识服务包里那个旧常量的宿主代码,升级后编译会提示删掉这行引用。
- 为什么做:知识平台「切分版本按策略计」之后的收尾,撤掉一个已经没有任何运行代码读取的公开常量,免得作者和 AI 以为改它有效。
- 出错会怎样:最坏是某个宿主仍引用它而编译失败,删掉那行引用即可;可直接撤回本改动,不会触发任何索引重建。
- 要你做的:无。

## What changes

`SPLIT_ALGORITHM_VERSION` leaves `@objectstack/service-knowledge` at
once, with no alias (the card's stage posture). Since the per-strategy
split version landed, the index fingerprint (ADR-0161 K7) reads
`SPLIT_ALGORITHM_VERSION_BY_STRATEGY` for the source's resolved
strategy, and the global constant was read by no runtime code.

- `src/split/splitter.ts`: the constant and its docblock are deleted.
The per-strategy table's docblock linked to it ("Every entry started at"
the constant); it now says every entry started at 1, the one split
version the fingerprint read before the table, which names no retired
symbol and stays true.
- `src/split/index.ts`, `src/index.ts`: both re-exports are deleted.
- `src/__tests__/index-fingerprint.test.ts`: the version pin keeps the
two remaining constants (`INDEX_FINGERPRINT_VERSION`,
`ASSEMBLY_RULE_VERSION`), and a new case pins the retirement: neither
the split barrel nor the package entry has the property, with a positive
control on the entry.
- Area-ordered additions (the sibling split card's L2 nit, comment text
only, no assertion, value or snapshot changed): two comments now name
both changes `markdown` version 2 carries, the body-less heading as its
own passage and a fitting section as one passage whatever `minChars` is.
One is the `markdown: 2` entry comment in
`SPLIT_ALGORITHM_VERSION_BY_STRATEGY` (`splitter.ts`); the other is the
`PINNED` docblock in `index-fingerprint.test.ts`. The second clause is
true only once PR objectstack-ai#38439 merges; the seat lands this PR after it. The
table's docblock does not tie version 2 to one change, so it needed no
edit.
- `.changeset/38377-retire-split-algorithm-version.md`: `patch` (kind
`none`), BREAKING banner, FROM/TO table, a sentence saying this
retirement replaces the still-pending 38349 changeset's note that the
constant keeps its name and value (that changeset is not edited),
ADR-0087 disposition `not-required (runtime-export-retired
@objectstack/service-knowledge#SPLIT_ALGORITHM_VERSION)`.

Item 2 of the card (the ADR-0161 K7 revisions row) is not in this PR: no
`docs/adr/**` edit. The landing seat appends it to the weekly ADR
revisions card (`carrier:` PR objectstack-ai#38375). `Fixes` stays because that row is
landing bookkeeping.

Landing: a narrowing of a published surface. It owes one
contract-review-tier L2 on its final head before the queue.

Read first: (1) `src/split/splitter.ts` — the reworded docblock is the
only prose a reader of the table keeps; (2) the changeset — it ships as
the CHANGELOG line an upgrader greps; (3) the new test case.

Two-minute check: `pnpm --filter @objectstack/service-knowledge exec
vitest run src/__tests__/index-fingerprint.test.ts` — expect 9 tests
passing, including "publishes no global split version beside the
per-strategy table".

## Tests

Package suite at `f76ba9c9`. At `987b09ca`, the last commit that touched
code or tests, `index-fingerprint.test.ts` alone under the verify lock:
Test Files 1 passed (1), Tests 9 passed (9), VERDICT command-exit 0.


<details><summary>service-knowledge test + typecheck (lock VERDICT
command-exit 0)</summary>

```
pnpm --filter @objectstack/service-knowledge test
 Test Files  21 passed (21)
      Tests  727 passed (727)
pnpm --filter @objectstack/service-knowledge typecheck
check:test-typecheck: OK, the test layer compiles under tsconfig.test.json; 0 file(s) / 0 error(s) held in test-typecheck-debt.json
```
</details>

<details><summary>Ablation of the new retirement pin</summary>

With `export const SPLIT_ALGORITHM_VERSION = 1;` appended to
`src/index.ts` on disk, `index-fingerprint.test.ts` went red: `publishes
no global split version beside the per-strategy table` failed with
`expected ... to not have property "SPLIT_ALGORITHM_VERSION"` (1 failed,
8 passed). Restored with `git checkout HEAD`, tree clean.
</details>

<details><summary>Full dogfood (the narrowing arm), at
`4fa2f8ee`</summary>

`pnpm turbo run build --filter='@objectstack/dogfood^...'` then `pnpm
--filter @objectstack/dogfood test` under the verify lock: VERDICT
command-exit 0, Test Files 495 passed, 3 skipped (498), Tests 4183
passed, 68 skipped (4251). `987b09ca` differs from `4fa2f8ee` by
comments only (`git diff --stat 4fa2f8e..HEAD`: 2 files changed, 4
insertions, 1 deletion; one hunk in `splitter.ts`, one in
`index-fingerprint.test.ts`, both comment lines). The final head
`42214359` adds one changeset sentence. So the battery was not re-run.
</details>

## Acceptance notes

- Whole-tree search before deleting, at `d751790c`: `git grep -n
'SPLIT_ALGORITHM_VERSION\b'` gave 13 lines. 5 were the declaration, the
two re-exports and the pin's import and assertion (all removed here); 1
was the per-strategy docblock link (reworded); the other 7 are history:
`.changeset/38349-split-version-per-strategy.md`,
`.changeset/pre/37100-knowledge-pgvector.md` and five generated
`CHANGELOG.md` files. They are left alone: existing changesets are never
edited, and CHANGELOGs are release-owned. No `skills`, `content/docs`,
`docs`, `examples`, `apps`, `ui` or `.claude` hit.
- The package has no API-surface baseline, so no generator was owed.

## Verification

<details><summary>Local gates (derived with dispatch-gates --commands,
reconciled with --ran: 63 derived, 63 run)</summary>

- 60 of 63 exited 0 on the first pass.
- `node scripts/check-adr-0087-registration.mjs --base origin/main` exit
1 on `0c4609e7` (the FROM column spelled an import statement, not the
operand); after the fix, exit 0 on `4fa2f8ee`: `not-required
(runtime-export-retired) -- verified:
@objectstack/service-knowledge#SPLIT_ALGORITHM_VERSION`.
- `node scripts/check-plugin-teardown-shape.mjs --self-test` exit 3
(shallow clone could not reach its pinned fixture commit); after
fetching that commit, exit 0, 48 cases pass.
- `pnpm check:dual-build-cjs-loads` exit 3, PREREQUISITE NOT MET (needs
every package built). NOT MEASURED locally, CI runs it.
- Re-run at `4fa2f8ee` after the changeset fix:
check-changeset-no-major, check-empty-changeset,
check:changeset-gate-self-tests, check:nul-bytes, check:doc-authoring,
check:issue-citations: all exit 0. check:nul-bytes exit 0 again at
`f76ba9c9` and at `987b09ca`. At `42214359` (changeset sentence only),
check-adr-0087-registration, check-changeset-no-major,
check-empty-changeset and check:nul-bytes: all exit 0.
- `node scripts/check-platform-checklist.mjs --changed-from origin/main`
exit 0: 0 anchored files in the change set.
- `node scripts/pm/overlap-check.mjs` before each push: clean; at
`f76ba9c9`, `987b09ca` and `42214359` it also merges cleanly with PR
objectstack-ai#38439.
</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01FEkQ5omA3kZCsWzBMMqF11

<!-- signed: repo:objectstack#5 · os-project-manager ·
session_01FEkQ5omA3kZCsWzBMMqF11 -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…ames chunk_target the longest passage (objectstack-ai#38468)

<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XDXvJPPtrTGfdDYhWWpihq5)_

Fixes objectstack-ai#38290
Clause-②: no
Metadata-protocol: none

## 维护者速读

-
用户能看到什么变化:写知识源的应用作者在知识检索指南里能读到“一条一段”的做法(每条写成一个标题、在同一条记录上派生一个专供检索的文本字段、可选的顶层标题写明文档和所属部门);管理员在知识设置页看到的“目标片段大小”改名为“片段最大长度”,各语言一致。
-
为什么做:知识切分专题第一阶段的文档项,回答外部作者提出的“怎样让每一条恰好一段”的问题;放得下的小节整节一段已按您的裁决合入,这里只把做法写清楚。
- 出错会怎样:只改文档和设置页的文字,键名、默认值、切分行为都不变;写错只会误导读者,直接撤回即可。
- 要你做的:无。

## What changes

- **Knowledge guide** (`content/docs/ai/knowledge-rag.mdx`): a new `###
One passage per unit` section under "Splitting documents into passages".
It teaches, as the landed `markdown` splitter behaves at f19ee34:
- one heading per unit (a heading at the start of its line; bold text is
not a heading; a unit's sub-items as list items, since a sub-heading is
a section and a passage of its own);
- a unit whose text with its heading path fits is one passage whatever
`minChars` is, and a table with the note after it inside that unit stay
together;
- no passage holds two units (each section is split on its own), and
every passage begins with its unit's heading path;
- a unit that does not fit is cut as `recursive` cuts, its pieces merged
up to `minChars`; the note after a cut table can land in another piece;
- `minChars` is the merge threshold of a unit that does not fit, not a
switch, and `minChars: 0` turns nothing off;
- a derived field on the same record carries the index text, listed
alone in `content` (why the same record and not a second object: the hit
names the record people open, the search re-checks that record as the
asker, `where` and `metadataFields` read its own fields);
- an optional top heading names the document (and the department that
owns it), so every passage's heading path begins with it; keep it short,
because a path that leaves less than half of the passage length shortens
to the unit's own heading; a title already in that heading needs no
second `content` entry;
- moving a source to this shape changes `content` and `split`, so it
rebuilds once and re-sends the source to the embedder.
- **Protocol page** (`content/docs/protocol/knowledge.mdx` §3.5): one
paragraph that states the result and points to the guide; the setting's
name updated.
- **Settings page** (`packages/services/service-settings`):
`knowledge.chunk_target` was labelled **Target chunk size (chars)**
while its help text and the splitter treat it as a maximum. The label is
now **Longest passage (characters)** and the help adds that passages can
be shorter, in the manifest and in all 11 locales (en, zh-CN, zh-Hant,
ja-JP, ko, de, es-ES, fr, pt-BR, ru, ar). Key, default, bounds and
reader unchanged.
- **Changeset**: a patch on `@objectstack/service-settings`, which also
says that earlier notes naming **Target chunk size** mean the same
setting (the pending changesets that name it are not edited).

## Answer to objectstack-ai#38290

The card asked for either a split strategy that cuts at a unit pattern,
or a documented way to get one passage per unit. objectstack-ai#38351's ruling A
(record 7247322956, 「objectstack-ai#38351 同意」, merged in PR objectstack-ai#38439) made a fitting
`markdown` section one passage by default, so the documented way needs
no setting: write each unit as a heading. `minChars: 0` is not that
switch and is not an opt-out (ruling item 2): `minChars` only merges the
pieces of a section that does not fit. A table and its trailing note
inside one fitting unit are one passage. The app's workaround (a second
object with one row per article) can become a derived field on the
policy record itself. The 84% → 94% figure is not cited here: the
topic's adoption comment notes it changed several variables at once.

## Acceptance notes

- `skills/objectstack-ai/SKILL.md` still names "the **Target chunk
size** setting". Skills are objectstack-ai#38442's surface; its dev was told to write
"the **Longest passage** setting" and to land after this PR.
- The card's claim names this PR's head in claim 7250337030 (the area's
re-post of 7250017151 with the platform branch).
- The pending changesets that name **Target chunk size**
(`.changeset/pre/37098-knowledge-splitter.md`,
`.changeset/pre/37292-skill-knowledge-split.md`) are not edited; this
PR's changeset carries the superseding sentence.

## Verification

All at head `340bb349`, tree `objectstack-ai/objectstack`, base
`origin/main` f459c86.

- `pnpm --filter @objectstack/service-settings test`: Test Files 79
passed (79), Tests 1545 passed (1545); exit 0.
- `pnpm --filter @objectstack/service-settings typecheck`: exit 0
(dependency closure built first, exit 0).
- `node scripts/pm/overlap-check.mjs --branch=HEAD`: `VERDICT clean exit
0` (merges cleanly with origin/main; no open PR head on these files).
- Derived gate families (`dispatch-gates --commands`): 89 derived, 86
run with exit 0, 3 NOT MEASURED (exit 3, prerequisite not met, nothing
measured; CI runs them):
- `node scripts/check-plugin-teardown-shape.mjs --self-test`: its
positive control is pinned to a commit the shallow clone cannot reach.
- `pnpm --filter @objectstack/spec run check:skill-examples`: needs a
`@objectstack/client-react` build this diff does not touch.
- `pnpm check:dual-build-cjs-loads`: needs every package's `dist/`,
which this container did not build.
- `dispatch-gates --ran`: 89 derived families accounted for, 86 run, 3
NOT MEASURED (derived from the recorded exit 3).
- Every other family CI runs on this PR is read from its check runs, not
re-run here.

Two-minute check: open `content/docs/ai/knowledge-rag.mdx` at "One
passage per unit" and compare each bullet with `withPrefix` and
`splitMarkdown` in
`packages/services/service-knowledge/src/split/splitter.ts`.

Read first: the new section of `content/docs/ai/knowledge-rag.mdx` (the
claims a reader acts on), then the `zh-CN.ts` / `ja-JP.ts` label
wording.

## Human Minimum

- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind. (no names
added)
- [x] 3. No formatter ran; `pnpm lint` passes. (CI)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01FEkQ5mDidoPNcFwxVX65bA

<!-- signed: repo:objectstack#5 · os-project-manager ·
session_01FEkQ5mDidoPNcFwxVX65bA -->

Co-authored-by: Claude <noreply@anthropic.com>
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…s its sources without an embedder or its deployment store (objectstack-ai#38470)

<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1X6jdZukAJaWgnbQHnPWHxMw)_

Refs objectstack-ai#38369

Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: follow-up objectstack-ai#38475

## 维护者速读

- 自托管部署如果没配嵌入模型(或部署的知识存储没挂上),知识源现在只列出、不构建、不同步、不检索,智能体工具里也不再出现
`search_knowledge`;启动日志说一次缺了哪一半、怎么补。以前这种部署照样启动构建和同步,工具也列出来,但每次构建和检索都报错。
- 属于知识库检索这条线,执行您对 objectstack-ai#38368 的裁决(四点全按推荐 1A 2A 3A 4A)和 ADR-0161 K8
的日期注记"挂载不等于启用"。这是三单中的第一单:先把"不服务"做实;保存时拒绝(第 2 单)和状态/命令行文字(第 3 单)随后各开一单。
-
只影响运行时自动挂载知识服务、且缺嵌入模型或知识存储的部署;配齐两半的部署、以及宿主自己挂载知识服务的部署行为不变;从不阻止启动;出问题可整单撤回。
- 要你做的:批准这次收窄(按审批流程)。

## What changes

The authority is the ADR-0161 K8 dated note on item 12 (PR objectstack-ai#38401,
0c1b2ff), with ruling 7248214179 (amendment 7248231750, points 1–4) and
build notes 7248592159 (points 1–4). This PR is part 1 of the three
serial PRs the card names: items 1–2, ruling points 2–3, build notes 1,
2 and 4. Part 2 (the save refusal: item 3, points 1 and 4, build note 3)
and part 3 (items 4–5) follow from `main` after this merges.

- **Enabled by configuration, read once at boot**
(`packages/services/service-knowledge/src/knowledge-service-plugin.ts`).
The capability composition
(`packages/core/src/capability-composition.ts`) now passes
`runtimeComposed: { declared }` beside `deploymentAdapter`; `declared`
is true only when the stack lists `knowledge` in `requires`. With
`runtimeComposed` set, the plugin reads at `kernel:bootstrapped`, after
every store's `start()` registered its adapter: an embedder is available
(another plugin registered one, or the saved `ai.embedder_*` settings
build one) and the deployment's store is mounted (an adapter of
`deploymentAdapter`'s id is registered). Both ⇒ the boot goes on as
today. Either missing ⇒ held. A plugin a host mounts (no
`runtimeComposed`) is untouched: it serves from the start, as before.
- **Held**
(`packages/services/service-knowledge/src/knowledge-service.ts`,
`KnowledgeService.settleEnablement`). Every source, whichever store it
names (point 2: an application-registered store too), is loaded and
listed, and never built, synced, reconciled or searched: the boot build,
the reload build, the reconcile pass and its job, the record sync
(enqueue, upsert, delete and the queued worker), the predicate-write
note and the unmounted-adapter report all return. A dropped source keeps
its index (a warn line says no store is called). `search`,
`rebuildSource` and `reindexSource` throw `heldSourcesError`: status
`503`, code `SERVICE_UNAVAILABLE`, and a message naming the missing half
and the fix (build note 2).
- **No reap guard and no store call while not enabled** (point 3, build
note 1). The lifecycle reap guard used to register at `kernel:ready`,
before the reading; the lifecycle service has no unregister. A
runtime-composed plugin now registers it only once the reading says
enabled. Held, a retention sweep deletes on time and calls no store.
- **One boot line**, never a boot refusal (ADR-0078 §4). `info` when
only a shipped `knowledge_source` mounted the service and nothing was
saved; `warn` when the stack declares `requires: ['knowledge']`, when a
saved embedder provider builds nothing (a provider saved without its
key), or when the store is not mounted. The embedder's own boot line is
not also said when held.
- **No tool definition while pending or held**
(`KnowledgeService.knowledgeTools()` answers `definitions: []`). HTTP
MCP reads the definitions per request, so it lists `search_knowledge`
only once enabled.
- **stdio** (`packages/mcp/src/plugin.ts`, build note 4). The stdio
bridge reads the tool in its own `start()`, before the reading, so a
runtime-composed service hands out nothing there. `MCPServerPlugin` now
registers `search_knowledge` at `kernel:listening` (after every
`kernel:bootstrapped` handler) only when the service then hands out its
definition. Fail-closed: an unknown state reads as absent, never listed
and then withdrawn. The MCP SDK takes a tool after the transport
attached and sends `notifications/tools/list_changed`; skill prompts
read the served tools at each listing. A host-mounted service's tool
still registers in `start()`, once.
- **ADR-0087**:
`packages/spec/src/migrations/entries/semantic/19.knowledge-service-held-without-embedder-or-store.ts`
(notice only, no D2 conversion: the fix is the deployment's
configuration, never the item). The changeset carries `registered` with
that id.

### Boot window

Between `kernel:ready` and `kernel:bootstrapped` the reading is pending.
In that window no tool definition is handed out (fail-closed); a record
write's sync behaves as today (it embeds through the stand-in embedder,
which refuses). Gating starts when the reading settles. No reap guard
registers in that window on a runtime-composed plugin.

### Point 2 measurement

None of `@objectstack/verify`'s `harness.required-providers` cases reads
as held: every one registers an embedder. The file is unchanged and its
16 cases pass.

### Docs

`content/docs/ai/knowledge-rag.mdx`: a "Mounted is not enabled" bullet
under *Turning it on* (held state, the boot line and its level, the
remedy, host-mounted not held), a clause on the "Nothing is configured"
embedder bullet, and one sentence under *The `search_knowledge` tool*
(not listed while held; on stdio registered after the reading, with
`notifications/tools/list_changed`).
`content/docs/protocol/knowledge.mdx`: a "Mounted is not enabled"
paragraph after *What mounts the service*, and the reap-guard section
says a runtime-composed service registers no guard until it is read as
enabled. Added after sibling objectstack-ai#38439 (objectstack-ai#38351) merged (f19ee34), with
`main` merged in first. `skills/objectstack-ai/SKILL.md` is out of
scope: follow-up objectstack-ai#38475 rewrites its knowledge wording once, from
`main`, after part 3.

## Tests

-
`packages/services/service-knowledge/src/__tests__/knowledge-settings-contribution.test.ts`,
new describe "a runtime-composed knowledge service is enabled by
configuration", booted on `LiteKernel` with a store plugin that counts
every call (10 cases): held with no embedder saved (one `info` line,
zero store calls after writes and a delete); no `search_knowledge`
definition, search answers `503 SERVICE_UNAVAILABLE` naming the missing
half, rebuild refused; `requires: ['knowledge']` ⇒ `warn`; a provider
saved without its key ⇒ `warn` (build note 3's state, read here; its
save refusal is part 2); store not mounted ⇒ `warn`; both halves missing
named together; point 2 (an application-registered store is held too);
controls: enabled through a host-registered embedder and through saved
settings (built, definition handed out); a host-mounted plugin builds as
before.
- `packages/services/service-knowledge/src/__tests__/reap-guard.test.ts`
(point 3, build note 1): held ⇒ `registerReapGuard` never called and the
retention sweep deletes `k1`, `k2` on time with no store call; control:
enabled ⇒ the guard registers for `['task']` after the reading and
de-indexes before the delete.
- `packages/mcp/src/mcp-knowledge-tools.test.ts` (build note 4): HTTP
lists the tool only once enabled (pending, held: absent; host-mounted:
listed from the start); stdio through `MCPServerPlugin` with the boot
hooks fired by hand: held is never listed and no `list_changed` is sent;
enabled registers at `kernel:listening` with
`notifications/tools/list_changed` and the same description;
host-mounted registers once in `start()`.
- `packages/runtime/src/mcp-knowledge-tools-bridge.test.ts`: the runtime
bridge reads the definitions per listing (pending and held `[]`, enabled
`['search_knowledge']`).
- `packages/core/src/capability-composition.test.ts`: `runtimeComposed:
{ declared }` is passed, `declared` only when the stack lists the token.
- `scripts/engine-double-contract.pinned.json` learns the stdio double's
`findOne` pin (the double routes through
`assertEngineFindOnePredicate`).

## Verification

**Final head `4659f2a369`** (`main` merged twice since `72a9cbfb6a`, for
objectstack-ai#38439 and objectstack-ai#38436; plus the docs commit). At that head, under the lock:
closure build exit 0; `@objectstack/service-knowledge` `pnpm test` 751
passed; `@objectstack/mcp` `pnpm test` 1655 passed; core 26, runtime 7,
verify 16 passed; typecheck exit 0 for service-knowledge, core, mcp and
runtime; `check:engine-double-contract`, `check:slot-lookup`,
`check-adr-0087-registration` (entry at or above PROTOCOL_MAJOR 19),
spec `check:docs`, `check:doc-authoring`, `check-affected-docs`,
`check:adr-anchors` exit 0. **Dogfood battery at `4659f2a369`: VERDICT
command-exit 0 · Test Files 495 passed, 3 skipped (498) · Tests 4183
passed, 68 skipped (4251) · 0 failed.** CI at `4659f2a369`: 62
check-runs success, 10 skipped, none failed.

The readings below were taken at `72a9cbfb6a` and stand where noted.
Shared container; every build and test ran through
`scripts/pm/os-verify-lock.sh`.

<details><summary>Tests and typecheck at 72a9cbf</summary>

- Closure build (`pnpm --filter '@objectstack/dogfood^...' --filter
'@objectstack/cli...' --filter '@objectstack/lint...' build`): VERDICT
command-exit 0.
- `@objectstack/service-knowledge` `pnpm test`: Test Files 21 passed,
Tests 738 passed; `typecheck` exit 0.
- `@objectstack/mcp` `pnpm test`: Test Files 88 passed, Tests 1655
passed; `typecheck` exit 0.
- `@objectstack/core` `capability-composition.test.ts`: Tests 26 passed;
`typecheck` exit 0.
- `@objectstack/runtime` `mcp-knowledge-tools-bridge.test.ts`: Tests 7
passed; `typecheck` exit 0.
- `@objectstack/verify` `harness.required-providers.test.ts`: Tests 16
passed (point 2 measurement above; file unchanged).
- `@objectstack/cli` `plan.artifact-item-capabilities.test.ts`,
`boot-preparation-parity.test.ts`,
`migrate-meta-engine-guidance.test.ts`: Tests 44 passed.
- `@objectstack/spec` `typecheck` exit 0 (migration registry regenerated
with the new entry).
- ESLint over every changed `.ts` file: exit 0.

</details>

<details><summary>Ablation</summary>

At `2d6c3dfd` (plugin unchanged since): `scripts/ablation-replace.mjs`
replaced `const held = this.settleEnablement(ctx, this.service,
embedder);` with `const held = false; void this.settleEnablement;`. The
runtime-composed describe went 9 failed / 1 passed (the host-mounted
control stayed green). Restored; blob back to HEAD, `git diff HEAD`
empty.

</details>

<details><summary>Dogfood battery at 72a9cbf</summary>

`pnpm --filter @objectstack/dogfood test` under the lock: VERDICT
command-exit 0 · Test Files 495 passed, 3 skipped (498) · Tests 4183
passed, 68 skipped (4251) · 0 failed.

</details>

<details><summary>Live positive control (os dev, showcase app)</summary>

The showcase mounts `KnowledgeServicePlugin` itself (host-mounted,
unchanged by this PR), so for the control its two knowledge plugins and
the source's `adapter: 'memory'` were commented out in the worktree only
(never committed; restored with `git checkout`), which lets the runtime
compose the service with the Turso store. `objectstack dev --seed-admin
--log-level info` on a file database, signed in as the seeded admin:

- **No embedder saved.** One boot line, `INFO KnowledgeServicePlugin:
the knowledge service is not enabled on this deployment: no embedder is
configured (no embedder provider is saved — …). Its sources are held:
none is built, synced or searched. To enable it, save an embedder
provider, then restart. 1 source(s) held: showcase-showcase_task_notes.`
(hidden at the default log level, as `info` should be). No build line.
`index_status` lists the source with `build: null`. The Knowledge page's
rebuild action answers "was not started: [knowledge] the knowledge
service is not enabled on this deployment: …". MCP over HTTP:
`tools/list` 20 tools, `search_knowledge` absent.
- **Embedder saved, restarted.** `PUT /api/settings/ai` saved a `custom`
provider pointing at a local OpenAI-compatible stub. The boot registered
the embedder, registered the reap guard for `[showcase_task]` after the
reading, and built the source: "8 row(s) read, 8 written". MCP
`tools/list` 21 tools with `search_knowledge`; a `search_knowledge` call
answered hits from `showcase-showcase_task_notes`; the stub logged one
call of 8 inputs (build) and one of 1 (search).
- The boot also logs `ERROR [knowledge] the start of the build … was not
recorded (Duplicate record refused on 'Knowledge Sync State' …)`
whenever a build starts, host-mounted or not. That is objectstack-ai#38418 (open, seat
1), not this change.
- `index_status` still reads the adapter while held (here: `state:
unreadable` with the embedder's reason). Saying "not enabled" there, and
in `os knowledge status` / `rebuild`, is card item 4, part 3.

</details>

<details><summary>Gates at 72a9cbf</summary>

`dispatch-gates --ran`: 106 derived families accounted for, 105 run with
exit 0, 1 NOT MEASURED: `check:dual-build-cjs-loads` exits 3 (no `dist/`
for `@objectstack/studio`, `client-react`, `scenarios`, outside this
closure); CI runs it. Among them: `check-adr-0087-registration` (1
declared-breaking changeset, `registered
knowledge-service-held-without-embedder-or-store`),
`check-changeset-no-major`, `check-empty-changeset`, spec
`check:upgrade-guide`, `check:spec-changes`, `check:api-surface`,
`check:liveness`, `check:engine-double-contract` (after the stdio
double's fix), `check:slot-lookup` (after typing the store plugin),
`check:error-status-conformance`, `check:type-check-debt`,
`check:nul-bytes`. `check-plugin-teardown-shape --self-test` exit 0
after fetching its pinned fixture commit. `overlap-check` before the
push: clean against `main` and against objectstack-ai#38439, objectstack-ai#38435 and objectstack-ai#38268 (objectstack-ai#38418
has no PR yet).

</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01FEkQ5m2rYCwPR3qqhnZDfW

<!-- signed: repo:objectstack#5 · os-project-manager ·
session_01FEkQ5m2rYCwPR3qqhnZDfW -->

---------

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

documentation Improvements or additions to documentation protocol:ai size/m 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.

service-knowledge: a markdown section that fits maxChars is still cut into several passages

2 participants