Skip to content

feat(cli): refactor Wikigraph local config and job progress - #91

Merged
Moskize91 merged 9 commits into
mainfrom
codex/wikg-local-config-refactor
Jul 3, 2026
Merged

Moskize91 merged 9 commits into
mainfrom
codex/wikg-local-config-refactor

Conversation

@Moskize91

@Moskize91 Moskize91 commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add wikg://local config and job URI operations backed by local state storage
  • reorganize ~/.wikigraph into core, jobs, cache, logs, staging, and tmp areas
  • replace public queue commands with URI-based job add/watch operations
  • unify job watch and index build progress output, including JSONL status snapshots and token usage
  • fix summary construction to map source groups through source segment boundaries

Validation

  • pnpm exec tsc -p tsconfig.json --noEmit
  • pnpm lint
  • pnpm format:check
  • pnpm test:run
  • wikg://local/config/llm test

@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0a514283-63a9-42f0-9342-6d943ef9ee9e

📥 Commits

Reviewing files that changed from the base of the PR and between 225c6d9 and 30cbfff.

📒 Files selected for processing (1)
  • src/document/shared-state-database.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/document/shared-state-database.ts

Summary by CodeRabbit

  • New Features

    • Added new local-config commands for viewing and updating local settings.
    • Improved job and index progress output with clearer status updates and token usage details.
  • Bug Fixes

    • Standardized the app’s URI format across commands and outputs.
    • Updated job, archive, and chapter workflows to use the corrected command forms.
  • Documentation

    • Refreshed help text and examples throughout the CLI to match the latest command and URI patterns.

Walkthrough

This PR renames Wiki Graph URI schemes from wkg:// and wkg-job:// to wikg:// and wikg://local/job, updates help text and CLI parsing around those forms, and adds a new local config command surface at wikg://local/config. It also replaces config-file and environment-based config loading with a SQLite-backed local config store, adds progress snapshot and token-usage reporting for queue/build flows, updates storage paths for jobs/cache/staging, and adjusts editor and archive/query code to use the new URI and segment-based indexing behavior.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the required format and accurately summarizes the main CLI config and job progress refactor.
Description check ✅ Passed The description is clearly related to the changeset and covers the main config, URI, progress, and directory layout updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/wikg-local-config-refactor

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
test/cli/args.test.ts (1)

1694-1802: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Rename the root-help URI placeholder to match the wikg scheme. data/help/commands/root.jinja still uses <located-wkg-uri> in the root search/list examples; if that’s not intentional, update it to <located-wikg-uri> for consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/cli/args.test.ts` around lines 1694 - 1802, The root help examples still
use the old URI placeholder name in the layered help contract tests, so update
the root-help text expectations to match the corrected `wikg` scheme
placeholder. In `renderMainHelpText`-driven assertions, replace the
`<located-wkg-uri>` references with the consistent `<located-wikg-uri>` form
used by the help template, keeping the `rootHelpText`/`commandHelpText` checks
aligned with the help renderers.
src/cli/convert.ts (1)

245-255: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Thread debugLogDirPath through createAppOptions. SpineDigestAppOptions still accepts debugLogDirPath and uses it to set downstream logDirPath; omitting it here drops CLI debug-log output.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/convert.ts` around lines 245 - 255, The createAppOptions helper is
dropping the debugLogDirPath option, so CLI debug logging never reaches
downstream logDirPath handling. Update createAppOptions to accept and pass
through debugLogDirPath from CLIArguments into the returned
SpineDigestAppOptions alongside verbose and llm, so the existing debug log flow
remains intact.
src/editor/markup.ts (1)

36-95: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Load the skipped fragments before summarizing gaps
loadFragments(input.segmentStartIndexes, ...) only fetches the selected segment starts, but collectSkippedSummary scans the in-between indexes and reads fragments[String(i)]. Those gap fragments are never loaded, so the skipped-summary path stays empty. The gap scan should use the actual fragment start ids, not += 1 over sentence indexes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/editor/markup.ts` around lines 36 - 95, The skipped-summary path in the
markup builder is scanning sentence indexes between selected segments, but those
gap fragments were never loaded by loadFragments, so collectSkippedSummary
cannot find them. Update the logic in the markup function to use the actual
fragment start ids for the in-between range instead of incrementing by 1 over
sentence indexes, and ensure the fragments passed into collectSkippedSummary are
the ones fetched for those real fragment starts.
🧹 Nitpick comments (10)
src/cli/llm.ts (1)

23-32: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Drop the dead sampling branches in src/cli/stage-runtime.ts. CLIConfig.llm no longer exposes temperature or topP, so these checks can never fire.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/llm.ts` around lines 23 - 32, Remove the obsolete sampling
conditionals from stage-runtime handling because CLIConfig.llm no longer
provides temperature or topP, so those branches are unreachable. Update the
logic in the stage runtime code that builds the LLM config to stop checking for
temperature/topP and only keep the supported fields, using the relevant LLM
config assembly path and any helper that forwards CLIConfig.llm into the model
creation flow.
src/editor/editor.ts (1)

