Repository navigation
feat: 应用内 BYOK 自然语言任务编辑(NLP edit) - #6
Merged
Lexiang-Xiong merged 39 commits intoJun 21, 2026
Merged
Lexiang-Xiong merged 39 commits into
Lexiang-Xiong merged 39 commits into
Conversation
Op schema (add/update/delete, enums locked, urgency excluded as derived) + planOps validation/diff/cascade guardrails. 30 tests pass, 3 todos for known-gaps (tree tempId, diff parent name, re-parent cycle). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
rel.split('/') failed on backslash paths from relative(); use split(/[\/]/). Also register apply-core/schema capability notes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Runs real planOps over fixtures (esbuild-transpiled, no key) -> layered HTML (form/raw/protocol) doubling as evidence + architecture boundary doc. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…d + show parent name in diff add_task gains tempId; a later op's parentId may reference an existing id OR an earlier tempId (forward-only), so 'new project + 3 subtasks' works in one batch. AddedPreview.parentLabel surfaces the parent name (existing title or 新建:X) so silent mis-parenting is visible. New DUPLICATE_TEMP_ID guard. 34 tests pass. App wiring (addTask returning real id) deferred to Phase 3. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…d delivery report Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…9 still open Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
update_task that sets parentId to the task itself or one of its descendants now returns a typed CYCLE error instead of silently creating a loop. Adds a test for the INVALID_OP defensive branch. 38 nlp-edit / 152 full-suite tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…rt, ledger Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a dedicated 'test' job (ubuntu, node 20, npm ci, npm test=vitest run) and broadens on: to push/PR on main + feat/** + fix/**. The three Tauri build jobs now 'needs: test' and are gated to v* tags via 'if: startsWith(github.ref, refs/tags/v)' so release behavior is unchanged — only a test gate is added. Closes TP5 (CI had no test step). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…haustiveness guard Upstream v2.2.0 widened TaskPriority from 3 to 5 levels (critical/heavy/high/medium/low). PRIORITY_VALUES/DEADLINE_TYPE_VALUES now use 'as const satisfies' plus an Exclude-based exhaustiveness assertion, so any future type member missing from these arrays fails tsc instead of silently dropping a level from the LLM function schema (Episode#3 drift). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…TP10 (5-level priority) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…anOps planOps gains invalidPolicy 'reject'|'skip'. reject = Phase-1 fail-fast (default, 160 locked tests intact). skip = per-op invalids recorded in new `skipped` array (shown in preview, never silent); valid ops still planned; tempId cascade naturally drops dependents. Adds op-shape validation (required fields + priority/deadlineType enum membership) -> MALFORMED_OP, for real-LLM output robustness. Batch errors (op-limit/empty) stay hard-stops in both modes. User-ratified: bad-op = partial-apply + preview gate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…mock gate
createProvider({fetchFn,storage,now,resolveEndpoint}) reads localStorage['byok_v1'] {base,key,model}, builds /chat/completions with tools:[emit_task_edits] + forced tool_choice + snapshot-summary context that steers tempId new-tree building (Episode#2 anti-mis-attach), parses tool_calls -> EditOp[]. Typed errors NOT_CONFIGURED/BAD_CONFIG/NETWORK/HTTP_ERROR/NO_TOOL_CALL/BAD_TOOL_ARGS. Injectable fetch (boundary rule); key only ever in the Authorization header, never logged/in errors/committed. 16 mock-gate tests incl. key-leak + full parse->planOps chain.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e-step undo) taskSlice.applyNlpActions(actions): one saveSnapshot + single setState (single-step undo, not per-op). Generates real ids for adds and resolves batch-local tempId parent refs to those real ids -> TP7 landing (children attach to the just-created real parent, not a literal tempId or a mis-attached existing task). Re-parent via update recomputes order to new-sibling tail; delete cascades whole subtree; recomputes taskComputedTimes. Returns tempId->realId map + createdIds. 6 store tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Multi-lens review (boundary/keyleak/contract/tests/spec) findings fixed: - KEY SAFETY: redact config.key from all error-message sinks (HTTP_ERROR body echo, NO_TOOL_CALL content, NETWORK) — a gateway reflecting the Authorization header in its 4xx body could otherwise leak the key; Authorization header now written LAST so a resolveEndpoint hook can't clobber it. Added adversarial no-leak tests (echoed-auth body, body-excludes-key, NETWORK redacted, clobber-resisted). - GATEWAY PORTABILITY: accept tool_call.arguments as object OR JSON string (Ollama/vLLM/LiteLLM hand back objects); aggregate ops across ALL emit_task_edits calls (no silent op loss on split); no matching tool -> NO_TOOL_CALL with the actual tool names instead of blindly parsing call[0]; non-JSON 200 -> new BAD_RESPONSE code (vs BAD_TOOL_ARGS). - TP8 completeness: UpdatedPreview now carries parentLabel for re-parent so a re-parent mis-attach is caught by the same parent-name preview defense as add. - Prompt: empty-zones branch tells the model not to emit add_task; summarizeSnapshot capped at 300 tasks with a truncation marker. - +18 tests (82 nlp-edit total). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e 3)
Prop-driven NlpEditDialog (matches repo convention): textarea -> Generate -> provider -> planOps('skip') -> diff preview -> Apply. Preview shows parent task NAME for both add and re-parent (TP8 last-line-of-defense vs Episode#2 silent mis-attach), lists skipped ops with reasons (partial-apply), and forces an explicit confirm checkbox when hasDeletes. Wired into ZoneManager header (Wand2 button) with tasks + onNlpApply=applyNlpActions threaded from App. runtime.ts adapts the pure provider to the browser: dev routes through a new vite /__byok proxy (server-side forward to the user's base_url, bypassing CORS; never logs Authorization; apply:'serve' so it's dev-only). i18n nlp.* keys (zh/en). Key still only from localStorage byok_v1. 4 dialog component tests + ZoneManager props updated. 214 tests green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…-skips without key) Drives the real BYOK gateway with '下午要干三件事,其中第二件下面有三个小点' against a snapshot seeded with a decoy existing task. Asserts no new subtask is silently mis-attached to the decoy and that a batch-new tempId parent is used (Episode#2 anti-mis-attach, against the REAL model). Reads key from env (BYOK_KEY/BYOK_BASE/BYOK_MODEL), node direct (no CORS/proxy). describe.skipIf(!BYOK_KEY) -> never runs in CI: evidence, not gate (byok-plan-v2 §7). Logs real ops + plan diff for human inspection. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…dence run, never committed) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…Phase 2-3 delivery report test-points.md: TP7 wiring covered (applyNlpActions), TP8 extended to update re-parent, +TP11 (key-never-leaks) +TP12 (gateway-variant robustness); TP1/TP3-evidence marked pending-run (tools ready, needs user's key). episode-log.md: Episode Lexiang-Xiong#4 (branch-drift grounding, 3 ratified decisions, 5-lens adversarial review w/ reproduced key-leak). phase2-3-nlp-edit.html: Change Verdict — 214/215 gate green, review summary, boundary impact (localStorage byok_v1 pivot + dev CORS proxy + key-leak defenses), 3 screenshot slots pending real run. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
apply-core: build update 'changes' via Object.entries filter instead of destructuring op/id into _-prefixed unused vars (pre-existing Phase-1 pattern the repo's eslint config flags). NlpEditDialog: drop now-unused titleById param from changeSummary. Behavior identical; 214 tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…t, test casts, schema.test narrowing tsc -b (the real build, stricter than tsc --noEmit) was failing on 6 type errors: 4 from this session (provider.ts resolveEndpoint default lost optional headers; 3 provider.test mock.calls[0] tuple casts) + 2 PRE-EXISTING in schema.test.ts (Phase-1: .find over oneOf union can't narrow to add_task at compile time; runtime fine). Fixed: annotate resolveEndpoint with NonNullable<...resolveEndpoint>; cast mock.calls[0] via unknown; cast add.properties for the schema-shape assertions. Production build now succeeds; 214 tests still green. (Lesson: run npm run build, not just tsc --noEmit.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ed against the live gateway Ran nlp-smoke against the user's real Xiaomi MiMo Token Plan key. Endpoint probe (真测): tp- key 401s on SGP (token-plan keys are region/cluster-locked) -> works on CN cluster https://token-plan-cn.xiaomimimo.com/v1, model mimo-v2.5-pro. Concrete hard case: MiMo built a new tree via tempId — the three sub-points attached to the NEW '写周报' (parentLabel='新建:写周报'), NOT silently mis-attached to the decoy existing '项目A'. Episode#2 failure mode defended against the real model. Abstract case (no task names): model asked for clarification instead of hallucinating/mis-attaching (good safety) -> confirms MiMo doesn't hard-honor forced tool_choice (contract-lens prediction); dialog NO_TOOL_CALL path surfaces it. Smoke prompt updated to the concrete case. Adds phase4-real-llm-evidence.md; updates delivery report + ledger TP3 (ops evidence covered, UI screenshots still pending user browser) + Episode Lexiang-Xiong#4. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds writeByokConfig() + an in-dialog config form (base/key/model/provider) shown on the not-configured state and via a gear button. Saves to localStorage['byok_v1'] (injectable saveConfig prop for tests), plaintext-risk note, then re-reads config and proceeds to input. Fixes the real shippability gap: previously byok_v1 could only be set via DevTools, so a published build was unusable by end users. Bug caught + fixed: on first-time config the form shows via !config.ok (configMode already false), so setConfigMode(false) alone didn't re-render — added an explicit re-render tick so the saved config is picked up. i18n nlp.cfg* keys (zh/en). +3 tests (save flow, validation, writeByokConfig round-trip). 216 tests green; tsc -b + build + eslint clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…pable config path) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…2E (closes TP1/TP2) scripts/e2e-shots.mjs drives the dev app headlessly (playwright-core + cached chromium) at localhost:8088 through the /__byok proxy to the SAME real MiMo V2.5 (China token-plan) gateway: creates a zone, fills the in-app BYOK config form, types the hard case, generates, previews, applies — capturing 4 states into docs/delivery/ (config form, input, diff-preview, landed tree). Evidence: preview shows '收集数据/写初稿/改定稿 ↳ 挂到「新建:写周报」下' (TP8 parent-name defense holding against the real model in the real UI), landed tree has 写周报 with 3 children + toast '已应用 AI 编辑(6 项)'. E2E also surfaced: empty store -> model correctly refuses '没有分区' (empty-zones prompt guard works on the live model). Embeds shots into phase1-nlp-core.html + phase2-3-nlp-edit.html slots; closes ledger TP1/TP2/TP3 (no known-gap); Episode Lexiang-Xiong#4 updated. Adds playwright-core devDep. Key stays in gitignored .byok.local.json; shot0's key field is password-masked. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…er op kind) + screenshots scripts/e2e-scenarios.mjs seeds exact fixtures via a dev-only window.__appStore (main.tsx, import.meta.env.DEV-guarded) and drives the dialog through real MiMo V2.5 (CN) per scenario, screenshotting each diff-preview into docs/delivery/scenarios/. Covers: add flat / new-tree(tempId), add-subtask-to-existing (shows existing parent name), update priority/completed, re-parent (parentLabel on update), delete+cascade (forced confirm, Apply disabled until checked), mixed add+update+delete. 12/12 produced correct ops; README.md + _results.json index the evidence. Key stays in gitignored .byok.local.json. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…enarios Single-page side-by-side view: each scenario shows the natural-language input + initial state + model output on the left, and the real diff-preview screenshot on the right. Open docs/delivery/scenarios/gallery.html. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e64) for sharing scripts/gen-demo-html.mjs assembles docs/delivery/byok-nlp-edit-demo.html — one portable HTML (3.2MB, 16 images embedded, zero external refs): section 1 = end-to-end 3-state hard case, section 2 = 12-scenario input↔interface capability matrix. Openable offline, sendable as a single file. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ors) The 'test' job only ran 'npm test' (vitest); the Tauri build is gated on v* tags, so type errors slipped through on push (e.g. the tsc -b breakage fixed in b48e959 — vitest was green but the build was red). Adds 'npm run build' to the test job so every push/PR typechecks (tsc -b) and bundles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds ByokSettingsSection (base/key/model/provider fields + save + clear + plaintext-risk note + configured/not-configured status), wired into SettingsPanel after the Language section. Reuses read/write/clearByokConfig (default localStorage). Folds in the 'clear config' control (TODO 2's encryption was dropped per user — plaintext-persist accepted for personal use). i18n nlp.settings*/clear/cleared/statusOk/statusNone (zh/en). +4 tests (section save/prefill/clear + clearByokConfig round-trip). tsc -b + build green; new files eslint-clean (SettingsPanel's set-state-in-effect warnings are pre-existing). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Release of the BYOK NLP-edit feature on the fork. Feature code only: src/lib/nlp-edit (schema/apply-core/provider/runtime + tests), NlpEditDialog + ByokSettingsSection, store applyNlpActions (single-step undo, tempId->real-id), /__byok dev CORS proxy, i18n, CI build/type gate. Versions synced to 2.3.0 (tauri.conf/package.json/Cargo.toml). Personal harness docs, delivery reports, the self-contained demo HTML, screenshots, and the Playwright e2e/evidence scripts are kept LOCAL (gitignored) — not part of the released code; the demo stays on the feat/byok-nlp-edit branch + GitHub Pages for sharing. Removed the dev-only window.__appStore hook and playwright-core devDep (were only for local e2e). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ning) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
应用内 BYOK 自然语言编辑任务
加了一个对话框:用户填自己的 OpenAI 兼容 key(BYOK),用一句自然语言增/删/改任务 → 先 diff 预览(显示挂到哪个父任务下 / 级联删除数 / 删除强制二次确认)→ 确认后落地(单步撤销)。
实现
src/lib/nlp-edit/:schema(op 的 JSON Schema = function-calling parameters,5 级 priority + 编译期完整性断言)、apply-core(纯逻辑校验/diff/级联/环守护/部分应用)、provider(OpenAI function-calling,可注入 fetch)、runtime(浏览器经/__byokdev 代理绕 CORS)。NlpEditDialog+ByokSettingsSection:对话框 + 设置页配置入口(填/改/清 key)。applyNlpActions:一次saveSnapshot+ 批量setState(单步撤销),批内 tempId→真实 id 落地建新树。tsc -b + vite build门。版本升到 v2.3.0。安全
localStorage、只发用户自己填的网关、不入仓 / 不进日志 / 错误信息脱敏;LLM 输出仅限 schema 约束的 op + 落地前人工 diff 确认(HIL)。测试
tsc -b/vite build干净。真机(MiMo V2.5)12 例能力矩阵 + 三态演示:https://lelelelelelelelelelelelele.github.io/Focus-Flow/delivery/byok-nlp-edit-demo.html说明
本 PR 把版本升到 2.3.0。另分支夹带了少量非 BYOK 的 fork 改动(global-view 分组、urgency-utils 等历史分叉);若只想要 BYOK 部分,我可再拆干净分支。
🤖 Generated with Claude Code