indusagi 0.12.19 → 0.12.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -36
- package/dist/agent/agent-loop.d.ts +3 -9
- package/dist/agent/agent-loop.d.ts.map +1 -1
- package/dist/agent/agent-loop.js +19 -58
- package/dist/agent/agent-loop.js.map +1 -1
- package/dist/agent/agent.d.ts +9 -10
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +182 -129
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/error-handler.d.ts.map +1 -1
- package/dist/agent/error-handler.js.map +1 -1
- package/dist/agent/event-bus.d.ts.map +1 -1
- package/dist/agent/event-bus.js +1 -3
- package/dist/agent/event-bus.js.map +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +0 -6
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/messages.d.ts +1 -1
- package/dist/agent/messages.d.ts.map +1 -1
- package/dist/agent/proxy.d.ts +1 -14
- package/dist/agent/proxy.d.ts.map +1 -1
- package/dist/agent/proxy.js +67 -148
- package/dist/agent/proxy.js.map +1 -1
- package/dist/agent/session-manager.d.ts +10 -10
- package/dist/agent/session-manager.d.ts.map +1 -1
- package/dist/agent/session-manager.js +20 -16
- package/dist/agent/session-manager.js.map +1 -1
- package/dist/agent/state-manager.d.ts +1 -1
- package/dist/agent/state-manager.d.ts.map +1 -1
- package/dist/agent/state-manager.js +1 -0
- package/dist/agent/state-manager.js.map +1 -1
- package/dist/agent/telemetry.d.ts.map +1 -1
- package/dist/agent/telemetry.js +1 -3
- package/dist/agent/telemetry.js.map +1 -1
- package/dist/agent/tools/bash.d.ts.map +1 -1
- package/dist/agent/tools/bash.js +143 -118
- package/dist/agent/tools/bash.js.map +1 -1
- package/dist/agent/tools/edit-diff.d.ts +1 -1
- package/dist/agent/tools/edit-diff.d.ts.map +1 -1
- package/dist/agent/tools/edit-diff.js +189 -175
- package/dist/agent/tools/edit-diff.js.map +1 -1
- package/dist/agent/tools/edit.d.ts.map +1 -1
- package/dist/agent/tools/edit.js +137 -121
- package/dist/agent/tools/edit.js.map +1 -1
- package/dist/agent/tools/find.d.ts.map +1 -1
- package/dist/agent/tools/find.js +100 -65
- package/dist/agent/tools/find.js.map +1 -1
- package/dist/agent/tools/grep.d.ts.map +1 -1
- package/dist/agent/tools/grep.js +126 -97
- package/dist/agent/tools/grep.js.map +1 -1
- package/dist/agent/tools/index.d.ts +53 -40
- package/dist/agent/tools/index.d.ts.map +1 -1
- package/dist/agent/tools/index.js +19 -12
- package/dist/agent/tools/index.js.map +1 -1
- package/dist/agent/tools/ls.d.ts +2 -1
- package/dist/agent/tools/ls.d.ts.map +1 -1
- package/dist/agent/tools/ls.js +145 -94
- package/dist/agent/tools/ls.js.map +1 -1
- package/dist/agent/tools/path-utils.d.ts.map +1 -1
- package/dist/agent/tools/path-utils.js +48 -29
- package/dist/agent/tools/path-utils.js.map +1 -1
- package/dist/agent/tools/process-controller.d.ts +15 -0
- package/dist/agent/tools/process-controller.d.ts.map +1 -0
- package/dist/agent/tools/process-controller.js +39 -0
- package/dist/agent/tools/process-controller.js.map +1 -0
- package/dist/agent/tools/process-manager.d.ts +60 -0
- package/dist/agent/tools/process-manager.d.ts.map +1 -0
- package/dist/agent/tools/process-manager.js +485 -0
- package/dist/agent/tools/process-manager.js.map +1 -0
- package/dist/agent/tools/process-types.d.ts +74 -0
- package/dist/agent/tools/process-types.d.ts.map +1 -0
- package/dist/agent/tools/process-types.js +7 -0
- package/dist/agent/tools/process-types.js.map +1 -0
- package/dist/agent/tools/process.d.ts +38 -0
- package/dist/agent/tools/process.d.ts.map +1 -0
- package/dist/agent/tools/process.js +360 -0
- package/dist/agent/tools/process.js.map +1 -0
- package/dist/agent/tools/read.d.ts.map +1 -1
- package/dist/agent/tools/read.js +157 -135
- package/dist/agent/tools/read.js.map +1 -1
- package/dist/agent/tools/registry.js +2 -4
- package/dist/agent/tools/registry.js.map +1 -1
- package/dist/agent/tools/teams/activity-tracker.d.ts +66 -0
- package/dist/agent/tools/teams/activity-tracker.d.ts.map +1 -0
- package/dist/agent/tools/teams/activity-tracker.js +480 -0
- package/dist/agent/tools/teams/activity-tracker.js.map +1 -0
- package/dist/agent/tools/teams/cleanup.d.ts +51 -0
- package/dist/agent/tools/teams/cleanup.d.ts.map +1 -0
- package/dist/agent/tools/teams/cleanup.js +219 -0
- package/dist/agent/tools/teams/cleanup.js.map +1 -0
- package/dist/agent/tools/teams/fs-lock.d.ts +12 -0
- package/dist/agent/tools/teams/fs-lock.d.ts.map +1 -0
- package/dist/agent/tools/teams/fs-lock.js +74 -0
- package/dist/agent/tools/teams/fs-lock.js.map +1 -0
- package/dist/agent/tools/teams/index.d.ts +12 -0
- package/dist/agent/tools/teams/index.d.ts.map +1 -0
- package/dist/agent/tools/teams/index.js +12 -0
- package/dist/agent/tools/teams/index.js.map +1 -0
- package/dist/agent/tools/teams/mailbox.d.ts +21 -0
- package/dist/agent/tools/teams/mailbox.d.ts.map +1 -0
- package/dist/agent/tools/teams/mailbox.js +106 -0
- package/dist/agent/tools/teams/mailbox.js.map +1 -0
- package/dist/agent/tools/teams/model-policy.d.ts +23 -0
- package/dist/agent/tools/teams/model-policy.d.ts.map +1 -0
- package/dist/agent/tools/teams/model-policy.js +113 -0
- package/dist/agent/tools/teams/model-policy.js.map +1 -0
- package/dist/agent/tools/teams/names.d.ts +28 -0
- package/dist/agent/tools/teams/names.d.ts.map +1 -0
- package/dist/agent/tools/teams/names.js +109 -0
- package/dist/agent/tools/teams/names.js.map +1 -0
- package/dist/agent/tools/teams/protocol.d.ts +75 -0
- package/dist/agent/tools/teams/protocol.d.ts.map +1 -0
- package/dist/agent/tools/teams/protocol.js +205 -0
- package/dist/agent/tools/teams/protocol.js.map +1 -0
- package/dist/agent/tools/teams/task-store.d.ts +89 -0
- package/dist/agent/tools/teams/task-store.d.ts.map +1 -0
- package/dist/agent/tools/teams/task-store.js +445 -0
- package/dist/agent/tools/teams/task-store.js.map +1 -0
- package/dist/agent/tools/teams/team-attach-claim.d.ts +36 -0
- package/dist/agent/tools/teams/team-attach-claim.d.ts.map +1 -0
- package/dist/agent/tools/teams/team-attach-claim.js +144 -0
- package/dist/agent/tools/teams/team-attach-claim.js.map +1 -0
- package/dist/agent/tools/teams/team-config.d.ts +55 -0
- package/dist/agent/tools/teams/team-config.d.ts.map +1 -0
- package/dist/agent/tools/teams/team-config.js +252 -0
- package/dist/agent/tools/teams/team-config.js.map +1 -0
- package/dist/agent/tools/teams/worktree.d.ts +40 -0
- package/dist/agent/tools/teams/worktree.d.ts.map +1 -0
- package/dist/agent/tools/teams/worktree.js +213 -0
- package/dist/agent/tools/teams/worktree.js.map +1 -0
- package/dist/agent/tools/todo-store.js +2 -1
- package/dist/agent/tools/todo-store.js.map +1 -1
- package/dist/agent/tools/todo.d.ts +2 -2
- package/dist/agent/tools/todo.js +2 -2
- package/dist/agent/tools/truncate.d.ts.map +1 -1
- package/dist/agent/tools/truncate.js +150 -134
- package/dist/agent/tools/truncate.js.map +1 -1
- package/dist/agent/tools/utils/hook-runner.d.ts +9 -10
- package/dist/agent/tools/utils/hook-runner.d.ts.map +1 -1
- package/dist/agent/tools/utils/hook-runner.js +18 -16
- package/dist/agent/tools/utils/hook-runner.js.map +1 -1
- package/dist/agent/tools/utils/image-resize.d.ts +1 -14
- package/dist/agent/tools/utils/image-resize.d.ts.map +1 -1
- package/dist/agent/tools/utils/image-resize.js +80 -34
- package/dist/agent/tools/utils/image-resize.js.map +1 -1
- package/dist/agent/tools/utils/mime.d.ts +0 -8
- package/dist/agent/tools/utils/mime.d.ts.map +1 -1
- package/dist/agent/tools/utils/mime.js +43 -32
- package/dist/agent/tools/utils/mime.js.map +1 -1
- package/dist/agent/tools/utils/shell.d.ts +1 -23
- package/dist/agent/tools/utils/shell.d.ts.map +1 -1
- package/dist/agent/tools/utils/shell.js +43 -86
- package/dist/agent/tools/utils/shell.js.map +1 -1
- package/dist/agent/tools/write.d.ts.map +1 -1
- package/dist/agent/tools/write.js +105 -62
- package/dist/agent/tools/write.js.map +1 -1
- package/dist/agent/types.d.ts +69 -64
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js +38 -23
- package/dist/agent/types.js.map +1 -1
- package/dist/agent.d.ts +4 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +4 -0
- package/dist/agent.js.map +1 -1
- package/dist/ai/api-registry.d.ts.map +1 -1
- package/dist/ai/api-registry.js +3 -4
- package/dist/ai/api-registry.js.map +1 -1
- package/dist/ai/cli.js +62 -82
- package/dist/ai/cli.js.map +1 -1
- package/dist/ai/env-api-keys.d.ts.map +1 -1
- package/dist/ai/env-api-keys.js +78 -81
- package/dist/ai/env-api-keys.js.map +1 -1
- package/dist/ai/index.d.ts +6 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +6 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/models.d.ts +7 -17
- package/dist/ai/models.d.ts.map +1 -1
- package/dist/ai/models.generated.d.ts +19 -0
- package/dist/ai/models.generated.d.ts.map +1 -1
- package/dist/ai/models.generated.js +14 -2
- package/dist/ai/models.generated.js.map +1 -1
- package/dist/ai/models.js +17 -11
- package/dist/ai/models.js.map +1 -1
- package/dist/ai/providers/amazon-bedrock.d.ts.map +1 -1
- package/dist/ai/providers/amazon-bedrock.js +319 -248
- package/dist/ai/providers/amazon-bedrock.js.map +1 -1
- package/dist/ai/providers/anthropic.d.ts.map +1 -1
- package/dist/ai/providers/anthropic.js +378 -324
- package/dist/ai/providers/anthropic.js.map +1 -1
- package/dist/ai/providers/azure-openai-responses.d.ts.map +1 -1
- package/dist/ai/providers/azure-openai-responses.js +164 -123
- package/dist/ai/providers/azure-openai-responses.js.map +1 -1
- package/dist/ai/providers/google-shared.d.ts +0 -18
- package/dist/ai/providers/google-shared.d.ts.map +1 -1
- package/dist/ai/providers/google-shared.js +224 -225
- package/dist/ai/providers/google-shared.js.map +1 -1
- package/dist/ai/providers/google-vertex.d.ts.map +1 -1
- package/dist/ai/providers/google-vertex.js +244 -226
- package/dist/ai/providers/google-vertex.js.map +1 -1
- package/dist/ai/providers/google.d.ts +3 -0
- package/dist/ai/providers/google.d.ts.map +1 -1
- package/dist/ai/providers/google.js +232 -210
- package/dist/ai/providers/google.js.map +1 -1
- package/dist/ai/providers/kimi.js +1 -0
- package/dist/ai/providers/kimi.js.map +1 -1
- package/dist/ai/providers/mock.d.ts +10 -0
- package/dist/ai/providers/mock.d.ts.map +1 -0
- package/dist/ai/providers/mock.js +64 -0
- package/dist/ai/providers/mock.js.map +1 -0
- package/dist/ai/providers/openai-codex-responses.d.ts.map +1 -1
- package/dist/ai/providers/openai-codex-responses.js +178 -133
- package/dist/ai/providers/openai-codex-responses.js.map +1 -1
- package/dist/ai/providers/openai-completions.d.ts.map +1 -1
- package/dist/ai/providers/openai-completions.js +468 -387
- package/dist/ai/providers/openai-completions.js.map +1 -1
- package/dist/ai/providers/openai-responses-shared.d.ts.map +1 -1
- package/dist/ai/providers/openai-responses-shared.js +187 -166
- package/dist/ai/providers/openai-responses-shared.js.map +1 -1
- package/dist/ai/providers/openai-responses.d.ts.map +1 -1
- package/dist/ai/providers/openai-responses.js +108 -85
- package/dist/ai/providers/openai-responses.js.map +1 -1
- package/dist/ai/providers/openai-scaffold.d.ts +4 -0
- package/dist/ai/providers/openai-scaffold.d.ts.map +1 -0
- package/dist/ai/providers/openai-scaffold.js +33 -0
- package/dist/ai/providers/openai-scaffold.js.map +1 -0
- package/dist/ai/providers/register-builtins.d.ts.map +1 -1
- package/dist/ai/providers/register-builtins.js +109 -42
- package/dist/ai/providers/register-builtins.js.map +1 -1
- package/dist/ai/providers/simple-options.js +2 -0
- package/dist/ai/providers/simple-options.js.map +1 -1
- package/dist/ai/providers/transform-messages.js +3 -9
- package/dist/ai/providers/transform-messages.js.map +1 -1
- package/dist/ai/stream.d.ts +4 -14
- package/dist/ai/stream.d.ts.map +1 -1
- package/dist/ai/stream.js +0 -36
- package/dist/ai/stream.js.map +1 -1
- package/dist/ai/types.d.ts +22 -3
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +154 -77
- package/dist/ai/types.js.map +1 -1
- package/dist/ai/utils/base-stream-handler.js +1 -0
- package/dist/ai/utils/base-stream-handler.js.map +1 -1
- package/dist/ai/utils/event-stream.d.ts +2 -0
- package/dist/ai/utils/event-stream.d.ts.map +1 -1
- package/dist/ai/utils/event-stream.js +22 -5
- package/dist/ai/utils/event-stream.js.map +1 -1
- package/dist/ai/utils/json-parse.d.ts +3 -0
- package/dist/ai/utils/json-parse.d.ts.map +1 -1
- package/dist/ai/utils/json-parse.js +8 -5
- package/dist/ai/utils/json-parse.js.map +1 -1
- package/dist/ai/utils/oauth/anthropic.d.ts.map +1 -1
- package/dist/ai/utils/oauth/anthropic.js +110 -65
- package/dist/ai/utils/oauth/anthropic.js.map +1 -1
- package/dist/ai/utils/oauth/github-copilot.d.ts +8 -16
- package/dist/ai/utils/oauth/github-copilot.d.ts.map +1 -1
- package/dist/ai/utils/oauth/github-copilot.js +218 -227
- package/dist/ai/utils/oauth/github-copilot.js.map +1 -1
- package/dist/ai/utils/oauth/openai-codex.d.ts +4 -2
- package/dist/ai/utils/oauth/openai-codex.d.ts.map +1 -1
- package/dist/ai/utils/oauth/openai-codex.js +221 -236
- package/dist/ai/utils/oauth/openai-codex.js.map +1 -1
- package/dist/ai/utils/oauth/pkce.d.ts +6 -5
- package/dist/ai/utils/oauth/pkce.d.ts.map +1 -1
- package/dist/ai/utils/oauth/pkce.js +24 -21
- package/dist/ai/utils/oauth/pkce.js.map +1 -1
- package/dist/ai/utils/oauth/types.d.ts +31 -12
- package/dist/ai/utils/oauth/types.d.ts.map +1 -1
- package/dist/ai/utils/oauth/types.js +10 -1
- package/dist/ai/utils/oauth/types.js.map +1 -1
- package/dist/ai/utils/overflow.d.ts.map +1 -1
- package/dist/ai/utils/overflow.js +49 -21
- package/dist/ai/utils/overflow.js.map +1 -1
- package/dist/ai/utils/provider-adapter.js +9 -0
- package/dist/ai/utils/provider-adapter.js.map +1 -1
- package/dist/ai/utils/provider-client-builder.js +1 -1
- package/dist/ai/utils/provider-client-builder.js.map +1 -1
- package/dist/ai/utils/provider-errors.js +2 -0
- package/dist/ai/utils/provider-errors.js.map +1 -1
- package/dist/ai/utils/sanitize-unicode.d.ts +0 -20
- package/dist/ai/utils/sanitize-unicode.d.ts.map +1 -1
- package/dist/ai/utils/sanitize-unicode.js +35 -17
- package/dist/ai/utils/sanitize-unicode.js.map +1 -1
- package/dist/ai/utils/stream-event-helper.js +3 -0
- package/dist/ai/utils/stream-event-helper.js.map +1 -1
- package/dist/ai/utils/stream-handler-types.js +5 -0
- package/dist/ai/utils/stream-handler-types.js.map +1 -1
- package/dist/ai/utils/streaming-state-manager.js +4 -2
- package/dist/ai/utils/streaming-state-manager.js.map +1 -1
- package/dist/ai/utils/typebox-helpers.d.ts +6 -4
- package/dist/ai/utils/typebox-helpers.d.ts.map +1 -1
- package/dist/ai/utils/typebox-helpers.js +25 -7
- package/dist/ai/utils/typebox-helpers.js.map +1 -1
- package/dist/ai/utils/validation.d.ts.map +1 -1
- package/dist/ai/utils/validation.js +67 -34
- package/dist/ai/utils/validation.js.map +1 -1
- package/dist/ai.d.ts +4 -0
- package/dist/ai.d.ts.map +1 -1
- package/dist/ai.js +4 -0
- package/dist/ai.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/client-pool.js +3 -2
- package/dist/mcp/client-pool.js.map +1 -1
- package/dist/mcp/client.js +19 -6
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/config.d.ts +6 -6
- package/dist/mcp/config.js +17 -17
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/errors.js +8 -0
- package/dist/mcp/errors.js.map +1 -1
- package/dist/mcp/index.d.ts +5 -5
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/schema-converter.d.ts +1 -1
- package/dist/mcp/schema-converter.js +1 -1
- package/dist/mcp/server.d.ts +4 -4
- package/dist/mcp/server.js +12 -7
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tool-factory.d.ts +2 -2
- package/dist/mcp/tool-factory.js +2 -2
- package/dist/mcp.d.ts +0 -4
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +0 -4
- package/dist/mcp.js.map +1 -1
- package/dist/observability.d.ts +2 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +2 -0
- package/dist/observability.js.map +1 -0
- package/dist/tui/autocomplete.d.ts +14 -18
- package/dist/tui/autocomplete.d.ts.map +1 -1
- package/dist/tui/autocomplete.js +290 -402
- package/dist/tui/autocomplete.js.map +1 -1
- package/dist/tui/components/box.d.ts +1 -6
- package/dist/tui/components/box.d.ts.map +1 -1
- package/dist/tui/components/box.js +98 -67
- package/dist/tui/components/box.js.map +1 -1
- package/dist/tui/components/cancellable-loader.d.ts +6 -3
- package/dist/tui/components/cancellable-loader.d.ts.map +1 -1
- package/dist/tui/components/cancellable-loader.js +8 -9
- package/dist/tui/components/cancellable-loader.js.map +1 -1
- package/dist/tui/components/editor.d.ts +18 -0
- package/dist/tui/components/editor.d.ts.map +1 -1
- package/dist/tui/components/editor.js +356 -354
- package/dist/tui/components/editor.js.map +1 -1
- package/dist/tui/components/image.d.ts +2 -0
- package/dist/tui/components/image.d.ts.map +1 -1
- package/dist/tui/components/image.js +79 -37
- package/dist/tui/components/image.js.map +1 -1
- package/dist/tui/components/input.d.ts +4 -8
- package/dist/tui/components/input.d.ts.map +1 -1
- package/dist/tui/components/input.js +236 -232
- package/dist/tui/components/input.js.map +1 -1
- package/dist/tui/components/loader.d.ts +5 -5
- package/dist/tui/components/loader.d.ts.map +1 -1
- package/dist/tui/components/loader.js +22 -19
- package/dist/tui/components/loader.js.map +1 -1
- package/dist/tui/components/markdown.d.ts +2 -32
- package/dist/tui/components/markdown.d.ts.map +1 -1
- package/dist/tui/components/markdown.js +338 -357
- package/dist/tui/components/markdown.js.map +1 -1
- package/dist/tui/components/select-list.d.ts +1 -0
- package/dist/tui/components/select-list.d.ts.map +1 -1
- package/dist/tui/components/select-list.js +83 -82
- package/dist/tui/components/select-list.js.map +1 -1
- package/dist/tui/components/settings-list.d.ts +10 -10
- package/dist/tui/components/settings-list.d.ts.map +1 -1
- package/dist/tui/components/settings-list.js +48 -40
- package/dist/tui/components/settings-list.js.map +1 -1
- package/dist/tui/components/spacer.d.ts +1 -0
- package/dist/tui/components/spacer.d.ts.map +1 -1
- package/dist/tui/components/spacer.js +20 -5
- package/dist/tui/components/spacer.js.map +1 -1
- package/dist/tui/components/text.d.ts.map +1 -1
- package/dist/tui/components/text.js +47 -20
- package/dist/tui/components/text.js.map +1 -1
- package/dist/tui/components/truncated-text.d.ts +8 -4
- package/dist/tui/components/truncated-text.d.ts.map +1 -1
- package/dist/tui/components/truncated-text.js +15 -12
- package/dist/tui/components/truncated-text.js.map +1 -1
- package/dist/tui/editor-component.d.ts +87 -23
- package/dist/tui/editor-component.d.ts.map +1 -1
- package/dist/tui/fuzzy.d.ts.map +1 -1
- package/dist/tui/fuzzy.js +101 -50
- package/dist/tui/fuzzy.js.map +1 -1
- package/dist/tui/keybindings.d.ts +3 -3
- package/dist/tui/keybindings.d.ts.map +1 -1
- package/dist/tui/keybindings.js +137 -111
- package/dist/tui/keybindings.js.map +1 -1
- package/dist/tui/keys.d.ts +46 -43
- package/dist/tui/keys.d.ts.map +1 -1
- package/dist/tui/keys.js +493 -411
- package/dist/tui/keys.js.map +1 -1
- package/dist/tui/stdin-buffer.d.ts.map +1 -1
- package/dist/tui/stdin-buffer.js +162 -159
- package/dist/tui/stdin-buffer.js.map +1 -1
- package/dist/tui/terminal-image.d.ts +10 -5
- package/dist/tui/terminal-image.d.ts.map +1 -1
- package/dist/tui/terminal-image.js +53 -51
- package/dist/tui/terminal-image.js.map +1 -1
- package/dist/tui/terminal.d.ts +4 -27
- package/dist/tui/terminal.d.ts.map +1 -1
- package/dist/tui/terminal.js +123 -121
- package/dist/tui/terminal.js.map +1 -1
- package/dist/tui/tui.d.ts +14 -1
- package/dist/tui/tui.d.ts.map +1 -1
- package/dist/tui/tui.js +185 -145
- package/dist/tui/tui.js.map +1 -1
- package/dist/tui/utils.d.ts.map +1 -1
- package/dist/tui/utils.js +235 -216
- package/dist/tui/utils.js.map +1 -1
- package/dist/tui.d.ts +4 -0
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +4 -0
- package/dist/tui.js.map +1 -1
- package/package.json +23 -43
- package/LICENSE.md +0 -22
- package/dist/agent/tools/task-types.d.ts +0 -74
- package/dist/agent/tools/task-types.d.ts.map +0 -1
- package/dist/agent/tools/task-types.js +0 -8
- package/dist/agent/tools/task-types.js.map +0 -1
- package/dist/agent/tools/task.d.ts +0 -84
- package/dist/agent/tools/task.d.ts.map +0 -1
- package/dist/agent/tools/task.js +0 -184
- package/dist/agent/tools/task.js.map +0 -1
- package/dist/memory/embedder/base.d.ts +0 -41
- package/dist/memory/embedder/base.d.ts.map +0 -1
- package/dist/memory/embedder/base.js +0 -10
- package/dist/memory/embedder/base.js.map +0 -1
- package/dist/memory/embedder/index.d.ts +0 -8
- package/dist/memory/embedder/index.d.ts.map +0 -1
- package/dist/memory/embedder/index.js +0 -6
- package/dist/memory/embedder/index.js.map +0 -1
- package/dist/memory/embedder/openai.d.ts +0 -35
- package/dist/memory/embedder/openai.d.ts.map +0 -1
- package/dist/memory/embedder/openai.js +0 -103
- package/dist/memory/embedder/openai.js.map +0 -1
- package/dist/memory/index.d.ts +0 -33
- package/dist/memory/index.d.ts.map +0 -1
- package/dist/memory/index.js +0 -31
- package/dist/memory/index.js.map +0 -1
- package/dist/memory/memory.d.ts +0 -126
- package/dist/memory/memory.d.ts.map +0 -1
- package/dist/memory/memory.js +0 -280
- package/dist/memory/memory.js.map +0 -1
- package/dist/memory/processors/base.d.ts +0 -42
- package/dist/memory/processors/base.d.ts.map +0 -1
- package/dist/memory/processors/base.js +0 -6
- package/dist/memory/processors/base.js.map +0 -1
- package/dist/memory/processors/index.d.ts +0 -16
- package/dist/memory/processors/index.d.ts.map +0 -1
- package/dist/memory/processors/index.js +0 -18
- package/dist/memory/processors/index.js.map +0 -1
- package/dist/memory/processors/message-history.d.ts +0 -35
- package/dist/memory/processors/message-history.d.ts.map +0 -1
- package/dist/memory/processors/message-history.js +0 -51
- package/dist/memory/processors/message-history.js.map +0 -1
- package/dist/memory/processors/observational-memory/index.d.ts +0 -82
- package/dist/memory/processors/observational-memory/index.d.ts.map +0 -1
- package/dist/memory/processors/observational-memory/index.js +0 -234
- package/dist/memory/processors/observational-memory/index.js.map +0 -1
- package/dist/memory/processors/observational-memory/observer-agent.d.ts +0 -64
- package/dist/memory/processors/observational-memory/observer-agent.d.ts.map +0 -1
- package/dist/memory/processors/observational-memory/observer-agent.js +0 -362
- package/dist/memory/processors/observational-memory/observer-agent.js.map +0 -1
- package/dist/memory/processors/observational-memory/reflector-agent.d.ts +0 -38
- package/dist/memory/processors/observational-memory/reflector-agent.d.ts.map +0 -1
- package/dist/memory/processors/observational-memory/reflector-agent.js +0 -213
- package/dist/memory/processors/observational-memory/reflector-agent.js.map +0 -1
- package/dist/memory/processors/observational-memory/token-counter.d.ts +0 -35
- package/dist/memory/processors/observational-memory/token-counter.d.ts.map +0 -1
- package/dist/memory/processors/observational-memory/token-counter.js +0 -90
- package/dist/memory/processors/observational-memory/token-counter.js.map +0 -1
- package/dist/memory/processors/semantic-recall.d.ts +0 -55
- package/dist/memory/processors/semantic-recall.d.ts.map +0 -1
- package/dist/memory/processors/semantic-recall.js +0 -143
- package/dist/memory/processors/semantic-recall.js.map +0 -1
- package/dist/memory/processors/working-memory.d.ts +0 -41
- package/dist/memory/processors/working-memory.d.ts.map +0 -1
- package/dist/memory/processors/working-memory.js +0 -82
- package/dist/memory/processors/working-memory.js.map +0 -1
- package/dist/memory/storage/base.d.ts +0 -288
- package/dist/memory/storage/base.d.ts.map +0 -1
- package/dist/memory/storage/base.js +0 -211
- package/dist/memory/storage/base.js.map +0 -1
- package/dist/memory/storage/index.d.ts +0 -9
- package/dist/memory/storage/index.d.ts.map +0 -1
- package/dist/memory/storage/index.js +0 -7
- package/dist/memory/storage/index.js.map +0 -1
- package/dist/memory/storage/inmemory.d.ts +0 -93
- package/dist/memory/storage/inmemory.d.ts.map +0 -1
- package/dist/memory/storage/inmemory.js +0 -646
- package/dist/memory/storage/inmemory.js.map +0 -1
- package/dist/memory/tools/working-memory.d.ts +0 -100
- package/dist/memory/tools/working-memory.d.ts.map +0 -1
- package/dist/memory/tools/working-memory.js +0 -237
- package/dist/memory/tools/working-memory.js.map +0 -1
- package/dist/memory/types.d.ts +0 -386
- package/dist/memory/types.d.ts.map +0 -1
- package/dist/memory/types.js +0 -58
- package/dist/memory/types.js.map +0 -1
- package/dist/memory/vector/base.d.ts +0 -145
- package/dist/memory/vector/base.d.ts.map +0 -1
- package/dist/memory/vector/base.js +0 -83
- package/dist/memory/vector/base.js.map +0 -1
- package/dist/memory/vector/index.d.ts +0 -8
- package/dist/memory/vector/index.d.ts.map +0 -1
- package/dist/memory/vector/index.js +0 -7
- package/dist/memory/vector/index.js.map +0 -1
- package/dist/memory/vector/inmemory.d.ts +0 -47
- package/dist/memory/vector/inmemory.d.ts.map +0 -1
- package/dist/memory/vector/inmemory.js +0 -234
- package/dist/memory/vector/inmemory.js.map +0 -1
|
@@ -1,107 +1,22 @@
|
|
|
1
1
|
import { marked } from "marked";
|
|
2
2
|
import { ComponentBase } from "../tui.js";
|
|
3
3
|
import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.paddingY = paddingY;
|
|
4
|
+
class InlineStyleEngine {
|
|
5
|
+
theme;
|
|
6
|
+
defaultTextStyle;
|
|
7
|
+
stylePrefixCache;
|
|
8
|
+
constructor(theme, defaultTextStyle) {
|
|
10
9
|
this.theme = theme;
|
|
11
10
|
this.defaultTextStyle = defaultTextStyle;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
this.text = text;
|
|
15
|
-
this.invalidate();
|
|
16
|
-
}
|
|
17
|
-
invalidate() {
|
|
18
|
-
super.invalidate();
|
|
19
|
-
this.cachedText = undefined;
|
|
20
|
-
this.cachedWidth = undefined;
|
|
21
|
-
this.cachedLines = undefined;
|
|
22
|
-
}
|
|
23
|
-
render(width) {
|
|
24
|
-
if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
|
|
25
|
-
return this.cachedLines;
|
|
26
|
-
}
|
|
27
|
-
return this.renderCached(width, () => {
|
|
28
|
-
// Calculate available width for content (subtract horizontal padding)
|
|
29
|
-
const contentWidth = Math.max(1, width - this.paddingX * 2);
|
|
30
|
-
// Don't render anything if there's no actual text
|
|
31
|
-
if (!this.text || this.text.trim() === "") {
|
|
32
|
-
const result = [];
|
|
33
|
-
// Update cache
|
|
34
|
-
this.cachedText = this.text;
|
|
35
|
-
this.cachedWidth = width;
|
|
36
|
-
this.cachedLines = result;
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
// Replace tabs with 3 spaces for consistent rendering
|
|
40
|
-
const normalizedText = this.text.replace(/\t/g, " ");
|
|
41
|
-
// Parse markdown to HTML-like tokens
|
|
42
|
-
const tokens = marked.lexer(normalizedText);
|
|
43
|
-
// Convert tokens to styled terminal output
|
|
44
|
-
const renderedLines = [];
|
|
45
|
-
for (let i = 0; i < tokens.length; i++) {
|
|
46
|
-
const token = tokens[i];
|
|
47
|
-
const nextToken = tokens[i + 1];
|
|
48
|
-
const tokenLines = this.renderToken(token, contentWidth, nextToken?.type);
|
|
49
|
-
renderedLines.push(...tokenLines);
|
|
50
|
-
}
|
|
51
|
-
// Wrap lines (NO padding, NO background yet)
|
|
52
|
-
const wrappedLines = [];
|
|
53
|
-
for (const line of renderedLines) {
|
|
54
|
-
wrappedLines.push(...wrapTextWithAnsi(line, contentWidth));
|
|
55
|
-
}
|
|
56
|
-
// Add margins and background to each wrapped line
|
|
57
|
-
const leftMargin = " ".repeat(this.paddingX);
|
|
58
|
-
const rightMargin = " ".repeat(this.paddingX);
|
|
59
|
-
const bgFn = this.defaultTextStyle?.bgColor;
|
|
60
|
-
const contentLines = [];
|
|
61
|
-
for (const line of wrappedLines) {
|
|
62
|
-
const lineWithMargins = leftMargin + line + rightMargin;
|
|
63
|
-
if (bgFn) {
|
|
64
|
-
contentLines.push(applyBackgroundToLine(lineWithMargins, width, bgFn));
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
// No background - just pad to width
|
|
68
|
-
const visibleLen = visibleWidth(lineWithMargins);
|
|
69
|
-
const paddingNeeded = Math.max(0, width - visibleLen);
|
|
70
|
-
contentLines.push(lineWithMargins + " ".repeat(paddingNeeded));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Add top/bottom padding (empty lines)
|
|
74
|
-
const emptyLine = " ".repeat(width);
|
|
75
|
-
const emptyLines = [];
|
|
76
|
-
for (let i = 0; i < this.paddingY; i++) {
|
|
77
|
-
const line = bgFn ? applyBackgroundToLine(emptyLine, width, bgFn) : emptyLine;
|
|
78
|
-
emptyLines.push(line);
|
|
79
|
-
}
|
|
80
|
-
// Combine top padding, content, and bottom padding
|
|
81
|
-
const result = [...emptyLines, ...contentLines, ...emptyLines];
|
|
82
|
-
// Update cache
|
|
83
|
-
this.cachedText = this.text;
|
|
84
|
-
this.cachedWidth = width;
|
|
85
|
-
this.cachedLines = result;
|
|
86
|
-
return result.length > 0 ? result : [""];
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Apply default text style to a string.
|
|
91
|
-
* This is the base styling applied to all text content.
|
|
92
|
-
* NOTE: Background color is NOT applied here - it's applied at the padding stage
|
|
93
|
-
* to ensure it extends to the full line width.
|
|
94
|
-
*/
|
|
95
|
-
applyDefaultStyle(text) {
|
|
12
|
+
applyDefault(text) {
|
|
96
13
|
if (!this.defaultTextStyle) {
|
|
97
14
|
return text;
|
|
98
15
|
}
|
|
99
16
|
let styled = text;
|
|
100
|
-
// Apply foreground color (NOT background - that's applied at padding stage)
|
|
101
17
|
if (this.defaultTextStyle.color) {
|
|
102
18
|
styled = this.defaultTextStyle.color(styled);
|
|
103
19
|
}
|
|
104
|
-
// Apply text decorations using this.theme
|
|
105
20
|
if (this.defaultTextStyle.bold) {
|
|
106
21
|
styled = this.theme.bold(styled);
|
|
107
22
|
}
|
|
@@ -116,12 +31,12 @@ export class Markdown extends ComponentBase {
|
|
|
116
31
|
}
|
|
117
32
|
return styled;
|
|
118
33
|
}
|
|
119
|
-
|
|
34
|
+
getStylePrefix() {
|
|
120
35
|
if (!this.defaultTextStyle) {
|
|
121
36
|
return "";
|
|
122
37
|
}
|
|
123
|
-
if (this.
|
|
124
|
-
return this.
|
|
38
|
+
if (this.stylePrefixCache !== undefined) {
|
|
39
|
+
return this.stylePrefixCache;
|
|
125
40
|
}
|
|
126
41
|
const sentinel = "\u0000";
|
|
127
42
|
let styled = sentinel;
|
|
@@ -141,16 +56,224 @@ export class Markdown extends ComponentBase {
|
|
|
141
56
|
styled = this.theme.underline(styled);
|
|
142
57
|
}
|
|
143
58
|
const sentinelIndex = styled.indexOf(sentinel);
|
|
144
|
-
this.
|
|
145
|
-
return this.
|
|
59
|
+
this.stylePrefixCache = sentinelIndex >= 0 ? styled.slice(0, sentinelIndex) : "";
|
|
60
|
+
return this.stylePrefixCache;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class MarkdownListRenderer {
|
|
64
|
+
theme;
|
|
65
|
+
renderInlineTokenList;
|
|
66
|
+
constructor(theme, renderInlineTokenList) {
|
|
67
|
+
this.theme = theme;
|
|
68
|
+
this.renderInlineTokenList = renderInlineTokenList;
|
|
69
|
+
}
|
|
70
|
+
render(token, depth) {
|
|
71
|
+
const lines = [];
|
|
72
|
+
const indent = " ".repeat(depth);
|
|
73
|
+
const startNumber = token.start ?? 1;
|
|
74
|
+
for (let i = 0; i < token.items.length; i++) {
|
|
75
|
+
const item = token.items[i];
|
|
76
|
+
const bullet = token.ordered ? `${startNumber + i}. ` : "- ";
|
|
77
|
+
const itemLines = this.renderListItemTokens(item.tokens || [], depth);
|
|
78
|
+
if (itemLines.length > 0) {
|
|
79
|
+
const firstLine = itemLines[0];
|
|
80
|
+
const isNestedList = /^\s+\x1b\[36m[-\d]/.test(firstLine);
|
|
81
|
+
if (isNestedList) {
|
|
82
|
+
lines.push(firstLine);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
lines.push(indent + this.theme.listBullet(bullet) + firstLine);
|
|
86
|
+
}
|
|
87
|
+
for (let j = 1; j < itemLines.length; j++) {
|
|
88
|
+
const line = itemLines[j];
|
|
89
|
+
const isNestedListLine = /^\s+\x1b\[36m[-\d]/.test(line);
|
|
90
|
+
if (isNestedListLine) {
|
|
91
|
+
lines.push(line);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
lines.push(`${indent} ${line}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
lines.push(indent + this.theme.listBullet(bullet));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return lines;
|
|
103
|
+
}
|
|
104
|
+
renderListItemTokens(tokens, parentDepth) {
|
|
105
|
+
const lines = [];
|
|
106
|
+
for (const token of tokens) {
|
|
107
|
+
if (token.type === "list") {
|
|
108
|
+
const nestedLines = this.render(token, parentDepth + 1);
|
|
109
|
+
lines.push(...nestedLines);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (token.type === "text") {
|
|
113
|
+
const text = token.tokens && token.tokens.length > 0
|
|
114
|
+
? this.renderInlineTokenList(token.tokens)
|
|
115
|
+
: (token.text ?? "");
|
|
116
|
+
lines.push(text);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (token.type === "paragraph") {
|
|
120
|
+
lines.push(this.renderInlineTokenList(token.tokens || []));
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (token.type === "code") {
|
|
124
|
+
const codeIndent = this.theme.codeBlockIndent ?? " ";
|
|
125
|
+
lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
|
|
126
|
+
if (this.theme.highlightCode) {
|
|
127
|
+
const highlightedLines = this.theme.highlightCode(token.text, token.lang);
|
|
128
|
+
for (const highlightedLine of highlightedLines) {
|
|
129
|
+
lines.push(`${codeIndent}${highlightedLine}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
for (const rawLine of token.text.split("\n")) {
|
|
134
|
+
lines.push(`${codeIndent}${this.theme.codeBlock(rawLine)}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
lines.push(this.theme.codeBlockBorder("```"));
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const fallbackText = this.renderInlineTokenList([token]);
|
|
141
|
+
if (fallbackText) {
|
|
142
|
+
lines.push(fallbackText);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return lines;
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
}
|
|
148
|
+
class MarkdownTableRenderer {
|
|
149
|
+
theme;
|
|
150
|
+
renderInlineTokenList;
|
|
151
|
+
constructor(theme, renderInlineTokenList) {
|
|
152
|
+
this.theme = theme;
|
|
153
|
+
this.renderInlineTokenList = renderInlineTokenList;
|
|
154
|
+
}
|
|
155
|
+
wrapCellText(text, maxWidth) {
|
|
156
|
+
return wrapTextWithAnsi(text, Math.max(1, maxWidth));
|
|
157
|
+
}
|
|
158
|
+
render(token, availableWidth) {
|
|
159
|
+
const lines = [];
|
|
160
|
+
const columnCount = token.header.length;
|
|
161
|
+
if (columnCount === 0) {
|
|
162
|
+
return lines;
|
|
163
|
+
}
|
|
164
|
+
const borderOverhead = 3 * columnCount + 1;
|
|
165
|
+
const minTableWidth = borderOverhead + columnCount;
|
|
166
|
+
if (availableWidth < minTableWidth) {
|
|
167
|
+
const fallbackLines = token.raw ? wrapTextWithAnsi(token.raw, availableWidth) : [];
|
|
168
|
+
fallbackLines.push("");
|
|
169
|
+
return fallbackLines;
|
|
170
|
+
}
|
|
171
|
+
const naturalWidths = [];
|
|
172
|
+
for (let i = 0; i < columnCount; i++) {
|
|
173
|
+
const headerText = this.renderInlineTokenList(token.header[i].tokens || []);
|
|
174
|
+
naturalWidths[i] = visibleWidth(headerText);
|
|
175
|
+
}
|
|
176
|
+
for (const row of token.rows) {
|
|
177
|
+
for (let i = 0; i < row.length; i++) {
|
|
178
|
+
const cellText = this.renderInlineTokenList(row[i].tokens || []);
|
|
179
|
+
naturalWidths[i] = Math.max(naturalWidths[i] || 0, visibleWidth(cellText));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const totalNaturalWidth = naturalWidths.reduce((a, b) => a + b, 0) + borderOverhead;
|
|
183
|
+
let columnWidths;
|
|
184
|
+
if (totalNaturalWidth <= availableWidth) {
|
|
185
|
+
columnWidths = naturalWidths;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const availableForCells = availableWidth - borderOverhead;
|
|
189
|
+
if (availableForCells <= columnCount) {
|
|
190
|
+
columnWidths = naturalWidths.map(() => Math.max(1, Math.floor(availableForCells / columnCount)));
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const totalNatural = naturalWidths.reduce((a, b) => a + b, 0);
|
|
194
|
+
columnWidths = naturalWidths.map((width) => {
|
|
195
|
+
const proportion = width / totalNatural;
|
|
196
|
+
return Math.max(1, Math.floor(proportion * availableForCells));
|
|
197
|
+
});
|
|
198
|
+
const allocated = columnWidths.reduce((a, b) => a + b, 0);
|
|
199
|
+
let remaining = availableForCells - allocated;
|
|
200
|
+
for (let i = 0; remaining > 0 && i < columnCount; i++) {
|
|
201
|
+
columnWidths[i]++;
|
|
202
|
+
remaining--;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const topBorderCells = columnWidths.map((w) => "─".repeat(w));
|
|
207
|
+
lines.push(`┌─${topBorderCells.join("─┬─")}─┐`);
|
|
208
|
+
const headerCellLines = token.header.map((cell, i) => {
|
|
209
|
+
const text = this.renderInlineTokenList(cell.tokens || []);
|
|
210
|
+
return this.wrapCellText(text, columnWidths[i]);
|
|
211
|
+
});
|
|
212
|
+
const headerLineCount = Math.max(...headerCellLines.map((cellLines) => cellLines.length));
|
|
213
|
+
for (let lineIndex = 0; lineIndex < headerLineCount; lineIndex++) {
|
|
214
|
+
const rowParts = headerCellLines.map((cellLines, columnIndex) => {
|
|
215
|
+
const text = cellLines[lineIndex] || "";
|
|
216
|
+
const padded = text + " ".repeat(Math.max(0, columnWidths[columnIndex] - visibleWidth(text)));
|
|
217
|
+
return this.theme.bold(padded);
|
|
218
|
+
});
|
|
219
|
+
lines.push(`│ ${rowParts.join(" │ ")} │`);
|
|
220
|
+
}
|
|
221
|
+
const separatorCells = columnWidths.map((w) => "─".repeat(w));
|
|
222
|
+
lines.push(`├─${separatorCells.join("─┼─")}─┤`);
|
|
223
|
+
for (const row of token.rows) {
|
|
224
|
+
const rowCellLines = row.map((cell, i) => {
|
|
225
|
+
const text = this.renderInlineTokenList(cell.tokens || []);
|
|
226
|
+
return this.wrapCellText(text, columnWidths[i]);
|
|
227
|
+
});
|
|
228
|
+
const rowLineCount = Math.max(...rowCellLines.map((cellLines) => cellLines.length));
|
|
229
|
+
for (let lineIndex = 0; lineIndex < rowLineCount; lineIndex++) {
|
|
230
|
+
const rowParts = rowCellLines.map((cellLines, columnIndex) => {
|
|
231
|
+
const text = cellLines[lineIndex] || "";
|
|
232
|
+
return text + " ".repeat(Math.max(0, columnWidths[columnIndex] - visibleWidth(text)));
|
|
233
|
+
});
|
|
234
|
+
lines.push(`│ ${rowParts.join(" │ ")} │`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const bottomBorderCells = columnWidths.map((w) => "─".repeat(w));
|
|
238
|
+
lines.push(`└─${bottomBorderCells.join("─┴─")}─┘`);
|
|
239
|
+
lines.push("");
|
|
240
|
+
return lines;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
class MarkdownRenderEngine {
|
|
244
|
+
theme;
|
|
245
|
+
defaultTextStyle;
|
|
246
|
+
paddingX;
|
|
247
|
+
paddingY;
|
|
248
|
+
inlineStyleEngine;
|
|
249
|
+
listRenderer;
|
|
250
|
+
tableRenderer;
|
|
251
|
+
constructor(theme, defaultTextStyle, paddingX, paddingY) {
|
|
252
|
+
this.theme = theme;
|
|
253
|
+
this.defaultTextStyle = defaultTextStyle;
|
|
254
|
+
this.paddingX = paddingX;
|
|
255
|
+
this.paddingY = paddingY;
|
|
256
|
+
this.inlineStyleEngine = new InlineStyleEngine(theme, defaultTextStyle);
|
|
257
|
+
this.listRenderer = new MarkdownListRenderer(theme, (tokens) => this.renderInlineTokenList(tokens));
|
|
258
|
+
this.tableRenderer = new MarkdownTableRenderer(theme, (tokens) => this.renderInlineTokenList(tokens));
|
|
259
|
+
}
|
|
260
|
+
renderTokens(tokens, contentWidth) {
|
|
261
|
+
const blockLines = [];
|
|
262
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
263
|
+
const token = tokens[i];
|
|
264
|
+
const nextTokenType = tokens[i + 1]?.type;
|
|
265
|
+
const tokenLines = this.renderBlockToken(token, contentWidth, nextTokenType);
|
|
266
|
+
blockLines.push(...tokenLines);
|
|
267
|
+
}
|
|
268
|
+
return blockLines;
|
|
269
|
+
}
|
|
270
|
+
renderBlockToken(token, width, nextTokenType) {
|
|
148
271
|
const lines = [];
|
|
149
272
|
switch (token.type) {
|
|
150
273
|
case "heading": {
|
|
151
274
|
const headingLevel = token.depth;
|
|
152
275
|
const headingPrefix = `${"#".repeat(headingLevel)} `;
|
|
153
|
-
const headingText = this.
|
|
276
|
+
const headingText = this.renderInlineTokenList(token.tokens || []);
|
|
154
277
|
let styledHeading;
|
|
155
278
|
if (headingLevel === 1) {
|
|
156
279
|
styledHeading = this.theme.heading(this.theme.bold(this.theme.underline(headingText)));
|
|
@@ -163,133 +286,116 @@ export class Markdown extends ComponentBase {
|
|
|
163
286
|
}
|
|
164
287
|
lines.push(styledHeading);
|
|
165
288
|
if (nextTokenType !== "space") {
|
|
166
|
-
lines.push("");
|
|
289
|
+
lines.push("");
|
|
167
290
|
}
|
|
168
291
|
break;
|
|
169
292
|
}
|
|
170
293
|
case "paragraph": {
|
|
171
|
-
|
|
172
|
-
lines.push(paragraphText);
|
|
173
|
-
// Don't add spacing if next token is space or list
|
|
294
|
+
lines.push(this.renderInlineTokenList(token.tokens || []));
|
|
174
295
|
if (nextTokenType && nextTokenType !== "list" && nextTokenType !== "space") {
|
|
175
296
|
lines.push("");
|
|
176
297
|
}
|
|
177
298
|
break;
|
|
178
299
|
}
|
|
179
300
|
case "code": {
|
|
180
|
-
const
|
|
301
|
+
const codeIndent = this.theme.codeBlockIndent ?? " ";
|
|
181
302
|
lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
|
|
182
303
|
if (this.theme.highlightCode) {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
lines.push(`${indent}${hlLine}`);
|
|
304
|
+
for (const highlightedLine of this.theme.highlightCode(token.text, token.lang)) {
|
|
305
|
+
lines.push(`${codeIndent}${highlightedLine}`);
|
|
186
306
|
}
|
|
187
307
|
}
|
|
188
308
|
else {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
for (const codeLine of codeLines) {
|
|
192
|
-
lines.push(`${indent}${this.theme.codeBlock(codeLine)}`);
|
|
309
|
+
for (const rawLine of token.text.split("\n")) {
|
|
310
|
+
lines.push(`${codeIndent}${this.theme.codeBlock(rawLine)}`);
|
|
193
311
|
}
|
|
194
312
|
}
|
|
195
313
|
lines.push(this.theme.codeBlockBorder("```"));
|
|
196
314
|
if (nextTokenType !== "space") {
|
|
197
|
-
lines.push("");
|
|
315
|
+
lines.push("");
|
|
198
316
|
}
|
|
199
317
|
break;
|
|
200
318
|
}
|
|
201
319
|
case "list": {
|
|
202
|
-
|
|
203
|
-
lines.push(...listLines);
|
|
204
|
-
// Don't add spacing after lists if a space token follows
|
|
205
|
-
// (the space token will handle it)
|
|
320
|
+
lines.push(...this.listRenderer.render(token, 0));
|
|
206
321
|
break;
|
|
207
322
|
}
|
|
208
323
|
case "table": {
|
|
209
|
-
|
|
210
|
-
lines.push(...tableLines);
|
|
324
|
+
lines.push(...this.tableRenderer.render(token, width));
|
|
211
325
|
break;
|
|
212
326
|
}
|
|
213
327
|
case "blockquote": {
|
|
214
|
-
const quoteText = this.
|
|
215
|
-
const
|
|
216
|
-
for (const quoteLine of quoteLines) {
|
|
328
|
+
const quoteText = this.renderInlineTokenList(token.tokens || []);
|
|
329
|
+
for (const quoteLine of quoteText.split("\n")) {
|
|
217
330
|
lines.push(this.theme.quoteBorder("│ ") + this.theme.quote(this.theme.italic(quoteLine)));
|
|
218
331
|
}
|
|
219
332
|
if (nextTokenType !== "space") {
|
|
220
|
-
lines.push("");
|
|
333
|
+
lines.push("");
|
|
221
334
|
}
|
|
222
335
|
break;
|
|
223
336
|
}
|
|
224
|
-
case "hr":
|
|
337
|
+
case "hr": {
|
|
225
338
|
lines.push(this.theme.hr("─".repeat(Math.min(width, 80))));
|
|
226
339
|
if (nextTokenType !== "space") {
|
|
227
|
-
lines.push("");
|
|
340
|
+
lines.push("");
|
|
228
341
|
}
|
|
229
342
|
break;
|
|
230
|
-
|
|
231
|
-
|
|
343
|
+
}
|
|
344
|
+
case "html": {
|
|
232
345
|
if ("raw" in token && typeof token.raw === "string") {
|
|
233
|
-
lines.push(this.
|
|
346
|
+
lines.push(this.inlineStyleEngine.applyDefault(token.raw.trim()));
|
|
234
347
|
}
|
|
235
348
|
break;
|
|
236
|
-
|
|
237
|
-
|
|
349
|
+
}
|
|
350
|
+
case "space": {
|
|
238
351
|
lines.push("");
|
|
239
352
|
break;
|
|
240
|
-
|
|
241
|
-
|
|
353
|
+
}
|
|
354
|
+
default: {
|
|
242
355
|
if ("text" in token && typeof token.text === "string") {
|
|
243
356
|
lines.push(token.text);
|
|
244
357
|
}
|
|
358
|
+
}
|
|
245
359
|
}
|
|
246
360
|
return lines;
|
|
247
361
|
}
|
|
248
|
-
|
|
362
|
+
renderInlineTokenList(tokens) {
|
|
249
363
|
let result = "";
|
|
250
364
|
for (const token of tokens) {
|
|
251
365
|
switch (token.type) {
|
|
252
366
|
case "text":
|
|
253
|
-
// Text tokens in list items can have nested tokens for inline formatting
|
|
254
367
|
if (token.tokens && token.tokens.length > 0) {
|
|
255
|
-
result += this.
|
|
368
|
+
result += this.renderInlineTokenList(token.tokens);
|
|
256
369
|
}
|
|
257
370
|
else {
|
|
258
|
-
|
|
259
|
-
result += this.applyDefaultStyle(token.text);
|
|
371
|
+
result += this.inlineStyleEngine.applyDefault(token.text);
|
|
260
372
|
}
|
|
261
373
|
break;
|
|
262
374
|
case "strong": {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
result += this.theme.bold(boldContent) + this.getDefaultStylePrefix();
|
|
375
|
+
const strongContent = this.renderInlineTokenList(token.tokens || []);
|
|
376
|
+
result += this.theme.bold(strongContent) + this.inlineStyleEngine.getStylePrefix();
|
|
266
377
|
break;
|
|
267
378
|
}
|
|
268
379
|
case "em": {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
result += this.theme.italic(italicContent) + this.getDefaultStylePrefix();
|
|
380
|
+
const emphasizedContent = this.renderInlineTokenList(token.tokens || []);
|
|
381
|
+
result += this.theme.italic(emphasizedContent) + this.inlineStyleEngine.getStylePrefix();
|
|
272
382
|
break;
|
|
273
383
|
}
|
|
274
384
|
case "codespan":
|
|
275
|
-
|
|
276
|
-
result += this.theme.code(token.text) + this.getDefaultStylePrefix();
|
|
385
|
+
result += this.theme.code(token.text) + this.inlineStyleEngine.getStylePrefix();
|
|
277
386
|
break;
|
|
278
387
|
case "link": {
|
|
279
|
-
const linkText = this.
|
|
280
|
-
// If link text matches href, only show the link once
|
|
281
|
-
// Compare raw text (token.text) not styled text (linkText) since linkText has ANSI codes
|
|
282
|
-
// For mailto: links, strip the prefix before comparing (autolinked emails have
|
|
283
|
-
// text="foo@bar.com" but href="mailto:foo@bar.com")
|
|
388
|
+
const linkText = this.renderInlineTokenList(token.tokens || []);
|
|
284
389
|
const hrefForComparison = token.href.startsWith("mailto:") ? token.href.slice(7) : token.href;
|
|
285
390
|
if (token.text === token.href || token.text === hrefForComparison) {
|
|
286
|
-
result +=
|
|
391
|
+
result +=
|
|
392
|
+
this.theme.link(this.theme.underline(linkText)) + this.inlineStyleEngine.getStylePrefix();
|
|
287
393
|
}
|
|
288
394
|
else {
|
|
289
395
|
result +=
|
|
290
396
|
this.theme.link(this.theme.underline(linkText)) +
|
|
291
397
|
this.theme.linkUrl(` (${token.href})`) +
|
|
292
|
-
this.
|
|
398
|
+
this.inlineStyleEngine.getStylePrefix();
|
|
293
399
|
}
|
|
294
400
|
break;
|
|
295
401
|
}
|
|
@@ -297,234 +403,109 @@ export class Markdown extends ComponentBase {
|
|
|
297
403
|
result += "\n";
|
|
298
404
|
break;
|
|
299
405
|
case "del": {
|
|
300
|
-
const
|
|
301
|
-
result += this.theme.strikethrough(
|
|
406
|
+
const deletedContent = this.renderInlineTokenList(token.tokens || []);
|
|
407
|
+
result += this.theme.strikethrough(deletedContent) + this.inlineStyleEngine.getStylePrefix();
|
|
302
408
|
break;
|
|
303
409
|
}
|
|
304
|
-
case "html":
|
|
305
|
-
// Render inline HTML as plain text
|
|
410
|
+
case "html": {
|
|
306
411
|
if ("raw" in token && typeof token.raw === "string") {
|
|
307
|
-
result += this.
|
|
412
|
+
result += this.inlineStyleEngine.applyDefault(token.raw);
|
|
308
413
|
}
|
|
309
414
|
break;
|
|
310
|
-
|
|
311
|
-
|
|
415
|
+
}
|
|
416
|
+
default: {
|
|
312
417
|
if ("text" in token && typeof token.text === "string") {
|
|
313
|
-
result += this.
|
|
418
|
+
result += this.inlineStyleEngine.applyDefault(token.text);
|
|
314
419
|
}
|
|
420
|
+
}
|
|
315
421
|
}
|
|
316
422
|
}
|
|
317
423
|
return result;
|
|
318
424
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const lines = [];
|
|
324
|
-
const indent = " ".repeat(depth);
|
|
325
|
-
// Use the list's start property (defaults to 1 for ordered lists)
|
|
326
|
-
const startNumber = token.start ?? 1;
|
|
327
|
-
for (let i = 0; i < token.items.length; i++) {
|
|
328
|
-
const item = token.items[i];
|
|
329
|
-
const bullet = token.ordered ? `${startNumber + i}. ` : "- ";
|
|
330
|
-
// Process item tokens to handle nested lists
|
|
331
|
-
const itemLines = this.renderListItem(item.tokens || [], depth);
|
|
332
|
-
if (itemLines.length > 0) {
|
|
333
|
-
// First line - check if it's a nested list
|
|
334
|
-
// A nested list will start with indent (spaces) followed by cyan bullet
|
|
335
|
-
const firstLine = itemLines[0];
|
|
336
|
-
const isNestedList = /^\s+\x1b\[36m[-\d]/.test(firstLine); // starts with spaces + cyan + bullet char
|
|
337
|
-
if (isNestedList) {
|
|
338
|
-
// This is a nested list, just add it as-is (already has full indent)
|
|
339
|
-
lines.push(firstLine);
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
// Regular text content - add indent and bullet
|
|
343
|
-
lines.push(indent + this.theme.listBullet(bullet) + firstLine);
|
|
344
|
-
}
|
|
345
|
-
// Rest of the lines
|
|
346
|
-
for (let j = 1; j < itemLines.length; j++) {
|
|
347
|
-
const line = itemLines[j];
|
|
348
|
-
const isNestedListLine = /^\s+\x1b\[36m[-\d]/.test(line); // starts with spaces + cyan + bullet char
|
|
349
|
-
if (isNestedListLine) {
|
|
350
|
-
// Nested list line - already has full indent
|
|
351
|
-
lines.push(line);
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
// Regular content - add parent indent + 2 spaces for continuation
|
|
355
|
-
lines.push(`${indent} ${line}`);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
lines.push(indent + this.theme.listBullet(bullet));
|
|
361
|
-
}
|
|
425
|
+
finalizeLines(blockLines, width) {
|
|
426
|
+
const flowWrappedLines = [];
|
|
427
|
+
for (const line of blockLines) {
|
|
428
|
+
flowWrappedLines.push(...wrapTextWithAnsi(line, Math.max(1, width - this.paddingX * 2)));
|
|
362
429
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
for (const token of tokens) {
|
|
372
|
-
if (token.type === "list") {
|
|
373
|
-
// Nested list - render with one additional indent level
|
|
374
|
-
// These lines will have their own indent, so we just add them as-is
|
|
375
|
-
const nestedLines = this.renderList(token, parentDepth + 1);
|
|
376
|
-
lines.push(...nestedLines);
|
|
377
|
-
}
|
|
378
|
-
else if (token.type === "text") {
|
|
379
|
-
// Text content (may have inline tokens)
|
|
380
|
-
const text = token.tokens && token.tokens.length > 0 ? this.renderInlineTokens(token.tokens) : token.text || "";
|
|
381
|
-
lines.push(text);
|
|
382
|
-
}
|
|
383
|
-
else if (token.type === "paragraph") {
|
|
384
|
-
// Paragraph in list item
|
|
385
|
-
const text = this.renderInlineTokens(token.tokens || []);
|
|
386
|
-
lines.push(text);
|
|
387
|
-
}
|
|
388
|
-
else if (token.type === "code") {
|
|
389
|
-
// Code block in list item
|
|
390
|
-
const indent = this.theme.codeBlockIndent ?? " ";
|
|
391
|
-
lines.push(this.theme.codeBlockBorder(`\`\`\`${token.lang || ""}`));
|
|
392
|
-
if (this.theme.highlightCode) {
|
|
393
|
-
const highlightedLines = this.theme.highlightCode(token.text, token.lang);
|
|
394
|
-
for (const hlLine of highlightedLines) {
|
|
395
|
-
lines.push(`${indent}${hlLine}`);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
else {
|
|
399
|
-
const codeLines = token.text.split("\n");
|
|
400
|
-
for (const codeLine of codeLines) {
|
|
401
|
-
lines.push(`${indent}${this.theme.codeBlock(codeLine)}`);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
lines.push(this.theme.codeBlockBorder("```"));
|
|
430
|
+
const leftMargin = " ".repeat(this.paddingX);
|
|
431
|
+
const rightMargin = " ".repeat(this.paddingX);
|
|
432
|
+
const backgroundFn = this.defaultTextStyle?.bgColor;
|
|
433
|
+
const composedLines = [];
|
|
434
|
+
for (const line of flowWrappedLines) {
|
|
435
|
+
const withMargins = leftMargin + line + rightMargin;
|
|
436
|
+
if (backgroundFn) {
|
|
437
|
+
composedLines.push(applyBackgroundToLine(withMargins, width, backgroundFn));
|
|
405
438
|
}
|
|
406
439
|
else {
|
|
407
|
-
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
lines.push(text);
|
|
411
|
-
}
|
|
440
|
+
const visibleLen = visibleWidth(withMargins);
|
|
441
|
+
const trailingPadding = Math.max(0, width - visibleLen);
|
|
442
|
+
composedLines.push(withMargins + " ".repeat(trailingPadding));
|
|
412
443
|
}
|
|
413
444
|
}
|
|
414
|
-
|
|
445
|
+
const blankLine = " ".repeat(width);
|
|
446
|
+
const verticalPaddingLines = [];
|
|
447
|
+
for (let i = 0; i < this.paddingY; i++) {
|
|
448
|
+
verticalPaddingLines.push(backgroundFn ? applyBackgroundToLine(blankLine, width, backgroundFn) : blankLine);
|
|
449
|
+
}
|
|
450
|
+
return [...verticalPaddingLines, ...composedLines, ...verticalPaddingLines];
|
|
415
451
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
452
|
+
}
|
|
453
|
+
export class Markdown extends ComponentBase {
|
|
454
|
+
text;
|
|
455
|
+
paddingX;
|
|
456
|
+
paddingY;
|
|
457
|
+
defaultTextStyle;
|
|
458
|
+
theme;
|
|
459
|
+
cachedText;
|
|
460
|
+
cachedWidth;
|
|
461
|
+
cachedLines;
|
|
462
|
+
constructor(text, paddingX, paddingY, theme, defaultTextStyle) {
|
|
463
|
+
super();
|
|
464
|
+
this.text = text;
|
|
465
|
+
this.paddingX = paddingX;
|
|
466
|
+
this.paddingY = paddingY;
|
|
467
|
+
this.theme = theme;
|
|
468
|
+
this.defaultTextStyle = defaultTextStyle;
|
|
424
469
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
// Minimum width for a bordered table with at least 1 char per column.
|
|
439
|
-
const minTableWidth = borderOverhead + numCols;
|
|
440
|
-
if (availableWidth < minTableWidth) {
|
|
441
|
-
// Too narrow to render a stable table. Fall back to raw markdown.
|
|
442
|
-
const fallbackLines = token.raw ? wrapTextWithAnsi(token.raw, availableWidth) : [];
|
|
443
|
-
fallbackLines.push("");
|
|
444
|
-
return fallbackLines;
|
|
445
|
-
}
|
|
446
|
-
// Calculate natural column widths (what each column needs without constraints)
|
|
447
|
-
const naturalWidths = [];
|
|
448
|
-
for (let i = 0; i < numCols; i++) {
|
|
449
|
-
const headerText = this.renderInlineTokens(token.header[i].tokens || []);
|
|
450
|
-
naturalWidths[i] = visibleWidth(headerText);
|
|
451
|
-
}
|
|
452
|
-
for (const row of token.rows) {
|
|
453
|
-
for (let i = 0; i < row.length; i++) {
|
|
454
|
-
const cellText = this.renderInlineTokens(row[i].tokens || []);
|
|
455
|
-
naturalWidths[i] = Math.max(naturalWidths[i] || 0, visibleWidth(cellText));
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
// Calculate column widths that fit within available width
|
|
459
|
-
const totalNaturalWidth = naturalWidths.reduce((a, b) => a + b, 0) + borderOverhead;
|
|
460
|
-
let columnWidths;
|
|
461
|
-
if (totalNaturalWidth <= availableWidth) {
|
|
462
|
-
// Everything fits naturally
|
|
463
|
-
columnWidths = naturalWidths;
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
// Need to shrink columns to fit
|
|
467
|
-
const availableForCells = availableWidth - borderOverhead;
|
|
468
|
-
if (availableForCells <= numCols) {
|
|
469
|
-
// Extremely narrow - give each column at least 1 char
|
|
470
|
-
columnWidths = naturalWidths.map(() => Math.max(1, Math.floor(availableForCells / numCols)));
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
// Distribute space proportionally based on natural widths
|
|
474
|
-
const totalNatural = naturalWidths.reduce((a, b) => a + b, 0);
|
|
475
|
-
columnWidths = naturalWidths.map((w) => {
|
|
476
|
-
const proportion = w / totalNatural;
|
|
477
|
-
return Math.max(1, Math.floor(proportion * availableForCells));
|
|
478
|
-
});
|
|
479
|
-
// Adjust for rounding errors - distribute remaining space
|
|
480
|
-
const allocated = columnWidths.reduce((a, b) => a + b, 0);
|
|
481
|
-
let remaining = availableForCells - allocated;
|
|
482
|
-
for (let i = 0; remaining > 0 && i < numCols; i++) {
|
|
483
|
-
columnWidths[i]++;
|
|
484
|
-
remaining--;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
470
|
+
setText(text) {
|
|
471
|
+
this.text = text;
|
|
472
|
+
this.invalidate();
|
|
473
|
+
}
|
|
474
|
+
invalidate() {
|
|
475
|
+
super.invalidate();
|
|
476
|
+
this.cachedText = undefined;
|
|
477
|
+
this.cachedWidth = undefined;
|
|
478
|
+
this.cachedLines = undefined;
|
|
479
|
+
}
|
|
480
|
+
readCache(width) {
|
|
481
|
+
if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
|
|
482
|
+
return this.cachedLines;
|
|
487
483
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const text = cellLines[lineIdx] || "";
|
|
500
|
-
const padded = text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
|
|
501
|
-
return this.theme.bold(padded);
|
|
502
|
-
});
|
|
503
|
-
lines.push(`│ ${rowParts.join(" │ ")} │`);
|
|
484
|
+
return undefined;
|
|
485
|
+
}
|
|
486
|
+
updateCache(width, lines) {
|
|
487
|
+
this.cachedText = this.text;
|
|
488
|
+
this.cachedWidth = width;
|
|
489
|
+
this.cachedLines = lines;
|
|
490
|
+
}
|
|
491
|
+
render(width) {
|
|
492
|
+
const cacheHit = this.readCache(width);
|
|
493
|
+
if (cacheHit) {
|
|
494
|
+
return cacheHit;
|
|
504
495
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
for (const row of token.rows) {
|
|
510
|
-
const rowCellLines = row.map((cell, i) => {
|
|
511
|
-
const text = this.renderInlineTokens(cell.tokens || []);
|
|
512
|
-
return this.wrapCellText(text, columnWidths[i]);
|
|
513
|
-
});
|
|
514
|
-
const rowLineCount = Math.max(...rowCellLines.map((c) => c.length));
|
|
515
|
-
for (let lineIdx = 0; lineIdx < rowLineCount; lineIdx++) {
|
|
516
|
-
const rowParts = rowCellLines.map((cellLines, colIdx) => {
|
|
517
|
-
const text = cellLines[lineIdx] || "";
|
|
518
|
-
return text + " ".repeat(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
|
|
519
|
-
});
|
|
520
|
-
lines.push(`│ ${rowParts.join(" │ ")} │`);
|
|
521
|
-
}
|
|
496
|
+
if (!this.text || this.text.trim() === "") {
|
|
497
|
+
const emptyResult = [];
|
|
498
|
+
this.updateCache(width, emptyResult);
|
|
499
|
+
return emptyResult;
|
|
522
500
|
}
|
|
523
|
-
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
501
|
+
const contentWidth = Math.max(1, width - this.paddingX * 2);
|
|
502
|
+
const normalizedText = this.text.replace(/\t/g, " ");
|
|
503
|
+
const tokens = marked.lexer(normalizedText);
|
|
504
|
+
const engine = new MarkdownRenderEngine(this.theme, this.defaultTextStyle, this.paddingX, this.paddingY);
|
|
505
|
+
const blockLines = engine.renderTokens(tokens, contentWidth);
|
|
506
|
+
const finalLines = engine.finalizeLines(blockLines, width);
|
|
507
|
+
this.updateCache(width, finalLines);
|
|
508
|
+
return finalLines.length > 0 ? finalLines : [""];
|
|
528
509
|
}
|
|
529
510
|
}
|
|
530
511
|
//# sourceMappingURL=markdown.js.map
|