236-269: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Redundant fragmentGroups.listBySerial fetch.

#getGroupSegmentStartIndexes() and #getFullText() each independently call this.#document.fragmentGroups.listBySerial(this.#serialId) and filter by groupId, duplicating the same IO/query per run() invocation.

♻️ Suggested fix
   public async run(): Promise<string> {
-    const segmentStartIndexes = await this.#getGroupSegmentStartIndexes();
+    const groups = (
+      await this.#document.fragmentGroups.listBySerial(this.#serialId)
+    ).filter((record) => record.groupId === this.#groupId);
+    const segmentStartIndexes = await this.#getGroupSegmentStartIndexes(groups);

     if (segmentStartIndexes.length === 0) {
       return "";
     }
     ...
-    const originalText = await this.#getFullText();
+    const originalText = await this.#getFullText(groups);

Then thread groups into both private methods instead of refetching.

Also applies to: 271-289

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/editor/editor.ts` around lines 236 - 269, The
`#getGroupSegmentStartIndexes()` flow is duplicating the
`this.#document.fragmentGroups.listBySerial(this.#serialId)` fetch that
`#getFullText()` already performs. Refactor `Editor.run()` to fetch and filter
`groups` once, then pass that shared `groups` data into both
`#getGroupSegmentStartIndexes` and `#getFullText` so they stop re-querying the
same records.
src/archive/query/archive-view.ts (3)

3357-3367: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Hardcoded wikg:// literals instead of WIKI_GRAPH_URI_PREFIX.

WIKI_GRAPH_URI_PREFIX is now imported into this file and used in parseEntityQid/parseWikiGraphReference, but formatTripleUri, formatEntityUri, formatTextStreamRangeUri, parseTripleHitUri, and several inline id constructions (Lines 1625-1626, 1827, 1837, 2538, 2702) still hardcode the "wikg://" string. This is exactly the kind of drift that made the prior wkg://→wikg:// rename touch dozens of call sites; using the constant everywhere would make a future scheme change a one-line edit.

♻️ Example fix for two of the helpers
 function formatTripleUri(
   subjectQid: string,
   predicate: string,
   objectQid: string,
 ): string {
-  return `wikg://triple/${subjectQid}/${encodeURIComponent(predicate)}/${objectQid}`;
+  return `${WIKI_GRAPH_URI_PREFIX}triple/${subjectQid}/${encodeURIComponent(predicate)}/${objectQid}`;
 }

 function formatEntityUri(qid: string): string {
-  return `wikg://entity/${qid}`;
+  return `${WIKI_GRAPH_URI_PREFIX}entity/${qid}`;
 }

Also applies to: 4835-4846, 5581-5589

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/archive/query/archive-view.ts` around lines 3357 - 3367, The URI helpers
and inline ID builders are still hardcoding the `wikg://` scheme instead of
using `WIKI_GRAPH_URI_PREFIX`. Update `formatTripleUri`, `formatEntityUri`,
`formatTextStreamRangeUri`, `parseTripleHitUri`, and the affected inline
constructions to build URIs from `WIKI_GRAPH_URI_PREFIX` consistently, using the
existing parser/helper symbols in `archive-view.ts` so any future scheme change
is centralized.

4199-4235: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Redundant text-stream index reload per fragment.

collectNodeSourceFragmentIds already builds and caches a createTextStreamIndex(document, chapterId, "source") promise per chapter while collecting fragmentIds. readNodeSourceFragments then calls createTextStreamIndex again for every fragment in the map, discarding that cache. For nodes spanning multiple fragments in the same chapter this reloads the same index multiple times.

Confirm whether createTextStreamIndex memoizes internally (e.g., document-level cache); if not, consider returning/reusing the per-chapter index map from collectNodeSourceFragmentIds in readNodeSourceFragments.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/archive/query/archive-view.ts` around lines 4199 - 4235, The fragment
loading in readNodeSourceFragments is re-fetching the same source text-stream
index for each fragment instead of reusing the per-chapter index work already
done by collectNodeSourceFragmentIds. Update readNodeSourceFragments (or its
helper flow around collectNodeSourceFragmentIds and createTextStreamIndex) to
reuse the existing per-chapter index/map rather than calling
createTextStreamIndex again inside the fragment loop. If createTextStreamIndex
is not internally memoized, return or pass along the chapter index from
collectNodeSourceFragmentIds so fragment range lookup can use the cached index.

5259-5262: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the redundant URI normalizer

normalizeWikiGraphObjectUri is still an identity helper. Inline or حذف it to avoid implying there’s any URI normalization here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/archive/query/archive-view.ts` around lines 5259 - 5262,
`normalizeWikiGraphObjectUri` is still just an identity helper, so remove the
redundant function or inline its call sites in archive-view.ts to avoid implying
any URI normalization behavior. Update the nearby callers to use the URI
directly, and keep the change scoped around the `normalizeWikiGraphObjectUri`
symbol so it can be deleted cleanly if unused.
src/archive/search-index/search-index.ts (1)

216-258: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Progress reporting runs inside the DB transaction.

progress?.() is awaited on every sentence/object while the whole rebuild runs inside database.transaction(...). If the reporter does any blocking I/O (e.g., writing JSONL snapshots per the PR description), the transaction is held open longer than necessary, increasing lock duration on the search-index database for large archives.

Consider buffering/throttling progress emission (e.g., every N items or time-based) or moving the transaction boundary so progress emission doesn't gate it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/archive/search-index/search-index.ts` around lines 216 - 258, Progress
reporting in the search index rebuild is awaited inside the database.transaction
flow, which keeps the transaction open while progress callbacks do blocking I/O.
Update the rebuild logic in search-index.ts around the transaction body and the
progress?.() calls in the text/object loops so progress emission is buffered,
throttled, or moved outside the transaction boundary. Use the existing rebuild
loop structure and the progress callback shape to preserve phase/done/total
updates without holding the transaction open on every item.
src/cli/local-config.ts (1)

106-112: 🎯 Functional Correctness | 🔵 Trivial

Success output may print "undefined" for model/provider.

String(llm.model) / String(llm.provider) read the raw stored config, not the resolved values buildLLMOptions actually used. If either is unset locally but a default applies internally, the successful test output misleadingly shows "undefined".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/local-config.ts` around lines 106 - 112, The success payload in
local-config output is reading raw fields from llm instead of the resolved
values used by buildLLMOptions, which can print "undefined" for model/provider.
Update the output construction in local-config to use the resolved model and
provider values from the same path that builds the LLM options, and keep the
output shape unchanged while ensuring the test result reflects the actual
configured values.
src/cli/local-config-store.ts (1)

201-222: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Validate llm.provider against the known provider set at write time.

validateLLMConfig only checks that provider is a non-empty string; the actual set of valid providers (anthropic|google|openai|openai-compatible) is enforced later, only in parseLLMProvider (src/cli/local-config.ts) when running test. An invalid provider can be silently persisted via set/put and will only fail later, at test/job time, with no field-level guidance at write time.

♻️ Proposed fix
 function validateLLMConfig(value: LocalConfigObject): LocalConfigObject {
   const allowedKeys = new Set([
     "apiKey",
     "baseURL",
     "model",
     "name",
     "provider",
   ]);
+  const allowedProviders = new Set([
+    "anthropic",
+    "google",
+    "openai",
+    "openai-compatible",
+  ]);
   const next: Record<string, unknown> = {};
 
   for (const [key, entry] of Object.entries(value)) {
     if (!allowedKeys.has(key)) {
       throw new Error(`Unknown llm config key: ${key}`);
     }
     if (typeof entry !== "string" || entry.trim() === "") {
       throw new Error(`llm.${key} must be a non-empty string.`);
     }
+    if (key === "provider" && !allowedProviders.has(entry.trim())) {
+      throw new Error(`Unknown llm.provider: ${entry.trim()}`);
+    }
     next[key] = entry.trim();
   }
 
   return next;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/local-config-store.ts` around lines 201 - 222, `validateLLMConfig`
currently accepts any non-empty `llm.provider`, so invalid providers can be
saved and only fail later in `parseLLMProvider`. Update the write-time
validation in `validateLLMConfig` to explicitly allow only the known provider
values (`anthropic`, `google`, `openai`, `openai-compatible`) while keeping the
existing non-empty string checks for the other fields, and surface a clear error
that points to `llm.provider` when the value is unsupported.
src/common/wiki-graph-dir.ts (1)

2-12: 🧹 Nitpick | 🔵 Trivial

LGTM! The centralized WIKIGRAPH_STATE_DIR override and new per-category directory resolvers (core, cache, jobs, staging, tmp, logs) are consistent with the downstream consumers (build-queue.ts, wikg-coordinator.ts, local-config-store.ts, search-cache.ts, continuation-cursor.ts, wiki-graph-temp.ts).

One note: resolveWikiGraphCacheDatabasePath() moves cache.sqlite from directly under the home directory into the new cache/ subdirectory, so upgraded installs will leave a stale cache.sqlite at the old location. Since it's rebuildable cache data this is low risk, but worth a mention in release/upgrade notes.

Also applies to: 14-16, 18-20, 22-24, 26-28, 30-32, 34-36, 38-39

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/common/wiki-graph-dir.ts` around lines 2 - 12,
`resolveWikiGraphCacheDatabasePath()` now points `cache.sqlite` into the new
`cache` subdirectory, so upgraded installs may retain an unused copy at the old
home-directory location. Keep the path change in the directory resolver
functions (especially `resolveWikiGraphCacheDatabasePath`) and add an
upgrade/release note that the old `cache.sqlite` is stale rebuildable cache data
and may be left behind after migration.
src/common/wiki-graph-temp.ts (1)

14-21: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the redundant resolveWikiGraphStateRootPath alias — it only forwards to resolveWikiGraphTempRootDirectoryPath(), so the GC call sites can use the temp-root helper directly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/common/wiki-graph-temp.ts` around lines 14 - 21, Remove the redundant
resolveWikiGraphStateRootPath alias and update the GC call sites to use
resolveWikiGraphTempRootDirectoryPath() directly. In wiki-graph-temp.ts, delete
the forwarding function and make any references in
resolveWikiGraphTempDirectoryPath or related callers point to the temp-root
helper so there is only one root-path API.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@data/help/topics/config.jinja`:
- Around line 19-58: The command examples in this help topic use the shortened
shell name “wikg” while the rest of the docs use “wikigraph”; update the example
commands in this section to the full CLI name while keeping the wikg:// URI
scheme unchanged. Locate the affected examples in the config help template and
normalize every shell invocation consistently so users see the same command name
throughout.

In `@src/cli/local-config-store.ts`:
- Around line 11-17: The shared-state SQLite files are created without explicit
permission hardening, leaving plaintext config values like llm.apiKey exposed.
Update the file-creation path used by resolveWikiGraphCoreDatabasePath(),
openSharedStateDatabase(), and the local config store initialization so the
database, init marker, and lock files are created with owner-only access (for
example via a restrictive umask or explicit 0600 permissions). Make sure the fix
is applied where the files are first created, not just when they are opened.

In `@src/cli/local-config.ts`:
- Around line 204-206: The error message thrown from local-config handling still
references the wrong CLI name, so update the string in the error path that
throws from the local config API key guard to use wikigraph instead of wikg;
check the Error construction in the local-config flow and make sure the command
shown in the message matches the current CLI name exactly.
- Around line 75-147: `runLLMConfigTest` builds LLM options before entering its
error-handling block, so failures from `buildLLMOptions` or `parseLLMProvider`
bypass the structured JSON failure path. Move the `buildLLMOptions` call and the
`llm`-derived option assembly inside the existing try/catch in
`runLLMConfigTest`, so invalid stored config is caught and reported through the
same `{ ok: false, error }` handling and `process.exitCode = 1` flow.

In `@src/editor/editor.ts`:
- Around line 302-334: The overlap logic in listSentencesInRange is shadowing
the requested range start with the fragment start index, which makes the segment
filter too broad. Update the filter in this method so it compares each
fragment’s segmentEndSentenceIndex against the outer requested
startSentenceIndex, and avoid reusing the same variable name inside the
callback. Keep the existing final sentence-level trimming, but ensure the
fragment loading step only fetches fragments that actually overlap the requested
range.

---

Outside diff comments:
In `@src/cli/convert.ts`:
- Around line 245-255: The createAppOptions helper is dropping the
debugLogDirPath option, so CLI debug logging never reaches downstream logDirPath
handling. Update createAppOptions to accept and pass through debugLogDirPath
from CLIArguments into the returned SpineDigestAppOptions alongside verbose and
llm, so the existing debug log flow remains intact.

In `@src/editor/markup.ts`:
- Around line 36-95: The skipped-summary path in the markup builder is scanning
sentence indexes between selected segments, but those gap fragments were never
loaded by loadFragments, so collectSkippedSummary cannot find them. Update the
logic in the markup function to use the actual fragment start ids for the
in-between range instead of incrementing by 1 over sentence indexes, and ensure
the fragments passed into collectSkippedSummary are the ones fetched for those
real fragment starts.

In `@test/cli/args.test.ts`:
- Around line 1694-1802: The root help examples still use the old URI
placeholder name in the layered help contract tests, so update the root-help
text expectations to match the corrected `wikg` scheme placeholder. In
`renderMainHelpText`-driven assertions, replace the `<located-wkg-uri>`
references with the consistent `<located-wikg-uri>` form used by the help
template, keeping the `rootHelpText`/`commandHelpText` checks aligned with the
help renderers.

---

Nitpick comments:
In `@src/archive/query/archive-view.ts`:
- Around line 3357-3367: The URI helpers and inline ID builders are still
hardcoding the `wikg://` scheme instead of using `WIKI_GRAPH_URI_PREFIX`. Update
`formatTripleUri`, `formatEntityUri`, `formatTextStreamRangeUri`,
`parseTripleHitUri`, and the affected inline constructions to build URIs from
`WIKI_GRAPH_URI_PREFIX` consistently, using the existing parser/helper symbols
in `archive-view.ts` so any future scheme change is centralized.
- Around line 4199-4235: The fragment loading in readNodeSourceFragments is
re-fetching the same source text-stream index for each fragment instead of
reusing the per-chapter index work already done by collectNodeSourceFragmentIds.
Update readNodeSourceFragments (or its helper flow around
collectNodeSourceFragmentIds and createTextStreamIndex) to reuse the existing
per-chapter index/map rather than calling createTextStreamIndex again inside the
fragment loop. If createTextStreamIndex is not internally memoized, return or
pass along the chapter index from collectNodeSourceFragmentIds so fragment range
lookup can use the cached index.
- Around line 5259-5262: `normalizeWikiGraphObjectUri` is still just an identity
helper, so remove the redundant function or inline its call sites in
archive-view.ts to avoid implying any URI normalization behavior. Update the
nearby callers to use the URI directly, and keep the change scoped around the
`normalizeWikiGraphObjectUri` symbol so it can be deleted cleanly if unused.

In `@src/archive/search-index/search-index.ts`:
- Around line 216-258: Progress reporting in the search index rebuild is awaited
inside the database.transaction flow, which keeps the transaction open while
progress callbacks do blocking I/O. Update the rebuild logic in search-index.ts
around the transaction body and the progress?.() calls in the text/object loops
so progress emission is buffered, throttled, or moved outside the transaction
boundary. Use the existing rebuild loop structure and the progress callback
shape to preserve phase/done/total updates without holding the transaction open
on every item.

In `@src/cli/llm.ts`:
- Around line 23-32: Remove the obsolete sampling conditionals from
stage-runtime handling because CLIConfig.llm no longer provides temperature or
topP, so those branches are unreachable. Update the logic in the stage runtime
code that builds the LLM config to stop checking for temperature/topP and only
keep the supported fields, using the relevant LLM config assembly path and any
helper that forwards CLIConfig.llm into the model creation flow.

In `@src/cli/local-config-store.ts`:
- Around line 201-222: `validateLLMConfig` currently accepts any non-empty
`llm.provider`, so invalid providers can be saved and only fail later in
`parseLLMProvider`. Update the write-time validation in `validateLLMConfig` to
explicitly allow only the known provider values (`anthropic`, `google`,
`openai`, `openai-compatible`) while keeping the existing non-empty string
checks for the other fields, and surface a clear error that points to
`llm.provider` when the value is unsupported.

In `@src/cli/local-config.ts`:
- Around line 106-112: The success payload in local-config output is reading raw
fields from llm instead of the resolved values used by buildLLMOptions, which
can print "undefined" for model/provider. Update the output construction in
local-config to use the resolved model and provider values from the same path
that builds the LLM options, and keep the output shape unchanged while ensuring
the test result reflects the actual configured values.

In `@src/common/wiki-graph-dir.ts`:
- Around line 2-12: `resolveWikiGraphCacheDatabasePath()` now points
`cache.sqlite` into the new `cache` subdirectory, so upgraded installs may
retain an unused copy at the old home-directory location. Keep the path change
in the directory resolver functions (especially
`resolveWikiGraphCacheDatabasePath`) and add an upgrade/release note that the
old `cache.sqlite` is stale rebuildable cache data and may be left behind after
migration.

In `@src/common/wiki-graph-temp.ts`:
- Around line 14-21: Remove the redundant resolveWikiGraphStateRootPath alias
and update the GC call sites to use resolveWikiGraphTempRootDirectoryPath()
directly. In wiki-graph-temp.ts, delete the forwarding function and make any
references in resolveWikiGraphTempDirectoryPath or related callers point to the
temp-root helper so there is only one root-path API.

In `@src/editor/editor.ts`:
- Around line 236-269: The `#getGroupSegmentStartIndexes()` flow is duplicating
the `this.#document.fragmentGroups.listBySerial(this.#serialId)` fetch that
`#getFullText()` already performs. Refactor `Editor.run()` to fetch and filter
`groups` once, then pass that shared `groups` data into both
`#getGroupSegmentStartIndexes` and `#getFullText` so they stop re-querying the
same records.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d572d1d9-fa7a-4d91-86e7-6feabc1386b7

📥 Commits

Reviewing files that changed from the base of the PR and between 42e6288 and 15a3af6.

📒 Files selected for processing (110)
  • data/help/commands/archive/create.jinja
  • data/help/commands/archive/estimate.jinja
  • data/help/commands/archive/evidence.jinja
  • data/help/commands/archive/export.jinja
  • data/help/commands/archive/get.jinja
  • data/help/commands/archive/list.jinja
  • data/help/commands/archive/next.jinja
  • data/help/commands/archive/pack.jinja
  • data/help/commands/archive/related.jinja
  • data/help/commands/archive/search.jinja
  • data/help/commands/config-status.jinja
  • data/help/commands/maintenance/chapter.jinja
  • data/help/commands/maintenance/chapter/add.jinja
  • data/help/commands/maintenance/chapter/list.jinja
  • data/help/commands/maintenance/chapter/move.jinja
  • data/help/commands/maintenance/chapter/remove.jinja
  • data/help/commands/maintenance/chapter/reset.jinja
  • data/help/commands/maintenance/chapter/set-source.jinja
  • data/help/commands/maintenance/chapter/set-summary.jinja
  • data/help/commands/maintenance/chapter/set-title.jinja
  • data/help/commands/maintenance/chapter/tree.jinja
  • data/help/commands/maintenance/cover.jinja
  • data/help/commands/maintenance/meta.jinja
  • data/help/commands/queue.jinja
  • data/help/commands/queue/add.jinja
  • data/help/commands/queue/boost.jinja
  • data/help/commands/queue/cancel.jinja
  • data/help/commands/queue/clean.jinja
  • data/help/commands/queue/list.jinja
  • data/help/commands/queue/pause.jinja
  • data/help/commands/queue/resume.jinja
  • data/help/commands/queue/status.jinja
  • data/help/commands/queue/target.jinja
  • data/help/commands/queue/watch.jinja
  • data/help/commands/queue/worker.jinja
  • data/help/commands/root.jinja
  • data/help/commands/transform.jinja
  • data/help/topics/ai.jinja
  • data/help/topics/command.jinja
  • data/help/topics/config-file.jinja
  • data/help/topics/config.jinja
  • data/help/topics/env.jinja
  • data/help/topics/format.jinja
  • data/help/topics/index.jinja
  • data/help/topics/recipe.jinja
  • data/help/topics/runtime.jinja
  • data/help/topics/task.jinja
  • data/help/topics/troubleshoot.jinja
  • data/help/topics/uri.jinja
  • package.json
  • src/archive/query/archive-view.ts
  • src/archive/query/continuation-cursor.ts
  • src/archive/query/search-cache.ts
  • src/archive/search-index/index.ts
  • src/archive/search-index/search-index.ts
  • src/cli/archive-chapter.ts
  • src/cli/archive-index.ts
  • src/cli/archive.ts
  • src/cli/args.ts
  • src/cli/config.ts
  • src/cli/convert.ts
  • src/cli/errors.ts
  • src/cli/help.ts
  • src/cli/llm.ts
  • src/cli/local-config-store.ts
  • src/cli/local-config.ts
  • src/cli/main.ts
  • src/cli/progress-output.ts
  • src/cli/queue.ts
  • src/cli/stage-runtime.ts
  • src/cli/status.ts
  • src/common/wiki-graph-dir.ts
  • src/common/wiki-graph-temp.ts
  • src/common/wiki-graph-uri.ts
  • src/editor/clue.ts
  • src/editor/editor.ts
  • src/editor/markup.ts
  • src/facade/build-queue.ts
  • src/facade/index.ts
  • src/facade/spine-digest.ts
  • src/llm/client.ts
  • src/llm/index.ts
  • src/llm/types.ts
  • src/output/epub/book.ts
  • src/output/plain-text.ts
  • src/serial.ts
  • src/wikg/wikg-coordinator.ts
  • src/wikipage/wikimedia-client.ts
  • test/archive/query/archive-view.test.ts
  • test/archive/query/search-cache.test.ts
  • test/cli/README.md
  • test/cli/archive-chapter.test.ts
  • test/cli/archive.test.ts
  • test/cli/args.test.ts
  • test/cli/config.test.ts
  • test/cli/convert.test.ts
  • test/cli/llm.test.ts
  • test/cli/local-config.test.ts
  • test/cli/main.test.ts
  • test/cli/queue.test.ts
  • test/cli/status.test.ts
  • test/common/wiki-graph-uri.test.ts
  • test/editor/editor.test.ts
  • test/facade/build-queue.test.ts
  • test/gc/gc.test.ts
  • test/llm/client.test.ts
  • test/wikg/spine-digest-file.test.ts
  • test/wikimatch/policy-judge.test.ts
  • test/wikipage/normalizer.test.ts
  • test/wikipage/resolver.test.ts
💤 Files with no reviewable changes (7)
  • data/help/commands/queue/worker.jinja
  • data/help/topics/env.jinja
  • data/help/topics/config-file.jinja
  • test/cli/status.test.ts
  • data/help/commands/config-status.jinja
  • src/cli/status.ts
  • src/cli/errors.ts

Comment thread data/help/topics/config.jinja Outdated
Comment thread src/cli/local-config-store.ts
Comment thread src/cli/local-config.ts
Comment thread src/cli/local-config.ts
Comment thread src/editor/editor.ts
@Moskize91 Moskize91 changed the title Refactor Wikigraph local config and job progress feat(cli): refactor Wikigraph local config and job progress Jul 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/document/shared-state-database.ts`:
- Around line 51-61: The existing-database paths in shared-state initialization
skip hardening the database file, so add a best-effort
hardenSharedStateFile(resolvedDatabasePath) before both the early
hasInitMarker(...) return and the marker-exists branch inside the initialize
flow in shared-state-database.ts; keep the current hardening for markerPath and
ensure resolvedDatabasePath is also hardened whenever Database.initialize is
bypassed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c5540d3-56d0-4616-bf1f-1852907732ca

📥 Commits

Reviewing files that changed from the base of the PR and between 15a3af6 and 225c6d9.

📒 Files selected for processing (12)
  • data/help/commands/archive/list.jinja
  • data/help/commands/root.jinja
  • data/help/commands/transform.jinja
  • data/help/topics/command.jinja
  • data/help/topics/config.jinja
  • src/cli/local-config-store.ts
  • src/cli/local-config.ts
  • src/document/shared-state-database.ts
  • src/editor/editor.ts
  • src/editor/markup.ts
  • test/cli/args.test.ts
  • test/cli/local-config.test.ts
✅ Files skipped from review due to trivial changes (4)
  • data/help/commands/transform.jinja
  • data/help/topics/command.jinja
  • data/help/topics/config.jinja
  • data/help/commands/root.jinja
🚧 Files skipped from review as they are similar to previous changes (7)
  • data/help/commands/archive/list.jinja
  • test/cli/local-config.test.ts
  • src/editor/editor.ts
  • src/cli/local-config-store.ts
  • src/cli/local-config.ts
  • src/editor/markup.ts
  • test/cli/args.test.ts

Comment thread src/document/shared-state-database.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant