carthagent 0.0.0-stage → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +219 -2
- package/bin/ctg.mjs +736 -0
- package/docs/budgets.md +72 -0
- package/docs/compaction.md +34 -0
- package/docs/context-efficiency-plan.md +24 -0
- package/docs/context-efficiency-review.md +27 -0
- package/docs/context-efficiency.md +49 -0
- package/docs/deepseek-jev-benchmark-plan.md +70 -0
- package/docs/deepseek-jev-benchmark-repair-plan.md +20 -0
- package/docs/deepseek-jev-benchmark-restart.md +9 -0
- package/docs/deepseek-jev-benchmark-results.md +77 -0
- package/docs/deepseek-jev-benchmark-running.md +60 -0
- package/docs/deepseek-jev-benchmark-v3-results.md +41 -0
- package/docs/deepseek-jev-benchmark-v4-protocol.md +15 -0
- package/docs/deepseek-jev-benchmark-v4-results.md +119 -0
- package/docs/deepseek-jev-http400-diagnosis.md +45 -0
- package/docs/delivery-review-evidence.md +53 -0
- package/docs/delivery-timeout-repair-plan.md +51 -0
- package/docs/evaluation-readiness.md +31 -0
- package/docs/evaluation.md +70 -0
- package/docs/extending.md +354 -0
- package/docs/glm-pilot-execution.md +9 -0
- package/docs/glm-pilot-plan.md +15 -0
- package/docs/glm-pilot-results.md +71 -0
- package/docs/graph-context-optimization.md +15 -0
- package/docs/jev-repository-pilot-plan.md +25 -0
- package/docs/jev-repository-pilot-protocol.md +39 -0
- package/docs/jev-repository-pilot-restart.md +7 -0
- package/docs/jev-repository-pilot-results.md +79 -0
- package/docs/jev.md +32 -0
- package/docs/model-registry.md +25 -0
- package/docs/native-compatibility.md +117 -0
- package/docs/opencode-archive.md +9 -0
- package/docs/opencode-migration.md +115 -0
- package/docs/opencode-runtime.md +94 -0
- package/docs/opencode-workspace.md +31 -0
- package/docs/owned-runtime-workflow-registration.md +17 -0
- package/docs/plan-advisor-evaluation.md +38 -0
- package/docs/planning-startup-fix-plan.md +23 -0
- package/docs/planning-startup-fix-review.md +24 -0
- package/docs/planning.md +118 -0
- package/docs/production-merge-review.md +23 -0
- package/docs/quality.md +35 -0
- package/docs/repository-benchmark-design.md +111 -0
- package/docs/review-assurance.md +9 -0
- package/docs/review-experiment-results.md +59 -0
- package/docs/tested-planning-roadmap.md +58 -0
- package/docs/tested-planning.md +58 -0
- package/docs/tui-pickers.md +9 -0
- package/docs/webdriver.md +83 -0
- package/docs/workflow-modes.md +26 -0
- package/docs/workflow.d2 +17 -0
- package/docs/workflow.svg +149 -0
- package/docs/workspace-coordination.md +9 -0
- package/evaluate.mjs +249 -0
- package/extensions/codegraph.ts +36 -0
- package/extensions/delivery.ts +819 -0
- package/extensions/experiential.ts +21 -0
- package/extensions/subscriptions.ts +21 -0
- package/guidance/profiles/authenticated-web.json +24 -0
- package/guidance/profiles/data-visualization.json +25 -0
- package/guidance/profiles/database-change.json +24 -0
- package/guidance/profiles/external-api.json +24 -0
- package/guidance/profiles/transactional-data.json +25 -0
- package/guidance/profiles/web-application.json +26 -0
- package/lib/acceptance-review.mjs +4 -0
- package/lib/browser-bin.mjs +160 -0
- package/lib/browser-errors.mjs +54 -0
- package/lib/browser.mjs +219 -0
- package/lib/budget.mjs +37 -0
- package/lib/cdp.mjs +221 -0
- package/lib/cloud/client.mjs +275 -0
- package/lib/cloud/control-plane.mjs +350 -0
- package/lib/cloud/gateway.mjs +380 -0
- package/lib/cloud/http.mjs +135 -0
- package/lib/cloud/ledger.mjs +215 -0
- package/lib/codegraph-query.mjs +60 -0
- package/lib/codegraph.mjs +378 -0
- package/lib/context-archive.mjs +18 -0
- package/lib/delivery-context.mjs +132 -0
- package/lib/delivery-guidance.mjs +9 -0
- package/lib/delivery-review.mjs +94 -0
- package/lib/delivery.mjs +610 -0
- package/lib/engine.mjs +137 -0
- package/lib/guidance.mjs +71 -0
- package/lib/jev-advisor.mjs +47 -0
- package/lib/opencode/archive.mjs +122 -0
- package/lib/opencode/compatibility.mjs +19 -0
- package/lib/opencode/credentials.mjs +205 -0
- package/lib/opencode/evaluation-budget-plugin/index.ts +147 -0
- package/lib/opencode/evaluation.mjs +242 -0
- package/lib/opencode/file-lock.mjs +86 -0
- package/lib/opencode/headless.mjs +200 -0
- package/lib/opencode/review.mjs +213 -0
- package/lib/opencode/runtime.mjs +246 -0
- package/lib/opencode/service.mjs +249 -0
- package/lib/opencode/session-options.mjs +60 -0
- package/lib/opencode/workspace.mjs +133 -0
- package/lib/openrouter-jev.mjs +37 -0
- package/lib/outcome-contract.mjs +21 -0
- package/lib/plan-advisor.mjs +38 -0
- package/lib/planning-access.mjs +7 -0
- package/lib/planning-advice.mjs +28 -0
- package/lib/planning-discovery.mjs +14 -0
- package/lib/planning-guide.mjs +34 -0
- package/lib/planning-view.mjs +57 -0
- package/lib/planning.mjs +155 -0
- package/lib/probe-diagnostics.mjs +13 -0
- package/lib/providers/experiential.mjs +292 -0
- package/lib/providers/model-catalog.json +700 -0
- package/lib/providers/model-catalog.mjs +7 -0
- package/lib/providers/names.mjs +13 -0
- package/lib/providers/subscription-models.mjs +483 -0
- package/lib/reports.mjs +80 -0
- package/lib/review-state.mjs +49 -0
- package/lib/review.mjs +114 -0
- package/lib/scenarios.mjs +99 -0
- package/lib/ship-auth.mjs +44 -0
- package/lib/ship-jev.mjs +59 -0
- package/lib/ship-telemetry.mjs +183 -0
- package/lib/tui/ansi.mjs +255 -0
- package/lib/tui/app.mjs +2445 -0
- package/lib/tui/auth.mjs +249 -0
- package/lib/tui/carthage.mjs +109 -0
- package/lib/tui/clipboard.mjs +122 -0
- package/lib/tui/d2.mjs +431 -0
- package/lib/tui/feed.mjs +467 -0
- package/lib/tui/framing.mjs +80 -0
- package/lib/tui/glyphs.mjs +172 -0
- package/lib/tui/hash-worker.mjs +11 -0
- package/lib/tui/mock-engine.mjs +222 -0
- package/lib/tui/models.mjs +73 -0
- package/lib/tui/picker.mjs +18 -0
- package/lib/tui/theme.mjs +663 -0
- package/lib/tui/title.mjs +7 -0
- package/lib/update-channel.mjs +62 -0
- package/lib/update.mjs +230 -0
- package/lib/webdriver.mjs +82 -0
- package/lib/workflow.mjs +88 -0
- package/lib/workspace.mjs +39 -0
- package/metadata.json +8 -0
- package/package.json +94 -4
- package/plugins/carthagent/index.ts +3 -0
- package/plugins/carthagent/package.json +28 -0
- package/plugins/carthagent/src/archive-rpc.ts +46 -0
- package/plugins/carthagent/src/bootstrap.ts +38 -0
- package/plugins/carthagent/src/index.ts +62 -0
- package/plugins/carthagent/src/pull-request-rpc.ts +54 -0
- package/plugins/carthagent/src/rpc.ts +76 -0
- package/plugins/carthagent/src/server/archive-rpc.ts +327 -0
- package/plugins/carthagent/src/server/budgets.ts +21 -0
- package/plugins/carthagent/src/server/codegraph.ts +46 -0
- package/plugins/carthagent/src/server/delivery.ts +488 -0
- package/plugins/carthagent/src/server/device-auth.ts +91 -0
- package/plugins/carthagent/src/server/native-delivery.ts +26 -0
- package/plugins/carthagent/src/server/orchestration.ts +56 -0
- package/plugins/carthagent/src/server/policy.ts +24 -0
- package/plugins/carthagent/src/server/providers.ts +424 -0
- package/plugins/carthagent/src/server/pull-request-rpc.ts +387 -0
- package/plugins/carthagent/src/server/session-controls.ts +82 -0
- package/plugins/carthagent/src/server/telemetry.ts +92 -0
- package/plugins/carthagent/src/server/workspace-rpc.ts +349 -0
- package/plugins/carthagent/src/session-rpc.ts +31 -0
- package/plugins/carthagent/src/testing.ts +85 -0
- package/plugins/carthagent/src/workspace-rpc.ts +133 -0
- package/plugins/carthagent/test-plugin/index.ts +4 -0
- package/plugins/carthagent/test-plugin/package.json +1 -0
- package/plugins/carthagent/tsconfig.json +19 -0
- package/plugins/carthagent/tui.ts +1 -0
- package/prompts/delivery.md +7 -0
- package/public/index.html +983 -0
- package/scenarios/cli/grade_cli.py +69 -0
- package/scenarios/cli/scenario.json +21 -0
- package/scenarios/game/baseline/minecraft.py +193 -0
- package/scenarios/game/context.md +1 -0
- package/scenarios/game/grade_minecraft_clone.py +603 -0
- package/scenarios/game/requirements.txt +2 -0
- package/scenarios/game/scenario.json +33 -0
- package/server.mjs +341 -0
- package/skills/game-development/SKILL.md +36 -0
- package/skills/game-development/assets/ursina_starter.py +98 -0
- package/skills/game-development/scripts/verify_ursina.py +80 -0
- package/skills/software-delivery/SKILL.md +50 -0
- package/skills/typescript-delivery/SKILL.md +69 -0
- package/tests/acceptance-review.test.mjs +13 -0
- package/tests/auth.test.mjs +234 -0
- package/tests/bounded-summary.test.mjs +68 -0
- package/tests/browser-bin.test.mjs +91 -0
- package/tests/browser.test.mjs +96 -0
- package/tests/budget-engine.test.mjs +110 -0
- package/tests/budget.test.mjs +23 -0
- package/tests/cli.test.mjs +245 -0
- package/tests/clipboard.test.mjs +79 -0
- package/tests/cloud-client.test.mjs +129 -0
- package/tests/cloud-control-plane.test.mjs +144 -0
- package/tests/cloud-gateway.test.mjs +147 -0
- package/tests/cloud-http.test.mjs +102 -0
- package/tests/cloud-ledger.test.mjs +75 -0
- package/tests/codegraph-query.test.mjs +66 -0
- package/tests/codegraph.test.mjs +142 -0
- package/tests/delivery-context.test.mjs +66 -0
- package/tests/delivery-review.test.mjs +139 -0
- package/tests/delivery.test.mjs +343 -0
- package/tests/engine-api.mjs +24 -0
- package/tests/experiential-extension.test.mjs +37 -0
- package/tests/experiential.test.mjs +300 -0
- package/tests/extension.test.mjs +921 -0
- package/tests/fixtures/archive-plugin/index.ts +10 -0
- package/tests/guidance.test.mjs +78 -0
- package/tests/model-registry.test.mjs +68 -0
- package/tests/models.test.mjs +70 -0
- package/tests/openai-idempotency.test.mjs +99 -0
- package/tests/opencode-archive-rpc.test.mjs +82 -0
- package/tests/opencode-delivery.test.mjs +231 -0
- package/tests/opencode-providers.test.mjs +414 -0
- package/tests/opencode-runtime.test.mjs +455 -0
- package/tests/opencode-session-controls.test.mjs +115 -0
- package/tests/opencode-session-options.test.mjs +26 -0
- package/tests/opencode-workspace.test.mjs +339 -0
- package/tests/outcome-contract.test.mjs +17 -0
- package/tests/picker.test.mjs +34 -0
- package/tests/plan-advisor.test.mjs +88 -0
- package/tests/plan-review-loop.test.mjs +53 -0
- package/tests/planning-advice.test.mjs +27 -0
- package/tests/planning-contract.test.mjs +65 -0
- package/tests/planning-startup.test.mjs +38 -0
- package/tests/planning-view.test.mjs +33 -0
- package/tests/planning.test.mjs +223 -0
- package/tests/probe-diagnostics.test.mjs +21 -0
- package/tests/pull-request-rpc.test.mjs +366 -0
- package/tests/review-state.test.mjs +32 -0
- package/tests/review.test.mjs +127 -0
- package/tests/server.test.mjs +252 -0
- package/tests/ship-jev.test.mjs +77 -0
- package/tests/ship-telemetry.test.mjs +333 -0
- package/tests/standard-workflow.test.mjs +28 -0
- package/tests/subscription-models.test.mjs +416 -0
- package/tests/subscriptions-extension.test.mjs +27 -0
- package/tests/terminal-title.test.mjs +13 -0
- package/tests/test_grade_minecraft_clone.py +199 -0
- package/tests/test_starter.py +78 -0
- package/tests/theme.test.mjs +175 -0
- package/tests/tui-copy-paste.test.mjs +54 -0
- package/tests/tui.test.mjs +808 -0
- package/tests/update-channels.test.mjs +129 -0
- package/tests/update.test.mjs +175 -0
- package/tests/webdriver.test.mjs +31 -0
- package/tests/workflow.test.mjs +47 -0
- package/tests/workspace-rpc.test.mjs +236 -0
- package/tests/workspace.test.mjs +24 -0
- package/tools/benchmark/advisor.test.mjs +7 -0
- package/tools/benchmark/advisor.ts +27 -0
- package/tools/benchmark/campaign.mjs +45 -0
- package/tools/benchmark/diagnose-request.mjs +40 -0
- package/tools/benchmark/eval-common.mjs +32 -0
- package/tools/benchmark/eval-ledger.mjs +22 -0
- package/tools/benchmark/eval-shop.mjs +26 -0
- package/tools/benchmark/eval-voxel.mjs +20 -0
- package/tools/benchmark/evaluate.mjs +24 -0
- package/tools/benchmark/evaluators.test.mjs +13 -0
- package/tools/benchmark/fixtures/shop/server.mjs +18 -0
- package/tools/benchmark/fixtures/shop/ui.html +8 -0
- package/tools/benchmark/freeze.mjs +30 -0
- package/tools/benchmark/gateway.mjs +91 -0
- package/tools/benchmark/gateway.test.mjs +38 -0
- package/tools/benchmark/generator.mjs +11 -0
- package/tools/benchmark/generator.test.mjs +26 -0
- package/tools/benchmark/guard.test.mjs +133 -0
- package/tools/benchmark/guard.ts +136 -0
- package/tools/benchmark/native-plugin/index.ts +24 -0
- package/tools/benchmark/planning-startup.test.mjs +47 -0
- package/tools/benchmark/preflight-live.mjs +31 -0
- package/tools/benchmark/preflight.mjs +22 -0
- package/tools/benchmark/replay-diagnostic.mjs +23 -0
- package/tools/benchmark/runner.mjs +141 -0
- package/tools/benchmark/runner.test.mjs +93 -0
- package/tools/benchmark/runtime.mjs +23 -0
- package/tools/benchmark/selftest.mjs +47 -0
- package/tools/benchmark/smoke-jev.mjs +5 -0
- package/tools/benchmark/tasks.mjs +20 -0
- package/tools/benchmark/transport.mjs +65 -0
- package/tools/benchmark/transport.test.mjs +44 -0
- package/tools/benchmark/upstream-error.mjs +18 -0
- package/tools/benchmark/upstream-error.test.mjs +10 -0
- package/tools/browser-check.mjs +109 -0
- package/tools/check-syntax.mjs +27 -0
- package/tools/evaluate-plan-advisor.mjs +20 -0
- package/tools/native-fixture.mjs +194 -0
- package/tools/native-pty-smoke.py +108 -0
- package/tools/native-report-plugin/index.ts +50 -0
- package/tools/native-report-plugin/package.json +7 -0
- package/tools/patch-compaction.mjs +24 -0
- package/tools/patch-model-catalog.mjs +12 -0
- package/tools/patch-print-shutdown.mjs +39 -0
- package/tools/repo-pilot/evaluator.cjs +32 -0
- package/tools/repo-pilot/reference.mjs +43 -0
- package/tools/repo-pilot/runner.mjs +85 -0
- package/tools/repo-pilot/sandbox-entry.mjs +12 -0
- package/tools/repo-pilot/tasks.mjs +20 -0
- package/tools/repo-pilot/type-evaluator.cjs +6 -0
- package/tools/test-native-controls.mjs +84 -0
- package/tools/test-native-delivery-host.mjs +307 -0
- package/tools/test-native-evaluation.mjs +46 -0
- package/tools/test-native-host.mjs +385 -0
- package/tools/test-native-outcomes.mjs +73 -0
- package/tools/test-native-package.mjs +70 -0
- package/tools/test-native-pty.mjs +20 -0
- package/tools/test-native-report.mjs +88 -0
- package/tools/test-native-swe-host.mjs +132 -0
- package/tools/test-native-swe.mjs +122 -0
- package/tools/test-picker-pty.py +45 -0
- package/tools/test-python.mjs +29 -0
- package/tools/test-webdriver.mjs +54 -0
- package/tools/verify-release-version.mjs +37 -0
- package/tools/webdriver-check.mjs +52 -0
- package/vendor/agent/bounded-summary.mjs +88 -0
- package/vendor/agent/chunks/anthropic-messages-VWZZOSJQ.js +6 -0
- package/vendor/agent/chunks/anthropic.js +75 -0
- package/vendor/agent/chunks/azure-openai-responses-BJLAM6CD.js +2 -0
- package/vendor/agent/chunks/bedrock-converse-stream.js +74 -0
- package/vendor/agent/chunks/chord-context.js +96 -0
- package/vendor/agent/chunks/chunk-4L3WN2XY.js +2 -0
- package/vendor/agent/chunks/chunk-6CYCI3EJ.js +12 -0
- package/vendor/agent/chunks/chunk-6R7UI4IY.js +2 -0
- package/vendor/agent/chunks/chunk-7ZC4UXSL.js +2 -0
- package/vendor/agent/chunks/chunk-AXIIZGTV.js +2 -0
- package/vendor/agent/chunks/chunk-CLNPYIDP.js +42 -0
- package/vendor/agent/chunks/chunk-DRQDKNXA.js +2 -0
- package/vendor/agent/chunks/chunk-GMWCTUPB.js +2 -0
- package/vendor/agent/chunks/chunk-IDDQWTHI.js +2 -0
- package/vendor/agent/chunks/chunk-JVUZSMYM.js +1548 -0
- package/vendor/agent/chunks/chunk-L2ZPNLYD.js +2 -0
- package/vendor/agent/chunks/chunk-NUHFSC37.js +25 -0
- package/vendor/agent/chunks/chunk-OUXLLA64.js +11 -0
- package/vendor/agent/chunks/chunk-PGXDEOVV.js +2 -0
- package/vendor/agent/chunks/chunk-PJACZCIR.js +2 -0
- package/vendor/agent/chunks/chunk-PRRNXB7S.js +2 -0
- package/vendor/agent/chunks/chunk-TEPMHNKQ.js +2 -0
- package/vendor/agent/chunks/chunk-TRDNDS6A.js +4 -0
- package/vendor/agent/chunks/chunk-U6ZMQKGD.js +50 -0
- package/vendor/agent/chunks/chunk-UAQELI3K.js +2 -0
- package/vendor/agent/chunks/chunk-USJZMAIR.js +2 -0
- package/vendor/agent/chunks/chunk-XDUWOHPL.js +6 -0
- package/vendor/agent/chunks/chunk-XNGRGP62.js +2 -0
- package/vendor/agent/chunks/github-copilot.js +2 -0
- package/vendor/agent/chunks/google-generative-ai-Q2K7FBDI.js +2 -0
- package/vendor/agent/chunks/google-vertex-7UJBF4S7.js +2 -0
- package/vendor/agent/chunks/https-proxy-agent-2VXB7436.js +13 -0
- package/vendor/agent/chunks/image-resize-worker.js +2 -0
- package/vendor/agent/chunks/kimi-coding.js +2 -0
- package/vendor/agent/chunks/lib-HGQMNYVT.js +9 -0
- package/vendor/agent/chunks/mistral-conversations-4M6BZBX6.js +5 -0
- package/vendor/agent/chunks/multipart-parser-SQ6GDJL7.js +3 -0
- package/vendor/agent/chunks/node-KG362ECQ.js +16 -0
- package/vendor/agent/chunks/node-TWVVAGPO.js +2 -0
- package/vendor/agent/chunks/openai-codex-responses-R6VYZTVY.js +10 -0
- package/vendor/agent/chunks/openai-codex.js +75 -0
- package/vendor/agent/chunks/openai-completions-EKZT2IH2.js +7 -0
- package/vendor/agent/chunks/openai-responses-TFDINO6W.js +2 -0
- package/vendor/agent/chunks/openrouter-images-N4XVVFSD.js +2 -0
- package/vendor/agent/chunks/openrouter.js +75 -0
- package/vendor/agent/chunks/pi-messages-PML4SPVJ.js +8 -0
- package/vendor/agent/chunks/radius.js +75 -0
- package/vendor/agent/chunks/src-UK77SYZE.js +4 -0
- package/vendor/agent/chunks/xai.js +2 -0
- package/vendor/agent/cli.js +3 -0
- package/vendor/agent/dist/modes/interactive/theme/dark.json +91 -0
- package/vendor/agent/dist/modes/interactive/theme/light.json +90 -0
- package/vendor/agent/dist/modes/interactive/theme/theme-schema.json +356 -0
- package/vendor/agent/index.js +2 -0
- package/vendor/agent/modes/interactive/theme/dark.json +91 -0
- package/vendor/agent/modes/interactive/theme/light.json +90 -0
- package/vendor/agent/modes/interactive/theme/theme-schema.json +356 -0
- package/vendor/agent/package.json +14 -0
- package/vendor/agent/rpc-entry.js +3 -0
- package/vendor/agent/theme/dark.json +91 -0
- package/vendor/agent/theme/light.json +90 -0
- package/vendor/agent/theme/theme-schema.json +356 -0
package/lib/tui/ansi.mjs
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/** ANSI + text-measurement primitives for the carthagent TUI. Zero dependencies.
|
|
2
|
+
*
|
|
3
|
+
* Truecolor-forced like opencode: 24-bit SGR always, unless the terminal is
|
|
4
|
+
* `dumb`, NO_COLOR is set, or CARTHAGENT_NO_TRUECOLOR=1 / CARTHAGENT_TRUECOLOR=0 opts out
|
|
5
|
+
* (which restores the legacy COLORTERM/TERM heuristic). `bgLine()` paints
|
|
6
|
+
* full-bleed background fills opencode-style.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const ESC = '\x1b';
|
|
10
|
+
export const RESET = `${ESC}[0m`;
|
|
11
|
+
export const BOLD = `${ESC}[1m`;
|
|
12
|
+
export const DIM = `${ESC}[2m`;
|
|
13
|
+
export const ITALIC = `${ESC}[3m`;
|
|
14
|
+
export const UNDERLINE = `${ESC}[4m`;
|
|
15
|
+
export const BLINK = `${ESC}[5m`;
|
|
16
|
+
export const INVERSE = `${ESC}[7m`;
|
|
17
|
+
export const STRIKE = `${ESC}[9m`;
|
|
18
|
+
|
|
19
|
+
export function detectColorDepth(env = process.env) {
|
|
20
|
+
if (env.TERM === 'dumb' || 'NO_COLOR' in env) return 4;
|
|
21
|
+
if (env.CARTHAGENT_NO_TRUECOLOR === '1' || env.CARTHAGENT_TRUECOLOR === '0') {
|
|
22
|
+
const ct = env.COLORTERM || '';
|
|
23
|
+
if (/truecolor|24bit/i.test(ct)) return 24;
|
|
24
|
+
if (/256color/i.test(env.TERM || '')) return 8;
|
|
25
|
+
return 4;
|
|
26
|
+
}
|
|
27
|
+
return 24;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const colorDepth = detectColorDepth();
|
|
31
|
+
|
|
32
|
+
/** True when the terminal can render opencode palettes at full fidelity. */
|
|
33
|
+
export function hasTruecolor(env = process.env) {
|
|
34
|
+
return detectColorDepth(env) === 24;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** One-line gold warning when truecolor is unavailable (opencode-style). */
|
|
38
|
+
export function truecolorWarning() {
|
|
39
|
+
return 'terminal lacks truecolor (set COLORTERM=truecolor) — colors approximated';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function hexToRgb(hex) {
|
|
43
|
+
const h = hex.replace('#', '');
|
|
44
|
+
const n = h.length === 3 ? h.split('').map(c => c + c).join('') : h;
|
|
45
|
+
return [parseInt(n.slice(0, 2), 16), parseInt(n.slice(2, 4), 16), parseInt(n.slice(4, 6), 16)];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const CUBE = [0, 95, 135, 175, 215, 255];
|
|
49
|
+
function rgbTo256(r, g, b) {
|
|
50
|
+
const gray = Math.round((r + g + b) / 3);
|
|
51
|
+
const ri = nearest(CUBE, r), gi = nearest(CUBE, g), bi = nearest(CUBE, b);
|
|
52
|
+
const cube = 16 + 36 * ri + 6 * gi + bi;
|
|
53
|
+
const grayIdx = gray < 8 ? 16 : gray > 248 ? 231 : 232 + Math.round((gray - 8) / 10);
|
|
54
|
+
const cd = (CUBE[ri] - r) ** 2 + (CUBE[gi] - g) ** 2 + (CUBE[bi] - b) ** 2;
|
|
55
|
+
const gs = grayIdx < 232 ? 0 : (grayIdx - 232) * 10 + 8;
|
|
56
|
+
const gd = 3 * (gs - gray) ** 2;
|
|
57
|
+
return gd < cd ? grayIdx : cube;
|
|
58
|
+
}
|
|
59
|
+
function nearest(arr, v) { let bi = 0, bd = 1e9; arr.forEach((x, i) => { const d = Math.abs(x - v); if (d < bd) { bd = d; bi = i; } }); return bi; }
|
|
60
|
+
|
|
61
|
+
/** Foreground color for a #rrggbb hex, honoring terminal color depth.
|
|
62
|
+
* 'none' passes through as '' (no SGR emitted). */
|
|
63
|
+
export function fg(hex) {
|
|
64
|
+
if (hex === 'none' || hex == null) return '';
|
|
65
|
+
const [r, g, b] = hexToRgb(hex);
|
|
66
|
+
if (colorDepth === 24) return `${ESC}[38;2;${r};${g};${b}m`;
|
|
67
|
+
if (colorDepth === 8) return `${ESC}[38;5;${rgbTo256(r, g, b)}m`;
|
|
68
|
+
return `${ESC}[${ansi16Index(r, g, b)}m`;
|
|
69
|
+
}
|
|
70
|
+
export function bg(hex) {
|
|
71
|
+
if (hex === 'none' || hex == null) return '';
|
|
72
|
+
const [r, g, b] = hexToRgb(hex);
|
|
73
|
+
if (colorDepth === 24) return `${ESC}[48;2;${r};${g};${b}m`;
|
|
74
|
+
if (colorDepth === 8) return `${ESC}[48;5;${rgbTo256(r, g, b)}m`;
|
|
75
|
+
return `${ESC}[${ansi16Index(r, g, b) + 10}m`;
|
|
76
|
+
}
|
|
77
|
+
const ANSI16 = [
|
|
78
|
+
[30, [0, 0, 0]], [31, [205, 49, 49]], [32, [13, 188, 121]], [33, [229, 229, 16]],
|
|
79
|
+
[34, [36, 114, 200]], [35, [188, 63, 188]], [36, [17, 168, 205]], [37, [229, 229, 229]],
|
|
80
|
+
[90, [102, 102, 102]], [91, [241, 76, 76]], [92, [35, 209, 139]], [93, [245, 245, 67]],
|
|
81
|
+
[94, [59, 142, 234]], [95, [214, 112, 214]], [96, [41, 184, 219]], [97, [255, 255, 255]],
|
|
82
|
+
];
|
|
83
|
+
function ansi16Index(r, g, b) {
|
|
84
|
+
let best = 37, bd = 1e9;
|
|
85
|
+
for (const [code, [cr, cg, cb]] of ANSI16) {
|
|
86
|
+
const d = (cr - r) ** 2 + (cg - g) ** 2 + (cb - b) ** 2;
|
|
87
|
+
if (d < bd) { bd = d; best = code; }
|
|
88
|
+
}
|
|
89
|
+
return best;
|
|
90
|
+
}
|
|
91
|
+
export function paint(text, hex) { return fg(hex) + text + RESET; }
|
|
92
|
+
export function mix(h1, h2, t) {
|
|
93
|
+
const a = hexToRgb(h1), b = hexToRgb(h2);
|
|
94
|
+
const c = a.map((v, i) => Math.round(v + (b[i] - v) * t));
|
|
95
|
+
return '#' + c.map(v => v.toString(16).padStart(2, '0')).join('');
|
|
96
|
+
}
|
|
97
|
+
/** Paint each char along a multi-stop gradient. */
|
|
98
|
+
export function gradient(text, stops) {
|
|
99
|
+
const chars = [...text];
|
|
100
|
+
if (chars.length <= 1 || stops.length === 1) return paint(text, stops[0]);
|
|
101
|
+
const segs = stops.length - 1;
|
|
102
|
+
return chars.map((ch, i) => {
|
|
103
|
+
const t = i / (chars.length - 1);
|
|
104
|
+
const seg = Math.min(segs - 1, Math.floor(t * segs));
|
|
105
|
+
return paint(ch, mix(stops[seg], stops[seg + 1], (t * segs) - seg));
|
|
106
|
+
}).join('');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Full-bleed background fill, opencode-style: paint `line` on `bgHex`,
|
|
111
|
+
* re-applying bg after every RESET (fg closes, modals, nested spans all
|
|
112
|
+
* reset), then pad with bg-painted spaces to width W. The caller must emit
|
|
113
|
+
* EL (`\x1b[K`) while bg is still active — see Screen.frame in app.mjs.
|
|
114
|
+
*/
|
|
115
|
+
export function bgLine(line, W, bgHex) {
|
|
116
|
+
const B = bg(bgHex);
|
|
117
|
+
if (!B) return line;
|
|
118
|
+
const painted = String(line).split(RESET).join(RESET + B);
|
|
119
|
+
const d = width(line);
|
|
120
|
+
const fill = d >= W ? '' : B + ' '.repeat(W - d);
|
|
121
|
+
return B + painted + fill + RESET;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const ANSI_RE = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
125
|
+
export function strip(s) { return String(s).replace(ANSI_RE, ''); }
|
|
126
|
+
|
|
127
|
+
/** Display width (wcwidth-lite): 0 combining/control, 2 wide/emoji. */
|
|
128
|
+
export function width(s) {
|
|
129
|
+
let w = 0;
|
|
130
|
+
for (const ch of strip(s)) {
|
|
131
|
+
const cp = ch.codePointAt(0);
|
|
132
|
+
w += charWidth(cp);
|
|
133
|
+
}
|
|
134
|
+
return w;
|
|
135
|
+
}
|
|
136
|
+
function charWidth(cp) {
|
|
137
|
+
if (cp < 32 || (cp >= 0x7f && cp < 0xa0)) return 0;
|
|
138
|
+
if ((cp >= 0x0300 && cp <= 0x036f) || (cp >= 0x1ab0 && cp <= 0x1aff) || (cp >= 0x1dc0 && cp <= 0x1dff) ||
|
|
139
|
+
(cp >= 0x20d0 && cp <= 0x20ff) || (cp >= 0xfe00 && cp <= 0xfe0f) || (cp >= 0xfe20 && cp <= 0xfe2f) ||
|
|
140
|
+
cp === 0x200d || cp === 0x200b) return 0;
|
|
141
|
+
if ((cp >= 0x1100 && cp <= 0x115f) || cp === 0x2329 || cp === 0x232a ||
|
|
142
|
+
(cp >= 0x2e80 && cp <= 0xa4cf) || (cp >= 0xac00 && cp <= 0xd7a3) ||
|
|
143
|
+
(cp >= 0xf900 && cp <= 0xfaff) || (cp >= 0xfe30 && cp <= 0xfe6f) ||
|
|
144
|
+
(cp >= 0xff00 && cp <= 0xff60) || (cp >= 0xffe0 && cp <= 0xffe6) ||
|
|
145
|
+
(cp >= 0x1f300 && cp <= 0x1faff) || (cp >= 0x20000 && cp <= 0x3fffd)) return 2;
|
|
146
|
+
return 1;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Truncate a styled string to a display width, preserving escapes + reset. */
|
|
150
|
+
export function truncate(s, w) {
|
|
151
|
+
let out = '', used = 0, i = 0;
|
|
152
|
+
const str = String(s);
|
|
153
|
+
while (i < str.length && used < w) {
|
|
154
|
+
if (str[i] === '\x1b') {
|
|
155
|
+
const m = str.slice(i).match(/^\x1b\[[0-9;?]*[ -/]*[@-~]/);
|
|
156
|
+
if (m) { out += m[0]; i += m[0].length; continue; }
|
|
157
|
+
}
|
|
158
|
+
const cp = str.codePointAt(i);
|
|
159
|
+
const ch = String.fromCodePoint(cp);
|
|
160
|
+
const cw = charWidth(cp);
|
|
161
|
+
if (used + cw > w) break;
|
|
162
|
+
out += ch; used += cw; i += ch.length;
|
|
163
|
+
}
|
|
164
|
+
return out + (i < str.length ? RESET : '');
|
|
165
|
+
}
|
|
166
|
+
export function padEnd(s, w, fill = ' ') {
|
|
167
|
+
const d = width(s);
|
|
168
|
+
return d >= w ? s : s + fill.repeat(w - d);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Slice a plain string to display columns [c0, c1); chars straddling the
|
|
172
|
+
* boundary are included so copied text matches the visual selection. */
|
|
173
|
+
export function sliceCols(s, c0, c1) {
|
|
174
|
+
let out = '', used = 0;
|
|
175
|
+
for (const ch of String(s)) {
|
|
176
|
+
const cw = charWidth(ch.codePointAt(0));
|
|
177
|
+
if (used >= c1) break;
|
|
178
|
+
if (used + cw > c0) out += ch;
|
|
179
|
+
used += cw;
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Wrap display columns [c0, c1) of a styled line in inverse video.
|
|
185
|
+
* Lines shorter than c0 are padded with plain spaces up to c0 first, then
|
|
186
|
+
* inverse padding up to c1, so multi-line selections read as a block. */
|
|
187
|
+
export function inverseCols(s, c0, c1) {
|
|
188
|
+
const str = String(s);
|
|
189
|
+
if (c1 <= c0) return str;
|
|
190
|
+
const close = `${ESC}[27m`;
|
|
191
|
+
let out = '', used = 0, i = 0, opened = false;
|
|
192
|
+
while (i < str.length && used < c1) {
|
|
193
|
+
if (str[i] === '\x1b') {
|
|
194
|
+
const m = str.slice(i).match(/^\x1b\[[0-9;?]*[ -/]*[@-~]/);
|
|
195
|
+
if (m) { out += m[0]; i += m[0].length; continue; }
|
|
196
|
+
}
|
|
197
|
+
const cp = str.codePointAt(i);
|
|
198
|
+
const ch = String.fromCodePoint(cp);
|
|
199
|
+
const cw = charWidth(cp);
|
|
200
|
+
if (!opened && used + cw > c0) { out += INVERSE; opened = true; }
|
|
201
|
+
out += ch;
|
|
202
|
+
used += cw;
|
|
203
|
+
i += ch.length;
|
|
204
|
+
}
|
|
205
|
+
if (opened) out += close;
|
|
206
|
+
out += str.slice(i);
|
|
207
|
+
if (used < c1) {
|
|
208
|
+
out += ' '.repeat(Math.max(0, c0 - used));
|
|
209
|
+
out += INVERSE + ' '.repeat(c1 - Math.max(used, c0)) + close;
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Word-wrap a styled/plain string to width. Returns array of styled lines. */
|
|
215
|
+
export function wrap(s, w) {
|
|
216
|
+
const out = [];
|
|
217
|
+
for (const rawLine of String(s).split('\n')) {
|
|
218
|
+
const words = rawLine.split(/(\s+)/);
|
|
219
|
+
let line = '', used = 0;
|
|
220
|
+
const push = () => { out.push(line); line = ''; used = 0; };
|
|
221
|
+
for (const word of words) {
|
|
222
|
+
const ww = width(word);
|
|
223
|
+
if (ww === 0) { line += word; continue; }
|
|
224
|
+
if (used + ww > w && used > 0) {
|
|
225
|
+
if (/^\s+$/.test(word)) continue;
|
|
226
|
+
push();
|
|
227
|
+
}
|
|
228
|
+
if (ww > w) {
|
|
229
|
+
// hard-break long token
|
|
230
|
+
for (const ch of word) {
|
|
231
|
+
const cw = charWidth(ch.codePointAt(0));
|
|
232
|
+
if (used + cw > w) push();
|
|
233
|
+
line += ch; used += cw;
|
|
234
|
+
}
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
line += word; used += ww;
|
|
238
|
+
}
|
|
239
|
+
push();
|
|
240
|
+
}
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** A styled line: array of {text, style} spans we can measure and compose. */
|
|
245
|
+
export function spans(line) { return [{ text: String(line) }]; }
|
|
246
|
+
export function cat(...styled) { return styled.join(''); }
|
|
247
|
+
|
|
248
|
+
export const SPINNER = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
249
|
+
export const DOTS = ['⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷'];
|
|
250
|
+
export function bar(frac, w, { filled = '█', empty = '░' } = {}) {
|
|
251
|
+
w = Math.max(0, Math.floor(w));
|
|
252
|
+
const n = Math.max(0, Math.min(1, frac));
|
|
253
|
+
const f = Math.round(n * w);
|
|
254
|
+
return filled.repeat(f) + empty.repeat(w - f);
|
|
255
|
+
}
|