Commit graph

89 commits

Author SHA1 Message Date
fancivez
be8ad72ba2 test: add comprehensive parseSseBuffer and deltaExtractor tests
Cover SSE parsing edge cases: single/multiple events, incomplete buffers,
CRLF line endings, [DONE] sentinel, multi-line data fields, malformed JSON
skipping, comment/event lines, data: without trailing space, empty buffer.
Test both OpenAI and Anthropic delta extractors with various input shapes.

Change-Id: I108352e07233490d23b86ed31b855692c360d4d1
2026-04-27 14:11:36 +08:00
fancivez
4c4468dd85 fix: add logging to silent catch blocks in CLI, job manager, and main
Replace silent error swallowing with console.warn in:
- GenerationJobManager cancel handler errors
- CLI process kill failures (timeout and cancellation)
- CLI stdin close failures
Add descriptive comments to intentionally silent scroll-related catches.

Change-Id: I2ec8fda6ca92186ed2d4fc1560efffd0677f3bcd
2026-04-27 14:11:36 +08:00
fancivez
ba6e44194a refactor: extract batch folder prompt dialog to src/batch.ts
Move the inline Modal dialog for batch folder selection into a reusable
promptForBatchFolder function. Removes Modal import from main.ts.
main.ts now 775 lines.

Change-Id: I7a5c62b7df95635dcbe0ac814007838ff83eded4
2026-04-27 14:11:36 +08:00
fancivez
50a3c4bec3 refactor: extract resolveCardAnchors and confirmRegenerateEditedCards from main.ts
Move resolveCardAnchors to src/cards.ts and confirmRegenerateEditedCards
to src/modal.ts to reduce main.ts from 835 to 796 lines (under 800 target).

Change-Id: If38ed4e45c61658b7cc52a6283f8e0e24458761e
2026-04-27 14:11:36 +08:00
fancivez
b3d774f4df test: add provider-parsers edge case coverage
Test all parser functions with empty responses, missing fields, null inputs,
legacy format fallbacks, multi-block concatenation, and tool-use rejection
for wrong tool names and missing content arrays.

Change-Id: Ie3c15aa636a6b421ca6bf4315313368c249f2782
2026-04-27 14:11:36 +08:00
fancivez
f7c4f42a5a test: add comprehensive CacheManager unit test coverage
Cover previously untested methods: get(), move() (success/failure/edge
cases), readFile() with corrupt JSON and missing entries, pruneIfNeeded(),
replaceCards() for missing entries, and scheduleSave()+flush() behavior.

Change-Id: Iee71e574d37925c2111eb70a292d5f59a80dc3c5
2026-04-27 14:11:36 +08:00
wujunchen
185f4fd146 chore: bump version to 1.0.5
Change-Id: Iaa1c3718557ab936d10ebcc659c245a9ebb8f801
2026-04-27 13:02:11 +08:00
wujunchen
3082e4a7bb chore: rebuild main.js after engineering quality improvements
Change-Id: Id0249bc0c38a237ca085d59dae6eac6a56cb5548
2026-04-27 12:58:40 +08:00
wujunchen
538d7bcedd test: add structured output fallback and non-retryable error tests
Cover the two key paths in requestJsonBodyWithStructuredFallback:
1. 400 with response_format mention → retry without structured output
2. 500 server error → no retry, error propagated

Change-Id: If8d0fc484e49238699444131cbadcf1b18bf992f
2026-04-27 12:44:42 +08:00
wujunchen
67a9ccdafb test: add applyApiProviderPreset model swap coverage
Cover the key scenarios for provider switching: model swapped when
matching previous preset, custom model preserved across switches,
empty model triggers swap, and input immutability verified.

Change-Id: I467604d51e8c11e990e54621347094cf914cb6b7
2026-04-27 12:43:29 +08:00
wujunchen
bc1de37868 fix: remove unsafe fallback cast in CardEditModal constructor
The constructor always receives a validated ResolvedCard from the call
site (which guards with !this.sections[index]). The fallback to an
empty object cast as ResolvedCard was dead code that hid type safety.

