Commit Graph

44 Commits

Author SHA1 Message Date
anonsaber 3917b96e71 docs: §4.1 / §6.3.1 指向 scripts/cron-drain.sh
「为什么收不到 Telegram」的答案分两层:调度没跑(外部 cron 问题),还是配置或
凭据问题。§4.1 第三步和 §6.3.1 各加一段指向新脚本,并说明 --diagnose 与
--test-notify 两个开关分别用来区分这两种情况。

顺带核对过 §6.3.1 的状态码表与 src/notify.rs 实际契约一致:/reconcile 成功是
204(401/409/503+Retry-After),/worker 成功是 204(400/401/503),RECONCILE_
INITIAL_CHANGES=100 在 notify.rs:294,/worker batch 上限 MAX=10 在 notify.rs:407,
行号锚点全部准确。

GATE-DOCS 6/6(PATH 475 -> 477)。
2026-09-30 22:24:53 +08:00
anonsaber 89dfe5cf3d feat(lb): /healthz 透传到源站,LB 聚合探针改挂 /healthz-worker
源站自己也暴露 /healthz;两者同路径时走 Worker 域名只能看到 LB 的聚合
结果,看不到源站自己的健康状态。现在拆开:

- GET /healthz        透传到源站(源站自己的健康检查)
- GET /healthz-worker LB 聚合探针(LB_VERSION + 后端汇总)

SAFE_ROUTES 增列 /healthz、ROUTE_METHODS 增列 /healthz: [GET],白名单 16 -> 17。
LB 探测源站的路径仍是 /healthz,不变。LB_VERSION 2026.10.1 -> 2026.10.2。

GATE-DOCS 6/6;node --check 全部通过。
2026-09-30 21:36:37 +08:00
anonsaber 15fa7f1e35 feat(lb): /healthz 回显版本号 LB_VERSION,确认线上是哪次部署在回答
上次生产事故里「改了代码不知道有没有生效」缺少直接证据;现在 /healthz 的
JSON 多一个 version 字段,取 env.LB_VERSION(写在 wrangler.toml 的 [vars],
当前 2026.10.1),未配置回退 unknown,探针永不因缺该字段而失败。

healthResponse(summary, version) 的第二参数可选:省略时 JSON 不含该字段
(JSON.stringify 丢弃 undefined),既有调用与用例不受影响。

放 [vars] 而不是 dashboard Add Variable 的理由:它必须跟代码同版本、可 diff,
写进 dashboard 反而容易漂。代价是改 LB 逻辑的提交要顺手 bump 它。

文档同步:§10.4 响应体形状加 version、§10.9 [vars] 示例与验证步骤、
README 环境变量表补一行;用例计数 32 → 35。

验证:node --test 35/35;wrangler deploy --dry-run 通过;docs gate 6/6。
2026-09-30 20:21:48 +08:00
anonsaber 3d6606d0cd docs: deployment.md §10/§10.9 同步 origin 列表改为 [vars] 明文例外
- §10 部署步骤:BACKEND_ORIGINS_JSON 从 secret 注入改为 wrangler.toml 的 [vars],
  secret put 降级为「出现非公开值时」的回退路径,并写明边界。
- §10.9 预览命令说明:预览环境现在能拿到 [vars] 里的 origin(能跑通转发);
  改回 secret 注入时才会退回只能验证 Worker 拉起 + 路由表生效。
- GATE-DOCS 6/6 clean(114 anchors / 252 sec-refs / 474 path-refs)。
2026-09-30 19:07:17 +08:00
anonsaber d7033066e2 docs: §10.9 构建命令改为 npm test,不再要求 npm ci
wrangler deploy 自己用 esbuild 把 4 个源文件打成一个 index.js 再上传
(实测 --outdir 产物 33,078 字节 + sourcemap),src/ 零外部依赖,所以
构建命令留空也不会失败——「构建」和「部署」在本项目是同一个动作。

填 npm test 的价值不在打包,而在两点:
- Cloudflare 默认安装跑 bun install,不读 npm 锁文件,已提交的锁文件
  被绕过,wrangler 版本由 ^4.144.0 浮动;
- npm test 是 32 个测试构成的部署前门禁,不依赖 node_modules(零外部
  依赖,空目录也能跑通 32/32,实测 2.6 秒)。

npm ci --no-audit --no-fund && npm test 仍写进文档作为锁死版本的选项,
代价是每次重新下载安装 35 个包(实测约 86 秒)。
2026-09-30 18:46:04 +08:00
anonsaber 7aa880c429 docs: §10.9 构建命令改为 npm ci + npm test
Cloudflare Git 集成的默认安装步骤实测用的是 bun install(日志
'Installing project dependencies: bun install'),bun 不读 npm 锁文件、
自己重新解析依赖('Saved lockfile'),仓库里提交的锁文件被完全绕过。
只填 no-op 构建命令意味着 CI 装的是 bun 解析出来的版本树,而不是我们
锁定的 wrangler 4.144.0。构建命令改成显式 npm ci 后由 npm ci 删掉
node_modules 再严格按锁文件重装;项目无编译步骤,顺带跑一遍 npm test
当门禁。

同时把 Node 版本说明改为实测值(CI 给的是 nodejs@24.18.0),并记录
wrangler 4 与 3 一样按 wrangler.toml 的 name 部署。
2026-09-30 18:08:57 +08:00
anonsaber e853032445 docs: 修正 §10.9 预览命令的建议——它是必填项,不是留空
上一条把预览命令写成「留空并取消勾选」,但 UI 里勾选启用预览构建后该字段为必需。
预览命令改用 npx wrangler dev --ip 0.0.0.0 --port 8787(wrangler 3.114.17 无
preview 子命令,dev 才有 --ip/--port;8787 是 dev 默认端口)。

同时澄清构建命令 ≠ 部署命令:部署命令(必需)保持 npx wrangler deploy 不动,
把 deploy 塞进可选的构建命令才是错的。补一句预览环境没有 BACKEND_ORIGINS_JSON,
所以预览只能验证 Worker 能拉起与路由表生效,后端转发只能看生产。

另补:根目录在折叠的「高级设置」里,设了之后三个命令都在 cloudflare-worker/ 下执行。

GATE-DOCS 6/6(114 行号锚点 / 252 节引用 / 469 路径引用)。
2026-09-30 17:10:35 +08:00
anonsaber 8d73b73fb5 docs: 新增 §10.9 网页版部署(Dashboard Code Editor / Git 集成)
补 Cloudflare Dashboard 的 Git 集成配置对照表——仓库根目录是 Rust 后端,
必须把根目录设成 cloudflare-worker,否则 Cloudflare 在仓库根跑 wrangler 直接失败。
另外三条:应用名要与 wrangler.toml 的 name 对齐、构建命令改成 no-op
(Cloudflare 构建后自己跑 wrangler deploy)、预览命令留空并关闭预览
(wrangler 3.114.17 无 preview 子命令,且预览环境没有 BACKEND_ORIGINS_JSON)。

GATE-DOCS 6/6(114 行号锚点 / 252 节引用 / 468 路径引用)。
2026-09-30 16:49:04 +08:00
anonsaber 048bd5d243 docs: 部署章节标出三个会让首次上线直接失败的坑
- §10.8 的 BACKEND_ORIGINS_JSON 示例用的是 {url,weight} 对象数组,但代码只
  接受字符串数组;且配置是每个请求重新解析的,症状是「每个请求 503」而不是
  「启动即 503」。补上 parseBackendOrigin 的位置与权重不存在的说明
  (lb.js 用 rng() 均匀选起始源)。
- 新增两条实测坑:wrangler.toml 的 JSDoc 注释会让 wrangler 在读配置阶段失败
  (Unknown character 47);npm test 在 Node 22.23 上 MODULE_NOT_FOUND。
