@kenkaiiii/gg-engine 0.0.0-stage → 7.1.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 +661 -0
- package/NOTICE +43 -0
- package/README.md +53 -2
- package/assets/skills/bulletproof/SKILL.md +132 -0
- package/assets/skills/bulletproof/references/agent-surface.md +113 -0
- package/assets/skills/bulletproof/references/attack-classes.md +226 -0
- package/assets/skills/bulletproof/references/audit-protocol.md +232 -0
- package/assets/skills/bulletproof/references/platform-playbooks.md +196 -0
- package/assets/skills/bulletproof/references/provenance.md +146 -0
- package/assets/skills/bulletproof/references/secure-defaults.md +137 -0
- package/assets/skills/bulletproof/references/supply-chain.md +84 -0
- package/assets/skills/bulletproof/references/threat-landscape.md +66 -0
- package/assets/skills/bulletproof/references/verification.md +74 -0
- package/assets/skills/compliance-guard/SKILL.md +115 -0
- package/assets/skills/compliance-guard/references/artifacts.md +199 -0
- package/assets/skills/compliance-guard/references/eu-uk.md +162 -0
- package/assets/skills/compliance-guard/references/exposure-triage.md +177 -0
- package/assets/skills/compliance-guard/references/full-review.md +155 -0
- package/assets/skills/compliance-guard/references/lawsuit-vectors.md +153 -0
- package/assets/skills/compliance-guard/references/provenance.md +135 -0
- package/assets/skills/compliance-guard/references/sector-gates.md +187 -0
- package/assets/skills/compliance-guard/references/security-baseline.md +117 -0
- package/assets/skills/compliance-guard/references/trigger-map.md +177 -0
- package/assets/skills/compliance-guard/references/us.md +194 -0
- package/assets/skills/durable/SKILL.md +114 -0
- package/assets/skills/durable/references/agent-db-safety.md +76 -0
- package/assets/skills/durable/references/backups-and-runtime.md +93 -0
- package/assets/skills/durable/references/migrations-and-schema.md +87 -0
- package/assets/skills/gg-guide/SKILL.md +43 -0
- package/assets/skills/gg-guide/references/chat-motion-goals.md +217 -0
- package/assets/skills/gg-guide/references/checklist-and-safety.md +177 -0
- package/assets/skills/gg-guide/references/code-mode.md +272 -0
- package/assets/skills/gg-guide/references/getting-started.md +295 -0
- package/assets/skills/gg-guide/references/ken-and-autopilot.md +172 -0
- package/assets/skills/gg-guide/references/mcp-and-skills.md +204 -0
- package/assets/skills/gg-guide/references/models-and-sign-in.md +200 -0
- package/assets/skills/gg-guide/references/sessions-and-history.md +213 -0
- package/assets/skills/gg-guide/references/settings.md +193 -0
- package/assets/skills/gg-guide/references/troubleshooting-and-data.md +186 -0
- package/assets/skills/lean/SKILL.md +117 -0
- package/assets/skills/lean/references/memory-and-processes.md +99 -0
- package/assets/skills/lean/references/playbooks.md +134 -0
- package/dist/app-error.d.ts +22 -0
- package/dist/app-error.js +41 -0
- package/dist/app-error.js.map +1 -0
- package/dist/config.d.ts +90 -0
- package/dist/config.js +240 -0
- package/dist/config.js.map +1 -0
- package/dist/core/acceptance-checks.d.ts +48 -0
- package/dist/core/acceptance-checks.js +151 -0
- package/dist/core/acceptance-checks.js.map +1 -0
- package/dist/core/action-threats.d.ts +68 -0
- package/dist/core/action-threats.js +894 -0
- package/dist/core/action-threats.js.map +1 -0
- package/dist/core/agent-notifications.d.ts +79 -0
- package/dist/core/agent-notifications.js +125 -0
- package/dist/core/agent-notifications.js.map +1 -0
- package/dist/core/agent-session/helpers.d.ts +26 -0
- package/dist/core/agent-session/helpers.js +47 -0
- package/dist/core/agent-session/helpers.js.map +1 -0
- package/dist/core/agent-session/mcp-tools.d.ts +87 -0
- package/dist/core/agent-session/mcp-tools.js +227 -0
- package/dist/core/agent-session/mcp-tools.js.map +1 -0
- package/dist/core/agent-session/run-loop-monitor.d.ts +63 -0
- package/dist/core/agent-session/run-loop-monitor.js +164 -0
- package/dist/core/agent-session/run-loop-monitor.js.map +1 -0
- package/dist/core/agent-session/transcript-markers.d.ts +57 -0
- package/dist/core/agent-session/transcript-markers.js +166 -0
- package/dist/core/agent-session/transcript-markers.js.map +1 -0
- package/dist/core/agent-session/verification-tracker.d.ts +71 -0
- package/dist/core/agent-session/verification-tracker.js +295 -0
- package/dist/core/agent-session/verification-tracker.js.map +1 -0
- package/dist/core/agent-session.d.ts +1401 -0
- package/dist/core/agent-session.js +5160 -0
- package/dist/core/agent-session.js.map +1 -0
- package/dist/core/agents.d.ts +63 -0
- package/dist/core/agents.js +160 -0
- package/dist/core/agents.js.map +1 -0
- package/dist/core/ask-user.d.ts +163 -0
- package/dist/core/ask-user.js +178 -0
- package/dist/core/ask-user.js.map +1 -0
- package/dist/core/auto-update.d.ts +32 -0
- package/dist/core/auto-update.js +218 -0
- package/dist/core/auto-update.js.map +1 -0
- package/dist/core/autopilot-cycle.d.ts +127 -0
- package/dist/core/autopilot-cycle.js +182 -0
- package/dist/core/autopilot-cycle.js.map +1 -0
- package/dist/core/autopilot-gate.d.ts +106 -0
- package/dist/core/autopilot-gate.js +192 -0
- package/dist/core/autopilot-gate.js.map +1 -0
- package/dist/core/autopilot-verdict.d.ts +55 -0
- package/dist/core/autopilot-verdict.js +226 -0
- package/dist/core/autopilot-verdict.js.map +1 -0
- package/dist/core/blocked-packages-file.d.ts +33 -0
- package/dist/core/blocked-packages-file.js +274 -0
- package/dist/core/blocked-packages-file.js.map +1 -0
- package/dist/core/bundled-agents.d.ts +2 -0
- package/dist/core/bundled-agents.js +253 -0
- package/dist/core/bundled-agents.js.map +1 -0
- package/dist/core/cache-diagnostics.d.ts +72 -0
- package/dist/core/cache-diagnostics.js +200 -0
- package/dist/core/cache-diagnostics.js.map +1 -0
- package/dist/core/cache-expiry.d.ts +89 -0
- package/dist/core/cache-expiry.js +117 -0
- package/dist/core/cache-expiry.js.map +1 -0
- package/dist/core/checklist-detection.d.ts +8 -0
- package/dist/core/checklist-detection.js +238 -0
- package/dist/core/checklist-detection.js.map +1 -0
- package/dist/core/checklist-git.d.ts +19 -0
- package/dist/core/checklist-git.js +54 -0
- package/dist/core/checklist-git.js.map +1 -0
- package/dist/core/checklist-items.d.ts +182 -0
- package/dist/core/checklist-items.js +228 -0
- package/dist/core/checklist-items.js.map +1 -0
- package/dist/core/checklist-prompt.d.ts +14 -0
- package/dist/core/checklist-prompt.js +64 -0
- package/dist/core/checklist-prompt.js.map +1 -0
- package/dist/core/checklist-snapshot.d.ts +7 -0
- package/dist/core/checklist-snapshot.js +46 -0
- package/dist/core/checklist-snapshot.js.map +1 -0
- package/dist/core/checklist-store.d.ts +45 -0
- package/dist/core/checklist-store.js +281 -0
- package/dist/core/checklist-store.js.map +1 -0
- package/dist/core/checkout-record.d.ts +22 -0
- package/dist/core/checkout-record.js +68 -0
- package/dist/core/checkout-record.js.map +1 -0
- package/dist/core/checkpoint-store.d.ts +109 -0
- package/dist/core/checkpoint-store.js +260 -0
- package/dist/core/checkpoint-store.js.map +1 -0
- package/dist/core/claude-code/complete.d.ts +35 -0
- package/dist/core/claude-code/complete.js +125 -0
- package/dist/core/claude-code/complete.js.map +1 -0
- package/dist/core/claude-code/events.d.ts +67 -0
- package/dist/core/claude-code/events.js +460 -0
- package/dist/core/claude-code/events.js.map +1 -0
- package/dist/core/claude-code/live-session.d.ts +94 -0
- package/dist/core/claude-code/live-session.js +525 -0
- package/dist/core/claude-code/live-session.js.map +1 -0
- package/dist/core/claude-code/loop.d.ts +9 -0
- package/dist/core/claude-code/loop.js +15 -0
- package/dist/core/claude-code/loop.js.map +1 -0
- package/dist/core/claude-code/session-sync.d.ts +28 -0
- package/dist/core/claude-code/session-sync.js +53 -0
- package/dist/core/claude-code/session-sync.js.map +1 -0
- package/dist/core/claude-code/tool-bridge.d.ts +49 -0
- package/dist/core/claude-code/tool-bridge.js +352 -0
- package/dist/core/claude-code/tool-bridge.js.map +1 -0
- package/dist/core/claude-code/transcripts.d.ts +39 -0
- package/dist/core/claude-code/transcripts.js +195 -0
- package/dist/core/claude-code/transcripts.js.map +1 -0
- package/dist/core/code-retrieval-chunkers.d.ts +26 -0
- package/dist/core/code-retrieval-chunkers.js +264 -0
- package/dist/core/code-retrieval-chunkers.js.map +1 -0
- package/dist/core/code-retrieval.d.ts +18 -0
- package/dist/core/code-retrieval.js +124 -0
- package/dist/core/code-retrieval.js.map +1 -0
- package/dist/core/codex-request-shape.d.ts +7 -0
- package/dist/core/codex-request-shape.js +19 -0
- package/dist/core/codex-request-shape.js.map +1 -0
- package/dist/core/compaction/active-context.d.ts +16 -0
- package/dist/core/compaction/active-context.js +20 -0
- package/dist/core/compaction/active-context.js.map +1 -0
- package/dist/core/compaction/compactor.d.ts +281 -0
- package/dist/core/compaction/compactor.js +1451 -0
- package/dist/core/compaction/compactor.js.map +1 -0
- package/dist/core/compaction/plan-step-policy.d.ts +46 -0
- package/dist/core/compaction/plan-step-policy.js +57 -0
- package/dist/core/compaction/plan-step-policy.js.map +1 -0
- package/dist/core/compaction/policy.d.ts +36 -0
- package/dist/core/compaction/policy.js +144 -0
- package/dist/core/compaction/policy.js.map +1 -0
- package/dist/core/compaction/query-aware-selector.d.ts +32 -0
- package/dist/core/compaction/query-aware-selector.js +202 -0
- package/dist/core/compaction/query-aware-selector.js.map +1 -0
- package/dist/core/compaction/token-estimator.d.ts +36 -0
- package/dist/core/compaction/token-estimator.js +180 -0
- package/dist/core/compaction/token-estimator.js.map +1 -0
- package/dist/core/compaction/tool-result-pruner.d.ts +90 -0
- package/dist/core/compaction/tool-result-pruner.js +238 -0
- package/dist/core/compaction/tool-result-pruner.js.map +1 -0
- package/dist/core/completion-review.d.ts +24 -0
- package/dist/core/completion-review.js +2 -0
- package/dist/core/completion-review.js.map +1 -0
- package/dist/core/context-files.d.ts +8 -0
- package/dist/core/context-files.js +46 -0
- package/dist/core/context-files.js.map +1 -0
- package/dist/core/context-limits.d.ts +40 -0
- package/dist/core/context-limits.js +43 -0
- package/dist/core/context-limits.js.map +1 -0
- package/dist/core/custom-commands.d.ts +18 -0
- package/dist/core/custom-commands.js +57 -0
- package/dist/core/custom-commands.js.map +1 -0
- package/dist/core/destructive-git-guard.d.ts +113 -0
- package/dist/core/destructive-git-guard.js +874 -0
- package/dist/core/destructive-git-guard.js.map +1 -0
- package/dist/core/display-items.d.ts +8 -0
- package/dist/core/display-items.js +2 -0
- package/dist/core/display-items.js.map +1 -0
- package/dist/core/encode-cwd.d.ts +41 -0
- package/dist/core/encode-cwd.js +53 -0
- package/dist/core/encode-cwd.js.map +1 -0
- package/dist/core/env-delta.d.ts +34 -0
- package/dist/core/env-delta.js +84 -0
- package/dist/core/env-delta.js.map +1 -0
- package/dist/core/event-bus.d.ts +178 -0
- package/dist/core/event-bus.js +171 -0
- package/dist/core/event-bus.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +7 -0
- package/dist/core/extensions/loader.js +68 -0
- package/dist/core/extensions/loader.js.map +1 -0
- package/dist/core/extensions/plugin-bundles.d.ts +13 -0
- package/dist/core/extensions/plugin-bundles.js +45 -0
- package/dist/core/extensions/plugin-bundles.js.map +1 -0
- package/dist/core/extensions/types.d.ts +18 -0
- package/dist/core/extensions/types.js +2 -0
- package/dist/core/extensions/types.js.map +1 -0
- package/dist/core/foreign-session-import.d.ts +119 -0
- package/dist/core/foreign-session-import.js +598 -0
- package/dist/core/foreign-session-import.js.map +1 -0
- package/dist/core/foreign-transcript-blocks.d.ts +50 -0
- package/dist/core/foreign-transcript-blocks.js +151 -0
- package/dist/core/foreign-transcript-blocks.js.map +1 -0
- package/dist/core/frontmatter.d.ts +22 -0
- package/dist/core/frontmatter.js +90 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/goal-run-marker.d.ts +32 -0
- package/dist/core/goal-run-marker.js +178 -0
- package/dist/core/goal-run-marker.js.map +1 -0
- package/dist/core/goal-summary.d.ts +15 -0
- package/dist/core/goal-summary.js +110 -0
- package/dist/core/goal-summary.js.map +1 -0
- package/dist/core/goals-store.d.ts +208 -0
- package/dist/core/goals-store.js +577 -0
- package/dist/core/goals-store.js.map +1 -0
- package/dist/core/hashline.d.ts +51 -0
- package/dist/core/hashline.js +76 -0
- package/dist/core/hashline.js.map +1 -0
- package/dist/core/idle-wake.d.ts +62 -0
- package/dist/core/idle-wake.js +103 -0
- package/dist/core/idle-wake.js.map +1 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/injection-detect.d.ts +39 -0
- package/dist/core/injection-detect.js +241 -0
- package/dist/core/injection-detect.js.map +1 -0
- package/dist/core/installed-threats.d.ts +23 -0
- package/dist/core/installed-threats.js +71 -0
- package/dist/core/installed-threats.js.map +1 -0
- package/dist/core/internal-diagnostics.d.ts +159 -0
- package/dist/core/internal-diagnostics.js +495 -0
- package/dist/core/internal-diagnostics.js.map +1 -0
- package/dist/core/keep-awake.d.ts +88 -0
- package/dist/core/keep-awake.js +251 -0
- package/dist/core/keep-awake.js.map +1 -0
- package/dist/core/ken-ask-answer.d.ts +24 -0
- package/dist/core/ken-ask-answer.js +96 -0
- package/dist/core/ken-ask-answer.js.map +1 -0
- package/dist/core/ken-context.d.ts +119 -0
- package/dist/core/ken-context.js +447 -0
- package/dist/core/ken-context.js.map +1 -0
- package/dist/core/ken-model.d.ts +45 -0
- package/dist/core/ken-model.js +26 -0
- package/dist/core/ken-model.js.map +1 -0
- package/dist/core/ken-prompt.d.ts +21 -0
- package/dist/core/ken-prompt.js +370 -0
- package/dist/core/ken-prompt.js.map +1 -0
- package/dist/core/language-detector.d.ts +41 -0
- package/dist/core/language-detector.js +293 -0
- package/dist/core/language-detector.js.map +1 -0
- package/dist/core/live-preview.d.ts +26 -0
- package/dist/core/live-preview.js +80 -0
- package/dist/core/live-preview.js.map +1 -0
- package/dist/core/local-endpoint-store.d.ts +53 -0
- package/dist/core/local-endpoint-store.js +221 -0
- package/dist/core/local-endpoint-store.js.map +1 -0
- package/dist/core/logger.d.ts +21 -0
- package/dist/core/logger.js +94 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/loop-breaker.d.ts +89 -0
- package/dist/core/loop-breaker.js +204 -0
- package/dist/core/loop-breaker.js.map +1 -0
- package/dist/core/lsp/client.d.ts +206 -0
- package/dist/core/lsp/client.js +685 -0
- package/dist/core/lsp/client.js.map +1 -0
- package/dist/core/lsp/edit-telemetry.d.ts +26 -0
- package/dist/core/lsp/edit-telemetry.js +52 -0
- package/dist/core/lsp/edit-telemetry.js.map +1 -0
- package/dist/core/lsp/format.d.ts +11 -0
- package/dist/core/lsp/format.js +30 -0
- package/dist/core/lsp/format.js.map +1 -0
- package/dist/core/lsp/jsonrpc.d.ts +68 -0
- package/dist/core/lsp/jsonrpc.js +153 -0
- package/dist/core/lsp/jsonrpc.js.map +1 -0
- package/dist/core/lsp/manager.d.ts +188 -0
- package/dist/core/lsp/manager.js +576 -0
- package/dist/core/lsp/manager.js.map +1 -0
- package/dist/core/lsp/pool.d.ts +114 -0
- package/dist/core/lsp/pool.js +259 -0
- package/dist/core/lsp/pool.js.map +1 -0
- package/dist/core/lsp/project-root.d.ts +9 -0
- package/dist/core/lsp/project-root.js +75 -0
- package/dist/core/lsp/project-root.js.map +1 -0
- package/dist/core/lsp/reference-project.d.ts +6 -0
- package/dist/core/lsp/reference-project.js +110 -0
- package/dist/core/lsp/reference-project.js.map +1 -0
- package/dist/core/lsp/servers.d.ts +44 -0
- package/dist/core/lsp/servers.js +289 -0
- package/dist/core/lsp/servers.js.map +1 -0
- package/dist/core/lsp/test-support.d.ts +17 -0
- package/dist/core/lsp/test-support.js +27 -0
- package/dist/core/lsp/test-support.js.map +1 -0
- package/dist/core/mcp/catalog-cache.d.ts +64 -0
- package/dist/core/mcp/catalog-cache.js +166 -0
- package/dist/core/mcp/catalog-cache.js.map +1 -0
- package/dist/core/mcp/client.d.ts +317 -0
- package/dist/core/mcp/client.js +1168 -0
- package/dist/core/mcp/client.js.map +1 -0
- package/dist/core/mcp/content.d.ts +23 -0
- package/dist/core/mcp/content.js +194 -0
- package/dist/core/mcp/content.js.map +1 -0
- package/dist/core/mcp/defaults.d.ts +26 -0
- package/dist/core/mcp/defaults.js +81 -0
- package/dist/core/mcp/defaults.js.map +1 -0
- package/dist/core/mcp/deferred-catalog.d.ts +53 -0
- package/dist/core/mcp/deferred-catalog.js +117 -0
- package/dist/core/mcp/deferred-catalog.js.map +1 -0
- package/dist/core/mcp/elicitation-bridge.d.ts +40 -0
- package/dist/core/mcp/elicitation-bridge.js +36 -0
- package/dist/core/mcp/elicitation-bridge.js.map +1 -0
- package/dist/core/mcp/index.d.ts +16 -0
- package/dist/core/mcp/index.js +10 -0
- package/dist/core/mcp/index.js.map +1 -0
- package/dist/core/mcp/loopback.d.ts +26 -0
- package/dist/core/mcp/loopback.js +66 -0
- package/dist/core/mcp/loopback.js.map +1 -0
- package/dist/core/mcp/oauth-provider.d.ts +55 -0
- package/dist/core/mcp/oauth-provider.js +106 -0
- package/dist/core/mcp/oauth-provider.js.map +1 -0
- package/dist/core/mcp/oauth-store.d.ts +44 -0
- package/dist/core/mcp/oauth-store.js +76 -0
- package/dist/core/mcp/oauth-store.js.map +1 -0
- package/dist/core/mcp/parse-add-command.d.ts +50 -0
- package/dist/core/mcp/parse-add-command.js +391 -0
- package/dist/core/mcp/parse-add-command.js.map +1 -0
- package/dist/core/mcp/resolve-stdio.d.ts +77 -0
- package/dist/core/mcp/resolve-stdio.js +359 -0
- package/dist/core/mcp/resolve-stdio.js.map +1 -0
- package/dist/core/mcp/shared-pool.d.ts +157 -0
- package/dist/core/mcp/shared-pool.js +236 -0
- package/dist/core/mcp/shared-pool.js.map +1 -0
- package/dist/core/mcp/store.d.ts +100 -0
- package/dist/core/mcp/store.js +202 -0
- package/dist/core/mcp/store.js.map +1 -0
- package/dist/core/mcp/tool-guard.d.ts +58 -0
- package/dist/core/mcp/tool-guard.js +215 -0
- package/dist/core/mcp/tool-guard.js.map +1 -0
- package/dist/core/mcp/types.d.ts +57 -0
- package/dist/core/mcp/types.js +2 -0
- package/dist/core/mcp/types.js.map +1 -0
- package/dist/core/message-images.d.ts +11 -0
- package/dist/core/message-images.js +52 -0
- package/dist/core/message-images.js.map +1 -0
- package/dist/core/model-unavailable.d.ts +14 -0
- package/dist/core/model-unavailable.js +23 -0
- package/dist/core/model-unavailable.js.map +1 -0
- package/dist/core/network-guard.d.ts +28 -0
- package/dist/core/network-guard.js +251 -0
- package/dist/core/network-guard.js.map +1 -0
- package/dist/core/node-debugger.d.ts +148 -0
- package/dist/core/node-debugger.js +642 -0
- package/dist/core/node-debugger.js.map +1 -0
- package/dist/core/opencode-catalog-store.d.ts +20 -0
- package/dist/core/opencode-catalog-store.js +82 -0
- package/dist/core/opencode-catalog-store.js.map +1 -0
- package/dist/core/openrouter-catalog-store.d.ts +24 -0
- package/dist/core/openrouter-catalog-store.js +140 -0
- package/dist/core/openrouter-catalog-store.js.map +1 -0
- package/dist/core/package-cooldown.d.ts +69 -0
- package/dist/core/package-cooldown.js +297 -0
- package/dist/core/package-cooldown.js.map +1 -0
- package/dist/core/package-threats.d.ts +92 -0
- package/dist/core/package-threats.js +1339 -0
- package/dist/core/package-threats.js.map +1 -0
- package/dist/core/parked-requests.d.ts +43 -0
- package/dist/core/parked-requests.js +34 -0
- package/dist/core/parked-requests.js.map +1 -0
- package/dist/core/persistent-shell.d.ts +81 -0
- package/dist/core/persistent-shell.js +452 -0
- package/dist/core/persistent-shell.js.map +1 -0
- package/dist/core/plan-delta.d.ts +23 -0
- package/dist/core/plan-delta.js +36 -0
- package/dist/core/plan-delta.js.map +1 -0
- package/dist/core/plan-handoff.d.ts +38 -0
- package/dist/core/plan-handoff.js +21 -0
- package/dist/core/plan-handoff.js.map +1 -0
- package/dist/core/plan-submission-gate.d.ts +28 -0
- package/dist/core/plan-submission-gate.js +27 -0
- package/dist/core/plan-submission-gate.js.map +1 -0
- package/dist/core/platform-clis.d.ts +15 -0
- package/dist/core/platform-clis.js +299 -0
- package/dist/core/platform-clis.js.map +1 -0
- package/dist/core/process-gate.d.ts +61 -0
- package/dist/core/process-gate.js +103 -0
- package/dist/core/process-gate.js.map +1 -0
- package/dist/core/process-manager.d.ts +242 -0
- package/dist/core/process-manager.js +902 -0
- package/dist/core/process-manager.js.map +1 -0
- package/dist/core/progress/engine.d.ts +22 -0
- package/dist/core/progress/engine.js +131 -0
- package/dist/core/progress/engine.js.map +1 -0
- package/dist/core/progress/git-xp.d.ts +15 -0
- package/dist/core/progress/git-xp.js +100 -0
- package/dist/core/progress/git-xp.js.map +1 -0
- package/dist/core/progress/ranks.d.ts +31 -0
- package/dist/core/progress/ranks.js +310 -0
- package/dist/core/progress/ranks.js.map +1 -0
- package/dist/core/progress/rebuild.d.ts +8 -0
- package/dist/core/progress/rebuild.js +125 -0
- package/dist/core/progress/rebuild.js.map +1 -0
- package/dist/core/progress/store.d.ts +34 -0
- package/dist/core/progress/store.js +200 -0
- package/dist/core/progress/store.js.map +1 -0
- package/dist/core/progress/types.d.ts +56 -0
- package/dist/core/progress/types.js +2 -0
- package/dist/core/progress/types.js.map +1 -0
- package/dist/core/project-discovery.d.ts +64 -0
- package/dist/core/project-discovery.js +908 -0
- package/dist/core/project-discovery.js.map +1 -0
- package/dist/core/project-files.d.ts +15 -0
- package/dist/core/project-files.js +37 -0
- package/dist/core/project-files.js.map +1 -0
- package/dist/core/project-health-scan.d.ts +109 -0
- package/dist/core/project-health-scan.js +673 -0
- package/dist/core/project-health-scan.js.map +1 -0
- package/dist/core/project-health-score.d.ts +41 -0
- package/dist/core/project-health-score.js +257 -0
- package/dist/core/project-health-score.js.map +1 -0
- package/dist/core/prompt-command-expansion.d.ts +13 -0
- package/dist/core/prompt-command-expansion.js +48 -0
- package/dist/core/prompt-command-expansion.js.map +1 -0
- package/dist/core/prompt-commands.d.ts +13 -0
- package/dist/core/prompt-commands.js +370 -0
- package/dist/core/prompt-commands.js.map +1 -0
- package/dist/core/pull-requests.d.ts +18 -0
- package/dist/core/pull-requests.js +95 -0
- package/dist/core/pull-requests.js.map +1 -0
- package/dist/core/radio-players.d.ts +28 -0
- package/dist/core/radio-players.js +132 -0
- package/dist/core/radio-players.js.map +1 -0
- package/dist/core/radio.d.ts +42 -0
- package/dist/core/radio.js +499 -0
- package/dist/core/radio.js.map +1 -0
- package/dist/core/regrounding.d.ts +37 -0
- package/dist/core/regrounding.js +89 -0
- package/dist/core/regrounding.js.map +1 -0
- package/dist/core/resolve-start.d.ts +28 -0
- package/dist/core/resolve-start.js +35 -0
- package/dist/core/resolve-start.js.map +1 -0
- package/dist/core/run-claim.d.ts +36 -0
- package/dist/core/run-claim.js +46 -0
- package/dist/core/run-claim.js.map +1 -0
- package/dist/core/run-lifecycle.d.ts +58 -0
- package/dist/core/run-lifecycle.js +104 -0
- package/dist/core/run-lifecycle.js.map +1 -0
- package/dist/core/run-status.d.ts +17 -0
- package/dist/core/run-status.js +28 -0
- package/dist/core/run-status.js.map +1 -0
- package/dist/core/runtime-mode.d.ts +21 -0
- package/dist/core/runtime-mode.js +43 -0
- package/dist/core/runtime-mode.js.map +1 -0
- package/dist/core/sandbox-domains.d.ts +13 -0
- package/dist/core/sandbox-domains.js +76 -0
- package/dist/core/sandbox-domains.js.map +1 -0
- package/dist/core/sandbox-feedback.d.ts +21 -0
- package/dist/core/sandbox-feedback.js +69 -0
- package/dist/core/sandbox-feedback.js.map +1 -0
- package/dist/core/sandbox.d.ts +106 -0
- package/dist/core/sandbox.js +383 -0
- package/dist/core/sandbox.js.map +1 -0
- package/dist/core/semantic-loop-check.d.ts +58 -0
- package/dist/core/semantic-loop-check.js +103 -0
- package/dist/core/semantic-loop-check.js.map +1 -0
- package/dist/core/session-compaction.d.ts +23 -0
- package/dist/core/session-compaction.js +54 -0
- package/dist/core/session-compaction.js.map +1 -0
- package/dist/core/session-export.d.ts +97 -0
- package/dist/core/session-export.js +368 -0
- package/dist/core/session-export.js.map +1 -0
- package/dist/core/session-history.d.ts +160 -0
- package/dist/core/session-history.js +467 -0
- package/dist/core/session-history.js.map +1 -0
- package/dist/core/session-manager.d.ts +512 -0
- package/dist/core/session-manager.js +1370 -0
- package/dist/core/session-manager.js.map +1 -0
- package/dist/core/session-preview.d.ts +12 -0
- package/dist/core/session-preview.js +58 -0
- package/dist/core/session-preview.js.map +1 -0
- package/dist/core/session-storage.d.ts +78 -0
- package/dist/core/session-storage.js +659 -0
- package/dist/core/session-storage.js.map +1 -0
- package/dist/core/session-summary-index.d.ts +51 -0
- package/dist/core/session-summary-index.js +192 -0
- package/dist/core/session-summary-index.js.map +1 -0
- package/dist/core/settings-manager.d.ts +113 -0
- package/dist/core/settings-manager.js +281 -0
- package/dist/core/settings-manager.js.map +1 -0
- package/dist/core/shared-checkout-guard.d.ts +78 -0
- package/dist/core/shared-checkout-guard.js +219 -0
- package/dist/core/shared-checkout-guard.js.map +1 -0
- package/dist/core/shell-path.d.ts +13 -0
- package/dist/core/shell-path.js +175 -0
- package/dist/core/shell-path.js.map +1 -0
- package/dist/core/shell-threats-popular-packages.d.ts +11 -0
- package/dist/core/shell-threats-popular-packages.js +675 -0
- package/dist/core/shell-threats-popular-packages.js.map +1 -0
- package/dist/core/shell-threats.d.ts +21 -0
- package/dist/core/shell-threats.js +235 -0
- package/dist/core/shell-threats.js.map +1 -0
- package/dist/core/shell.d.ts +54 -0
- package/dist/core/shell.js +99 -0
- package/dist/core/shell.js.map +1 -0
- package/dist/core/shutdown.d.ts +70 -0
- package/dist/core/shutdown.js +144 -0
- package/dist/core/shutdown.js.map +1 -0
- package/dist/core/skill-scan.d.ts +112 -0
- package/dist/core/skill-scan.js +781 -0
- package/dist/core/skill-scan.js.map +1 -0
- package/dist/core/skills.d.ts +80 -0
- package/dist/core/skills.js +270 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/slash-commands.d.ts +58 -0
- package/dist/core/slash-commands.js +242 -0
- package/dist/core/slash-commands.js.map +1 -0
- package/dist/core/steering.d.ts +47 -0
- package/dist/core/steering.js +65 -0
- package/dist/core/steering.js.map +1 -0
- package/dist/core/steroids.d.ts +66 -0
- package/dist/core/steroids.js +243 -0
- package/dist/core/steroids.js.map +1 -0
- package/dist/core/stream-diag-level.d.ts +3 -0
- package/dist/core/stream-diag-level.js +24 -0
- package/dist/core/stream-diag-level.js.map +1 -0
- package/dist/core/stream-rules.d.ts +30 -0
- package/dist/core/stream-rules.js +151 -0
- package/dist/core/stream-rules.js.map +1 -0
- package/dist/core/subagent-manager.d.ts +242 -0
- package/dist/core/subagent-manager.js +1075 -0
- package/dist/core/subagent-manager.js.map +1 -0
- package/dist/core/subagent-policy.d.ts +9 -0
- package/dist/core/subagent-policy.js +41 -0
- package/dist/core/subagent-policy.js.map +1 -0
- package/dist/core/subagent-receipt.d.ts +54 -0
- package/dist/core/subagent-receipt.js +274 -0
- package/dist/core/subagent-receipt.js.map +1 -0
- package/dist/core/subagent-store.d.ts +41 -0
- package/dist/core/subagent-store.js +284 -0
- package/dist/core/subagent-store.js.map +1 -0
- package/dist/core/subagent-turn-record.d.ts +18 -0
- package/dist/core/subagent-turn-record.js +82 -0
- package/dist/core/subagent-turn-record.js.map +1 -0
- package/dist/core/tasks-store.d.ts +31 -0
- package/dist/core/tasks-store.js +97 -0
- package/dist/core/tasks-store.js.map +1 -0
- package/dist/core/telegram-config.d.ts +20 -0
- package/dist/core/telegram-config.js +52 -0
- package/dist/core/telegram-config.js.map +1 -0
- package/dist/core/telegram.d.ts +114 -0
- package/dist/core/telegram.js +275 -0
- package/dist/core/telegram.js.map +1 -0
- package/dist/core/temp-paths.d.ts +5 -0
- package/dist/core/temp-paths.js +50 -0
- package/dist/core/temp-paths.js.map +1 -0
- package/dist/core/test-impact.d.ts +73 -0
- package/dist/core/test-impact.js +467 -0
- package/dist/core/test-impact.js.map +1 -0
- package/dist/core/threat-feed.d.ts +65 -0
- package/dist/core/threat-feed.js +334 -0
- package/dist/core/threat-feed.js.map +1 -0
- package/dist/core/trophies/catalog-more.d.ts +2 -0
- package/dist/core/trophies/catalog-more.js +837 -0
- package/dist/core/trophies/catalog-more.js.map +1 -0
- package/dist/core/trophies/catalog.d.ts +4 -0
- package/dist/core/trophies/catalog.js +649 -0
- package/dist/core/trophies/catalog.js.map +1 -0
- package/dist/core/trophies/engine.d.ts +70 -0
- package/dist/core/trophies/engine.js +347 -0
- package/dist/core/trophies/engine.js.map +1 -0
- package/dist/core/trophies/store.d.ts +17 -0
- package/dist/core/trophies/store.js +113 -0
- package/dist/core/trophies/store.js.map +1 -0
- package/dist/core/trophies/types.d.ts +87 -0
- package/dist/core/trophies/types.js +74 -0
- package/dist/core/trophies/types.js.map +1 -0
- package/dist/core/ui-adoption.d.ts +32 -0
- package/dist/core/ui-adoption.js +302 -0
- package/dist/core/ui-adoption.js.map +1 -0
- package/dist/core/ui-compatibility.d.ts +10 -0
- package/dist/core/ui-compatibility.js +51 -0
- package/dist/core/ui-compatibility.js.map +1 -0
- package/dist/core/ui-registry.d.ts +101 -0
- package/dist/core/ui-registry.js +292 -0
- package/dist/core/ui-registry.js.map +1 -0
- package/dist/core/user-shell-context.d.ts +8 -0
- package/dist/core/user-shell-context.js +12 -0
- package/dist/core/user-shell-context.js.map +1 -0
- package/dist/core/verification-evidence.d.ts +49 -0
- package/dist/core/verification-evidence.js +816 -0
- package/dist/core/verification-evidence.js.map +1 -0
- package/dist/core/verification-gate.d.ts +77 -0
- package/dist/core/verification-gate.js +504 -0
- package/dist/core/verification-gate.js.map +1 -0
- package/dist/core/verification-snapshot.d.ts +7 -0
- package/dist/core/verification-snapshot.js +109 -0
- package/dist/core/verification-snapshot.js.map +1 -0
- package/dist/core/verify-commands.d.ts +34 -0
- package/dist/core/verify-commands.js +203 -0
- package/dist/core/verify-commands.js.map +1 -0
- package/dist/core/voice-transcriber.d.ts +32 -0
- package/dist/core/voice-transcriber.js +114 -0
- package/dist/core/voice-transcriber.js.map +1 -0
- package/dist/core/workspace-guard.d.ts +56 -0
- package/dist/core/workspace-guard.js +334 -0
- package/dist/core/workspace-guard.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +44 -0
- package/dist/session.js +105 -0
- package/dist/session.js.map +1 -0
- package/dist/system-prompt.d.ts +104 -0
- package/dist/system-prompt.js +480 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/test-support/fake-home.d.ts +19 -0
- package/dist/test-support/fake-home.js +37 -0
- package/dist/test-support/fake-home.js.map +1 -0
- package/dist/test-support/keep-alive.d.ts +14 -0
- package/dist/test-support/keep-alive.js +17 -0
- package/dist/test-support/keep-alive.js.map +1 -0
- package/dist/test-support/slow-git.d.ts +1 -0
- package/dist/test-support/slow-git.js +21 -0
- package/dist/test-support/slow-git.js.map +1 -0
- package/dist/test-support/system-tools.d.ts +6 -0
- package/dist/test-support/system-tools.js +36 -0
- package/dist/test-support/system-tools.js.map +1 -0
- package/dist/tools/ask-user.d.ts +34 -0
- package/dist/tools/ask-user.js +99 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/background-watch-lint.d.ts +18 -0
- package/dist/tools/background-watch-lint.js +102 -0
- package/dist/tools/background-watch-lint.js.map +1 -0
- package/dist/tools/bash-read-evidence.d.ts +23 -0
- package/dist/tools/bash-read-evidence.js +180 -0
- package/dist/tools/bash-read-evidence.js.map +1 -0
- package/dist/tools/bash.d.ts +64 -0
- package/dist/tools/bash.js +552 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/browser-api.d.ts +27 -0
- package/dist/tools/browser-api.js +449 -0
- package/dist/tools/browser-api.js.map +1 -0
- package/dist/tools/browser-sandbox.d.ts +16 -0
- package/dist/tools/browser-sandbox.js +158 -0
- package/dist/tools/browser-sandbox.js.map +1 -0
- package/dist/tools/browser-session.d.ts +84 -0
- package/dist/tools/browser-session.js +304 -0
- package/dist/tools/browser-session.js.map +1 -0
- package/dist/tools/browser-snapshot.d.ts +19 -0
- package/dist/tools/browser-snapshot.js +109 -0
- package/dist/tools/browser-snapshot.js.map +1 -0
- package/dist/tools/browser.d.ts +11 -0
- package/dist/tools/browser.js +106 -0
- package/dist/tools/browser.js.map +1 -0
- package/dist/tools/checklist.d.ts +49 -0
- package/dist/tools/checklist.js +154 -0
- package/dist/tools/checklist.js.map +1 -0
- package/dist/tools/compress.d.ts +56 -0
- package/dist/tools/compress.js +226 -0
- package/dist/tools/compress.js.map +1 -0
- package/dist/tools/debug.d.ts +54 -0
- package/dist/tools/debug.js +230 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/document-text.d.ts +6 -0
- package/dist/tools/document-text.js +154 -0
- package/dist/tools/document-text.js.map +1 -0
- package/dist/tools/edit-diff.d.ts +123 -0
- package/dist/tools/edit-diff.js +476 -0
- package/dist/tools/edit-diff.js.map +1 -0
- package/dist/tools/edit-targets.d.ts +10 -0
- package/dist/tools/edit-targets.js +31 -0
- package/dist/tools/edit-targets.js.map +1 -0
- package/dist/tools/edit.d.ts +38 -0
- package/dist/tools/edit.js +695 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/enter-plan.d.ts +7 -0
- package/dist/tools/enter-plan.js +20 -0
- package/dist/tools/enter-plan.js.map +1 -0
- package/dist/tools/exit-plan.d.ts +7 -0
- package/dist/tools/exit-plan.js +51 -0
- package/dist/tools/exit-plan.js.map +1 -0
- package/dist/tools/find.d.ts +17 -0
- package/dist/tools/find.js +100 -0
- package/dist/tools/find.js.map +1 -0
- package/dist/tools/generate-image.d.ts +83 -0
- package/dist/tools/generate-image.js +625 -0
- package/dist/tools/generate-image.js.map +1 -0
- package/dist/tools/grep-scan.d.ts +96 -0
- package/dist/tools/grep-scan.js +283 -0
- package/dist/tools/grep-scan.js.map +1 -0
- package/dist/tools/grep.d.ts +48 -0
- package/dist/tools/grep.js +1013 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/html-extract.d.ts +57 -0
- package/dist/tools/html-extract.js +130 -0
- package/dist/tools/html-extract.js.map +1 -0
- package/dist/tools/index.d.ts +198 -0
- package/dist/tools/index.js +216 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/live-preview.d.ts +23 -0
- package/dist/tools/live-preview.js +41 -0
- package/dist/tools/live-preview.js.map +1 -0
- package/dist/tools/ls.d.ts +9 -0
- package/dist/tools/ls.js +59 -0
- package/dist/tools/ls.js.map +1 -0
- package/dist/tools/operations.d.ts +86 -0
- package/dist/tools/operations.js +117 -0
- package/dist/tools/operations.js.map +1 -0
- package/dist/tools/overflow.d.ts +17 -0
- package/dist/tools/overflow.js +68 -0
- package/dist/tools/overflow.js.map +1 -0
- package/dist/tools/path-utils.d.ts +30 -0
- package/dist/tools/path-utils.js +74 -0
- package/dist/tools/path-utils.js.map +1 -0
- package/dist/tools/pdf-extract.d.ts +17 -0
- package/dist/tools/pdf-extract.js +43 -0
- package/dist/tools/pdf-extract.js.map +1 -0
- package/dist/tools/prompt-hints.d.ts +46 -0
- package/dist/tools/prompt-hints.js +171 -0
- package/dist/tools/prompt-hints.js.map +1 -0
- package/dist/tools/read-only-bash.d.ts +31 -0
- package/dist/tools/read-only-bash.js +338 -0
- package/dist/tools/read-only-bash.js.map +1 -0
- package/dist/tools/read-tracker.d.ts +43 -0
- package/dist/tools/read-tracker.js +120 -0
- package/dist/tools/read-tracker.js.map +1 -0
- package/dist/tools/read.d.ts +18 -0
- package/dist/tools/read.js +316 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/redaction-guard.d.ts +10 -0
- package/dist/tools/redaction-guard.js +55 -0
- package/dist/tools/redaction-guard.js.map +1 -0
- package/dist/tools/routine-output.d.ts +39 -0
- package/dist/tools/routine-output.js +281 -0
- package/dist/tools/routine-output.js.map +1 -0
- package/dist/tools/safe-env.d.ts +1 -0
- package/dist/tools/safe-env.js +79 -0
- package/dist/tools/safe-env.js.map +1 -0
- package/dist/tools/session-stats.d.ts +26 -0
- package/dist/tools/session-stats.js +51 -0
- package/dist/tools/session-stats.js.map +1 -0
- package/dist/tools/side-web-search.d.ts +34 -0
- package/dist/tools/side-web-search.js +146 -0
- package/dist/tools/side-web-search.js.map +1 -0
- package/dist/tools/skill.d.ts +12 -0
- package/dist/tools/skill.js +94 -0
- package/dist/tools/skill.js.map +1 -0
- package/dist/tools/source-path.d.ts +8 -0
- package/dist/tools/source-path.js +135 -0
- package/dist/tools/source-path.js.map +1 -0
- package/dist/tools/steroids.d.ts +44 -0
- package/dist/tools/steroids.js +356 -0
- package/dist/tools/steroids.js.map +1 -0
- package/dist/tools/subagent-control.d.ts +5 -0
- package/dist/tools/subagent-control.js +211 -0
- package/dist/tools/subagent-control.js.map +1 -0
- package/dist/tools/subagent-shared.d.ts +115 -0
- package/dist/tools/subagent-shared.js +182 -0
- package/dist/tools/subagent-shared.js.map +1 -0
- package/dist/tools/subagent.d.ts +39 -0
- package/dist/tools/subagent.js +412 -0
- package/dist/tools/subagent.js.map +1 -0
- package/dist/tools/task-output.d.ts +10 -0
- package/dist/tools/task-output.js +74 -0
- package/dist/tools/task-output.js.map +1 -0
- package/dist/tools/task-send.d.ts +11 -0
- package/dist/tools/task-send.js +36 -0
- package/dist/tools/task-send.js.map +1 -0
- package/dist/tools/task-stop.d.ts +8 -0
- package/dist/tools/task-stop.js +15 -0
- package/dist/tools/task-stop.js.map +1 -0
- package/dist/tools/tasks.d.ts +15 -0
- package/dist/tools/tasks.js +94 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/tool-search.d.ts +26 -0
- package/dist/tools/tool-search.js +81 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/tool-tiers.d.ts +65 -0
- package/dist/tools/tool-tiers.js +121 -0
- package/dist/tools/tool-tiers.js.map +1 -0
- package/dist/tools/truncate.d.ts +39 -0
- package/dist/tools/truncate.js +242 -0
- package/dist/tools/truncate.js.map +1 -0
- package/dist/tools/ui-adopt.d.ts +16 -0
- package/dist/tools/ui-adopt.js +66 -0
- package/dist/tools/ui-adopt.js.map +1 -0
- package/dist/tools/ui-registry.d.ts +15 -0
- package/dist/tools/ui-registry.js +39 -0
- package/dist/tools/ui-registry.js.map +1 -0
- package/dist/tools/verification-review.d.ts +2 -0
- package/dist/tools/verification-review.js +41 -0
- package/dist/tools/verification-review.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +52 -0
- package/dist/tools/web-fetch.js +986 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +35 -0
- package/dist/tools/web-search.js +926 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/write.d.ts +16 -0
- package/dist/tools/write.js +196 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +44 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/commit-message.d.ts +25 -0
- package/dist/utils/commit-message.js +72 -0
- package/dist/utils/commit-message.js.map +1 -0
- package/dist/utils/git.d.ts +102 -0
- package/dist/utils/git.js +325 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/github-ci.d.ts +9 -0
- package/dist/utils/github-ci.js +138 -0
- package/dist/utils/github-ci.js.map +1 -0
- package/dist/utils/github.d.ts +19 -0
- package/dist/utils/github.js +67 -0
- package/dist/utils/github.js.map +1 -0
- package/dist/utils/image.d.ts +166 -0
- package/dist/utils/image.js +673 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/open-browser.d.ts +13 -0
- package/dist/utils/open-browser.js +31 -0
- package/dist/utils/open-browser.js.map +1 -0
- package/dist/utils/plan-steps.d.ts +90 -0
- package/dist/utils/plan-steps.js +209 -0
- package/dist/utils/plan-steps.js.map +1 -0
- package/dist/utils/process.d.ts +48 -0
- package/dist/utils/process.js +175 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/prompt-enhancer.d.ts +34 -0
- package/dist/utils/prompt-enhancer.js +178 -0
- package/dist/utils/prompt-enhancer.js.map +1 -0
- package/dist/utils/text.d.ts +61 -0
- package/dist/utils/text.js +68 -0
- package/dist/utils/text.js.map +1 -0
- package/package.json +87 -3
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
let sharpFn = null;
|
|
8
|
+
async function loadSharp() {
|
|
9
|
+
if (sharpFn)
|
|
10
|
+
return sharpFn;
|
|
11
|
+
// Sharp publishes as CJS where `module.exports = sharpFunction`. Under
|
|
12
|
+
// ESM dynamic import, that lands on `.default` — but some tooling normalises
|
|
13
|
+
// it onto the namespace object directly. Try `.default` first, fall back
|
|
14
|
+
// to the namespace if not present.
|
|
15
|
+
const mod = (await import("sharp"));
|
|
16
|
+
sharpFn = mod.default ?? mod;
|
|
17
|
+
return sharpFn;
|
|
18
|
+
}
|
|
19
|
+
/** Anthropic's maximum image size in bytes (5 MB). */
|
|
20
|
+
const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
21
|
+
/** Max width (px) for inline terminal-graphics previews so scrollback stays small. */
|
|
22
|
+
const PREVIEW_MAX_WIDTH = 480;
|
|
23
|
+
/**
|
|
24
|
+
* Visual token budget — vision encoders tile an image into fixed-size patches
|
|
25
|
+
* and charge per patch, so pixels beyond the budget are re-scaled away by the
|
|
26
|
+
* provider *after* we paid to upload them. Bounding here instead means fewer
|
|
27
|
+
* bytes on the wire and fewer image tokens billed, with no loss of detail the
|
|
28
|
+
* model would have seen anyway.
|
|
29
|
+
*
|
|
30
|
+
* `VISUAL_PATCH_PX` is the encoder's patch edge; `VISUAL_MAX_PATCHES` the patch
|
|
31
|
+
* budget; `VISUAL_MAX_EDGE` the hard per-side cap (a 3000x400 panorama is well
|
|
32
|
+
* inside the patch budget but still gets downscaled on the long edge).
|
|
33
|
+
*/
|
|
34
|
+
const VISUAL_PATCH_PX = 28;
|
|
35
|
+
const VISUAL_MAX_PATCHES = 1568;
|
|
36
|
+
const VISUAL_MAX_EDGE = 1568;
|
|
37
|
+
/**
|
|
38
|
+
* Does a `width x height` image fit the visual token budget — both per-side
|
|
39
|
+
* cap and total patch count?
|
|
40
|
+
*
|
|
41
|
+
* Patch count is measured as continuous area (`w*h / patch^2`) rather than
|
|
42
|
+
* `ceil(w/patch) * ceil(h/patch)`: the encoder resizes to a patch-aligned grid
|
|
43
|
+
* before tiling, so area is what actually determines the token cost.
|
|
44
|
+
*/
|
|
45
|
+
export function fitsVisualBudget(width, height) {
|
|
46
|
+
if (!Number.isFinite(width) || !Number.isFinite(height))
|
|
47
|
+
return false;
|
|
48
|
+
if (width <= 0 || height <= 0)
|
|
49
|
+
return true;
|
|
50
|
+
if (width > VISUAL_MAX_EDGE || height > VISUAL_MAX_EDGE)
|
|
51
|
+
return false;
|
|
52
|
+
return (width * height) / (VISUAL_PATCH_PX * VISUAL_PATCH_PX) <= VISUAL_MAX_PATCHES;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Largest aspect-preserving size that still satisfies {@link fitsVisualBudget}.
|
|
56
|
+
* Returns the input untouched when it already fits (so ordinary screenshots are
|
|
57
|
+
* never re-encoded).
|
|
58
|
+
*
|
|
59
|
+
* Binary-searches the long edge because the short edge is rounded to whole
|
|
60
|
+
* pixels — the closed-form area scale can overshoot the budget by a patch or
|
|
61
|
+
* two once that rounding is applied.
|
|
62
|
+
*/
|
|
63
|
+
export function boundedSize(width, height) {
|
|
64
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width < 1 || height < 1) {
|
|
65
|
+
return { width, height };
|
|
66
|
+
}
|
|
67
|
+
if (fitsVisualBudget(width, height))
|
|
68
|
+
return { width, height };
|
|
69
|
+
const landscape = width >= height;
|
|
70
|
+
const longEdge = landscape ? width : height;
|
|
71
|
+
const shortEdge = landscape ? height : width;
|
|
72
|
+
const ratio = shortEdge / longEdge;
|
|
73
|
+
const project = (edge) => {
|
|
74
|
+
const long = Math.max(1, Math.round(edge));
|
|
75
|
+
const short = Math.max(1, Math.round(long * ratio));
|
|
76
|
+
return landscape ? { width: long, height: short } : { width: short, height: long };
|
|
77
|
+
};
|
|
78
|
+
let lo = 1;
|
|
79
|
+
let hi = Math.floor(Math.min(longEdge, VISUAL_MAX_EDGE));
|
|
80
|
+
let best = project(1);
|
|
81
|
+
while (lo <= hi) {
|
|
82
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
83
|
+
const candidate = project(mid);
|
|
84
|
+
if (fitsVisualBudget(candidate.width, candidate.height)) {
|
|
85
|
+
best = candidate;
|
|
86
|
+
lo = mid + 1;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
hi = mid - 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return best;
|
|
93
|
+
}
|
|
94
|
+
export const IMAGE_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp"]);
|
|
95
|
+
export const VIDEO_EXTENSIONS = new Set([".mp4", ".mov", ".webm", ".avi", ".mkv"]);
|
|
96
|
+
const TEXT_EXTENSIONS = new Set([".md", ".txt"]);
|
|
97
|
+
const ATTACHABLE_EXTENSIONS = new Set([
|
|
98
|
+
...IMAGE_EXTENSIONS,
|
|
99
|
+
...VIDEO_EXTENSIONS,
|
|
100
|
+
...TEXT_EXTENSIONS,
|
|
101
|
+
]);
|
|
102
|
+
/** Max video size loaded into base64 at attach time (50 MB). Video is routed by
|
|
103
|
+
* file path, so the bytes are only kept as a fallback for path-less clipboard
|
|
104
|
+
* clips; larger clips keep `data` empty and rely on the path. Per-model upload
|
|
105
|
+
* caps live in the model registry (`maxVideoBytes`) and drive compression. */
|
|
106
|
+
export const MAX_VIDEO_BYTES = 50 * 1024 * 1024;
|
|
107
|
+
// ── Video compression (fit oversized clips under a per-model cap) ─────────
|
|
108
|
+
/** Compression target — 90 MB leaves headroom under the 100 MB upload cap for
|
|
109
|
+
* container overhead and bitrate overshoot. */
|
|
110
|
+
const COMPRESS_TARGET_BYTES = 90 * 1024 * 1024;
|
|
111
|
+
const COMPRESS_MAX_WIDTH = 1280; // cap long edge; preserves aspect (height auto)
|
|
112
|
+
const COMPRESS_FPS = 5; // plenty for content understanding; shrinks size hard
|
|
113
|
+
const COMPRESS_AUDIO_KBPS = 64; // keep speech intelligible
|
|
114
|
+
const COMPRESS_MIN_VIDEO_KBPS = 100; // floor so very long clips stay decodable
|
|
115
|
+
function isMissingBinary(err) {
|
|
116
|
+
return err?.code === "ENOENT";
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Transcode an oversized video down to fit under {@link COMPRESS_TARGET_BYTES}
|
|
120
|
+
* using ffmpeg: downscale to {@link COMPRESS_MAX_WIDTH}px wide, drop to
|
|
121
|
+
* {@link COMPRESS_FPS} fps, and target a bitrate computed from the clip's
|
|
122
|
+
* duration. Video understanding samples frames, so aggressive downsampling
|
|
123
|
+
* keeps the content analyzable while shrinking multi-GB clips to <100 MB.
|
|
124
|
+
*
|
|
125
|
+
* Writes to a temp file and returns its path; the caller owns deleting it.
|
|
126
|
+
* Best-effort: returns `{ ok: false, reason }` if ffmpeg/ffprobe are missing,
|
|
127
|
+
* the probe fails, or the result still exceeds the target.
|
|
128
|
+
*/
|
|
129
|
+
export async function compressVideoToFit(inputPath, targetBytes = COMPRESS_TARGET_BYTES, signal) {
|
|
130
|
+
// Probe duration to compute a size-targeted bitrate.
|
|
131
|
+
let durationSec;
|
|
132
|
+
try {
|
|
133
|
+
const { stdout } = await execFileAsync("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "default=nw=1:nk=1", inputPath], { signal });
|
|
134
|
+
durationSec = Number.parseFloat(stdout.trim());
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
return {
|
|
138
|
+
ok: false,
|
|
139
|
+
reason: isMissingBinary(err)
|
|
140
|
+
? "ffmpeg/ffprobe is not installed"
|
|
141
|
+
: `could not probe video: ${err instanceof Error ? err.message : String(err)}`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (!Number.isFinite(durationSec) || durationSec <= 0) {
|
|
145
|
+
return { ok: false, reason: "could not determine video duration" };
|
|
146
|
+
}
|
|
147
|
+
// total kbps budget = target bits / duration, with 90% safety margin; the
|
|
148
|
+
// audio track gets a fixed slice, the rest goes to video (floored).
|
|
149
|
+
const totalKbps = Math.floor(((targetBytes * 8) / durationSec / 1000) * 0.9);
|
|
150
|
+
const videoKbps = Math.max(COMPRESS_MIN_VIDEO_KBPS, totalKbps - COMPRESS_AUDIO_KBPS);
|
|
151
|
+
const outPath = path.join(os.tmpdir(), `ggcoder-compressed-${Date.now()}.mp4`);
|
|
152
|
+
try {
|
|
153
|
+
await execFileAsync("ffmpeg", [
|
|
154
|
+
"-y",
|
|
155
|
+
"-nostats",
|
|
156
|
+
"-loglevel",
|
|
157
|
+
"error",
|
|
158
|
+
"-i",
|
|
159
|
+
inputPath,
|
|
160
|
+
"-vf",
|
|
161
|
+
`scale='min(${COMPRESS_MAX_WIDTH},iw)':-2,fps=${COMPRESS_FPS}`,
|
|
162
|
+
"-c:v",
|
|
163
|
+
"libx264",
|
|
164
|
+
"-b:v",
|
|
165
|
+
`${videoKbps}k`,
|
|
166
|
+
"-maxrate",
|
|
167
|
+
`${Math.floor(videoKbps * 1.5)}k`,
|
|
168
|
+
"-bufsize",
|
|
169
|
+
`${videoKbps}k`,
|
|
170
|
+
"-preset",
|
|
171
|
+
"veryfast",
|
|
172
|
+
"-c:a",
|
|
173
|
+
"aac",
|
|
174
|
+
"-b:a",
|
|
175
|
+
`${COMPRESS_AUDIO_KBPS}k`,
|
|
176
|
+
outPath,
|
|
177
|
+
], { signal, maxBuffer: 16 * 1024 * 1024 });
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
await fs.unlink(outPath).catch(() => { });
|
|
181
|
+
return {
|
|
182
|
+
ok: false,
|
|
183
|
+
reason: isMissingBinary(err)
|
|
184
|
+
? "ffmpeg is not installed"
|
|
185
|
+
: `ffmpeg compression failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
let compressedBytes;
|
|
189
|
+
let originalBytes;
|
|
190
|
+
try {
|
|
191
|
+
compressedBytes = (await fs.stat(outPath)).size;
|
|
192
|
+
originalBytes = (await fs.stat(inputPath)).size;
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
await fs.unlink(outPath).catch(() => { });
|
|
196
|
+
return { ok: false, reason: "compression produced no usable output" };
|
|
197
|
+
}
|
|
198
|
+
if (compressedBytes > targetBytes) {
|
|
199
|
+
await fs.unlink(outPath).catch(() => { });
|
|
200
|
+
return {
|
|
201
|
+
ok: false,
|
|
202
|
+
reason: `compressed video is still ${(compressedBytes / (1024 * 1024)).toFixed(0)} MB`,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return { ok: true, path: outPath, originalBytes, compressedBytes };
|
|
206
|
+
}
|
|
207
|
+
export const IMAGE_MEDIA_TYPES = {
|
|
208
|
+
".png": "image/png",
|
|
209
|
+
".jpg": "image/jpeg",
|
|
210
|
+
".jpeg": "image/jpeg",
|
|
211
|
+
".gif": "image/gif",
|
|
212
|
+
".webp": "image/webp",
|
|
213
|
+
".bmp": "image/bmp",
|
|
214
|
+
};
|
|
215
|
+
export const VIDEO_MEDIA_TYPES = {
|
|
216
|
+
".mp4": "video/mp4",
|
|
217
|
+
".mov": "video/quicktime",
|
|
218
|
+
".webm": "video/webm",
|
|
219
|
+
".avi": "video/x-msvideo",
|
|
220
|
+
".mkv": "video/x-matroska",
|
|
221
|
+
};
|
|
222
|
+
// Backwards-compat alias for internal use below
|
|
223
|
+
const MEDIA_TYPES = IMAGE_MEDIA_TYPES;
|
|
224
|
+
/** Check if a file path points to an attachable file (image or text). */
|
|
225
|
+
export function isAttachablePath(filePath) {
|
|
226
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
227
|
+
return ATTACHABLE_EXTENSIONS.has(ext);
|
|
228
|
+
}
|
|
229
|
+
function resolvePath(filePath, cwd) {
|
|
230
|
+
let resolved = filePath.trim();
|
|
231
|
+
// Strip surrounding quotes
|
|
232
|
+
if ((resolved.startsWith("'") && resolved.endsWith("'")) ||
|
|
233
|
+
(resolved.startsWith('"') && resolved.endsWith('"'))) {
|
|
234
|
+
resolved = resolved.slice(1, -1);
|
|
235
|
+
}
|
|
236
|
+
// Strip file:// prefix
|
|
237
|
+
if (resolved.startsWith("file://")) {
|
|
238
|
+
resolved = resolved.slice(7);
|
|
239
|
+
}
|
|
240
|
+
// Unescape backslash-escaped characters (e.g. "\ " → " ")
|
|
241
|
+
resolved = resolved.replace(/\\(.)/g, "$1");
|
|
242
|
+
// Resolve home dir
|
|
243
|
+
if (resolved.startsWith("~/")) {
|
|
244
|
+
resolved = path.join(process.env.HOME ?? "/", resolved.slice(2));
|
|
245
|
+
}
|
|
246
|
+
else if (!path.isAbsolute(resolved)) {
|
|
247
|
+
resolved = path.join(cwd, resolved);
|
|
248
|
+
}
|
|
249
|
+
return resolved;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Check if a token looks like an intentional file path rather than a bare filename
|
|
253
|
+
* mentioned in conversation. Bare names like "claude.md" should not be auto-attached;
|
|
254
|
+
* only explicit paths like "./claude.md", "/tmp/file.md", "~/notes.md", etc.
|
|
255
|
+
*/
|
|
256
|
+
function looksLikePath(token) {
|
|
257
|
+
const stripped = token.replace(/^['"]|['"]$/g, "");
|
|
258
|
+
return (stripped.includes("/") ||
|
|
259
|
+
stripped.includes("\\") ||
|
|
260
|
+
stripped.startsWith("~") ||
|
|
261
|
+
stripped.startsWith("file://"));
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Extract attachable file paths from input text by checking if tokens resolve
|
|
265
|
+
* to existing files on disk. Returns verified paths and the remaining text.
|
|
266
|
+
*
|
|
267
|
+
* Only tokens that look like explicit paths (contain `/`, `~`, `\`, or `file://`)
|
|
268
|
+
* are considered. Bare filenames like "readme.md" are left as text.
|
|
269
|
+
*/
|
|
270
|
+
export async function extractImagePaths(text, cwd) {
|
|
271
|
+
const imagePaths = [];
|
|
272
|
+
const cleanParts = [];
|
|
273
|
+
// Try the entire input as a single path first (only if it looks like a path)
|
|
274
|
+
if (looksLikePath(text)) {
|
|
275
|
+
const wholePath = resolvePath(text, cwd);
|
|
276
|
+
if (isAttachablePath(wholePath) && (await fileExists(wholePath))) {
|
|
277
|
+
return { imagePaths: [wholePath], cleanText: "" };
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// Split on unescaped whitespace (respect backslash-escaped spaces like "file\ name.png")
|
|
281
|
+
const tokens = text.match(/(?:[^\s\\]|\\.)+/g) ?? [];
|
|
282
|
+
for (const token of tokens) {
|
|
283
|
+
if (!token)
|
|
284
|
+
continue;
|
|
285
|
+
if (looksLikePath(token)) {
|
|
286
|
+
const resolved = resolvePath(token, cwd);
|
|
287
|
+
if (isAttachablePath(resolved) && (await fileExists(resolved))) {
|
|
288
|
+
imagePaths.push(resolved);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
cleanParts.push(token);
|
|
293
|
+
}
|
|
294
|
+
return { imagePaths, cleanText: cleanParts.join(" ") };
|
|
295
|
+
}
|
|
296
|
+
/** Alias of {@link extractImagePaths} that also picks up video paths (video
|
|
297
|
+
* extensions are part of ATTACHABLE_EXTENSIONS). Name reflects the widened scope. */
|
|
298
|
+
export const extractMediaPaths = extractImagePaths;
|
|
299
|
+
async function fileExists(filePath) {
|
|
300
|
+
try {
|
|
301
|
+
const stat = await fs.stat(filePath);
|
|
302
|
+
return stat.isFile();
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/** Map sharp's detected format string to an Anthropic-compatible media type. */
|
|
309
|
+
const SHARP_FORMAT_TO_MEDIA = {
|
|
310
|
+
png: "image/png",
|
|
311
|
+
jpeg: "image/jpeg",
|
|
312
|
+
jpg: "image/jpeg",
|
|
313
|
+
gif: "image/gif",
|
|
314
|
+
webp: "image/webp",
|
|
315
|
+
};
|
|
316
|
+
/** Media types the Anthropic + OpenAI vision APIs actually accept as image
|
|
317
|
+
* blocks. Anything else (.ico, .bmp, .svg, .tiff, …) must NOT be sent as an
|
|
318
|
+
* image or the provider rejects the whole request. */
|
|
319
|
+
const VISION_MEDIA_TYPES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
|
320
|
+
/**
|
|
321
|
+
* Validate that a base64-decoded buffer is a REAL, fully-decodable image in a
|
|
322
|
+
* format the vision APIs accept. Returns the corrected media type on success,
|
|
323
|
+
* or `null` when the data is corrupt or an unsupported format.
|
|
324
|
+
*
|
|
325
|
+
* Why this exists: an image content block with corrupt or unsupported bytes
|
|
326
|
+
* (e.g. a malformed `.ico`, or a `.png` with a bad IDAT/CRC) makes the provider
|
|
327
|
+
* reject the ENTIRE turn with "The image data you provided does not represent a
|
|
328
|
+
* valid image" — the agent never gets to respond. Callers use the `null` return
|
|
329
|
+
* to downgrade such an attachment to a plain file note (saved to disk, inspected
|
|
330
|
+
* with tools) so the request still succeeds and the model can diagnose the file.
|
|
331
|
+
*
|
|
332
|
+
* The header sniff alone is insufficient (a corrupt PNG still has PNG magic), so
|
|
333
|
+
* this forces a full pixel decode — resized small to bound memory — which makes
|
|
334
|
+
* libvips surface mid-stream corruption here instead of at the provider.
|
|
335
|
+
*/
|
|
336
|
+
export async function validateVisionImage(buffer) {
|
|
337
|
+
try {
|
|
338
|
+
const sharp = await loadSharp();
|
|
339
|
+
const meta = await sharp(buffer).metadata();
|
|
340
|
+
const mediaType = meta.format ? SHARP_FORMAT_TO_MEDIA[meta.format] : undefined;
|
|
341
|
+
if (!mediaType || !VISION_MEDIA_TYPES.has(mediaType))
|
|
342
|
+
return null;
|
|
343
|
+
// Force a full decode (failOn: "error") so a corrupt payload the header check
|
|
344
|
+
// misses is caught here. Resize small so a huge image doesn't balloon memory.
|
|
345
|
+
await sharp(buffer, { failOn: "error" })
|
|
346
|
+
.resize(256, 256, { fit: "inside", withoutEnlargement: true })
|
|
347
|
+
.raw()
|
|
348
|
+
.toBuffer();
|
|
349
|
+
return mediaType;
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Downscale an image buffer so it fits within both the visual token budget
|
|
357
|
+
* ({@link boundedSize}) and MAX_IMAGE_BYTES. Preserves format (PNG→PNG,
|
|
358
|
+
* JPEG→JPEG, etc.) and aspect ratio — a lossless PNG screenshot of UI stays a
|
|
359
|
+
* lossless PNG with its alpha channel intact.
|
|
360
|
+
*/
|
|
361
|
+
export async function shrinkToFit(buffer, mediaType) {
|
|
362
|
+
const sharp = await loadSharp();
|
|
363
|
+
const meta = await sharp(buffer).metadata();
|
|
364
|
+
const origW = meta.width ?? 4096;
|
|
365
|
+
const origH = meta.height ?? 4096;
|
|
366
|
+
const bounded = boundedSize(origW, origH);
|
|
367
|
+
const exceedsDim = bounded.width !== origW || bounded.height !== origH;
|
|
368
|
+
// Trust the buffer over the caller-supplied mediaType: if a file was named
|
|
369
|
+
// foo.png but is actually a JPEG, sharp tells the truth and Anthropic
|
|
370
|
+
// rejects mismatched media types with a 400.
|
|
371
|
+
const detected = meta.format ? SHARP_FORMAT_TO_MEDIA[meta.format] : undefined;
|
|
372
|
+
if (detected && detected !== mediaType) {
|
|
373
|
+
mediaType = detected;
|
|
374
|
+
}
|
|
375
|
+
// Short-circuit: within both limits — return as-is.
|
|
376
|
+
if (!exceedsDim && buffer.length <= MAX_IMAGE_BYTES) {
|
|
377
|
+
return { buffer, mediaType };
|
|
378
|
+
}
|
|
379
|
+
// Determine output format from mediaType
|
|
380
|
+
const formatMap = {
|
|
381
|
+
"image/png": "png",
|
|
382
|
+
"image/jpeg": "jpeg",
|
|
383
|
+
"image/gif": "gif",
|
|
384
|
+
"image/webp": "webp",
|
|
385
|
+
"image/bmp": "png", // convert BMP to PNG (sharp doesn't output BMP)
|
|
386
|
+
};
|
|
387
|
+
let outFormat = formatMap[mediaType] ?? "png";
|
|
388
|
+
let outMediaType = mediaType === "image/bmp" ? "image/png" : mediaType;
|
|
389
|
+
// Initial target dimensions come from the visual token budget. Explicit
|
|
390
|
+
// width/height (rather than leaning on sharp's fit: "inside") so the byte
|
|
391
|
+
// loop below can shrink them further.
|
|
392
|
+
let width = bounded.width;
|
|
393
|
+
let height = bounded.height;
|
|
394
|
+
// Encode at the budget-capped size first — often this is already under
|
|
395
|
+
// MAX_IMAGE_BYTES and we're done.
|
|
396
|
+
{
|
|
397
|
+
const first = await sharp(buffer)
|
|
398
|
+
.resize(width, height, { fit: "inside", withoutEnlargement: true })
|
|
399
|
+
.toFormat(outFormat)
|
|
400
|
+
.toBuffer();
|
|
401
|
+
if (first.length <= MAX_IMAGE_BYTES) {
|
|
402
|
+
return { buffer: first, mediaType: outMediaType };
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
// Still too large — progressively shrink by 25% per step.
|
|
406
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
407
|
+
width = Math.max(1, Math.round(width * 0.75));
|
|
408
|
+
height = Math.max(1, Math.round(height * 0.75));
|
|
409
|
+
if (width < 1 || height < 1)
|
|
410
|
+
break;
|
|
411
|
+
const result = await sharp(buffer)
|
|
412
|
+
.resize(width, height, { fit: "inside", withoutEnlargement: true })
|
|
413
|
+
.toFormat(outFormat)
|
|
414
|
+
.toBuffer();
|
|
415
|
+
if (result.length <= MAX_IMAGE_BYTES) {
|
|
416
|
+
return { buffer: result, mediaType: outMediaType };
|
|
417
|
+
}
|
|
418
|
+
// If PNG is still too big after 3 attempts, switch to JPEG for better compression
|
|
419
|
+
if (attempt === 2 && outFormat === "png") {
|
|
420
|
+
outFormat = "jpeg";
|
|
421
|
+
outMediaType = "image/jpeg";
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
// Last resort: aggressive JPEG compression at small size
|
|
425
|
+
const result = await sharp(buffer)
|
|
426
|
+
.resize(Math.round(width * 0.5), Math.round(height * 0.5), {
|
|
427
|
+
fit: "inside",
|
|
428
|
+
withoutEnlargement: true,
|
|
429
|
+
})
|
|
430
|
+
.jpeg({ quality: 60 })
|
|
431
|
+
.toBuffer();
|
|
432
|
+
return { buffer: result, mediaType: "image/jpeg" };
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Downscale an image buffer for an inline terminal preview, capping its width
|
|
436
|
+
* at PREVIEW_MAX_WIDTH so previews stay small in scrollback. The full-resolution
|
|
437
|
+
* copy is kept separately for the model. Preserves format and aspect ratio.
|
|
438
|
+
*
|
|
439
|
+
* On any sharp failure the original buffer is returned unchanged — a preview is
|
|
440
|
+
* cosmetic and must never break the turn.
|
|
441
|
+
*/
|
|
442
|
+
export async function downscaleForPreview(buffer) {
|
|
443
|
+
try {
|
|
444
|
+
const sharp = await loadSharp();
|
|
445
|
+
const meta = await sharp(buffer).metadata();
|
|
446
|
+
const width = meta.width ?? 0;
|
|
447
|
+
if (width > 0 && width <= PREVIEW_MAX_WIDTH)
|
|
448
|
+
return buffer;
|
|
449
|
+
// Without `animated`, sharp decodes only the first frame and a GIF preview would freeze.
|
|
450
|
+
const animated = (meta.pages ?? 1) > 1;
|
|
451
|
+
return await sharp(buffer, { animated })
|
|
452
|
+
.resize(PREVIEW_MAX_WIDTH, undefined, { fit: "inside", withoutEnlargement: true })
|
|
453
|
+
.toBuffer();
|
|
454
|
+
}
|
|
455
|
+
catch {
|
|
456
|
+
return buffer;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/** Largest animated preview sent to the chat; above it, a smaller or still copy. */
|
|
460
|
+
export const MAX_ANIMATED_PREVIEW_BYTES = 2.5 * 1024 * 1024;
|
|
461
|
+
const SMALL_PREVIEW_WIDTH = 320;
|
|
462
|
+
/**
|
|
463
|
+
* The chat preview for an animated GIF: every frame at preview width while it
|
|
464
|
+
* stays under MAX_ANIMATED_PREVIEW_BYTES, then narrower, then the first frame
|
|
465
|
+
* as a PNG, so a long, wide GIF (or a batch of them) cannot swamp the event stream.
|
|
466
|
+
*/
|
|
467
|
+
export async function animatedPreview(gif, maxBytes = MAX_ANIMATED_PREVIEW_BYTES) {
|
|
468
|
+
const preview = await downscaleForPreview(gif);
|
|
469
|
+
if (preview.length <= maxBytes) {
|
|
470
|
+
return { buffer: preview, mediaType: "image/gif" };
|
|
471
|
+
}
|
|
472
|
+
try {
|
|
473
|
+
const sharp = await loadSharp();
|
|
474
|
+
const smaller = await sharp(gif, { animated: true })
|
|
475
|
+
.resize(SMALL_PREVIEW_WIDTH, undefined, { fit: "inside", withoutEnlargement: true })
|
|
476
|
+
.toBuffer();
|
|
477
|
+
if (smaller.length <= maxBytes) {
|
|
478
|
+
return { buffer: smaller, mediaType: "image/gif" };
|
|
479
|
+
}
|
|
480
|
+
const still = await sharp(gif)
|
|
481
|
+
.resize(PREVIEW_MAX_WIDTH, undefined, { fit: "inside", withoutEnlargement: true })
|
|
482
|
+
.png()
|
|
483
|
+
.toBuffer();
|
|
484
|
+
return { buffer: still, mediaType: "image/png" };
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
return { buffer: preview, mediaType: "image/gif" };
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Pixel dimensions from the image header, or null when it cannot be read.
|
|
492
|
+
* Header only: no pixel decode, so it is cheap on large images.
|
|
493
|
+
*/
|
|
494
|
+
export async function imageDimensions(buffer) {
|
|
495
|
+
try {
|
|
496
|
+
const sharp = await loadSharp();
|
|
497
|
+
const { width, height } = await sharp(buffer).metadata();
|
|
498
|
+
return width && height ? { width, height } : null;
|
|
499
|
+
}
|
|
500
|
+
catch {
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Re-encode an image as `format`. Unlike the preview helpers this is the saved
|
|
506
|
+
* file itself, so a failure propagates rather than silently keeping the
|
|
507
|
+
* original bytes under a mismatched extension.
|
|
508
|
+
*/
|
|
509
|
+
export async function convertImageFormat(buffer, format) {
|
|
510
|
+
const sharp = await loadSharp();
|
|
511
|
+
return sharp(buffer).toFormat(format).toBuffer();
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Inline previews (`details.imagePreviews`) for image blocks a tool returns
|
|
515
|
+
* without a file of its own (MCP servers). The chat only
|
|
516
|
+
* renders tool images from these previews, so a tool that skips them shows
|
|
517
|
+
* nothing live and only surfaces its images after a session reload.
|
|
518
|
+
*/
|
|
519
|
+
export async function previewsForImageBlocks(blocks) {
|
|
520
|
+
const previews = [];
|
|
521
|
+
for (const block of blocks) {
|
|
522
|
+
if (block.type !== "image" || !block.mediaType || !block.data)
|
|
523
|
+
continue;
|
|
524
|
+
const preview = await downscaleForPreview(Buffer.from(block.data, "base64"));
|
|
525
|
+
previews.push({ base64: preview.toString("base64"), mediaType: block.mediaType });
|
|
526
|
+
}
|
|
527
|
+
return previews;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Read a file and return an attachment (base64 for images, raw text for text files).
|
|
531
|
+
*
|
|
532
|
+
* Image decode / shrink failures degrade to a text placeholder instead of throwing,
|
|
533
|
+
* so a corrupt or unsupported image doesn't crash the turn. The caller sees a
|
|
534
|
+
* `kind: "text"` attachment the model can read as `<file>…</file>` context.
|
|
535
|
+
*/
|
|
536
|
+
export async function readImageFile(filePath) {
|
|
537
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
538
|
+
const fileName = path.basename(filePath);
|
|
539
|
+
if (VIDEO_EXTENSIONS.has(ext)) {
|
|
540
|
+
try {
|
|
541
|
+
const mediaType = VIDEO_MEDIA_TYPES[ext] ?? "video/mp4";
|
|
542
|
+
const stat = await fs.stat(filePath);
|
|
543
|
+
// Always classify as `video` so it routes through the video path (and the
|
|
544
|
+
// UI shows it as a video, not a generic file). Providers that deliver
|
|
545
|
+
// video via an upload/read-tool reference it by `filePath` at any size.
|
|
546
|
+
// Only providers that inline base64 need the bytes in-memory, and only up
|
|
547
|
+
// to MAX_VIDEO_BYTES — so for larger clips we keep `data` empty and let
|
|
548
|
+
// the path-based routes handle it.
|
|
549
|
+
const data = stat.size <= MAX_VIDEO_BYTES ? (await fs.readFile(filePath)).toString("base64") : "";
|
|
550
|
+
return { kind: "video", fileName, filePath, mediaType, data };
|
|
551
|
+
}
|
|
552
|
+
catch (err) {
|
|
553
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
554
|
+
return {
|
|
555
|
+
kind: "text",
|
|
556
|
+
fileName,
|
|
557
|
+
filePath,
|
|
558
|
+
mediaType: "text/plain",
|
|
559
|
+
data: `[video ${fileName} could not be loaded: ${reason}]`,
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
if (TEXT_EXTENSIONS.has(ext)) {
|
|
564
|
+
try {
|
|
565
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
566
|
+
return { kind: "text", fileName, filePath, mediaType: "text/plain", data: content };
|
|
567
|
+
}
|
|
568
|
+
catch (err) {
|
|
569
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
570
|
+
return {
|
|
571
|
+
kind: "text",
|
|
572
|
+
fileName,
|
|
573
|
+
filePath,
|
|
574
|
+
mediaType: "text/plain",
|
|
575
|
+
data: `[file ${fileName} could not be read: ${reason}]`,
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
try {
|
|
580
|
+
const mediaType = MEDIA_TYPES[ext] ?? "image/png";
|
|
581
|
+
const rawBuffer = await fs.readFile(filePath);
|
|
582
|
+
const { buffer } = await shrinkToFit(rawBuffer, mediaType);
|
|
583
|
+
// Final guard: confirm the (possibly shrunk) buffer is a real, fully-decodable
|
|
584
|
+
// image in a vision-supported format. shrinkToFit short-circuits without a
|
|
585
|
+
// full decode when the image is already within size limits, so a corrupt or
|
|
586
|
+
// unsupported file (e.g. a malformed .ico) could slip through and make the
|
|
587
|
+
// provider reject the whole turn. On failure, degrade to a text placeholder
|
|
588
|
+
// the model can still read as <file> context — never break the turn.
|
|
589
|
+
const validatedType = await validateVisionImage(buffer);
|
|
590
|
+
if (!validatedType) {
|
|
591
|
+
return {
|
|
592
|
+
kind: "text",
|
|
593
|
+
fileName,
|
|
594
|
+
filePath,
|
|
595
|
+
mediaType: "text/plain",
|
|
596
|
+
data: `[image ${fileName} is not a valid/supported image (corrupt or unsupported format); saved at ${filePath} — inspect it with your tools if needed]`,
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
return {
|
|
600
|
+
kind: "image",
|
|
601
|
+
fileName,
|
|
602
|
+
filePath,
|
|
603
|
+
mediaType: validatedType,
|
|
604
|
+
data: buffer.toString("base64"),
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
catch (err) {
|
|
608
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
609
|
+
return {
|
|
610
|
+
kind: "text",
|
|
611
|
+
fileName,
|
|
612
|
+
filePath,
|
|
613
|
+
mediaType: "text/plain",
|
|
614
|
+
data: `[image ${fileName} could not be loaded: ${reason}]`,
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
/** Alias of {@link readImageFile} that also handles video files. Name reflects
|
|
619
|
+
* the widened scope. */
|
|
620
|
+
export const readMediaFile = readImageFile;
|
|
621
|
+
/**
|
|
622
|
+
* Try to read image data from the system clipboard (macOS only).
|
|
623
|
+
* Returns null if no image is on the clipboard.
|
|
624
|
+
*/
|
|
625
|
+
export function getClipboardImage() {
|
|
626
|
+
if (process.platform !== "darwin")
|
|
627
|
+
return Promise.resolve(null);
|
|
628
|
+
return new Promise((resolve) => {
|
|
629
|
+
// Check if clipboard has image data
|
|
630
|
+
execFile("osascript", ["-e", "clipboard info"], (err, stdout) => {
|
|
631
|
+
if (err || (!stdout.includes("PNGf") && !stdout.includes("TIFF"))) {
|
|
632
|
+
resolve(null);
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
// Determine format — prefer PNG
|
|
636
|
+
const isPng = stdout.includes("PNGf");
|
|
637
|
+
const clipClass = isPng ? "PNGf" : "TIFF";
|
|
638
|
+
const ext = isPng ? "png" : "tiff";
|
|
639
|
+
const mediaType = isPng ? "image/png" : "image/tiff";
|
|
640
|
+
// Write clipboard image to temp file, then read as base64
|
|
641
|
+
const tmpPath = `/tmp/ggcoder-clipboard-${Date.now()}.${ext}`;
|
|
642
|
+
const writeScript = [
|
|
643
|
+
`set imgData to the clipboard as «class ${clipClass}»`,
|
|
644
|
+
`set filePath to POSIX file "${tmpPath}"`,
|
|
645
|
+
`set fileRef to open for access filePath with write permission`,
|
|
646
|
+
`write imgData to fileRef`,
|
|
647
|
+
`close access fileRef`,
|
|
648
|
+
].join("\n");
|
|
649
|
+
execFile("osascript", ["-e", writeScript], async (writeErr) => {
|
|
650
|
+
if (writeErr) {
|
|
651
|
+
resolve(null);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
try {
|
|
655
|
+
const rawBuffer = await fs.readFile(tmpPath);
|
|
656
|
+
await fs.unlink(tmpPath).catch(() => { });
|
|
657
|
+
const { buffer: finalBuffer, mediaType: finalMediaType } = await shrinkToFit(rawBuffer, mediaType);
|
|
658
|
+
resolve({
|
|
659
|
+
kind: "image",
|
|
660
|
+
fileName: `clipboard.${ext}`,
|
|
661
|
+
filePath: tmpPath,
|
|
662
|
+
mediaType: finalMediaType,
|
|
663
|
+
data: finalBuffer.toString("base64"),
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
catch {
|
|
667
|
+
resolve(null);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
});
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
//# sourceMappingURL=image.js.map
|