@cjhyy/code-shell-core 0.5.0-rc.0
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/LICENSE +21 -0
- package/README.md +162 -0
- package/dist/agent/coordinator.d.ts +49 -0
- package/dist/agent/coordinator.js +77 -0
- package/dist/arena/arena.d.ts +43 -0
- package/dist/arena/arena.js +334 -0
- package/dist/arena/context/context-tools.d.ts +16 -0
- package/dist/arena/context/context-tools.js +231 -0
- package/dist/arena/detect-mode.d.ts +20 -0
- package/dist/arena/detect-mode.js +78 -0
- package/dist/arena/digest-builder.d.ts +25 -0
- package/dist/arena/digest-builder.js +120 -0
- package/dist/arena/index.d.ts +29 -0
- package/dist/arena/index.js +29 -0
- package/dist/arena/iterate/convergence.d.ts +25 -0
- package/dist/arena/iterate/convergence.js +103 -0
- package/dist/arena/iterate/formats/index.d.ts +22 -0
- package/dist/arena/iterate/formats/index.js +283 -0
- package/dist/arena/iterate/index.d.ts +11 -0
- package/dist/arena/iterate/index.js +9 -0
- package/dist/arena/iterate/iterative-arena.d.ts +23 -0
- package/dist/arena/iterate/iterative-arena.js +237 -0
- package/dist/arena/iterate/parse.d.ts +42 -0
- package/dist/arena/iterate/parse.js +123 -0
- package/dist/arena/iterate/phases/argue.d.ts +22 -0
- package/dist/arena/iterate/phases/argue.js +159 -0
- package/dist/arena/iterate/phases/revise.d.ts +16 -0
- package/dist/arena/iterate/phases/revise.js +62 -0
- package/dist/arena/iterate/phases/tournament.d.ts +34 -0
- package/dist/arena/iterate/phases/tournament.js +113 -0
- package/dist/arena/iterate/tools/web-tools.d.ts +13 -0
- package/dist/arena/iterate/tools/web-tools.js +54 -0
- package/dist/arena/iterate/types.d.ts +152 -0
- package/dist/arena/iterate/types.js +8 -0
- package/dist/arena/ledger.d.ts +47 -0
- package/dist/arena/ledger.js +151 -0
- package/dist/arena/lenses/architecture.d.ts +5 -0
- package/dist/arena/lenses/architecture.js +22 -0
- package/dist/arena/lenses/engineering.d.ts +5 -0
- package/dist/arena/lenses/engineering.js +22 -0
- package/dist/arena/lenses/general.d.ts +5 -0
- package/dist/arena/lenses/general.js +20 -0
- package/dist/arena/lenses/index.d.ts +16 -0
- package/dist/arena/lenses/index.js +47 -0
- package/dist/arena/lenses/product.d.ts +5 -0
- package/dist/arena/lenses/product.js +22 -0
- package/dist/arena/model-presets.d.ts +23 -0
- package/dist/arena/model-presets.js +44 -0
- package/dist/arena/phases/adjudication.d.ts +24 -0
- package/dist/arena/phases/adjudication.js +144 -0
- package/dist/arena/phases/build-consensus.d.ts +29 -0
- package/dist/arena/phases/build-consensus.js +86 -0
- package/dist/arena/phases/claim-registry.d.ts +26 -0
- package/dist/arena/phases/claim-registry.js +60 -0
- package/dist/arena/phases/cross-review.d.ts +45 -0
- package/dist/arena/phases/cross-review.js +224 -0
- package/dist/arena/phases/debate-rounds.d.ts +27 -0
- package/dist/arena/phases/debate-rounds.js +162 -0
- package/dist/arena/phases/participant-research.d.ts +38 -0
- package/dist/arena/phases/participant-research.js +317 -0
- package/dist/arena/phases/planning-detail-expansion.d.ts +38 -0
- package/dist/arena/phases/planning-detail-expansion.js +121 -0
- package/dist/arena/planner.d.ts +27 -0
- package/dist/arena/planner.js +312 -0
- package/dist/arena/providers/docs.d.ts +6 -0
- package/dist/arena/providers/docs.js +108 -0
- package/dist/arena/providers/git.d.ts +8 -0
- package/dist/arena/providers/git.js +174 -0
- package/dist/arena/providers/index.d.ts +32 -0
- package/dist/arena/providers/index.js +132 -0
- package/dist/arena/providers/none.d.ts +7 -0
- package/dist/arena/providers/none.js +11 -0
- package/dist/arena/providers/repo.d.ts +6 -0
- package/dist/arena/providers/repo.js +255 -0
- package/dist/arena/render/session.d.ts +17 -0
- package/dist/arena/render/session.js +190 -0
- package/dist/arena/render/terminal.d.ts +34 -0
- package/dist/arena/render/terminal.js +286 -0
- package/dist/arena/strategies/discussion.d.ts +25 -0
- package/dist/arena/strategies/discussion.js +143 -0
- package/dist/arena/strategies/index.d.ts +15 -0
- package/dist/arena/strategies/index.js +28 -0
- package/dist/arena/strategies/language-wrapper.d.ts +17 -0
- package/dist/arena/strategies/language-wrapper.js +102 -0
- package/dist/arena/strategies/lens-wrapper.d.ts +16 -0
- package/dist/arena/strategies/lens-wrapper.js +236 -0
- package/dist/arena/strategies/planning.d.ts +30 -0
- package/dist/arena/strategies/planning.js +225 -0
- package/dist/arena/strategies/review.d.ts +26 -0
- package/dist/arena/strategies/review.js +168 -0
- package/dist/arena/strategies/utils.d.ts +39 -0
- package/dist/arena/strategies/utils.js +647 -0
- package/dist/arena/tools/selector.d.ts +17 -0
- package/dist/arena/tools/selector.js +61 -0
- package/dist/arena/transitions.d.ts +48 -0
- package/dist/arena/transitions.js +92 -0
- package/dist/arena/types.d.ts +508 -0
- package/dist/arena/types.js +27 -0
- package/dist/cli/agent-server-stdio.d.ts +32 -0
- package/dist/cli/agent-server-stdio.js +116 -0
- package/dist/colorizer.d.ts +23 -0
- package/dist/colorizer.js +12 -0
- package/dist/context/compaction.d.ts +116 -0
- package/dist/context/compaction.js +534 -0
- package/dist/context/manager.d.ts +145 -0
- package/dist/context/manager.js +423 -0
- package/dist/context/token-counter.d.ts +27 -0
- package/dist/context/token-counter.js +91 -0
- package/dist/context/tool-result-storage.d.ts +96 -0
- package/dist/context/tool-result-storage.js +296 -0
- package/dist/cost-tracker.d.ts +64 -0
- package/dist/cost-tracker.js +314 -0
- package/dist/cron/scheduler.d.ts +34 -0
- package/dist/cron/scheduler.js +115 -0
- package/dist/data/deepseek-models.json +46 -0
- package/dist/data/gemini-models.json +67 -0
- package/dist/data/openai-models.json +175 -0
- package/dist/data/openrouter-models.d.ts +35 -0
- package/dist/data/openrouter-models.js +36 -0
- package/dist/data/openrouter-models.json +4626 -0
- package/dist/data/openrouter-sync.d.ts +16 -0
- package/dist/data/openrouter-sync.js +53 -0
- package/dist/data/static-catalogs.d.ts +25 -0
- package/dist/data/static-catalogs.js +26 -0
- package/dist/data/zai-models.json +56 -0
- package/dist/engine/cost-store.d.ts +22 -0
- package/dist/engine/cost-store.js +15 -0
- package/dist/engine/engine.d.ts +295 -0
- package/dist/engine/engine.js +1467 -0
- package/dist/engine/model-facade.d.ts +24 -0
- package/dist/engine/model-facade.js +194 -0
- package/dist/engine/parse-task.d.ts +59 -0
- package/dist/engine/parse-task.js +135 -0
- package/dist/engine/patch-orphaned-tools.d.ts +52 -0
- package/dist/engine/patch-orphaned-tools.js +95 -0
- package/dist/engine/query.d.ts +50 -0
- package/dist/engine/query.js +107 -0
- package/dist/engine/runtime.d.ts +50 -0
- package/dist/engine/runtime.js +59 -0
- package/dist/engine/streaming-tool-queue.d.ts +34 -0
- package/dist/engine/streaming-tool-queue.js +61 -0
- package/dist/engine/token-budget.d.ts +22 -0
- package/dist/engine/token-budget.js +40 -0
- package/dist/engine/tool-summary.d.ts +13 -0
- package/dist/engine/tool-summary.js +35 -0
- package/dist/engine/turn-loop.d.ts +122 -0
- package/dist/engine/turn-loop.js +602 -0
- package/dist/engine/turn-state.d.ts +20 -0
- package/dist/engine/turn-state.js +17 -0
- package/dist/exceptions.d.ts +61 -0
- package/dist/exceptions.js +116 -0
- package/dist/git/utils.d.ts +35 -0
- package/dist/git/utils.js +98 -0
- package/dist/git/worktree.d.ts +36 -0
- package/dist/git/worktree.js +139 -0
- package/dist/hooks/events.d.ts +114 -0
- package/dist/hooks/events.js +4 -0
- package/dist/hooks/inject.d.ts +19 -0
- package/dist/hooks/inject.js +29 -0
- package/dist/hooks/registry.d.ts +15 -0
- package/dist/hooks/registry.js +84 -0
- package/dist/hooks/shell-runner.d.ts +45 -0
- package/dist/hooks/shell-runner.js +173 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +145 -0
- package/dist/llm/api-key-sanitize.d.ts +22 -0
- package/dist/llm/api-key-sanitize.js +81 -0
- package/dist/llm/capabilities/index.d.ts +20 -0
- package/dist/llm/capabilities/index.js +39 -0
- package/dist/llm/capabilities/rules.d.ts +26 -0
- package/dist/llm/capabilities/rules.js +215 -0
- package/dist/llm/capabilities/types.d.ts +114 -0
- package/dist/llm/capabilities/types.js +24 -0
- package/dist/llm/client-base.d.ts +29 -0
- package/dist/llm/client-base.js +137 -0
- package/dist/llm/client-factory.d.ts +10 -0
- package/dist/llm/client-factory.js +29 -0
- package/dist/llm/model-cache.d.ts +21 -0
- package/dist/llm/model-cache.js +46 -0
- package/dist/llm/model-fetcher.d.ts +29 -0
- package/dist/llm/model-fetcher.js +282 -0
- package/dist/llm/model-pool.d.ts +95 -0
- package/dist/llm/model-pool.js +246 -0
- package/dist/llm/provider-catalog.d.ts +32 -0
- package/dist/llm/provider-catalog.js +50 -0
- package/dist/llm/provider-kinds.d.ts +21 -0
- package/dist/llm/provider-kinds.js +132 -0
- package/dist/llm/providers/anthropic.d.ts +19 -0
- package/dist/llm/providers/anthropic.js +267 -0
- package/dist/llm/providers/openai.d.ts +64 -0
- package/dist/llm/providers/openai.js +606 -0
- package/dist/llm/retry.d.ts +12 -0
- package/dist/llm/retry.js +17 -0
- package/dist/llm/stream-watchdog.d.ts +42 -0
- package/dist/llm/stream-watchdog.js +70 -0
- package/dist/llm/token-counter.d.ts +17 -0
- package/dist/llm/token-counter.js +36 -0
- package/dist/llm/types.d.ts +37 -0
- package/dist/llm/types.js +4 -0
- package/dist/logging/logger.d.ts +109 -0
- package/dist/logging/logger.js +390 -0
- package/dist/logging/sanitize-messages.d.ts +42 -0
- package/dist/logging/sanitize-messages.js +150 -0
- package/dist/logging/session-recorder.d.ts +90 -0
- package/dist/logging/session-recorder.js +304 -0
- package/dist/lsp/client.d.ts +41 -0
- package/dist/lsp/client.js +166 -0
- package/dist/lsp/manager.d.ts +40 -0
- package/dist/lsp/manager.js +124 -0
- package/dist/lsp/servers.d.ts +16 -0
- package/dist/lsp/servers.js +60 -0
- package/dist/migrate-models.d.ts +45 -0
- package/dist/migrate-models.js +179 -0
- package/dist/onboarding.d.ts +189 -0
- package/dist/onboarding.js +625 -0
- package/dist/plugins/gitOps.d.ts +32 -0
- package/dist/plugins/gitOps.js +62 -0
- package/dist/plugins/installedPlugins.d.ts +15 -0
- package/dist/plugins/installedPlugins.js +56 -0
- package/dist/plugins/knownMarketplaces.d.ts +10 -0
- package/dist/plugins/knownMarketplaces.js +46 -0
- package/dist/plugins/loadPluginHooks.d.ts +52 -0
- package/dist/plugins/loadPluginHooks.js +162 -0
- package/dist/plugins/marketplaceManager.d.ts +49 -0
- package/dist/plugins/marketplaceManager.js +142 -0
- package/dist/plugins/parseMarketplaceInput.d.ts +16 -0
- package/dist/plugins/parseMarketplaceInput.js +73 -0
- package/dist/plugins/pluginCommandHook.d.ts +54 -0
- package/dist/plugins/pluginCommandHook.js +180 -0
- package/dist/plugins/pluginCommandsLoader.d.ts +25 -0
- package/dist/plugins/pluginCommandsLoader.js +114 -0
- package/dist/plugins/pluginInstaller.d.ts +36 -0
- package/dist/plugins/pluginInstaller.js +228 -0
- package/dist/plugins/schemas.d.ts +9 -0
- package/dist/plugins/schemas.js +136 -0
- package/dist/plugins/types.d.ts +75 -0
- package/dist/plugins/types.js +7 -0
- package/dist/plugins/varRewrite.d.ts +42 -0
- package/dist/plugins/varRewrite.js +129 -0
- package/dist/preset/index.d.ts +60 -0
- package/dist/preset/index.js +159 -0
- package/dist/product/define.d.ts +60 -0
- package/dist/product/define.js +123 -0
- package/dist/product/index.d.ts +5 -0
- package/dist/product/index.js +4 -0
- package/dist/product/types.d.ts +111 -0
- package/dist/product/types.js +21 -0
- package/dist/prompt/composer.d.ts +49 -0
- package/dist/prompt/composer.js +168 -0
- package/dist/prompt/instruction-scanner.d.ts +54 -0
- package/dist/prompt/instruction-scanner.js +187 -0
- package/dist/prompt/section-cache.d.ts +15 -0
- package/dist/prompt/section-cache.js +31 -0
- package/dist/prompt/section-loader.d.ts +26 -0
- package/dist/prompt/section-loader.js +53 -0
- package/dist/prompt/sections/base.md +35 -0
- package/dist/prompt/sections/coding.md +31 -0
- package/dist/prompt/sections/orchestration.md +16 -0
- package/dist/prompt/sections/tone.md +9 -0
- package/dist/protocol/chat-session-manager.d.ts +33 -0
- package/dist/protocol/chat-session-manager.js +65 -0
- package/dist/protocol/chat-session.d.ts +49 -0
- package/dist/protocol/chat-session.js +86 -0
- package/dist/protocol/client.d.ts +104 -0
- package/dist/protocol/client.js +260 -0
- package/dist/protocol/factories.d.ts +93 -0
- package/dist/protocol/factories.js +64 -0
- package/dist/protocol/helpers.d.ts +42 -0
- package/dist/protocol/helpers.js +55 -0
- package/dist/protocol/index.d.ts +4 -0
- package/dist/protocol/index.js +4 -0
- package/dist/protocol/server.d.ts +80 -0
- package/dist/protocol/server.js +855 -0
- package/dist/protocol/transport.d.ts +37 -0
- package/dist/protocol/transport.js +85 -0
- package/dist/protocol/types.d.ts +221 -0
- package/dist/protocol/types.js +61 -0
- package/dist/remote/bridge.d.ts +37 -0
- package/dist/remote/bridge.js +103 -0
- package/dist/run/ArtifactTracker.d.ts +38 -0
- package/dist/run/ArtifactTracker.js +132 -0
- package/dist/run/CheckpointWriter.d.ts +53 -0
- package/dist/run/CheckpointWriter.js +135 -0
- package/dist/run/EngineRunner.d.ts +72 -0
- package/dist/run/EngineRunner.js +119 -0
- package/dist/run/Evaluator.d.ts +56 -0
- package/dist/run/Evaluator.js +62 -0
- package/dist/run/FileRunStore.d.ts +39 -0
- package/dist/run/FileRunStore.js +176 -0
- package/dist/run/Heartbeat.d.ts +54 -0
- package/dist/run/Heartbeat.js +123 -0
- package/dist/run/RunApprovalBackend.d.ts +53 -0
- package/dist/run/RunApprovalBackend.js +85 -0
- package/dist/run/RunLock.d.ts +40 -0
- package/dist/run/RunLock.js +98 -0
- package/dist/run/RunManager.d.ts +82 -0
- package/dist/run/RunManager.js +587 -0
- package/dist/run/RunQueue.d.ts +27 -0
- package/dist/run/RunQueue.js +73 -0
- package/dist/run/RunStore.d.ts +25 -0
- package/dist/run/RunStore.js +9 -0
- package/dist/run/factory.d.ts +63 -0
- package/dist/run/factory.js +51 -0
- package/dist/run/index.d.ts +17 -0
- package/dist/run/index.js +23 -0
- package/dist/run/types.d.ts +136 -0
- package/dist/run/types.js +28 -0
- package/dist/runtime/safe-spawn.d.ts +118 -0
- package/dist/runtime/safe-spawn.js +268 -0
- package/dist/services/analytics.d.ts +29 -0
- package/dist/services/analytics.js +84 -0
- package/dist/services/auto-dream.d.ts +49 -0
- package/dist/services/auto-dream.js +124 -0
- package/dist/services/diagnostics.d.ts +41 -0
- package/dist/services/diagnostics.js +99 -0
- package/dist/services/extract-memories.d.ts +31 -0
- package/dist/services/extract-memories.js +71 -0
- package/dist/services/index.d.ts +11 -0
- package/dist/services/index.js +17 -0
- package/dist/services/memory-orchestrator.d.ts +60 -0
- package/dist/services/memory-orchestrator.js +133 -0
- package/dist/services/notifier.d.ts +25 -0
- package/dist/services/notifier.js +69 -0
- package/dist/services/oauth.d.ts +27 -0
- package/dist/services/oauth.js +153 -0
- package/dist/services/session-memory.d.ts +37 -0
- package/dist/services/session-memory.js +81 -0
- package/dist/session/file-history.d.ts +41 -0
- package/dist/session/file-history.js +115 -0
- package/dist/session/memory.d.ts +104 -0
- package/dist/session/memory.js +310 -0
- package/dist/session/session-manager.d.ts +41 -0
- package/dist/session/session-manager.js +261 -0
- package/dist/session/transcript.d.ts +39 -0
- package/dist/session/transcript.js +186 -0
- package/dist/settings/manager.d.ts +36 -0
- package/dist/settings/manager.js +187 -0
- package/dist/settings/schema.d.ts +1219 -0
- package/dist/settings/schema.js +246 -0
- package/dist/skills/frontmatter.d.ts +13 -0
- package/dist/skills/frontmatter.js +70 -0
- package/dist/skills/index.d.ts +7 -0
- package/dist/skills/index.js +6 -0
- package/dist/skills/scanner.d.ts +31 -0
- package/dist/skills/scanner.js +171 -0
- package/dist/state.d.ts +160 -0
- package/dist/state.js +267 -0
- package/dist/tool-system/builtin/agent-notifications.d.ts +84 -0
- package/dist/tool-system/builtin/agent-notifications.js +197 -0
- package/dist/tool-system/builtin/agent-registry.d.ts +67 -0
- package/dist/tool-system/builtin/agent-registry.js +126 -0
- package/dist/tool-system/builtin/agent-transcript-translator.d.ts +22 -0
- package/dist/tool-system/builtin/agent-transcript-translator.js +160 -0
- package/dist/tool-system/builtin/agent.d.ts +16 -0
- package/dist/tool-system/builtin/agent.js +364 -0
- package/dist/tool-system/builtin/apply-patch/applier.d.ts +26 -0
- package/dist/tool-system/builtin/apply-patch/applier.js +250 -0
- package/dist/tool-system/builtin/apply-patch/index.d.ts +20 -0
- package/dist/tool-system/builtin/apply-patch/index.js +101 -0
- package/dist/tool-system/builtin/apply-patch/parser.d.ts +17 -0
- package/dist/tool-system/builtin/apply-patch/parser.js +212 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +18 -0
- package/dist/tool-system/builtin/apply-patch/seek-sequence.js +123 -0
- package/dist/tool-system/builtin/apply-patch/types.d.ts +49 -0
- package/dist/tool-system/builtin/apply-patch/types.js +13 -0
- package/dist/tool-system/builtin/arena.d.ts +31 -0
- package/dist/tool-system/builtin/arena.js +416 -0
- package/dist/tool-system/builtin/ask-user.d.ts +20 -0
- package/dist/tool-system/builtin/ask-user.js +99 -0
- package/dist/tool-system/builtin/bash.d.ts +21 -0
- package/dist/tool-system/builtin/bash.js +149 -0
- package/dist/tool-system/builtin/brief.d.ts +6 -0
- package/dist/tool-system/builtin/brief.js +41 -0
- package/dist/tool-system/builtin/config.d.ts +6 -0
- package/dist/tool-system/builtin/config.js +67 -0
- package/dist/tool-system/builtin/cron.d.ts +10 -0
- package/dist/tool-system/builtin/cron.js +61 -0
- package/dist/tool-system/builtin/edit.d.ts +6 -0
- package/dist/tool-system/builtin/edit.js +100 -0
- package/dist/tool-system/builtin/file-cache.d.ts +11 -0
- package/dist/tool-system/builtin/file-cache.js +39 -0
- package/dist/tool-system/builtin/glob.d.ts +7 -0
- package/dist/tool-system/builtin/glob.js +76 -0
- package/dist/tool-system/builtin/grep.d.ts +7 -0
- package/dist/tool-system/builtin/grep.js +150 -0
- package/dist/tool-system/builtin/index.d.ts +20 -0
- package/dist/tool-system/builtin/index.js +449 -0
- package/dist/tool-system/builtin/lsp.d.ts +6 -0
- package/dist/tool-system/builtin/lsp.js +141 -0
- package/dist/tool-system/builtin/mcp-tools.d.ts +10 -0
- package/dist/tool-system/builtin/mcp-tools.js +102 -0
- package/dist/tool-system/builtin/memory.d.ts +26 -0
- package/dist/tool-system/builtin/memory.js +226 -0
- package/dist/tool-system/builtin/notebook-edit.d.ts +6 -0
- package/dist/tool-system/builtin/notebook-edit.js +124 -0
- package/dist/tool-system/builtin/plan.d.ts +15 -0
- package/dist/tool-system/builtin/plan.js +55 -0
- package/dist/tool-system/builtin/powershell.d.ts +11 -0
- package/dist/tool-system/builtin/powershell.js +64 -0
- package/dist/tool-system/builtin/read.d.ts +6 -0
- package/dist/tool-system/builtin/read.js +70 -0
- package/dist/tool-system/builtin/remote-trigger.d.ts +6 -0
- package/dist/tool-system/builtin/remote-trigger.js +54 -0
- package/dist/tool-system/builtin/repl.d.ts +11 -0
- package/dist/tool-system/builtin/repl.js +82 -0
- package/dist/tool-system/builtin/send-message.d.ts +6 -0
- package/dist/tool-system/builtin/send-message.js +47 -0
- package/dist/tool-system/builtin/skill-prompt.d.ts +20 -0
- package/dist/tool-system/builtin/skill-prompt.js +52 -0
- package/dist/tool-system/builtin/skill.d.ts +9 -0
- package/dist/tool-system/builtin/skill.js +55 -0
- package/dist/tool-system/builtin/sleep.d.ts +6 -0
- package/dist/tool-system/builtin/sleep.js +33 -0
- package/dist/tool-system/builtin/task.d.ts +48 -0
- package/dist/tool-system/builtin/task.js +139 -0
- package/dist/tool-system/builtin/tool-search.d.ts +11 -0
- package/dist/tool-system/builtin/tool-search.js +90 -0
- package/dist/tool-system/builtin/web-fetch.d.ts +10 -0
- package/dist/tool-system/builtin/web-fetch.js +328 -0
- package/dist/tool-system/builtin/web-search.d.ts +25 -0
- package/dist/tool-system/builtin/web-search.js +174 -0
- package/dist/tool-system/builtin/worktree.d.ts +10 -0
- package/dist/tool-system/builtin/worktree.js +95 -0
- package/dist/tool-system/builtin/write.d.ts +6 -0
- package/dist/tool-system/builtin/write.js +36 -0
- package/dist/tool-system/context.d.ts +165 -0
- package/dist/tool-system/context.js +18 -0
- package/dist/tool-system/executor.d.ts +49 -0
- package/dist/tool-system/executor.js +495 -0
- package/dist/tool-system/investigation-guard.d.ts +46 -0
- package/dist/tool-system/investigation-guard.js +155 -0
- package/dist/tool-system/mcp-manager.d.ts +67 -0
- package/dist/tool-system/mcp-manager.js +249 -0
- package/dist/tool-system/permission.d.ts +111 -0
- package/dist/tool-system/permission.js +774 -0
- package/dist/tool-system/registry.d.ts +32 -0
- package/dist/tool-system/registry.js +131 -0
- package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
- package/dist/tool-system/sandbox/bwrap.js +63 -0
- package/dist/tool-system/sandbox/index.d.ts +78 -0
- package/dist/tool-system/sandbox/index.js +222 -0
- package/dist/tool-system/sandbox/off.d.ts +2 -0
- package/dist/tool-system/sandbox/off.js +8 -0
- package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
- package/dist/tool-system/sandbox/seatbelt.js +109 -0
- package/dist/tool-system/task-guard.d.ts +29 -0
- package/dist/tool-system/task-guard.js +70 -0
- package/dist/tool-system/validation.d.ts +5 -0
- package/dist/tool-system/validation.js +39 -0
- package/dist/types.d.ts +376 -0
- package/dist/types.js +4 -0
- package/dist/updater.d.ts +65 -0
- package/dist/updater.js +405 -0
- package/dist/utils/debug.d.ts +41 -0
- package/dist/utils/debug.js +110 -0
- package/dist/utils/earlyInput.d.ts +43 -0
- package/dist/utils/earlyInput.js +166 -0
- package/dist/utils/env.d.ts +24 -0
- package/dist/utils/env.js +104 -0
- package/dist/utils/envUtils.d.ts +51 -0
- package/dist/utils/envUtils.js +135 -0
- package/dist/utils/execFileNoThrow.d.ts +39 -0
- package/dist/utils/execFileNoThrow.js +74 -0
- package/dist/utils/format.d.ts +44 -0
- package/dist/utils/format.js +236 -0
- package/dist/utils/intl.d.ts +22 -0
- package/dist/utils/intl.js +83 -0
- package/dist/utils/lockfile.d.ts +15 -0
- package/dist/utils/lockfile.js +30 -0
- package/dist/utils/memoize.d.ts +19 -0
- package/dist/utils/memoize.js +14 -0
- package/dist/utils/semver.d.ts +6 -0
- package/dist/utils/semver.js +13 -0
- package/dist/utils/sliceAnsi.d.ts +12 -0
- package/dist/utils/sliceAnsi.js +62 -0
- package/dist/utils/systemTheme.d.ts +40 -0
- package/dist/utils/systemTheme.js +108 -0
- package/dist/utils/task-sanitizer.d.ts +6 -0
- package/dist/utils/task-sanitizer.js +24 -0
- package/dist/utils/theme.d.ts +93 -0
- package/dist/utils/theme.js +544 -0
- package/dist/utils/toolDisplay.d.ts +31 -0
- package/dist/utils/toolDisplay.js +188 -0
- package/package.json +72 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract Memories service — extract durable memories from session transcripts.
|
|
3
|
+
*
|
|
4
|
+
* Runs at the end of a query loop to identify important information
|
|
5
|
+
* worth persisting across sessions.
|
|
6
|
+
*/
|
|
7
|
+
export interface ExtractedMemory {
|
|
8
|
+
type: "user" | "feedback" | "project" | "reference";
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
content: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build the prompt for extracting memories from a conversation.
|
|
15
|
+
*/
|
|
16
|
+
export declare function buildExtractionPrompt(transcript: Array<{
|
|
17
|
+
role: string;
|
|
18
|
+
content: string;
|
|
19
|
+
}>, existingMemories: Array<{
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
description: string;
|
|
23
|
+
}>): string;
|
|
24
|
+
/** Max memories to accept from a single extraction pass. Code-side cap that
|
|
25
|
+
* enforces the same limit the prompt asks for — the model occasionally
|
|
26
|
+
* ignores prompt rules, but this guarantees the cap. */
|
|
27
|
+
export declare const MAX_MEMORIES_PER_EXTRACTION = 2;
|
|
28
|
+
/**
|
|
29
|
+
* Parse extracted memories from LLM response.
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseExtractionResponse(response: string): ExtractedMemory[];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract Memories service — extract durable memories from session transcripts.
|
|
3
|
+
*
|
|
4
|
+
* Runs at the end of a query loop to identify important information
|
|
5
|
+
* worth persisting across sessions.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Build the prompt for extracting memories from a conversation.
|
|
9
|
+
*/
|
|
10
|
+
export function buildExtractionPrompt(transcript, existingMemories) {
|
|
11
|
+
const conversationText = transcript
|
|
12
|
+
.map((m) => `[${m.role}]: ${m.content.slice(0, 3000)}`)
|
|
13
|
+
.join("\n\n");
|
|
14
|
+
const existingList = existingMemories.length > 0
|
|
15
|
+
? existingMemories.map((m) => ` - [${m.type}] ${m.name}: ${m.description}`).join("\n")
|
|
16
|
+
: " (none)";
|
|
17
|
+
return `Analyze the following conversation and extract any information worth remembering for future sessions.
|
|
18
|
+
|
|
19
|
+
## Existing Memories
|
|
20
|
+
${existingList}
|
|
21
|
+
|
|
22
|
+
## Conversation
|
|
23
|
+
${conversationText.slice(0, 30000)}
|
|
24
|
+
|
|
25
|
+
## Instructions
|
|
26
|
+
Identify NEW information that should be saved as persistent memories. Categories:
|
|
27
|
+
- **user**: Information about the user's role, preferences, or expertise
|
|
28
|
+
- **feedback**: Guidance about how to approach work (corrections or confirmations)
|
|
29
|
+
- **project**: Non-obvious facts about ongoing work, goals, or decisions
|
|
30
|
+
- **reference**: Pointers to external resources or systems
|
|
31
|
+
|
|
32
|
+
Rules:
|
|
33
|
+
- Extract AT MOST 2 memories per session. Prefer 0 to a marginal one — most sessions are noise.
|
|
34
|
+
- Only extract information that would be useful in FUTURE conversations
|
|
35
|
+
- Do not duplicate existing memories (re-read the "Existing Memories" list above carefully)
|
|
36
|
+
- Do not extract code patterns, file structures, or git history (derivable from code)
|
|
37
|
+
- Do not extract ephemeral task details, progress snapshots, or in-flight work state — those belong in the conversation, not memory
|
|
38
|
+
- Do not extract one-off research products (news reports, AI industry summaries, slide deck content, daily progress dumps) — they're done and not "durable, reusable information"
|
|
39
|
+
- Each memory should have a clear, specific description
|
|
40
|
+
|
|
41
|
+
Respond with a JSON array of objects with fields: type, name, description, content
|
|
42
|
+
If nothing worth remembering, respond with an empty array: []`;
|
|
43
|
+
}
|
|
44
|
+
/** Max memories to accept from a single extraction pass. Code-side cap that
|
|
45
|
+
* enforces the same limit the prompt asks for — the model occasionally
|
|
46
|
+
* ignores prompt rules, but this guarantees the cap. */
|
|
47
|
+
export const MAX_MEMORIES_PER_EXTRACTION = 2;
|
|
48
|
+
/**
|
|
49
|
+
* Parse extracted memories from LLM response.
|
|
50
|
+
*/
|
|
51
|
+
export function parseExtractionResponse(response) {
|
|
52
|
+
try {
|
|
53
|
+
// Find JSON array in response
|
|
54
|
+
const jsonMatch = response.match(/\[[\s\S]*\]/);
|
|
55
|
+
if (!jsonMatch)
|
|
56
|
+
return [];
|
|
57
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
58
|
+
if (!Array.isArray(parsed))
|
|
59
|
+
return [];
|
|
60
|
+
const valid = parsed.filter((m) => typeof m === "object" &&
|
|
61
|
+
m !== null &&
|
|
62
|
+
typeof m.type === "string" &&
|
|
63
|
+
typeof m.name === "string" &&
|
|
64
|
+
typeof m.content === "string" &&
|
|
65
|
+
["user", "feedback", "project", "reference"].includes(m.type));
|
|
66
|
+
return valid.slice(0, MAX_MEMORIES_PER_EXTRACTION);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Services index — re-exports all service modules.
|
|
3
|
+
*/
|
|
4
|
+
export { analytics, trackEvent } from "./analytics.js";
|
|
5
|
+
export { authorize, refreshToken, type OAuthConfig, type OAuthTokens } from "./oauth.js";
|
|
6
|
+
export { notify, notifyComplete, notifyError } from "./notifier.js";
|
|
7
|
+
export { diagnostics } from "./diagnostics.js";
|
|
8
|
+
export { buildExtractionPrompt, parseExtractionResponse, type ExtractedMemory, } from "./extract-memories.js";
|
|
9
|
+
export { shouldAutoDream, recordSession, recordDreamComplete, buildDreamSystemPrompt, buildDreamUserPrompt, } from "./auto-dream.js";
|
|
10
|
+
export { saveSessionMemory, loadSessionMemory, listSessionMemories, searchSessionMemories, buildSessionMemoryPrompt, } from "./session-memory.js";
|
|
11
|
+
export { MemoryOrchestrator, type MemoryOrchestratorOptions, type MemoryOrchestratorResult, } from "./memory-orchestrator.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Services index — re-exports all service modules.
|
|
3
|
+
*/
|
|
4
|
+
export { analytics, trackEvent } from "./analytics.js";
|
|
5
|
+
// NOTE: ./compact.ts was a stand-alone stub that duplicated the real
|
|
6
|
+
// microcompact/autocompact logic now living in src/context/. It was never
|
|
7
|
+
// wired into Engine and shipped with incompatible semantics (a single
|
|
8
|
+
// `microCompact` that truncated long *messages* by char count, unrelated
|
|
9
|
+
// to the tool_result-based microcompact in ContextManager). Removed to end
|
|
10
|
+
// the "which microcompact?" ambiguity — the source of truth is ContextManager.
|
|
11
|
+
export { authorize, refreshToken } from "./oauth.js";
|
|
12
|
+
export { notify, notifyComplete, notifyError } from "./notifier.js";
|
|
13
|
+
export { diagnostics } from "./diagnostics.js";
|
|
14
|
+
export { buildExtractionPrompt, parseExtractionResponse, } from "./extract-memories.js";
|
|
15
|
+
export { shouldAutoDream, recordSession, recordDreamComplete, buildDreamSystemPrompt, buildDreamUserPrompt, } from "./auto-dream.js";
|
|
16
|
+
export { saveSessionMemory, loadSessionMemory, listSessionMemories, searchSessionMemories, buildSessionMemoryPrompt, } from "./session-memory.js";
|
|
17
|
+
export { MemoryOrchestrator, } from "./memory-orchestrator.js";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemoryOrchestrator — ties extract-memories, session-memory, and auto-dream
|
|
3
|
+
* into a single end-of-session pipeline.
|
|
4
|
+
*
|
|
5
|
+
* Called by Engine.run() after the turn loop completes. Runs memory extraction
|
|
6
|
+
* and session summarisation via lightweight LLM calls, then conditionally
|
|
7
|
+
* triggers auto-dream consolidation. None of this blocks the Engine result.
|
|
8
|
+
*
|
|
9
|
+
* Dream uses a tool-call loop (not free-text JSON output) so the LLM can
|
|
10
|
+
* incrementally inspect and modify the dream-scope workspace via the same
|
|
11
|
+
* MemoryList/Read/Save/Delete tools the user-facing assistant has access to.
|
|
12
|
+
* The caller supplies `runDream`, which owns the LLM client and tool registry
|
|
13
|
+
* — orchestrator just decides WHEN to trigger.
|
|
14
|
+
*/
|
|
15
|
+
import { MemoryManager } from "../session/memory.js";
|
|
16
|
+
export interface MemoryOrchestratorOptions {
|
|
17
|
+
/** Lightweight LLM call — must be a non-streaming summarisation call. */
|
|
18
|
+
callLLM: (systemPrompt: string, userMsg: string) => Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Auto-dream consolidation driver. Called when the dream cadence is due
|
|
21
|
+
* (every N sessions, no more than once per 24h). Returns true if the dream
|
|
22
|
+
* actually executed (so the orchestrator can record the timestamp); false
|
|
23
|
+
* if the caller decided to skip (e.g. no memories to consolidate, headless
|
|
24
|
+
* mode without LLM client, etc.).
|
|
25
|
+
*
|
|
26
|
+
* Implementation lives in Engine because it needs the LLM client and the
|
|
27
|
+
* memory tool implementations — both of which are orchestrator-agnostic.
|
|
28
|
+
*/
|
|
29
|
+
runDream?: (input: {
|
|
30
|
+
systemPrompt: string;
|
|
31
|
+
userPrompt: string;
|
|
32
|
+
projectDir?: string;
|
|
33
|
+
}) => Promise<boolean>;
|
|
34
|
+
/** Project root; when set, memories are scoped per-project. */
|
|
35
|
+
projectDir?: string;
|
|
36
|
+
/** Optional pre-constructed MemoryManager (avoids re-creating for every call). */
|
|
37
|
+
memoryManager?: MemoryManager;
|
|
38
|
+
}
|
|
39
|
+
export interface MemoryOrchestratorResult {
|
|
40
|
+
/** Number of new memory entries extracted and saved. */
|
|
41
|
+
extracted: number;
|
|
42
|
+
/** Whether the auto-dream consolidation was triggered. */
|
|
43
|
+
dreamTriggered: boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare class MemoryOrchestrator {
|
|
46
|
+
private readonly options;
|
|
47
|
+
constructor(options: MemoryOrchestratorOptions);
|
|
48
|
+
/**
|
|
49
|
+
* Run the full end-of-session memory pipeline.
|
|
50
|
+
*
|
|
51
|
+
* 1. Extract durable memories from the transcript (extract-memories)
|
|
52
|
+
* 2. Summarise the session (session-memory)
|
|
53
|
+
* 3. Record a completed session for auto-dream tracking
|
|
54
|
+
* 4. Conditionally trigger auto-dream consolidation
|
|
55
|
+
*/
|
|
56
|
+
run(transcript: Array<{
|
|
57
|
+
role: string;
|
|
58
|
+
content: string;
|
|
59
|
+
}>, sessionId: string): Promise<MemoryOrchestratorResult>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemoryOrchestrator — ties extract-memories, session-memory, and auto-dream
|
|
3
|
+
* into a single end-of-session pipeline.
|
|
4
|
+
*
|
|
5
|
+
* Called by Engine.run() after the turn loop completes. Runs memory extraction
|
|
6
|
+
* and session summarisation via lightweight LLM calls, then conditionally
|
|
7
|
+
* triggers auto-dream consolidation. None of this blocks the Engine result.
|
|
8
|
+
*
|
|
9
|
+
* Dream uses a tool-call loop (not free-text JSON output) so the LLM can
|
|
10
|
+
* incrementally inspect and modify the dream-scope workspace via the same
|
|
11
|
+
* MemoryList/Read/Save/Delete tools the user-facing assistant has access to.
|
|
12
|
+
* The caller supplies `runDream`, which owns the LLM client and tool registry
|
|
13
|
+
* — orchestrator just decides WHEN to trigger.
|
|
14
|
+
*/
|
|
15
|
+
import { MemoryManager } from "../session/memory.js";
|
|
16
|
+
import { buildExtractionPrompt, parseExtractionResponse } from "./extract-memories.js";
|
|
17
|
+
import { saveSessionMemory, buildSessionMemoryPrompt } from "./session-memory.js";
|
|
18
|
+
import { shouldAutoDream, recordSession, recordDreamComplete, buildDreamSystemPrompt, buildDreamUserPrompt } from "./auto-dream.js";
|
|
19
|
+
import { logger } from "../logging/logger.js";
|
|
20
|
+
export class MemoryOrchestrator {
|
|
21
|
+
options;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run the full end-of-session memory pipeline.
|
|
27
|
+
*
|
|
28
|
+
* 1. Extract durable memories from the transcript (extract-memories)
|
|
29
|
+
* 2. Summarise the session (session-memory)
|
|
30
|
+
* 3. Record a completed session for auto-dream tracking
|
|
31
|
+
* 4. Conditionally trigger auto-dream consolidation
|
|
32
|
+
*/
|
|
33
|
+
async run(transcript, sessionId) {
|
|
34
|
+
const mm = this.options.memoryManager ?? new MemoryManager({ projectDir: this.options.projectDir });
|
|
35
|
+
const startTime = Date.now();
|
|
36
|
+
// --------------- 1. Extract durable memories ---------------
|
|
37
|
+
let extracted = 0;
|
|
38
|
+
try {
|
|
39
|
+
const existing = mm.loadAll();
|
|
40
|
+
const extractionPrompt = buildExtractionPrompt(transcript, existing);
|
|
41
|
+
const response = await this.options.callLLM("You are a memory extraction assistant. Extract only durable, reusable information worth carrying into future sessions.", extractionPrompt);
|
|
42
|
+
const entries = parseExtractionResponse(response);
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
mm.save({
|
|
45
|
+
type: entry.type,
|
|
46
|
+
name: entry.name,
|
|
47
|
+
description: entry.description,
|
|
48
|
+
content: entry.content,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
extracted = entries.length;
|
|
52
|
+
logger.info("memory.extraction_done", {
|
|
53
|
+
sessionId,
|
|
54
|
+
extracted,
|
|
55
|
+
elapsedMs: Date.now() - startTime,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
logger.warn("memory.extraction_failed", {
|
|
60
|
+
sessionId,
|
|
61
|
+
error: err.message,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// --------------- 2. Session summary ---------------
|
|
65
|
+
try {
|
|
66
|
+
// Only summarise sessions with enough content to be meaningful.
|
|
67
|
+
const messageCount = transcript.filter((m) => m.role !== "system").length;
|
|
68
|
+
if (messageCount >= 3) {
|
|
69
|
+
const smPrompt = buildSessionMemoryPrompt(transcript);
|
|
70
|
+
const smResponse = await this.options.callLLM("You are a session summariser. Output only valid JSON.", smPrompt);
|
|
71
|
+
const jsonMatch = smResponse.match(/\{[\s\S]*\}/);
|
|
72
|
+
if (jsonMatch) {
|
|
73
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
74
|
+
saveSessionMemory({
|
|
75
|
+
sessionId,
|
|
76
|
+
summary: String(parsed.summary ?? "").slice(0, 1000),
|
|
77
|
+
keyTopics: Array.isArray(parsed.keyTopics) ? parsed.keyTopics.slice(0, 20) : [],
|
|
78
|
+
decisions: Array.isArray(parsed.decisions) ? parsed.decisions.slice(0, 20) : [],
|
|
79
|
+
createdAt: new Date().toISOString(),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
logger.warn("memory.session_memory_failed", {
|
|
86
|
+
sessionId,
|
|
87
|
+
error: err.message,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// --------------- 3. Record session for auto-dream tracking ---------------
|
|
91
|
+
recordSession();
|
|
92
|
+
// --------------- 4. Auto-dream consolidation ---------------
|
|
93
|
+
// Drives a tool-call loop in the caller (Engine.runDream) so the LLM can
|
|
94
|
+
// list/read/save/delete dream-scope memories via the same Memory* tools
|
|
95
|
+
// the user-facing assistant uses. Skipped when:
|
|
96
|
+
// - the cadence isn't due yet (shouldAutoDream returns false)
|
|
97
|
+
// - the caller didn't wire a runDream driver (e.g. headless tests)
|
|
98
|
+
// - the workspace is empty (nothing to consolidate)
|
|
99
|
+
let dreamTriggered = false;
|
|
100
|
+
try {
|
|
101
|
+
if (shouldAutoDream() && this.options.runDream) {
|
|
102
|
+
// Dream sees BOTH scopes — user/ is read-only context so it can spot
|
|
103
|
+
// duplicates spanning scopes, dream/ is the workspace it edits.
|
|
104
|
+
const userMems = mm.loadScope("user");
|
|
105
|
+
const dreamMems = mm.loadScope("dream");
|
|
106
|
+
if (userMems.length + dreamMems.length > 0) {
|
|
107
|
+
const ran = await this.options.runDream({
|
|
108
|
+
systemPrompt: buildDreamSystemPrompt(),
|
|
109
|
+
userPrompt: buildDreamUserPrompt(userMems, dreamMems),
|
|
110
|
+
projectDir: this.options.projectDir,
|
|
111
|
+
});
|
|
112
|
+
if (ran) {
|
|
113
|
+
recordDreamComplete();
|
|
114
|
+
dreamTriggered = true;
|
|
115
|
+
logger.info("memory.auto_dream_done", {
|
|
116
|
+
sessionId,
|
|
117
|
+
userMemoryCount: userMems.length,
|
|
118
|
+
dreamMemoryCount: dreamMems.length,
|
|
119
|
+
elapsedMs: Date.now() - startTime,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
logger.warn("memory.auto_dream_failed", {
|
|
127
|
+
sessionId,
|
|
128
|
+
error: err.message,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return { extracted, dreamTriggered };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifier service — desktop/system notifications.
|
|
3
|
+
*
|
|
4
|
+
* Sends notifications when tasks complete, agents finish, or errors occur.
|
|
5
|
+
* Falls back gracefully when no notification system is available.
|
|
6
|
+
*/
|
|
7
|
+
export interface NotificationOptions {
|
|
8
|
+
title: string;
|
|
9
|
+
message: string;
|
|
10
|
+
sound?: boolean;
|
|
11
|
+
/** Urgency level: low, normal, critical */
|
|
12
|
+
urgency?: "low" | "normal" | "critical";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Send a desktop notification.
|
|
16
|
+
*/
|
|
17
|
+
export declare function notify(options: NotificationOptions): void;
|
|
18
|
+
/**
|
|
19
|
+
* Send a notification that a task/agent has completed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function notifyComplete(taskName: string, duration?: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Send an error notification.
|
|
24
|
+
*/
|
|
25
|
+
export declare function notifyError(context: string, error: string): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notifier service — desktop/system notifications.
|
|
3
|
+
*
|
|
4
|
+
* Sends notifications when tasks complete, agents finish, or errors occur.
|
|
5
|
+
* Falls back gracefully when no notification system is available.
|
|
6
|
+
*/
|
|
7
|
+
import { execSync } from "node:child_process";
|
|
8
|
+
/**
|
|
9
|
+
* Send a desktop notification.
|
|
10
|
+
*/
|
|
11
|
+
export function notify(options) {
|
|
12
|
+
const { title, message, sound = false, urgency = "normal" } = options;
|
|
13
|
+
try {
|
|
14
|
+
if (process.platform === "darwin") {
|
|
15
|
+
// macOS: osascript
|
|
16
|
+
const soundFlag = sound ? 'sound name "default"' : "";
|
|
17
|
+
execSync(`osascript -e 'display notification "${escape(message)}" with title "${escape(title)}" ${soundFlag}'`, { timeout: 5000 });
|
|
18
|
+
}
|
|
19
|
+
else if (process.platform === "linux") {
|
|
20
|
+
// Linux: notify-send
|
|
21
|
+
const urgencyFlag = urgency === "critical" ? "-u critical" : urgency === "low" ? "-u low" : "-u normal";
|
|
22
|
+
execSync(`notify-send ${urgencyFlag} "${escape(title)}" "${escape(message)}"`, {
|
|
23
|
+
timeout: 5000,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else if (process.platform === "win32") {
|
|
27
|
+
// Windows: PowerShell toast
|
|
28
|
+
const ps = `
|
|
29
|
+
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
|
|
30
|
+
$xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
|
|
31
|
+
$text = $xml.GetElementsByTagName('text')
|
|
32
|
+
$text[0].AppendChild($xml.CreateTextNode('${escape(title)}')) | Out-Null
|
|
33
|
+
$text[1].AppendChild($xml.CreateTextNode('${escape(message)}')) | Out-Null
|
|
34
|
+
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
|
|
35
|
+
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('CodeShell').Show($toast)
|
|
36
|
+
`.trim();
|
|
37
|
+
execSync(`powershell.exe -NoProfile -Command "${ps.replace(/\n/g, "; ")}"`, {
|
|
38
|
+
timeout: 5000,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Silently fail — notifications are best-effort
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Send a notification that a task/agent has completed.
|
|
48
|
+
*/
|
|
49
|
+
export function notifyComplete(taskName, duration) {
|
|
50
|
+
const durationStr = duration ? ` (${(duration / 1000).toFixed(1)}s)` : "";
|
|
51
|
+
notify({
|
|
52
|
+
title: "Code Shell",
|
|
53
|
+
message: `✓ ${taskName} completed${durationStr}`,
|
|
54
|
+
sound: true,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Send an error notification.
|
|
59
|
+
*/
|
|
60
|
+
export function notifyError(context, error) {
|
|
61
|
+
notify({
|
|
62
|
+
title: "Code Shell Error",
|
|
63
|
+
message: `✗ ${context}: ${error.slice(0, 100)}`,
|
|
64
|
+
urgency: "critical",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function escape(str) {
|
|
68
|
+
return str.replace(/['"\\]/g, "\\$&").replace(/\n/g, " ");
|
|
69
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth service — OAuth 2.0 authorization code flow with PKCE.
|
|
3
|
+
*
|
|
4
|
+
* Supports browser-based login flow for API authentication.
|
|
5
|
+
*/
|
|
6
|
+
export interface OAuthConfig {
|
|
7
|
+
clientId: string;
|
|
8
|
+
authorizationEndpoint: string;
|
|
9
|
+
tokenEndpoint: string;
|
|
10
|
+
redirectUri?: string;
|
|
11
|
+
scopes?: string[];
|
|
12
|
+
}
|
|
13
|
+
export interface OAuthTokens {
|
|
14
|
+
accessToken: string;
|
|
15
|
+
refreshToken?: string;
|
|
16
|
+
expiresAt?: number;
|
|
17
|
+
tokenType: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Run the OAuth authorization code flow.
|
|
21
|
+
* Opens a browser for user login and waits for the callback.
|
|
22
|
+
*/
|
|
23
|
+
export declare function authorize(config: OAuthConfig): Promise<OAuthTokens>;
|
|
24
|
+
/**
|
|
25
|
+
* Refresh an access token using a refresh token.
|
|
26
|
+
*/
|
|
27
|
+
export declare function refreshToken(config: OAuthConfig, refreshTokenValue: string): Promise<OAuthTokens>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth service — OAuth 2.0 authorization code flow with PKCE.
|
|
3
|
+
*
|
|
4
|
+
* Supports browser-based login flow for API authentication.
|
|
5
|
+
*/
|
|
6
|
+
import { createServer } from "node:http";
|
|
7
|
+
import { randomBytes, createHash } from "node:crypto";
|
|
8
|
+
import { exec } from "node:child_process";
|
|
9
|
+
/**
|
|
10
|
+
* Generate PKCE code verifier and challenge.
|
|
11
|
+
*/
|
|
12
|
+
function generatePKCE() {
|
|
13
|
+
const verifier = randomBytes(32).toString("base64url");
|
|
14
|
+
const challenge = createHash("sha256").update(verifier).digest("base64url");
|
|
15
|
+
return { verifier, challenge };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Open a URL in the system browser.
|
|
19
|
+
*/
|
|
20
|
+
function openBrowser(url) {
|
|
21
|
+
const cmd = process.platform === "darwin"
|
|
22
|
+
? `open "${url}"`
|
|
23
|
+
: process.platform === "win32"
|
|
24
|
+
? `start "${url}"`
|
|
25
|
+
: `xdg-open "${url}"`;
|
|
26
|
+
exec(cmd, () => { });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Run the OAuth authorization code flow.
|
|
30
|
+
* Opens a browser for user login and waits for the callback.
|
|
31
|
+
*/
|
|
32
|
+
export async function authorize(config) {
|
|
33
|
+
const { verifier, challenge } = generatePKCE();
|
|
34
|
+
const state = randomBytes(16).toString("hex");
|
|
35
|
+
const port = 18910 + Math.floor(Math.random() * 100);
|
|
36
|
+
const redirectUri = config.redirectUri ?? `http://localhost:${port}/callback`;
|
|
37
|
+
// Build authorization URL
|
|
38
|
+
const params = new URLSearchParams({
|
|
39
|
+
response_type: "code",
|
|
40
|
+
client_id: config.clientId,
|
|
41
|
+
redirect_uri: redirectUri,
|
|
42
|
+
state,
|
|
43
|
+
code_challenge: challenge,
|
|
44
|
+
code_challenge_method: "S256",
|
|
45
|
+
});
|
|
46
|
+
if (config.scopes?.length) {
|
|
47
|
+
params.set("scope", config.scopes.join(" "));
|
|
48
|
+
}
|
|
49
|
+
const authUrl = `${config.authorizationEndpoint}?${params.toString()}`;
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const timeout = setTimeout(() => {
|
|
52
|
+
server.close();
|
|
53
|
+
reject(new Error("OAuth authorization timed out (120s)"));
|
|
54
|
+
}, 120_000);
|
|
55
|
+
const server = createServer(async (req, res) => {
|
|
56
|
+
if (!req.url?.startsWith("/callback")) {
|
|
57
|
+
res.writeHead(404);
|
|
58
|
+
res.end("Not found");
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const url = new URL(req.url, `http://localhost:${port}`);
|
|
62
|
+
const code = url.searchParams.get("code");
|
|
63
|
+
const returnedState = url.searchParams.get("state");
|
|
64
|
+
const error = url.searchParams.get("error");
|
|
65
|
+
clearTimeout(timeout);
|
|
66
|
+
if (error) {
|
|
67
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
68
|
+
res.end("<html><body><h1>Authorization failed</h1><p>You can close this window.</p></body></html>");
|
|
69
|
+
server.close();
|
|
70
|
+
reject(new Error(`OAuth error: ${error}`));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!code || returnedState !== state) {
|
|
74
|
+
res.writeHead(400, { "Content-Type": "text/html" });
|
|
75
|
+
res.end("<html><body><h1>Invalid callback</h1></body></html>");
|
|
76
|
+
server.close();
|
|
77
|
+
reject(new Error("Invalid OAuth callback: missing code or state mismatch"));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// Exchange code for tokens
|
|
81
|
+
try {
|
|
82
|
+
const tokenParams = new URLSearchParams({
|
|
83
|
+
grant_type: "authorization_code",
|
|
84
|
+
code,
|
|
85
|
+
redirect_uri: redirectUri,
|
|
86
|
+
client_id: config.clientId,
|
|
87
|
+
code_verifier: verifier,
|
|
88
|
+
});
|
|
89
|
+
const tokenRes = await fetch(config.tokenEndpoint, {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
92
|
+
body: tokenParams.toString(),
|
|
93
|
+
});
|
|
94
|
+
if (!tokenRes.ok) {
|
|
95
|
+
throw new Error(`Token exchange failed: ${tokenRes.status} ${await tokenRes.text()}`);
|
|
96
|
+
}
|
|
97
|
+
const data = (await tokenRes.json());
|
|
98
|
+
const tokens = {
|
|
99
|
+
accessToken: data.access_token,
|
|
100
|
+
refreshToken: data.refresh_token,
|
|
101
|
+
expiresAt: data.expires_in
|
|
102
|
+
? Date.now() + data.expires_in * 1000
|
|
103
|
+
: undefined,
|
|
104
|
+
tokenType: data.token_type ?? "Bearer",
|
|
105
|
+
};
|
|
106
|
+
res.writeHead(200, { "Content-Type": "text/html" });
|
|
107
|
+
res.end("<html><body><h1>Authorization successful!</h1><p>You can close this window.</p></body></html>");
|
|
108
|
+
server.close();
|
|
109
|
+
resolve(tokens);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
res.writeHead(500, { "Content-Type": "text/html" });
|
|
113
|
+
res.end("<html><body><h1>Token exchange failed</h1></body></html>");
|
|
114
|
+
server.close();
|
|
115
|
+
reject(err);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
server.listen(port, () => {
|
|
119
|
+
openBrowser(authUrl);
|
|
120
|
+
});
|
|
121
|
+
server.on("error", (err) => {
|
|
122
|
+
clearTimeout(timeout);
|
|
123
|
+
reject(new Error(`OAuth server error: ${err.message}`));
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Refresh an access token using a refresh token.
|
|
129
|
+
*/
|
|
130
|
+
export async function refreshToken(config, refreshTokenValue) {
|
|
131
|
+
const params = new URLSearchParams({
|
|
132
|
+
grant_type: "refresh_token",
|
|
133
|
+
client_id: config.clientId,
|
|
134
|
+
refresh_token: refreshTokenValue,
|
|
135
|
+
});
|
|
136
|
+
const res = await fetch(config.tokenEndpoint, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
139
|
+
body: params.toString(),
|
|
140
|
+
});
|
|
141
|
+
if (!res.ok) {
|
|
142
|
+
throw new Error(`Token refresh failed: ${res.status}`);
|
|
143
|
+
}
|
|
144
|
+
const data = (await res.json());
|
|
145
|
+
return {
|
|
146
|
+
accessToken: data.access_token,
|
|
147
|
+
refreshToken: data.refresh_token ?? refreshTokenValue,
|
|
148
|
+
expiresAt: data.expires_in
|
|
149
|
+
? Date.now() + data.expires_in * 1000
|
|
150
|
+
: undefined,
|
|
151
|
+
tokenType: data.token_type ?? "Bearer",
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Memory service — automatic session memory maintenance.
|
|
3
|
+
*
|
|
4
|
+
* Extracts and maintains conversation context as persistent memory
|
|
5
|
+
* entries that survive across sessions.
|
|
6
|
+
*/
|
|
7
|
+
export interface SessionMemoryEntry {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
summary: string;
|
|
10
|
+
keyTopics: string[];
|
|
11
|
+
decisions: string[];
|
|
12
|
+
createdAt: string;
|
|
13
|
+
tokenCount?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Save a session memory entry.
|
|
17
|
+
*/
|
|
18
|
+
export declare function saveSessionMemory(entry: SessionMemoryEntry): void;
|
|
19
|
+
/**
|
|
20
|
+
* Load a session memory by session ID.
|
|
21
|
+
*/
|
|
22
|
+
export declare function loadSessionMemory(sessionId: string): SessionMemoryEntry | null;
|
|
23
|
+
/**
|
|
24
|
+
* List all session memories, most recent first.
|
|
25
|
+
*/
|
|
26
|
+
export declare function listSessionMemories(limit?: number): SessionMemoryEntry[];
|
|
27
|
+
/**
|
|
28
|
+
* Search session memories by keyword.
|
|
29
|
+
*/
|
|
30
|
+
export declare function searchSessionMemories(query: string): SessionMemoryEntry[];
|
|
31
|
+
/**
|
|
32
|
+
* Build a prompt for extracting session memory from a conversation.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildSessionMemoryPrompt(messages: Array<{
|
|
35
|
+
role: string;
|
|
36
|
+
content: string;
|
|
37
|
+
}>): string;
|