[Bug] Session Markdown export corrupts YAML frontmatter for workspace paths containing # or colon-space

オープン 初心者向け
#4,588 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@rishibalanagu0108 がすでに取り組んでいます。

2026年11月2日 から。

  • #4622 @rishibalanagu0108 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript, yaml
領域
cli

調査の方向性

work_dir のエスケープされていない埋め込みは、apps/vscode/src/utils/session-context.ts の frontmatter 生成部分(buildExportMarkdown、34〜41行目付近)と、apps/kimi-code/src/tui/utils/export-markdown.ts(230〜240行目付近)にあります。まず issue に含まれる再現スクリプトから始めてください。3 つのパスすべてが誤って解析されることが示されるはずです。完了の条件は、'/tmp/Project #1'、'/tmp/Project: Demo'、通常のパスのそれぞれについて、両エクスポーターの frontmatter が元のパスに正確に戻ることを確認し、apps/kimi-code/test/tui/export-markdown.test.ts に回帰テストケースを追加することです。

索引モデルが issue の本文から書いたものです。

説明

What version of Kimi Code is running?

Source checkout at a2afdbc7d1fa0737d45d5780cc6c2bd38e477b55. Both affected files also match the upstream default-branch blobs fetched on 2026-11-01.

Verified by directly executing the VS Code Markdown formatter and parsing its output. This was not reproduced through an installed CLI release or a running VS Code extension.

Which open platform/subscription were you using?

N/A — local Markdown formatting; no authentication or model request is involved.

Which model were you using?

N/A.

What platform is your computer?

macOS, Darwin 24.6.0, arm64. Formatter check: Node.js 24.22.1. YAML parser: Ruby Psych 3.1.0.

The directory names below were successfully created on the local filesystem.

What issue are you seeing?

Session Markdown exports interpolate the workspace path into YAML frontmatter without quoting or escaping it. Certain valid directory names therefore corrupt the exported metadata:

Workspace path (illustrative parent directory) Parsed work_dir
/tmp/Project /tmp/Project
/tmp/Project #1 /tmp/Project — silently truncated
/tmp/Project: Demo YAML syntax error

For example:

---
work_dir: /tmp/Project #1
---

Here #1 becomes a YAML comment. With work_dir: /tmp/Project: Demo, Psych raises:

Psych::SyntaxError: mapping values are not allowed in this context

The Markdown file can still be written successfully. The failure affects downstream frontmatter consumers: they receive a wrong workspace path or cannot parse the metadata.

Both implementations contain the same unescaped interpolation:

Their export handlers pass the workspace path directly to these formatters.

What steps can reproduce the bug?

The following minimal check calls the actual VS Code formatter from the repository root, with Node.js 24.15+ and Ruby available. The resolution hook only supplies the .ts extension for the formatter's relative helper import.

node --input-type=module > /tmp/kimi-export-frontmatter.jsonl <<'JS'
import { registerHooks } from 'node:module';

registerHooks({
  resolve(specifier, context, nextResolve) {
    return nextResolve(
      specifier === './hook-parts' ? './hook-parts.ts' : specifier,
      context,
    );
  },
});

const { buildExportMarkdown } =
  await import('./apps/vscode/src/utils/session-context.ts');

for (const workDir of ['/tmp/Project', '/tmp/Project #1', '/tmp/Project: Demo']) {
  const markdown = buildExportMarkdown({
    sessionId: '00000000-0000-4000-8000-000000000001',
    workDir,
    history: [
      { role: 'user', content: [{ type: 'text', text: 'Hello' }], toolCalls: [] },
    ],
    tokenCount: 1,
    now: new Date('2026-11-01T00:00:00.000Z'),
  });
  console.log(JSON.stringify({ workDir, yaml: markdown.split('---')[1] }));
}
JS

ruby -rjson -rpsych <<'RUBY'
File.foreach('/tmp/kimi-export-frontmatter.jsonl') do |line|
  row = JSON.parse(line)
  begin
    parsed = Psych.safe_load(row.fetch('yaml'), permitted_classes: [Time])
    puts "#{row.fetch('workDir').inspect} => #{parsed.fetch('work_dir').inspect}"
  rescue Psych::SyntaxError => error
    puts "#{row.fetch('workDir').inspect} => #{error.class}: #{error.problem}"
  end
end
RUBY

Expected observed output:

"/tmp/Project" => "/tmp/Project"
"/tmp/Project #1" => "/tmp/Project"
"/tmp/Project: Demo" => Psych::SyntaxError: mapping values are not allowed in this context

Verification scope: the VS Code formatter was executed directly with a nonempty history, including a normal-path control. The CLI/TUI formatter and both callers were inspected. Full interactive CLI/TUI and VS Code integration checks have not been performed.

What is the expected behavior?

Parsing the exported frontmatter should recover the exact original workspace path, including legal filename characters such as # and : . Ordinary paths should continue to round-trip.

Additional information

A focused fix would serialize work_dir as a properly escaped YAML string in both exporters, with regression cases for ordinary paths and the two failing path forms.

Existing CLI coverage is in export-markdown.test.ts.

I searched open/closed issues and PRs for frontmatter, work_dir with export, and export YAML and did not find an equivalent report or fix. #4008 concerns parsing user-authored agent definitions, rather than generating session-export metadata.

主要言語
TypeScript
スター
8.1k
フォーク
1.3k
平均マージ
18時間 41分
マージ済み PR(30日)
186

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MoonshotAI/kimi-code のほかの issue

MoonshotAI/kimi-code の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。