@zwbigi/ink-xy 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +2 -2
- package/.next/build-manifest.json +2 -2
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/inkos/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/install/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/search/route.js.nft.json +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +1 -1
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app-paths-manifest.json +2 -2
- package/.next/server/chunks/162.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/trace +4 -4
- package/.next/trace-build +1 -1
- package/bin/pi-web.js +4 -1
- package/inkos/.env.example +20 -0
- package/inkos/.node-version +1 -0
- package/inkos/.nvmrc +1 -0
- package/inkos/CHANGELOG.md +787 -0
- package/inkos/CONTRIBUTING.md +89 -0
- package/inkos/LICENSE +661 -0
- package/inkos/README.en.md +483 -0
- package/inkos/README.ja.md +461 -0
- package/inkos/README.md +272 -0
- package/inkos/assets/15qun.jpg +0 -0
- package/inkos/assets/41777702961_.pic.jpg +0 -0
- package/inkos/assets/inkos-short-demo-cover.png +0 -0
- package/inkos/assets/inkos-text.svg +40 -0
- package/inkos/assets/logo.svg +47 -0
- package/inkos/assets/screenshot-chapters.png +0 -0
- package/inkos/assets/screenshot-pipeline.png +0 -0
- package/inkos/assets/screenshot-state.png +0 -0
- package/inkos/assets/screenshot-terminal.png +0 -0
- package/inkos/assets/wechat-group-v8.jpg +0 -0
- package/inkos/package.json +42 -0
- package/inkos/packages/cli/package.json +74 -0
- package/inkos/packages/cli/src/__tests__/analytics.test.ts +154 -0
- package/inkos/packages/cli/src/__tests__/cli-integration.test.ts +1031 -0
- package/inkos/packages/cli/src/__tests__/daemon.test.ts +93 -0
- package/inkos/packages/cli/src/__tests__/doctor.test.ts +36 -0
- package/inkos/packages/cli/src/__tests__/interact-command.test.ts +142 -0
- package/inkos/packages/cli/src/__tests__/interaction-tools.test.ts +107 -0
- package/inkos/packages/cli/src/__tests__/llm-overrides.test.ts +25 -0
- package/inkos/packages/cli/src/__tests__/localization.test.ts +121 -0
- package/inkos/packages/cli/src/__tests__/progress-text.test.ts +92 -0
- package/inkos/packages/cli/src/__tests__/project-bootstrap.test.ts +71 -0
- package/inkos/packages/cli/src/__tests__/publish-package.test.ts +272 -0
- package/inkos/packages/cli/src/__tests__/revision-command.test.ts +82 -0
- package/inkos/packages/cli/src/__tests__/runtime-requirements.test.ts +89 -0
- package/inkos/packages/cli/src/__tests__/short-fiction-command.test.ts +48 -0
- package/inkos/packages/cli/src/__tests__/studio-runtime.test.ts +142 -0
- package/inkos/packages/cli/src/__tests__/studio.test.ts +87 -0
- package/inkos/packages/cli/src/__tests__/tui-activity-state.test.ts +20 -0
- package/inkos/packages/cli/src/__tests__/tui-agent-session.test.ts +213 -0
- package/inkos/packages/cli/src/__tests__/tui-chat-depth.test.ts +27 -0
- package/inkos/packages/cli/src/__tests__/tui-chat-draft.test.ts +44 -0
- package/inkos/packages/cli/src/__tests__/tui-command.test.ts +86 -0
- package/inkos/packages/cli/src/__tests__/tui-composer-caret.test.ts +46 -0
- package/inkos/packages/cli/src/__tests__/tui-composer-display.test.ts +40 -0
- package/inkos/packages/cli/src/__tests__/tui-dashboard.test.tsx +219 -0
- package/inkos/packages/cli/src/__tests__/tui-effects-i18n.test.ts +29 -0
- package/inkos/packages/cli/src/__tests__/tui-i18n.test.ts +22 -0
- package/inkos/packages/cli/src/__tests__/tui-input-chrome.test.ts +10 -0
- package/inkos/packages/cli/src/__tests__/tui-input-history.test.ts +40 -0
- package/inkos/packages/cli/src/__tests__/tui-layout.test.ts +55 -0
- package/inkos/packages/cli/src/__tests__/tui-local-commands.test.ts +47 -0
- package/inkos/packages/cli/src/__tests__/tui-session-store.test.ts +81 -0
- package/inkos/packages/cli/src/__tests__/tui-setup-i18n.test.ts +31 -0
- package/inkos/packages/cli/src/__tests__/tui-slash-autocomplete.test.ts +33 -0
- package/inkos/packages/cli/src/commands/agent.ts +65 -0
- package/inkos/packages/cli/src/commands/analytics.ts +77 -0
- package/inkos/packages/cli/src/commands/audit.ts +52 -0
- package/inkos/packages/cli/src/commands/book.ts +260 -0
- package/inkos/packages/cli/src/commands/compose.ts +50 -0
- package/inkos/packages/cli/src/commands/config.ts +328 -0
- package/inkos/packages/cli/src/commands/consolidate.ts +50 -0
- package/inkos/packages/cli/src/commands/daemon.ts +121 -0
- package/inkos/packages/cli/src/commands/detect.ts +125 -0
- package/inkos/packages/cli/src/commands/doctor.ts +391 -0
- package/inkos/packages/cli/src/commands/draft.ts +43 -0
- package/inkos/packages/cli/src/commands/eval.ts +217 -0
- package/inkos/packages/cli/src/commands/export.ts +45 -0
- package/inkos/packages/cli/src/commands/fanfic.ts +183 -0
- package/inkos/packages/cli/src/commands/genre.ts +160 -0
- package/inkos/packages/cli/src/commands/import.ts +158 -0
- package/inkos/packages/cli/src/commands/init.ts +47 -0
- package/inkos/packages/cli/src/commands/interact.ts +109 -0
- package/inkos/packages/cli/src/commands/plan.ts +54 -0
- package/inkos/packages/cli/src/commands/radar.ts +60 -0
- package/inkos/packages/cli/src/commands/review.ts +253 -0
- package/inkos/packages/cli/src/commands/revise.ts +58 -0
- package/inkos/packages/cli/src/commands/short-fiction.ts +294 -0
- package/inkos/packages/cli/src/commands/status.ts +138 -0
- package/inkos/packages/cli/src/commands/studio.ts +194 -0
- package/inkos/packages/cli/src/commands/style.ts +99 -0
- package/inkos/packages/cli/src/commands/tui.ts +18 -0
- package/inkos/packages/cli/src/commands/update.ts +45 -0
- package/inkos/packages/cli/src/commands/write.ts +324 -0
- package/inkos/packages/cli/src/index.ts +5 -0
- package/inkos/packages/cli/src/interaction/tools.ts +49 -0
- package/inkos/packages/cli/src/localization.ts +215 -0
- package/inkos/packages/cli/src/program.ts +106 -0
- package/inkos/packages/cli/src/progress-text.ts +85 -0
- package/inkos/packages/cli/src/project-bootstrap.ts +175 -0
- package/inkos/packages/cli/src/runtime-requirements.ts +135 -0
- package/inkos/packages/cli/src/tui/__tests__/markdown.test.ts +64 -0
- package/inkos/packages/cli/src/tui/activity-state.ts +41 -0
- package/inkos/packages/cli/src/tui/agent-input.ts +264 -0
- package/inkos/packages/cli/src/tui/ansi.ts +72 -0
- package/inkos/packages/cli/src/tui/app.ts +130 -0
- package/inkos/packages/cli/src/tui/chat-depth.ts +22 -0
- package/inkos/packages/cli/src/tui/chat-draft.ts +42 -0
- package/inkos/packages/cli/src/tui/composer-caret.ts +22 -0
- package/inkos/packages/cli/src/tui/composer-display.ts +26 -0
- package/inkos/packages/cli/src/tui/dashboard-model.ts +164 -0
- package/inkos/packages/cli/src/tui/dashboard.tsx +544 -0
- package/inkos/packages/cli/src/tui/effects.ts +542 -0
- package/inkos/packages/cli/src/tui/i18n.ts +278 -0
- package/inkos/packages/cli/src/tui/input-history.ts +69 -0
- package/inkos/packages/cli/src/tui/local-commands.ts +55 -0
- package/inkos/packages/cli/src/tui/markdown.ts +64 -0
- package/inkos/packages/cli/src/tui/session-store.ts +6 -0
- package/inkos/packages/cli/src/tui/setup.ts +397 -0
- package/inkos/packages/cli/src/tui/slash-autocomplete.ts +62 -0
- package/inkos/packages/cli/src/tui/theme.ts +17 -0
- package/inkos/packages/cli/src/utils.ts +222 -0
- package/inkos/packages/cli/tsconfig.json +9 -0
- package/inkos/packages/core/genres/cozy.md +43 -0
- package/inkos/packages/core/genres/cultivation.md +42 -0
- package/inkos/packages/core/genres/dungeon-core.md +40 -0
- package/inkos/packages/core/genres/horror.md +51 -0
- package/inkos/packages/core/genres/isekai.md +43 -0
- package/inkos/packages/core/genres/litrpg.md +43 -0
- package/inkos/packages/core/genres/other.md +24 -0
- package/inkos/packages/core/genres/progression.md +41 -0
- package/inkos/packages/core/genres/romantasy.md +45 -0
- package/inkos/packages/core/genres/sci-fi.md +42 -0
- package/inkos/packages/core/genres/system-apocalypse.md +40 -0
- package/inkos/packages/core/genres/tower-climber.md +41 -0
- package/inkos/packages/core/genres/urban.md +53 -0
- package/inkos/packages/core/genres/xianxia.md +46 -0
- package/inkos/packages/core/genres/xuanhuan.md +64 -0
- package/inkos/packages/core/package.json +61 -0
- package/inkos/packages/core/src/__tests__/agent-max-tokens-policy.test.ts +29 -0
- package/inkos/packages/core/src/__tests__/agent-session.test.ts +866 -0
- package/inkos/packages/core/src/__tests__/agent-system-prompt.test.ts +167 -0
- package/inkos/packages/core/src/__tests__/agent-tools-params.test.ts +197 -0
- package/inkos/packages/core/src/__tests__/agent-tools.test.ts +421 -0
- package/inkos/packages/core/src/__tests__/ai-tells.test.ts +90 -0
- package/inkos/packages/core/src/__tests__/architect-phase5-consolidated.test.ts +445 -0
- package/inkos/packages/core/src/__tests__/architect-phase5.test.ts +455 -0
- package/inkos/packages/core/src/__tests__/architect-phase7.test.ts +210 -0
- package/inkos/packages/core/src/__tests__/architect.test.ts +859 -0
- package/inkos/packages/core/src/__tests__/audit-parse.test.ts +78 -0
- package/inkos/packages/core/src/__tests__/book-id.test.ts +26 -0
- package/inkos/packages/core/src/__tests__/book-session-store.test.ts +447 -0
- package/inkos/packages/core/src/__tests__/book-session.test.ts +113 -0
- package/inkos/packages/core/src/__tests__/chapter-analyzer.test.ts +574 -0
- package/inkos/packages/core/src/__tests__/chapter-memo-parser.test.ts +247 -0
- package/inkos/packages/core/src/__tests__/chapter-persistence.test.ts +198 -0
- package/inkos/packages/core/src/__tests__/chapter-review-cycle.test.ts +294 -0
- package/inkos/packages/core/src/__tests__/chapter-splitter.test.ts +156 -0
- package/inkos/packages/core/src/__tests__/chapter-state-recovery.test.ts +235 -0
- package/inkos/packages/core/src/__tests__/chapter-truth-validation.test.ts +253 -0
- package/inkos/packages/core/src/__tests__/composer.test.ts +627 -0
- package/inkos/packages/core/src/__tests__/config-loader.test.ts +325 -0
- package/inkos/packages/core/src/__tests__/config-migration.test.ts +102 -0
- package/inkos/packages/core/src/__tests__/consolidator.test.ts +32 -0
- package/inkos/packages/core/src/__tests__/context-filter.test.ts +60 -0
- package/inkos/packages/core/src/__tests__/context-transform.test.ts +108 -0
- package/inkos/packages/core/src/__tests__/continuity.test.ts +391 -0
- package/inkos/packages/core/src/__tests__/detection-insights.test.ts +59 -0
- package/inkos/packages/core/src/__tests__/detector.test.ts +86 -0
- package/inkos/packages/core/src/__tests__/draft-directive-parser.test.ts +386 -0
- package/inkos/packages/core/src/__tests__/edit-controller.test.ts +190 -0
- package/inkos/packages/core/src/__tests__/effective-llm-config.test.ts +486 -0
- package/inkos/packages/core/src/__tests__/fanfic-dimensions.test.ts +58 -0
- package/inkos/packages/core/src/__tests__/fanfic-models.test.ts +69 -0
- package/inkos/packages/core/src/__tests__/governed-working-set.test.ts +155 -0
- package/inkos/packages/core/src/__tests__/hook-arbiter.test.ts +124 -0
- package/inkos/packages/core/src/__tests__/hook-governance.test.ts +228 -0
- package/inkos/packages/core/src/__tests__/hook-health.test.ts +166 -0
- package/inkos/packages/core/src/__tests__/hook-ledger-validator.test.ts +236 -0
- package/inkos/packages/core/src/__tests__/hook-promotion.test.ts +192 -0
- package/inkos/packages/core/src/__tests__/hook-stale-detection.test.ts +136 -0
- package/inkos/packages/core/src/__tests__/index-notify-lazy.test.ts +20 -0
- package/inkos/packages/core/src/__tests__/interaction-chat-tokens.test.ts +170 -0
- package/inkos/packages/core/src/__tests__/interaction-models.test.ts +155 -0
- package/inkos/packages/core/src/__tests__/interaction-nl-router.test.ts +223 -0
- package/inkos/packages/core/src/__tests__/interaction-runtime.test.ts +633 -0
- package/inkos/packages/core/src/__tests__/interaction-tools.test.ts +343 -0
- package/inkos/packages/core/src/__tests__/length-metrics.test.ts +82 -0
- package/inkos/packages/core/src/__tests__/length-normalizer.test.ts +331 -0
- package/inkos/packages/core/src/__tests__/list-models.test.ts +109 -0
- package/inkos/packages/core/src/__tests__/llm-env.test.ts +31 -0
- package/inkos/packages/core/src/__tests__/logger.test.ts +175 -0
- package/inkos/packages/core/src/__tests__/long-span-fatigue.test.ts +160 -0
- package/inkos/packages/core/src/__tests__/memory-retrieval.test.ts +1303 -0
- package/inkos/packages/core/src/__tests__/models.test.ts +918 -0
- package/inkos/packages/core/src/__tests__/outline-paths.test.ts +97 -0
- package/inkos/packages/core/src/__tests__/path-safety.test.ts +22 -0
- package/inkos/packages/core/src/__tests__/persisted-governed-plan.test.ts +134 -0
- package/inkos/packages/core/src/__tests__/phase5-cleanup.test.ts +393 -0
- package/inkos/packages/core/src/__tests__/phase5-hotfix.test.ts +288 -0
- package/inkos/packages/core/src/__tests__/phase7-hotfix.test.ts +614 -0
- package/inkos/packages/core/src/__tests__/pipeline-agent.test.ts +354 -0
- package/inkos/packages/core/src/__tests__/pipeline-runner-memory-sync.test.ts +317 -0
- package/inkos/packages/core/src/__tests__/pipeline-runner.test.ts +5200 -0
- package/inkos/packages/core/src/__tests__/planner-context.test.ts +137 -0
- package/inkos/packages/core/src/__tests__/planner-prompts-ratio.test.ts +11 -0
- package/inkos/packages/core/src/__tests__/planner-prompts.test.ts +171 -0
- package/inkos/packages/core/src/__tests__/planner.test.ts +362 -0
- package/inkos/packages/core/src/__tests__/planning-materials.test.ts +90 -0
- package/inkos/packages/core/src/__tests__/polisher.test.ts +189 -0
- package/inkos/packages/core/src/__tests__/post-write-validator.test.ts +291 -0
- package/inkos/packages/core/src/__tests__/probe.test.ts +77 -0
- package/inkos/packages/core/src/__tests__/project-interaction.test.ts +241 -0
- package/inkos/packages/core/src/__tests__/provider.test.ts +953 -0
- package/inkos/packages/core/src/__tests__/providers-group.test.ts +34 -0
- package/inkos/packages/core/src/__tests__/providers-lookup.test.ts +81 -0
- package/inkos/packages/core/src/__tests__/providers-schema.test.ts +158 -0
- package/inkos/packages/core/src/__tests__/proxy-fetch.test.ts +75 -0
- package/inkos/packages/core/src/__tests__/revise-foundation.test.ts +514 -0
- package/inkos/packages/core/src/__tests__/reviser.test.ts +859 -0
- package/inkos/packages/core/src/__tests__/runtime-state-store.test.ts +388 -0
- package/inkos/packages/core/src/__tests__/scheduler.test.ts +123 -0
- package/inkos/packages/core/src/__tests__/secrets-migration.test.ts +71 -0
- package/inkos/packages/core/src/__tests__/secrets.test.ts +95 -0
- package/inkos/packages/core/src/__tests__/sensitive-words.test.ts +88 -0
- package/inkos/packages/core/src/__tests__/service-presets-regression.test.ts +73 -0
- package/inkos/packages/core/src/__tests__/service-resolver-regression.test.ts +75 -0
- package/inkos/packages/core/src/__tests__/service-resolver.test.ts +228 -0
- package/inkos/packages/core/src/__tests__/session-transcript-restore.test.ts +1311 -0
- package/inkos/packages/core/src/__tests__/session-transcript.test.ts +195 -0
- package/inkos/packages/core/src/__tests__/settler-delta-parser.test.ts +133 -0
- package/inkos/packages/core/src/__tests__/short-fiction-public.test.ts +241 -0
- package/inkos/packages/core/src/__tests__/spot-fix-patches.test.ts +104 -0
- package/inkos/packages/core/src/__tests__/state-manager.test.ts +1298 -0
- package/inkos/packages/core/src/__tests__/state-projections.test.ts +130 -0
- package/inkos/packages/core/src/__tests__/state-reducer.test.ts +372 -0
- package/inkos/packages/core/src/__tests__/state-validator-agent.test.ts +165 -0
- package/inkos/packages/core/src/__tests__/state-validator.test.ts +122 -0
- package/inkos/packages/core/src/__tests__/style-analyzer.test.ts +61 -0
- package/inkos/packages/core/src/__tests__/temperature-constraints.test.ts +57 -0
- package/inkos/packages/core/src/__tests__/v13-hotfix-round4.test.ts +343 -0
- package/inkos/packages/core/src/__tests__/verify-service.test.ts +77 -0
- package/inkos/packages/core/src/__tests__/webhook.test.ts +91 -0
- package/inkos/packages/core/src/__tests__/writer-parser.test.ts +348 -0
- package/inkos/packages/core/src/__tests__/writer-prompts.test.ts +269 -0
- package/inkos/packages/core/src/__tests__/writer.test.ts +1360 -0
- package/inkos/packages/core/src/agent/agent-session.ts +737 -0
- package/inkos/packages/core/src/agent/agent-system-prompt.ts +199 -0
- package/inkos/packages/core/src/agent/agent-tools.ts +835 -0
- package/inkos/packages/core/src/agent/context-transform.ts +85 -0
- package/inkos/packages/core/src/agent/index.ts +14 -0
- package/inkos/packages/core/src/agents/ai-tells.ts +161 -0
- package/inkos/packages/core/src/agents/architect.ts +1291 -0
- package/inkos/packages/core/src/agents/base.ts +100 -0
- package/inkos/packages/core/src/agents/chapter-analyzer.ts +634 -0
- package/inkos/packages/core/src/agents/composer.ts +469 -0
- package/inkos/packages/core/src/agents/consolidator.ts +218 -0
- package/inkos/packages/core/src/agents/continuity.ts +824 -0
- package/inkos/packages/core/src/agents/detection-insights.ts +72 -0
- package/inkos/packages/core/src/agents/detector.ts +224 -0
- package/inkos/packages/core/src/agents/en-prompt-sections.ts +129 -0
- package/inkos/packages/core/src/agents/fanfic-canon-importer.ts +146 -0
- package/inkos/packages/core/src/agents/fanfic-dimensions.ts +87 -0
- package/inkos/packages/core/src/agents/fanfic-prompt-sections.ts +109 -0
- package/inkos/packages/core/src/agents/foundation-reviewer.ts +204 -0
- package/inkos/packages/core/src/agents/length-normalizer.ts +218 -0
- package/inkos/packages/core/src/agents/observer-prompts.ts +127 -0
- package/inkos/packages/core/src/agents/planner-context.ts +297 -0
- package/inkos/packages/core/src/agents/planner-prompts.ts +404 -0
- package/inkos/packages/core/src/agents/planner.ts +783 -0
- package/inkos/packages/core/src/agents/polisher.ts +153 -0
- package/inkos/packages/core/src/agents/post-write-validator.ts +873 -0
- package/inkos/packages/core/src/agents/radar-source.ts +123 -0
- package/inkos/packages/core/src/agents/radar.ts +120 -0
- package/inkos/packages/core/src/agents/reviser.ts +701 -0
- package/inkos/packages/core/src/agents/rules-reader.ts +155 -0
- package/inkos/packages/core/src/agents/sensitive-words.ts +142 -0
- package/inkos/packages/core/src/agents/settler-delta-parser.ts +53 -0
- package/inkos/packages/core/src/agents/settler-parser.ts +38 -0
- package/inkos/packages/core/src/agents/settler-prompts.ts +230 -0
- package/inkos/packages/core/src/agents/short-fiction.ts +429 -0
- package/inkos/packages/core/src/agents/state-validator.ts +322 -0
- package/inkos/packages/core/src/agents/style-analyzer.ts +93 -0
- package/inkos/packages/core/src/agents/writer-parser.ts +178 -0
- package/inkos/packages/core/src/agents/writer-prompts.ts +899 -0
- package/inkos/packages/core/src/agents/writer.ts +1450 -0
- package/inkos/packages/core/src/index.ts +392 -0
- package/inkos/packages/core/src/interaction/book-session-store.ts +226 -0
- package/inkos/packages/core/src/interaction/draft-directive-parser.ts +266 -0
- package/inkos/packages/core/src/interaction/edit-controller.ts +270 -0
- package/inkos/packages/core/src/interaction/events.ts +41 -0
- package/inkos/packages/core/src/interaction/export-artifact.ts +151 -0
- package/inkos/packages/core/src/interaction/intents.ts +63 -0
- package/inkos/packages/core/src/interaction/modes.ts +13 -0
- package/inkos/packages/core/src/interaction/nl-router.ts +258 -0
- package/inkos/packages/core/src/interaction/project-control.ts +150 -0
- package/inkos/packages/core/src/interaction/project-session-store.ts +81 -0
- package/inkos/packages/core/src/interaction/project-tools.ts +704 -0
- package/inkos/packages/core/src/interaction/request-router.ts +5 -0
- package/inkos/packages/core/src/interaction/runtime.ts +1167 -0
- package/inkos/packages/core/src/interaction/session-transcript-legacy.ts +113 -0
- package/inkos/packages/core/src/interaction/session-transcript-restore.ts +607 -0
- package/inkos/packages/core/src/interaction/session-transcript-schema.ts +76 -0
- package/inkos/packages/core/src/interaction/session-transcript.ts +189 -0
- package/inkos/packages/core/src/interaction/session.ts +226 -0
- package/inkos/packages/core/src/interaction/truth-authority.ts +45 -0
- package/inkos/packages/core/src/llm/config-migration.ts +58 -0
- package/inkos/packages/core/src/llm/cover-providers.ts +45 -0
- package/inkos/packages/core/src/llm/provider.ts +1331 -0
- package/inkos/packages/core/src/llm/providers/endpoints/ai360.ts +42 -0
- package/inkos/packages/core/src/llm/providers/endpoints/anthropic.ts +82 -0
- package/inkos/packages/core/src/llm/providers/endpoints/astronCodingPlan.ts +30 -0
- package/inkos/packages/core/src/llm/providers/endpoints/baichuan.ts +28 -0
- package/inkos/packages/core/src/llm/providers/endpoints/bailian.ts +65 -0
- package/inkos/packages/core/src/llm/providers/endpoints/bailianCodingPlan.ts +30 -0
- package/inkos/packages/core/src/llm/providers/endpoints/custom.ts +22 -0
- package/inkos/packages/core/src/llm/providers/endpoints/deepseek.ts +35 -0
- package/inkos/packages/core/src/llm/providers/endpoints/giteeai.ts +41 -0
- package/inkos/packages/core/src/llm/providers/endpoints/githubCopilot.ts +43 -0
- package/inkos/packages/core/src/llm/providers/endpoints/glmCodingPlan.ts +28 -0
- package/inkos/packages/core/src/llm/providers/endpoints/google.ts +51 -0
- package/inkos/packages/core/src/llm/providers/endpoints/hunyuan.ts +42 -0
- package/inkos/packages/core/src/llm/providers/endpoints/infiniai.ts +72 -0
- package/inkos/packages/core/src/llm/providers/endpoints/internlm.ts +28 -0
- package/inkos/packages/core/src/llm/providers/endpoints/kimiCode.ts +23 -0
- package/inkos/packages/core/src/llm/providers/endpoints/kimiCodingPlan.ts +24 -0
- package/inkos/packages/core/src/llm/providers/endpoints/kkaiapi.ts +56 -0
- package/inkos/packages/core/src/llm/providers/endpoints/longcat.ts +25 -0
- package/inkos/packages/core/src/llm/providers/endpoints/minimax.ts +39 -0
- package/inkos/packages/core/src/llm/providers/endpoints/minimaxCodingPlan.ts +28 -0
- package/inkos/packages/core/src/llm/providers/endpoints/mistral.ts +40 -0
- package/inkos/packages/core/src/llm/providers/endpoints/modelscope.ts +30 -0
- package/inkos/packages/core/src/llm/providers/endpoints/moonshot.ts +39 -0
- package/inkos/packages/core/src/llm/providers/endpoints/newapi.ts +21 -0
- package/inkos/packages/core/src/llm/providers/endpoints/ollama.ts +73 -0
- package/inkos/packages/core/src/llm/providers/endpoints/openai.ts +77 -0
- package/inkos/packages/core/src/llm/providers/endpoints/opencodeCodingPlan.ts +30 -0
- package/inkos/packages/core/src/llm/providers/endpoints/openrouter.ts +87 -0
- package/inkos/packages/core/src/llm/providers/endpoints/ppio.ts +86 -0
- package/inkos/packages/core/src/llm/providers/endpoints/qiniu.ts +32 -0
- package/inkos/packages/core/src/llm/providers/endpoints/sensenova.ts +45 -0
- package/inkos/packages/core/src/llm/providers/endpoints/siliconcloud.ts +126 -0
- package/inkos/packages/core/src/llm/providers/endpoints/spark.ts +33 -0
- package/inkos/packages/core/src/llm/providers/endpoints/stepfun.ts +35 -0
- package/inkos/packages/core/src/llm/providers/endpoints/tencentcloud.ts +25 -0
- package/inkos/packages/core/src/llm/providers/endpoints/volcengine.ts +52 -0
- package/inkos/packages/core/src/llm/providers/endpoints/volcengineCodingPlan.ts +42 -0
- package/inkos/packages/core/src/llm/providers/endpoints/wenxin.ts +106 -0
- package/inkos/packages/core/src/llm/providers/endpoints/xai.ts +34 -0
- package/inkos/packages/core/src/llm/providers/endpoints/xiaomimimo.ts +26 -0
- package/inkos/packages/core/src/llm/providers/endpoints/zeroone.ts +34 -0
- package/inkos/packages/core/src/llm/providers/endpoints/zhipu.ts +61 -0
- package/inkos/packages/core/src/llm/providers/index.ts +71 -0
- package/inkos/packages/core/src/llm/providers/lookup.ts +70 -0
- package/inkos/packages/core/src/llm/providers/probe.ts +35 -0
- package/inkos/packages/core/src/llm/providers/types.ts +89 -0
- package/inkos/packages/core/src/llm/providers/verify.ts +104 -0
- package/inkos/packages/core/src/llm/secrets.ts +77 -0
- package/inkos/packages/core/src/llm/service-presets.ts +215 -0
- package/inkos/packages/core/src/llm/service-resolver.ts +91 -0
- package/inkos/packages/core/src/models/book-rules.ts +126 -0
- package/inkos/packages/core/src/models/book.ts +70 -0
- package/inkos/packages/core/src/models/chapter.ts +42 -0
- package/inkos/packages/core/src/models/detection.ts +25 -0
- package/inkos/packages/core/src/models/genre-profile.ts +36 -0
- package/inkos/packages/core/src/models/input-governance.ts +99 -0
- package/inkos/packages/core/src/models/length-governance.ts +46 -0
- package/inkos/packages/core/src/models/project.ts +161 -0
- package/inkos/packages/core/src/models/runtime-state.ts +144 -0
- package/inkos/packages/core/src/models/state.ts +52 -0
- package/inkos/packages/core/src/models/style-profile.ts +15 -0
- package/inkos/packages/core/src/notify/dispatcher.ts +96 -0
- package/inkos/packages/core/src/notify/feishu.ts +34 -0
- package/inkos/packages/core/src/notify/telegram.ts +25 -0
- package/inkos/packages/core/src/notify/webhook.ts +58 -0
- package/inkos/packages/core/src/notify/wechat-work.ts +22 -0
- package/inkos/packages/core/src/pipeline/agent.ts +691 -0
- package/inkos/packages/core/src/pipeline/chapter-persistence.ts +79 -0
- package/inkos/packages/core/src/pipeline/chapter-review-cycle.ts +324 -0
- package/inkos/packages/core/src/pipeline/chapter-state-recovery.ts +236 -0
- package/inkos/packages/core/src/pipeline/chapter-truth-validation.ts +145 -0
- package/inkos/packages/core/src/pipeline/detection-runner.ts +164 -0
- package/inkos/packages/core/src/pipeline/persisted-governed-plan.ts +216 -0
- package/inkos/packages/core/src/pipeline/runner.ts +3438 -0
- package/inkos/packages/core/src/pipeline/scheduler.ts +411 -0
- package/inkos/packages/core/src/pipeline/short-fiction-runner.ts +801 -0
- package/inkos/packages/core/src/prompts/index.ts +1 -0
- package/inkos/packages/core/src/prompts/short-fiction.ts +273 -0
- package/inkos/packages/core/src/state/manager.ts +560 -0
- package/inkos/packages/core/src/state/memory-db.ts +359 -0
- package/inkos/packages/core/src/state/runtime-state-store.ts +164 -0
- package/inkos/packages/core/src/state/state-bootstrap.ts +657 -0
- package/inkos/packages/core/src/state/state-projections.ts +255 -0
- package/inkos/packages/core/src/state/state-reducer.ts +260 -0
- package/inkos/packages/core/src/state/state-validator.ts +117 -0
- package/inkos/packages/core/src/utils/analytics.ts +92 -0
- package/inkos/packages/core/src/utils/book-id.ts +31 -0
- package/inkos/packages/core/src/utils/cadence-policy.ts +46 -0
- package/inkos/packages/core/src/utils/chapter-cadence.ts +211 -0
- package/inkos/packages/core/src/utils/chapter-memo-parser.ts +157 -0
- package/inkos/packages/core/src/utils/chapter-splitter.ts +80 -0
- package/inkos/packages/core/src/utils/config-loader.ts +29 -0
- package/inkos/packages/core/src/utils/context-assembly.ts +98 -0
- package/inkos/packages/core/src/utils/context-filter.ts +190 -0
- package/inkos/packages/core/src/utils/effective-llm-config.ts +529 -0
- package/inkos/packages/core/src/utils/governed-context.ts +101 -0
- package/inkos/packages/core/src/utils/governed-working-set.ts +395 -0
- package/inkos/packages/core/src/utils/hook-arbiter.ts +332 -0
- package/inkos/packages/core/src/utils/hook-governance.ts +199 -0
- package/inkos/packages/core/src/utils/hook-health.ts +189 -0
- package/inkos/packages/core/src/utils/hook-ledger-validator.ts +277 -0
- package/inkos/packages/core/src/utils/hook-lifecycle.ts +224 -0
- package/inkos/packages/core/src/utils/hook-policy.ts +115 -0
- package/inkos/packages/core/src/utils/hook-promotion.ts +313 -0
- package/inkos/packages/core/src/utils/hook-stale-detection.ts +168 -0
- package/inkos/packages/core/src/utils/length-metrics.ts +123 -0
- package/inkos/packages/core/src/utils/llm-endpoint-auth.ts +40 -0
- package/inkos/packages/core/src/utils/llm-env.ts +74 -0
- package/inkos/packages/core/src/utils/logger.ts +123 -0
- package/inkos/packages/core/src/utils/long-span-fatigue.ts +545 -0
- package/inkos/packages/core/src/utils/memory-retrieval.ts +527 -0
- package/inkos/packages/core/src/utils/narrative-control.ts +177 -0
- package/inkos/packages/core/src/utils/outline-paths.ts +275 -0
- package/inkos/packages/core/src/utils/path-safety.ts +11 -0
- package/inkos/packages/core/src/utils/planning-materials.ts +185 -0
- package/inkos/packages/core/src/utils/pov-filter.ts +149 -0
- package/inkos/packages/core/src/utils/proxy-fetch.ts +44 -0
- package/inkos/packages/core/src/utils/runtime-writer.ts +41 -0
- package/inkos/packages/core/src/utils/spot-fix-patches.ts +189 -0
- package/inkos/packages/core/src/utils/story-markdown.ts +346 -0
- package/inkos/packages/core/src/utils/web-search.ts +82 -0
- package/inkos/packages/core/src/utils/writing-methodology.ts +164 -0
- package/inkos/packages/core/tsconfig.json +8 -0
- package/inkos/packages/core/vitest.config.ts +7 -0
- package/inkos/packages/studio/components.json +25 -0
- package/inkos/packages/studio/index.html +13 -0
- package/inkos/packages/studio/package.json +72 -0
- package/inkos/packages/studio/postcss.config.js +3 -0
- package/inkos/packages/studio/src/App.test.ts +25 -0
- package/inkos/packages/studio/src/App.tsx +280 -0
- package/inkos/packages/studio/src/api/__tests__/normalize-base-url.test.ts +40 -0
- package/inkos/packages/studio/src/api/book-create.test.ts +104 -0
- package/inkos/packages/studio/src/api/book-create.ts +94 -0
- package/inkos/packages/studio/src/api/errors.ts +17 -0
- package/inkos/packages/studio/src/api/index.ts +30 -0
- package/inkos/packages/studio/src/api/lib/run-store.ts +177 -0
- package/inkos/packages/studio/src/api/lib/sse.ts +50 -0
- package/inkos/packages/studio/src/api/phase5-hotfix.test.ts +335 -0
- package/inkos/packages/studio/src/api/safety.ts +6 -0
- package/inkos/packages/studio/src/api/server.test.ts +3162 -0
- package/inkos/packages/studio/src/api/server.ts +3666 -0
- package/inkos/packages/studio/src/api/v13-hotfix-round4.test.ts +226 -0
- package/inkos/packages/studio/src/app-state.test.ts +8 -0
- package/inkos/packages/studio/src/app-state.ts +1 -0
- package/inkos/packages/studio/src/components/ConfirmDialog.tsx +95 -0
- package/inkos/packages/studio/src/components/ServiceConfigSourceCard.tsx +139 -0
- package/inkos/packages/studio/src/components/ServiceQuickLinks.tsx +65 -0
- package/inkos/packages/studio/src/components/Sidebar.tsx +652 -0
- package/inkos/packages/studio/src/components/ai-elements/code-block.tsx +562 -0
- package/inkos/packages/studio/src/components/ai-elements/confirmation.tsx +174 -0
- package/inkos/packages/studio/src/components/ai-elements/message.tsx +360 -0
- package/inkos/packages/studio/src/components/ai-elements/prompt-input.tsx +1457 -0
- package/inkos/packages/studio/src/components/ai-elements/reasoning.tsx +226 -0
- package/inkos/packages/studio/src/components/ai-elements/shimmer.tsx +77 -0
- package/inkos/packages/studio/src/components/ai-elements/tool.tsx +173 -0
- package/inkos/packages/studio/src/components/chat/BookSidebar.tsx +291 -0
- package/inkos/packages/studio/src/components/chat/ChatMessage.tsx +39 -0
- package/inkos/packages/studio/src/components/chat/QuickActions.tsx +73 -0
- package/inkos/packages/studio/src/components/chat/ToolExecutionSteps.tsx +320 -0
- package/inkos/packages/studio/src/components/chat/__tests__/ToolExecutionSteps.test.ts +114 -0
- package/inkos/packages/studio/src/components/chat-utils.ts +56 -0
- package/inkos/packages/studio/src/components/chatbar-state.test.ts +69 -0
- package/inkos/packages/studio/src/components/sidebar/ChaptersSection.tsx +66 -0
- package/inkos/packages/studio/src/components/sidebar/CharacterSection.tsx +129 -0
- package/inkos/packages/studio/src/components/sidebar/FoundationSection.tsx +61 -0
- package/inkos/packages/studio/src/components/sidebar/ProgressSection.tsx +124 -0
- package/inkos/packages/studio/src/components/sidebar/SidebarCard.tsx +30 -0
- package/inkos/packages/studio/src/components/sidebar/SummarySection.tsx +89 -0
- package/inkos/packages/studio/src/components/ui/alert.tsx +76 -0
- package/inkos/packages/studio/src/components/ui/badge.tsx +52 -0
- package/inkos/packages/studio/src/components/ui/button-group.tsx +87 -0
- package/inkos/packages/studio/src/components/ui/button.tsx +58 -0
- package/inkos/packages/studio/src/components/ui/collapsible.tsx +19 -0
- package/inkos/packages/studio/src/components/ui/command.tsx +194 -0
- package/inkos/packages/studio/src/components/ui/dialog.tsx +158 -0
- package/inkos/packages/studio/src/components/ui/dropdown-menu.tsx +266 -0
- package/inkos/packages/studio/src/components/ui/hover-card.tsx +51 -0
- package/inkos/packages/studio/src/components/ui/input-group.tsx +158 -0
- package/inkos/packages/studio/src/components/ui/input.tsx +20 -0
- package/inkos/packages/studio/src/components/ui/select.tsx +199 -0
- package/inkos/packages/studio/src/components/ui/separator.tsx +23 -0
- package/inkos/packages/studio/src/components/ui/spinner.tsx +10 -0
- package/inkos/packages/studio/src/components/ui/textarea.tsx +18 -0
- package/inkos/packages/studio/src/components/ui/tooltip.tsx +66 -0
- package/inkos/packages/studio/src/constants/service-groups.ts +29 -0
- package/inkos/packages/studio/src/hooks/use-api.test.ts +93 -0
- package/inkos/packages/studio/src/hooks/use-api.ts +189 -0
- package/inkos/packages/studio/src/hooks/use-book-activity.test.ts +129 -0
- package/inkos/packages/studio/src/hooks/use-book-activity.ts +180 -0
- package/inkos/packages/studio/src/hooks/use-colors.ts +27 -0
- package/inkos/packages/studio/src/hooks/use-hash-route.test.ts +101 -0
- package/inkos/packages/studio/src/hooks/use-hash-route.ts +89 -0
- package/inkos/packages/studio/src/hooks/use-i18n.ts +289 -0
- package/inkos/packages/studio/src/hooks/use-session-events.ts +64 -0
- package/inkos/packages/studio/src/hooks/use-sse.test.ts +52 -0
- package/inkos/packages/studio/src/hooks/use-sse.ts +92 -0
- package/inkos/packages/studio/src/hooks/use-theme.test.ts +31 -0
- package/inkos/packages/studio/src/hooks/use-theme.ts +75 -0
- package/inkos/packages/studio/src/index.css +323 -0
- package/inkos/packages/studio/src/lib/error-copy.test.ts +34 -0
- package/inkos/packages/studio/src/lib/error-copy.ts +37 -0
- package/inkos/packages/studio/src/lib/utils.ts +6 -0
- package/inkos/packages/studio/src/main.tsx +10 -0
- package/inkos/packages/studio/src/pages/Analytics.tsx +80 -0
- package/inkos/packages/studio/src/pages/BookCreate.tsx +895 -0
- package/inkos/packages/studio/src/pages/BookDetail.tsx +652 -0
- package/inkos/packages/studio/src/pages/ChapterReader.tsx +266 -0
- package/inkos/packages/studio/src/pages/ChatPage.tsx +521 -0
- package/inkos/packages/studio/src/pages/DaemonControl.tsx +116 -0
- package/inkos/packages/studio/src/pages/Dashboard.tsx +379 -0
- package/inkos/packages/studio/src/pages/DoctorView.tsx +82 -0
- package/inkos/packages/studio/src/pages/GenreManager.tsx +464 -0
- package/inkos/packages/studio/src/pages/ImportManager.tsx +216 -0
- package/inkos/packages/studio/src/pages/LanguageSelector.tsx +74 -0
- package/inkos/packages/studio/src/pages/LogViewer.tsx +82 -0
- package/inkos/packages/studio/src/pages/RadarView.tsx +157 -0
- package/inkos/packages/studio/src/pages/ServiceDetailPage.tsx +393 -0
- package/inkos/packages/studio/src/pages/ServiceListPage.tsx +463 -0
- package/inkos/packages/studio/src/pages/StyleManager.tsx +225 -0
- package/inkos/packages/studio/src/pages/TruthFiles.tsx +194 -0
- package/inkos/packages/studio/src/pages/chat-page-state.test.ts +206 -0
- package/inkos/packages/studio/src/pages/chat-page-state.ts +112 -0
- package/inkos/packages/studio/src/pages/page-state.test.ts +258 -0
- package/inkos/packages/studio/src/pages/service-detail-state.test.ts +294 -0
- package/inkos/packages/studio/src/pages/service-detail-state.ts +234 -0
- package/inkos/packages/studio/src/pages/style-manager-state.test.ts +22 -0
- package/inkos/packages/studio/src/pages/truth-files-state.test.ts +61 -0
- package/inkos/packages/studio/src/shared/contracts.ts +143 -0
- package/inkos/packages/studio/src/store/chat/__tests__/message-parts.test.ts +172 -0
- package/inkos/packages/studio/src/store/chat/index.ts +3 -0
- package/inkos/packages/studio/src/store/chat/initialState.ts +8 -0
- package/inkos/packages/studio/src/store/chat/message-policy.test.ts +16 -0
- package/inkos/packages/studio/src/store/chat/message-policy.ts +5 -0
- package/inkos/packages/studio/src/store/chat/parts-builder.ts +187 -0
- package/inkos/packages/studio/src/store/chat/selectors.ts +13 -0
- package/inkos/packages/studio/src/store/chat/slices/create/action.ts +10 -0
- package/inkos/packages/studio/src/store/chat/slices/create/initialState.ts +9 -0
- package/inkos/packages/studio/src/store/chat/slices/message/action.ts +417 -0
- package/inkos/packages/studio/src/store/chat/slices/message/initialState.ts +10 -0
- package/inkos/packages/studio/src/store/chat/slices/message/runtime.test.ts +21 -0
- package/inkos/packages/studio/src/store/chat/slices/message/runtime.ts +233 -0
- package/inkos/packages/studio/src/store/chat/slices/message/stream-events.ts +272 -0
- package/inkos/packages/studio/src/store/chat/store.ts +11 -0
- package/inkos/packages/studio/src/store/chat/types.ts +169 -0
- package/inkos/packages/studio/src/store/service/index.ts +2 -0
- package/inkos/packages/studio/src/store/service/store.ts +123 -0
- package/inkos/packages/studio/src/store/service/types.ts +50 -0
- package/inkos/packages/studio/tsconfig.json +24 -0
- package/inkos/packages/studio/tsconfig.server.json +11 -0
- package/inkos/packages/studio/vite.config.ts +34 -0
- package/inkos/packages/studio/vitest.config.ts +14 -0
- package/inkos/pnpm-lock.yaml +9569 -0
- package/inkos/pnpm-workspace.yaml +2 -0
- package/inkos/scripts/prepare-package-for-publish.mjs +135 -0
- package/inkos/scripts/restore-package-json.mjs +31 -0
- package/inkos/scripts/set-package-versions.mjs +74 -0
- package/inkos/scripts/verify-no-workspace-protocol.mjs +140 -0
- package/inkos/skills/SKILL.md +654 -0
- package/inkos/tsconfig.json +19 -0
- package/package.json +4 -3
- /package/.next/static/{F2hMZMf1IyCVAWpkbtRz7 → -3vIrBZXdQ0rp7Wa3Kz40}/_buildManifest.js +0 -0
- /package/.next/static/{F2hMZMf1IyCVAWpkbtRz7 → -3vIrBZXdQ0rp7Wa3Kz40}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/* ── Auto-init & environment detection for TUI ── */
|
|
2
|
+
|
|
3
|
+
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { join, basename } from "node:path";
|
|
5
|
+
import readline from "node:readline/promises";
|
|
6
|
+
import {
|
|
7
|
+
c, bold, dim, italic,
|
|
8
|
+
cyan, green, yellow, gray, red,
|
|
9
|
+
brightCyan, brightGreen, brightWhite,
|
|
10
|
+
} from "./ansi.js";
|
|
11
|
+
import { resolveTuiLocale, type TuiLocale } from "./i18n.js";
|
|
12
|
+
import { GLOBAL_ENV_PATH, loadConfig } from "../utils.js";
|
|
13
|
+
import { ensureProjectGitignore } from "../project-bootstrap.js";
|
|
14
|
+
|
|
15
|
+
const PROVIDERS = ["openai", "anthropic", "kkaiapi", "custom"] as const;
|
|
16
|
+
const KKAIAPI_BASE_URL = "https://api.kkaiapi.com/v1";
|
|
17
|
+
type SetupProvider = typeof PROVIDERS[number];
|
|
18
|
+
type RuntimeProvider = "openai" | "anthropic" | "custom";
|
|
19
|
+
|
|
20
|
+
export function resolveSetupProvider(provider: string, baseUrl: string): RuntimeProvider {
|
|
21
|
+
const normalizedProvider = PROVIDERS.includes(provider.trim() as SetupProvider)
|
|
22
|
+
? provider.trim() as SetupProvider
|
|
23
|
+
: "openai";
|
|
24
|
+
const normalizedUrl = baseUrl.trim().toLowerCase();
|
|
25
|
+
if (normalizedUrl.includes("api.kimi.com/coding")) {
|
|
26
|
+
return "anthropic";
|
|
27
|
+
}
|
|
28
|
+
if (normalizedProvider === "anthropic" || normalizedProvider === "custom") {
|
|
29
|
+
return normalizedProvider;
|
|
30
|
+
}
|
|
31
|
+
return "openai";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function resolveSetupService(provider: string, baseUrl: string): string | undefined {
|
|
35
|
+
const normalizedProvider = provider.trim().toLowerCase();
|
|
36
|
+
const normalizedUrl = baseUrl.trim().toLowerCase();
|
|
37
|
+
if (normalizedProvider === "kkaiapi" || normalizedUrl.includes("api.kkaiapi.com")) {
|
|
38
|
+
return "kkaiapi";
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface SetupResult {
|
|
44
|
+
readonly projectRoot: string;
|
|
45
|
+
readonly hasLlmConfig: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface InteractiveSetupCopy {
|
|
49
|
+
readonly title: string;
|
|
50
|
+
readonly subtitle: string;
|
|
51
|
+
readonly steps: {
|
|
52
|
+
readonly provider: string;
|
|
53
|
+
readonly baseUrl: string;
|
|
54
|
+
readonly apiKey: string;
|
|
55
|
+
readonly model: string;
|
|
56
|
+
readonly scope: string;
|
|
57
|
+
};
|
|
58
|
+
readonly hints: {
|
|
59
|
+
readonly provider: string;
|
|
60
|
+
readonly baseUrl: string;
|
|
61
|
+
readonly apiKey: string;
|
|
62
|
+
readonly model: string;
|
|
63
|
+
readonly scope: string;
|
|
64
|
+
};
|
|
65
|
+
readonly defaults: {
|
|
66
|
+
readonly provider: string;
|
|
67
|
+
readonly baseUrl: string;
|
|
68
|
+
readonly scope: string;
|
|
69
|
+
};
|
|
70
|
+
readonly scopeChoices: {
|
|
71
|
+
readonly global: string;
|
|
72
|
+
readonly project: string;
|
|
73
|
+
};
|
|
74
|
+
readonly savedTo: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function buildInteractiveSetupCopy(locale: TuiLocale): InteractiveSetupCopy {
|
|
78
|
+
if (locale === "en") {
|
|
79
|
+
return {
|
|
80
|
+
title: "LLM Setup",
|
|
81
|
+
subtitle: "Configure your model provider to start writing.",
|
|
82
|
+
steps: {
|
|
83
|
+
provider: "Provider",
|
|
84
|
+
baseUrl: "Base URL",
|
|
85
|
+
apiKey: "API Key",
|
|
86
|
+
model: "Model",
|
|
87
|
+
scope: "Save scope",
|
|
88
|
+
},
|
|
89
|
+
hints: {
|
|
90
|
+
provider: "openai / anthropic / kkaiapi / custom (OpenAI-compatible proxy)",
|
|
91
|
+
baseUrl: "Your API endpoint",
|
|
92
|
+
apiKey: "Paste the API key for the selected provider.",
|
|
93
|
+
model: "e.g. gpt-4o, claude-sonnet-4-20250514, deepseek-chat",
|
|
94
|
+
scope: "global = all projects, project = this directory only",
|
|
95
|
+
},
|
|
96
|
+
defaults: {
|
|
97
|
+
provider: "openai",
|
|
98
|
+
baseUrl: "(default)",
|
|
99
|
+
scope: "[global]",
|
|
100
|
+
},
|
|
101
|
+
scopeChoices: {
|
|
102
|
+
global: "all projects",
|
|
103
|
+
project: "this directory",
|
|
104
|
+
},
|
|
105
|
+
savedTo: "Saved to",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
title: "模型配置",
|
|
111
|
+
subtitle: "配置模型服务后即可开始使用。",
|
|
112
|
+
steps: {
|
|
113
|
+
provider: "服务提供方",
|
|
114
|
+
baseUrl: "接口地址",
|
|
115
|
+
apiKey: "API 密钥",
|
|
116
|
+
model: "模型",
|
|
117
|
+
scope: "保存范围",
|
|
118
|
+
},
|
|
119
|
+
hints: {
|
|
120
|
+
provider: "openai / anthropic / kkaiapi / custom(兼容 OpenAI 的代理)",
|
|
121
|
+
baseUrl: "你的 API 入口地址",
|
|
122
|
+
apiKey: "粘贴所选服务商的 API Key",
|
|
123
|
+
model: "例如 gpt-5.4、claude-sonnet-4-20250514、deepseek-chat",
|
|
124
|
+
scope: "global = 所有项目,project = 仅当前目录",
|
|
125
|
+
},
|
|
126
|
+
defaults: {
|
|
127
|
+
provider: "openai",
|
|
128
|
+
baseUrl: "(默认)",
|
|
129
|
+
scope: "[global]",
|
|
130
|
+
},
|
|
131
|
+
scopeChoices: {
|
|
132
|
+
global: "所有项目",
|
|
133
|
+
project: "当前目录",
|
|
134
|
+
},
|
|
135
|
+
savedTo: "已保存到",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function buildAutoInitMessages(projectName: string, locale: TuiLocale): {
|
|
140
|
+
readonly initializing: string;
|
|
141
|
+
readonly initialized: string;
|
|
142
|
+
readonly envTemplateHeader: string;
|
|
143
|
+
} {
|
|
144
|
+
if (locale === "en") {
|
|
145
|
+
return {
|
|
146
|
+
initializing: `Initializing project in ${projectName}/ ...`,
|
|
147
|
+
initialized: "Project initialized",
|
|
148
|
+
envTemplateHeader: "# LLM Configuration — run inkos tui to configure interactively",
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
initializing: `正在初始化项目:${projectName}/ ...`,
|
|
154
|
+
initialized: "项目已初始化",
|
|
155
|
+
envTemplateHeader: "# LLM 配置 —— 运行 inkos tui 进行交互式配置",
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export async function ensureProject(cwd: string): Promise<SetupResult> {
|
|
160
|
+
const configPath = join(cwd, "inkos.json");
|
|
161
|
+
const hasConfig = await fileExists(configPath);
|
|
162
|
+
|
|
163
|
+
if (!hasConfig) {
|
|
164
|
+
await autoInit(cwd);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const hasLlm = await hasLlmConfig(cwd);
|
|
168
|
+
return { projectRoot: cwd, hasLlmConfig: hasLlm };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export async function interactiveLlmSetup(
|
|
172
|
+
projectRoot: string,
|
|
173
|
+
): Promise<void> {
|
|
174
|
+
const projectLanguage = await detectProjectLanguage(projectRoot);
|
|
175
|
+
const locale = resolveTuiLocale(process.env, projectLanguage);
|
|
176
|
+
const copy = buildInteractiveSetupCopy(locale);
|
|
177
|
+
const rl = readline.createInterface({
|
|
178
|
+
input: process.stdin,
|
|
179
|
+
output: process.stdout,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
console.log();
|
|
184
|
+
console.log(` ${c("◈", brightCyan)} ${c(copy.title, bold, brightWhite)}`);
|
|
185
|
+
console.log(c(` ${copy.subtitle}`, dim));
|
|
186
|
+
console.log();
|
|
187
|
+
|
|
188
|
+
// Provider
|
|
189
|
+
console.log(` ${c("1", cyan)} ${c(copy.steps.provider, gray)}`);
|
|
190
|
+
console.log(c(` ${copy.hints.provider}`, dim));
|
|
191
|
+
const providerInput = await rl.question(` ${c("❯", cyan)} `);
|
|
192
|
+
const provider = PROVIDERS.includes(providerInput.trim() as SetupProvider)
|
|
193
|
+
? providerInput.trim() as SetupProvider
|
|
194
|
+
: copy.defaults.provider as SetupProvider;
|
|
195
|
+
const providerDefaultBaseUrl = provider === "kkaiapi" ? KKAIAPI_BASE_URL : copy.defaults.baseUrl;
|
|
196
|
+
console.log(` ${c("✓", brightGreen)} ${provider}`);
|
|
197
|
+
console.log();
|
|
198
|
+
|
|
199
|
+
// Base URL
|
|
200
|
+
console.log(` ${c("2", cyan)} ${c(copy.steps.baseUrl, gray)}`);
|
|
201
|
+
console.log(c(` ${copy.hints.baseUrl}`, dim));
|
|
202
|
+
const baseUrl = await rl.question(` ${c("❯", cyan)} `);
|
|
203
|
+
console.log(` ${c("✓", brightGreen)} ${baseUrl.trim() || providerDefaultBaseUrl}`);
|
|
204
|
+
console.log();
|
|
205
|
+
|
|
206
|
+
// API Key
|
|
207
|
+
console.log(` ${c("3", cyan)} ${c(copy.steps.apiKey, gray)}`);
|
|
208
|
+
console.log(c(` ${copy.hints.apiKey}`, dim));
|
|
209
|
+
const apiKey = await rl.question(` ${c("❯", cyan)} `);
|
|
210
|
+
const maskedKey = apiKey.trim().length > 8
|
|
211
|
+
? apiKey.trim().slice(0, 4) + "···" + apiKey.trim().slice(-4)
|
|
212
|
+
: "···";
|
|
213
|
+
console.log(` ${c("✓", brightGreen)} ${maskedKey}`);
|
|
214
|
+
console.log();
|
|
215
|
+
|
|
216
|
+
// Model
|
|
217
|
+
console.log(` ${c("4", cyan)} ${c(copy.steps.model, gray)}`);
|
|
218
|
+
console.log(c(` ${copy.hints.model}`, dim));
|
|
219
|
+
const model = await rl.question(` ${c("❯", cyan)} `);
|
|
220
|
+
console.log(` ${c("✓", brightGreen)} ${model.trim()}`);
|
|
221
|
+
console.log();
|
|
222
|
+
|
|
223
|
+
// Scope
|
|
224
|
+
console.log(` ${c("5", cyan)} ${c(copy.steps.scope, gray)}`);
|
|
225
|
+
console.log(c(` ${copy.hints.scope}`, dim));
|
|
226
|
+
const scope = await rl.question(` ${c("❯", cyan)} ${c(copy.defaults.scope, dim)} `);
|
|
227
|
+
const useGlobal = scope.trim().toLowerCase() !== "project";
|
|
228
|
+
const effectiveBaseUrl = baseUrl.trim() || (provider === "kkaiapi" ? providerDefaultBaseUrl : "");
|
|
229
|
+
const finalProvider = resolveSetupProvider(provider, effectiveBaseUrl);
|
|
230
|
+
const finalService = resolveSetupService(provider, effectiveBaseUrl);
|
|
231
|
+
|
|
232
|
+
const envContent = [
|
|
233
|
+
`INKOS_LLM_PROVIDER=${finalProvider}`,
|
|
234
|
+
...(finalService ? [`INKOS_LLM_SERVICE=${finalService}`] : []),
|
|
235
|
+
`INKOS_LLM_BASE_URL=${effectiveBaseUrl}`,
|
|
236
|
+
`INKOS_LLM_API_KEY=${apiKey.trim()}`,
|
|
237
|
+
`INKOS_LLM_MODEL=${model.trim()}`,
|
|
238
|
+
].join("\n");
|
|
239
|
+
|
|
240
|
+
if (useGlobal) {
|
|
241
|
+
const globalDir = join(GLOBAL_ENV_PATH, "..");
|
|
242
|
+
await mkdir(globalDir, { recursive: true });
|
|
243
|
+
await writeFile(GLOBAL_ENV_PATH, envContent + "\n", "utf-8");
|
|
244
|
+
console.log();
|
|
245
|
+
console.log(` ${c("✓", brightGreen, bold)} ${c(copy.savedTo, dim)} ${c(GLOBAL_ENV_PATH, gray)}`);
|
|
246
|
+
} else {
|
|
247
|
+
await writeFile(join(projectRoot, ".env"), envContent + "\n", "utf-8");
|
|
248
|
+
console.log();
|
|
249
|
+
console.log(` ${c("✓", brightGreen, bold)} ${c(copy.savedTo, dim)} ${c(".env", gray)}`);
|
|
250
|
+
}
|
|
251
|
+
console.log();
|
|
252
|
+
} finally {
|
|
253
|
+
rl.close();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function autoInit(cwd: string): Promise<void> {
|
|
258
|
+
const projectName = basename(cwd);
|
|
259
|
+
const locale = resolveTuiLocale();
|
|
260
|
+
const messages = buildAutoInitMessages(projectName, locale);
|
|
261
|
+
console.log();
|
|
262
|
+
console.log(` ${c("◌", cyan)} ${c(messages.initializing, dim)}`);
|
|
263
|
+
|
|
264
|
+
await mkdir(join(cwd, "books"), { recursive: true });
|
|
265
|
+
await mkdir(join(cwd, "radar"), { recursive: true });
|
|
266
|
+
|
|
267
|
+
const config = {
|
|
268
|
+
name: projectName,
|
|
269
|
+
version: "0.1.0",
|
|
270
|
+
language: "zh",
|
|
271
|
+
llm: {
|
|
272
|
+
provider: process.env.INKOS_LLM_PROVIDER ?? "openai",
|
|
273
|
+
baseUrl: process.env.INKOS_LLM_BASE_URL ?? "",
|
|
274
|
+
model: process.env.INKOS_LLM_MODEL ?? "",
|
|
275
|
+
},
|
|
276
|
+
notify: [],
|
|
277
|
+
daemon: {
|
|
278
|
+
schedule: {
|
|
279
|
+
radarCron: "0 */6 * * *",
|
|
280
|
+
writeCron: "*/15 * * * *",
|
|
281
|
+
},
|
|
282
|
+
maxConcurrentBooks: 3,
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
await writeFile(
|
|
287
|
+
join(cwd, "inkos.json"),
|
|
288
|
+
JSON.stringify(config, null, 2),
|
|
289
|
+
"utf-8",
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
const hasGlobal = await hasGlobalConfig();
|
|
293
|
+
if (!hasGlobal) {
|
|
294
|
+
await writeFile(
|
|
295
|
+
join(cwd, ".env"),
|
|
296
|
+
[
|
|
297
|
+
messages.envTemplateHeader,
|
|
298
|
+
"INKOS_LLM_PROVIDER=openai",
|
|
299
|
+
"INKOS_LLM_BASE_URL=",
|
|
300
|
+
"INKOS_LLM_API_KEY=",
|
|
301
|
+
"INKOS_LLM_MODEL=",
|
|
302
|
+
].join("\n"),
|
|
303
|
+
"utf-8",
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
await ensureProjectGitignore(cwd);
|
|
308
|
+
|
|
309
|
+
console.log(` ${c("✓", brightGreen, bold)} ${c(messages.initialized, dim)}`);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async function hasLlmConfig(projectRoot: string): Promise<boolean> {
|
|
313
|
+
const projectEnv = join(projectRoot, ".env");
|
|
314
|
+
if (await checkEnvForKey(projectEnv)) return true;
|
|
315
|
+
return checkEnvForKey(GLOBAL_ENV_PATH);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
async function hasGlobalConfig(): Promise<boolean> {
|
|
319
|
+
return checkEnvForKey(GLOBAL_ENV_PATH);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async function checkEnvForKey(envPath: string): Promise<boolean> {
|
|
323
|
+
try {
|
|
324
|
+
const content = await readFile(envPath, "utf-8");
|
|
325
|
+
const match = content.match(/INKOS_LLM_API_KEY=(.+)/);
|
|
326
|
+
return !!match && match[1]!.trim().length > 0 && !match[1]!.includes("your-api-key");
|
|
327
|
+
} catch {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export interface ModelInfo {
|
|
333
|
+
readonly provider: string;
|
|
334
|
+
readonly model: string;
|
|
335
|
+
readonly baseUrl: string;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export async function detectModelInfo(projectRoot: string): Promise<ModelInfo | undefined> {
|
|
339
|
+
try {
|
|
340
|
+
const config = await loadConfig({ requireApiKey: false, projectRoot });
|
|
341
|
+
const service = config.llm.service?.trim();
|
|
342
|
+
const provider = service || config.llm.provider || "openai";
|
|
343
|
+
const model = config.llm.model?.trim() || "unknown";
|
|
344
|
+
return {
|
|
345
|
+
provider,
|
|
346
|
+
model,
|
|
347
|
+
baseUrl: config.llm.baseUrl ?? "",
|
|
348
|
+
};
|
|
349
|
+
} catch {
|
|
350
|
+
// Fall back to legacy env parsing below.
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const paths = [join(projectRoot, ".env"), GLOBAL_ENV_PATH];
|
|
354
|
+
for (const p of paths) {
|
|
355
|
+
const info = await parseEnvModel(p);
|
|
356
|
+
if (info) return info;
|
|
357
|
+
}
|
|
358
|
+
return undefined;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export async function detectProjectLanguage(projectRoot: string): Promise<string | undefined> {
|
|
362
|
+
try {
|
|
363
|
+
const raw = await readFile(join(projectRoot, "inkos.json"), "utf-8");
|
|
364
|
+
const parsed = JSON.parse(raw) as { language?: string };
|
|
365
|
+
return parsed.language;
|
|
366
|
+
} catch {
|
|
367
|
+
return undefined;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async function parseEnvModel(envPath: string): Promise<ModelInfo | undefined> {
|
|
372
|
+
try {
|
|
373
|
+
const content = await readFile(envPath, "utf-8");
|
|
374
|
+
const get = (key: string) => {
|
|
375
|
+
const m = content.match(new RegExp(`^${key}=(.+)$`, "m"));
|
|
376
|
+
return m?.[1]?.trim() ?? "";
|
|
377
|
+
};
|
|
378
|
+
const key = get("INKOS_LLM_API_KEY");
|
|
379
|
+
if (!key || key.includes("your-api-key")) return undefined;
|
|
380
|
+
return {
|
|
381
|
+
provider: get("INKOS_LLM_PROVIDER") || "openai",
|
|
382
|
+
model: get("INKOS_LLM_MODEL") || "unknown",
|
|
383
|
+
baseUrl: get("INKOS_LLM_BASE_URL") || "",
|
|
384
|
+
};
|
|
385
|
+
} catch {
|
|
386
|
+
return undefined;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
async function fileExists(path: string): Promise<boolean> {
|
|
391
|
+
try {
|
|
392
|
+
await access(path);
|
|
393
|
+
return true;
|
|
394
|
+
} catch {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export const SLASH_COMMANDS = [
|
|
2
|
+
"/new 输入你的想法",
|
|
3
|
+
"/write",
|
|
4
|
+
"/books",
|
|
5
|
+
"/rewrite <n>",
|
|
6
|
+
"/focus <text>",
|
|
7
|
+
"/truth <file> <content>",
|
|
8
|
+
"/rename <from> => <to>",
|
|
9
|
+
"/replace <n> <from> => <to>",
|
|
10
|
+
"/export [txt|md|epub]",
|
|
11
|
+
"/help",
|
|
12
|
+
"/status",
|
|
13
|
+
"/clear",
|
|
14
|
+
"/depth <light|normal|deep>",
|
|
15
|
+
"/quit",
|
|
16
|
+
"/exit",
|
|
17
|
+
] as const;
|
|
18
|
+
|
|
19
|
+
export type SlashNavigationDirection = "up" | "down";
|
|
20
|
+
|
|
21
|
+
export function getSlashSuggestions(input: string, commands: readonly string[]): string[] {
|
|
22
|
+
const value = input.trim();
|
|
23
|
+
if (!value.startsWith("/")) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return commands.filter((command) => slashCommandStem(command).startsWith(value));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getNextSlashSelection(
|
|
31
|
+
currentIndex: number,
|
|
32
|
+
suggestionCount: number,
|
|
33
|
+
direction: SlashNavigationDirection,
|
|
34
|
+
): number {
|
|
35
|
+
if (suggestionCount <= 0) {
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (direction === "down") {
|
|
40
|
+
return (currentIndex + 1) % suggestionCount;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (currentIndex - 1 + suggestionCount) % suggestionCount;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function applySlashSuggestion(
|
|
47
|
+
_input: string,
|
|
48
|
+
suggestions: readonly string[],
|
|
49
|
+
selectedIndex: number,
|
|
50
|
+
): string {
|
|
51
|
+
const suggestion = suggestions[selectedIndex] ?? "";
|
|
52
|
+
return slashSuggestionInsertion(suggestion);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function slashCommandStem(command: string): string {
|
|
56
|
+
return command.match(/^\/\S+/)?.[0] ?? command;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function slashSuggestionInsertion(suggestion: string): string {
|
|
60
|
+
const stem = slashCommandStem(suggestion);
|
|
61
|
+
return suggestion === stem ? stem : `${stem} `;
|
|
62
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Whether the terminal is macOS Terminal.app. */
|
|
2
|
+
export const isAppleTerminal = process.env.TERM_PROGRAM === "Apple_Terminal";
|
|
3
|
+
|
|
4
|
+
export const WARM_ACCENT = "#c88a56";
|
|
5
|
+
export const WARM_MUTED = "#8f8374";
|
|
6
|
+
export const WARM_REPLY = "#f0e6d8";
|
|
7
|
+
export const WARM_BORDER = "#6b6156";
|
|
8
|
+
|
|
9
|
+
// Semantic status colors
|
|
10
|
+
export const STATUS_SUCCESS = "#7ec87e";
|
|
11
|
+
export const STATUS_ERROR = "#e06060";
|
|
12
|
+
export const STATUS_ACTIVE = "#d4a76a";
|
|
13
|
+
export const STATUS_IDLE = "#7a7268";
|
|
14
|
+
|
|
15
|
+
// Role colors
|
|
16
|
+
export const ROLE_USER = "#a8c4d4";
|
|
17
|
+
export const ROLE_SYSTEM = "#b8a8d0";
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { readFile, stat } from "node:fs/promises";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { createLLMClient, StateManager, createLogger, createStderrSink, createJsonLineSink, resolveEffectiveLLMConfig, loadLLMEnvLayers, GLOBAL_CONFIG_DIR, GLOBAL_ENV_PATH, type EffectiveLLMConfigResult, type LLMConfigCliOverrides, type ProjectConfig, type PipelineConfig, type LogSink } from "@actalk/inkos-core";
|
|
4
|
+
import { formatSqliteMemorySupportWarning } from "./runtime-requirements.js";
|
|
5
|
+
|
|
6
|
+
export { GLOBAL_CONFIG_DIR, GLOBAL_ENV_PATH };
|
|
7
|
+
|
|
8
|
+
let sqliteMemorySupportWarned = false;
|
|
9
|
+
|
|
10
|
+
export async function resolveContext(opts: {
|
|
11
|
+
readonly context?: string;
|
|
12
|
+
readonly contextFile?: string;
|
|
13
|
+
}): Promise<string | undefined> {
|
|
14
|
+
if (opts.context) return opts.context;
|
|
15
|
+
if (opts.contextFile) {
|
|
16
|
+
return readFile(resolve(opts.contextFile), "utf-8");
|
|
17
|
+
}
|
|
18
|
+
if (process.env.INKOS_NO_STDIN === "true") {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
// Read from stdin if piped (non-TTY)
|
|
22
|
+
if (!process.stdin.isTTY) {
|
|
23
|
+
const chunks: Buffer[] = [];
|
|
24
|
+
for await (const chunk of process.stdin) {
|
|
25
|
+
chunks.push(chunk as Buffer);
|
|
26
|
+
}
|
|
27
|
+
const text = Buffer.concat(chunks).toString("utf-8").trim();
|
|
28
|
+
if (text.length > 0) return text;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function findProjectRoot(): string {
|
|
34
|
+
return process.cwd();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function loadConfig(options?: {
|
|
38
|
+
readonly requireApiKey?: boolean;
|
|
39
|
+
readonly projectRoot?: string;
|
|
40
|
+
readonly cli?: LLMConfigCliOverrides;
|
|
41
|
+
}): Promise<ProjectConfig> {
|
|
42
|
+
return (await loadConfigWithDiagnostics(options)).config;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function loadConfigWithDiagnostics(options?: {
|
|
46
|
+
readonly requireApiKey?: boolean;
|
|
47
|
+
readonly projectRoot?: string;
|
|
48
|
+
readonly cli?: LLMConfigCliOverrides;
|
|
49
|
+
}): Promise<EffectiveLLMConfigResult> {
|
|
50
|
+
const root = options?.projectRoot ?? findProjectRoot();
|
|
51
|
+
const cli = {
|
|
52
|
+
...parseLLMOverridesFromArgv(process.argv.slice(2)),
|
|
53
|
+
...options?.cli,
|
|
54
|
+
};
|
|
55
|
+
const envLayers = await loadLLMEnvLayers(root);
|
|
56
|
+
return resolveEffectiveLLMConfig({
|
|
57
|
+
consumer: "cli",
|
|
58
|
+
projectRoot: root,
|
|
59
|
+
envLayers,
|
|
60
|
+
cli,
|
|
61
|
+
requireApiKey: options?.requireApiKey,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createClient(config: ProjectConfig) {
|
|
66
|
+
return createLLMClient(config.llm);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function parseLLMOverridesFromArgv(argv: readonly string[]): LLMConfigCliOverrides {
|
|
70
|
+
const overrides: {
|
|
71
|
+
service?: string;
|
|
72
|
+
model?: string;
|
|
73
|
+
apiKeyEnv?: string;
|
|
74
|
+
baseUrl?: string;
|
|
75
|
+
apiFormat?: "chat" | "responses";
|
|
76
|
+
stream?: boolean;
|
|
77
|
+
} = {};
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < argv.length; i++) {
|
|
80
|
+
const arg = argv[i];
|
|
81
|
+
if (!arg) continue;
|
|
82
|
+
|
|
83
|
+
const [flag, inlineValue] = arg.split("=", 2) as [string, string | undefined];
|
|
84
|
+
const nextValue = () => inlineValue ?? argv[++i];
|
|
85
|
+
|
|
86
|
+
if (flag === "--service") {
|
|
87
|
+
const value = nextValue();
|
|
88
|
+
if (value) overrides.service = value;
|
|
89
|
+
} else if (flag === "--model") {
|
|
90
|
+
const value = nextValue();
|
|
91
|
+
if (value) overrides.model = value;
|
|
92
|
+
} else if (flag === "--api-key-env") {
|
|
93
|
+
const value = nextValue();
|
|
94
|
+
if (value) overrides.apiKeyEnv = value;
|
|
95
|
+
} else if (flag === "--base-url") {
|
|
96
|
+
const value = nextValue();
|
|
97
|
+
if (value) overrides.baseUrl = value;
|
|
98
|
+
} else if (flag === "--api-format") {
|
|
99
|
+
const value = nextValue();
|
|
100
|
+
if (value === "chat" || value === "responses") overrides.apiFormat = value;
|
|
101
|
+
} else if (flag === "--stream") {
|
|
102
|
+
overrides.stream = true;
|
|
103
|
+
} else if (flag === "--no-stream") {
|
|
104
|
+
overrides.stream = false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return overrides;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function buildPipelineConfig(
|
|
112
|
+
config: ProjectConfig,
|
|
113
|
+
root: string,
|
|
114
|
+
extra?: Partial<Pick<PipelineConfig, "notifyChannels" | "radarSources" | "externalContext" | "inputGovernanceMode">> & {
|
|
115
|
+
readonly quiet?: boolean;
|
|
116
|
+
readonly logFile?: NodeJS.WritableStream;
|
|
117
|
+
},
|
|
118
|
+
): PipelineConfig {
|
|
119
|
+
if (!extra?.quiet && !sqliteMemorySupportWarned) {
|
|
120
|
+
const warning = formatSqliteMemorySupportWarning();
|
|
121
|
+
if (warning) {
|
|
122
|
+
sqliteMemorySupportWarned = true;
|
|
123
|
+
process.stderr.write(`[WARN] ${warning}\n`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const sinks: LogSink[] = [];
|
|
128
|
+
if (!extra?.quiet) {
|
|
129
|
+
sinks.push(createStderrSink({ minLevel: "info" }));
|
|
130
|
+
}
|
|
131
|
+
if (extra?.logFile) {
|
|
132
|
+
sinks.push(createJsonLineSink(extra.logFile));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const hasLogging = sinks.length > 0;
|
|
136
|
+
const logger = hasLogging ? createLogger({ tag: "inkos", sinks }) : undefined;
|
|
137
|
+
|
|
138
|
+
const onStreamProgress = hasLogging
|
|
139
|
+
? (progress: { readonly elapsedMs: number; readonly totalChars: number; readonly chineseChars: number; readonly status: string }) => {
|
|
140
|
+
if (progress.status === "streaming") {
|
|
141
|
+
logger?.info(
|
|
142
|
+
`streaming ${Math.round(progress.elapsedMs / 1000)}s, ${progress.totalChars} chars (${progress.chineseChars} CJK)`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
: undefined;
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
client: createLLMClient(config.llm),
|
|
150
|
+
model: config.llm.model,
|
|
151
|
+
projectRoot: root,
|
|
152
|
+
defaultLLMConfig: config.llm,
|
|
153
|
+
foundationReviewRetries: config.foundation.reviewRetries,
|
|
154
|
+
writingReviewRetries: config.writing?.reviewRetries ?? 1,
|
|
155
|
+
modelOverrides: config.modelOverrides,
|
|
156
|
+
inputGovernanceMode: extra?.inputGovernanceMode ?? config.inputGovernanceMode,
|
|
157
|
+
notifyChannels: extra?.notifyChannels ?? config.notify,
|
|
158
|
+
radarSources: extra?.radarSources,
|
|
159
|
+
externalContext: extra?.externalContext,
|
|
160
|
+
logger,
|
|
161
|
+
onStreamProgress,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function log(message: string): void {
|
|
166
|
+
process.stdout.write(`${message}\n`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function logError(message: string): void {
|
|
170
|
+
process.stderr.write(`[ERROR] ${message}\n`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Resolve book-id: if provided use it, otherwise auto-detect when exactly one book exists.
|
|
175
|
+
* Validates that the book actually exists.
|
|
176
|
+
*/
|
|
177
|
+
export async function resolveBookId(
|
|
178
|
+
bookIdArg: string | undefined,
|
|
179
|
+
root: string,
|
|
180
|
+
): Promise<string> {
|
|
181
|
+
const state = new StateManager(root);
|
|
182
|
+
const books = await state.listBooks();
|
|
183
|
+
|
|
184
|
+
if (bookIdArg) {
|
|
185
|
+
if (!books.includes(bookIdArg)) {
|
|
186
|
+
const available = books.length > 0 ? books.join(", ") : "(none)";
|
|
187
|
+
throw new Error(
|
|
188
|
+
`Book "${bookIdArg}" not found. Available books: ${available}`,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
return bookIdArg;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (books.length === 0) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
"No books found. Create one first:\n inkos book create --title '...' --genre xuanhuan",
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
if (books.length === 1) {
|
|
200
|
+
return books[0]!;
|
|
201
|
+
}
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Multiple books found: ${books.join(", ")}\nPlease specify a book-id.`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export async function getLegacyMigrationHint(
|
|
208
|
+
root: string,
|
|
209
|
+
bookId: string,
|
|
210
|
+
): Promise<string | null> {
|
|
211
|
+
const state = new StateManager(root);
|
|
212
|
+
const stateDir = join(state.bookDir(bookId), "story", "state");
|
|
213
|
+
try {
|
|
214
|
+
const info = await stat(stateDir);
|
|
215
|
+
if (info.isDirectory()) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
} catch {
|
|
219
|
+
return `Book "${bookId}" uses legacy format (pre-v0.6). The next write will auto-migrate its state files.`;
|
|
220
|
+
}
|
|
221
|
+
return `Book "${bookId}" uses legacy format (pre-v0.6). The next write will auto-migrate its state files.`;
|
|
222
|
+
}
|