Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(plugins): 收录 requirements-box 插件(收需求的页面 + 定时巡台 + 每轮邮件)

lmliheng2f62dc0f3de5
diff --git a/README.zh.md b/README.zh.md
index 8e1d0881..b0ee15a0 100644
--- a/README.zh.md
+++ b/README.zh.md
@@ -72,7 +72,7 @@ https://github.com/user-attachments/assets/aec49ae9-b743-467b-b247-37bedfeaa36e
| 分类 | 插件 |
| ----------- | ------------------------------------------------------------------------------- |
-| 办公效率 | `data-analysis`、`use-firecrawl`、`browser-automation`、`use-bento-slides`、`humanizer`、`goal`、`continual-learning`、`csu-mail`、`lesson-video` |
+| 办公效率 | `data-analysis`、`use-firecrawl`、`browser-automation`、`use-bento-slides`、`humanizer`、`goal`、`continual-learning`、`csu-mail`、`lesson-video`、`requirements-box` |
| 软件开发 | `software-development`、`use-claude-code`、`wechat-miniprogram` |
| AI 应用开发 | `agent-development`、`model-development`、`skill-porting`、`agent-tuning` |
| Agent 公司 | `agent-company` |
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 2bee2ec4..345fac51 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -35,6 +35,7 @@
"@lmliheng/humanizer": "workspace:*",
"@lmliheng/lesson-video": "workspace:*",
"@lmliheng/model-development": "workspace:*",
+ "@lmliheng/requirements-box": "workspace:*",
"@lmliheng/skill-porting": "workspace:*",
"@lmliheng/software-development": "workspace:*",
"@lmliheng/use-bento-slides": "workspace:*",
diff --git a/packages/core/package.json b/packages/core/package.json
index 91ab4a41..a9bfe09c 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -68,6 +68,7 @@
"@lmliheng/humanizer": "workspace:*",
"@lmliheng/lesson-video": "workspace:*",
"@lmliheng/model-development": "workspace:*",
+ "@lmliheng/requirements-box": "workspace:*",
"@lmliheng/skill-porting": "workspace:*",
"@lmliheng/software-development": "workspace:*",
"@lmliheng/use-bento-slides": "workspace:*",
diff --git a/packages/core/test/plugins.test.ts b/packages/core/test/plugins.test.ts
index c1f0a204..4cfb94cf 100644
--- a/packages/core/test/plugins.test.ts
+++ b/packages/core/test/plugins.test.ts
@@ -65,7 +65,7 @@ describe("loadLibraryPlugins", () => {
it("loads every plugin directory sorted by name, each with a date-sequence version and a category", () => {
const plugins = loadLibraryPlugins();
expect(plugins.map((p) => p.name)).toEqual([...plugins.map((p) => p.name)].sort());
- expect(plugins.length).toBe(17);
+ expect(plugins.length).toBe(18);
for (const plugin of plugins) {
expect(plugin.version, plugin.name).toMatch(PLUGIN_VERSION_PATTERN);
expect(
@@ -213,6 +213,7 @@ describe("groupPlugins / loadPluginGroups", () => {
"goal",
"humanizer",
"lesson-video",
+ "requirements-box",
"use-bento-slides",
"use-firecrawl",
]);
diff --git a/packages/desktop/package.json b/packages/desktop/package.json
index 1c4a077f..ee04b05b 100644
--- a/packages/desktop/package.json
+++ b/packages/desktop/package.json
@@ -27,6 +27,7 @@
"@lmliheng/humanizer": "workspace:*",
"@lmliheng/lesson-video": "workspace:*",
"@lmliheng/model-development": "workspace:*",
+ "@lmliheng/requirements-box": "workspace:*",
"@lmliheng/skill-porting": "workspace:*",
"@lmliheng/software-development": "workspace:*",
"@lmliheng/use-bento-slides": "workspace:*",
diff --git a/packages/docs/content/skills.en.md b/packages/docs/content/skills.en.md
index 53e6ef08..9c90399e 100644
--- a/packages/docs/content/skills.en.md
+++ b/packages/docs/content/skills.en.md
@@ -224,6 +224,7 @@ The built-in plugins, by category (`PLUGIN_CATEGORIES` in `packages/core/src/plu
| | `continual-learning` | When a Task ends after more than 30 turns, hands its condensed excerpt to a background subagent that folds the durable findings into the agent's Skills (not preinstalled) |
| | `csu-mail` | Manage a Coremail mailbox (CSU student mail, `mail.csu.edu.cn`): generate a client app password once, then list, search, read and send mail over IMAP/SMTP, with a copy kept in the Sent folder — daily mail work never touches the unified auth portal (not preinstalled) |
| | `lesson-video` | Turn a written script into a narrated vertical lesson video (1080×1920, Douyin / Reels ready) and its cover art: an HTML deck pinned to a timeline, edge-tts voice-over with word-level timing, Playwright frame capture, an ffmpeg mux, edge safe areas left empty for mobile app buttons, a pre-render self-check for overflow and clipping, and publishing copy with at most five tags (not preinstalled: install from the library when needed) |
+| | `requirements-box` | Stand up a requirements box: one keyed page where the user files what they want done (edit, withdraw, select several and act in bulk, schedule an item), a scheduled task that wakes the agent to work through it, and a per-round report by mail. The service is one dependency-free Node file (a JSON store, a keyed GET/POST/PATCH API, the page it serves, and a do-it-now button that starts a session), the patrol protocol a markdown file the user can rewrite, and the installer lays both down and registers the schedule (not preinstalled: install from the library when needed) |
| Software Development | `software-development` | Software development end to end, with two Skills: `software-engineering` (investigate, implement and validate with minimal scope) and `web-design` (the Penguin visual language for generated web UIs) |
| | `use-claude-code` | Run Claude Code on a remote host over SSH: a persistent expect session, headless `-p` with the stdin fix, a tmux-driven interactive TUI and multi-turn continuity (not preinstalled: install from the library when needed) |
| | `wechat-miniprogram` | Take a WeChat mini-program from code to published on a headless Linux server: QR login to mp.weixin.qq.com, switching from a public account to the mini-program backend, the AppID and upload key, IP whitelisting, upload with miniprogram-ci, a verified preview QR, the mandatory user-privacy policy, review and release (not preinstalled) |
diff --git a/packages/docs/content/skills.zh.md b/packages/docs/content/skills.zh.md
index 0f6d78a5..9af0116d 100644
--- a/packages/docs/content/skills.zh.md
+++ b/packages/docs/content/skills.zh.md
@@ -224,6 +224,7 @@ Agent 可以在 Task 中重写自己的 `SKILL.md`。结合 Benchmark 评估和
| | `continual-learning` | Task 运行超过 30 轮才结束时,把 Task 的精简摘录交给后台子 Agent,由它把有长期价值的发现沉淀到 Agent 的 Skill 中(不预装) |
| | `csu-mail` | 管理中南大学 Coremail 邮箱(`mail.csu.edu.cn`):一次性生成客户端专用密码,之后用 IMAP/SMTP 从命令行查信、检索、读信、发信,并在「已发送」留底——日常收发信完全不碰统一身份认证(不预装) |
| | `lesson-video` | 把写好的讲稿做成竖屏教学视频(1080×1920,抖音 / Reels 规格)与配套封面:HTML 课件按时间轴定格、edge-tts 逐词对齐配音、Playwright 逐帧截图、ffmpeg 合成,两侧与上部按手机 App 按钮留出安全区,渲染前先自检越界与裁切,并给出标签不超过五个的发布文案(不预装:需要时从插件库安装) |
+| | `requirements-box` | 立起一个需求箱:一页受口令保护的表单让用户随手提需求(可编辑、撤回、多条勾选批量处理、按条目排期),一个定时任务按节奏叫 Agent 来做,每轮一封邮件汇报。服务是一个零依赖的 Node 文件(JSON 存储、带口令的 GET/POST/PATCH 接口、它自己那一页、以及立刻开会话开工的按钮),巡台协议是一份可改写的 Markdown,安装脚本把文件摆好并登记定时任务(不预装:需要时从插件库安装) |
| 软件开发 | `software-development` | 端到端的软件开发,包含两个 Skill:`software-engineering`(在最小范围内调查、实现和验证)和 `web-design`(生成 Web UI 用的 Penguin 视觉语言) |
| | `use-claude-code` | 通过 SSH 在远程主机上运行 Claude Code:持久 expect 会话、带 stdin 修复的无头 `-p` 模式、tmux 驱动的交互式 TUI,以及多轮连续性(不预装:需要时从插件库安装) |
| | `wechat-miniprogram` | 在无桌面的 Linux 服务器上把微信小程序从代码做到发布:扫码登录 mp.weixin.qq.com、从公众号后台切到小程序后台、取 AppID 与上传密钥、加 IP 白名单、用 miniprogram-ci 上传、交付校验过的预览码、填写必填的用户隐私保护指引、提交审核与发布(不预装) |
diff --git a/plugins/README.md b/plugins/README.md
index ca33a318..5cfa42d4 100644
--- a/plugins/README.md
+++ b/plugins/README.md
@@ -8,12 +8,12 @@ Included plugins, by category (`PLUGIN_CATEGORIES` in `packages/core/src/plugins
| Category | Plugins |
| --- | --- |
-| Office Productivity | `data-analysis`, `use-firecrawl`, `browser-automation`, `use-bento-slides`, `humanizer`, `goal`, `continual-learning`, `csu-mail`, `lesson-video` |
+| Office Productivity | `data-analysis`, `use-firecrawl`, `browser-automation`, `use-bento-slides`, `humanizer`, `goal`, `continual-learning`, `csu-mail`, `lesson-video`, `requirements-box` |
| Software Development | `software-development`, `use-claude-code`, `wechat-miniprogram` |
| AI App Development | `agent-development`, `model-development`, `skill-porting`, `agent-tuning` |
| Agent Company | `agent-company` |
-`humanizer`, `use-claude-code`, `continual-learning`, `agent-company`, `csu-mail`, `wechat-miniprogram` and `lesson-video` carry `preinstall: false`, so `default_agent` does not get them at initialization — they are installed from the library on demand (`agent-company` by the organization itself, when it creates the CEO and hires employees, or by hand onto any Agent that should be able to create one). `goal` is the stop hook behind goal mode: its `start.mjs`, a `user_prompt` command marked `"trigger": "host"` so that it runs only when a goal starts, writes the Session's `GOAL.json` and composes round 1; its `stop.mjs` reads the Trace after every Task and injects the next round or ends the goal. `continual-learning` hands a long task's condensed excerpt to a background subagent that folds the findings into the agent's skills.
+`humanizer`, `use-claude-code`, `continual-learning`, `agent-company`, `csu-mail`, `wechat-miniprogram`, `lesson-video` and `requirements-box` carry `preinstall: false`, so `default_agent` does not get them at initialization — they are installed from the library on demand (`agent-company` by the organization itself, when it creates the CEO and hires employees, or by hand onto any Agent that should be able to create one). `goal` is the stop hook behind goal mode: its `start.mjs`, a `user_prompt` command marked `"trigger": "host"` so that it runs only when a goal starts, writes the Session's `GOAL.json` and composes round 1; its `stop.mjs` reads the Trace after every Task and injects the next round or ends the goal. `continual-learning` hands a long task's condensed excerpt to a background subagent that folds the findings into the agent's skills.
`browser-automation` drives the desktop app's built-in browser through `penguin browser`: GenericAgent's scan → act → check loop over simplified HTML, trusted clicks and typing, and sign-ins imported from the system browser, with Amazon orders as the worked example.
diff --git a/plugins/requirements-box/LICENSE b/plugins/requirements-box/LICENSE
new file mode 100644
index 00000000..261eeb9e
--- /dev/null
+++ b/plugins/requirements-box/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/plugins/requirements-box/README.md b/plugins/requirements-box/README.md
new file mode 100644
index 00000000..06586d27
--- /dev/null
+++ b/plugins/requirements-box/README.md
@@ -0,0 +1,56 @@
+# requirements-box
+
+A **requirements box**: one page where the user writes down what they want done, a scheduled task that wakes
+the agent to work through it, and a report by mail per round — so asking for something does not cost a
+conversation, and nothing gets lost between them.
+
+```
+user files a request on the page
+ │
+ ├─ status=new … the page keeps it, the schedule waits
+ ▼
+every <period> the agent wakes, reads the list, marks each item doing, and works through up to three
+ │
+ ├─ done → committed, gated, shipped; item archived, one mail per round
+ ├─ blocked → the question it could not answer, mailed to the user
+ └─ rejected → why not, in the same mail
+```
+
+## What's inside
+
+| Piece | What it is |
+| --- | --- |
+| `kit/requirements.mjs` | The whole service: a JSON store with atomic writes, the keyed API (list/create/read/patch, the patrol cadence, and the do-it-now trigger), and it serves the page. Node standard library only — no build step, no dependency tree. |
+| `kit/requirements.html` | The page: file a request, edit or withdraw one, select several and act in bulk, schedule an item, pause the patrol or change its cadence, and a "do it now" button. |
+| `kit/serve.mjs` | A standalone server for the box alone, so it can run on its own port without touching anything else already on the machine. |
+| `kit/patrol.md` | The protocol the scheduled round follows: take work, mark it doing before touching it, triage, gate, ship, mail, archive — and the red lines. |
+| `kit/install.mjs` | Lays the files down, generates the key, writes `box.config.json`, writes the schedule, and prints the two commands left to run. |
+
+## Why it exists
+
+- **Asking is not a conversation.** The user's own words are on the page; the agent reads them when it wakes,
+ not when it happens to be listening.
+- **No dependency tree for a form.** One Node file, one JSON store — nothing to install, nothing to upgrade,
+ and the whole state is a file you can read.
+- **The schedule is a file, not a black box.** The round is a `.toml` the platform re-reads; the cadence, the
+ on/off switch and the "do it now" button all write that one file.
+- **Doing it now is one click.** Waiting for the next tick is the common complaint, so the page can start a
+ session immediately, and can do it for just the items the user selected.
+
+## Install
+
+```bash
+node <skill dir>/kit/install.mjs --dir ~/requirements-box --workspace ~/my-project --port 3007 --period 2h
+```
+
+Then start `node ~/requirements-box/serve.mjs` and open the printed URL (the key rides in `?key=` once and
+the page remembers it). Everything machine-specific lives in the generated `box.config.json`; environment
+variables override it.
+
+## Notes
+
+- The key is the ability to make the agent work. It lives in `key.txt` (0600) and must not reach a commit,
+ a log or a mail body.
+- The page is meant to be reachable by one person, not published: bind `127.0.0.1` unless the user asked for
+ a wider listen, and never expose it without the key.
+- The patrol protocol is deliberately in one markdown file the user can rewrite — the flow is theirs to change.
diff --git a/plugins/requirements-box/icon.svg b/plugins/requirements-box/icon.svg
new file mode 100644
index 00000000..ad58541e
--- /dev/null
+++ b/plugins/requirements-box/icon.svg
@@ -0,0 +1,8 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Requirements box">
+ <rect x="8" y="10" width="48" height="44" rx="7" fill="#2f6fed"/>
+ <rect x="12.5" y="14.5" width="39" height="35" rx="4" fill="#0b1220"/>
+ <rect x="17" y="20" width="11" height="3.2" rx="1.6" fill="#eaf1ff"/>
+ <rect x="17" y="27.5" width="30" height="3.2" rx="1.6" fill="#7aa7f7"/>
+ <rect x="17" y="35" width="24" height="3.2" rx="1.6" fill="#5f8ff0"/>
+ <rect x="17" y="42.5" width="15" height="3.2" rx="1.6" fill="#3f6fd8"/>
+</svg>
diff --git a/plugins/requirements-box/package.json b/plugins/requirements-box/package.json
new file mode 100644
index 00000000..f5a1caf2
--- /dev/null
+++ b/plugins/requirements-box/package.json
@@ -0,0 +1,30 @@
+{
+ "name": "@lmliheng/requirements-box",
+ "version": "0.3.1",
+ "description": "A requirements box: one keyed page where the user files what they want done, a scheduled task that wakes the agent to work through them, and a per-round report by mail — the service being a single dependency-free Node file with a JSON store and a keyed API, the patrol protocol one markdown file.",
+ "license": "Apache-2.0",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/lmliheng/Adelie.git",
+ "directory": "plugins/requirements-box"
+ },
+ "keywords": [
+ "adelie-plugin",
+ "penguin-harness",
+ "requirements",
+ "queue",
+ "schedule",
+ "node",
+ "http"
+ ],
+ "files": [
+ "plugin.json",
+ "icon.svg",
+ "README.md",
+ "skills",
+ "LICENSE"
+ ],
+ "publishConfig": {
+ "access": "public"
+ }
+}
diff --git a/plugins/requirements-box/plugin.json b/plugins/requirements-box/plugin.json
new file mode 100644
index 00000000..2e95be3f
--- /dev/null
+++ b/plugins/requirements-box/plugin.json
@@ -0,0 +1,9 @@
+{
+ "description": "Stand up a requirements box — one keyed web page where the user files what they want done, a scheduled task that wakes the agent to work through them, and a per-round report by mail. The service is a single dependency-free Node file: a JSON store, a keyed GET/POST/PATCH API, the page it serves, per-item scheduling, batch selection, and a do-it-now button that starts a session immediately. The patrol protocol is one markdown file, and the installer lays both down and registers the schedule.",
+ "description_zh": "立起一个需求箱:一页受口令保护的表单让用户提需求,一个定时任务按节奏叫 Agent 来做,每轮一封邮件汇报。服务是一个零依赖的 Node 文件(JSON 存储、带口令的 GET/POST/PATCH 接口、它自己那一页、按条目排期、批量勾选,以及一个立刻开会话开工的按钮),巡台协议是一份 Markdown,安装脚本把两者摆好并登记定时任务。",
+ "short_description": "A keyed request page plus a scheduled patrol that works through it.",
+ "short_description_zh": "一页收需求的表单 + 定时巡台去做 + 每轮邮件汇报。",
+ "version": "2026.10.06.1",
+ "category": "office-productivity",
+ "preinstall": false
+}
diff --git a/plugins/requirements-box/skills/requirements-box/SKILL.md b/plugins/requirements-box/skills/requirements-box/SKILL.md
new file mode 100644
index 00000000..4b95f77c
--- /dev/null
+++ b/plugins/requirements-box/skills/requirements-box/SKILL.md
@@ -0,0 +1,77 @@
+---
+name: requirements-box
+description: Stand up a requirements box — one keyed web page where the user files what they want done, a scheduled task that wakes the agent to work through them, and a per-round report by mail. The service is a single Node file with no dependencies (a JSON store, keyed GET/POST/PATCH API, the page it serves, per-item scheduling, batch selection, and a "do it now" button that starts a session immediately), the patrol protocol is one markdown file, and the installer lays both down and registers the schedule. Use when the user wants to file requests asynchronously instead of interrupting a conversation, wants a queue the agent works on a timer, or asks to set up, change or diagnose such a box.
+---
+
+# 需求箱:一页收需求,定时来做,做完回信
+
+## Before you start
+
+如果消息只是点名这个技能(比如「用 requirements-box」)而没有具体的事,先问清楚:装到哪台机器、
+需求要在哪个项目里落地(也就是巡台那轮在哪个工作目录改代码)、端口用哪个。三样都有再动手。
+
+**先确认一件事**:这个技能装的是一个**服务 + 一个定时任务**,它会真的替用户改代码、发版、发邮件。
+装之前把这两句讲清楚:服务跑起来之后,页面上那个口令就是「让 Adelie 干活」的钥匙,别泄漏;定时任务
+一旦启用,每一轮都会真去做工。
+
+## 结论先行
+
+| 你要的 | 用哪一步 | 产物 |
+| --- | --- | --- |
+| 一页让用户提需求 | `kit/install.mjs` 摆好,`node serve.mjs` 起服务 | `/requirements` 页面 + 口令保护的接口 |
+| 定时来看 | install 顺带写的那个定时任务(`.toml`,平台自己重读) | 每 `--period` 一轮 |
+| 每轮怎么做 | `kit/patrol.md` —— **准则的唯一出处**,改流程只改它 | 每条需求的去向 + 一封汇报邮件 |
+| 用户想立刻做 | 页面上的「现在就跑一轮」「现在就做」 | 立刻开一个新会话开工 |
+
+一句话:**服务只负责收和记,干活的规矩在 `patrol.md`,什么时候干由那个定时任务说了算。**
+
+## 一、立起来
+
+```bash
+mkdir -p ~/requirements-box
+node <技能目录>/kit/install.mjs \
+ --dir ~/requirements-box \
+ --workspace ~/my-project \ # 巡台那一轮在哪儿改代码
+ --port 3007 \
+ --period 2h
+```
+
+install 会:把服务拷到 `--dir`、生成口令(`data/key.txt`,0600)、写出 `box.config.json`(这台机器的
+路径都在这里,代码里不写死)、写好巡台那个 `.toml`,并调一次 `penguin schedule ls` 核对平台认不认。
+**它不替你起进程** —— 最后会打印两条命令:起服务、打开带口令的地址。
+
+- 端口别跟别的服务撞;`HOST=0.0.0.0` 会暴露到局域网,默认只听 `127.0.0.1`。
+- 想常驻就挂 systemd / docker,`node serve.mjs` 前台跑也一样。
+- 不放心可以先 `--print-only` 看它打算做什么。
+
+## 二、那一页与它的接口
+
+页面上能做:提一条(标题 / 说明 / 紧急程度 / **排到某个时间**)、逐条**编辑**与**撤回**、勾选多条
+**批量**改紧急程度或排期、**批量撤回**,以及两个不等定时的按钮 —— 「现在就跑一轮」「现在就做」。
+
+接口只有四个前缀,全要口令:
+
+| 方法 | 路径 | 干什么 |
+| --- | --- | --- |
+| GET / POST | `/api/requirements` | 列表(可用 `?status=`、`?archived=1`)、提交一条 |
+| GET / PATCH | `/api/requirements/<id>` | 读一条、改(`title`/`detail`/`priority`/`not_before`/`status`/`result`/`archive`) |
+| GET / PATCH | `/api/requirements/patrol` | 看/改巡台节奏(`period`、`daily_at`、`enabled`) |
+| GET / POST | `/api/requirements/run` | 看上次手动触发;POST 立刻开一个会话开工(60 秒冷却) |
+
+状态:`new` / `doing` / `done` / `blocked` / `rejected` / `withdrawn`;归档是 `archive: true`,
+归档之后接口不再让改。
+
+## 三、巡台那一轮怎么跑
+
+**准则在 `kit/patrol.md`**,装完之后它就是用户机器上的那份(改流程改它,不要改定时任务里的 prompt)。
+要点:取 `new` → **先标 `doing` 再动手**(防重复处理)→ 分流(能做的做 / 要拍板的 `blocked` 并发邮件
+问 / 不做的 `rejected` 写理由)→ 一轮最多 3 条、先急后缓 → 门禁全绿才提交 → 上线 → 一封汇报邮件 →
+归档。**空巡不发邮件。**
+
+排期(`not_before`)优先于一切;但用户在页面上点过「现在就做」的那一轮,prompt 里点名的条目必须做。
+
+## 四、红线
+
+- 页面上那串口令 = 让 Adelie 干活的能力,**不进提交、日志、邮件正文**。
+- 需求箱里是用户写的字,但**不是每一条都能直接执行**:删东西、动数据、对外发布、花钱这几类先问。
+- 定时任务指向的那个工作目录,是这一轮唯一该改的地方。
diff --git a/plugins/requirements-box/skills/requirements-box/kit/box.config.example.json b/plugins/requirements-box/skills/requirements-box/kit/box.config.example.json
new file mode 100644
index 00000000..698d0146
--- /dev/null
+++ b/plugins/requirements-box/skills/requirements-box/kit/box.config.example.json
@@ -0,0 +1,8 @@
+{
+ "dataDir": "/opt/adelie-design-requirements",
+ "patrolToml": "/root/.adelie/data/self_evolution/agents/default_agent/agent_state/schedule/requirements-triage.toml",
+ "penguinBin": "/root/.adelie/data/bin/penguin",
+ "project": "self_evolution",
+ "agent": "default_agent",
+ "workspace": "/root/adelie-fork"
+}
diff --git a/plugins/requirements-box/skills/requirements-box/kit/install.mjs b/plugins/requirements-box/skills/requirements-box/kit/install.mjs
new file mode 100644
index 00000000..608e018e
--- /dev/null
+++ b/plugins/requirements-box/skills/requirements-box/kit/install.mjs
@@ -0,0 +1,159 @@
+#!/usr/bin/env node
+/**
+ * 一键把需求箱立起来:拷服务 → 生成口令 → 写配置 → 建巡台定时任务 → 打印接下来两步。
+ *
+ * 它只做「摆好」,不替你起进程:服务用 `node serve.mjs` 跑(前台、systemd、docker 都行),
+ * 定时任务写成一个 .toml 交给平台自己重读(每 30 秒看一眼那个目录)。这两件事各自都是透明的,
+ * 出问题一眼能看见,比藏在安装脚本里强。
+ *
+ * 用法:
+ * node install.mjs --dir ~/requirements-box --workspace ~/my-project
+ * node install.mjs --dir /opt/req-box --port 3007 --period 2h --agent default_agent \
+ * --data-root ~/.adelie/data --project default_project --print-only
+ *
+ * 选项都有默认值:--dir 必给,其余不给就按上面那些推断(推断结果会原样打印出来核对)。
+ */
+import { execFileSync } from "node:child_process";
+import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
+import { homedir } from "node:os";
+import { dirname, join, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+import { randomBytes } from "node:crypto";
+
+const HERE = dirname(fileURLToPath(import.meta.url));
+const KIT_FILES = ["requirements.mjs", "requirements.html", "serve.mjs", "patrol.md"];
+
+function parseArgs(argv) {
+ const flags = {};
+ for (let i = 0; i < argv.length; i += 1) {
+ const a = argv[i];
+ if (!a.startsWith("--")) continue;
+ const key = a.slice(2);
+ const next = argv[i + 1];
+ if (next === undefined || next.startsWith("--")) flags[key] = true;
+ else {
+ flags[key] = next;
+ i += 1;
+ }
+ }
+ return flags;
+}
+
+const flags = parseArgs(process.argv.slice(2));
+const die = (msg) => {
+ console.error(`install.mjs: ${msg}`);
+ process.exit(2);
+};
+
+if (!flags.dir || flags.dir === true) die("必须给 --dir(服务装到哪个目录)");
+
+const DIR = resolve(String(flags.dir));
+const DATA_ROOT = resolve(
+ String(
+ flags["data-root"] ??
+ process.env.PENGUIN_HOME ??
+ process.env.ADELIE_HOME ??
+ join(homedir(), ".penguin"),
+ ),
+);
+const PROJECT = String(flags.project ?? process.env.PENGUIN_PROJECT_ID ?? "default_project");
+const AGENT = String(flags.agent ?? process.env.PENGUIN_AGENT_ID ?? "default_agent");
+const WORKSPACE = resolve(String(flags.workspace ?? process.cwd()));
+const PORT = Number(flags.port ?? 3007);
+const HOST = String(flags.host ?? "127.0.0.1");
+const PERIOD = String(flags.period ?? "2h");
+const SCHEDULE = String(flags["schedule-name"] ?? "requirements-triage");
+const SCHEDULE_DIR = resolve(
+ String(
+ flags["schedule-dir"] ?? join(DATA_ROOT, PROJECT, "agents", AGENT, "agent_state", "schedule"),
+ ),
+);
+const SCHEDULE_TOML = join(SCHEDULE_DIR, `${SCHEDULE}.toml`);
+const DATA_DIR = resolve(String(flags["data-dir"] ?? join(DIR, "data")));
+const PENGUIN_BIN = String(flags["penguin-bin"] ?? process.env.PENGUIN_BIN ?? "penguin");
+const PRINT_ONLY = flags["print-only"] === true;
+
+if (!PERIOD.match(/^\d+[mhd]$/)) die(`--period 要是 30m / 2h / 7d 这样的写法,收到的是 ${PERIOD}`);
+// 巡台会话在这个目录里干活:它不存在的话,spawn 会在点「现在就做」的那一刻才报 ENOENT,
+// 那种错没人看得懂 —— 摆的时候就拦住。
+if (!existsSync(WORKSPACE))
+ die(`--workspace 指向的目录不存在:${WORKSPACE}(巡台那一轮要在那里改代码)`);
+
+// 1. 拷服务本体
+if (!PRINT_ONLY) mkdirSync(DIR, { recursive: true });
+for (const name of KIT_FILES) {
+ const from = join(HERE, name);
+ if (!existsSync(from)) die(`kit 里少了 ${name}`);
+ if (!PRINT_ONLY) copyFileSync(from, join(DIR, name));
+}
+
+// 2. 口令与数据目录:口令只在用户自己手上那份地址里出现,不进日志、不进提交
+if (!PRINT_ONLY) mkdirSync(DATA_DIR, { recursive: true, mode: 0o700 });
+const KEY_FILE = join(DATA_DIR, "key.txt");
+let key = "";
+if (existsSync(KEY_FILE)) key = readFileSync(KEY_FILE, "utf8").trim();
+else if (!PRINT_ONLY) {
+ key = randomBytes(24).toString("hex");
+ writeFileSync(KEY_FILE, `${key}\n`, { mode: 0o600 });
+}
+
+// 3. 配置:代码里不写死任何一台机器的路径,全从这份 json(或环境变量)来
+const config = {
+ dataDir: DATA_DIR,
+ patrolToml: SCHEDULE_TOML,
+ penguinBin: PENGUIN_BIN,
+ project: PROJECT,
+ agent: AGENT,
+ workspace: WORKSPACE,
+};
+if (!PRINT_ONLY)
+ writeFileSync(join(DIR, "box.config.json"), `${JSON.stringify(config, null, 2)}\n`);
+
+// 4. 巡台那个定时任务:写成一个 .toml 交给平台自己重读。prompt 的正文出自 patrol.md(唯一出处),
+// 这里只把「去哪儿读、口令在哪」这几处指针填进去。
+const base = `http://${HOST === "0.0.0.0" ? "127.0.0.1" : HOST}:${PORT}`;
+const prompt = [
+ `按 ${join(DIR, "patrol.md")} 跑一轮「需求箱巡台」:从 ${base} 上读 status=new 的需求`,
+ `(口令在 ${KEY_FILE}),先逐条标成 doing 再动手;能做的做掉,做不了或需要用户拍板的标成 blocked `,
+ `并写清卡在哪个决定上,做完的把结论写回接口并归档;最后给用户发一封本轮汇报(空巡不发邮件)。`,
+].join("");
+const toml = [
+ `prompt = """${prompt}"""`,
+ `workspace = "${WORKSPACE}"`,
+ "enabled = true",
+ `start_at = ${new Date(Date.now() + 60_000).toISOString()}`,
+ `period = "${PERIOD}"`,
+ "",
+].join("\n");
+if (!PRINT_ONLY) {
+ mkdirSync(SCHEDULE_DIR, { recursive: true });
+ writeFileSync(SCHEDULE_TOML, toml, { mode: 0o600 });
+}
+
+// 5. 能查就替用户核一眼:这个定时任务平台认不认
+let verified = "没核(--print-only,或者本机没有 penguin)";
+if (!PRINT_ONLY) {
+ try {
+ const out = execFileSync(PENGUIN_BIN, ["schedule", "ls"], { encoding: "utf8", timeout: 30000 });
+ const line = out.split("\n").find((l) => l.includes(SCHEDULE));
+ verified = line ? line.trim() : `没在 penguin schedule ls 里看到 ${SCHEDULE}`;
+ } catch (err) {
+ verified = `没能核(${err.message.split("\n")[0]})`;
+ }
+}
+
+console.log(`装到 ${DIR}${PRINT_ONLY ? "(--print-only:什么都没写)" : ""}
+数据 / 口令 ${DATA_DIR}${key ? `(口令 ${key.slice(0, 8)}…,完整值在 key.txt)` : ""}
+配置 ${join(DIR, "box.config.json")}
+定时任务 ${SCHEDULE_TOML}(每 ${PERIOD})
+工作目录 ${WORKSPACE}
+核对 ${verified}
+
+接下来两步:
+
+ 1) 起服务(前台跑;要常驻就挂 systemd / docker,端口别跟别的服务撞)
+ HOST=${HOST} PORT=${PORT} node ${join(DIR, "serve.mjs")}
+
+ 2) 浏览器打开(口令放在 ?key= 后面一次,之后它自己记住)
+ ${base}/requirements?key=${key || "<key.txt 里的那串>"}
+`);
diff --git a/plugins/requirements-box/skills/requirements-box/kit/patrol.md b/plugins/requirements-box/skills/requirements-box/kit/patrol.md
new file mode 100644
index 00000000..e539f3cc
--- /dev/null
+++ b/plugins/requirements-box/skills/requirements-box/kit/patrol.md
@@ -0,0 +1,121 @@
+# 需求箱巡台准则
+
+这份文件是**需求巡台定时任务的行为准则**。定时任务的 prompt 只说「按这份文件跑一轮」,细则都在这里
+—— 改流程就改这份文件,不用动定时任务。
+
+用户的口径是:「我往一页上提需求,你按时来看,能做就做,做不了或者需要我判断的先发邮件,做完之后
+自己更新服务、提交代码、走 CI、最后发完成邮件,并把做完的归档。」
+
+## 0. 需求箱在哪儿
+
+- 页面 `/requirements`,接口 `/api/requirements`,全部要口令(`x-adelie-key` 头或 `?key=`)。
+ 口令在服务的数据目录里那个 `key.txt`(0600)。
+- 口令**只从那个文件读**,绝不写进提交、日志、邮件正文。
+- 数据是服务旁边的一个 `items.json`(原子替换写入);接口里的内容才是最新的事实。
+- 记账在**服务目录下的 `runs/`**(下面 1.6 里的 `<记录根>` 就是它):一轮一个目录,跟服务摆在一起,
+ 用户翻记录不用去别处找。
+
+读一批新需求:
+
+```bash
+KEY=$(cat <数据目录>/key.txt)
+curl -s -H "x-adelie-key: $KEY" 'http://127.0.0.1:<端口>/api/requirements?status=new,doing'
+```
+
+改一条(状态 / 结论 / 备注 / 归档):
+
+```bash
+curl -s -X PATCH -H "x-adelie-key: $KEY" -H 'content-type: application/json' \
+ -d '{"status":"done","note":"…","result":"…","commits":["abc1234"],"archive":true}' \
+ http://127.0.0.1:<端口>/api/requirements/req-7
+```
+
+状态只有六个:`new`(刚提)· `doing`(这轮在做)· `done`(做完了)· `blocked`(要用户拍板)·
+`rejected`(不做,得写清为什么)· `withdrawn`(用户自己撤回了,**不当活儿也不当问题**)。
+
+用户能在页面上**改**自己提的条目(标题 / 说明 / 紧急程度 / 排期)和**撤回**它;也能勾选多条批量改。
+改过的以接口里的最新内容为准(不是他当初那句话)。归档之后服务端不再让改。
+
+**节奏不用手改文件**:页面上那张「巡台节奏」卡片(`PATCH /api/requirements/patrol`)写的就是这个
+定时任务;页面上那两个「现在就跑一轮 / 现在就做」按钮(`POST /api/requirements/run`)会立刻开一个
+新会话,收到的那种轮次里 prompt 会点名要做的 id —— **那些必须做到**,不论紧急程度与排期。
+
+## 1. 一轮的顺序
+
+### 1.1 取活
+
+拉 `status=new` 的条目。**先逐条 PATCH 成 `doing` 并留一句「本轮开始做」**,再动手 —— 这一轮中途被
+打断,下一次巡台也不会把同一条重做一遍。一轮最多做 **3 条**:**先挑 `priority: high`,同一个优先级里
+按 id 从小到大**(先来的先做),剩下的留到下一轮。需要用户拍板的那类(`blocked`)不算在这 3 条里
+—— 它只是发一封信,不占工位。
+
+**排期(`not_before`)优先于一切**:用户可以在页面上把一条需求「排到某个时间」。当前时间还没到那个
+点,就**原样留在 `new`**(不要标 `doing`、不要写事件、不要在邮件里提),等下一轮再说 —— 这是他自己
+设的,不是卡点。已经过了的点直接忽略(当没设)。
+
+**但「现在就做」压过排期**:那种轮次的 prompt 里列出的 id,不管紧急程度、不管排期,都必须做。
+
+### 1.2 分流(每条标一个)
+
+| 情况 | 状态 | 动作 |
+| --- | --- | --- |
+| 需求清楚,能自己决定怎么做 | `doing` → 做工 | 见 1.3 |
+| 需求里缺关键信息,或要动红线里的东西 | `blocked` | 写清「卡在哪个决定上、选项有哪几个」,进 1.5 邮件 |
+| 明确不做(与产品方向冲突、代价远超收益) | `rejected` | 写清理由,进 1.5 邮件 |
+| 描述不清但能猜 | `blocked` | 别猜着做:猜错要重做的代价比问一句大 |
+
+红线(必须问用户,不许自己拍板):删仓库、改数据根或迁移数据、动现网的数据、对外改名、给别的机器
+装东西、花钱(买域名/扩容)。
+
+### 1.3 做工
+
+要点:**一次一个逻辑改动一个提交**,提交信息照那个项目自己的规矩。做完把那个项目的门禁**全跑一遍**
+(类型检查、lint、格式检查、测试 —— 用项目自己的命令,不要凭印象写),原始输出留着。
+
+- 界面类需求:还要在真的页面里点一遍,并截图看一眼;改了控件要顺带看深色主题。
+- 服务端/接口类:用真请求验一遍,起在空闲端口上,别占别人的端口。
+- **门禁红了就不要提交半成品**:改到绿,或者把这条退回 `blocked` 并在邮件里说清哪一道红。
+
+### 1.4 上线
+
+1. 推上去,让 CI 自己跑 —— 这就是「走 CICD」。
+2. 发版口径:标了「急」的做完就发一个 patch 版本;普通的按那个项目自己的节奏攒。**用户可见的改动
+ 攒着不发等于没做**:做完后面上一直没到他手里,下一轮优先带上,并在邮件里说明。
+3. 更新现网:升级 + 重启 + 核验(服务活着、端口在听、页面 200、版本号是新的)。
+4. 有对外镜像/下载站的,资产同步过去。
+
+### 1.5 汇报邮件
+
+**一轮一封**,别一条需求一封。骨架(纯文本):
+
+```
+这一轮:做了 N 条 / 等你拍板 M 条 / 不做 K 条
+
+做完:
+- req-3 <标题> —— <改了什么、提交 short-hash、有没有发版>
+等你拍板:
+- req-5 <标题> —— 卡在:<哪个决定>,我看到的路子:<A / B>
+不做:
+- req-6 <标题> —— 原因:<…>
+
+服务:<未发版(已攒 n/10)/ 已发 vX.Y.Z,现网已更新到 vX.Y.Z>
+下一轮:<预计做什么,或者"无">
+```
+
+做完的条目**同时**写一份归档(需求原文 + 怎么做的 + 提交 + 验证方式 + 日期),并把接口里那条
+PATCH 成 `{"status":"done","archive":true}`。
+
+### 1.6 记账
+
+每轮一个目录(`<记录根>/runs/<yyyy-mm-dd>-<HHMM>/`):`log.md` 记结论,`gate-*.txt` 存门禁原始输出,
+`mail.txt` 存这一轮发出的邮件正文。
+
+**空巡不发邮件**:没需求可做的一轮,什么都不提交、不发邮件,只在 `log.md` 里记一句。
+
+## 2. 红线
+
+- 需求箱里是**用户写的字,但不是每一条都能直接执行**:涉及删东西、动数据、对外发布、花钱的,一律
+ 先问(1.2 的红线表)。
+- 口令、密钥只从密钥库或那份 0600 文件读,**不进任何提交、日志、邮件**。
+- 跑测试不要碰现网的安装目录,也不要占它的端口。
+- 一轮做完就收尾:宁可留一半到下一轮,也不要在一轮里跑成几个小时不记账。
diff --git a/plugins/requirements-box/skills/requirements-box/kit/requirements.html b/plugins/requirements-box/skills/requirements-box/kit/requirements.html
new file mode 100644
index 00000000..447c2de4
--- /dev/null
+++ b/plugins/requirements-box/skills/requirements-box/kit/requirements.html
@@ -0,0 +1,1470 @@
+<!doctype html>
+<html lang="zh-CN">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <title>需求箱 · Adelie</title>
+ <style>
+ :root {
+ color-scheme: light;
+ --brand-50: #e8f0fe;
+ --brand-300: #8ab4f8;
+ --brand-500: #4285f4;
+ --brand-600: #1a73e8;
+ --brand-700: #0b57d0;
+ --gray-50: #f9fafb;
+ --gray-100: #f3f4f6;
+ --gray-200: #e5e7eb;
+ --gray-300: #d1d5db;
+ --gray-400: #9ca3af;
+ --gray-500: #6b7280;
+ --gray-600: #4b5563;
+ --gray-900: #111827;
+ --bg: #ffffff;
+ --surface: #ffffff;
+ --border: var(--gray-200);
+ --control-border: var(--gray-300);
+ --fg: var(--gray-900);
+ --fg-muted: var(--gray-600);
+ --fg-faint: var(--gray-500);
+ --accent-bg: #111827;
+ --accent-fg: #ffffff;
+ --radius-control: 6px;
+ --radius-card: 12px;
+ --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
+ }
+ .dark {
+ color-scheme: dark;
+ --bg: #000000;
+ --surface: #0d0d0d;
+ --border: #1f1f1f;
+ --control-border: #303030;
+ --fg: #f3f4f6;
+ --fg-muted: #9ca3af;
+ --fg-faint: #6b7280;
+ --accent-bg: #f3f4f6;
+ --accent-fg: #111827;
+ --brand-600: #8ab4f8;
+ --brand-700: #8ab4f8;
+ }
+ * {
+ box-sizing: border-box;
+ }
+ body {
+ margin: 0;
+ background: var(--bg);
+ color: var(--fg);
+ font-family:
+ ui-sans-serif,
+ system-ui,
+ -apple-system,
+ "Segoe UI",
+ Roboto,
+ "PingFang SC",
+ "Microsoft YaHei",
+ sans-serif;
+ -webkit-font-smoothing: antialiased;
+ font-size: 14px;
+ line-height: 1.5;
+ }
+ code,
+ .mono,
+ kbd {
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
+ }
+ header {
+ position: sticky;
+ top: 0;
+ z-index: 10;
+ height: 56px;
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 0 16px;
+ border-bottom: 1px solid var(--border);
+ background: color-mix(in srgb, var(--bg) 85%, transparent);
+ backdrop-filter: blur(8px);
+ }
+ .mark {
+ width: 28px;
+ height: 28px;
+ border-radius: 8px;
+ background: var(--brand-500);
+ color: #fff;
+ display: grid;
+ place-items: center;
+ font-weight: 600;
+ }
+ .brand {
+ font-size: 15px;
+ font-weight: 600;
+ letter-spacing: -0.025em;
+ }
+ .grow {
+ flex: 1;
+ }
+ main {
+ max-width: 52rem;
+ margin: 0 auto;
+ padding: 24px 16px 64px;
+ }
+ h1 {
+ font-size: 26px;
+ font-weight: 600;
+ letter-spacing: -0.025em;
+ margin: 8px 0 4px;
+ }
+ .lede {
+ color: var(--fg-muted);
+ margin: 0 0 20px;
+ }
+ .card {
+ border: 1px solid var(--border);
+ border-radius: var(--radius-card);
+ background: var(--surface);
+ padding: 20px;
+ margin-bottom: 20px;
+ }
+ label {
+ display: block;
+ font-size: 13px;
+ color: var(--fg-muted);
+ margin: 0 0 6px;
+ }
+ input[type="text"],
+ input[type="time"],
+ input[type="datetime-local"],
+ textarea,
+ select {
+ width: 100%;
+ border: 1px solid var(--control-border);
+ border-radius: var(--radius-control);
+ background: var(--bg);
+ color: var(--fg);
+ padding: 8px 12px;
+ font: inherit;
+ margin-bottom: 14px;
+ }
+ textarea {
+ min-height: 96px;
+ resize: vertical;
+ line-height: 1.6;
+ }
+ input:focus-visible,
+ textarea:focus-visible,
+ select:focus-visible,
+ button:focus-visible,
+ a:focus-visible {
+ outline: none;
+ border-color: var(--gray-400);
+ box-shadow: 0 0 0 2px rgb(156 163 175 / 0.3);
+ }
+ button {
+ font: inherit;
+ cursor: pointer;
+ border-radius: var(--radius-control);
+ transition:
+ color,
+ background-color,
+ border-color 150ms var(--ease);
+ }
+ .primary {
+ background: var(--accent-bg);
+ color: var(--accent-fg);
+ border: 1px solid transparent;
+ padding: 8px 14px;
+ font-weight: 500;
+ }
+ .primary:hover {
+ opacity: 0.9;
+ }
+ .primary[disabled] {
+ opacity: 0.5;
+ cursor: default;
+ }
+ .secondary {
+ background: var(--surface);
+ color: var(--fg);
+ border: 1px solid var(--control-border);
+ padding: 6px 10px;
+ }
+ .secondary:hover {
+ background: var(--gray-100);
+ }
+ .dark .secondary:hover {
+ background: #1f1f1f;
+ }
+ .icon-btn {
+ background: transparent;
+ border: 1px solid transparent;
+ color: var(--fg-muted);
+ width: 36px;
+ height: 36px;
+ display: grid;
+ place-items: center;
+ }
+ .icon-btn:hover {
+ background: var(--gray-100);
+ color: var(--fg);
+ }
+ .dark .icon-btn:hover {
+ background: #1f1f1f;
+ }
+ .row {
+ display: flex;
+ gap: 12px;
+ align-items: center;
+ flex-wrap: wrap;
+ }
+ .chip {
+ border-radius: 9999px;
+ border: 1px solid var(--border);
+ padding: 2px 10px;
+ font-size: 12px;
+ color: var(--fg-muted);
+ white-space: nowrap;
+ }
+ .chip.new {
+ background: var(--brand-50);
+ border-color: var(--brand-100, #d2e3fc);
+ color: var(--brand-700);
+ }
+ .dark .chip.new {
+ background: rgb(138 180 248 / 0.12);
+ border-color: rgb(138 180 248 / 0.3);
+ }
+ .chip.doing {
+ border-color: var(--control-border);
+ color: var(--fg);
+ }
+ .chip.done {
+ border-color: #bbf7d0;
+ background: #f0fdf4;
+ color: #15803d;
+ }
+ .dark .chip.done {
+ background: rgb(34 197 94 / 0.12);
+ border-color: rgb(34 197 94 / 0.3);
+ color: #86efac;
+ }
+ .chip.blocked {
+ border-color: #fde68a;
+ background: #fffbeb;
+ color: #b45309;
+ }
+ .dark .chip.blocked {
+ background: rgb(245 158 11 / 0.12);
+ border-color: rgb(245 158 11 / 0.3);
+ color: #fcd34d;
+ }
+ .chip.rejected {
+ color: var(--fg-faint);
+ }
+ .chip.withdrawn {
+ color: var(--fg-faint);
+ text-decoration: line-through;
+ }
+ .item {
+ border: 1px solid var(--border);
+ border-radius: var(--radius-card);
+ background: var(--surface);
+ padding: 16px;
+ margin-bottom: 12px;
+ }
+ .item h2 {
+ font-size: 16px;
+ font-weight: 600;
+ margin: 0 0 6px;
+ letter-spacing: -0.01em;
+ }
+ .meta {
+ font-size: 12px;
+ color: var(--fg-faint);
+ }
+ .detail {
+ white-space: pre-wrap;
+ margin: 10px 0 0;
+ color: var(--fg);
+ }
+ .result {
+ margin-top: 10px;
+ border-left: 2px solid var(--brand-300);
+ padding: 2px 0 2px 10px;
+ color: var(--fg-muted);
+ white-space: pre-wrap;
+ }
+ .muted {
+ color: var(--fg-faint);
+ font-size: 12px;
+ }
+ .actions {
+ display: flex;
+ gap: 8px;
+ margin-top: 12px;
+ }
+ .actions .link-btn {
+ background: transparent;
+ border: 1px solid transparent;
+ color: var(--fg-muted);
+ padding: 4px 8px;
+ font-size: 13px;
+ }
+ .actions .link-btn:hover {
+ background: var(--gray-100);
+ color: var(--fg);
+ }
+ .dark .actions .link-btn:hover {
+ background: #1f1f1f;
+ }
+ .actions .link-btn.danger:hover {
+ color: #b91c1c;
+ }
+ .dark .actions .link-btn.danger:hover {
+ color: #f87171;
+ }
+ .list {
+ max-height: 34rem;
+ overflow-y: auto;
+ scrollbar-width: thin;
+ scrollbar-color: var(--control-border) transparent;
+ }
+ .item input[type="checkbox"] {
+ width: 16px;
+ height: 16px;
+ margin: 0;
+ flex: none;
+ accent-color: var(--brand-500);
+ cursor: pointer;
+ }
+ .batch {
+ border: 1px solid var(--border);
+ border-radius: var(--radius-card);
+ background: var(--surface);
+ padding: 12px 16px;
+ margin-bottom: 12px;
+ }
+ .live {
+ border: 1px solid var(--brand-300);
+ background: var(--brand-50);
+ color: var(--brand-700);
+ border-radius: var(--radius-card);
+ padding: 10px 14px;
+ margin-bottom: 12px;
+ font-size: 13px;
+ }
+ .dark .live {
+ background: rgb(138 180 248 / 0.12);
+ border-color: rgb(138 180 248 / 0.3);
+ color: #8ab4f8;
+ }
+ .pulse {
+ display: inline-block;
+ width: 8px;
+ height: 8px;
+ margin-right: 8px;
+ border-radius: 50%;
+ background: currentColor;
+ vertical-align: 1px;
+ animation: blink 1.6s ease-in-out infinite;
+ }
+ @keyframes blink {
+ 0%,
+ 100% {
+ opacity: 1;
+ }
+ 50% {
+ opacity: 0.25;
+ }
+ }
+ .batch input[type="datetime-local"] {
+ width: auto;
+ margin: 0;
+ }
+ .batch .link-btn {
+ background: transparent;
+ border: 1px solid transparent;
+ color: var(--fg-muted);
+ padding: 4px 8px;
+ font-size: 13px;
+ }
+ .batch .link-btn:hover {
+ background: var(--gray-100);
+ color: var(--fg);
+ }
+ .dark .batch .link-btn:hover {
+ background: #1f1f1f;
+ }
+ .skeleton {
+ background: var(--gray-100);
+ border-radius: 6px;
+ height: 74px;
+ margin-bottom: 12px;
+ animation: pulse 1.4s ease-in-out infinite;
+ }
+ .dark .skeleton {
+ background: #1f1f1f;
+ }
+ @keyframes pulse {
+ 0%,
+ 100% {
+ opacity: 0.5;
+ }
+ 50% {
+ opacity: 1;
+ }
+ }
+ .toast {
+ position: fixed;
+ right: 16px;
+ bottom: 16px;
+ z-index: 20;
+ background: var(--surface);
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ padding: 10px 14px;
+ font-size: 13px;
+ animation: rise 280ms var(--ease);
+ }
+ @keyframes rise {
+ from {
+ opacity: 0;
+ transform: translateY(10px);
+ }
+ to {
+ opacity: 1;
+ transform: none;
+ }
+ }
+ .error-box {
+ border-radius: 8px;
+ padding: 10px 12px;
+ font-size: 13px;
+ background: #fef2f2;
+ color: #b91c1c;
+ border: 1px solid #fecaca;
+ margin-bottom: 14px;
+ }
+ .dark .error-box {
+ background: #450a0a;
+ color: #f87171;
+ border-color: #7f1d1d;
+ }
+ .sr-only {
+ position: absolute;
+ width: 1px;
+ height: 1px;
+ padding: 0;
+ margin: -1px;
+ overflow: hidden;
+ clip: rect(0 0 0 0);
+ white-space: nowrap;
+ border: 0;
+ }
+ @media (min-width: 640px) {
+ .grid-2 {
+ display: grid;
+ grid-template-columns: 1fr 1fr;
+ gap: 0 14px;
+ }
+ }
+ @media (prefers-reduced-motion: reduce) {
+ * {
+ animation: none !important;
+ transition: none !important;
+ }
+ }
+ </style>
+ </head>
+ <body>
+ <header>
+ <span class="mark" aria-hidden="true">A</span>
+ <span class="brand">需求箱</span>
+ <span class="muted" id="cadence">Adelie 每两小时来看一次</span>
+ <span class="grow"></span>
+ <button
+ class="icon-btn"
+ id="theme"
+ type="button"
+ aria-label="切换深浅色"
+ data-tooltip="切换深浅色"
+ >
+ ◐
+ </button>
+ <button
+ class="icon-btn"
+ id="refresh"
+ type="button"
+ aria-label="刷新列表"
+ data-tooltip="刷新列表"
+ >
+ ⟳
+ </button>
+ </header>
+
+ <main>
+ <h1>要 Adelie 做什么</h1>
+ <p class="lede">
+ 写下来就行:能做的它会做掉(改代码、过门禁、发版、更新服务),做完给你发邮件并在这里归档;
+ 做不了或需要你拍板的,也会先发邮件问你。
+ </p>
+
+ <section id="gate" class="card" hidden>
+ <label for="key">口令</label>
+ <p class="muted" style="margin: 0 0 10px">
+ 这一页在公网上,读写都要口令;口令在你手上那份地址的
+ <code>?key=</code> 后面,填一次就记住了。
+ </p>
+ <input type="text" id="key" autocomplete="off" spellcheck="false" placeholder="粘贴口令" />
+ <button class="primary" id="key-save" type="button">进去</button>
+ </section>
+
+ <section id="compose" class="card" hidden>
+ <form id="form" autocomplete="off">
+ <label for="title">一句话需求</label>
+ <input
+ type="text"
+ id="title"
+ maxlength="200"
+ placeholder="例:左侧栏那个折叠条太长了,改小一点"
+ required
+ />
+
+ <label for="detail">详细说明(可省)</label>
+ <textarea
+ id="detail"
+ maxlength="20000"
+ placeholder="想要的样子、在哪一页、什么情况触发…写得越具体,它越不会问回来"
+ ></textarea>
+
+ <div class="grid-2">
+ <div>
+ <label for="priority">紧急程度</label>
+ <select id="priority">
+ <option value="normal">普通</option>
+ <option value="high">急</option>
+ </select>
+ </div>
+ <div>
+ <label for="when">排到(可省)</label>
+ <input type="datetime-local" id="when" />
+ </div>
+ </div>
+ <p class="muted" style="margin: -6px 0 14px">
+ 留空就是尽快;填了时间,Adelie
+ 到那个点之前不碰它(夜里、周末、等某个东西上线,都可以这么排)。
+ </p>
+
+ <div class="row">
+ <button class="primary" type="submit" id="submit">提交需求</button>
+ <span class="muted" id="hint">Ctrl / ⌘ + Enter 也能提交</span>
+ </div>
+ </form>
+ </section>
+
+ <section id="patrol" class="card" hidden>
+ <div class="row" style="margin-bottom: 4px">
+ <h2 style="font-size: 15px; font-weight: 600; margin: 0">巡台节奏</h2>
+ <span class="grow"></span>
+ <span class="chip" id="patrol-state">读不到</span>
+ </div>
+ <p class="muted" style="margin: 0 0 14px" id="patrol-next">—</p>
+
+ <div class="grid-2">
+ <div>
+ <label for="patrol-mode">怎么排</label>
+ <select id="patrol-mode">
+ <option value="interval">每隔几小时</option>
+ <option value="daily">每天一个点</option>
+ </select>
+ </div>
+ <div id="patrol-every-wrap">
+ <label for="patrol-every">间隔</label>
+ <select id="patrol-every">
+ <option value="30m">每 30 分钟</option>
+ <option value="1h">每 1 小时</option>
+ <option value="90m">每 1.5 小时</option>
+ <option value="2h">每 2 小时</option>
+ <option value="3h">每 3 小时</option>
+ <option value="4h">每 4 小时</option>
+ <option value="6h">每 6 小时</option>
+ <option value="8h">每 8 小时</option>
+ <option value="12h">每 12 小时</option>
+ <option value="24h">每 24 小时</option>
+ </select>
+ </div>
+ <div id="patrol-daily-wrap" hidden>
+ <label for="patrol-daily">每天几点</label>
+ <input type="time" id="patrol-daily" />
+ </div>
+ </div>
+
+ <div class="row">
+ <button class="primary" id="patrol-save" type="button">保存节奏</button>
+ <button class="secondary" id="patrol-pause" type="button">暂停巡台</button>
+ <button class="secondary" id="run-now" type="button">现在就跑一轮</button>
+ <span class="muted">改完不用重启,30 秒内生效</span>
+ </div>
+ </section>
+
+ <section>
+ <div class="row" style="margin-bottom: 10px">
+ <h2 style="font-size: 17px; font-weight: 600; margin: 0">需求列表</h2>
+ <span class="grow"></span>
+ <select id="filter" style="width: auto; margin: 0; padding: 4px 8px">
+ <option value="">全部(不含已归档)</option>
+ <option value="new,doing">进行中</option>
+ <option value="blocked">等你拍板</option>
+ <option value="done">已完成</option>
+ <option value="rejected,withdrawn">不做 / 撤回</option>
+ <option value="archived">已归档</option>
+ </select>
+ </div>
+ <div id="status-line" class="muted" style="margin-bottom: 10px"></div>
+ <div id="live" class="live" hidden></div>
+ <div id="batch" class="batch" hidden>
+ <div class="row">
+ <span class="muted" id="batch-count">已选 0 条</span>
+ <span class="grow"></span>
+ <button class="link-btn" id="batch-clear" type="button">取消选择</button>
+ </div>
+ <div class="row" style="margin-top: 8px">
+ <button class="primary" id="batch-run" type="button">现在就做</button>
+ <button class="secondary" id="batch-high" type="button">标为急</button>
+ <button class="secondary" id="batch-normal" type="button">改回普通</button>
+ <button class="secondary" id="batch-withdraw" type="button">撤回</button>
+ </div>
+ <div class="row" style="margin-top: 8px">
+ <input type="datetime-local" id="batch-when" aria-label="批量排到" />
+ <button class="secondary" id="batch-schedule" type="button">排到</button>
+ <button class="secondary" id="batch-unschedule" type="button">取消排期</button>
+ <span class="muted">排到 = 到那个点之前不动;取消排期 = 恢复成尽快</span>
+ </div>
+ </div>
+ <div id="list" class="list" aria-live="polite"></div>
+ </section>
+ </main>
+
+ <script>
+ (function () {
+ var STORE_KEY = "adelie.requirements.key";
+ var THEME_KEY = "adelie.requirements.theme";
+ var params = new URLSearchParams(location.search);
+ var fromUrl = params.get("key");
+ if (fromUrl) {
+ localStorage.setItem(STORE_KEY, fromUrl);
+ history.replaceState(null, "", "/requirements");
+ }
+ var key = localStorage.getItem(STORE_KEY) || "";
+
+ var els = {
+ gate: document.getElementById("gate"),
+ compose: document.getElementById("compose"),
+ key: document.getElementById("key"),
+ keySave: document.getElementById("key-save"),
+ form: document.getElementById("form"),
+ title: document.getElementById("title"),
+ detail: document.getElementById("detail"),
+ priority: document.getElementById("priority"),
+ when: document.getElementById("when"),
+ submit: document.getElementById("submit"),
+ list: document.getElementById("list"),
+ filter: document.getElementById("filter"),
+ statusLine: document.getElementById("status-line"),
+ live: document.getElementById("live"),
+ cadence: document.getElementById("cadence"),
+ patrol: document.getElementById("patrol"),
+ patrolState: document.getElementById("patrol-state"),
+ patrolNext: document.getElementById("patrol-next"),
+ patrolMode: document.getElementById("patrol-mode"),
+ patrolEvery: document.getElementById("patrol-every"),
+ patrolEveryWrap: document.getElementById("patrol-every-wrap"),
+ patrolDaily: document.getElementById("patrol-daily"),
+ patrolDailyWrap: document.getElementById("patrol-daily-wrap"),
+ patrolSave: document.getElementById("patrol-save"),
+ patrolPause: document.getElementById("patrol-pause"),
+ runNow: document.getElementById("run-now"),
+ batch: document.getElementById("batch"),
+ batchCount: document.getElementById("batch-count"),
+ batchClear: document.getElementById("batch-clear"),
+ batchRun: document.getElementById("batch-run"),
+ batchHigh: document.getElementById("batch-high"),
+ batchNormal: document.getElementById("batch-normal"),
+ batchWithdraw: document.getElementById("batch-withdraw"),
+ batchWhen: document.getElementById("batch-when"),
+ batchSchedule: document.getElementById("batch-schedule"),
+ batchUnschedule: document.getElementById("batch-unschedule"),
+ };
+
+ // 深浅色跟着系统走,选过就记住。
+ var saved = localStorage.getItem(THEME_KEY);
+ var dark = saved ? saved === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
+ function paintTheme() {
+ document.documentElement.classList.toggle("dark", dark);
+ }
+ paintTheme();
+ document.getElementById("theme").addEventListener("click", function () {
+ dark = !dark;
+ localStorage.setItem(THEME_KEY, dark ? "dark" : "light");
+ paintTheme();
+ });
+
+ function api(path, options) {
+ var opts = options || {};
+ opts.headers = Object.assign({ "x-adelie-key": key }, opts.headers || {});
+ return fetch("/api/requirements" + path, opts).then(function (res) {
+ return res.json().then(function (body) {
+ if (!res.ok) throw new Error(body && body.error ? body.error : "HTTP " + res.status);
+ return body;
+ });
+ });
+ }
+
+ function toast(text) {
+ var el = document.createElement("div");
+ el.className = "toast";
+ el.setAttribute("role", "status");
+ el.textContent = text;
+ document.body.appendChild(el);
+ setTimeout(function () {
+ el.remove();
+ }, 3600);
+ }
+
+ function showError(text) {
+ var box = document.getElementById("error-box");
+ if (!box) {
+ box = document.createElement("div");
+ box.id = "error-box";
+ box.className = "error-box";
+ els.list.parentNode.insertBefore(box, els.list);
+ }
+ box.textContent = text;
+ }
+ function clearError() {
+ var box = document.getElementById("error-box");
+ if (box) box.remove();
+ }
+
+ var LABELS = {
+ new: "待处理",
+ doing: "在做",
+ done: "已完成",
+ blocked: "等你拍板",
+ rejected: "不做",
+ withdrawn: "已撤回",
+ };
+ function fmt(iso) {
+ try {
+ return new Date(iso).toLocaleString("zh-CN", { hour12: false });
+ } catch (e) {
+ return iso;
+ }
+ }
+ /** `datetime-local` 的值是本地时间,接口收的是 ISO;两边各转一次。 */
+ function isoFromWhenInput(value) {
+ return value ? new Date(value).toISOString() : "";
+ }
+ function whenInputFromIso(iso) {
+ if (!iso) return "";
+ var d = new Date(iso);
+ var pad = function (n) {
+ return String(n).padStart(2, "0");
+ };
+ return (
+ d.getFullYear() +
+ "-" +
+ pad(d.getMonth() + 1) +
+ "-" +
+ pad(d.getDate()) +
+ "T" +
+ pad(d.getHours()) +
+ ":" +
+ pad(d.getMinutes())
+ );
+ }
+
+ /**
+ * 巡台节奏。这一块读写的是背后那个定时任务(多久来看一次),不是某一条需求的时间 ——
+ * 需求自己的「排到」在上面那条表单里。服务端只认「起点 + 固定间隔」,所以「每天一个点」
+ * 就是间隔 24 小时、起点对齐到那个钟点。
+ */
+ var PERIOD_LABEL = {
+ "30m": "30 分钟",
+ "1h": "1 小时",
+ "90m": "1.5 小时",
+ "2h": "2 小时",
+ "3h": "3 小时",
+ "4h": "4 小时",
+ "6h": "6 小时",
+ "8h": "8 小时",
+ "12h": "12 小时",
+ "24h": "24 小时",
+ };
+ var patrol = null;
+
+ function paintPatrol() {
+ var p = patrol;
+ if (!p) return;
+ var isDaily = p.mode === "daily";
+ els.patrolMode.value = isDaily ? "daily" : "interval";
+ els.patrolEveryWrap.hidden = isDaily;
+ els.patrolDailyWrap.hidden = !isDaily;
+ if (isDaily && p.daily_at) els.patrolDaily.value = p.daily_at;
+ if (!isDaily && p.period && PERIOD_LABEL[p.period]) els.patrolEvery.value = p.period;
+
+ els.patrolState.className = "chip" + (p.enabled ? "" : " withdrawn");
+ els.patrolState.textContent = p.enabled ? "在跑" : "已暂停";
+ els.patrolPause.textContent = p.enabled ? "暂停巡台" : "恢复巡台";
+ paintPatrolNext();
+
+ if (!p.enabled) els.cadence.textContent = "巡台已暂停";
+ else if (isDaily) els.cadence.textContent = "Adelie 每天 " + p.daily_at + " 来看一次";
+ else
+ els.cadence.textContent =
+ "Adelie 每 " + (PERIOD_LABEL[p.period] || p.period) + "来看一次";
+ }
+
+ function paintPatrolNext() {
+ if (!patrol) return;
+ var line = patrol.enabled
+ ? "下一次巡台:" + fmt(patrol.next_at) + "(本机时间)"
+ : "暂停中 —— 已经提上来的需求都还在,恢复之后照常处理。";
+ if (lastRun && lastRun.at) {
+ line +=
+ " · 上次手动叫它:" +
+ fmt(lastRun.at) +
+ (lastRun.session_id ? "(" + lastRun.session_id + ")" : "");
+ }
+ els.patrolNext.textContent = line;
+ }
+
+ function loadPatrol() {
+ return Promise.all([
+ api("/patrol"),
+ api("/run").catch(function () {
+ return null;
+ }),
+ ])
+ .then(function (res) {
+ patrol = res[0].patrol;
+ lastRun = res[1] ? res[1].last : null;
+ els.patrol.hidden = false;
+ paintPatrol();
+ })
+ .catch(function (err) {
+ els.patrol.hidden = false;
+ els.patrolState.textContent = "读不到";
+ els.patrolNext.textContent = "巡台节奏没读出来:" + err.message;
+ });
+ }
+
+ function savePatrol(body, done) {
+ els.patrolSave.disabled = true;
+ api("/patrol", {
+ method: "PATCH",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify(body),
+ })
+ .then(function (res) {
+ clearError();
+ patrol = res.patrol;
+ paintPatrol();
+ toast(done);
+ })
+ .catch(function (err) {
+ showError("节奏没改上:" + err.message);
+ })
+ .then(function () {
+ els.patrolSave.disabled = false;
+ });
+ }
+
+ /**
+ * 批量。选中的条目一起改(紧急程度 / 排期 / 撤回),或者一起交给 Adelie 现在就做 ——
+ * 「现在就做」不只是排队:它让平台**立刻开一个会话**开工,不等下一个整点。
+ */
+ var selected = {};
+ var lastRun = null;
+ var cooldownUntil = 0;
+
+ function selectedIds() {
+ return Object.keys(selected).filter(function (id) {
+ return selected[id];
+ });
+ }
+
+ function paintBatch() {
+ var ids = selectedIds();
+ els.batch.hidden = ids.length === 0;
+ els.batchCount.textContent = "已选 " + ids.length + " 条";
+ }
+
+ function tickCooldown() {
+ var left = Math.ceil((cooldownUntil - Date.now()) / 1000);
+ if (left > 0) {
+ // 服务端也是 60 秒冷却,这里跟着倒计时,免得点了才发现被拒。
+ els.runNow.disabled = true;
+ els.runNow.textContent = "刚叫过,等 " + left + " 秒";
+ els.batchRun.disabled = true;
+ setTimeout(tickCooldown, 500);
+ return;
+ }
+ els.runNow.disabled = false;
+ els.runNow.textContent = "现在就跑一轮";
+ els.batchRun.disabled = false;
+ }
+
+ function runNow(ids) {
+ var what = ids.length ? "这 " + ids.length + " 条" : "一轮巡台";
+ if (
+ !confirm(
+ "让 Adelie 现在就跑" +
+ what +
+ "?它会立刻开一个新会话开工(改代码、过门禁、按口径发版)。",
+ )
+ ) {
+ return;
+ }
+ els.runNow.disabled = true;
+ els.batchRun.disabled = true;
+ api("/run", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ ids: ids }),
+ })
+ .then(function (body) {
+ clearError();
+ lastRun = { at: body.at, ids: body.ids, session_id: body.session_id };
+ cooldownUntil = Date.now() + 60000;
+ tickCooldown();
+ selected = {};
+ paintBatch();
+ toast(
+ body.session_id
+ ? "已经叫醒它了:" + body.session_id
+ : "已经叫醒它了,会话马上出现在列表里",
+ );
+ paintPatrolNext();
+ return load();
+ })
+ .catch(function (err) {
+ showError("没叫起来:" + err.message);
+ els.runNow.disabled = false;
+ els.batchRun.disabled = false;
+ });
+ }
+
+ /** 批量改:逐条走各自那条已经验过的 PATCH,一次错只影响那一条。 */
+ function batchPatch(body, done) {
+ var ids = selectedIds();
+ if (ids.length === 0) return;
+ els.batchRun.disabled = true;
+ Promise.all(
+ ids.map(function (id) {
+ return api("/" + id, {
+ method: "PATCH",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify(body),
+ });
+ }),
+ )
+ .then(function () {
+ clearError();
+ toast(done + ":" + ids.length + " 条");
+ })
+ .catch(function (err) {
+ showError("批量没做完:" + err.message);
+ })
+ .then(function () {
+ selected = {};
+ paintBatch();
+ els.batchRun.disabled = false;
+ return load();
+ });
+ }
+
+ function chip(text, extra) {
+ var el = document.createElement("span");
+ el.className = "chip" + (extra ? " " + extra : "");
+ el.textContent = text;
+ return el;
+ }
+
+ /**
+ * 一条需求的卡片。没归档的带「编辑」和「撤回」:提错了、想补一句、想换个紧急程度,
+ * 都不必再提一条。归档了的是记录,不再改(服务端也拦着)。
+ */
+ function renderCard(item) {
+ var card = document.createElement("article");
+ card.className = "item";
+ var editing = false;
+
+ function paint() {
+ card.textContent = "";
+
+ var row = document.createElement("div");
+ row.className = "row";
+ // 归档了的是记录,不能改也就不给选;其余每条一个勾选框,选中后上面那条批量栏才出现。
+ if (!item.archived_at) {
+ var box = document.createElement("input");
+ box.type = "checkbox";
+ box.checked = !!selected[item.id];
+ box.setAttribute("aria-label", "选中 " + item.id);
+ box.addEventListener("change", function () {
+ selected[item.id] = box.checked;
+ paintBatch();
+ });
+ row.appendChild(box);
+ }
+ row.appendChild(chip(LABELS[item.status] || item.status, item.status));
+ if (item.priority === "high") row.appendChild(chip("急"));
+ if (item.not_before) row.appendChild(chip("排到 " + fmt(item.not_before)));
+ var meta = document.createElement("span");
+ meta.className = "meta";
+ meta.textContent = item.id + " · 提交于 " + fmt(item.created_at);
+ row.appendChild(meta);
+ card.appendChild(row);
+
+ if (editing) {
+ var titleInput = document.createElement("input");
+ titleInput.type = "text";
+ titleInput.maxLength = 200;
+ titleInput.value = item.title;
+ titleInput.setAttribute("aria-label", "需求标题");
+ titleInput.style.marginTop = "10px";
+
+ var detailInput = document.createElement("textarea");
+ detailInput.value = item.detail || "";
+ detailInput.maxLength = 20000;
+ detailInput.setAttribute("aria-label", "详细说明");
+
+ var prioritySelect = document.createElement("select");
+ prioritySelect.setAttribute("aria-label", "紧急程度");
+ [
+ ["normal", "普通"],
+ ["high", "急"],
+ ].forEach(function (pair) {
+ var opt = document.createElement("option");
+ opt.value = pair[0];
+ opt.textContent = pair[1];
+ if (item.priority === pair[0]) opt.selected = true;
+ prioritySelect.appendChild(opt);
+ });
+
+ var whenInput = document.createElement("input");
+ whenInput.type = "datetime-local";
+ whenInput.value = whenInputFromIso(item.not_before);
+ whenInput.setAttribute("aria-label", "排到(留空就是尽快)");
+ whenInput.title = "留空就是尽快";
+
+ card.appendChild(titleInput);
+ card.appendChild(detailInput);
+ card.appendChild(prioritySelect);
+ card.appendChild(whenInput);
+
+ var actions = document.createElement("div");
+ actions.className = "actions";
+ var save = document.createElement("button");
+ save.type = "button";
+ save.className = "primary";
+ save.textContent = "保存";
+ save.disabled = true;
+ // 没改过就别让点,免得手滑存一次空改动。
+ function dirty() {
+ return (
+ titleInput.value.trim() !== item.title ||
+ detailInput.value.trim() !== (item.detail || "") ||
+ prioritySelect.value !== item.priority ||
+ isoFromWhenInput(whenInput.value) !== (item.not_before || "")
+ );
+ }
+ [titleInput, detailInput, prioritySelect, whenInput].forEach(function (el) {
+ el.addEventListener("input", function () {
+ save.disabled = !dirty();
+ });
+ el.addEventListener("change", function () {
+ save.disabled = !dirty();
+ });
+ });
+ save.addEventListener("click", function () {
+ if (!titleInput.value.trim()) {
+ showError("标题不能为空");
+ return;
+ }
+ save.disabled = true;
+ api("/" + item.id, {
+ method: "PATCH",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ title: titleInput.value,
+ detail: detailInput.value,
+ priority: prioritySelect.value,
+ not_before: isoFromWhenInput(whenInput.value),
+ }),
+ })
+ .then(function (body) {
+ clearError();
+ item = body.item;
+ editing = false;
+ editingCards -= 1;
+ toast("已保存:" + item.id);
+ paint();
+ })
+ .catch(function (err) {
+ showError("没保存上:" + err.message);
+ save.disabled = false;
+ });
+ });
+ var cancel = document.createElement("button");
+ cancel.type = "button";
+ cancel.className = "link-btn";
+ cancel.textContent = "取消";
+ cancel.addEventListener("click", function () {
+ editing = false;
+ editingCards -= 1;
+ paint();
+ });
+ actions.appendChild(save);
+ actions.appendChild(cancel);
+ card.appendChild(actions);
+ titleInput.focus();
+ return;
+ }
+
+ var h = document.createElement("h2");
+ h.textContent = item.title;
+ card.appendChild(h);
+
+ if (item.detail) {
+ var p = document.createElement("p");
+ p.className = "detail";
+ p.textContent = item.detail;
+ card.appendChild(p);
+ }
+ if (item.result) {
+ var r = document.createElement("p");
+ r.className = "result";
+ r.textContent = item.result;
+ card.appendChild(r);
+ }
+ if (item.events && item.events.length > 1) {
+ var last = item.events[item.events.length - 1];
+ var note = document.createElement("p");
+ note.className = "muted";
+ note.style.margin = "8px 0 0";
+ note.textContent = "最近: " + last.note + "(" + fmt(last.at) + ")";
+ card.appendChild(note);
+ }
+ if (item.archived_at) {
+ var arch = document.createElement("p");
+ arch.className = "muted";
+ arch.style.margin = "8px 0 0";
+ arch.textContent = "已归档 " + fmt(item.archived_at);
+ card.appendChild(arch);
+ return;
+ }
+
+ var actions = document.createElement("div");
+ actions.className = "actions";
+ var edit = document.createElement("button");
+ edit.type = "button";
+ edit.className = "link-btn";
+ edit.textContent = "编辑";
+ edit.addEventListener("click", function () {
+ editing = true;
+ editingCards += 1; // 编辑期间不自动刷新,免得把填了一半的表单冲掉
+ paint();
+ });
+ actions.appendChild(edit);
+
+ var withdraw = document.createElement("button");
+ withdraw.type = "button";
+ withdraw.className = "link-btn danger";
+ withdraw.textContent = "撤回";
+ withdraw.addEventListener("click", function () {
+ if (!confirm("撤回「" + item.title + "」?撤回之后这一条不再被处理,记录还在。"))
+ return;
+ api("/" + item.id, {
+ method: "PATCH",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ status: "withdrawn", note: "用户自己在页面上撤回" }),
+ })
+ .then(function (body) {
+ item = body.item;
+ toast("已撤回:" + item.id);
+ paint();
+ })
+ .catch(function (err) {
+ showError("没撤回成:" + err.message);
+ });
+ });
+ actions.appendChild(withdraw);
+ card.appendChild(actions);
+ }
+
+ paint();
+ return card;
+ }
+
+ function render(items) {
+ els.list.textContent = "";
+ if (!items.length) {
+ var empty = document.createElement("p");
+ empty.className = "muted";
+ empty.style.padding = "12px 2px";
+ empty.textContent = "这里还空着 —— 上面的框里写一条就成了。";
+ els.list.appendChild(empty);
+ paintLive(items);
+ return;
+ }
+ items
+ .slice()
+ .reverse()
+ .forEach(function (item) {
+ els.list.appendChild(renderCard(item));
+ });
+ paintLive(items);
+ }
+
+ /**
+ * 「它到底动没动」这件事必须写在页面上。被叫起来的那一轮不是立刻就有回音的:会话要先读
+ * 需求、再动手,几十秒后才把条目标成「在做」。中间这段什么提示都没有,看着就像没反应 ——
+ * 所以只要列表里有「在做」的条目(不管是手动叫的还是定时那一轮),顶上就亮一条。
+ */
+ function paintLive(items) {
+ var doing = (items || []).filter(function (i) {
+ return i.status === "doing";
+ });
+ if (doing.length === 0) {
+ var fresh = lastRun && lastRun.at && Date.now() - lastRun.at < 180000;
+ if (!fresh) {
+ els.live.hidden = true;
+ return;
+ }
+ els.live.hidden = false;
+ els.live.textContent = "";
+ var d0 = document.createElement("span");
+ d0.className = "pulse";
+ els.live.appendChild(d0);
+ els.live.appendChild(
+ document.createTextNode(
+ "刚叫醒它" +
+ (lastRun.session_id ? "(会话 " + lastRun.session_id + ")" : "") +
+ ",它正在读需求,过一会儿这里就会自己冒出「在做」的条目。",
+ ),
+ );
+ return;
+ }
+ els.live.hidden = false;
+ els.live.textContent = "";
+ var dot = document.createElement("span");
+ dot.className = "pulse";
+ els.live.appendChild(dot);
+ var text =
+ "Adelie 正在做:" +
+ doing
+ .map(function (i) {
+ return i.id;
+ })
+ .join("、") +
+ "。不用手动刷新 —— 这一页每 " +
+ Math.round(REFRESH_MS / 1000) +
+ " 秒自己看一次。";
+ if (lastRun && lastRun.at) {
+ text +=
+ "(上次手动叫它 " +
+ fmt(lastRun.at) +
+ (lastRun.session_id ? ",会话 " + lastRun.session_id : "") +
+ ")";
+ }
+ els.live.appendChild(document.createTextNode(text));
+ }
+
+ function load(opts) {
+ var quiet = opts && opts.quiet;
+ if (!quiet) {
+ els.list.textContent = "";
+ for (var i = 0; i < 3; i += 1) {
+ var sk = document.createElement("div");
+ sk.className = "skeleton";
+ els.list.appendChild(sk);
+ }
+ }
+ var filter = els.filter.value;
+ var query = filter === "archived" ? "?archived=1" : filter ? "?status=" + filter : "";
+ return api(query)
+ .then(function (body) {
+ clearError();
+ els.statusLine.textContent = "共 " + body.count + " 条 · 序号已发到 " + body.seq;
+ render(body.items);
+ })
+ .catch(function (err) {
+ // 后台那一遍刷新失败就当没发生:不要把正在看的东西换成一个报错框
+ if (quiet) return;
+ els.list.textContent = "";
+ showError("列表没读出来:" + err.message);
+ });
+ }
+
+ // 页面开着就自己刷新 —— 不然「它动没动」全靠手动按那个 ⟳。
+ var REFRESH_MS = 10000;
+ var editingCards = 0;
+ setInterval(function autoload() {
+ if (document.visibilityState !== "visible") return;
+ if (editingCards > 0) return; // 正在改的那张卡片不能被刷新冲掉
+ load({ quiet: true });
+ }, REFRESH_MS);
+
+ function gate(open) {
+ els.gate.hidden = !open;
+ els.compose.hidden = open;
+ els.patrol.hidden = open;
+ if (open) els.key.focus();
+ }
+
+ els.patrolMode.addEventListener("change", function () {
+ var isDaily = els.patrolMode.value === "daily";
+ els.patrolEveryWrap.hidden = isDaily;
+ els.patrolDailyWrap.hidden = !isDaily;
+ if (isDaily && !els.patrolDaily.value) {
+ els.patrolDaily.value = (patrol && patrol.daily_at) || "09:00";
+ }
+ });
+
+ els.patrolSave.addEventListener("click", function () {
+ if (els.patrolMode.value === "daily") {
+ if (!els.patrolDaily.value) {
+ showError("先选一个钟点");
+ return;
+ }
+ savePatrol(
+ { daily_at: els.patrolDaily.value },
+ "改成每天 " + els.patrolDaily.value + " 巡一次",
+ );
+ return;
+ }
+ var period = els.patrolEvery.value;
+ savePatrol({ period: period }, "改成每 " + (PERIOD_LABEL[period] || period) + "巡一次");
+ });
+
+ els.patrolPause.addEventListener("click", function () {
+ var next = !(patrol && patrol.enabled);
+ savePatrol({ enabled: next }, next ? "巡台已恢复" : "巡台已暂停");
+ });
+
+ els.runNow.addEventListener("click", function () {
+ runNow([]);
+ });
+
+ els.batchClear.addEventListener("click", function () {
+ selected = {};
+ paintBatch();
+ load();
+ });
+ els.batchRun.addEventListener("click", function () {
+ runNow(selectedIds());
+ });
+ els.batchHigh.addEventListener("click", function () {
+ batchPatch({ priority: "high" }, "标为急");
+ });
+ els.batchNormal.addEventListener("click", function () {
+ batchPatch({ priority: "normal" }, "改回普通");
+ });
+ els.batchWithdraw.addEventListener("click", function () {
+ var ids = selectedIds();
+ if (ids.length === 0) return;
+ if (!confirm("撤回选中的 " + ids.length + " 条?撤回之后不再处理,记录还在。")) return;
+ batchPatch({ status: "withdrawn", note: "用户自己在页面上批量撤回" }, "已撤回");
+ });
+ els.batchSchedule.addEventListener("click", function () {
+ if (!els.batchWhen.value) {
+ showError("先选一个时间");
+ return;
+ }
+ batchPatch(
+ { not_before: isoFromWhenInput(els.batchWhen.value) },
+ "排到 " + els.batchWhen.value.replace("T", " "),
+ );
+ });
+ els.batchUnschedule.addEventListener("click", function () {
+ batchPatch({ not_before: "" }, "取消排期");
+ });
+
+ els.keySave.addEventListener("click", function () {
+ key = els.key.value.trim();
+ if (!key) return;
+ localStorage.setItem(STORE_KEY, key);
+ api("")
+ .then(function (body) {
+ clearError();
+ gate(false);
+ els.statusLine.textContent = "共 " + body.count + " 条 · 序号已发到 " + body.seq;
+ render(body.items);
+ loadPatrol();
+ })
+ .catch(function (err) {
+ showError("口令不对或者服务没起来:" + err.message);
+ });
+ });
+
+ // Enter 提交要避开输入法组字状态:中文输入时那个 Enter 只是上屏。
+ els.form.addEventListener("keydown", function (e) {
+ if (
+ e.key === "Enter" &&
+ (e.ctrlKey || e.metaKey) &&
+ !(e.isComposing || e.keyCode === 229)
+ ) {
+ e.preventDefault();
+ els.form.requestSubmit();
+ }
+ });
+
+ els.form.addEventListener("submit", function (e) {
+ e.preventDefault();
+ var title = els.title.value.trim();
+ if (!title) return;
+ els.submit.disabled = true;
+ api("", {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ title: title,
+ detail: els.detail.value,
+ priority: els.priority.value,
+ not_before: isoFromWhenInput(els.when.value),
+ }),
+ })
+ .then(function (body) {
+ els.title.value = "";
+ els.detail.value = "";
+ els.when.value = "";
+ toast("已提交:" + body.item.id + ",Adelie 下次巡台会看到它");
+ return load();
+ })
+ .catch(function (err) {
+ showError("没提交上去:" + err.message);
+ })
+ .then(function () {
+ els.submit.disabled = false;
+ });
+ });
+
+ els.filter.addEventListener("change", load);
+ document.getElementById("refresh").addEventListener("click", function () {
+ load().then(function () {
+ toast("已刷新");
+ });
+ loadPatrol();
+ });
+
+ if (key) {
+ gate(false);
+ load();
+ loadPatrol();
+ } else {
+ gate(true);
+ }
+ })();
+ </script>
+ </body>
+</html>
diff --git a/plugins/requirements-box/skills/requirements-box/kit/requirements.mjs b/plugins/requirements-box/skills/requirements-box/kit/requirements.mjs
new file mode 100644
index 00000000..e3a4d29e
--- /dev/null
+++ b/plugins/requirements-box/skills/requirements-box/kit/requirements.mjs
@@ -0,0 +1,721 @@
+// /opt/adelie-design/requirements.mjs
+//
+// 「需求箱」——用户提需求、Adelie 定时处理的那一页与它背后的几个接口。
+//
+// 为什么插在这里而不是另起一个进程:用户的口径是「服务就插入原本的 3003」(2026-10-06)。
+// 3003 上本来就是这个静态服务,多一个端口就多一份要盯的东西;需求箱的流量与静态页完全
+// 不是一个量级,塞进同一个事件循环没有代价。
+//
+// 只用 Node 标准库,和 server.mjs 一个理由:这一页没有构建步骤,也不该为了收几条需求装
+// 一个依赖树。存储用一个 JSON 文件 + 原子替换(写临时文件再 rename),份量就这么多。
+//
+// 鉴权不是可选项:这一页在公网上(同一个站点还挂着安装包下载),而没有鉴权的提交口等于
+// 把「让 Adelie 干点什么」的能力开放给任何人 —— 定时任务会照着需求里的字去改代码。因此
+// 读写全部要求一个口令(`x-adelie-key` 头或 `?key=`),口令第一次启动时随机生成、0600
+// 落在数据目录里,只在用户自己的书签里出现。
+//
+// 数据放在 ROOT 之外的 REQUIREMENTS_DIR(默认 /opt/adelie-design-requirements):静态
+// 服务器按前缀路径发文件,数据放在它够得着的地方意味着 items.json 可以被任何人下载。
+
+import { spawn } from "node:child_process";
+import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
+import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const HERE = dirname(fileURLToPath(import.meta.url));
+
+/**
+ * 本机配置不写进代码:优先级 环境变量 > 同目录的 `box.config.json` > 中性默认值。
+ * 那份 json 由安装脚本(kit/install.mjs)生成,也可以照 `box.config.example.json` 手写 ——
+ * 这样同一份代码在别人的机器上照样跑,不必改源码。
+ */
+function loadConfig() {
+ try {
+ return JSON.parse(readFileSync(join(HERE, "box.config.json"), "utf8"));
+ } catch {
+ return {};
+ }
+}
+
+const CONFIG = loadConfig();
+const pick = (envKey, configKey, fallback) => process.env[envKey] ?? CONFIG[configKey] ?? fallback;
+
+const DATA_DIR = pick("REQUIREMENTS_DIR", "dataDir", join(HERE, "data"));
+const ITEMS_FILE = join(DATA_DIR, "items.json");
+const KEY_FILE = join(DATA_DIR, "key.txt");
+const PAGE_FILE = join(HERE, "requirements.html");
+const PATROL_TOML = pick("PATROL_TOML", "patrolToml", "");
+const PENGUIN_BIN = pick("PENGUIN_BIN", "penguinBin", "penguin");
+const PATROL_PROJECT = pick("PATROL_PROJECT", "project", "");
+const PATROL_AGENT = pick("PATROL_AGENT", "agent", "");
+const PATROL_WORKSPACE = pick("PATROL_WORKSPACE", "workspace", process.cwd());
+
+/** 状态的封闭集合。`new` 是刚提上来还没被看过的;`doing` 是这一轮正在做的。 */
+const STATUSES = new Set(["new", "doing", "done", "blocked", "rejected", "withdrawn"]);
+
+function ensureDataDir() {
+ if (!existsSync(DATA_DIR)) mkdirSync(DATA_DIR, { recursive: true, mode: 0o700 });
+ if (!existsSync(KEY_FILE)) {
+ const key = randomBytes(24).toString("hex");
+ writeFileSync(KEY_FILE, key + "\n", { mode: 0o600 });
+ console.log(`需求箱口令已生成:${KEY_FILE}(只有这个文件里有一份)`);
+ }
+}
+
+function readKey() {
+ return readFileSync(KEY_FILE, "utf8").trim();
+}
+
+function load() {
+ if (!existsSync(ITEMS_FILE)) return { seq: 0, items: [] };
+ try {
+ const parsed = JSON.parse(readFileSync(ITEMS_FILE, "utf8"));
+ if (!Array.isArray(parsed.items)) return { seq: 0, items: [] };
+ return { seq: Number(parsed.seq) || parsed.items.length, items: parsed.items };
+ } catch (err) {
+ // 文件坏了不能装作没有需求:把坏文件挪开留证,再从空的开始,别把用户提过的东西
+ // 直接覆盖掉。
+ const broken = `${ITEMS_FILE}.broken-${Date.now()}`;
+ renameSync(ITEMS_FILE, broken);
+ console.log(`需求箱数据文件读不动(${err.message}),已挪到 ${broken}`);
+ return { seq: 0, items: [] };
+ }
+}
+
+function save(state) {
+ const tmp = `${ITEMS_FILE}.tmp`;
+ writeFileSync(tmp, JSON.stringify(state, null, 2) + "\n", { mode: 0o600 });
+ renameSync(tmp, ITEMS_FILE);
+}
+
+function json(res, status, body) {
+ const payload = JSON.stringify(body);
+ res.writeHead(status, {
+ "content-type": "application/json; charset=utf-8",
+ "cache-control": "no-store",
+ "content-length": String(Buffer.byteLength(payload)),
+ });
+ res.end(payload);
+}
+
+function readBody(req, limit = 64 * 1024) {
+ return new Promise((resolve, reject) => {
+ let size = 0;
+ const chunks = [];
+ req.on("data", (chunk) => {
+ size += chunk.length;
+ if (size > limit) {
+ reject(new Error("too large"));
+ req.destroy();
+ return;
+ }
+ chunks.push(chunk);
+ });
+ req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
+ req.on("error", reject);
+ });
+}
+
+function keyOk(url, req) {
+ const expected = readKey();
+ const given = req.headers["x-adelie-key"] ?? url.searchParams.get("key") ?? "";
+ const a = Buffer.from(String(given));
+ const b = Buffer.from(expected);
+ return a.length === b.length && timingSafeEqual(a, b);
+}
+
+/** 一条需求的形状:提上来是什么、后来变成什么,都留在 events 里,不覆盖历史。 */
+function makeItem(state, input) {
+ const now = new Date().toISOString();
+ state.seq += 1;
+ const notBefore = normalizeNotBefore(input.not_before);
+ return {
+ id: `req-${state.seq}`,
+ seq: state.seq,
+ title: String(input.title ?? "")
+ .trim()
+ .slice(0, 200),
+ detail: String(input.detail ?? "")
+ .trim()
+ .slice(0, 20000),
+ priority: input.priority === "high" ? "high" : "normal",
+ status: "new",
+ // 排期:到这个时刻之后再动手;null / 缺省 = 尽快。上一轮没到点的条目由巡台自己跳过,
+ // 状态仍是 new,不占工位也不发邮件。
+ not_before: Number.isNaN(notBefore) ? null : (notBefore ?? null),
+ created_at: now,
+ updated_at: now,
+ events: [{ at: now, status: "new", note: "已收到" }],
+ };
+}
+
+/**
+ * 排期的规范化:缺省(undefined)表示「这次请求没提这件事」,保持不变;空串或 null 表示
+ * 清掉排期(尽快);其它值要能解析成时间,解析不了返回 NaN 由调用方拒掉。
+ */
+function normalizeNotBefore(value) {
+ if (value === undefined) return undefined;
+ if (value === null || value === "") return null;
+ const parsed = Date.parse(String(value));
+ return Number.isFinite(parsed) ? new Date(parsed).toISOString() : NaN;
+}
+
+// --- 巡台节奏 ---------------------------------------------------------------
+//
+// 这一页管的不只是「提什么」,还有「多久来看一次」。巡台的实体是 agent_state/schedule/
+// 下的一个定时任务文件,harness 每 30 秒重读一次目录 —— 改这个文件就等于改节奏,不用重启
+// 任何东西。所以页面上那个「巡台节奏」直接写它,写完把原文备一份到数据目录,改坏了能翻回去。
+const PATROL_BACKUP = join(DATA_DIR, "patrol-toml.bak");
+
+/** 没配巡台时,错误信息要指向那份配置,而不是一个空路径。 */
+function patrolMissing() {
+ return PATROL_TOML
+ ? `读不到定时任务文件:${PATROL_TOML}`
+ : "还没配巡台:在 box.config.json 里写 patrolToml(或设环境变量 PATROL_TOML)指向那个定时任务文件";
+}
+/** 允许的节奏。`24h` 另有一条「每天几点」的路,那条也是写 24h,只是起点对齐到钟点。 */
+const PERIOD_MS = {
+ "30m": 1800e3,
+ "1h": 3600e3,
+ "90m": 5400e3,
+ "2h": 7200e3,
+ "3h": 10800e3,
+ "4h": 14400e3,
+ "6h": 21600e3,
+ "8h": 28800e3,
+ "12h": 43200e3,
+ "24h": 86400e3,
+};
+
+function patrolPeriodMs(period) {
+ const m = /^(\d+)([mhd])$/.exec(String(period ?? "").trim());
+ if (!m) return 0;
+ return Number(m[1]) * { m: 60e3, h: 3600e3, d: 86400e3 }[m[2]];
+}
+
+function pad2(n) {
+ return String(n).padStart(2, "0");
+}
+
+/** 下一个「整点对齐」的触发时刻:2h 就是 00:00 / 02:00 …,用的是本机时区。 */
+function nextLocalBoundary(periodMs) {
+ const now = new Date();
+ const offsetMs = now.getTimezoneOffset() * 60e3;
+ const local = now.getTime() - offsetMs;
+ return new Date((Math.floor(local / periodMs) + 1) * periodMs + offsetMs);
+}
+
+/** 今天(或明天)的某个本机钟点。 */
+function nextLocalTime(hhmm) {
+ const [h, m] = hhmm.split(":").map(Number);
+ const now = new Date();
+ const at = new Date(now.getFullYear(), now.getMonth(), now.getDate(), h, m, 0, 0);
+ if (at.getTime() <= now.getTime()) at.setDate(at.getDate() + 1);
+ return at;
+}
+
+/** 读定时任务文件。读不到返回 null —— 调用方据此报错,不假装节奏还在。 */
+function readPatrol() {
+ let text;
+ try {
+ text = readFileSync(PATROL_TOML, "utf8");
+ } catch {
+ return null;
+ }
+ const one = (key) => {
+ const m = text.match(new RegExp(`^${key}\\s*=\\s*(.+)$`, "m"));
+ return m ? m[1].trim().replace(/^["']|["']$/g, "") : null;
+ };
+ const period = one("period");
+ const startAt = one("start_at");
+ const startMs = Date.parse(startAt ?? "");
+ const periodMs = patrolPeriodMs(period);
+ let nextAt = null;
+ if (Number.isFinite(startMs)) {
+ if (periodMs > 0) {
+ const now = Date.now();
+ const steps = now < startMs ? 0 : Math.floor((now - startMs) / periodMs) + 1;
+ nextAt = new Date(startMs + steps * periodMs).toISOString();
+ } else {
+ nextAt = startAt;
+ }
+ }
+ const daily = periodMs === 86400e3 && Number.isFinite(startMs);
+ const at = Number.isFinite(startMs) ? new Date(startMs) : null;
+ return {
+ file: PATROL_TOML,
+ enabled: one("enabled") === "true",
+ period,
+ start_at: startAt,
+ next_at: nextAt,
+ mode: daily ? "daily" : "interval",
+ daily_at: daily ? `${pad2(at.getHours())}:${pad2(at.getMinutes())}` : null,
+ };
+}
+
+/**
+ * 写回定时任务文件:只动 enabled / start_at / period 三行,prompt 与 workspace 原样留着 ——
+ * 那段 prompt 是这一页真正要跑的活,格式一坏整个巡台就哑了。
+ */
+function writePatrol({ enabled, period, startAt }) {
+ const text = readFileSync(PATROL_TOML, "utf8");
+ writeFileSync(PATROL_BACKUP, text, { mode: 0o600 });
+ const lines = text
+ .split("\n")
+ .filter((line) => !/^(enabled|start_at|period)\s*=/.test(line.trim()));
+ while (lines.length > 0 && lines[lines.length - 1].trim() === "") lines.pop();
+ lines.push(`enabled = ${enabled ? "true" : "false"}`);
+ lines.push(`start_at = ${startAt}`);
+ lines.push(`period = "${period}"`);
+ const tmp = `${PATROL_TOML}.tmp`;
+ writeFileSync(tmp, lines.join("\n") + "\n", { mode: 0o600 });
+ renameSync(tmp, PATROL_TOML);
+}
+
+// --- 立即跑一轮 -------------------------------------------------------------
+//
+// 定时任务最快也得等到下一个整点,而「万一我现在就要」是常态。这里给页面一个按钮:直接让
+// 平台开一个新会话,把巡台那段 prompt 发过去,现在就跑。
+//
+// 走的是 `penguin run --background`:CLI 把任务交给服务端就退出,真正跑的是平台里的那个会话
+// —— 所以浏览器关掉、3003 重启,那一轮也不受影响。子进程用的是干净环境(不继承本服务的
+// HOST/PORT/ROOT),CLI 自己认本机那个 server.lock 与 api-token。
+//
+// 这不是一个「便宜」的按钮:它会真的开一个会话去改代码、过门禁、发版、更新现网。所以有
+// 60 秒冷却(手抖点两下不会开两个会话),页面上还有一次确认。
+const RUN_COOLDOWN_MS = 60 * 1000;
+const SESSION_ID_RE = /session-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}-[0-9a-f]{8}/;
+
+let lastManualRun = { at: 0, ids: [], session_id: null };
+
+/** 巡台那段 prompt 的唯一出处是定时任务文件,这里读它,改准则不用改两处。 */
+function patrolPrompt() {
+ try {
+ const m = readFileSync(PATROL_TOML, "utf8").match(/^prompt\s*=\s*"""([\s\S]*?)"""/m);
+ if (m) return m[1].trim();
+ } catch {
+ // 读不到就落回下面这句,总比什么都不做要强
+ }
+ return "按 /root/evolution/REQUIREMENTS.md 跑一轮「需求箱巡台」。";
+}
+
+function patrolMessage(ids) {
+ const lines = [patrolPrompt(), ""];
+ if (ids.length > 0) {
+ lines.push(
+ `【用户刚在页面上点了「现在就做」】这一轮先做这几条,按他点的顺序:${ids.join("、")}。`,
+ );
+ lines.push("不管它们是什么紧急程度,都排进这一轮要做的条目里;其余照准则走。");
+ } else {
+ lines.push(
+ "【用户刚在页面上点了「现在就跑一轮」】这是他在定时之外额外要的一轮,别等下一次定点。",
+ );
+ }
+ return lines.join("\n");
+}
+
+/** 起了就返回,不为它等多久 —— 12 秒拿不到会话号也照样告诉用户「叫醒了」。 */
+function spawnPatrol(ids, res) {
+ const now = Date.now();
+ const waited = now - lastManualRun.at;
+ if (waited < RUN_COOLDOWN_MS) {
+ json(res, 429, {
+ ok: false,
+ error: `刚叫过一次(${Math.round(waited / 1000)} 秒前),${Math.ceil((RUN_COOLDOWN_MS - waited) / 1000)} 秒后可以再叫`,
+ });
+ return;
+ }
+
+ let out = "";
+ let child;
+ try {
+ // 没配的项就不传这个参数 —— 让 penguin CLI 用它自己的默认(当前项目 / 默认 Agent),
+ // 传一个空串反而会被当成一个真的 id。
+ const args = ["run", "--background"];
+ if (PATROL_PROJECT) args.push("--project-id", PATROL_PROJECT);
+ if (PATROL_AGENT) args.push("--agent-id", PATROL_AGENT);
+ args.push("--workspace", PATROL_WORKSPACE, "-m", patrolMessage(ids));
+ child = spawn(PENGUIN_BIN, args, {
+ cwd: PATROL_WORKSPACE,
+ detached: true,
+ stdio: ["ignore", "pipe", "pipe"],
+ env: {
+ HOME: process.env.HOME ?? "/root",
+ PATH: process.env.PATH ?? "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
+ },
+ });
+ } catch (err) {
+ json(res, 500, { ok: false, error: `起不来:${err.message}` });
+ return;
+ }
+
+ lastManualRun = { at: now, ids, session_id: null };
+ let answered = false;
+ const answer = (pending, code) => {
+ if (answered) return;
+ answered = true;
+ clearTimeout(timer);
+ const sid = (out.match(SESSION_ID_RE) ?? [null])[0];
+ lastManualRun.session_id = sid;
+ const at = new Date(now).toISOString();
+ if (sid) console.log(`手动触发巡台:${sid}${ids.length ? `(优先 ${ids.join("、")})` : ""}`);
+ else console.log(`手动触发巡台:没读到会话号(exit=${code})${out.trim().slice(0, 200)}`);
+ json(res, 200, {
+ ok: true,
+ session_id: sid,
+ pending,
+ ids,
+ at,
+ output: sid ? undefined : out.trim().slice(0, 400),
+ });
+ };
+ const timer = setTimeout(() => answer(true), 12000);
+ child.stdout?.on("data", (d) => {
+ out += String(d);
+ });
+ child.stderr?.on("data", (d) => {
+ out += String(d);
+ });
+ child.on("error", (err) => {
+ out += String(err.message);
+ answer(false, "error");
+ });
+ child.on("exit", (code) => answer(false, code));
+ child.unref();
+}
+
+const PAGE_CSP = [
+ "default-src 'none'",
+ "style-src 'unsafe-inline'",
+ "script-src 'unsafe-inline'",
+ "connect-src 'self'",
+ "img-src 'self' data:",
+ "base-uri 'none'",
+ "form-action 'none'",
+].join("; ");
+
+function sendPage(res) {
+ let html;
+ try {
+ html = readFileSync(PAGE_FILE, "utf8");
+ } catch (err) {
+ json(res, 500, { ok: false, error: `需求箱页面读不到:${err.message}` });
+ return;
+ }
+ res.writeHead(200, {
+ "content-type": "text/html; charset=utf-8",
+ "cache-control": "no-store",
+ "content-security-policy": PAGE_CSP,
+ "x-content-type-options": "nosniff",
+ });
+ res.end(html);
+}
+
+/**
+ * 需求箱的路由。返回 true 表示这个请求归它管(已经响应过了),false 表示交回静态服务器。
+ * 前缀只有两个:页面 `/requirements`,接口 `/api/requirements`。
+ */
+export function handleRequirements(req, res, rawUrl) {
+ let url;
+ try {
+ url = new URL(rawUrl, "http://localhost");
+ } catch {
+ return false;
+ }
+ const path = url.pathname;
+
+ if (path === "/requirements" || path === "/requirements/") {
+ if (req.method !== "GET" && req.method !== "HEAD") {
+ json(res, 405, { ok: false, error: "只支持 GET" });
+ return true;
+ }
+ sendPage(res);
+ return true;
+ }
+
+ if (path !== "/api/requirements" && !path.startsWith("/api/requirements/")) return false;
+
+ if (!keyOk(url, req)) {
+ json(res, 401, { ok: false, error: "口令不对(x-adelie-key 头或 ?key=)" });
+ return true;
+ }
+
+ const tail = path.slice("/api/requirements".length).replace(/^\//, "");
+ const method = req.method ?? "GET";
+
+ if (tail === "") {
+ if (method === "GET") {
+ const state = load();
+ const wanted = url.searchParams.get("status");
+ const statuses = wanted ? wanted.split(",").map((s) => s.trim()) : null;
+ const archived = url.searchParams.get("archived");
+ let items = state.items;
+ if (statuses) items = items.filter((i) => statuses.includes(i.status));
+ // 归档是一个视图,不是另一个库:做过的东西留在同一个文件里,默认不返回。
+ if (archived === "1") items = items.filter((i) => i.archived_at);
+ else items = items.filter((i) => !i.archived_at);
+ const limit = Number(url.searchParams.get("limit"));
+ if (Number.isFinite(limit) && limit > 0) items = items.slice(-limit);
+ json(res, 200, { ok: true, seq: state.seq, count: items.length, items });
+ return true;
+ }
+
+ if (method === "POST") {
+ readBody(req)
+ .then((raw) => {
+ let input;
+ try {
+ input = JSON.parse(raw || "{}");
+ } catch {
+ json(res, 400, { ok: false, error: "正文不是 JSON" });
+ return;
+ }
+ if (typeof input.title !== "string" || input.title.trim() === "") {
+ json(res, 400, { ok: false, error: "标题不能为空" });
+ return;
+ }
+ const state = load();
+ const item = makeItem(state, input);
+ state.items.push(item);
+ save(state);
+ console.log(`需求箱收到 ${item.id}:${item.title}`);
+ json(res, 201, { ok: true, item });
+ })
+ .catch((err) => json(res, 413, { ok: false, error: err.message }));
+ return true;
+ }
+
+ json(res, 405, { ok: false, error: "只支持 GET / POST" });
+ return true;
+ }
+
+ // 立即跑一轮:/api/requirements/run(GET 看上次叫它是什么时候)
+ if (tail === "run") {
+ if (method === "GET") {
+ json(res, 200, { ok: true, last: lastManualRun });
+ return true;
+ }
+ if (method === "POST") {
+ readBody(req)
+ .then((raw) => {
+ let input;
+ try {
+ input = JSON.parse(raw || "{}");
+ } catch {
+ json(res, 400, { ok: false, error: "正文不是 JSON" });
+ return;
+ }
+ let ids = [];
+ if (Array.isArray(input.ids) && input.ids.length > 0) {
+ ids = input.ids
+ .map(String)
+ .filter((s) => /^req-\d+$/.test(s))
+ .slice(0, 20);
+ if (ids.length === 0) {
+ json(res, 400, { ok: false, error: "要做的条目 id 不对(形如 req-3)" });
+ return;
+ }
+ }
+ spawnPatrol(ids, res);
+ })
+ .catch((err) => json(res, 413, { ok: false, error: err.message }));
+ return true;
+ }
+ json(res, 405, { ok: false, error: "只支持 GET / POST" });
+ return true;
+ }
+
+ // 节奏:/api/requirements/patrol
+ if (tail === "patrol") {
+ if (method === "GET") {
+ const patrol = readPatrol();
+ if (!patrol) {
+ json(res, 500, { ok: false, error: patrolMissing() });
+ return true;
+ }
+ json(res, 200, { ok: true, patrol });
+ return true;
+ }
+ if (method === "PATCH" || method === "POST") {
+ readBody(req)
+ .then((raw) => {
+ let patch;
+ try {
+ patch = JSON.parse(raw || "{}");
+ } catch {
+ json(res, 400, { ok: false, error: "正文不是 JSON" });
+ return;
+ }
+ const current = readPatrol();
+ if (!current) {
+ json(res, 500, { ok: false, error: patrolMissing() });
+ return;
+ }
+ const enabled = patch.enabled === undefined ? current.enabled : patch.enabled === true;
+ let period = current.period;
+ let startAt = current.start_at;
+
+ if (patch.daily_at !== undefined && patch.daily_at !== null && patch.daily_at !== "") {
+ if (!/^([01]\d|2[0-3]):[0-5]\d$/.test(String(patch.daily_at))) {
+ json(res, 400, { ok: false, error: "每天几点要写成 HH:MM(24 小时制)" });
+ return;
+ }
+ period = "24h";
+ startAt = nextLocalTime(String(patch.daily_at)).toISOString();
+ } else if (patch.period !== undefined && patch.period !== null && patch.period !== "") {
+ if (!Object.hasOwn(PERIOD_MS, String(patch.period))) {
+ json(res, 400, {
+ ok: false,
+ error: `节奏只能是:${Object.keys(PERIOD_MS).join(" / ")}`,
+ });
+ return;
+ }
+ period = String(patch.period);
+ startAt = nextLocalBoundary(PERIOD_MS[period]).toISOString();
+ } else if (patch.mode === "daily" && current.daily_at) {
+ // 只切模式不改钟点:沿用现在那个点,但把下一次算到今天的这个点。
+ period = "24h";
+ startAt = nextLocalTime(current.daily_at).toISOString();
+ }
+
+ writePatrol({ enabled, period, startAt });
+ const patrol = readPatrol();
+ console.log(
+ `巡台节奏更新:${patrol.enabled ? "开" : "暂停"} · 每 ${patrol.period} · 下一次 ${patrol.next_at}`,
+ );
+ json(res, 200, { ok: true, patrol });
+ })
+ .catch((err) => json(res, 413, { ok: false, error: err.message }));
+ return true;
+ }
+ json(res, 405, { ok: false, error: "只支持 GET / PATCH" });
+ return true;
+ }
+
+ // 单条:/api/requirements/<id>
+ const id = tail.split("/")[0];
+ const state = load();
+ const item = state.items.find((i) => i.id === id);
+ if (!item) {
+ json(res, 404, { ok: false, error: `没有这条需求:${id}` });
+ return true;
+ }
+
+ if (method === "GET") {
+ json(res, 200, { ok: true, item });
+ return true;
+ }
+
+ if (method === "PATCH" || method === "POST") {
+ readBody(req)
+ .then((raw) => {
+ let patch;
+ try {
+ patch = JSON.parse(raw || "{}");
+ } catch {
+ json(res, 400, { ok: false, error: "正文不是 JSON" });
+ return;
+ }
+ if (patch.status !== undefined) {
+ if (!STATUSES.has(patch.status)) {
+ json(res, 400, { ok: false, error: `状态只能是:${[...STATUSES].join(" / ")}` });
+ return;
+ }
+ item.status = patch.status;
+ }
+
+ // 改内容:标题、说明、紧急程度。已经归档的是一条记录,不再改 —— 归档之后还要改,
+ // 说明该另外提一条。
+ if (item.archived_at) {
+ const onlyArchive =
+ patch.status === undefined &&
+ patch.note === undefined &&
+ patch.result === undefined &&
+ patch.commits === undefined &&
+ patch.version === undefined &&
+ patch.title === undefined &&
+ patch.detail === undefined &&
+ patch.priority === undefined;
+ if (!onlyArchive) {
+ json(res, 409, { ok: false, error: "这条已经归档,改不了;要改就另提一条" });
+ return;
+ }
+ }
+ const edits = [];
+ if (typeof patch.title === "string") {
+ const title = patch.title.trim().slice(0, 200);
+ if (title === "") {
+ json(res, 400, { ok: false, error: "标题不能为空" });
+ return;
+ }
+ if (title !== item.title) {
+ item.title = title;
+ edits.push("标题");
+ }
+ }
+ if (typeof patch.detail === "string") {
+ const detail = patch.detail.trim().slice(0, 20000);
+ if (detail !== item.detail) {
+ item.detail = detail;
+ edits.push("说明");
+ }
+ }
+ if (patch.priority !== undefined) {
+ const priority = patch.priority === "high" ? "high" : "normal";
+ if (priority !== item.priority) {
+ item.priority = priority;
+ edits.push("紧急程度");
+ }
+ }
+ if (patch.not_before !== undefined) {
+ const notBefore = normalizeNotBefore(patch.not_before);
+ if (Number.isNaN(notBefore)) {
+ json(res, 400, { ok: false, error: "排期不是一个能识别的时间" });
+ return;
+ }
+ const next = notBefore ?? null;
+ if (next !== (item.not_before ?? null)) {
+ item.not_before = next;
+ edits.push("排期");
+ }
+ }
+
+ if (typeof patch.result === "string") item.result = patch.result.slice(0, 20000);
+ if (edits.length > 0) {
+ item.events.push({
+ at: new Date().toISOString(),
+ status: item.status,
+ note: `${patch.by === "adelie" ? "Adelie" : "用户"}改了${edits.join("、")}`,
+ });
+ }
+ if (typeof patch.note === "string" && patch.note.trim() !== "") {
+ item.events.push({
+ at: new Date().toISOString(),
+ status: item.status,
+ note: patch.note.slice(0, 4000),
+ });
+ }
+ if (Array.isArray(patch.commits)) item.commits = patch.commits.map(String).slice(0, 20);
+ if (typeof patch.version === "string") item.version = patch.version.slice(0, 40);
+ if (patch.archive === true) item.archived_at = new Date().toISOString();
+ item.updated_at = new Date().toISOString();
+ save(state);
+ console.log(`需求箱更新 ${item.id} -> ${item.status}`);
+ json(res, 200, { ok: true, item });
+ })
+ .catch((err) => json(res, 413, { ok: false, error: err.message }));
+ return true;
+ }
+
+ json(res, 405, { ok: false, error: "只支持 GET / PATCH" });
+ return true;
+}
+
+export function initRequirements() {
+ ensureDataDir();
+ // 口令的指纹:日志里能看出「还是那一把」,但看不出是什么。
+ const fingerprint = createHash("sha256").update(readKey()).digest("hex").slice(0, 8);
+ const state = load();
+ console.log(`需求箱就绪:${DATA_DIR}(${state.items.length} 条,口令指纹 #${fingerprint})`);
+}
diff --git a/plugins/requirements-box/skills/requirements-box/kit/serve.mjs b/plugins/requirements-box/skills/requirements-box/kit/serve.mjs
new file mode 100644
index 00000000..3c53ff67
--- /dev/null
+++ b/plugins/requirements-box/skills/requirements-box/kit/serve.mjs
@@ -0,0 +1,50 @@
+#!/usr/bin/env node
+/**
+ * 需求箱的独立服务器:一个端口上只有这一页和它的接口,没有别的静态文件。
+ *
+ * 作者的机器上是另一种跑法 —— 把它挂在既有的静态服务上(那边 server.mjs 里一行
+ * `handleRequirements(req, res, url)` 挂钩)。插件带这个独立入口,是为了不必为了收几条需求
+ * 去动别人已经跑着的服务:想停就停,想换端口就换端口。
+ *
+ * 用法(先跑 install.mjs 生成目录与配置):
+ * node serve.mjs # 读同目录的 box.config.json,HOST/PORT 走环境变量
+ * HOST=0.0.0.0 PORT=3007 node serve.mjs
+ */
+import { createServer } from "node:http";
+import { handleRequirements, initRequirements } from "./requirements.mjs";
+
+const HOST = process.env.HOST ?? "127.0.0.1";
+const PORT = Number(process.env.PORT ?? 3007);
+
+initRequirements();
+
+const server = createServer((req, res) => {
+ const url = req.url ?? "/";
+
+ // 两个前缀(页面 /requirements、接口 /api/requirements)归需求箱;其余的一律不发。
+ if (handleRequirements(req, res, url)) return;
+
+ if (url.split("?")[0] === "/healthz") {
+ const body = JSON.stringify({ ok: true, service: "requirements-box" });
+ res.writeHead(200, {
+ "content-type": "application/json; charset=utf-8",
+ "cache-control": "no-store",
+ "content-length": String(Buffer.byteLength(body)),
+ });
+ res.end(body);
+ return;
+ }
+
+ // 这里不是静态站:除了那一页,什么都不给,也不列目录。
+ res.writeHead(302, { location: "/requirements", "cache-control": "no-store" });
+ res.end();
+});
+
+server.listen(PORT, HOST, () => {
+ const shown = HOST === "0.0.0.0" ? "0.0.0.0" : HOST;
+ console.log(`需求箱已就绪:http://${shown}:${PORT}/requirements`);
+});
+
+for (const sig of ["SIGINT", "SIGTERM"]) {
+ process.on(sig, () => server.close(() => process.exit(0)));
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f449a590..313d0b5d 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -87,6 +87,9 @@ importers:
'@lmliheng/penguin-server':
specifier: workspace:*
version: file:packages/server([email protected])([email protected])
+ '@lmliheng/requirements-box':
+ specifier: workspace:*
+ version: link:../../plugins/requirements-box
'@lmliheng/skill-porting':
specifier: workspace:*
version: link:../../plugins/skill-porting
@@ -175,6 +178,9 @@ importers:
'@lmliheng/model-development':
specifier: workspace:*
version: link:../../plugins/model-development
+ '@lmliheng/requirements-box':
+ specifier: workspace:*
+ version: link:../../plugins/requirements-box
'@lmliheng/skill-porting':
specifier: workspace:*
version: link:../../plugins/skill-porting
@@ -269,6 +275,9 @@ importers:
'@lmliheng/model-development':
specifier: workspace:*
version: link:../../plugins/model-development
+ '@lmliheng/requirements-box':
+ specifier: workspace:*
+ version: link:../../plugins/requirements-box
'@lmliheng/skill-porting':
specifier: workspace:*
version: link:../../plugins/skill-porting
@@ -677,6 +686,8 @@ importers:
plugins/model-development: {}
+ plugins/requirements-box: {}
+
plugins/sandbox-bwrap:
devDependencies:
'@lmliheng/penguin-core':
@@ -1493,6 +1504,9 @@ packages:
resolution: {directory: packages/server, type: directory}
engines: {node: '>=24'}
+ '@lmliheng/requirements-box@file:plugins/requirements-box':
+ resolution: {directory: plugins/requirements-box, type: directory}
+
'@lmliheng/skill-porting@file:plugins/skill-porting':
resolution: {directory: plugins/skill-porting, type: directory}
@@ -5570,6 +5584,7 @@ snapshots:
'@lmliheng/model-development': file:plugins/model-development
'@lmliheng/penguin-core': file:packages/core([email protected])([email protected])
'@lmliheng/penguin-server': file:packages/server([email protected])
+ '@lmliheng/requirements-box': file:plugins/requirements-box
'@lmliheng/skill-porting': file:plugins/skill-porting
'@lmliheng/software-development': file:plugins/software-development
'@lmliheng/use-bento-slides': file:plugins/use-bento-slides
@@ -5604,6 +5619,7 @@ snapshots:
'@lmliheng/humanizer': file:plugins/humanizer
'@lmliheng/lesson-video': file:plugins/lesson-video
'@lmliheng/model-development': file:plugins/model-development
+ '@lmliheng/requirements-box': file:plugins/requirements-box
'@lmliheng/skill-porting': file:plugins/skill-porting
'@lmliheng/software-development': file:plugins/software-development
'@lmliheng/use-bento-slides': file:plugins/use-bento-slides
@@ -5636,6 +5652,7 @@ snapshots:
'@lmliheng/humanizer': file:plugins/humanizer
'@lmliheng/lesson-video': file:plugins/lesson-video
'@lmliheng/model-development': file:plugins/model-development
+ '@lmliheng/requirements-box': file:plugins/requirements-box
'@lmliheng/skill-porting': file:plugins/skill-porting
'@lmliheng/software-development': file:plugins/software-development
'@lmliheng/use-bento-slides': file:plugins/use-bento-slides
@@ -5720,6 +5737,8 @@ snapshots:
- utf-8-validate
- zod
+ '@lmliheng/requirements-box@file:plugins/requirements-box': {}
+
'@lmliheng/skill-porting@file:plugins/skill-porting': {}
'@lmliheng/software-development@file:plugins/software-development': {}