- §10.9 验证第 2 条:/healthz 是 Worker 自生成、不透传后端,且 BACKEND_ORIGINS_JSON
  缺失/格式错/为空时 handleHealth 吞掉解析异常返回 HTTP 200 + no-backends,
  所以只看 200 会误判,必须看响应体的 available。补上三档判据速查。
2026-09-30 16:24:44 +08:00
anonsaber 2447106840 docs: describe the reconcile cursor, re-anchor drifted refs, fix three stale claims
reference.md: new Section 6.5 explains the bimodal cursor, the two token
classes (Session.state is not an Email-collection token; newState is), why a
truncated walk persists as a walk, and why oldState and destroyed are dropped.
Section 6.2 budget table is renamed to the new constant names and gains
RECONCILE_INITIAL_CHANGES. state:jmap:since is listed as a pipeline key.

opengaps.md: the re-baseline fix is described with the new session_state()
name, and the position-walk note no longer claims a state argument is passed
as None - the None is folder_id, and the method has no state parameter at all.

retired.md: the dead-code removal no longer claims those were the last three
#[expect(dead_code)] attributes in src/; reload_async still has one.

deployment.md / design.md: the 54+14 anchors the code move had shifted by one
hunk are re-anchored, plus two manual corrections (the /reconcile route and the
unconditional 204 return). charter.md: baseline 89 -> 93 passed.
AGENTS.md: the two anchor counts it quotes (60, 44) were stale; they are 54
and 17.

check_sec_refs.py: two-part section refs attributed to an RFC (RFC 8620
Section 2.1) are external, not doc references - the trailing-dot test only
caught the three-part form.
2026-09-30 14:11:52 +08:00
anonsaber 655167e862 docs: close the TTL gap, re-anchor drifted code refs, add anchor tooling
opengaps.md: the TTL item is now closed on the code side. The 21-value
table is keyed by ttl constant rather than by line number, so it stops
drifting. The honest caveat is called out in the open instead of being
implied away: the two real-Redis assertions are wired but unrunnable with
the credentials on hand, so 'assertion ready' is not the same as 'verified
on real hardware'. The residual-risk note that was still sitting under the
closed item has been removed along with it.

charter.md: test baseline 88 -> 89 passed.

deployment.md, design.md, retired.md: 41 stale src/ line anchors. The
drift was real and the audit missed it every time, because
audit_anchors.py only asserts that a referenced line exists and is
non-blank. Three are off-by-one; the rest are wrong code --
state.rs:379 pointed at XREADGROUP XACK while the claim was about
read_batch, retired.md:99 pointed into Intent::Search::parse, the two
route-table anchors landed on state: Arc::new(state),, and one
register_push anchor sat 31 lines above the fn.