Change-Id: I35c9731d9079b9aeea5eb0fda7eda46a740bc964
2026-04-27 12:41:13 +08:00
wujunchen
f635823499 fix: add error handling to fire-and-forget async patterns
Replace void-prefixed async calls with .catch() error logging in:
- onunload flush operations (settings + cache)
- file-open, rename, and delete event handlers
- settings-tab cache commit handler

Also await syncViewToFile in the open-view command where it was
unnecessarily fire-and-forget inside an already-async callback.

Change-Id: Ied1e88035b77a92a59c50ab6caef539a254c7787
2026-04-27 12:40:29 +08:00
wujunchen
f2e197453c fix: prevent modal confirmation promise from resolving twice
The regenerate confirmation modal's onClose callback fired after button
click handlers, calling resolve() a second time. While Promise.resolve
is idempotent, this was confusing. Added explicit settlement tracking
so the promise resolves exactly once regardless of how the modal closes.

Change-Id: Ief4cbb78f15fe220a20adaf8343d744ffa8c1653
2026-04-27 12:34:33 +08:00
wujunchen
b02d0f4f30 test: add cache pruning interleaved with put test
Verify that when a new entry is added via put() and the cache exceeds
maxCacheEntries, the oldest entry (by timestamp) is pruned and the
pruned state is correctly persisted to disk.

