@cjhyy/code-shell-core 0.7.1 → 0.8.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/README.md +36 -23
- package/dist/agent/agent-definition-registry.d.ts +2 -2
- package/dist/agent/agent-definition-registry.js +47 -10
- package/dist/agent/agent-definition.d.ts +5 -0
- package/dist/agent/agent-definition.js +14 -0
- package/dist/automation/index.d.ts +7 -4
- package/dist/automation/index.js +4 -2
- package/dist/automation/runner.js +3 -1
- package/dist/automation/scheduler.d.ts +57 -1
- package/dist/automation/scheduler.js +123 -23
- package/dist/automation/store.d.ts +6 -2
- package/dist/automation/store.js +7 -3
- package/dist/capabilities/index.d.ts +109 -0
- package/dist/capabilities/index.js +80 -0
- package/dist/capability-control/disabled-lists.d.ts +2 -1
- package/dist/capability-control/disabled-lists.js +3 -5
- package/dist/capability-control/overlay.d.ts +14 -1
- package/dist/capability-control/overlay.js +40 -0
- package/dist/capability-control/service.js +6 -4
- package/dist/cli/agent-server-stdio.d.ts +1 -1
- package/dist/cli/agent-server-stdio.js +66 -6
- package/dist/cli/agent-server-tcp.js +7 -3
- package/dist/context/compaction.d.ts +39 -3
- package/dist/context/compaction.js +151 -39
- package/dist/context/manager.d.ts +17 -1
- package/dist/context/manager.js +36 -1
- package/dist/credentials/access.d.ts +3 -1
- package/dist/credentials/access.js +24 -3
- package/dist/credentials/index.d.ts +1 -1
- package/dist/credentials/index.js +1 -1
- package/dist/credentials/oauth.d.ts +4 -1
- package/dist/credentials/oauth.js +14 -0
- package/dist/credentials/store.d.ts +15 -1
- package/dist/credentials/store.js +17 -4
- package/dist/credentials/types.d.ts +24 -0
- package/dist/credentials/use-credential-tool.js +15 -1
- package/dist/engine/auxiliary-pipeline.d.ts +40 -0
- package/dist/engine/auxiliary-pipeline.js +181 -0
- package/dist/{settings → engine}/disk-defaults.d.ts +2 -2
- package/dist/{settings → engine}/disk-defaults.js +5 -2
- package/dist/engine/dynamic-tool-defs.d.ts +4 -0
- package/dist/engine/dynamic-tool-defs.js +4 -0
- package/dist/engine/engine.d.ts +254 -195
- package/dist/engine/engine.js +1812 -2041
- package/dist/engine/file-history-hook.d.ts +11 -0
- package/dist/engine/file-history-hook.js +31 -0
- package/dist/engine/goal-judge-context.d.ts +9 -0
- package/dist/engine/goal-judge-context.js +234 -0
- package/dist/engine/injected-context-cache.d.ts +6 -0
- package/dist/engine/injected-context-cache.js +13 -0
- package/dist/engine/input-attachments.d.ts +1 -1
- package/dist/engine/model-facade.d.ts +3 -3
- package/dist/engine/model-facade.js +15 -14
- package/dist/engine/permission-controller.d.ts +55 -0
- package/dist/engine/permission-controller.js +148 -0
- package/dist/engine/prompt-cache-diagnostics.d.ts +58 -0
- package/dist/engine/prompt-cache-diagnostics.js +178 -0
- package/dist/engine/run-accounting.d.ts +41 -0
- package/dist/engine/run-accounting.js +126 -0
- package/dist/engine/run-context.d.ts +44 -0
- package/dist/engine/run-context.js +88 -0
- package/dist/engine/run-environment.d.ts +30 -0
- package/dist/engine/run-environment.js +77 -0
- package/dist/engine/run-finalize.d.ts +58 -0
- package/dist/engine/run-finalize.js +245 -0
- package/dist/engine/run-goal.d.ts +58 -0
- package/dist/engine/run-goal.js +188 -0
- package/dist/engine/run-image-input.d.ts +1 -1
- package/dist/engine/run-image-input.js +5 -3
- package/dist/engine/run-session-open.d.ts +41 -0
- package/dist/engine/run-session-open.js +186 -0
- package/dist/engine/run-setup.d.ts +42 -0
- package/dist/engine/run-setup.js +58 -0
- package/dist/engine/run-tooling.d.ts +125 -0
- package/dist/engine/run-tooling.js +283 -0
- package/dist/engine/run-types.d.ts +139 -0
- package/dist/engine/run-types.js +12 -0
- package/dist/engine/run-workspace.d.ts +50 -0
- package/dist/engine/run-workspace.js +114 -0
- package/dist/engine/steer-queue.d.ts +1 -1
- package/dist/engine/subagent-spawner.d.ts +32 -0
- package/dist/engine/subagent-spawner.js +287 -0
- package/dist/engine/tool-summary.d.ts +2 -2
- package/dist/engine/tool-summary.js +2 -2
- package/dist/engine/turn-loop.d.ts +49 -10
- package/dist/engine/turn-loop.js +370 -104
- package/dist/engine/types.d.ts +30 -3
- package/dist/engine/types.js +1 -1
- package/dist/{engine/goal.d.ts → goal/lifecycle.d.ts} +76 -4
- package/dist/goal/lifecycle.js +482 -0
- package/dist/hooks/events.d.ts +24 -10
- package/dist/hooks/goal-stop-hook.d.ts +17 -28
- package/dist/hooks/goal-stop-hook.js +110 -465
- package/dist/hooks/registry.js +1 -1
- package/dist/index.d.ts +48 -108
- package/dist/index.extension.d.ts +51 -0
- package/dist/index.extension.js +39 -0
- package/dist/index.internal.d.ts +86 -0
- package/dist/index.internal.js +92 -0
- package/dist/index.js +34 -123
- package/dist/links/cli.d.ts +48 -0
- package/dist/links/cli.js +617 -0
- package/dist/links/http.d.ts +40 -0
- package/dist/links/http.js +166 -0
- package/dist/links/index.d.ts +4 -0
- package/dist/links/index.js +3 -0
- package/dist/links/link-action-tool.d.ts +5 -0
- package/dist/links/link-action-tool.js +241 -0
- package/dist/links/providers.d.ts +8 -0
- package/dist/links/providers.js +665 -0
- package/dist/links/types.d.ts +44 -0
- package/dist/llm/client-base.d.ts +7 -0
- package/dist/llm/client-base.js +60 -0
- package/dist/llm/model-pool.d.ts +1 -1
- package/dist/llm/model-pool.js +1 -1
- package/dist/llm/providers/anthropic.d.ts +1 -0
- package/dist/llm/providers/anthropic.js +9 -0
- package/dist/llm/providers/openai.d.ts +1 -0
- package/dist/llm/providers/openai.js +17 -0
- package/dist/model-catalog/index.js +15 -2
- package/dist/model-catalog/resolve.d.ts +13 -1
- package/dist/model-catalog/resolve.js +37 -2
- package/dist/model-catalog/types.d.ts +74 -48
- package/dist/model-catalog/types.js +16 -5
- package/dist/model-catalog/upsert.d.ts +3 -1
- package/dist/model-catalog/upsert.js +9 -0
- package/dist/onboarding.d.ts +0 -1
- package/dist/onboarding.js +1 -22
- package/dist/panel-apps/bindings.d.ts +24 -0
- package/dist/panel-apps/bindings.js +69 -0
- package/dist/panel-apps/github-archive.d.ts +21 -0
- package/dist/panel-apps/github-archive.js +98 -0
- package/dist/panel-apps/index.d.ts +4 -0
- package/dist/panel-apps/index.js +4 -0
- package/dist/panel-apps/installer.d.ts +68 -0
- package/dist/panel-apps/installer.js +622 -0
- package/dist/panel-apps/manifest.d.ts +364 -0
- package/dist/panel-apps/manifest.js +189 -0
- package/dist/panel-apps/paths.d.ts +13 -0
- package/dist/panel-apps/paths.js +38 -0
- package/dist/panel-apps/registry.d.ts +51 -0
- package/dist/panel-apps/registry.js +99 -0
- package/dist/panel-apps/runtime.d.ts +80 -0
- package/dist/panel-apps/runtime.js +154 -0
- package/dist/plugins/gitOps.js +8 -1
- package/dist/plugins/installedPlugins.d.ts +2 -1
- package/dist/plugins/installedPlugins.js +146 -8
- package/dist/plugins/installer/codex/convertAgents.d.ts +4 -1
- package/dist/plugins/installer/codex/convertAgents.js +62 -8
- package/dist/plugins/installer/codex/convertCommands.d.ts +5 -5
- package/dist/plugins/installer/codex/convertCommands.js +35 -12
- package/dist/plugins/installer/codex/convertHooks.d.ts +10 -0
- package/dist/plugins/installer/codex/convertHooks.js +82 -0
- package/dist/plugins/installer/codex/convertSkills.js +41 -6
- package/dist/plugins/installer/install.d.ts +7 -1
- package/dist/plugins/installer/install.js +21 -87
- package/dist/plugins/installer/installFromArchive.d.ts +26 -4
- package/dist/plugins/installer/installFromArchive.js +44 -27
- package/dist/plugins/installer/installFromNpm.d.ts +31 -0
- package/dist/plugins/installer/installFromNpm.js +273 -0
- package/dist/plugins/installer/loadPluginAgents.js +17 -4
- package/dist/plugins/installer/loadPluginMcp.d.ts +14 -0
- package/dist/plugins/installer/loadPluginMcp.js +245 -35
- package/dist/plugins/installer/normalizeManifest.d.ts +13 -0
- package/dist/plugins/installer/normalizeManifest.js +306 -0
- package/dist/plugins/installer/npmTar.d.ts +13 -0
- package/dist/plugins/installer/npmTar.js +321 -0
- package/dist/plugins/installer/parseSource.d.ts +11 -0
- package/dist/plugins/installer/parseSource.js +48 -0
- package/dist/plugins/installer/preview.d.ts +101 -0
- package/dist/plugins/installer/preview.js +336 -0
- package/dist/plugins/installer/projectPluginSource.d.ts +14 -0
- package/dist/plugins/installer/projectPluginSource.js +140 -0
- package/dist/plugins/installer/types.d.ts +775 -0
- package/dist/plugins/installer/types.js +100 -0
- package/dist/plugins/installer/unzip.d.ts +11 -0
- package/dist/plugins/installer/unzip.js +123 -9
- package/dist/plugins/installer/update.d.ts +2 -2
- package/dist/plugins/installer/update.js +43 -4
- package/dist/plugins/loadPluginHooks.d.ts +19 -2
- package/dist/plugins/loadPluginHooks.js +97 -86
- package/dist/plugins/pluginAutomationTemplates.d.ts +18 -0
- package/dist/plugins/pluginAutomationTemplates.js +50 -0
- package/dist/plugins/pluginCatalog.d.ts +45 -0
- package/dist/plugins/pluginCatalog.js +87 -0
- package/dist/plugins/pluginCommandHook.d.ts +6 -0
- package/dist/plugins/pluginCommandHook.js +25 -8
- package/dist/plugins/pluginCommandsLoader.d.ts +19 -0
- package/dist/plugins/pluginCommandsLoader.js +181 -7
- package/dist/plugins/pluginContent.d.ts +10 -1
- package/dist/plugins/pluginContent.js +87 -30
- package/dist/plugins/pluginHookApproval.d.ts +30 -0
- package/dist/plugins/pluginHookApproval.js +160 -0
- package/dist/plugins/pluginHookIntegrity.d.ts +69 -0
- package/dist/plugins/pluginHookIntegrity.js +361 -0
- package/dist/plugins/pluginInstaller.js +71 -12
- package/dist/plugins/pluginMcpApproval.d.ts +19 -0
- package/dist/plugins/pluginMcpApproval.js +110 -0
- package/dist/plugins/pluginMcpIntegrity.d.ts +21 -0
- package/dist/plugins/pluginMcpIntegrity.js +74 -0
- package/dist/plugins/types.d.ts +30 -0
- package/dist/plugins/varRewrite.d.ts +9 -5
- package/dist/plugins/varRewrite.js +26 -17
- package/dist/preset/index.d.ts +11 -8
- package/dist/preset/index.js +62 -203
- package/dist/product/define.js +9 -3
- package/dist/product/types.d.ts +0 -2
- package/dist/profile/activation.d.ts +36 -0
- package/dist/profile/activation.js +57 -0
- package/dist/profile/catalog-store.d.ts +77 -0
- package/dist/profile/catalog-store.js +346 -0
- package/dist/profile/catalog.d.ts +54 -0
- package/dist/profile/catalog.js +152 -0
- package/dist/profile/index.d.ts +7 -0
- package/dist/profile/index.js +7 -0
- package/dist/profile/requirements.d.ts +76 -0
- package/dist/profile/requirements.js +117 -0
- package/dist/profile/resolve.d.ts +11 -0
- package/dist/profile/resolve.js +41 -0
- package/dist/profile/store.d.ts +17 -0
- package/dist/profile/store.js +167 -0
- package/dist/profile/types.d.ts +321 -0
- package/dist/profile/types.js +104 -0
- package/dist/prompt/composer.d.ts +46 -7
- package/dist/prompt/composer.js +78 -48
- package/dist/prompt/instruction-scanner.d.ts +6 -5
- package/dist/prompt/instruction-scanner.js +8 -23
- package/dist/prompt/section-loader.d.ts +2 -2
- package/dist/prompt/section-loader.js +7 -4
- package/dist/prompt/sections/browser.md +10 -9
- package/dist/prompt/sections/harness-base.md +9 -0
- package/dist/protocol/chat-session-manager.d.ts +64 -1
- package/dist/protocol/chat-session-manager.js +104 -0
- package/dist/protocol/chat-session.d.ts +61 -10
- package/dist/protocol/chat-session.js +135 -25
- package/dist/protocol/client.d.ts +33 -3
- package/dist/protocol/client.js +96 -5
- package/dist/protocol/index.d.ts +2 -2
- package/dist/protocol/index.js +2 -2
- package/dist/protocol/mobile-remote-types.d.ts +406 -0
- package/dist/protocol/mobile-remote-types.js +1 -0
- package/dist/protocol/server.d.ts +127 -3
- package/dist/protocol/server.js +1309 -182
- package/dist/protocol/types.d.ts +152 -34
- package/dist/protocol/types.js +16 -0
- package/dist/run/ArtifactTracker.d.ts +6 -1
- package/dist/run/ArtifactTracker.js +29 -21
- package/dist/run/EngineRunner.d.ts +2 -0
- package/dist/run/EngineRunner.js +1 -0
- package/dist/run/RunManager.d.ts +26 -0
- package/dist/run/RunManager.js +82 -11
- package/dist/run/factory.d.ts +3 -0
- package/dist/run/factory.js +2 -0
- package/dist/runtime/safe-spawn.d.ts +6 -0
- package/dist/runtime/safe-spawn.js +8 -13
- package/dist/services/auto-dream.d.ts +13 -1
- package/dist/services/auto-dream.js +56 -8
- package/dist/services/dream-consolidation.js +10 -1
- package/dist/services/memory-orchestrator.js +6 -2
- package/dist/services/oauth.js +4 -1
- package/dist/services/session-memory.d.ts +4 -4
- package/dist/services/session-memory.js +13 -10
- package/dist/session/memory.d.ts +26 -7
- package/dist/session/memory.js +79 -21
- package/dist/session/session-manager.d.ts +182 -28
- package/dist/session/session-manager.js +910 -130
- package/dist/session/session-message.d.ts +22 -0
- package/dist/session/session-message.js +1 -0
- package/dist/session/transcript.d.ts +46 -5
- package/dist/session/transcript.js +159 -3
- package/dist/settings/feature-flags.d.ts +40 -0
- package/dist/settings/feature-flags.js +40 -0
- package/dist/settings/manager.d.ts +39 -1
- package/dist/settings/manager.js +102 -41
- package/dist/settings/migrate-config.js +4 -2
- package/dist/settings/schema.d.ts +511 -177
- package/dist/settings/schema.js +98 -25
- package/dist/skills/scanner.d.ts +6 -2
- package/dist/skills/scanner.js +160 -9
- package/dist/sources/adapter.d.ts +14 -0
- package/dist/sources/adapter.js +7 -0
- package/dist/sources/adapters/local-files.d.ts +10 -0
- package/dist/sources/adapters/local-files.js +127 -0
- package/dist/sources/adapters/mcp-resource.d.ts +17 -0
- package/dist/sources/adapters/mcp-resource.js +41 -0
- package/dist/sources/adapters/mock.d.ts +3 -0
- package/dist/sources/adapters/mock.js +29 -0
- package/dist/sources/binding.d.ts +6 -0
- package/dist/sources/binding.js +24 -0
- package/dist/sources/catalog.d.ts +6 -0
- package/dist/sources/catalog.js +64 -0
- package/dist/sources/context-summary.d.ts +8 -0
- package/dist/sources/context-summary.js +13 -0
- package/dist/sources/credential-status.d.ts +2 -0
- package/dist/sources/credential-status.js +13 -0
- package/dist/sources/index.d.ts +10 -0
- package/dist/sources/index.js +10 -0
- package/dist/sources/resolve.d.ts +28 -0
- package/dist/sources/resolve.js +47 -0
- package/dist/sources/truncate-utf8.d.ts +7 -0
- package/dist/sources/truncate-utf8.js +18 -0
- package/dist/sources/types.d.ts +71 -0
- package/dist/sources/types.js +26 -0
- package/dist/testing/fetch-stub.d.ts +32 -0
- package/dist/testing/fetch-stub.js +24 -0
- package/dist/themes/image.d.ts +18 -0
- package/dist/themes/image.js +117 -0
- package/dist/themes/index.d.ts +4 -0
- package/dist/themes/index.js +4 -0
- package/dist/themes/installer.d.ts +50 -0
- package/dist/themes/installer.js +290 -0
- package/dist/themes/manifest.d.ts +102 -0
- package/dist/themes/manifest.js +86 -0
- package/dist/themes/paths.d.ts +14 -0
- package/dist/themes/paths.js +33 -0
- package/dist/tool-system/browser-bridge.d.ts +53 -11
- package/dist/tool-system/browser-bridge.js +8 -9
- package/dist/tool-system/builtin/agent-heartbeat.d.ts +2 -2
- package/dist/tool-system/builtin/agent-heartbeat.js +20 -6
- package/dist/tool-system/builtin/agent-notifications.d.ts +127 -72
- package/dist/tool-system/builtin/agent-notifications.js +291 -101
- package/dist/tool-system/builtin/agent-output-file.js +1 -3
- package/dist/tool-system/builtin/agent-progress.d.ts +6 -0
- package/dist/tool-system/builtin/agent-progress.js +83 -0
- package/dist/tool-system/builtin/agent-registry.d.ts +38 -2
- package/dist/tool-system/builtin/agent-registry.js +178 -9
- package/dist/tool-system/builtin/agent-transcript-translator.js +1 -1
- package/dist/tool-system/builtin/agent.d.ts +2 -0
- package/dist/tool-system/builtin/agent.js +274 -33
- package/dist/tool-system/builtin/background-jobs.d.ts +55 -2
- package/dist/tool-system/builtin/background-jobs.js +96 -4
- package/dist/tool-system/builtin/background-work.d.ts +6 -0
- package/dist/tool-system/builtin/background-work.js +8 -1
- package/dist/tool-system/builtin/bash.js +5 -2
- package/dist/tool-system/builtin/browser-tools.d.ts +6 -3
- package/dist/tool-system/builtin/browser-tools.js +89 -23
- package/dist/tool-system/builtin/edit-model-catalog.d.ts +6 -0
- package/dist/tool-system/builtin/edit-model-catalog.js +172 -12
- package/dist/tool-system/builtin/edit.js +2 -6
- package/dist/tool-system/builtin/file-cache.d.ts +2 -0
- package/dist/tool-system/builtin/file-cache.js +4 -0
- package/dist/tool-system/builtin/generate-image.js +17 -10
- package/dist/tool-system/builtin/generate-video.js +26 -7
- package/dist/tool-system/builtin/grep.js +2 -2
- package/dist/tool-system/builtin/image-uploader.js +7 -1
- package/dist/tool-system/builtin/index.d.ts +32 -7
- package/dist/tool-system/builtin/index.js +237 -167
- package/dist/tool-system/builtin/memory.d.ts +6 -0
- package/dist/tool-system/builtin/memory.js +36 -15
- package/dist/tool-system/builtin/panel.d.ts +9 -0
- package/dist/tool-system/builtin/panel.js +314 -0
- package/dist/tool-system/builtin/read.js +5 -1
- package/dist/tool-system/builtin/send-message-to-session.d.ts +6 -0
- package/dist/tool-system/builtin/send-message-to-session.js +67 -0
- package/dist/tool-system/builtin/sources.d.ts +8 -0
- package/dist/tool-system/builtin/sources.js +137 -0
- package/dist/tool-system/builtin/tool-search.js +7 -2
- package/dist/tool-system/builtin/update-automation-memory.js +2 -0
- package/dist/tool-system/builtin/web-fetch.js +17 -13
- package/dist/tool-system/builtin/web-search.js +1 -3
- package/dist/tool-system/capability-module.d.ts +93 -0
- package/dist/tool-system/capability-module.js +53 -0
- package/dist/tool-system/context.d.ts +77 -19
- package/dist/tool-system/executor.js +75 -50
- package/dist/tool-system/external-tool-exposure.d.ts +60 -0
- package/dist/tool-system/external-tool-exposure.js +304 -0
- package/dist/tool-system/mcp-manager.d.ts +11 -1
- package/dist/tool-system/mcp-manager.js +19 -4
- package/dist/tool-system/mcp-tool-policy.d.ts +9 -0
- package/dist/tool-system/mcp-tool-policy.js +34 -0
- package/dist/tool-system/panel-bridge.d.ts +53 -0
- package/dist/tool-system/panel-bridge.js +1 -0
- package/dist/tool-system/permission.d.ts +26 -0
- package/dist/tool-system/permission.js +46 -0
- package/dist/tool-system/registry.d.ts +12 -1
- package/dist/tool-system/registry.js +31 -7
- package/dist/tool-system/sandbox/index.js +3 -8
- package/dist/tool-system/sandbox/seatbelt.js +2 -6
- package/dist/tool-system/session-tool-host.d.ts +139 -0
- package/dist/tool-system/session-tool-host.js +167 -0
- package/dist/tool-system/testing/tool-registry-harness.d.ts +31 -0
- package/dist/tool-system/testing/tool-registry-harness.js +51 -0
- package/dist/tool-system/validation.d.ts +14 -7
- package/dist/tool-system/validation.js +701 -7
- package/dist/types.d.ts +186 -20
- package/dist/{cc-orchestrator → utils}/cwd-normalize.d.ts +1 -0
- package/dist/{cc-orchestrator → utils}/cwd-normalize.js +1 -0
- package/dist/utils/file-mutex.d.ts +65 -0
- package/dist/utils/file-mutex.js +145 -0
- package/dist/utils/json.d.ts +2 -4
- package/dist/utils/json.js +2 -4
- package/dist/utils/lockfile.d.ts +30 -1
- package/dist/utils/lockfile.js +2 -2
- package/dist/utils/secret-scrubber.d.ts +8 -0
- package/dist/utils/secret-scrubber.js +227 -0
- package/dist/utils/toolDisplay.js +1 -1
- package/package.json +20 -5
- package/THIRD_PARTY_NOTICES.md +0 -206
- package/dist/arena/arena.d.ts +0 -45
- package/dist/arena/arena.js +0 -362
- package/dist/arena/context/context-tools.d.ts +0 -16
- package/dist/arena/context/context-tools.js +0 -272
- package/dist/arena/context/within-root.d.ts +0 -7
- package/dist/arena/context/within-root.js +0 -15
- package/dist/arena/detect-mode.d.ts +0 -20
- package/dist/arena/detect-mode.js +0 -78
- package/dist/arena/digest-builder.d.ts +0 -25
- package/dist/arena/digest-builder.js +0 -120
- package/dist/arena/index.d.ts +0 -29
- package/dist/arena/index.js +0 -29
- package/dist/arena/iterate/convergence.d.ts +0 -25
- package/dist/arena/iterate/convergence.js +0 -103
- package/dist/arena/iterate/formats/index.d.ts +0 -22
- package/dist/arena/iterate/formats/index.js +0 -283
- package/dist/arena/iterate/index.d.ts +0 -11
- package/dist/arena/iterate/index.js +0 -9
- package/dist/arena/iterate/iterative-arena.d.ts +0 -23
- package/dist/arena/iterate/iterative-arena.js +0 -237
- package/dist/arena/iterate/parse.d.ts +0 -42
- package/dist/arena/iterate/parse.js +0 -123
- package/dist/arena/iterate/phases/argue.d.ts +0 -22
- package/dist/arena/iterate/phases/argue.js +0 -165
- package/dist/arena/iterate/phases/revise.d.ts +0 -16
- package/dist/arena/iterate/phases/revise.js +0 -62
- package/dist/arena/iterate/phases/tournament.d.ts +0 -34
- package/dist/arena/iterate/phases/tournament.js +0 -113
- package/dist/arena/iterate/tools/web-tools.d.ts +0 -13
- package/dist/arena/iterate/tools/web-tools.js +0 -54
- package/dist/arena/iterate/types.d.ts +0 -152
- package/dist/arena/iterate/types.js +0 -8
- package/dist/arena/ledger.d.ts +0 -47
- package/dist/arena/ledger.js +0 -159
- package/dist/arena/lenses/architecture.d.ts +0 -5
- package/dist/arena/lenses/architecture.js +0 -22
- package/dist/arena/lenses/engineering.d.ts +0 -5
- package/dist/arena/lenses/engineering.js +0 -22
- package/dist/arena/lenses/general.d.ts +0 -5
- package/dist/arena/lenses/general.js +0 -20
- package/dist/arena/lenses/index.d.ts +0 -16
- package/dist/arena/lenses/index.js +0 -47
- package/dist/arena/lenses/product.d.ts +0 -5
- package/dist/arena/lenses/product.js +0 -22
- package/dist/arena/model-presets.d.ts +0 -23
- package/dist/arena/model-presets.js +0 -44
- package/dist/arena/phases/adjudication.d.ts +0 -25
- package/dist/arena/phases/adjudication.js +0 -142
- package/dist/arena/phases/build-consensus.d.ts +0 -30
- package/dist/arena/phases/build-consensus.js +0 -85
- package/dist/arena/phases/claim-registry.d.ts +0 -26
- package/dist/arena/phases/claim-registry.js +0 -60
- package/dist/arena/phases/cross-review.d.ts +0 -47
- package/dist/arena/phases/cross-review.js +0 -224
- package/dist/arena/phases/debate-rounds.d.ts +0 -28
- package/dist/arena/phases/debate-rounds.js +0 -161
- package/dist/arena/phases/participant-research.d.ts +0 -39
- package/dist/arena/phases/participant-research.js +0 -316
- package/dist/arena/phases/planning-detail-expansion.d.ts +0 -39
- package/dist/arena/phases/planning-detail-expansion.js +0 -120
- package/dist/arena/planner.d.ts +0 -28
- package/dist/arena/planner.js +0 -312
- package/dist/arena/providers/docs.d.ts +0 -7
- package/dist/arena/providers/docs.js +0 -111
- package/dist/arena/providers/git.d.ts +0 -8
- package/dist/arena/providers/git.js +0 -174
- package/dist/arena/providers/index.d.ts +0 -32
- package/dist/arena/providers/index.js +0 -132
- package/dist/arena/providers/none.d.ts +0 -7
- package/dist/arena/providers/none.js +0 -11
- package/dist/arena/providers/repo.d.ts +0 -7
- package/dist/arena/providers/repo.js +0 -258
- package/dist/arena/render/session.d.ts +0 -17
- package/dist/arena/render/session.js +0 -190
- package/dist/arena/render/terminal.d.ts +0 -34
- package/dist/arena/render/terminal.js +0 -286
- package/dist/arena/strategies/discussion.d.ts +0 -25
- package/dist/arena/strategies/discussion.js +0 -143
- package/dist/arena/strategies/index.d.ts +0 -15
- package/dist/arena/strategies/index.js +0 -28
- package/dist/arena/strategies/language-wrapper.d.ts +0 -17
- package/dist/arena/strategies/language-wrapper.js +0 -102
- package/dist/arena/strategies/lens-wrapper.d.ts +0 -16
- package/dist/arena/strategies/lens-wrapper.js +0 -236
- package/dist/arena/strategies/planning.d.ts +0 -30
- package/dist/arena/strategies/planning.js +0 -225
- package/dist/arena/strategies/review.d.ts +0 -26
- package/dist/arena/strategies/review.js +0 -168
- package/dist/arena/strategies/utils.d.ts +0 -36
- package/dist/arena/strategies/utils.js +0 -603
- package/dist/arena/tools/selector.d.ts +0 -17
- package/dist/arena/tools/selector.js +0 -61
- package/dist/arena/transitions.d.ts +0 -53
- package/dist/arena/transitions.js +0 -97
- package/dist/arena/types.d.ts +0 -518
- package/dist/arena/types.js +0 -27
- package/dist/cc-orchestrator/agent-adapter.d.ts +0 -54
- package/dist/cc-orchestrator/agent-adapter.js +0 -143
- package/dist/cc-orchestrator/cc-capability.d.ts +0 -19
- package/dist/cc-orchestrator/cc-capability.js +0 -53
- package/dist/cc-orchestrator/codex-session-discovery.d.ts +0 -24
- package/dist/cc-orchestrator/codex-session-discovery.js +0 -191
- package/dist/cc-orchestrator/codex-session-history.d.ts +0 -38
- package/dist/cc-orchestrator/codex-session-history.js +0 -247
- package/dist/cc-orchestrator/external-agent-bindings.d.ts +0 -27
- package/dist/cc-orchestrator/external-agent-bindings.js +0 -150
- package/dist/cc-orchestrator/external-agent-changes.d.ts +0 -19
- package/dist/cc-orchestrator/external-agent-changes.js +0 -231
- package/dist/cc-orchestrator/external-agent-driver.d.ts +0 -19
- package/dist/cc-orchestrator/external-agent-driver.js +0 -284
- package/dist/cc-orchestrator/external-agent-session-store.d.ts +0 -23
- package/dist/cc-orchestrator/external-agent-session-store.js +0 -146
- package/dist/cc-orchestrator/index.d.ts +0 -8
- package/dist/cc-orchestrator/index.js +0 -8
- package/dist/cc-orchestrator/relevance-judge.d.ts +0 -15
- package/dist/cc-orchestrator/relevance-judge.js +0 -29
- package/dist/cc-orchestrator/session-discovery.d.ts +0 -46
- package/dist/cc-orchestrator/session-discovery.js +0 -125
- package/dist/cc-orchestrator/session-history.d.ts +0 -54
- package/dist/cc-orchestrator/session-history.js +0 -150
- package/dist/cron/cron-runtime.d.ts +0 -2
- package/dist/cron/cron-runtime.js +0 -2
- package/dist/cron/cron-store.d.ts +0 -2
- package/dist/cron/cron-store.js +0 -2
- package/dist/cron/scheduler.d.ts +0 -7
- package/dist/cron/scheduler.js +0 -7
- package/dist/engine/goal.js +0 -206
- package/dist/external-agents/config.d.ts +0 -2
- package/dist/external-agents/config.js +0 -15
- package/dist/external-agents/types.d.ts +0 -31
- package/dist/git/parse-log.d.ts +0 -13
- package/dist/git/parse-log.js +0 -21
- package/dist/git/utils.d.ts +0 -49
- package/dist/git/utils.js +0 -161
- package/dist/git/worktree/crud.d.ts +0 -72
- package/dist/git/worktree/crud.js +0 -235
- package/dist/git/worktree/diff.d.ts +0 -14
- package/dist/git/worktree/diff.js +0 -82
- package/dist/git/worktree/git-exec.d.ts +0 -7
- package/dist/git/worktree/git-exec.js +0 -87
- package/dist/git/worktree/index.d.ts +0 -5
- package/dist/git/worktree/index.js +0 -5
- package/dist/git/worktree/query.d.ts +0 -43
- package/dist/git/worktree/query.js +0 -128
- package/dist/git/worktree/slug.d.ts +0 -11
- package/dist/git/worktree/slug.js +0 -58
- package/dist/git/worktree.d.ts +0 -1
- package/dist/git/worktree.js +0 -5
- package/dist/lsp/client.d.ts +0 -41
- package/dist/lsp/client.js +0 -186
- package/dist/lsp/manager.d.ts +0 -40
- package/dist/lsp/manager.js +0 -155
- package/dist/lsp/root-path.d.ts +0 -9
- package/dist/lsp/root-path.js +0 -12
- package/dist/lsp/servers.d.ts +0 -16
- package/dist/lsp/servers.js +0 -60
- package/dist/prompt/sections/coding.md +0 -35
- package/dist/quota/credentials.d.ts +0 -3
- package/dist/quota/credentials.js +0 -80
- package/dist/quota/index.d.ts +0 -36
- package/dist/quota/index.js +0 -155
- package/dist/quota/types.d.ts +0 -48
- package/dist/quota/types.js +0 -13
- package/dist/review/review-prompt.d.ts +0 -28
- package/dist/review/review-prompt.js +0 -81
- package/dist/state.d.ts +0 -160
- package/dist/state.js +0 -267
- package/dist/tool-system/builtin/apply-patch/applier.d.ts +0 -26
- package/dist/tool-system/builtin/apply-patch/applier.js +0 -308
- package/dist/tool-system/builtin/apply-patch/backup-targets.d.ts +0 -10
- package/dist/tool-system/builtin/apply-patch/backup-targets.js +0 -30
- package/dist/tool-system/builtin/apply-patch/index.d.ts +0 -20
- package/dist/tool-system/builtin/apply-patch/index.js +0 -105
- package/dist/tool-system/builtin/apply-patch/parser.d.ts +0 -17
- package/dist/tool-system/builtin/apply-patch/parser.js +0 -212
- package/dist/tool-system/builtin/apply-patch/seek-sequence.d.ts +0 -18
- package/dist/tool-system/builtin/apply-patch/seek-sequence.js +0 -123
- package/dist/tool-system/builtin/apply-patch/types.d.ts +0 -49
- package/dist/tool-system/builtin/apply-patch/types.js +0 -13
- package/dist/tool-system/builtin/arena.d.ts +0 -31
- package/dist/tool-system/builtin/arena.js +0 -416
- package/dist/tool-system/builtin/brief.d.ts +0 -6
- package/dist/tool-system/builtin/brief.js +0 -41
- package/dist/tool-system/builtin/check-quota.d.ts +0 -15
- package/dist/tool-system/builtin/check-quota.js +0 -34
- package/dist/tool-system/builtin/drive-claude-code.d.ts +0 -51
- package/dist/tool-system/builtin/drive-claude-code.js +0 -698
- package/dist/tool-system/builtin/lsp.d.ts +0 -7
- package/dist/tool-system/builtin/lsp.js +0 -144
- package/dist/tool-system/builtin/notebook-edit.d.ts +0 -7
- package/dist/tool-system/builtin/notebook-edit.js +0 -127
- package/dist/tool-system/builtin/worktree.d.ts +0 -11
- package/dist/tool-system/builtin/worktree.js +0 -363
- /package/dist/{external-agents → links}/types.js +0 -0
- /package/dist/{engine/session-usage.d.ts → session/usage.d.ts} +0 -0
- /package/dist/{engine/session-usage.js → session/usage.js} +0 -0
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { asArray, asRecord, firstString, intParam, pathParam, pathSegmentParam, pick, stringParam, } from "./http.js";
|
|
6
|
+
import { getLocalLinkProvider } from "./providers.js";
|
|
7
|
+
const CONFIG = {
|
|
8
|
+
github: {
|
|
9
|
+
command: "gh",
|
|
10
|
+
hostname: "github.com",
|
|
11
|
+
statusArgs: ["auth", "status", "--active", "--hostname", "github.com"],
|
|
12
|
+
loginArgs: [
|
|
13
|
+
"auth",
|
|
14
|
+
"login",
|
|
15
|
+
"--hostname",
|
|
16
|
+
"github.com",
|
|
17
|
+
"--web",
|
|
18
|
+
"--clipboard",
|
|
19
|
+
"--git-protocol",
|
|
20
|
+
"https",
|
|
21
|
+
"--skip-ssh-key",
|
|
22
|
+
],
|
|
23
|
+
tokenEnv: ["GH_TOKEN", "GITHUB_TOKEN", "GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN"],
|
|
24
|
+
},
|
|
25
|
+
gitlab: {
|
|
26
|
+
command: "glab",
|
|
27
|
+
hostname: "gitlab.com",
|
|
28
|
+
statusArgs: ["auth", "status", "--hostname", "gitlab.com"],
|
|
29
|
+
loginArgs: [
|
|
30
|
+
"auth",
|
|
31
|
+
"login",
|
|
32
|
+
"--hostname",
|
|
33
|
+
"gitlab.com",
|
|
34
|
+
"--web",
|
|
35
|
+
"--git-protocol",
|
|
36
|
+
"https",
|
|
37
|
+
"--use-keyring",
|
|
38
|
+
],
|
|
39
|
+
tokenEnv: ["GITLAB_TOKEN", "GITLAB_ACCESS_TOKEN", "OAUTH_TOKEN", "CI_JOB_TOKEN"],
|
|
40
|
+
},
|
|
41
|
+
notion: {
|
|
42
|
+
command: "ntn",
|
|
43
|
+
statusArgs: ["--version"],
|
|
44
|
+
loginArgs: ["login"],
|
|
45
|
+
tokenEnv: ["NOTION_API_TOKEN"],
|
|
46
|
+
},
|
|
47
|
+
todoist: {
|
|
48
|
+
command: "td",
|
|
49
|
+
statusArgs: ["auth", "status", "--json"],
|
|
50
|
+
loginArgs: ["auth", "login", "--read-only", "--json"],
|
|
51
|
+
tokenEnv: ["TODOIST_API_TOKEN", "TODOIST_TOKEN"],
|
|
52
|
+
},
|
|
53
|
+
vercel: {
|
|
54
|
+
command: "vercel",
|
|
55
|
+
statusArgs: ["whoami", "--no-color"],
|
|
56
|
+
loginArgs: ["login", "--no-color"],
|
|
57
|
+
tokenEnv: ["VERCEL_TOKEN"],
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
const TOKEN_PATTERN = /\b(?:github_pat_|gh[pousr]_|glpat-|glcbt-|gldt-|ntn_|secret_)[A-Za-z0-9_.-]{6,}\b/gi;
|
|
61
|
+
const MAX_OUTPUT_BYTES = 2 * 1024 * 1024;
|
|
62
|
+
/** App-private CLI location. It never mutates the user's system PATH. */
|
|
63
|
+
export function managedLinkCliPath(providerId) {
|
|
64
|
+
const base = process.env.CODESHELL_LINK_CLI_DIR ??
|
|
65
|
+
join(process.env.HOME ?? homedir(), ".code-shell", "tools", "link-cli");
|
|
66
|
+
const executable = `${CONFIG[providerId].command}${process.platform === "win32" ? ".exe" : ""}`;
|
|
67
|
+
return join(base, providerId, executable);
|
|
68
|
+
}
|
|
69
|
+
export function resolveLinkCliExecutable(providerId, fallbackCommand = CONFIG[providerId].command) {
|
|
70
|
+
const managed = managedLinkCliPath(providerId);
|
|
71
|
+
return existsSync(managed) ? managed : fallbackCommand;
|
|
72
|
+
}
|
|
73
|
+
function safeMessage(value) {
|
|
74
|
+
const stderr = value && typeof value === "object" && "stderr" in value
|
|
75
|
+
? String(value.stderr ?? "").trim()
|
|
76
|
+
: "";
|
|
77
|
+
const raw = stderr || (value instanceof Error ? value.message : String(value ?? ""));
|
|
78
|
+
return raw.replace(TOKEN_PATTERN, "[redacted]").trim().slice(0, 500);
|
|
79
|
+
}
|
|
80
|
+
function isMissingExecutable(error) {
|
|
81
|
+
return Boolean(error &&
|
|
82
|
+
typeof error === "object" &&
|
|
83
|
+
"code" in error &&
|
|
84
|
+
error.code === "ENOENT");
|
|
85
|
+
}
|
|
86
|
+
export const runCliLinkCommand = (providerId, command, args, options) => new Promise((resolve, reject) => {
|
|
87
|
+
const env = { ...process.env };
|
|
88
|
+
for (const name of CONFIG[providerId].tokenEnv)
|
|
89
|
+
delete env[name];
|
|
90
|
+
const child = execFile(resolveLinkCliExecutable(providerId, command), args, {
|
|
91
|
+
cwd: options.cwd,
|
|
92
|
+
env,
|
|
93
|
+
encoding: "utf8",
|
|
94
|
+
timeout: options.timeoutMs,
|
|
95
|
+
maxBuffer: MAX_OUTPUT_BYTES,
|
|
96
|
+
windowsHide: true,
|
|
97
|
+
signal: options.signal,
|
|
98
|
+
}, (error, stdout, stderr) => {
|
|
99
|
+
if (error) {
|
|
100
|
+
Object.assign(error, { stdout, stderr });
|
|
101
|
+
reject(error);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
resolve({ stdout: String(stdout), stderr: String(stderr) });
|
|
105
|
+
});
|
|
106
|
+
// All supported flows are deliberately non-interactive (browser/device
|
|
107
|
+
// authorization or machine-readable API calls). Always close stdin so a
|
|
108
|
+
// CLI cannot mistake the Electron pipe for pending JSON or a hidden prompt.
|
|
109
|
+
child.stdin?.end(options.input ?? "");
|
|
110
|
+
});
|
|
111
|
+
function parseJson(result, providerId) {
|
|
112
|
+
try {
|
|
113
|
+
return JSON.parse(result.stdout);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
throw new Error(`${providerId} CLI returned an invalid response`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async function api(providerId, endpoint, options = {}, run = runCliLinkCommand) {
|
|
120
|
+
const config = CONFIG[providerId];
|
|
121
|
+
if (providerId === "todoist")
|
|
122
|
+
throw new Error("Todoist CLI does not expose a raw API command");
|
|
123
|
+
let args;
|
|
124
|
+
if (providerId === "github") {
|
|
125
|
+
args = ["api", endpoint, "--hostname", CONFIG.github.hostname];
|
|
126
|
+
if (options.method && options.method !== "GET")
|
|
127
|
+
args.push("--method", options.method);
|
|
128
|
+
if (options.input !== undefined)
|
|
129
|
+
args.push("--input", "-");
|
|
130
|
+
}
|
|
131
|
+
else if (providerId === "gitlab") {
|
|
132
|
+
args = ["api", endpoint, "--hostname", CONFIG.gitlab.hostname, "--output", "json"];
|
|
133
|
+
if (options.method && options.method !== "GET")
|
|
134
|
+
args.push("--method", options.method);
|
|
135
|
+
if (options.input !== undefined)
|
|
136
|
+
args.push("--input", "-");
|
|
137
|
+
}
|
|
138
|
+
else if (providerId === "notion") {
|
|
139
|
+
args = ["api", endpoint];
|
|
140
|
+
if (options.method && options.method !== "GET")
|
|
141
|
+
args.push("-X", options.method);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
args = ["api", endpoint, "--no-color"];
|
|
145
|
+
if (options.method && options.method !== "GET")
|
|
146
|
+
args.push("-X", options.method);
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
const result = await run(providerId, config.command, args, {
|
|
150
|
+
cwd: options.cwd,
|
|
151
|
+
signal: options.signal,
|
|
152
|
+
timeoutMs: 30_000,
|
|
153
|
+
input: options.input === undefined ? undefined : JSON.stringify(options.input),
|
|
154
|
+
});
|
|
155
|
+
return parseJson(result, providerId);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
const message = safeMessage(error);
|
|
159
|
+
throw new Error(message || `${providerId} CLI request failed`, { cause: error });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function identityFromUser(providerId, data) {
|
|
163
|
+
const root = asRecord(data) ?? {};
|
|
164
|
+
const user = providerId === "vercel" ? (asRecord(root.user) ?? root) : root;
|
|
165
|
+
const externalAccountId = String(user.id ?? "account");
|
|
166
|
+
const label = (() => {
|
|
167
|
+
if (providerId === "github")
|
|
168
|
+
return firstString(user.login, user.name) ?? externalAccountId;
|
|
169
|
+
if (providerId === "gitlab")
|
|
170
|
+
return firstString(user.username, user.name) ?? externalAccountId;
|
|
171
|
+
if (providerId === "todoist") {
|
|
172
|
+
return firstString(user.email, user.fullName, user.name) ?? externalAccountId;
|
|
173
|
+
}
|
|
174
|
+
return firstString(user.name, user.username, user.email) ?? externalAccountId;
|
|
175
|
+
})();
|
|
176
|
+
const detail = firstString(user.name, user.email);
|
|
177
|
+
return { externalAccountId, label, ...(detail && detail !== label ? { detail } : {}) };
|
|
178
|
+
}
|
|
179
|
+
async function liveIdentity(providerId, options, run) {
|
|
180
|
+
if (providerId === "todoist") {
|
|
181
|
+
const status = parseJson(await run(providerId, CONFIG.todoist.command, CONFIG.todoist.statusArgs, {
|
|
182
|
+
...options,
|
|
183
|
+
timeoutMs: 15_000,
|
|
184
|
+
}), providerId);
|
|
185
|
+
const identity = identityFromUser(providerId, status);
|
|
186
|
+
const projectRoot = asRecord(parseJson(await run(providerId, CONFIG.todoist.command, ["project", "list", "--json", "--limit", "12"], { ...options, timeoutMs: 30_000 }), providerId));
|
|
187
|
+
const resourceLabels = asArray(projectRoot?.results)
|
|
188
|
+
.map((value) => firstString(asRecord(value)?.name))
|
|
189
|
+
.filter((value) => Boolean(value))
|
|
190
|
+
.slice(0, 12);
|
|
191
|
+
return { ...identity, resourceLabels };
|
|
192
|
+
}
|
|
193
|
+
const userEndpoint = providerId === "notion" ? "v1/users/me" : providerId === "vercel" ? "/v2/user" : "user";
|
|
194
|
+
const user = await api(providerId, userEndpoint, options, run);
|
|
195
|
+
const identity = identityFromUser(providerId, user);
|
|
196
|
+
if (providerId === "notion")
|
|
197
|
+
return identity;
|
|
198
|
+
const resources = providerId === "github"
|
|
199
|
+
? await api(providerId, "user/repos?per_page=12&sort=updated", options, run)
|
|
200
|
+
: providerId === "gitlab"
|
|
201
|
+
? await api(providerId, "projects?membership=true&simple=true&per_page=12", options, run)
|
|
202
|
+
: await api(providerId, "/v10/projects?limit=12", options, run);
|
|
203
|
+
const resourceValues = providerId === "vercel" ? asArray(asRecord(resources)?.projects) : asArray(resources);
|
|
204
|
+
const resourceLabels = resourceValues
|
|
205
|
+
.map((value) => {
|
|
206
|
+
const record = asRecord(value);
|
|
207
|
+
return providerId === "github"
|
|
208
|
+
? firstString(record?.full_name)
|
|
209
|
+
: providerId === "gitlab"
|
|
210
|
+
? firstString(record?.path_with_namespace)
|
|
211
|
+
: firstString(record?.name);
|
|
212
|
+
})
|
|
213
|
+
.filter((value) => Boolean(value))
|
|
214
|
+
.slice(0, 12);
|
|
215
|
+
return { ...identity, resourceLabels };
|
|
216
|
+
}
|
|
217
|
+
async function currentIdentity(providerId, options, run) {
|
|
218
|
+
if (providerId === "todoist") {
|
|
219
|
+
return identityFromUser(providerId, parseJson(await run(providerId, CONFIG.todoist.command, CONFIG.todoist.statusArgs, {
|
|
220
|
+
...options,
|
|
221
|
+
timeoutMs: 15_000,
|
|
222
|
+
}), providerId));
|
|
223
|
+
}
|
|
224
|
+
return identityFromUser(providerId, await api(providerId, providerId === "notion" ? "v1/users/me" : providerId === "vercel" ? "/v2/user" : "user", options, run));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* A CLI may switch accounts after Link was connected. Pin every Action to the
|
|
228
|
+
* originally approved account so a local CLI change cannot silently widen or
|
|
229
|
+
* redirect the Link connection.
|
|
230
|
+
*/
|
|
231
|
+
export async function assertCliLinkAccount(providerId, expectedExternalAccountId, options = {}, run = runCliLinkCommand) {
|
|
232
|
+
const identity = await currentIdentity(providerId, options, run);
|
|
233
|
+
if (identity.externalAccountId !== expectedExternalAccountId) {
|
|
234
|
+
throw new Error(`${CONFIG[providerId].command} is signed in to a different account; reconnect this Link`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export function isCliLinkProvider(providerId) {
|
|
238
|
+
return (providerId === "github" ||
|
|
239
|
+
providerId === "gitlab" ||
|
|
240
|
+
providerId === "notion" ||
|
|
241
|
+
providerId === "todoist" ||
|
|
242
|
+
providerId === "vercel");
|
|
243
|
+
}
|
|
244
|
+
export async function getCliLinkStatus(providerId, options = {}, run = runCliLinkCommand) {
|
|
245
|
+
const config = CONFIG[providerId];
|
|
246
|
+
try {
|
|
247
|
+
const statusResult = await run(providerId, config.command, config.statusArgs, {
|
|
248
|
+
...options,
|
|
249
|
+
timeoutMs: 15_000,
|
|
250
|
+
});
|
|
251
|
+
const user = providerId === "todoist"
|
|
252
|
+
? identityFromUser(providerId, parseJson(statusResult, providerId))
|
|
253
|
+
: await currentIdentity(providerId, options, run);
|
|
254
|
+
return {
|
|
255
|
+
providerId,
|
|
256
|
+
command: config.command,
|
|
257
|
+
installed: true,
|
|
258
|
+
authenticated: true,
|
|
259
|
+
account: user.label,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
if (isMissingExecutable(error)) {
|
|
264
|
+
return {
|
|
265
|
+
providerId,
|
|
266
|
+
command: config.command,
|
|
267
|
+
installed: false,
|
|
268
|
+
authenticated: false,
|
|
269
|
+
message: `${config.command} is not installed`,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
providerId,
|
|
274
|
+
command: config.command,
|
|
275
|
+
installed: true,
|
|
276
|
+
authenticated: false,
|
|
277
|
+
message: safeMessage(error) || `${config.command} is not signed in`,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
export async function connectCliLink(providerId, options, run = runCliLinkCommand) {
|
|
282
|
+
let status = await getCliLinkStatus(providerId, options, run);
|
|
283
|
+
if (!status.installed)
|
|
284
|
+
throw new Error(`${status.command} is not installed`);
|
|
285
|
+
if (!status.authenticated && options.loginIfNeeded) {
|
|
286
|
+
const config = CONFIG[providerId];
|
|
287
|
+
try {
|
|
288
|
+
await run(providerId, config.command, config.loginArgs, {
|
|
289
|
+
cwd: options.cwd,
|
|
290
|
+
signal: options.signal,
|
|
291
|
+
timeoutMs: 15 * 60_000,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
throw new Error(safeMessage(error) || `${config.command} browser authorization failed`, {
|
|
296
|
+
cause: error,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
status = await getCliLinkStatus(providerId, options, run);
|
|
300
|
+
}
|
|
301
|
+
if (!status.authenticated)
|
|
302
|
+
throw new Error(`${status.command} is not signed in`);
|
|
303
|
+
const provider = getLocalLinkProvider(providerId);
|
|
304
|
+
if (!provider)
|
|
305
|
+
throw new Error(`Unknown local Link provider: ${providerId}`);
|
|
306
|
+
return {
|
|
307
|
+
providerId,
|
|
308
|
+
identity: await liveIdentity(providerId, options, run),
|
|
309
|
+
capabilityIds: provider.actions.map((action) => `${providerId}.${action.id}`),
|
|
310
|
+
verifiedAt: new Date().toISOString(),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function compactList(data, keys, limit = 100) {
|
|
314
|
+
return asArray(data)
|
|
315
|
+
.slice(0, limit)
|
|
316
|
+
.map((value) => pick(value, keys));
|
|
317
|
+
}
|
|
318
|
+
function githubFile(data, owner, repo, ref) {
|
|
319
|
+
const record = asRecord(data) ?? {};
|
|
320
|
+
if (record.type !== "file")
|
|
321
|
+
throw new Error("GitHub path is not a file");
|
|
322
|
+
const encoded = typeof record.content === "string" ? record.content.replace(/\s/g, "") : "";
|
|
323
|
+
const content = encoded ? Buffer.from(encoded, "base64").toString("utf8").slice(0, 262_144) : "";
|
|
324
|
+
return {
|
|
325
|
+
owner,
|
|
326
|
+
repo,
|
|
327
|
+
path: record.path,
|
|
328
|
+
...(ref ? { ref } : {}),
|
|
329
|
+
sha: record.sha,
|
|
330
|
+
size: record.size,
|
|
331
|
+
content,
|
|
332
|
+
truncated: typeof record.size === "number"
|
|
333
|
+
? record.size > Buffer.byteLength(content)
|
|
334
|
+
: content.length >= 262_144,
|
|
335
|
+
html_url: record.html_url,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
async function executeGithubCliAction(actionId, params, options, run) {
|
|
339
|
+
if (actionId === "list_repositories") {
|
|
340
|
+
const limit = intParam(params, "limit", 30, 100);
|
|
341
|
+
const data = await api("github", `user/repos?per_page=${limit}&sort=updated`, options, run);
|
|
342
|
+
return {
|
|
343
|
+
repositories: compactList(data, [
|
|
344
|
+
"id",
|
|
345
|
+
"full_name",
|
|
346
|
+
"description",
|
|
347
|
+
"private",
|
|
348
|
+
"archived",
|
|
349
|
+
"default_branch",
|
|
350
|
+
"html_url",
|
|
351
|
+
"updated_at",
|
|
352
|
+
]),
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
// `gh api` resolves the endpoint against the REST base URL, so dot segments
|
|
356
|
+
// in argv would escape the fixed path template exactly like in a browser URL.
|
|
357
|
+
const owner = pathSegmentParam(params, "owner", { required: true, maxLength: 100 });
|
|
358
|
+
const repo = pathSegmentParam(params, "repo", { required: true, maxLength: 100 });
|
|
359
|
+
const base = `repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}`;
|
|
360
|
+
if (actionId === "get_readme") {
|
|
361
|
+
const result = githubFile(await api("github", `${base}/readme`, options, run), owner, repo);
|
|
362
|
+
return { ...result, size: undefined };
|
|
363
|
+
}
|
|
364
|
+
if (actionId === "get_file") {
|
|
365
|
+
const path = pathParam(params, "path", { required: true, maxLength: 2_000 });
|
|
366
|
+
const ref = stringParam(params, "ref", { maxLength: 300 });
|
|
367
|
+
const endpoint = `${base}/contents/${path}${ref ? `?ref=${encodeURIComponent(ref)}` : ""}`;
|
|
368
|
+
return githubFile(await api("github", endpoint, options, run), owner, repo, ref);
|
|
369
|
+
}
|
|
370
|
+
if (actionId === "list_issues") {
|
|
371
|
+
const limit = intParam(params, "limit", 30, 100);
|
|
372
|
+
const data = asArray(await api("github", `${base}/issues?per_page=${limit}`, options, run));
|
|
373
|
+
return {
|
|
374
|
+
issues: data
|
|
375
|
+
.filter((value) => !asRecord(value)?.pull_request)
|
|
376
|
+
.slice(0, 100)
|
|
377
|
+
.map((value) => pick(value, [
|
|
378
|
+
"number",
|
|
379
|
+
"title",
|
|
380
|
+
"state",
|
|
381
|
+
"html_url",
|
|
382
|
+
"created_at",
|
|
383
|
+
"updated_at",
|
|
384
|
+
"user",
|
|
385
|
+
"labels",
|
|
386
|
+
])),
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
if (actionId === "list_pull_requests") {
|
|
390
|
+
const limit = intParam(params, "limit", 30, 100);
|
|
391
|
+
const data = await api("github", `${base}/pulls?per_page=${limit}`, options, run);
|
|
392
|
+
return {
|
|
393
|
+
pull_requests: compactList(data, [
|
|
394
|
+
"number",
|
|
395
|
+
"title",
|
|
396
|
+
"state",
|
|
397
|
+
"draft",
|
|
398
|
+
"html_url",
|
|
399
|
+
"created_at",
|
|
400
|
+
"updated_at",
|
|
401
|
+
"user",
|
|
402
|
+
"head",
|
|
403
|
+
"base",
|
|
404
|
+
]),
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
if (actionId === "get_issue") {
|
|
408
|
+
const number = intParam(params, "issue_number", 0, Number.MAX_SAFE_INTEGER);
|
|
409
|
+
return pick(await api("github", `${base}/issues/${number}`, options, run), [
|
|
410
|
+
"number",
|
|
411
|
+
"title",
|
|
412
|
+
"body",
|
|
413
|
+
"state",
|
|
414
|
+
"state_reason",
|
|
415
|
+
"html_url",
|
|
416
|
+
"created_at",
|
|
417
|
+
"updated_at",
|
|
418
|
+
"closed_at",
|
|
419
|
+
"user",
|
|
420
|
+
"assignees",
|
|
421
|
+
"labels",
|
|
422
|
+
"milestone",
|
|
423
|
+
"comments",
|
|
424
|
+
]);
|
|
425
|
+
}
|
|
426
|
+
if (actionId === "get_pull_request") {
|
|
427
|
+
const number = intParam(params, "pull_number", 0, Number.MAX_SAFE_INTEGER);
|
|
428
|
+
return pick(await api("github", `${base}/pulls/${number}`, options, run), [
|
|
429
|
+
"number",
|
|
430
|
+
"title",
|
|
431
|
+
"body",
|
|
432
|
+
"state",
|
|
433
|
+
"draft",
|
|
434
|
+
"merged",
|
|
435
|
+
"mergeable",
|
|
436
|
+
"html_url",
|
|
437
|
+
"created_at",
|
|
438
|
+
"updated_at",
|
|
439
|
+
"closed_at",
|
|
440
|
+
"merged_at",
|
|
441
|
+
"user",
|
|
442
|
+
"assignees",
|
|
443
|
+
"requested_reviewers",
|
|
444
|
+
"labels",
|
|
445
|
+
"head",
|
|
446
|
+
"base",
|
|
447
|
+
"commits",
|
|
448
|
+
"additions",
|
|
449
|
+
"deletions",
|
|
450
|
+
"changed_files",
|
|
451
|
+
]);
|
|
452
|
+
}
|
|
453
|
+
if (actionId === "create_issue") {
|
|
454
|
+
const title = stringParam(params, "title", { required: true, maxLength: 256 });
|
|
455
|
+
const body = stringParam(params, "body", { maxLength: 20_000 });
|
|
456
|
+
const data = await api("github", `${base}/issues`, { ...options, method: "POST", input: { title, ...(body ? { body } : {}) } }, run);
|
|
457
|
+
return pick(data, ["number", "title", "state", "html_url", "created_at"]);
|
|
458
|
+
}
|
|
459
|
+
throw new Error(`Unknown GitHub CLI Link Action: ${actionId}`);
|
|
460
|
+
}
|
|
461
|
+
async function executeGitlabCliAction(actionId, params, options, run) {
|
|
462
|
+
const limit = intParam(params, "limit", 30, 100);
|
|
463
|
+
if (actionId === "list_projects") {
|
|
464
|
+
const data = await api("gitlab", `projects?membership=true&simple=true&per_page=${limit}`, options, run);
|
|
465
|
+
return {
|
|
466
|
+
projects: compactList(data, [
|
|
467
|
+
"id",
|
|
468
|
+
"name",
|
|
469
|
+
"path_with_namespace",
|
|
470
|
+
"description",
|
|
471
|
+
"visibility",
|
|
472
|
+
"default_branch",
|
|
473
|
+
"web_url",
|
|
474
|
+
"last_activity_at",
|
|
475
|
+
]),
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
if (actionId === "list_issues") {
|
|
479
|
+
const data = await api("gitlab", `issues?scope=assigned_to_me&per_page=${limit}`, options, run);
|
|
480
|
+
return {
|
|
481
|
+
issues: compactList(data, [
|
|
482
|
+
"id",
|
|
483
|
+
"iid",
|
|
484
|
+
"project_id",
|
|
485
|
+
"title",
|
|
486
|
+
"state",
|
|
487
|
+
"web_url",
|
|
488
|
+
"created_at",
|
|
489
|
+
"updated_at",
|
|
490
|
+
"labels",
|
|
491
|
+
]),
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
throw new Error(`Unknown GitLab CLI Link Action: ${actionId}`);
|
|
495
|
+
}
|
|
496
|
+
async function runJsonCommand(providerId, args, options, run) {
|
|
497
|
+
try {
|
|
498
|
+
return parseJson(await run(providerId, CONFIG[providerId].command, args, {
|
|
499
|
+
...options,
|
|
500
|
+
timeoutMs: 30_000,
|
|
501
|
+
}), providerId);
|
|
502
|
+
}
|
|
503
|
+
catch (error) {
|
|
504
|
+
const message = safeMessage(error);
|
|
505
|
+
throw new Error(message || `${providerId} CLI request failed`, { cause: error });
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
async function executeNotionCliAction(actionId, params, options, run) {
|
|
509
|
+
if (actionId === "search") {
|
|
510
|
+
const query = stringParam(params, "query", { maxLength: 200 });
|
|
511
|
+
const data = asRecord(await api("notion", "v1/search", {
|
|
512
|
+
...options,
|
|
513
|
+
method: "POST",
|
|
514
|
+
input: {
|
|
515
|
+
page_size: intParam(params, "limit", 30, 100),
|
|
516
|
+
...(query ? { query } : {}),
|
|
517
|
+
},
|
|
518
|
+
}, run)) ?? {};
|
|
519
|
+
return {
|
|
520
|
+
results: asArray(data.results)
|
|
521
|
+
.slice(0, 100)
|
|
522
|
+
.map((value) => pick(value, [
|
|
523
|
+
"object",
|
|
524
|
+
"id",
|
|
525
|
+
"url",
|
|
526
|
+
"created_time",
|
|
527
|
+
"last_edited_time",
|
|
528
|
+
"archived",
|
|
529
|
+
"parent",
|
|
530
|
+
"properties",
|
|
531
|
+
"title",
|
|
532
|
+
])),
|
|
533
|
+
has_more: data.has_more,
|
|
534
|
+
next_cursor: data.next_cursor,
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
if (actionId === "get_page") {
|
|
538
|
+
const pageId = pathSegmentParam(params, "page_id", { required: true, maxLength: 100 });
|
|
539
|
+
return pick(await api("notion", `v1/pages/${encodeURIComponent(pageId)}`, options, run), [
|
|
540
|
+
"object",
|
|
541
|
+
"id",
|
|
542
|
+
"url",
|
|
543
|
+
"created_time",
|
|
544
|
+
"last_edited_time",
|
|
545
|
+
"archived",
|
|
546
|
+
"parent",
|
|
547
|
+
"properties",
|
|
548
|
+
]);
|
|
549
|
+
}
|
|
550
|
+
throw new Error(`Unknown Notion CLI Link Action: ${actionId}`);
|
|
551
|
+
}
|
|
552
|
+
function todoistProject(value) {
|
|
553
|
+
const project = asRecord(value) ?? {};
|
|
554
|
+
return {
|
|
555
|
+
...pick(project, ["id", "name", "description", "color", "url"]),
|
|
556
|
+
...(typeof project.isFavorite === "boolean" ? { is_favorite: project.isFavorite } : {}),
|
|
557
|
+
...(typeof project.parentId === "string" ? { parent_id: project.parentId } : {}),
|
|
558
|
+
...(typeof project.workspaceId === "string" ? { workspace_id: project.workspaceId } : {}),
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function todoistTask(value) {
|
|
562
|
+
const task = asRecord(value) ?? {};
|
|
563
|
+
return {
|
|
564
|
+
...pick(task, ["id", "content", "description", "priority", "due", "labels", "url"]),
|
|
565
|
+
...(typeof task.projectId === "string" ? { project_id: task.projectId } : {}),
|
|
566
|
+
...(typeof task.sectionId === "string" ? { section_id: task.sectionId } : {}),
|
|
567
|
+
...(typeof task.parentId === "string" ? { parent_id: task.parentId } : {}),
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
async function executeTodoistCliAction(actionId, params, options, run) {
|
|
571
|
+
const limit = intParam(params, "limit", actionId === "list_tasks" ? 50 : 30, 100);
|
|
572
|
+
if (actionId === "list_projects") {
|
|
573
|
+
const root = asRecord(await runJsonCommand("todoist", ["project", "list", "--json", "--limit", String(limit)], options, run)) ?? {};
|
|
574
|
+
return { projects: asArray(root.results).slice(0, 100).map(todoistProject) };
|
|
575
|
+
}
|
|
576
|
+
if (actionId === "list_tasks") {
|
|
577
|
+
const root = asRecord(await runJsonCommand("todoist", ["task", "list", "--json", "--limit", String(limit)], options, run)) ?? {};
|
|
578
|
+
return {
|
|
579
|
+
tasks: asArray(root.results).slice(0, 100).map(todoistTask),
|
|
580
|
+
next_cursor: root.nextCursor,
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
throw new Error(`Unknown Todoist CLI Link Action: ${actionId}`);
|
|
584
|
+
}
|
|
585
|
+
async function executeVercelCliAction(actionId, params, options, run) {
|
|
586
|
+
const limit = intParam(params, "limit", 50, 100);
|
|
587
|
+
const teamId = stringParam(params, "team_id", { maxLength: 100 });
|
|
588
|
+
const query = new URLSearchParams({ limit: String(limit) });
|
|
589
|
+
if (teamId)
|
|
590
|
+
query.set("teamId", teamId);
|
|
591
|
+
if (actionId === "list_projects") {
|
|
592
|
+
const root = asRecord(await api("vercel", `/v10/projects?${query}`, options, run)) ?? {};
|
|
593
|
+
return {
|
|
594
|
+
projects: compactList(root.projects, ["id", "name", "framework", "updatedAt", "createdAt", "latestDeployments"], 100),
|
|
595
|
+
pagination: root.pagination,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
if (actionId === "list_deployments") {
|
|
599
|
+
const root = asRecord(await api("vercel", `/v7/deployments?${query}`, options, run)) ?? {};
|
|
600
|
+
return {
|
|
601
|
+
deployments: compactList(root.deployments, ["uid", "name", "url", "state", "target", "created", "ready", "meta"], 100),
|
|
602
|
+
pagination: root.pagination,
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
throw new Error(`Unknown Vercel CLI Link Action: ${actionId}`);
|
|
606
|
+
}
|
|
607
|
+
export async function executeCliLinkAction(providerId, actionId, params, options = {}, run = runCliLinkCommand) {
|
|
608
|
+
if (providerId === "github")
|
|
609
|
+
return executeGithubCliAction(actionId, params, options, run);
|
|
610
|
+
if (providerId === "gitlab")
|
|
611
|
+
return executeGitlabCliAction(actionId, params, options, run);
|
|
612
|
+
if (providerId === "notion")
|
|
613
|
+
return executeNotionCliAction(actionId, params, options, run);
|
|
614
|
+
if (providerId === "todoist")
|
|
615
|
+
return executeTodoistCliAction(actionId, params, options, run);
|
|
616
|
+
return executeVercelCliAction(actionId, params, options, run);
|
|
617
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface LinkHttpRequest {
|
|
2
|
+
url: URL;
|
|
3
|
+
method?: "GET" | "POST";
|
|
4
|
+
headers: Record<string, string>;
|
|
5
|
+
body?: unknown;
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
fetchImpl?: typeof fetch;
|
|
8
|
+
}
|
|
9
|
+
export declare function linkRequestJson(request: LinkHttpRequest): Promise<unknown>;
|
|
10
|
+
export declare function asRecord(value: unknown): Record<string, unknown> | undefined;
|
|
11
|
+
export declare function asArray(value: unknown): unknown[];
|
|
12
|
+
export declare function firstString(...values: unknown[]): string | undefined;
|
|
13
|
+
export declare function stringParam(params: Record<string, unknown>, key: string, options?: {
|
|
14
|
+
required?: boolean;
|
|
15
|
+
maxLength?: number;
|
|
16
|
+
}): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Values interpolated into a fixed URL path template must never move the
|
|
19
|
+
* request to another endpoint. `encodeURIComponent` does not neutralize
|
|
20
|
+
* `.`/`..`, and both `new URL()` and CLI backends like `gh api` normalize dot
|
|
21
|
+
* segments away, so `organization: ".."` would otherwise turn
|
|
22
|
+
* `/organizations/../projects/` into `/projects/`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function assertPathSegment(value: string, key: string): string;
|
|
25
|
+
/** A string param used as exactly one segment of a URL path template. */
|
|
26
|
+
export declare function pathSegmentParam(params: Record<string, unknown>, key: string, options?: {
|
|
27
|
+
required?: boolean;
|
|
28
|
+
maxLength?: number;
|
|
29
|
+
}): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* A slash-separated resource path (e.g. a file path inside a repository).
|
|
32
|
+
* Every segment is validated like assertPathSegment and encoded individually;
|
|
33
|
+
* the returned string is ready to interpolate into a URL path template.
|
|
34
|
+
*/
|
|
35
|
+
export declare function pathParam(params: Record<string, unknown>, key: string, options?: {
|
|
36
|
+
required?: boolean;
|
|
37
|
+
maxLength?: number;
|
|
38
|
+
}): string | undefined;
|
|
39
|
+
export declare function intParam(params: Record<string, unknown>, key: string, fallback: number, max: number): number;
|
|
40
|
+
export declare function pick(record: unknown, keys: readonly string[]): Record<string, unknown>;
|