Skip to content

feat(kap-server): keep client metadata on prompts and skill activations - #3764

Merged
chengluyu merged 13 commits into
mainfrom
integration/browser-core-main
Sep 16, 2026
Merged

chengluyu merged 13 commits into
mainfrom
integration/browser-core-main

Conversation

@chengluyu

@chengluyu chengluyu commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

POST /sessions/{id}/prompts already accepts an optional metadata object, and the route discards it. Skill activation has no equivalent field.

A client often sends the model something different from what the user saw in the editor — a mention expanded into its full context, for example. It then has no way to:

  1. restore its own editor state for that message when the conversation is reopened, and
  2. get a session title, undo label, or fork title that reads like what the user typed rather than the expanded model input.

What changed

Treat metadata as opaque client metadata that the server stores and echoes back and never adds to model content.

  • REST. metadata on prompt submission is now kept, and skill activation accepts the same field. Either is stored as clientMetadata: [metadata] on the user or skill-activation origin, and prompt items echo it back as metadata.

  • Core. clientMetadata lives on UserPromptOrigin and SkillActivationOrigin, and travels on prompt.submitted / prompt.queued. When steered messages merge, each message keeps its own entry, in order; a message that had none gets { display_text } built from its visible text, so the merged list still lines up with the messages.

  • Transcript. clientMetadata is added to both TranscriptUserOrigin variants and to TranscriptPrompt, and carried across the prompt lifecycle by the projector and the transcript snapshot. The history rebuild now keeps the user origin as the turn payload, so metadata also survives a cold reload.

  • Display text. When every entry carries a string display_text, it replaces the model-facing text for session titles, undo labels, fork titles and skill-activation titles. Otherwise the existing text is used unchanged.

  • Skill prompts. A skill activated while idle runs as a tracked prompt with a skill_activation origin; the prompt listing and live transcript backfill read its metadata too.

  • Path-free turn payloads. User turn payloads, live and rebuilt, go through projectTranscriptUserTurnOrigin, which keeps kind, client metadata and skill names/args and drops attachment and skill paths. The live projector previously exposed the raw origin; the rebuild now matches it without the paths.

Guarantees covered by tests

  • Client metadata never reaches model content; a literal present only in the metadata is absent from the model input.
  • Metadata survives a single activation plus a cold resume, and appears on the rebuilt turn's origin payload.
  • Steered prompts keep their metadata in FIFO order, including a mix of prompts with and without it.
  • The prompt lifecycle (submitted → queued → started → completed) keeps metadata on the prompt entity.
  • Titles, undo labels and fork titles use display_text when present.
  • No server-local path appears in a live or rebuilt user turn.
  • Metadata is listed for an active skill-activation prompt, directly and through the transcript backfill.

Validation

  • Typecheck clean for @moonshot-ai/transcript, @moonshot-ai/agent-core-v2, @moonshot-ai/kap-server.
  • @moonshot-ai/transcript 121 passed.
  • @moonshot-ai/agent-core-v2 6728 passed, including the regenerated state manifest.
  • @moonshot-ai/kap-server: 70 failures, all in test/search/searchRoute.test.ts and searchService.test.ts, matching main on the same machine.

No changeset: this adds an optional protocol field that first-party CLI surfaces do not send, so there is nothing user-perceivable in the CLI.

@changeset-bot

changeset-bot Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dcab5a8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chenweigao

Copy link
Copy Markdown

desktop 要来了吗

Preserve client input metadata, rich skill context, and optional media names for the desktop browser test branch. This is a temporary integration snapshot, not a proposed final protocol design.
@chengluyu
chengluyu force-pushed the integration/browser-core-main branch from e2cbe99 to 29bb971 Compare September 14, 2026 13:44
The desktop composer does not carry its document snapshot through steer, so
the inputs payload on PromptSteered had no producer. Remove the event field,
its loop population and the transcript projector restore, and keep the
client metadata carried by submit and queue events.
…field

Main now accepts text parts in activateSkillAttachmentSchema, so the separate
content field and its concatenation onto attachments are redundant. Send the
ordered parts as attachments instead and keep the metadata field, which
carries client metadata.

Keep both sides of the promptService and skills test additions.
…unning turn

Activating a skill while a turn is running submits it as a steer whose origin
kind is skill_activation. onTurnSteered returned an empty op list for any
origin that was not user, so no frame was created: the agent received the
input and the transcript kept no record of it.

Accept the origin when its trigger is user-slash, which is the form a person
types, and keep ignoring model-tool activations. Widen TranscriptUserOrigin
and its contract schema to carry that shape, and project the skill name and
args through.

Take no prompt id for those frames. unpairedSteerPromptIds is filled by
prompt.steered and drained one entry per user steer frame, and a skill
activation never enqueues a prompt, so draining there would label the
activation with an id belonging to another prompt and leave that prompt's own
frame unlabelled. Clients match frames to pending messages by those ids, so a
frame without one renders twice.
A file attachment on a steered prompt or slash skill lives only in the
origin's attachments; the steer input carries a text notice instead of a
media part. steerUserFrame projected media parts from the input and ignored
the origin, so the live frame had no attachment while cold reconstruction
added it from the same origin, and the file appeared only after a reload.

