Commit graph

143 commits

Author SHA1 Message Date
wujunchen
310c81a073 fix: add cancel action to batch prompt
Change-Id: Ic3922d55d776d369959eff4e5c811c5d3434db2b
2026-04-29 14:13:47 +08:00
wujunchen
57c1c0e124 docs: document e2e contract gate
Change-Id: I940bac18e567c55a7cd57e1ccf37203f871c6aec
2026-04-29 14:09:55 +08:00
wujunchen
970a7bc364 chore: add e2e contract gate
Change-Id: Idf5c36b17a5b816e354d07f1e28ff4011e54f32e
2026-04-29 14:08:38 +08:00
wujunchen
3bdd6d67c6 fix: localize batch prompt confirmation
Change-Id: I13b546785c5984a9d0cb5abaffa843f9ad7655d0
2026-04-29 13:58:10 +08:00
wujunchen
2bf4e86451 fix: confirm before overwriting exports
Change-Id: I922fca90e46a8982686a3449b00ed793e924097b
2026-04-29 13:56:36 +08:00
wujunchen
5304ed3a48 fix: localize remaining action labels
Change-Id: I4ac6db14c4aede9a106e8023effac3c99d3c037a
2026-04-29 13:54:53 +08:00
wujunchen
2d39a91aed test: split architecture guard tests
Change-Id: Ibde4ae79f202ae0e26658ab47bbcf5b52ef9effe
2026-04-29 13:53:19 +08:00
wujunchen
39ddd4289e fix: count batch generation failures
Change-Id: Ie6b29cb3efc22fe72250e9c63c1e82c71b24a356
2026-04-29 13:51:33 +08:00
fancivez
ceea8d6ff0 chore: bump version to 1.0.9
Change-Id: I5bd7ac74eb9101ffeeb99ef24518f68e91b9c101
2026-04-27 20:41:14 +08:00
fancivez
dae5175b6c fix: add void operator to all floating promises in callbacks
Satisfies @typescript-eslint/no-floating-promises for fire-and-forget
async calls (runForFile, copyToClipboard, scrollEditorToLine, etc.)

Change-Id: I758cc8e1ae49deacd7e8527abcda90c0e3d4fe1c
2026-04-27 20:39:14 +08:00
wujunchen
f8bf0f99ca chore: bump version to 1.0.8
Change-Id: I0eedef0d4ad19f84f189f8c95a4a1f69b6d09eb4
2026-04-27 20:27:52 +08:00
wujunchen
0801b644f6 fix: address CR findings — bump script, test runner, temp cleanup
- bump-version.mjs: reject duplicate versions (use --force to override),
  auto git-add manifest.json + versions.json for npm version hook
- run-tests.mjs: use execFileSync to handle paths with spaces
- test-setup.js: clean up esbuild temp directory on process exit

Change-Id: I44410b550d09487dd7f5e30a8f9385a2c500252a
2026-04-27 20:19:53 +08:00
wujunchen
199ab73188 refactor: split main.test.js into focused test files
Reduce main.test.js from 560 to 70 lines by keeping only architecture
guards and export smoke tests. Moved provider error tests, Anthropic
tool-use parsing, and cancellationNoticeKey tests to providers.test.js.
Settings, cache, and other tests were already covered in their
dedicated test files.

Change-Id: I8f0f3c576dec7fcf5a4c6e0c2b6071601940349d
2026-04-27 19:59:46 +08:00
wujunchen
f5f974fd74 build: remove __test barrel from production bundle
Tests now load src/test-exports.ts via esbuild buildSync instead of
importing __test from the production main.js. This removes ~60 internal
symbols and all test-only module code from the shipped plugin bundle.

Change-Id: I2caf5232f6894c7514215e1751f2e268b74d7dc4
2026-04-27 19:57:28 +08:00
wujunchen
0bf5ab12b1 lint: extend Biome coverage to tests/ and scripts/
Add tests/**/*.js and scripts/**/*.mjs to biome.json includes and
update npm lint scripts to cover these directories. Auto-fixed all
formatting issues in 26 files.

Change-Id: I8c2763cb9683616a8abc1484d91bf8af79bb590e
2026-04-27 19:53:35 +08:00
wujunchen
b26b241c7f refactor: centralize obsidian mock into tests/obsidian-mock.js
Extracts the duplicated Module._load obsidian stub from main.test.js,
generation-job-manager.test.js, and test-setup.js into a single shared
file. All three now require('./obsidian-mock') instead of defining
their own copy.

Change-Id: I8ac38f779299ac250963357eee9f7824e13c7d33
2026-04-27 19:52:34 +08:00
wujunchen
e10cbbbe9c build: add version bump script
npm run version <x.y.z> atomically updates manifest.json and
versions.json. Replaces the manual three-file version dance.

