Gist Code Share
When returning code:
- 1. If code is 10 lines or fewer, inline code block is allowed.
- If code is over 10 lines, prefer GitHub Gist.
- Default to secret gist unless user asks for public.
- Return a short summary + gist URL; avoid pasting long duplicate code in chat.
- Never publish secrets in shared code. If sensitive values are needed, use placeholders and tell user to fill them locally.
Required checks
- - Verify GitHub CLI auth: INLINECODE0
- If not authenticated (or missing gist scope), ask user to run: INLINECODE1
- Keep behavior simple: do not auto-fallback to alternate sharing backends by default; prefer guiding user to configure GitHub properly.
Sensitive data policy (mandatory)
Before sharing code, scan for sensitive data and remove it.
- - Never include API keys, tokens, passwords, private keys, cookies, session IDs, webhook secrets, phone/email PII, or absolute local secret paths.
- If code requires secrets, replace with placeholders, for example:
-
API_KEY="<FILL_ME>"
-
TOKEN="<YOUR_TOKEN_HERE>"
-
.env entry with empty value
- - Add a short note telling the user to fill placeholders locally after copying.
Update mode (same URL)
When user asks to modify previously shared code, prefer updating the same gist link (new revision) instead of creating a new gist.
Use:
CODEBLOCK0
Behavior:
- - Keep the same gist URL.
- Save changes as a new revision.
- Return the same fixed 3-line response format.
Create a new gist only when:
- - user explicitly asks for a new link, or
- existing gist is not editable by current GitHub account.
Create gist
Use:
CODEBLOCK1
If code is generated in-session, write it to a temp file in workspace first. Use language-appropriate extension (.py, .js, .ts, etc.) so Gist syntax highlighting works well.
With bundled script:
CODEBLOCK2
If <file> has no extension, pass [lang] (for example python, typescript) so the script can upload with a proper extension.
Default behavior: do not use --web (automation-friendly).
Optional: use --web only when the user explicitly asks to open the gist in browser immediately.
Response format (fixed)
Always use exactly this 3-line format:
- 1. One sentence on what was shared.
- Gist URL (separate line).
- INLINECODE14
Example:
Shared the full script as a secret Gist for clean copy/paste.
https://gist.github.com/...
File: lc761_solution.py · Lines: 42
Gist 代码分享
返回代码时:
- 1. 若代码不超过10行,允许使用内联代码块。
- 若代码超过10行,优先使用GitHub Gist。
- 默认创建私密Gist,除非用户要求公开。
- 返回简短摘要+Gist链接;避免在聊天中粘贴冗长的重复代码。
- 切勿在共享代码中泄露机密信息。若需敏感值,请使用占位符并告知用户在本地填写。
必要检查
- - 验证GitHub CLI认证状态:gh auth status
- 若未认证(或缺少gist权限),请用户运行:gh auth login
- 保持行为简洁:默认不自动回退到其他共享后端;优先引导用户正确配置GitHub。
敏感数据处理策略(强制)
共享代码前,扫描并移除敏感数据。
- - 切勿包含API密钥、令牌、密码、私钥、Cookie、会话ID、Webhook密钥、电话/邮箱等个人身份信息,或本地绝对路径中的机密信息。
- 若代码需要机密信息,请替换为占位符,例如:
- API_KEY=<请填写>
- TOKEN=<你的令牌在此>
- .env条目留空值
- - 添加简短提示,告知用户在复制后本地填写占位符。
更新模式(相同链接)
当用户要求修改之前共享的代码时,优先更新同一Gist链接(新修订版本),而非创建新Gist。
使用命令:
bash
./scripts/update_gist.sh <文件> <简短描述> [public|secret] [lang]
行为:
- - 保持相同Gist链接。
- 将更改保存为新修订版本。
- 返回相同的固定3行响应格式。
仅在以下情况创建新Gist:
- - 用户明确要求新链接,或
- 当前GitHub账户无法编辑现有Gist。
创建Gist
使用命令:
bash
gh gist create <文件> --desc <简短描述>
若代码在会话中生成,先将其写入工作区的临时文件。使用语言对应的扩展名(.py、.js、.ts等),以确保Gist语法高亮正常工作。
使用捆绑脚本:
bash
./scripts/create_gist.sh <文件> <简短描述> [public|secret] [lang]
若<文件>没有扩展名,请传递[lang](例如python、typescript),以便脚本使用正确扩展名上传。
默认行为:不使用--web(便于自动化)。
可选:仅当用户明确要求立即在浏览器中打开Gist时,使用--web。
响应格式(固定)
始终使用以下精确的3行格式:
- 1. 一句话说明共享内容。
- Gist链接(单独一行)。
- 文件:<文件名> · 行数:<行数>
示例:
已将完整脚本作为私密Gist共享,便于整洁复制粘贴。
https://gist.github.com/...
文件:lc761_solution.py · 行数:42