Change-Id: Ia937800a97d7591877e1d2d1fe808b86858735e1
2026-04-27 12:30:56 +08:00
wujunchen
cfdd985f78 test: add batch state isolation and cancellation tests
Verify that two concurrent BatchRunState objects don't interfere with
each other (cancelling one doesn't affect the other), and that stats
accumulate correctly when processing is stopped mid-iteration.

Change-Id: Id32b27307beafe49594cfde6fa818b2f22b87c66
2026-04-27 12:29:42 +08:00
wujunchen
593817734b test: add streaming cancellation edge case tests
Cover pre-aborted signal (aborted before fetch starts) and mid-read
abort (signal aborted while reading response body). Both verify that
abort listeners are properly cleaned up after rejection.

Change-Id: I0760f6ed051de1504e9b7aeead01a10cfd12476e
2026-04-27 12:28:36 +08:00
wujunchen
1d3aa81678 fix: close abort signal race window in streaming fetch
The previous code checked signal.aborted before adding the listener,
creating a timing window where the signal could abort between the check
and addEventListener. Now the listener is always registered first, then
signal.aborted is checked after, ensuring no abort event is missed.

Change-Id: I1abc3ad21e5bb93559d66922edf7c325a977bc65
2026-04-27 12:22:43 +08:00
wujunchen
09f39dde8d fix: make normalizeSettings return a new object instead of mutating input
normalizeSettings previously modified its input parameter in-place.
While callers already created copies before calling it, the function
signature was misleading. Now it creates a shallow copy internally and
operates on that, with a Readonly<PluginSettings> parameter type to
signal intent. Added a test verifying the original object is unchanged.

Change-Id: I7600ac37930bbcebb02aa7c84d8988cb7aa71196
2026-04-27 12:20:56 +08:00
wujunchen
816b015e56 chore: bump version to 1.0.4
Change-Id: Id5040ec82babe747976121e07b7eabe1f6d82406
2026-04-27 12:11:29 +08:00
wujunchen
ff1116d7f4 fix: pass --max-tokens to Claude Code CLI to prevent output truncation
The CLI path was not forwarding settings.apiMaxTokens, causing the
model to use its own default which is too small for long documents
with many CJK cards. This was the root cause of repeated "LLM 返回
非 JSON" errors — the JSON was being cut off mid-card.

Change-Id: Ia738418e2e6cf7f919752cb3128a82768d95cedf
2026-04-27 11:58:04 +08:00
wujunchen
abce923f14 fix: salvage truncated LLM JSON and make errors copyable
- Add repairTruncatedCardsJson to recover complete cards when output
  is cut off mid-card (e.g. token limit reached)
- Log raw LLM response to console on parse failure for debugging
- Make error panel text selectable and add "copy error" button

Change-Id: I4e76121138888234d42f84f3695cbbfd6beba886
2026-04-27 11:56:40 +08:00
wujunchen
5f12113fcd chore: improve engineering quality and hardening
- Fix CI to run all 4 test files (was missing direct-modules.test.js)
- Remove unused ESLint dependencies (eslint, @typescript-eslint/*, eslint-plugin-obsidianmd)
- Enable noImplicitReturns in tsconfig.json for stricter type safety
- Make applyApiProviderPreset return new object instead of mutating input
- Add per-file error handling in batch processing loop with error count in summary
- Narrow all catch clause types to unknown with proper instanceof narrowing

Change-Id: I76975dbd5ebdb5645d18c5858c8a52fd6da3405e
2026-04-27 11:15:35 +08:00
wujunchen
b1e35fc8fc chore: bump version to 1.0.3
Change-Id: I58a40e2a7037c83bed96f30af077c096314160f2
2026-04-27 10:46:01 +08:00
wujunchen
d75107d84c chore: update versions.json for 1.0.2 release
Change-Id: Icc8e905a4b117a5707d6e6b48729a8d6dc60a619
2026-04-27 10:45:27 +08:00
wujunchen
6e83d216c2 feat: add generate button to empty state panel
When a note has no cached parallel notes, the empty state now shows a
clickable "Generate" button so users can trigger generation directly
without going through the command palette. Closes #2.

Change-Id: I879897168ef77c44e0ab570e9c094fa9af9f66d4
2026-04-27 10:24:05 +08:00
wujunchen
6aba90bfd3 fix: remove unnecessary async from catch handler
The catch callback no longer contains any await expressions
after the previous refactor removed await on sync view methods.

Change-Id: I054c50fe209aba0e925bd1838896228bce686841
2026-04-26 21:12:16 +08:00
wujunchen
da535cb064 fix: address remaining Obsidian review bot required issues
- Remove unnecessary TFile cast (instanceof already narrows)
- Remove await on non-Promise view methods (loadFor, renderLoading, renderError)
- Remove async from CacheManager.touch() (no await expression)
- Replace this-aliasing with captured locals in batch modal
- Use CSS class instead of inline style for modal input width
- Fix sentence case in settings UI text

Change-Id: I2a222c6429eb7e4d69761cca8369956fef510054
2026-04-26 19:34:45 +08:00
wujunchen
de08ec778a chore: add eslint tooling dependencies
Change-Id: I3f855a85e1ed9ef45a0f77210d5a68081a967d59
2026-04-26 19:25:51 +08:00
wujunchen
3d8d72b66e refactor: split settings tab renderers
Change-Id: I456ddd16868150b2e22f5592c97d579a3540e48d
2026-04-26 19:17:12 +08:00
wujunchen
486060bddf test: cover cache manager with fake adapter
Change-Id: I83f6b71a46af31f783522faa53bffbfc6c4bc54d
2026-04-26 18:31:17 +08:00
wujunchen
557908ca44 fix: clean up streaming abort listener
Change-Id: I9fa8ace7bc0fa723466ef851f7ec2960c6638eba
2026-04-26 18:29:48 +08:00
wujunchen
bc51acd00e fix: parse multiline sse events
Change-Id: I9c013dbe6840a0892836eb5d71206c6fcde5ec78
2026-04-26 18:27:28 +08:00
wujunchen
846e32301a test: import pure modules directly
Change-Id: Ia029de2ac4c3cb3ddb7ea638c868d6347af5c67e
2026-04-26 18:25:50 +08:00
wujunchen
2364e62911 chore: check build artifact consistency
Change-Id: I485ee9ef2eaf584a1c1fcf890ee85fb82a34a8fb
2026-04-26 18:22:11 +08:00
wujunchen
70f9a39cd7 refactor: extract provider response parsers
Change-Id: I6884999f34594faec349378deb59e68972e07355
2026-04-26 18:20:49 +08:00
wujunchen
6dd7ef15a4 test: cover cli edge cases
Change-Id: Ia6114ab7ba24e32f7f86ff76710a596b0c24682c
2026-04-26 18:16:38 +08:00
wujunchen
174fa7295d feat: expose streaming timeout setting
Change-Id: Ide69c0f0fe208a557024f9f77d83c9d1215391cf
2026-04-26 18:14:43 +08:00
wujunchen
9098de6884 feat: validate batch folder input
Change-Id: I137fa046e77781e063ee782af4321b7277d64d51
2026-04-26 18:12:38 +08:00
wujunchen
d8dc82362b feat: support cancellable batch generation
Change-Id: I89302f58995e4e15fbf77c20c87a94832e572d20
2026-04-26 18:10:17 +08:00
wujunchen
ebc882c2f1 refactor: encapsulate cache rename
Change-Id: I89ee56c071c8e5404f8eb9ea744172957811d714
2026-04-26 18:05:38 +08:00
wujunchen
fe05ed1a2d test: cover generation orchestration
Change-Id: Iff416f01c0f09111e67e1ad67957b85fdb19623a
2026-04-26 17:59:35 +08:00
wujunchen
2d4bef9539 refactor: extract batch generation helpers
Change-Id: I16ad657b783b65cc5b3e36a6ea163cc19740b651
2026-04-26 17:54:35 +08:00
wujunchen
b199f56a35 refactor: extract generation orchestration
Change-Id: I17002ff04b0d79d8ec27da3dbb4b08df9bf3659e
2026-04-26 17:45:43 +08:00
wujunchen
9ed36570b5 refactor: restore strict lint hygiene
Change-Id: I26917328ec55e529242dfd8e4c42af0b3fcd58b7
2026-04-26 17:41:28 +08:00
wujunchen
89e1ab9d5c chore: bump version to 1.0.2
Change-Id: I40e3893b061e73620e9e7d8f818684d3620c1d9f
2026-04-26 16:01:39 +08:00
wujunchen
89d28d1113 fix: address all required issues from Obsidian plugin review bot
- Remove `parallel-reader-` prefix from command IDs (Obsidian auto-namespaces)
- Remove default hotkeys to avoid conflicts with user keybindings
- Replace `as TFile` casts with `instanceof TFile` checks
- Make onunload sync, remove detachLeavesOfType (preserves leaf positions)
- Use `vault.configDir` instead of hardcoded `.obsidian`
- Replace `window.confirm` with Obsidian Modal dialog
- Fix unhandled promises with `void` or `await`
- Remove unnecessary `async` from methods without `await`
- Use `new Setting().setHeading()` instead of raw HTML headings
- Fix promise-returning callbacks in event listeners
- Fix error type narrowing with `instanceof Error`
- Apply sentence case to UI text labels

Change-Id: I6e850d8a13b458d5cf1ad91227bf1772636b56b9
2026-04-26 15:57:16 +08:00
fancivez
e0acce7f6d
Merge pull request #1 from fancive/feat/engineering-improvements
refactor: engineering improvements batch
2026-04-26 15:43:18 +08:00
Claude
69af9938c6
build: update compiled main.js artifact
https://claude.ai/code/session_016QvEfqw6YZ3RjwBHrJ4w8S
2026-04-26 06:21:53 +00:00
Claude
02fc5678ae
feat: add folder-level batch summarization command
Register parallel-reader-batch-generate command. It prompts the user for a
folder path via a Modal, finds all .md files in that folder (non-recursive),
skips files whose cache is still valid, and runs runForFile() sequentially
on the rest, showing per-file progress notices. Add i18n keys for the new
UI strings in both zh and en.

https://claude.ai/code/session_016QvEfqw6YZ3RjwBHrJ4w8S
2026-04-26 06:18:58 +00:00
Claude
10d811f197
refactor: upgrade Biome lint rules
Promote noExplicitAny from warn to error and enable noNonNullAssertion
at warn level. Fix the two resulting errors in src/schema.ts by introducing
a JsonSchema interface to replace the any-typed local variables.

https://claude.ai/code/session_016QvEfqw6YZ3RjwBHrJ4w8S
2026-04-26 06:16:36 +00:00