Change-Id: Ib894147f654b284d8f4c1df95bd8ff5da80d5dcc
2026-04-27 19:51:11 +08:00
wujunchen
e5f5af43ca ci: add tag-triggered release workflow
On tag push (e.g. 1.0.7), builds from source, runs typecheck + tests,
then creates a GitHub Release with main.js, main.js.map, manifest.json,
and styles.css attached. This replaces the need to commit main.js to
the repository.

Change-Id: I8ccbdddaa45267d2738cc43a4e7fccd1d35346ab
2026-04-27 19:50:17 +08:00
wujunchen
f6ce405249 build: remove main.js from git tracking
main.js is now a build artifact produced by esbuild, not tracked in
git. The release workflow (next commit) will build and attach it to
GitHub Releases. Also removes the check-build-artifacts script that
enforced main.js stay in sync.

Change-Id: I35f7dede09c5ac3c2d788c11248e2ed4931a95bc
2026-04-27 19:49:45 +08:00
wujunchen
098fee763c build: enable linked source maps for production builds
Generates main.js.map alongside main.js so error stack traces in the
Obsidian developer console point to original source locations.

Change-Id: I3f63196bfa421c2ac69aee371e4c294d42ee629c
2026-04-27 19:48:26 +08:00
wujunchen
f9e33d4c5d build: align tsconfig target and esbuild target to ES2022
Both were ES2020 while lib was already ES2022, creating a mismatch
that could allow using APIs esbuild wouldn't polyfill. Obsidian 1.4+
runs Electron 25+ which fully supports ES2022.

Change-Id: I732538280146c6a91cf52cc52ef124f6a364dc5e
2026-04-27 19:47:41 +08:00
wujunchen
552dd41109 chore: bump version to 1.0.7
Change-Id: Id06610a41ee7664e29f0b3f2894e2270b36649b7
2026-04-27 19:08:13 +08:00
wujunchen
df48dc2cc4 fix: remove unsupported --max-tokens flag from claude CLI args
The Claude Code CLI doesn't support --max-tokens. This caused the CLI
backend to always fail with exit code 1. Also adds args validation tests
for both claude and codex CLI backends.

Change-Id: I57c5cc672ed08de291e3941511ce68ba56e5b4ff
2026-04-27 19:07:53 +08:00
wujunchen
ea5f440ca5 chore: bump version to 1.0.6
Change-Id: Icc2aa02d42c7ffe32c1b6cc5ae8b2ea995460a3f
2026-04-27 17:21:07 +08:00
wujunchen
1fff3cb343 fix: address CR findings — test runner, CI dedup, error cause
- Create scripts/run-tests.mjs to auto-discover test files, replacing
  the 900-char inline test command in package.json (P3-1)
- Add test:only script for CI to avoid duplicate build+typecheck (P2-1)
- Preserve original SyntaxError as cause in responseJson (P2-3)

Change-Id: I51d0c8c51d3b0b648ed5ff4ea282bda070b0d457
2026-04-27 16:04:03 +08:00
wujunchen
986143b05b refactor: split settings-tab renderBackendSection into CLI/API methods
Extracts renderCliBackendSettings() and renderApiBackendSettings() from
the 144-line renderBackendSection(). The parent method is now a 5-line
dispatcher. CLI settings (14 lines) and API settings (128 lines) are
cleanly separated.

Change-Id: Ic866ba78d3b572f5f564760b248460584b0819c5
2026-04-27 15:45:25 +08:00
wujunchen
4b7b8cccfc refactor: create test-exports.ts barrel to clean up main.ts
Replaces the 64-line __test manual export block in main.ts with a
single import from src/test-exports.ts. Also removes 30+ imports that
were only needed for __test re-export. main.ts reduced from 788 to
693 lines.

Change-Id: I029f127faf053135d04dba17b8c39c8c39ca8540
2026-04-27 15:43:58 +08:00
wujunchen
60e9ad6bb2 refactor: extract provider HTTP helpers to provider-request.ts
Moves RequestUrlFunction type, endpointUrl, responseJson, requestJsonBody,
shouldRetryWithoutStructuredOutput, and requestJsonBodyWithStructuredFallback
to a dedicated provider-request.ts module (103 lines). providers.ts reduced
from 377 to 277 lines.

Change-Id: I013d6a0b9565770c00e48eb416541fcf08d1c5e8
2026-04-27 15:41:28 +08:00
wujunchen
ed93e25cc9 refactor: split view.ts render() into 5 focused helper methods
Decomposes the 76-line render() method into renderHeader(),
renderStaleBanner(), renderLoadingState(), renderErrorState(), and
renderCardList(). Each helper is under 22 lines. render() is now a
15-line orchestrator that delegates to the appropriate helper.

