Skip to content

feat(ai): a skill names the context pack it works from, and its MCP prompt takes a record id - #37552

Draft
objectstack-fleet[bot] wants to merge 10 commits into
mainfrom
claude/issue-37141-skill-context-key
Draft

objectstack-fleet[bot] wants to merge 10 commits into
mainfrom
claude/issue-37141-skill-context-key

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #37141

Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: follow-up owed — skills/objectstack-ai/references/context-packs.md, skills/objectstack-ai/SKILL.md

维护者速读

  • 用户能看到什么变化:写技能的作者可以给技能指定一个资料包;外部 AI 经 MCP 调这个技能时可以带一条记录的编号,提示词会让模型先读这条记录的资料。不带编号时提示词和以前完全一样。
  • 为什么做:这是「记录 AI 问询」专题的第 8 行,把技能和资料包连起来,应用内助手(第 9 行,云端)也要读这个键。
  • 出错会怎样:只影响声明了这个新键的技能;没有技能用到它时一切照旧。可以直接撤回这个合并。
  • 要你做的:无。

What changes

ADR-0160 D8, with point 1's advisory (D1, amended 2026-11-25) and ADR-0150's addendum of 2026-11-25, reader 2.

  1. packages/spec — SkillSchema.context?: string, a bare pack name (ROUTER_ADDRESSABLE_NAME_PATTERN; a face like acme-policy_document is refused). A skill that declares it and does not bind get_record_context in tools (by name or a matching wildcard) is refused at parse, located on tools (refuseUnboundRecordContext, a superRefine). skillBindsRecordContextTool(tools) is the one predicate both the refusal and the lint advisory ask. Liveness row in liveness/skill.json naming its reader; a context control in skill.form.ts.
  2. packages/mcp/src/skill-prompts.ts — skillPromptRecordContext resolves a skill's context by the one rule (resolvePackageScopedHolders, ADR-0150 D3) over the same pack listing get_record_context selects from: from the skill's own package (own pack, else the one holder in its closure), or as a caller with no package for an environment skill; a refusal resolves to no pack, never one picked by order. The pack is handed on by its face (deriveAiFaceName), so the tool's selection reads back exactly that pack. When it resolves, prompts/list lists one optional argument, recordId; given, the one message is instructions, a blank line, SKILL_PROMPT_RECORD_CONTEXT_LINE, and the call as one JSON object {objectName, recordId, context}. The id is only ever a JSON.stringify string value; the pack is never inlined. Without the argument (or with a context that resolves to no pack) the result is byte-identical to the same skill without the key. A blank id is refused -32602. McpSkillBridge gains optional listContextPacks and packageResolutionClosure.
  3. Both MCP doors — the per-request HTTP surface (registerSkillPrompts) and the long-lived stdio server (MCPServerRuntime.bridgePrompts, which now lists packs through the same merged read and takes the closure as an optional 4th argument; plugin.ts passes it from the engine registry through packageResolutionClosure). packages/runtime/src/domains/mcp.ts hands the /mcp bridge the same pack listing the record-context members read (one function, hoisted) and the skill's package closure.
  4. packages/lint — inside validateAiToolReferences (where skills are validated, os validate): ai-skill-context-unknown (a context naming no pack the stack defines) and ai-skill-context-omitted (a skill binding get_record_context without context while an object has more than one pack; one finding per such object). Both warnings.
  5. Generated — authorable-surface/ai.json, api-surface/ai.json, export-origins/ai.json, liveness/state-counts/skill.md, content/docs/references/ai/skill.mdx, skills/objectstack-ai/references/_index.md (the skill-refs mirror: skill.zod.ts now imports record-context-tools.zod.ts), and five new sites in dropped-refinements.baseline.json (the new refinement does not project into JSON Schema; the build printed the corrected entries, copied verbatim, header total 1210 → 1215).