scripts/docs_check/reanchor.py: maps HEAD -> working-tree line numbers
straight off git diff -U0 hunks, applies the fix or reports only with
--check. scripts/docs_check/show_anchors.py: prints every doc anchor next
to the line it lands on, which is what caught the semantic errors the
audit structurally cannot.
2026-09-30 13:20:13 +08:00
anonsaber bc68c6b241 docs: unblock GATE-DOCS (debug.rs anchors drifted + file over 500 lines)
debug.rs grew past 500 lines with no SPLIT-EVAL marker, and the seven
/src/debug/* anchors in deployment.md pointed at the blank line just
above each function - so GATE-DOCS was red on two unrelated pre-existing
counts (SIZE CHECK, ANCHOR AUDIT) while the other four checks were green.

Re-anchor all seven to the function bodies they describe, add the marker
with the reason we are keeping the module whole, and document the
redis_failure_detail classification that deployment.md still called
"redis_probe_failed". Bump the GATE-P0 baseline to 88.
2026-09-30 12:17:04 +08:00
anonsaber b764d6dc30 feat: reject stale business-config submits with a 409
revision becomes a request-body control field on BusinessConfigPatch. It is
never a setting: apply() and is_complete() ignore it, so the stored wire
never gains a revision key, and a PUT body that omits it keeps
last-write-wins for callers that never read the revision back.

The SPA records the revision it read, echoes it on every partial submit, and
on a 409 re-reads the stored values into the form and tells the operator to
recheck what they changed. Without that reload every retry would 409
forever; if the reload itself fails the SPA falls back to last-write-wins
rather than trapping the operator. The control field is excluded from the
empty-patch check so echoing it never counts as a change.

The compare-then-write is deliberately not atomic. Without a Lua script an
optimistic lock still has a residual window in which two requests racing
inside the same tick both pass and the later one wins; the window stays
small because a patch carries only the fields the operator actually changed.

notify.rs gained 18 lines before line 700, so its anchors in deployment.md,
opengaps.md and retired.md shifted by +18. Every one was checked against the
real line content, since the anchor audit only flags blank targets.

Gates: rust fmt/clippy clean, cargo test 87 passed 2 ignored, node --test
web/config.test.mjs 18 passed, docs_check/run_all.sh 6/6.
2026-09-30 02:56:15 +08:00
anonsaber 166b77eb34 docs: stop maintaining source line numbers in reference.md
`docs/reference.md` is the single source of truth and gets touched on every API
change, yet 40 of its 56 `notify.rs` anchors had drifted onto a closing brace,
a doc comment, or the wrong symbol - including one whole line pointing at
`revoke_admin_session` where a jmap dedup key is claimed - while
`scripts/docs_check/audit_anchors.py` reported every one of them clean. Its own
docstring says it only checks that the target line exists and is non-blank.

Remove the anchors rather than correcting them: fixing 40 numbers creates a
treadmill that re-drifts on the next unrelated edit to the same file, and the
file's own convention already called the line number "not an identity". Symbol
names are kept everywhere, which is what the gates and the readers need.

`docs/deployment.md` keeps its line numbers - it is an operator runbook read
mid-incident - and the five anchors that were wrong there are corrected.

docs/reference.md
- Drop the false "Verified against commit b2dbe7c" header claim; the anchors
  never matched that commit. Replace it with the design decision and the
  reason, and drop the "Only this file carries line numbers" convention that
  `deployment.md` was already violating.
- Remove all `*.rs:NNN` and bare `:NNN` anchors, keeping symbol names.
- Fix a wrong fact the anchors were hiding: the session issued by
  `POST /api/admin/session` is a fresh CSPRNG token generated per call, not a
  "fixed 32-byte hex secret derived from admin_token". The anchor pointed at
  `bootstrap`'s body.

docs/deployment.md
- `retry_or_dlq` call site 481 -> 479; `lock:reconcile` acquire 289 -> 290
  (twice); heartbeat `renew_lock` 302 -> 303 (twice).

AGENTS.md
- Record the convention: symbol names in docs, line numbers only in
  `docs/deployment.md`, plus the audit script's limits so nobody reads its
  output as "the anchors are correct".

scripts/docs_check/audit_anchor_semantics.py (new)
- Independent script, not wired into `run_all.sh`, always `exit 0`, prints
  candidates only. It flags an anchor whose target line has no relation to the
  symbol the doc claims. Candidates go 20 -> 5 and `reference.md` disappears
  from the list entirely. It cannot catch a one- or two-line off-by-one - that
  still needs a human - and a bare `:NNN` shorthand is not a matchable anchor.

Gates: GATE-DOCS 6/6 clean (ANCHOR AUDIT 324 -> 129 refs, 0 errors).
`src/` is untouched, so the test baseline stands at 86 passed / 0 failed /
2 ignored.
2026-09-30 02:02:34 +08:00
anonsaber e3924a53c1 test: cover business config read-back and partial submit
Adds the missing test coverage for the GET /api/business-config read-back
and the partial-patch PUT, then syncs the docs to the behaviour the code
actually has.

src/notify.rs
- PUT response body now carries "revision" alongside the
  x-business-config-revision header, which the SPA surfaces in its status line.
- 4 test helpers (a router that returns (Router, MemoryState) so a config can be
  seeded first, a full valid wire value, a direct state writer that skips
  validation, and a wire value whose JMAP URL fails fast) plus 9 tests:
  - GET 401 leaks no business field at all (body is exactly error + request_id)
  - GET echoes the 10 non-secret values and returns secrets only as presence
    booleans; the serialised body is asserted to contain none of the 6 secret
    values (SAF-NO-SECRET-ECHO)
  - GET with nothing stored returns 200 configured:false revision:0, not 404
  - a first save with an incomplete patch is rejected and writes nothing
  - a partial submit replaces only the fields it carries, verified by reading
    the merged result back over the same path the SPA uses
  - validation runs on the merged result, so changing one field cannot bypass
    the rest, and a rejected submit neither persists nor bumps the revision
  - telegram_chat_id is accepted as a number or a numeric string and a garbage
    string is rejected without overwriting the stored value
  - a typo in a field name is rejected rather than silently dropped

src/config.rs
- Pure deserialisation test for de_i64_from_number_or_string, with no router and
  no store. This is the only place that separates "the custom deserializer
  refuses the string" from "a later validation step refused it" - a real
  distinction, since the SPA submits telegram_chat_id as a string on a partial
  submit while the read-back model returns a number.

cloudflare-worker/test/index.test.js
- The forwarded-route test asserted a fixed upstream origin, which is not stable:
  the LB rotates its start index between tests. Assert the origin is one of the
  configured backends and check the path and method exactly instead.

docs
- 17 spots bring the docs in line with the shipped contract: GET is now
  documented, PUT as a partial patch, the worker safelist at 16 routes, and the
  preflight path listed as forwarded.
- Corrections the docs had backwards: the response field is "configured"
  (revision is a u64, 0 when nothing is stored); Invalid returns 422, only
  Unreachable returns 503; there is no chat_allowlist_empty error code.
- "Blank keeps the stored value" is now stated as a client-side contract. The
  backend does not distinguish an omitted field from an empty string - apply()
  uses unwrap_or_else, so an explicitly submitted "" really does clear the
  secret (validation then rejects it). Saying it was server-side was wrong.
- POST /worker was listed as a forwarded route though it is not in SAFE_ROUTES,
  and the per-category counts did not match the lists they introduced.
- POST /api/bootstrap does not share the patch-merge contract; it deserialises a
  full BusinessConfigWire, which is the only path that can create a config from
  nothing.
- Re-anchored 9 src/notify.rs line refs that had drifted blank and raised the
  baseline to 86 passed / 0 failed / 2 ignored.

Gates: fmt, clippy -D warnings, test 86/0/2 ignored, worker 32/32, SPA 17/17,
GATE-DOCS 6/6 clean.
2026-09-30 01:24:42 +08:00
anonsaber 0cee50b4c9 feat: read business config back and accept partial patches
GET /api/business-config returns the stored values with presence-only secrets, and PUT now merges a patch against the stored config instead of replacing it, so the SPA can show what is already set and send back only the fields that changed.

The SPA marks secrets as set-but-unreadable, edits chat_allowlist as an unordered set, and omits fields it did not touch; blank required fields keep the stored value, blank optional fields clear it. The read-back is Serialize-only, so a client cannot inject secrets_present.

Forward both paths at the gateway: /api/business-config accepted PUT only, so the read-back returned 405, and the preflight path was missing from the safelist entirely, so it returned 404. The SPA is served from the Worker domain, so the whole edit experience was unreachable behind the production gateway. Route methods are now asserted per path, which the safelist test never checked.

Also: /debug/config reports timezone again, the timezone select is styled like the other fields, and the docs follow the new contract.
2026-09-30 00:53:58 +08:00
anonsaber 953a4db6f0 docs: document the notification rendering contract and sweep anchors
New reference.md 5.4 pins the user-visible contract: notifications are three
metadata lines only (From / Subject / Received), never the body and never an
LLM summary; the mailbox display form and its fallback literals; the
timezone field, its 16-zone whitelist, the 422 on anything else, and why DST
is not tracked. Registered as REQ-TIMEZONE-DISPLAY in charter 8.

deployment 5 gains the TIMEZONE row, including the SPA section and the
reason DST zones cannot be added.

Opengaps 1 drops two blockers that are verified done and moves the remaining
two to a "what you do / what I do" checklist.

Corrected doc claims that the line-number checker cannot reach:

- reference 6.2 and the Redis key table cited notify.rs 240/253 and
  252/253 for lock TTL and heartbeat; the lock is acquired at :289 and
  renewed at :302.
- The Redis key table's dedup:tg / dedup:jmap / ratelimit / stream call-site
  anchors all pointed into the ready() handler and into unrelated config
  helpers. Re-pointed at the real statement lines.
- Both Retry-After helpers were anchored at error_response 321-329 and
  error_response_with_id 1088-1094; the real definitions are 370-378 and
  1368-1375, and the readiness path passes retry at :210, not :162.
- design claimed summarize() is also called by notify.rs for new-mail
  notifications. There is exactly one call site, the /summary branch in
  worker.rs; notifications never call the LLM.
- design described list_emails as requesting an explicit property list and
  returning Vec<EmailSummary>; the code passes no properties and returns
  Vec<EmailMetadata>.
- retired listed 6 intents but only 5; worker.rs:533 for /search is :553.
- Config is 7 fields now that timezone is mirrored into it.

The anchor audit now flags any citation that lands on a bare brace, paren or
comma - the shape these drifted references had.
2026-09-29 21:48:04 +08:00
anonsaber 8b1afac430 docs: close two integration blockers and document the worker drain schedule
- opengaps: drop the Telegram inbound callback and Stalwart PushSubscription
  blockers, both verified live; 2 items remain (newState semantics, TTL
  measurement). The public-callback mapping question is also resolved -- the
  integration env has no Worker in front and Stalwart hits the backend origin
  directly, while /push/jmap is already in the Worker safelist for production
- deployment 4.1 (new): full setWebhook and /api/push/register procedure,
  expected replies, failure symptoms, and the setWebHook rotation trap (the
  deployed secret must be re-registered after any TG_WEBHOOK_SECRET change)
- deployment 6.2: the worker is neither a background task nor a separate
  container; POST /worker is the only consumer entry point
- deployment 6.3.1: add the /worker drain step to the cron and k8s CronJob
  examples, plus a two-endpoint comparison table, ordering requirements, the
  10-message batch cap, and the "204 is not a success signal" warning
- deployment 10.4: describe /worker as scheduler-driven, not manually invoked
- reference, retired: /worker anchor notify.rs:331 -> 380; the old value fell
  inside the reconcile function body, so the anchor audit passed while being
  semantically wrong
- charter 6.6: narrow the blocker list; code baseline b2dbe7c -> fc686ab
- design 11.2: PushSubscription permission now verified; the external Cron
  must call both /reconcile and /worker

GATE-P0: cargo fmt / check / clippy clean, 69 passed, 1 ignored
GATE-DOCS: 6/6 clean (ANCHOR 299, SECTION-REF 234, PATH 428)
2026-09-29 20:55:54 +08:00
anonsaber d4c4c1d09b docs: rename roadmap.md to opengaps.md and drop completed items
- rename docs/roadmap.md -> docs/opengaps.md: file now holds only
  still-open / still-unverified items, so the name matches its content
- removed items proven done during the 2026-09-28 live integration run:
  /search E2E, Telegram 429 backoff, multi-instance duplicate window,
  /ready end-to-end dependency probe, JMAP read-only adapter real-device
  verification, real platform log collection acceptance
- removed the C-NO-LONG-CONN long-polling item (permanent non-goal,
  already registered in docs/retired.md) and the duplicated Redis ACL
  encoding clause (merged into the Redis TLS item)
- removed the whole 验收待办 section (all 3 items resolved)
- narrowed the phase goal to setWebhook + PushSubscription callback chain
- baseline corrected 61 -> 69 passed / 0 failed / 1 ignored, re-measured
  2026-09-29 with cargo test --locked --bin message-weave
- docs/charter.md D-G1-1 marked real-device verified, closing the
  contradiction with docs/design.md:397/:600
- update the DOCS list in all 4 docs gate scripts + TARGET_BEFORE regex
- GATE-DOCS 6/6 pass: VALIDATION, TABLE, ANCHOR 269, SECTION-REF 224,
  SIZE, PATH 392
2026-09-29 19:38:38 +08:00
anonsaber fc686abc22 config: persist business config regardless of client build, add preflight probe
PUT /api/business-config and POST /api/bootstrap now treat validation as the only
write gate: a valid wire is always persisted, and only then are the clients built
and the running worker swapped. A failed build returns 200 with persisted=true,
runtime_applied=false and a warnings array of {component, step, detail} instead of
503, so an unreachable JMAP/LLM no longer turns a valid configuration into a silent
data loss. The previous worker keeps serving.

POST /api/business-config/preflight runs the same validation and client build
against the submitted wire without writing anything and without touching the
running worker. It answers 200 even when the configuration is bad, because that
is the answer the caller asked for; components is null after a validation
failure, and llm is null rather than vacuously ok when LLM is disabled.
Authentication is the admin-session gate, not DEBUG_TOKEN.

The SPA drops the account_id field (the backend still accepts it; omitted falls
back to the session primary account), adds a Test connection button, and shows
the build fingerprint in the footer, the topbar and the setup card. The
503 message no longer claims JMAP/LLM build failure, which is not what produces
it.

BusinessConfigWire.account_id gains #[serde(default)]; without it, omitting the
field in the wire body made deserialization fail outright.

build.rs bakes BUILD_VERSION (git sha or nogit, plus a UTC build timestamp) which
GET /api/status exposes as version.
2026-09-29 18:25:56 +08:00
anonsaber 80d13c0292 fix(notify): stop exposing the business and admin routes in configuration-setup mode
The setup router delegated to the full factory, so all 12 business and
admin routes were registered even though not one could ever work:
admin_token is an empty SecretString and constant_time_eq has a
!expected.is_empty() guard, so an empty expected value rejects every
candidate forever. MemoryState could not persist a bootstrap write either.

Those routes answered 401 {"error":"unauthorized"}, which is
indistinguishable from a mistyped credential. An operator or a probe
reads that as "try a different token" when the truth is "these
endpoints do not exist in this mode".

router_configuration_setup now builds its own AppState and mounts only
/api/status, /ready and /healthz. Verified live with no env vars:
healthz 200, ready 503, /api/status 200 with the missing list, and all
12 business/admin routes 404. The SPA is unaffected: /api/status is the
only endpoint it calls at startup, and web/config.js reveals the
admin-session card only when ready === true.

Added configuration_setup_mounts_only_status_and_probes to guard the
route table, and configuration_setup_call as its helper.

Docs: reference.md section 3 and 5.1 now describe the reduced surface
and cite the empty-expected-value guard; deployment.md's probe table had
/api/status listed as 503 {"status":...} when it returns 200 with a
"mode" field; retired.md section 4.1 records the removed route
registrations. Anchors refreshed for the +19 lines in notify.rs.
2026-09-29 15:26:54 +08:00
anonsaber 4cf128fcc8 feat(debug): 开关信号改为 DEBUG_ENABLED 环境变量,启动命令不再需要改动
起因:用户反馈会临时改启动命令(比如给 start 加 --debug)。而 hoststack.yaml
声明的 start.command 优先级最高且每次部署都覆盖控制台旧值,所以每次开关调试面
都得改 YAML、提交、推送、部署——最麻烦的那条路。

改法:把双因子的「开启信号」从单一 argv 变成「argv 或 env 二者之一」:
- --debug 保留,本地开发照旧用
- 新增 DEBUG_ENABLED(1/true/TRUE/True/yes/YES,精确匹配),生产走控制台环境变量
- DEBUG_TOKEN 仍然必须非空。刻意不让 token 单独生效——token 是平台上的长期
  Secret,让它自己开门就等于把双因子退化成单因子

收益:生产开关调试面 = 控制台改一个 env + 重新部署,不改代码、不改 hoststack.yaml、
不重新构建。启动命令从此静态,顺带消解了"YAML 还是控制台"的争论——命令不再需要变,
放哪都无所谓。

实现:把判定抽成纯函数 debug_surface_requested(debug_arg, debug_enabled_var),
不直接读全局 env。env 是进程级全局态,测试里读它会和同二进制内其他测试竞争;
调用方传入已取好的值,测试就能覆盖真值集合、假值集合(含 "TRUE " 带空格、
"debug" 这类近似值)与"开了开关但没 token 仍然关闭"。

文档:deployment.md §2.1 双因子条件重写 + 环境变量清单;§5 表格;§5.1 启动命令
说明;reference.md §3 表与调试面描述;design.md 架构图注与 LLM_ALLOW_NET 锚点;
charter.md 两条 ID 描述。hoststack.yaml 的 start 注释从"临时加 --debug"改成
"用 DEBUG_ENABLED 切"。

顺带修掉加代码引发的锚点漂移(新代码把 main.rs 后面的行号整体后移 13):
design.md:366、design.md:739、reference.md:205/335/336/380 共 6 处。

验证:cargo test --bin message-weave = 65 passed / 0 failed(新增 4 个测试,
含真值集合、假值集合、无 token 仍关闭)。GATE-DOCS PASS 6/6,259 line-refs 全绿。
2026-09-29 12:54:06 +08:00
anonsaber 633b41394c docs: 回答 hoststack.yaml 的来历与官方做法,补上命令字段不回写的证据
回答用户追问「这个文件哪里来的、官方推荐怎么做」。git 考古 + agent 源码两条路:

来历:a571033 自己手写的(2026-09-25),不是 HostStack 生成的。agent 镜像里既没有
init 类命令也没有内嵌模板 YAML(find 全仓 0 个 yaml 文件),只负责在仓库根读取
hoststack.yaml 或 hoststack.yml。所以"官方推荐怎么写"没有标准模板可抄,只有 schema。

官方做法:源码自己的定位是 Infrastructure-as-Code——
  "hoststack.yaml is Infrastructure-as-Code: when the repo declares a command,
   it wins over whatever happens to be cached on the services row"

新证据,把"UI 更方便管理"这个前提彻底否掉:agent 里只有两个 YAML->DB 回写事件
(yaml_port_declared、yaml_disk_declared),**命令字段没有**。注释原文明说
"the two that need to reach the services row have their own handled frames"。
所以每次部署都是拿 YAML 临时覆盖 services 行里的旧值,DB 里永远是过期的
./target/release/app。port 与 disk 要回写是因为 autoscaling 和 sleep-wake 直接
读那行;命令只有部署路径自己读,不值得持久化。

结论:控制台对命令字段永远是过期缓存,不存在"以 UI 为准"的稳态。
要删 hoststack.yaml,必须先改控制台那三条命令,文档里已有此前提。

audit_paths.py:hoststack.yml 加入 CONVENTIONAL allowlist——它是 yaml-parser
实际接受的第二种文件名,与已在白名单里的 docker-compose.yml 同类。

验证:GATE-DOCS PASS 6/6(PATH AUDIT 378 path-refs / 0)。
2026-09-29 12:25:08 +08:00
anonsaber cf252a9f06 docs+build: Dockerfile 降级为仅本地开发用,并记录 hoststack.yaml 保留/移除决策
用户要求两件事:把 Dockerfile 明确降级成「仅本地开发用」并说清边界;
以及若日后决定移除 hoststack.yaml,把理由写进相关文档。

先核了一遍决定性的技术前提——删掉 YAML 到底会发生什么。读 HostStack agent
源码,优先级是三层,而且和我上一轮写的说法不一样:

  1. 控制台 services 表已存的值 -> payload
  2. YAML 声明的字段无条件覆盖(guard 只是 `if (svcConfig.start?.command)`,
     没有 `&& !payload.x` 短路)
  3. YAML 省略的字段沿用控制台值;框架默认值只在仍为空时才填,而 agent 自己的
     注释写着 "trigger-payload always populates payload.x from the DB",
     所以对已建好的服务这条分支实际是死代码

因此删掉 hoststack.yaml **不会**回落到 cargo fetch / app 那套默认值,而是直接
采用控制台现存的值——而那恰好就是坏掉的 ./target/release/app。"UI 更方便管理"
这个前提成立,但必须先改 UI 再删文件。据此写了决策记录,当前决定是保留。

Dockerfile / docs/deployment.md §3 / docs/design.md / README.md
- 统一标为仅本地开发 / 本地容器调试路径,生产不执行
- 写清边界后果:诊断工具、ENTRYPOINT tini、EXPOSE 8080 在线上都不生效
- 给出判定方法:容器内看 /proc/1/cmdline 与 /etc/os-release
- 顺带修掉 design.md 里把 hoststack.yaml 描述成"网关编排清单"的错误——
  文件里没有任何 gateway,只有 services.web

docs/deployment.md §5.1
- 三层优先级替换掉原先"YAML 省略则回落框架默认值"的错误说法
- 新增决策记录:保留的理由(进 git、可 review 可回滚)与代价(双写);
  若日后移除,必须在控制台先把 install/build/start 三条改对再删,并把本段
  移到 docs/retired.md 记下移除 commit

验证:GATE-DOCS PASS 6/6(SECTION-REF 226 refs / 0,PATH AUDIT 376 refs / 0)。
2026-09-29 12:22:00 +08:00
anonsaber 978288f8d7 build+docs: 用 HostStack agent 源码实证校正部署事实,砍掉 dig 的 42.7MB 膨胀
从本机缓存的 registry.hoststack.dev/hoststack/agent 镜像里直接读出运行时
配置,纠正了此前靠猜的四条部署事实:

hoststack.yaml
- 撤回上一版把 install: 合并进 build.command 的"修正"——schema 里
  install.command 本来就是合法键(agent 的 schema 与 yaml-parser.ts 均定义),
  install/build/start 是三条独立命令
- 补上为什么这个文件不能删:runtime: rust 的框架默认 start 命令是
  ./target/release/app,与 Cargo 包名无关。删掉 YAML 后 Start Command
  回落到 app,进程在绑定端口前就以 not found 退出
- 记录实测优先级:YAML 值生效,省略才回落框架默认值(Cargo.toml 只声明
  [[bin]] message-weave,仓库里既无 app 目标也无 app.rs)

Dockerfile
- 移除 bind9-dnsutils:连带 libicudata.so.72(29.8MB)等多级依赖,实测
  边际成本 42.7MB,是其余 7 个工具总和(19.7MB)的两倍多
- DNS 解析用基础镜像自带的 getent 已覆盖(getent hosts / ahostsv4 / ahostsv6)
- 注释写明 19.7MB 的实测口径

docs/deployment.md
- §5.1 重写:build 在 rust:slim-trixie、runner 是 debian:trixie-slim,
  本仓库 Dockerfile 完全不被执行
- 修正"没有 install: 键"与"validate 拦未知键"两处错误说法:agent 部署路径
  不应用 zod 校验,未知键被静默丢弃而非报错,validate 才是唯一防线
- §4.1 容器安全档改成源码实测值:readonlyRootfs/dropCapabilities/
  noNewPrivileges 全为 true,pidsLimit 256,tmpfs 选项 rw,nosuid,nodev,
  size=64m——原先写的 noexec 并不存在;并标注 dev 档 rootfs 可写
- §8.1 明确两条部署路径的镜像差异(bookworm vs trixie)
- §6 HEALTHCHECK 与二进制"内置 health 子命令"的过期说法
- 删除文档中指向不存在文件 app.rs 的引用

验证:GATE-DOCS PASS 6/6(PATH AUDIT 369 path-refs / 0);
runtime 阶段实测构建成功且 curl/ps/pgrep/ss/ip/jq/nc/getent 齐备、
dig 按预期缺席、getent hosts 可解析、uid 999;
8 个工具 dpkg Installed-Size 合计 7935kB 而全量 du 差 62.3MB,
剔除 dig 后 19.7MB——这个差额就是本次砍掉的膨胀。
2026-09-29 12:15:52 +08:00
anonsaber 417f378d68 build+docs: 镜像内置只读诊断工具,清理 Dockerfile 的死 ENV 与文档过期表述
生产镜像此前只有 ca-certificates + tini,容器 rootfs 又只读,运维在容器内既
装不了 apt 也没有 curl/ps,排查只能靠宿主机的 /proc。把只读诊断工具装进
runtime 阶段,实测体积 +7.7 MB:

  curl procps(ps/pgrep/free) iproute2(ss/ip) jq bind9-dnsutils(dig) netcat-openbsd(nc)

全部是只读查询能力,不引入包管理之外的写能力,也不新增 shell 解释器。

顺手修掉四处已被事实推翻的表述:

  1. Dockerfile 的 ENV RUN_MODE=webhook 是死变量——该标识符随 Config::from_env()
     删除后代码零读取,文档 5 处都记着已删除,镜像却还在设。删掉并留注释防回退。
  2. deployment.md 说「runtime 只装了 ca-certificates tini」「镜像内没有 curl/wget」,
     两处都是健康检查建议的承重理由,随内置 curl 一起更新为「技术上可行但不建议」。
  3. deployment.md 说非 root 用户是 uid 1000,实际 useradd --system 给 uid 999,
     已实测修正。
  4. retired.md 里 compose healthcheck 示例的删除理由把「镜像无 curl」当主因,
     真正的承重原因是 src/main.rs 没有 CLI 子命令解析,已改写并标注 curl 已内置。

同时补齐 hoststack.yaml 缺失的 install 段(cargo fetch --locked),并在 start 段
写清临时开 --debug 的确切改法与「必须在容器内探、别走公网域名」的约束。

验证:
  - 包名与安装步骤在同一 debian:bookworm-slim 基础镜像内实测通过
  - useradd 实测输出 uid=999,与设计一致
  - docker build --check 无告警
  - GATE-DOCS PASS 6/6(SECTION-REF 217 / 0,PATH AUDIT 364 / 0)

注:install: { command: ... } 的键名是按现有 build:/start: 的同构推断的,
若 HostStack 拒绝该键,删掉这两行即可,不影响 build/start。
2026-09-29 11:24:13 +08:00
anonsaber 55a2bf5a14 docs: 修正 6 处代码行号锚点漂移,补 1 处缺失锚点
全量人工核对 44 个 `file.rs:行号` 锚点,发现并修正 6 处解析通过但指向错误行号的锚点
(`audit_anchors` 只验证锚点可解析,不验证该行是否承载文中所述内容):

- src/main.rs 的 `--debug`/DEBUG_TOKEN 双因子读取块已从 96-109 上移到 82-92:
  deployment.md:62 (96→82)、:63 (97-100→82-89)、:65 (107-109→90-92),
  reference.md:228 (96-100→82-89)
- SendMessage 结构体在 channel.rs:60 而非 :10(原指向 TELEGRAM_BACKOFF_BASE_MS 常量)
- reference.md:206 生产路由合并点是 main.rs:180 而非 :194;205 的 setup 路由锚点同处校正
- design.md:739 的 llm 构造分支锚定 111-127 整段而非孤立的 :125
- deployment.md:69 补上 worker_authorized 自身定义点 (notify.rs:446),
  原先只有 constant_time_eq (1136) 一个锚点,读者跳转后看不到被命名的符号

校验:GATE-DOCS PASS 6/6,ANCHOR AUDIT 250 line-refs / 0 errors,
PATH AUDIT 363 path-refs / 0 errors,人工 dump 复核 44/44 锚点落点正确。
2026-09-29 10:14:03 +08:00
anonsaber 2da11b9f92 docs+fix: delete the legacy env compat layer; sync every doc that described it
Code (src/config.rs 521->394, src/main.rs 232->200):
- Config::from_env() + required_secret / required_nonblank / env_bool deleted.
  config.rs now performs no std::env read; all business fields come from Redis
  business config (BusinessConfigWire -> validate_business_wire -> validate_nonblank).
- RUN_MODE deleted: variable, Config.run_mode field and the main.rs validation
  block. The two modes never changed runtime behaviour -- webhook and reconcile
  share one router, POST /reconcile is a standalone endpoint.
- jmap_password() accessor deleted; the field name is kept in
  BusinessConfig / BusinessConfigWire because it is real data, not a stub.
- Config.port and Config.redis_url deleted: both had zero readers, and port was
  hardcoded to 8080 in both constructors while the listener binds straight from
  the PORT env var, so the field could silently disagree with the real port.
  Config is now 6 fields: telegram / jmap / account_id / llm / auth / worker_token.
- redis_only() and from_business(value) signatures simplified accordingly.
- #[expect(dead_code)] count in src/ is now 0.

Test coverage: the from_env()-driven startup_rejects_blank_auth_secret case is
gone with the path it tested. The non-leak assertion it carried was reattached
to the real validation route (BusinessConfigWire -> TryFrom -> validate_nonblank)
with a stronger third assertion that the rejected value is not echoed either.

Docs: design.md 7.1 re-scoped to the Redis business config table; reference.md
5.1/5.3 rewritten (no legacy env path); deployment.md 5 and the runtime-mode
table rewritten; retired.md gains section 4 registering every deletion;
README x2, .env.example, charter.md updated.

GATE-P0: fmt / check / clippy -D warnings green, 61 passed / 0 failed / 1
ignored (was 62; the deleted case). GATE-DOCS: PASS 5/5, ANCHOR 247 line-refs /
0, SECTION-REF 216 / 0.
2026-09-29 02:02:44 +08:00
anonsaber 638c3a8cbc docs: consume all four self-checks; make the file-size rule enforceable
Every member's audit is now read and each real finding fixed, not just reported.

AGENTS.md §2.1
- The 500-line soft cap now has a machine-checkable exception: an over-limit
  file must carry a one-line `SPLIT-EVAL:` marker stating the split decision.
- Six files were over the cap with no justification: notify.rs 2036, state.rs
  1586, worker.rs 1045, config.js 1079, client.rs 601, config.rs 521. All now
  carry the marker. client.rs was missed by my own earlier line count, which
  did not descend into src/domain/jmap/.
- New validator scripts/docs_check/check_file_size.py; GATE-DOCS 4/4 -> 5/5.
  It proves the marker exists, not that the written reason is sound.
- Re-based 144 line anchors across six docs for the +1 line each file gained;
  every shifted anchor verified against the code, not just for non-blankness.

audit-arch.md
- design.md §6.1 module matrix omitted the `debug` module entirely; added.
- Seven numeric duplications in design.md now defer to reference.md §6.1 as
  the single authority instead of restating the values.
- reference.md §5.1 was missing DEBUG_TOKEN; §5.3 listed six recognised names
  and guessed `JMAP_*`. It now lists all 20 exactly as config.rs reads them.
- Corrected two wrong claims in the audit itself: debug.rs is compiled
  unconditionally, not under #[cfg(debug_assertions)] (there are no cargo
  features at all), and /debug/* exposes 7 routes, not the invented session
  list / resend / rebuild surface.

audit-fileplanner.md
- reference.md cited a nonexistent `jmap_service.rs`; replaced with the real
  adapter chain worker.rs -> domain/jmap.rs -> domain/jmap/client.rs.
- cloudflare-worker/README.md was outside every validator's scope; all four
  doc validators now include it (208 section refs, 250 line refs).
- README.zh-CN.md stated only half of what README.md says about RUN_MODE; the
  forward-placeholder sentence is now bilingual.
- charter.md §7 boundary table was missing rows for itself and for web/.

audit-rust.md / audit-frontend.md
- Error envelope corrected: `error` is a bare machine code, no `message`.
- Status table, AI-consent labels and ~15 stale or phantom facts fixed against
  notify.rs; `TelegramClient::SendMessage` and `web_config` phantoms removed.
- GET|PUT /api/enabled forwarded by the worker so the SPA kill switch works.
- Ten UI strings that called the admin credential the Redis ACL password now
  say CONFIG_ENCRYPTION_KEY.
- POST /healthz returns 405; dead HTTP_STATUS removed.
- audit_anchors.py now flags identifiers that do not exist in the file they
  are anchored to.

charter.md
- `SAF-ENABLE-FLAG` registered (85 IDs); `SAF-ADMIN-SESSION` row corrected;
- `REQ-PUSH-TYPES` registered; the stale `admin_session_digest` removed.

Gates: GATE-DOCS PASS 5/5 (250 line-refs, 208 section refs, 0 errors);
GATE-P0 62 passed / 0 failed / 1 ignored, baseline unchanged; worker and SPA
36 tests, 0 failures.

Real Stalwart / Telegram / managed Redis verification stays blocked on missing
credentials and remains labelled as unverified.
2026-09-29 01:16:11 +08:00
anonsaber e0882c7c68 docs: de-projectize AGENTS.md into language-agnostic norms; add docs/charter.md
AGENTS.md (276 -> 239 lines) is now a language-agnostic engineering-norms
document: code style, config and secrets handling, build environment,
testing gates, document governance. It states no project fact and names no
language, framework, dependency, or file. Verified: zero hits for JMAP,
Telegram, Redis, axum, Cloudflare, LLM, *.rs, and every project env var.

All project-specific content moved to the new docs/charter.md (~276 lines):
project goals, locked technology choices, 23 numbered security invariants,
implementation stages, prohibitions, test/acceptance gates with the full
GATE-P0 command and baseline, document boundary rules, and the stable ID
registry.

docs/charter.md §8 is the single authority index for stable IDs: 83 rows,
no duplicates, ID | definition file | one-line statement | category. Four
IDs that were referenced across the docs but never registered are now
registered: ARCH-STATE-REDIS, C-REDIS-EXTERNAL, GATE-UPTIME-KUMA, GATE-DOCS.
All previously registered IDs are preserved.

Defect fixed while rebuilding the registry: SAF-ADMIN-SESSION cited
src/config.rs `admin_session_digest`, a name that has 0 hits in src/ -- a
phantom identifier that survived in the authoritative registry since before
this restructure. Corrected to `session_digest` (src/config.rs:7). All 8
distinct backticked symbols in the registry's definition-file column now
verify against src/.

Two false project facts removed from the docs (both claimed the SPA writes
through POST /api/bootstrap, which web/config.js never calls -- 0 hits; the
actual path is PUT /api/business-config): README.md, README.zh-CN.md,
docs/reference.md. The first successful write creates the configuration and
later writes hot-reload it; POST /api/bootstrap remains the one-shot
automation endpoint.

Cross-reference redirections in 9 files: README.md, README.zh-CN.md,
docs/deployment.md, docs/design.md, docs/reference.md,
cloudflare-worker/README.md, cloudflare-worker/src/index.js,
cloudflare-worker/wrangler.toml now point project facts at charter.md and
language-agnostic quality rules at AGENTS.md.

Four validators extended to cover docs/charter.md: DOCS lists in
audit_anchors.py, check_tables.py, validate_docs.py, check_sec_refs.py, plus
charter.md added to check_sec_refs.py's TARGET_BEFORE regex and to
validate_docs.py's index-file cross-doc exemption.

Gates: GATE-DOCS PASS 4/4 (VALIDATION 0 errors, TABLE STRUCTURE 0
mismatches, ANCHOR AUDIT 227 line-refs / 0 errors, SECTION-REF AUDIT 191
refs / 0 errors). GATE-P0 PASS, baseline unchanged 62 passed / 0 failed /
1 ignored. Anchor audit proves line reachability only, not that the line
contains what the prose claims.
2026-09-28 23:39:26 +08:00
anonsaber b70d188864 docs+fix: sweep stale and phantom references; log the actual bound port
Code (2 sites):
- main.rs logged bootstrap_config.port, which is always the hardcoded 8080 in
  the two-variable production config; the listener actually binds the port
  parsed at main.rs:31-34. Log the bound port.
- That exposed Config.port as genuinely unread (clippy -D warnings), so mark it
  with #[expect(dead_code, reason=...)] instead of silently deleting a
  documented env-parsing site.

Docs, phantom identifiers (names that do not exist in src/):
- RuntimeConfig x3 -> OutboundConfig via RuntimeConfigProvider (state.rs:34/41)
- LlmClient::noop() x2 -> None in Option<Arc<LlmClient>> (main.rs:125)
- main.rs::validate_env_or_exit x2 -> config.rs:338 read, main.rs:75 validation
- TelegramChannel::send_message -> TelegramClient::send_text (channel.rs:134)

Docs, stale facts:
- LLM table: ENABLED and ALLOW_NET defaulted true,true -> false,false;
  API_KEY, BASE_URL, MODE were "required" -> only required when enabled. This
  contradicted design.md:385-387, which already had the correct values.
- design.md:560 said RUN_MODE "is actually consumed"; it is only read and
  validated and never affects behaviour (main.rs:73-74).
- RUN_MODE operator docs (README, reference, deployment, .env.example) now say
  both accepted values produce identical behaviour.
- retired.md: 5 intents -> 6 (/search shipped, worker.rs:517); 4 LLM env vars
  -> 6; main.rs tracing events 6 -> 7.
- design.md:494 tracing count 6 -> 7, debug-gate warning added to the list.
- design.md:350 code-gap count 2 -> 1 (multi-instance window done in 6c99ce5).
- design.md:554 marks the 45-paused stage-0 baseline explicitly as historical.
- .env.example said the Redis ACL password was the bootstrap trust root; it is
  CONFIG_ENCRYPTION_KEY (main.rs:88-91).

Docs, re-anchored after the main.rs shrink (6 refs shifted by -2).

GATE-P0 62 passed / 0 failed / 1 ignored; GATE-DOCS 4/4 clean
(228 line anchors, 211 section refs, 0 errors).
2026-09-28 22:33:27 +08:00
anonsaber 399b26918e docs: ④ /debug/* 配套文档 + 全量锚点重锚 + AGENTS v3 版本基线(01a0e6de)
## 锚点重锚(afa6cec 之后)

④ 对 notify.rs 的编辑使一批 `notify.rs:N` 引用整体失效。全量重扫 8 个 md、
165 个 src 锚点,0 硬错误(越界 / 区间全空 / 单行指空行三类全查)。修正要点:
- reference.md(30+ 处):dedup/committed/inflight/ratelimit 键调用点、
  error_response 320-328、error_response_with_id 1087-1093、readiness 161、
  router 1275 + routes 1304-1318、worker 330、main.rs 40/50/34/78-81、
  NoopWorker 由 notify.rs 更正为 worker.rs:142-144、
  PROBE_TIMEOUT 73 与 tokio::join! 147、state.rs 639。
- deployment.md:149-152→227-230、159/172→239/252、index.js 40-55→45-60。
- retired.md:704→717、887-890→897-900、326→330、873→884。
- roadmap.md:95→175;design.md:main.rs 109→128。
- cloudflare-worker 侧 4 处 stale:ROUTE_METHODS 45-60、404 77-78、
  405 80-83、503 85-93。

## /debug/* 文档

- deployment.md 新增 §2.1:双因子门禁、7 条路由状态码表、/debug/config 字段清单、
  三条部署约束、生产建议;§5 env 表补 --debug / DEBUG_TOKEN。
- README.md / README.zh-CN.md 各加一段「远程联调面(可选,默认关闭)」,指向 §2.1。
- design.md 新增 §7.6「为何默认绝对关闭」:双因子挂载、404 而非 401
  (401 会泄漏路由存在性)、无默认开启回退、不在网关白名单内 fail-closed。

## 文档纠错(与任务书相反,已按源码核实)

- /debug/worker 是 GET 不是 POST(debug.rs:79)。
- /debug/config 不是「只出布尔」:明文回 jmap.{session_url,username}、
  telegram.chat_id、llm.{base_url,model} 与全部 timeout/retry,
  仅 5 个凭据字段出 *_configured。文档措辞改为「不含凭据,不是全脱敏」。
- 门禁位置更正:--debug 读 main.rs:99、DEBUG_TOKEN 读 main.rs:100-103、
  merge 在 notify.rs:1320-1321(无 DEBUG_BASE 常量,路径为字面量)。

## AGENTS.md

- 版本基线 v3(代码 afa6cec / 文档 e502c40),三处文档基线号 c5bc7b8→afa6cec。
- 新增 2 个 ID:SAF-DEBUG-ORIGIN-ONLY(不在网关 14 条白名单,Worker 404
  route not forwarded,只能直连 origin)、SAF-DEBUG-ALLOWLIST。
- §6 deployment.md 行、§7 六行 ID 定义点回填文档位置。

## 未决项登记

- roadmap.md 新增:SAF-DEBUG-ALLOWLIST —— debug.rs:232-235 的白名单判定
  「非空且不含」导致业务白名单为空时 /debug/notify 的 chat_id 不拦截。
  本轮不改代码(该面默认关闭且需 Bearer,空白名单下主产品本就接受任意 chat);
  若要收紧需改为「空白名单则拒绝」+ 补测试 + 跑 gate。

## 校验

文档校验器 0 error;负向对照断链/死锚点/奇数反引号/页内锚点 4 类注入全命中。
48 张 markdown 表 0 处单元格数不符。行数合计 2415。纯文档,未触碰 src/ web/
cloudflare-worker/。代码基线仍 afa6cec,gate 49 passed / 0 failed / 1 ignored。
2026-09-28 16:20:18 +08:00
anonsaber 82794c95cf worker: /reconcile 走 per-route 长超时且绝不故障转移(01a0e595)
POST /reconcile 是后端同步长任务:后端持集群级单飞锁 lock:reconcile(初租 300 s,
期间每 30 s 心跳续租至 90 s,notify.rs:159/172),但网关原先只有全局超时 10 s、
最多 2 次尝试。一次完整对账很容易撑过网关窗口被误判失败,随后故障转移到第二实例,
而第二实例必然立刻返回 409;客户端既拿不到 204 也拿不到 409,只能看到
"all backends failed"。

改动:
- handleFetch 为 /reconcile 单独覆盖超时与尝试次数:超时取 LB_RECONCILE_TIMEOUT_MS
 (默认 320000 ms,大于锁初租 300 s + 心跳余量),maxAttempts=1 绝不故障转移
  (切实例只会撞锁,没有任何收益)
- 其余快路径完全不受影响,仍用全局 LB_REQUEST_TIMEOUT_MS / LB_MAX_ATTEMPTS
- 新增测试:记录 setTimeout 收到的延迟来断言 /reconcile 走 320000 ms,并用 503 响应
  断言它只尝试 1 个 origin;同时断言 /webhook/tg 仍用 5000 ms 且仍故障转移到第二
  实例;并断言 env 覆盖生效而 maxAttempts 恒为 1
- worker README 补 LB_RECONCILE_TIMEOUT_MS 说明与 /reconcile 例外
- deployment.md §6.3.1 删掉「请把 LB_REQUEST_TIMEOUT_MS 调到大于锁租期」的旧 workaround
  建议(现已由 per-route 覆盖解决),§10 worker 故障转移条目补例外,secret 清单补新变量
- 顺手清掉 health.js 注释里已退役的 GATE-READY-DEPS,改为 ARCH-READY-BASELINE

验证:cloudflare-worker node --test 29/29 通过(原 28 + 新增 1);
web config.test.mjs 6/6 通过。无 src/ 改动,Rust 门禁不受影响。
2026-09-28 12:18:04 +08:00
anonsaber cc645020d9 docs: /ready 端到端就绪语义同步 + 删除 Redis 错误映射虚构断言
两件事一批提交(全部 docs-only,无代码改动):

① /ready 语义升级为端到端就绪(对应 commit c5bc7b8 的实际行为)
- ARCH-READY-BASELINE 从「配置完整性 + Redis 可达性」改为:配置完整性
  + Redis 可达 + JMAP session 探针 + Telegram getMe 探针,四者全过返 200
  与就绪报告,任一失败返 503 + 标准错误 envelope + Retry-After: 30
- 探针细节:各 PROBE_TIMEOUT 3000ms、tokio::join! 并行、最坏约 3s
  (先前文档写「串行 / 最坏 6s」是错的,已全量修正 10 处,含 AGENTS.md /
  design.md / deployment.md / roadmap.md / reference.md / README 中英)
- LB 探针超时下限从「> 6s」改为「> 3s(建议 >= 10s)」
- JMAP 探针实际行为:取 JMAP_SESSION_URL 的 origin 后 GET
  {origin}/.well-known/jmap 并带配置的 Basic 认证(不是打裸 session URL);
  原因是裸 URL 不带认证会永远 not-ready,进而让 ingress 停止路由
- deployment.md 新增 /ready 出站 egress 硬依赖说明:egress 不通则长期 503,
  而 reqwest 以 default-features=false 编译不解析 HTTPS_PROXY
- reference.md Retry-After 规则改准:error_response 仅在 retry=true 时设置;
  error_response_with_id 无条件设置但仅用于 push register/disable 的
  push_state_unavailable / push_destroy_failed(恒 503);503 错误码表补上
  这两个此前漏掉的码
- GATE-READY-DEPS 门禁已闭合,从 AGENTS.md 与 roadmap.md 删除该 ID

② 删除「Redis 错误映射」这条虚构断言(代码缺口 4 -> 3)
- roadmap.md 与 design.md:634 的同一条断言删除;design.md 脚注「4 条」->「3 条」
- 根因:消费入口是 HTTP handler worker(notify.rs),不是后台循环
  —— 全仓 src/ 零 select!、无信号处理、无常驻 worker 进程;read_batch 与
  retry_or_dlq 的 Err 均经 ? 上抛,调用方一律返 503 + retryable=true。
  原先描述的「循环不因单次失败退出」这个前提本身不成立
- retired.md 新增一条虚构断言记录,完整保留原始断言与推翻依据
- roadmap 验收待办同步:/ready 端到端探测转已完成,并注明两个探针是可复用
  纯函数、④ 远程 debug 应直接复用同一实现,不要另写一套

③ 顺手修正本轮代码移动导致的失效行号锚
- retired.md:refresh_business_config 628->704;lock:push-register 810-819->887-890;
  register_push 668->873;notify::push_handler 改引真实函数名 jmap_push /
  worker / reconcile(原行号 250/97/136 全错,且 push_handler 非真实函数名);
  worker safelist fail-closed index.js:69-82 -> :77-92
- reference.md:router 1238-1265 -> 1250-1277;/worker 314 -> 326;
  路由表补上此前漏掉的 /、/assets/config.js、/assets/styles.css

基线:三处「验证基线」(roadmap.md:5、retired.md:7、reference.md:6)由
ed93358 更新为 c5bc7b8。

校验:8 个 md 代码块偶数、无行尾空格、无 CR;5 个文件全部表格列数一致
(剥掉 code span 后再计数);相对链接与锚点全部可达。
Rust 门禁不受影响(无 src/ 改动),基线仍为 45 passed / 0 failed / 1 ignored。
2026-09-28 12:08:33 +08:00
anonsaber 24cfbb45b0 docs: 重构文档体系 — README 瘦身中英对等 + 新增 reference.md 权威事实表
- README.md / README.zh-CN.md 瘦身至 ~100 行,五节 1:1 对等(是什么/5分钟/配置入口/安全边界/去哪读更多)
- 新增 docs/reference.md:Redis 键+TTL+写者+读者、错误 envelope+Retry-After、后端路由与网关白名单矩阵、env 三层等单一权威表(顶部 verified against ed93358)
- 新增 docs/roadmap.md 取代 docs/todo.md(只放缺口/阻塞/阶段目标/待决策)
- docs/design.md 保留架构语义,可查表改引 reference.md;修正 /search 未实现、XAUTOCLAIM 阈值矛盾、teloxide 幽灵引用等 9 处标注
- docs/deployment.md §8.1 重写,删除依赖不存在子命令/curl 的必然失败 healthcheck 示例
- AGENTS.md §6 登记 reference.md/roadmap.md + 冲突仲裁「以 reference.md 为准」+ 中英同轮同步/公共 API 变更规则
2026-09-27 18:55:38 +08:00
anonsaber ed93358e29 feat(notify): unify /ready not-ready 503 into the error envelope
- GET /ready: ready -> 200 + diagnostic report (unchanged success body);
  not ready -> 503 + {"error":"service_unavailable","request_id":id}
  + Retry-After: 30, consistent with the other public entry points
- drop the legacy {"status":"not_ready"} diagnostic block from the 503 body
  (backward compatibility not required)
- HTTP 200/503 semantics preserved, so Uptime Kuma HTTP(s) monitors
  (status-code based) keep working
- sync docs: README.md, README.zh-CN.md, docs/design.md, docs/deployment.md,
  AGENTS.md, docs/todo.md
2026-09-27 13:11:29 +08:00
anonsaber a8fad19daa docs: default README to English, reconcile docs, drop HANDOFF
- README.md is now English; add README.zh-CN.md with cross-links; both versions
  cover the same 40 sections and the same key facts
- correct stale docs/design.md 10.5.1 and docs/todo.md to the current code
  (XAUTOCLAIM threshold, malformed-entry ACK, error envelope now done)
- replace the temporary HANDOFF.md with docs/todo.md (unfinished work + blockers)
- adjust docs/deployment.md and AGENTS.md accordingly
2026-09-27 12:56:04 +08:00
anonsaber 956ef6a1d3 feat(config): add global Redis-backed enable switch 2026-09-25 20:11:35 +08:00
anonsaber a5710331fa docs(hoststack): add native Rust deployment config 2026-09-25 18:51:36 +08:00
anonsaber a57cb4f75d fix(redis): enable TLS for Upstash connections 2026-09-25 17:45:24 +08:00
anonsaber c75858fda0 refactor: rename project to MessageWeave 2026-09-25 10:29:18 +08:00
anonsaber 9064fc5f1d fix: hide admin authorization in setup mode 2026-09-25 10:05:47 +08:00
anonsaber e5ec3aef4c feat: provide configuration setup mode 2026-09-25 09:30:45 +08:00
anonsaber dceecaf2f4 feat: initial MessageWeave release 2026-09-25 09:14:04 +08:00