Change-Id: Iffcf31131fcf0bce882c1e9ee35aaf58d002b5fa
2026-04-27 15:39:12 +08:00
wujunchen
49c75a5a15 fix: update CI to use npm test instead of hardcoded test file list
The CI workflow still referenced the deleted modules.test.js and
direct-modules.test.js files. Now uses npm test which runs all 24
test files via the package.json script.

Change-Id: Iba3575459e56aa036f4002c76ecaa9c5f2e82278
2026-04-27 15:38:17 +08:00
wujunchen
05ac2b923f test: add batch.ts comprehensive tests including isFileInBatchFolder
Tests cover isFileInBatchFolder (root, subfolder, nested), edge cases
for normalizeBatchFolderInput (null, undefined, only slashes),
hasUnsafeBatchFolderSegments (null, single dot, dotfile), selectBatchFiles
with complex folder structures, and stats immutability verification.

Change-Id: If4964355db427347060ea3f902e8f6ef71ea2471
2026-04-27 15:31:37 +08:00
wujunchen
741012e535 test: add settings.ts edge case tests for utility functions
Tests cover stableStringify (key sorting, nested, types), isApiBackend,
getApiFormat/getApiAuthType fallback behavior, normalizeMaxCacheEntries,
hashContent consistency, normalizeSettings validation (invalid uiLanguage,
apiProvider, apiFormat, apiAuthType, non-string customSystemPrompt),
and pruneCacheEntries with null/empty/non-object inputs.

Change-Id: I96269c69871e3c17ccb06a71ac9cfb9733a382f6
2026-04-27 15:30:33 +08:00
wujunchen
6f80d0de03 test: add generation.ts cancellationNoticeKey edge case tests
Tests cover all backend types (api, anthropic-api, claude-code, codex),
all generation phases (queued, reading, cache-check, generating, saving),
and null settings/job edge cases.

Change-Id: I722fb0cf1129c7cf45dfc5bf2544577652df843d
2026-04-27 15:29:29 +08:00
wujunchen
0f8625874e test: add comprehensive markdown.ts unit tests
Tests cover cardToMarkdown, cardToPlain, and cardsToMarkdown with
edge cases: empty/missing fields, anchor whitespace normalization,
null cards array, empty title fallback, plain text bullet formatting.

Change-Id: I1972705d385f0393c9fd1be7f80d6513f5328d06
2026-04-27 15:28:34 +08:00
wujunchen
1e2ccc0840 test: add comprehensive prompt.ts unit tests
Tests cover promptLanguageInstruction, promptSchemaExample,
renderPromptTemplate, and buildPrompts edge cases including
auto language, truncation markers, custom prompt variable
substitution, card count normalization, and fallback behavior.

Change-Id: I75d5b354df15456ddbd08d9d21846f74d6b6cea3
2026-04-27 15:27:19 +08:00
wujunchen
0264ef0b6c refactor: split direct-modules.test.js into 5 per-module test files
Replaces the monolithic direct-modules.test.js (780 lines) with focused
per-module test files sharing a common direct-test-setup.js. Each file
is under 165 lines. All existing test assertions preserved.

New files: direct-test-setup.js, direct-cache.test.js,
direct-providers.test.js, direct-settings.test.js, direct-i18n.test.js,
direct-streaming.test.js

Change-Id: Ie9cceaf3b9b71e618c0d7e524a5186b5c44079c8
2026-04-27 15:24:32 +08:00
wujunchen
7cb68658f5 refactor: split modules.test.js into 12 per-module test files
Replaces the monolithic modules.test.js (983 lines) with focused
per-module test files sharing a common test-setup.js. Each file is
under 225 lines. All existing test assertions preserved.

New files: test-setup.js, anchor.test.js, schema.test.js, cache.test.js,
cards-nav.test.js, markdown.test.js, vault-batch.test.js, i18n.test.js,
scroll.test.js, settings.test.js, providers.test.js, streaming.test.js,
cli.test.js

Change-Id: I37a3342a1588807277e679e6535cde361e650565
2026-04-27 15:21:03 +08:00
wujunchen
62f99718f6 refactor: extract API_PROVIDER_PRESETS to provider-presets.ts
Moves 18 provider preset definitions (148 lines) from settings.ts into
a dedicated provider-presets.ts file. settings.ts reduced from 443 to
297 lines, now contains only utility functions and non-preset constants.

Change-Id: Ia9a1ef48854ab79cb405df9cd1f88d19826317d6
2026-04-27 15:15:23 +08:00
wujunchen
15b471efad refactor: extract i18n translation strings to dedicated i18n-strings.ts
Moves the STRINGS object (330 lines of zh/en translations) from i18n.ts
into a separate i18n-strings.ts file. i18n.ts now contains only the
resolveUiLanguage and translate logic (28 lines).