Project the origin's file attachments with the name, media type and size
that onTurnStarted and the history rebuild already use, leaving the path
out, on both the immediate and the deferred steer paths.
@chengluyu chengluyu changed the title chore: publish temporary core integration for desktop browser testing feat(kap-server): keep client metadata on prompts and skill activations Sep 16, 2026
@chengluyu
chengluyu marked this pull request as ready for review September 16, 2026 09:16
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-16T09:54:41.153226Z dcab5a8 New commits
🔒 Security Review ✅ Completed 2026-09-16T09:55:27.608104Z dcab5a8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@dcab5a8
npx https://pkg.pr.new/@moonshot-ai/kimi-code@dcab5a8

commit: dcab5a8

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 888e703ce4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…yloads

A skill activated while the loop is idle runs as a tracked prompt whose
origin kind is skill_activation, and both the prompt listing and the live
transcript backfill read client metadata only from user origins, so the
metadata disappeared while that turn ran. Read it from either kind.

The history rebuild copied the persisted user origin into the public turn
payload, which carries attachment paths and bundled skill paths. The live
projector already did the same. Project both through
projectTranscriptUserTurnOrigin, which keeps the kind, client metadata and
skill names and args, so live and rebuilt turns share one path-free payload.
@chengluyu
chengluyu merged commit 41eac5d into main Sep 16, 2026
15 checks passed
@chengluyu
chengluyu deleted the integration/browser-core-main branch September 16, 2026 09:56
7723qqq added a commit to 7723qqq/kimi-code that referenced this pull request Sep 17, 2026
…#3764)

The transcript-contract half of this upstream change landed with the 2.0.0
merge (clientMetadata on the user/skill-activation origin, the path-free user
turn projection). This wires the engine half so the metadata actually reaches
persistence:

- turns gains an origin column (idempotent ALTER TABLE migration);
  save_turn/list_turns/TurnRecord carry it.
- The REST prompt route reads the request's `metadata` (a non-object is a
  400), wraps it as the one-element clientMetadata array, echoes it on the
  prompt item and the prompt.submitted event, and passes the built origin
  through the prompt queue (admit/advance/take_queued) into
  run_turn_with_media and save_turn.
- The v3 projector derives the turn's origin kind from the persisted record
  via TurnOrigin::from_kind instead of hardcoding `user`; `task` falls back to
  `user` because the wire kind needs a task_id the turn record does not carry.
- Metadata never reaches model content, matching upstream.

Also applies MoonshotAI#3879, which upstream pushed after the tag: the engine's system
prompt template drops the "never read, write, or execute files outside the
working directory" sentence, keeping the "not a sandbox" framing.

MoonshotAI#3762 (api_key_env for provider credentials) is recorded as tracked debt: the
commit reshapes credential resolution across 80 files including the retired
engine, and needs its own triage round against the fork's credential flow.

Tests: client_metadata_rides_the_item_and_the_run (prompt queue),
test_turn_origin_persists_and_projects (store round-trip); full suite 2629
passed / 0 failed; clippy -D warnings and fmt clean; parity and delta gates
pass.
7723qqq added a commit to 7723qqq/kimi-code that referenced this pull request Sep 18, 2026
…eam entry rules

Upstream uses client displayTexts for prompt-derived metadata only under
explicit rules; the native harness preferred a displayText whenever one was
present. Align the per-entry and set-wide behaviors:

- applyPromptMetadata now takes the content-derived fallback and the raw
  client displayText separately and applies the per-entry preference itself:
  a supplied displayText is sanitized (secret redaction, control stripping,
  truncation) and used alone, never mixed with the fallback. Previously the
  raw displayText bypassed promptMetadataTextFromText entirely.
- Every applied entry appends a NativePromptMetadataRecord (text,
  hasDisplayText, raw displayText) to NativeSessionMeta.promptMetadata in
  submission order, in memory.
- Export displayTextForUndoOrForkLabel: the all-entries set judgment behind
  upstream's undo-label and fork-title derivations. It returns the sanitized
  displayText join only when every record carries a displayText, else
  undefined (fall back to text derivation). The SDK has no undo-label or
  fork-title decision points yet, so this is the wiring seam, documented at
  the helper.
- steer honors skipPromptMetadata like prompt; the busy skill-activation
  resubmission passes it so the activation applies its metadata exactly once
  (upstream applies promptMetadataTextFromSkill once) instead of having its
  displayText clobbered by a second derivation from the rendered skill text.

clientMetadata stays optional; no type surface changes.
7723qqq added a commit to 7723qqq/kimi-code that referenced this pull request Sep 18, 2026
…ext semantics

P2-1: applyPromptMetadata builds the NativePromptMetadataRecord with plain
shorthand { displayText } instead of a conditional spread — the repo
convention (AGENTS.md General Coding Rules) for optional properties, and
behavior-identical since exactOptionalPropertyTypes is off and the only
consumer filters on displayText !== undefined.

P2-2: displayTextForUndoOrForkLabel's JSDoc now distinguishes the two causes
of an undefined result, mirroring upstream (promptMetadataText.ts +
applyPromptMetadataUpdate): a record without displayText (or an empty set)
falls the derivation back to text-derived metadata, while an all-displayText
set whose sanitized join is empty (every entry displayText: '') means
upstream applies no metadata update at all — no text-derived fallback. The
doc names the every(hasDisplayText) discriminator for future undo/fork
consumers. No behavior change: the helper already returns undefined for both
cases and has no call sites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants