MD Web — Publish Raw Markdown to S3/Docsify
Upload one raw .md file to the user's S3-compatible bucket under md-web/; a Docsify viewer in that bucket renders it at a public URL. {SKILL_DIR} is this skill's directory — always substitute the real path and quote all path arguments.
Authorization & Security Guardrails
- Public publish gate: Only an explicit request for online publication or a public/shareable link authorizes uploading (including retries). Inform the user that the link is public before uploading; resolve ambiguous sharing scope first, review and redact out-of-scope sensitive content, and publish raw Markdown (do not convert to HTML).
- Shared viewer setup gate (
--setup):--setupuploadsassets/<bundle-hash>/and replaces shared bucket-rootREADME.mdandindex.html(old assets remain for cached pages; existing document URLs stay valid). Explain affected root paths and obtain explicit authorization before running--setup --confirm-shared-writesunless already authorized in this task. Never pass--confirm-shared-writesmerely to bypass an error. - Retention policy gate (
expire_days): Setting, changing, or removing (0)expire_daysmodifies the bucket's lifecycle policy (scoped to onemd-web/rule while preserving other rules). Omitexpire_daysunless explicitly requested, and obtain authorization before changing it. - Credentials & untrusted HTML: Config and deployment hints live in
~/.md-web/config.jsonand~/.md-web/.deployed(legacy adjacent config migrates automatically with0700/0600permissions on macOS/Linux; Windows relies on user directory ACLs orMD_WEB_ACCESS_KEY/MD_WEB_SECRET_KEYenv vars; no root/elevated privileges are ever needed). Keep secrets out of chat, version control, and shared output; prefer a dedicated bucket. The viewer renders inline HTML — its CSP blocks inline scripts and its route guard restricts loads to same-originmd-web/, but page elements are not sanitized, so review unfamiliar markup before publishing.
Workflow
1. Check Configuration
Check ~/.md-web/config.json (%USERPROFILE%\.md-web\config.json on Windows).
- If the user config exists, use it and fill in any missing required fields. The script checks this file first.
- If it is absent,
upload.jsmigrates a legacyconfig.jsonbeside the script on the next setup or publish. If neither file exists, follow First-Time Configuration below.
2. Prepare Markdown Input
Use the user's existing .md file, or write chat content to a unique scratch file in the OS temp directory (/tmp/, $TEMP, %TEMP%, or $env:TEMP) and delete only that temp file after the upload attempt (never modify or delete a user file).
Viewer constraints to respect before uploading:
- Start with
# Title(sets browser tab title); YAML front matter is stripped automatically (document must be non-empty afterward). - Only the
.mdfile is uploaded — use absolutehttps://URLs for images (relative paths break). - GFM, tables,
<details>, and inline HTML render; Mermaid and LaTeX/KaTeX do not render (use tables, lists, or images instead).
3. Publish (and Setup If Prompted)
node "{SKILL_DIR}/upload.js" "<local-file>" "<remote-key>"
<remote-key>: short lowercase ASCII slug (e.g.api-docs, even for Chinese docs; non-ASCII collapses todoc). The script adds timestamp + random suffix +.mdundermd-web/so re-publishing always creates a new link.- Handling setup & lifecycle signals:
SETUP_REQUIRED: Obtain viewer-setup authorization per guardrails above, run setup, then retry the same publish command:
Setup also appliesnode "{SKILL_DIR}/upload.js" --setup --confirm-shared-writesexpire_days(note: publishing does not detectexpire_dayschanges; run setup after editingexpire_days, upgrading the viewer, or switchingbucket/endpoint).SETUP_CONFLICT: A concurrent setup changedindex.htmlor the S3 provider lacks ETag/conditional write support (If-Match/If-None-Match). Inspect the active viewer before retrying; never force-overwrite.Warning: lifecycle —: Viewer setup succeeded, but retention was not confirmed (missing lifecycle permission, unsupported/incomplete XML, rule conflict, or concurrent edit). Serialize lifecycle changes with other admins, inspect actual bucket policy, and do not blindly broaden credentials.
4. Reply & Error Triage
- Success: Last stdout line is the public URL. Reply with document title/slug, clickable link, and any material setup/retention warning (do not dump the full doc unless asked).
- Failure: Report the cause and the recovery step. Link to the existing local Markdown when available. For a document composed in chat, return the prepared text if the user still needs a copy.
| Error contains | Likely cause & fix |
|---|---|
SignatureDoesNotMatch, InvalidAccessKeyId |
Wrong credentials or wrong region (auto for R2; exact region for AWS) |
AccessDenied on upload |
Token lacks Object Read & Write or is scoped to another bucket |
NoSuchBucket |
Typo in bucket or wrong account endpoint |
CONFIG_MISSING |
Follow First-Time Configuration to create the user config. |
CONFIG_INVALID |
Follow the specific diagnostic. For a JSON error, repair the existing file locally as a JSON object. Preserve its fields and keep credential values out of logs. |
ENOTFOUND or invalid endpoint/URL |
Check the S3 API hostname in endpoint and the viewer's HTTP(S) address in public_url (prefer HTTPS). |
Missing config fields |
Complete config.json or export MD_WEB_ACCESS_KEY / MD_WEB_SECRET_KEY |
| Page shows "Looking for a document?" | Document expired (expire_days) or public_url points to another bucket |
First-Time Configuration
- Explain that an S3-compatible bucket with public read access is required; reference README.md (中文) for R2/S3/B2/Spaces/Wasabi/COS steps.
- Gather required fields (
endpointwithouthttps://,bucket,public_url— custom domain recommended over rate-limitedr2.dev— andaccess_key/secret_keywith Object Read & Write). Offer that the user edit~/.md-web/config.jsondirectly or exportMD_WEB_ACCESS_KEY/MD_WEB_SECRET_KEY(file takes precedence if both exist) to keep secrets out of chat. - Optional fields:
region(defaultauto; AWS needs real region e.g.us-east-1),expire_days(omit unless requested; requires provider lifecycle permission — R2 Admin Read & Write or AWS PutBucketLifecycleConfiguration). - Create
~/.md-web/(0700on macOS/Linux) and write~/.md-web/config.json(0600before writing secrets):{ "access_key": "...", "secret_key": "...", "endpoint": "ACCOUNT_ID.r2.cloudflarestorage.com", "bucket": "md-web", "region": "auto", "public_url": "https://pub-XXXX.r2.dev" } - Run
--setup --confirm-shared-writeswhen viewer setup is authorized. Continue to document upload only if the user also requested publication.
