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

Đang mở Phù hợp với người mới
#4,588 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@rishibalanagu0108 đang làm issue này rồi.

Từ ngày 2/11/2026.

  • #4622 của @rishibalanagu0108 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript, yaml
Lĩnh vực
cli

Hướng nghiên cứu

Phép nội suy work_dir không được escape nằm trong bộ tạo frontmatter tại apps/vscode/src/utils/session-context.ts (buildExportMarkdown, khoảng dòng 34-41) và trong apps/kimi-code/src/tui/utils/export-markdown.ts (khoảng dòng 230-240). Bắt đầu với script tái hiện lỗi trong issue, script này sẽ cho thấy ba đường dẫn đều bị phân tích sai. Hoàn thành khi frontmatter của mỗi trình xuất, khi phân tích lại, cho đúng đường dẫn gốc với '/tmp/Project #1', '/tmp/Project: Demo' và một đường dẫn thông thường, và các trường hợp hồi quy được thêm vào apps/kimi-code/test/tui/export-markdown.test.ts.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
8.1k
Fork
1.3k
Merge trung bình
16 giờ 21 phút
Pull request đã merge (30 ngày)
227

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của MoonshotAI/kimi-code

Tất cả issue của MoonshotAI/kimi-code

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.