skills/** readings (generated mirror only): skills/objectstack-ai/references/_index.md 52 → 53 lines; every SKILL.md summed 4961 → 4961 lines (none touched).

Tests

  • packages/spec/src/ai/skill.test.ts — parse refusal without the binding (located on tools), wildcard bindings, control without context, face/non-snake refused, the predicate.
  • packages/mcp/src/skill-prompts.test.ts — the argument list; the message shape with and without the argument; the record id only as a JSON string value (a hostile id with quotes and newlines); a context naming no pack lists no argument and the prompt is unchanged; a connection that does not serve get_record_context does not serve the skill (skillBindingServed); a blank id refused; D3 resolution (own package, closure, environment, refusal → no pack); the long-lived stdio server answering the same messages as the HTTP door.
  • packages/lint/src/validate-ai-tool-references.test.ts — unknown pack (with near-miss), the item-6 advisory incl. a wildcard binding, and controls.
  • packages/runtime/src/domains/mcp-merged-skill-read.test.ts — the /mcp bridge lists packs (read decorations stripped) only where the record-context seam is served, and the closure is the one walk over the engine registry.

Ablations (both committed first, each restored with blob == HEAD proven by scripts/ablation-replace.mjs):

  • Parse refusal: anchor if (skillBindsRecordContextTool(skill.tools)) return; → always return. skill.test.ts: 1 failed / 25 passed (the refusal case). Restored blob f49db7f7.
  • Record id as JSON only: the line joined with The record is ${recordId}. → skill-prompts.test.ts: 2 failed / 48 passed (message shape, record-id-only-in-JSON). Restored blob bc176cb1.

Acceptance notes

  • The card's "expected" ai-skill-tool-unresolved warning for mcpPrompt: false + context no longer fires on this tree: Row 9, objectstack half: get_record_context joins PLATFORM_TOOLS_BY_PACKAGE and gets its chatbot.tool label in every locale #37190 already put get_record_context into PLATFORM_TOOLS_BY_PACKAGE['service-ai'], so the name resolves for an in-product skill (validate-ai-tool-references.test.ts "resolves get_record_context on a mcpPrompt: false skill" pins that). Nothing was suppressed here.
  • Lint judges context against the stack's own aiContexts (one holder, D3 step 1); a pack only a dependency package ships is reported as unknown by os validate. The runtime prompt resolves it through the closure.
  • A host without packageResolutionClosure resolves a package skill's context to its own package's pack only, never environment-wide.
  • The file surface reached packages/mcp/src/mcp-server-runtime.ts, packages/mcp/src/plugin.ts and packages/runtime/src/domains/mcp.ts (+ its skill-read test): the bridges that feed the prompt surface; without them the key would have no reader at run time.

Verification

Two-minute check

pnpm --filter @objectstack/mcp exec vitest run src/skill-prompts.test.ts -t "a skill with context takes a record" — 14 cases green (incl. the nested resolution block); the "given the record id" case prints the message as instructions, the fixed line, then {"objectName":"policy","recordId":"pol_1","context":"policy_document"}.

Read first: packages/mcp/src/skill-prompts.ts (skillPromptRecordContext, skillPromptResult), packages/spec/src/ai/skill.zod.ts (refuseUnboundRecordContext), packages/mcp/src/mcp-server-runtime.ts (bridgePrompts registration with argsSchema).


Generated by Claude Code

https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc

@github-actions github-actions Bot added size/xl 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 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 5 package(s): @objectstack/lint, @objectstack/mcp, @objectstack/platform-objects, @objectstack/runtime, @objectstack/spec, touching 43 documentable anchor(s). ⚠️ 7 changed file(s) yielded no anchor (packages/lint/src/index.ts, packages/spec/api-surface/ai.json, packages/spec/authorable-surface/ai.json, …), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

56 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 411646562566a1e12b4e0fc3de256192e8302719.

⛔ 20 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 7 changed file(s) yielded no anchor (packages/lint/src/index.ts, packages/spec/api-surface/ai.json, packages/spec/authorable-surface/ai.json, …) — pages documenting those are invisible to this run
  • 1 anchor(s) matched too much of the corpus to be a work list: objectName (symbol, 60 pages)
  • 7 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 — 187 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 411646562566a1e12b4e0fc3de256192e8302719 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 411646562566a1e12b4e0fc3de256192e8302719

⚠️ 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 411646562566a1e12b4e0fc3de256192e8302719 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…ntrol; pay the metadata load at collection

The skill form's new `context` control moves the platform-objects metadata-form
bundles (check:i18n), and the runtime bridge test reaches a lazy
`@objectstack/metadata` import (check:test-source-alias).

Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com>
…shipped locale

The extractor fills a new leaf with the source text; the echo-decision pins
require the metadata-form catalog to carry no fills, so the label and help
text are authored per locale and the positive-control count moves 837 → 838.

Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
Co-authored-by: Claude <noreply@anthropic.com>
…ill-context-key

# Conflicts:
#	packages/platform-objects/src/apps/translations/object-lifecycle-panel-echo-decisions.test.ts

This branch has not been deployed

No deployments
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/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.

记录 AI 问询 8:技能键 context,MCP 技能提示词可带记录参数

2 participants