Change-Id: I9ddea79bddb4e8313dc16aae2a7c8d4eeff96fe1
2026-04-27 15:13:31 +08:00
fancivez
f4e0d84a9c refactor: replace magic numbers in scroll.ts with named constants
Add DEFAULT_MAX_OFFSET_PX (80), DEFAULT_PROBE_RATIO (0.1), and
FALLBACK_FRAME_MS (16) to document the purpose of each value.

Change-Id: Ie34d61c290384de81ae001f292e89f17b410e701
2026-04-27 14:11:37 +08:00
fancivez
be8a424d42 chore: upgrade biome noNonNullAssertion from warn to error
No violations exist in the codebase, so this prevents future regressions.

Change-Id: I2e5fa7fea867f1ad5752e48d277a03ce6d9560d7
2026-04-27 14:11:37 +08:00
fancivez
3338c80311 refactor: extract runForFile error handler and streaming callback
Split runForFile into focused methods: handleGenerationError for the
catch block and streamProgressFor for streaming callback creation.
Reduces runForFile from 91 to ~55 lines with clearer separation.

Change-Id: Icb0195092f25ab640f8227834a96519d14cab8df
2026-04-27 14:11:37 +08:00
fancivez
b2716da4ca test: add getApiKey, cacheEntryMatches, normalizeCardCount edge case tests
Cover normalizeCardCount boundary values (0, negative, NaN, max 30, string).
Test getApiKey with direct key, env var, precedence, and trimming.
Test cacheEntryMatches for valid match, null entry, wrong hash, wrong schema.

Change-Id: I1113d923885e03f6b28d47721cc303bbbb6d70ed
2026-04-27 14:11:37 +08:00
fancivez
bda21a0fb1 fix: replace unsafe (e as Error).message casts with instanceof guards
Fix 4 locations in providers.ts, cli.ts, and settings-tab.ts where error
objects were cast to Error without checking. Now uses proper instanceof
narrowing with String fallback for non-Error throwables.

Change-Id: Ib324380f5d56945672e32b9d3621855f6179186a
2026-04-27 14:11:37 +08:00
fancivez
5eb005f293 refactor: extract body builders and types to src/provider-bodies.ts
Move buildAnthropicMessagesBody, buildOpenAiChatBody, buildOpenAiResponsesBody,
buildGeminiBody, tokenLimitFieldForOpenAiChat and their type interfaces to a
new module. Reduces providers.ts from 494 to 367 lines (under 400 target).

Change-Id: Ib124d5cf5f2f66bac03acbf83e1a224cb6325d12
2026-04-27 14:11:37 +08:00
fancivez
c111865fbd test: add resolveCardAnchors unit tests
Cover sorting by startLine, unanchored cards pushed to end, empty/null
input, all-unanchored relative order, and default level value.

Change-Id: I74c48041897e8e4fb44555aaa319e6ebde8f91b1
2026-04-27 14:11:37 +08:00
fancivez
0ef6395ed7 test: add parseApiHeaders unit tests covering all input formats
Export parseApiHeaders for testing. Cover: JSON object input, empty/whitespace,
line-based input, comments/blank lines, malformed JSON, array input fallback,
missing colon, non-string JSON values filtered, colons in values preserved.

Change-Id: Ia00898888c6a0b78a284b43f29e382cc4080ba88
2026-04-27 14:11:37 +08:00
fancivez
ff08dbe3c2 fix: eliminate unsafe as-unknown-as casts in scroll.ts
Replace fragile double-casts with a branded ScheduleId wrapper that
unifies RAF (returns number) and setTimeout (returns Timeout) IDs
without losing type safety. The wrapper is opaque to callers.

Change-Id: I304d68b562ff803d0b20ebcbfb71a3c3d9e1d881
2026-04-27 14:11:37 +08:00
fancivez
5f8b3cfd86 chore: upgrade biome noImplicitAnyLet to error, fix parsed type in schema
Set noImplicitAnyLet to error in biome.json. Fix the violation in
parseCardsJson by typing the parsed variable as unknown. Widen
normalizeCardsPayload to accept unknown (it already handles non-object
input defensively). Remove now-unnecessary cast in provider-parsers.ts.

Change-Id: I57ee46d3179775d5d7c34f35803a44c45061b0ec
2026-04-27 14:11:37 +08:00
fancivez
c4f25a7957 style: fix import ordering and formatting per biome rules
Change-Id: I8cb97ba7c64bd56ae5408f7e8b6fdf882e832206
2026-04-27 14:11:37 +08:00