canonical_id: "km_writer"
display_name: "KM Writer"
category: "api"
version: "v1"
wasi_target: "preview1"
stability: "floating"
runtime_compat:
  - "cf-workers"
  - "workerd"
constraints:
  max_size_kb: 2048
  max_cold_start_ms: 50
  no_network_syscall: false
  no_filesystem_syscall: true
  io_model: "stdin_stdout_json"
input_schema:
  type: object
  required: [action, mira_url, token]
  properties:
    action:
      type: string
      description: "操作類型：read_journal | read_journal_date | append_journal | list_pages | read_page | write_page"
      enum: [read_journal, read_journal_date, append_journal, list_pages, read_page, write_page]
    mira_url:
      type: string
      description: "Mira 服務基礎 URL（例：https://mira.uncle6.me）"
    token:
      type: string
      description: "Mira MIRA_TOKEN（Bearer token）"
    content:
      type: string
      description: "內容（append_journal / write_page 時必填）"
    timestamp:
      type: string
      description: "ISO 8601 時間戳（append_journal 時選填，影響日期和時間顯示）"
    date:
      type: string
      description: "日期 YYYY-MM-DD（read_journal_date 時必填）"
    name:
      type: string
      description: "頁面名稱（read_page / write_page 時必填）"
output_schema:
  type: object
  properties:
    success:
      type: boolean
    data:
      type: object
      description: "Mira API 回應資料"
    error:
      type: string
      description: "錯誤訊息（success=false 時）"
gherkin_tests:
  - scenario: "缺少 action"
    given: '{"mira_url":"https://mira.uncle6.me","token":"abc"}'
    then_contains: '{"success":false'
  - scenario: "缺少 token"
    given: '{"action":"list_pages","mira_url":"https://mira.uncle6.me"}'
    then_contains: '{"success":false'
tags: [km, journal, logseq, mira, knowledge-management]
description: "讀寫 Mira leo-graph 的 journals 和 pages。透過 host function 呼叫 Mira /km/* API，支援讀取、新增日誌條目，以及讀寫頁面。"
config_example: |
  append_to_journal:
    action: "append_journal"
    mira_url: "https://mira.uncle6.me"
    token: "<mira_token>"
    content: "今天完成了 arcrun km_writer 元件"
