@odysx/codemind 0.0.0-stage → 0.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/README.md +293 -2
- package/dist/commands/agents.d.ts +2 -0
- package/dist/commands/agents.d.ts.map +1 -0
- package/dist/commands/agents.js +91 -0
- package/dist/commands/agents.js.map +1 -0
- package/dist/commands/auth.d.ts +2 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +35 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/chat.d.ts +2 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +180 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/keys.d.ts +2 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +81 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/local.d.ts +2 -0
- package/dist/commands/local.d.ts.map +1 -0
- package/dist/commands/local.js +325 -0
- package/dist/commands/local.js.map +1 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +73 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/prompts.d.ts +2 -0
- package/dist/commands/prompts.d.ts.map +1 -0
- package/dist/commands/prompts.js +59 -0
- package/dist/commands/prompts.js.map +1 -0
- package/dist/commands/skills.d.ts +2 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +41 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/core/auth/index.d.ts +10 -0
- package/dist/core/auth/index.d.ts.map +1 -0
- package/dist/core/auth/index.js +82 -0
- package/dist/core/auth/index.js.map +1 -0
- package/dist/core/config/index.d.ts +47 -0
- package/dist/core/config/index.d.ts.map +1 -0
- package/dist/core/config/index.js +118 -0
- package/dist/core/config/index.js.map +1 -0
- package/dist/core/history.d.ts +14 -0
- package/dist/core/history.d.ts.map +1 -0
- package/dist/core/history.js +80 -0
- package/dist/core/history.js.map +1 -0
- package/dist/core/markdown-renderer.d.ts +47 -0
- package/dist/core/markdown-renderer.d.ts.map +1 -0
- package/dist/core/markdown-renderer.js +385 -0
- package/dist/core/markdown-renderer.js.map +1 -0
- package/dist/core/permissions/index.d.ts +31 -0
- package/dist/core/permissions/index.d.ts.map +1 -0
- package/dist/core/permissions/index.js +64 -0
- package/dist/core/permissions/index.js.map +1 -0
- package/dist/core/provider/external.d.ts +28 -0
- package/dist/core/provider/external.d.ts.map +1 -0
- package/dist/core/provider/external.js +248 -0
- package/dist/core/provider/external.js.map +1 -0
- package/dist/core/provider/index.d.ts +96 -0
- package/dist/core/provider/index.d.ts.map +1 -0
- package/dist/core/provider/index.js +423 -0
- package/dist/core/provider/index.js.map +1 -0
- package/dist/core/registry/index.d.ts +25 -0
- package/dist/core/registry/index.d.ts.map +1 -0
- package/dist/core/registry/index.js +216 -0
- package/dist/core/registry/index.js.map +1 -0
- package/dist/core/schema/types.d.ts +93 -0
- package/dist/core/schema/types.d.ts.map +1 -0
- package/dist/core/schema/types.js +12 -0
- package/dist/core/schema/types.js.map +1 -0
- package/dist/core/terminal.d.ts +40 -0
- package/dist/core/terminal.d.ts.map +1 -0
- package/dist/core/terminal.js +134 -0
- package/dist/core/terminal.js.map +1 -0
- package/dist/core/workspace/index.d.ts +35 -0
- package/dist/core/workspace/index.d.ts.map +1 -0
- package/dist/core/workspace/index.js +194 -0
- package/dist/core/workspace/index.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +393 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/app.d.ts +3 -0
- package/dist/ui/app.d.ts.map +1 -0
- package/dist/ui/app.js +554 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/commands/cases/catalog.d.ts +11 -0
- package/dist/ui/commands/cases/catalog.d.ts.map +1 -0
- package/dist/ui/commands/cases/catalog.js +62 -0
- package/dist/ui/commands/cases/catalog.js.map +1 -0
- package/dist/ui/commands/cases/misc.d.ts +35 -0
- package/dist/ui/commands/cases/misc.d.ts.map +1 -0
- package/dist/ui/commands/cases/misc.js +245 -0
- package/dist/ui/commands/cases/misc.js.map +1 -0
- package/dist/ui/commands/cases/tasks.d.ts +13 -0
- package/dist/ui/commands/cases/tasks.d.ts.map +1 -0
- package/dist/ui/commands/cases/tasks.js +91 -0
- package/dist/ui/commands/cases/tasks.js.map +1 -0
- package/dist/ui/commands/runCommand.d.ts +22 -0
- package/dist/ui/commands/runCommand.d.ts.map +1 -0
- package/dist/ui/commands/runCommand.js +136 -0
- package/dist/ui/commands/runCommand.js.map +1 -0
- package/dist/ui/components/AgentPicker.d.ts +11 -0
- package/dist/ui/components/AgentPicker.d.ts.map +1 -0
- package/dist/ui/components/AgentPicker.js +7 -0
- package/dist/ui/components/AgentPicker.js.map +1 -0
- package/dist/ui/components/AuthPicker.d.ts +14 -0
- package/dist/ui/components/AuthPicker.d.ts.map +1 -0
- package/dist/ui/components/AuthPicker.js +7 -0
- package/dist/ui/components/AuthPicker.js.map +1 -0
- package/dist/ui/components/Banner.d.ts +8 -0
- package/dist/ui/components/Banner.d.ts.map +1 -0
- package/dist/ui/components/Banner.js +24 -0
- package/dist/ui/components/Banner.js.map +1 -0
- package/dist/ui/components/CommandMenu.d.ts +17 -0
- package/dist/ui/components/CommandMenu.d.ts.map +1 -0
- package/dist/ui/components/CommandMenu.js +21 -0
- package/dist/ui/components/CommandMenu.js.map +1 -0
- package/dist/ui/components/ErrorBoundary.d.ts +24 -0
- package/dist/ui/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/ui/components/ErrorBoundary.js +51 -0
- package/dist/ui/components/ErrorBoundary.js.map +1 -0
- package/dist/ui/components/InputBar.d.ts +28 -0
- package/dist/ui/components/InputBar.d.ts.map +1 -0
- package/dist/ui/components/InputBar.js +108 -0
- package/dist/ui/components/InputBar.js.map +1 -0
- package/dist/ui/components/KeysPanel.d.ts +12 -0
- package/dist/ui/components/KeysPanel.d.ts.map +1 -0
- package/dist/ui/components/KeysPanel.js +25 -0
- package/dist/ui/components/KeysPanel.js.map +1 -0
- package/dist/ui/components/MessageView.d.ts +29 -0
- package/dist/ui/components/MessageView.d.ts.map +1 -0
- package/dist/ui/components/MessageView.js +107 -0
- package/dist/ui/components/MessageView.js.map +1 -0
- package/dist/ui/components/PermissionPrompt.d.ts +10 -0
- package/dist/ui/components/PermissionPrompt.d.ts.map +1 -0
- package/dist/ui/components/PermissionPrompt.js +4 -0
- package/dist/ui/components/PermissionPrompt.js.map +1 -0
- package/dist/ui/components/Pickers.d.ts +43 -0
- package/dist/ui/components/Pickers.d.ts.map +1 -0
- package/dist/ui/components/Pickers.js +33 -0
- package/dist/ui/components/Pickers.js.map +1 -0
- package/dist/ui/components/SearchOverlay.d.ts +21 -0
- package/dist/ui/components/SearchOverlay.d.ts.map +1 -0
- package/dist/ui/components/SearchOverlay.js +14 -0
- package/dist/ui/components/SearchOverlay.js.map +1 -0
- package/dist/ui/components/SessionPicker.d.ts +12 -0
- package/dist/ui/components/SessionPicker.d.ts.map +1 -0
- package/dist/ui/components/SessionPicker.js +8 -0
- package/dist/ui/components/SessionPicker.js.map +1 -0
- package/dist/ui/components/WorkingIndicator.d.ts +10 -0
- package/dist/ui/components/WorkingIndicator.d.ts.map +1 -0
- package/dist/ui/components/WorkingIndicator.js +23 -0
- package/dist/ui/components/WorkingIndicator.js.map +1 -0
- package/dist/ui/controls/ApiKeyEntry.d.ts +8 -0
- package/dist/ui/controls/ApiKeyEntry.d.ts.map +1 -0
- package/dist/ui/controls/ApiKeyEntry.js +5 -0
- package/dist/ui/controls/ApiKeyEntry.js.map +1 -0
- package/dist/ui/controls/MultiSelect.d.ts +18 -0
- package/dist/ui/controls/MultiSelect.d.ts.map +1 -0
- package/dist/ui/controls/MultiSelect.js +9 -0
- package/dist/ui/controls/MultiSelect.js.map +1 -0
- package/dist/ui/hooks/useAgentPicker.d.ts +14 -0
- package/dist/ui/hooks/useAgentPicker.d.ts.map +1 -0
- package/dist/ui/hooks/useAgentPicker.js +53 -0
- package/dist/ui/hooks/useAgentPicker.js.map +1 -0
- package/dist/ui/hooks/useAuthFlow.d.ts +14 -0
- package/dist/ui/hooks/useAuthFlow.d.ts.map +1 -0
- package/dist/ui/hooks/useAuthFlow.js +31 -0
- package/dist/ui/hooks/useAuthFlow.js.map +1 -0
- package/dist/ui/hooks/useKeysFlow.d.ts +17 -0
- package/dist/ui/hooks/useKeysFlow.d.ts.map +1 -0
- package/dist/ui/hooks/useKeysFlow.js +130 -0
- package/dist/ui/hooks/useKeysFlow.js.map +1 -0
- package/dist/ui/hooks/useSessionPicker.d.ts +29 -0
- package/dist/ui/hooks/useSessionPicker.d.ts.map +1 -0
- package/dist/ui/hooks/useSessionPicker.js +58 -0
- package/dist/ui/hooks/useSessionPicker.js.map +1 -0
- package/dist/ui/hooks/useTerminalSize.d.ts +6 -0
- package/dist/ui/hooks/useTerminalSize.d.ts.map +1 -0
- package/dist/ui/hooks/useTerminalSize.js +29 -0
- package/dist/ui/hooks/useTerminalSize.js.map +1 -0
- package/dist/ui/input/keyRouter.d.ts +125 -0
- package/dist/ui/input/keyRouter.d.ts.map +1 -0
- package/dist/ui/input/keyRouter.js +574 -0
- package/dist/ui/input/keyRouter.js.map +1 -0
- package/dist/ui/layouts/ScreenLayout.d.ts +98 -0
- package/dist/ui/layouts/ScreenLayout.d.ts.map +1 -0
- package/dist/ui/layouts/ScreenLayout.js +56 -0
- package/dist/ui/layouts/ScreenLayout.js.map +1 -0
- package/dist/ui/shared/types.d.ts +143 -0
- package/dist/ui/shared/types.d.ts.map +1 -0
- package/dist/ui/shared/types.js +38 -0
- package/dist/ui/shared/types.js.map +1 -0
- package/dist/ui/theme.d.ts +29 -0
- package/dist/ui/theme.d.ts.map +1 -0
- package/dist/ui/theme.js +54 -0
- package/dist/ui/theme.js.map +1 -0
- package/dist/ui/utils/markdown.d.ts +74 -0
- package/dist/ui/utils/markdown.d.ts.map +1 -0
- package/dist/ui/utils/markdown.js +187 -0
- package/dist/ui/utils/markdown.js.map +1 -0
- package/dist/ui/utils/mentions.d.ts +12 -0
- package/dist/ui/utils/mentions.d.ts.map +1 -0
- package/dist/ui/utils/mentions.js +28 -0
- package/dist/ui/utils/mentions.js.map +1 -0
- package/dist/ui/utils/terminal-text.d.ts +33 -0
- package/dist/ui/utils/terminal-text.d.ts.map +1 -0
- package/dist/ui/utils/terminal-text.js +123 -0
- package/dist/ui/utils/terminal-text.js.map +1 -0
- package/dist/ui/utils/text.d.ts +72 -0
- package/dist/ui/utils/text.d.ts.map +1 -0
- package/dist/ui/utils/text.js +171 -0
- package/dist/ui/utils/text.js.map +1 -0
- package/eslint.config.js +40 -0
- package/graphify-out/GRAPH_REPORT.md +140 -0
- package/graphify-out/cache/1236b1806943f8eb5c64fece9fb448149370f4a1b52b32f0977ad528d7911291.json +1 -0
- package/graphify-out/cache/15cbf641dcc0fd641c18da872214918203a1f64baa7ac8430e4702ef32d18b02.json +1 -0
- package/graphify-out/cache/1abc52745bb46f6cc5a528530e2bc1f368c26e348dff85cdde5cad6f275d7177.json +1 -0
- package/graphify-out/cache/1c7815c37c13177e98895e272285f6151a8d0807478fc843ec452634b3e9912d.json +1 -0
- package/graphify-out/cache/1ec38c39f044f329c78642b61d6394fb8e15d0014335f32947d1f5c7b88c02bc.json +1 -0
- package/graphify-out/cache/20c9b57ff76dbb9d57cbd00659b0a42d2b28dd2abacf1ef4143cc67a5b6fe7f4.json +1 -0
- package/graphify-out/cache/285e11876884eb619e779d540cd957b33e70f14c67ecc26c9b9755aa9cedd717.json +1 -0
- package/graphify-out/cache/2c0a9c49ab51f4e0f07543b4e941bf802b7db31fa607c4cee8e595575be68fe7.json +1 -0
- package/graphify-out/cache/3025e6c2756c79ccaadd51d611f25a8b6630a6a11ce1b4e6e261b3e033dc194f.json +1 -0
- package/graphify-out/cache/4801a686ddfa0a52824a4fc3d65443cbb0ab9f0b030af67d02fccb520c584a08.json +1 -0
- package/graphify-out/cache/4f8fd96f38aa7d0293b4fab60c4581c4f3e68f4533c664c9cd78d1c53bea1cba.json +1 -0
- package/graphify-out/cache/5928e562b0f5700184b810e2403f4aa685e2b93c3c584c10460562b514c40fdd.json +1 -0
- package/graphify-out/cache/66132486efb0a4cfaeea766448f1f15bb33635808714052e7e24e5b00fbc984f.json +1 -0
- package/graphify-out/cache/66ab27669e7ec685130063662af9f30018c267f7639b4af4b0504a98282c383a.json +1 -0
- package/graphify-out/cache/6ff6b3dd433b5ffe96e166263a203dd622397e419dc00bb676824988b7defeab.json +1 -0
- package/graphify-out/cache/7a00a49932177a6215e2590b1ddfd6f1d8494792f693068e9d427d16b165d370.json +1 -0
- package/graphify-out/cache/7b681bc5182f40f707f1c0b16b78af38efffa62a1df315d10878f4de888408ef.json +1 -0
- package/graphify-out/cache/81196d44e50ac0b276d826a531ed10c425a528b298e3fe18e8d5a3eec996e9d5.json +1 -0
- package/graphify-out/cache/8934e9b32dea6e66fdc34fa1681b287ff1335c389917e0fc6ee2fc573e23e87b.json +1 -0
- package/graphify-out/cache/975f6c99807f86b79c80ca40c783618e2080a927eaebe6ea3db37b869f048851.json +1 -0
- package/graphify-out/cache/9ab98f08626fd8190462595e38de828293ad184db8df5e1177b05a8fe290faa1.json +1 -0
- package/graphify-out/cache/9c434a6796d7932b6e87a908c155c09cb2b8d097fc55f141f0302b6600f94749.json +1 -0
- package/graphify-out/cache/ac5cf4c489dc417c1f6ea728d0b6ba12ac7087bc6c2e736697ff3024b4d4e534.json +1 -0
- package/graphify-out/cache/ae5083b5c1dca3e5c6af485e7f6eb8a08ff8b382cdecf92ab5e0902053442afe.json +1 -0
- package/graphify-out/cache/b274057fc2e0118cf2746d1d8060841122bb2a2b0305566fc3f32d3a51e08bcc.json +1 -0
- package/graphify-out/cache/b39beef31da682387f030c0d149f6cd5b3e66effbf936cc8430db15360759dda.json +1 -0
- package/graphify-out/cache/bf3c6a36bb72820bc11cbf4a5c49067d1f62013d4686c019a4dbd9951b1e980e.json +1 -0
- package/graphify-out/cache/c034e156028d1a58b89bce659726e9a4065ddc4d2b560d6bce7a206fdff8dad3.json +1 -0
- package/graphify-out/cache/c619b5bbe8d1f427fbd7816d1e9fcfaf90d7201b020ae6b578166aeb9cb20683.json +1 -0
- package/graphify-out/cache/c8db77a9da0b0f601acfa50a620f31155cdda0d0cc0f2285adcea19e77194ee6.json +1 -0
- package/graphify-out/cache/ca664791ec7741a2077d9e7c10384142d30e7a3b77b388df719c315da608d57d.json +1 -0
- package/graphify-out/cache/cba43a116186bd55c8a63368dea4eee4a8123b2bec0a42df6efb3254f89f9a7a.json +1 -0
- package/graphify-out/cache/cd51cbb3dad1cf34417b9761fe2eb184a9f57d23dc86e45630e63bfa2ecafddc.json +1 -0
- package/graphify-out/cache/d06738cde193b34a136b94104220c17e0212b814b3e4d7ff399105635cae1a03.json +1 -0
- package/graphify-out/cache/d093c19f0169c0398eeb1360895b1c16ecc50abc59f4be8eec3f6fd27c89a6e5.json +1 -0
- package/graphify-out/cache/da8f75c438531d232fe114d5cbf2374576ce842a5fb87c7e5a88b78fdb334e5e.json +1 -0
- package/graphify-out/cache/e35798fa04ddede548a6953bdea506bd7d0788dfed4e8a8ea6ae77b1b60ef5e0.json +1 -0
- package/graphify-out/cache/e5a38c254719000487098782125e15e2e982c07d66b99d359ed1781f30f9fc8c.json +1 -0
- package/graphify-out/cache/e6e4c4a5a7200ee0154585b5d6538f699b0a746dbded3164f8391f06ce7cb212.json +1 -0
- package/graphify-out/cache/ea8d0838df6309b673b031f616b253af957898ee7289d25a541fa6183b732e4e.json +1 -0
- package/graphify-out/cache/ebaee92b0e881efd7a08f3143e2c1803310396b4651d4f77532003c699cc6836.json +1 -0
- package/graphify-out/cache/edf8543318a9e60d56d04704078da6c37202ddd6fdfc83144fe2b94fe19b80ef.json +1 -0
- package/graphify-out/cache/efca19d3668035f11126fc9eccbeab290abfa94babf3f9a8706de81d17aba263.json +1 -0
- package/graphify-out/cache/f1480bb642025ebd6d99986cdd8a7d5726897ec038300e4b095c9c938435dfad.json +1 -0
- package/graphify-out/cache/f459f21277f03865f732affb175b1b092954dae5967f27b3cd1864466e3e24f4.json +1 -0
- package/graphify-out/cache/f899e37e864010b30f4c196e86082d7bd022a0df032005e0407883ebcec36514.json +1 -0
- package/graphify-out/cache/fb3cbe07fbcd97c536cff9c6bc343c35f22d49613f05c53ad30ef67a75c5d93e.json +1 -0
- package/graphify-out/cache/fd3dc682b1ca2f5ae03b50d6b0e045ae50f5701c0a21c5a388d77ef482939d3a.json +1 -0
- package/graphify-out/graph.html +257 -0
- package/graphify-out/graph.json +4396 -0
- package/package.json +45 -6
- package/scripts/e2e-external.mjs +65 -0
- package/scripts/live-agents.mjs +6 -0
- package/scripts/live-stream.mjs +51 -0
- package/src/commands/agents.ts +91 -0
- package/src/commands/auth.ts +39 -0
- package/src/commands/chat.ts +198 -0
- package/src/commands/keys.ts +83 -0
- package/src/commands/local.ts +302 -0
- package/src/commands/mcp.ts +74 -0
- package/src/commands/prompts.ts +58 -0
- package/src/commands/skills.ts +43 -0
- package/src/core/auth/index.ts +101 -0
- package/src/core/config/index.ts +152 -0
- package/src/core/history.ts +79 -0
- package/src/core/markdown-renderer.ts +420 -0
- package/src/core/permissions/index.ts +99 -0
- package/src/core/provider/external.ts +312 -0
- package/src/core/provider/index.ts +517 -0
- package/src/core/registry/index.ts +250 -0
- package/src/core/schema/types.ts +106 -0
- package/src/core/terminal.ts +124 -0
- package/src/core/workspace/index.ts +216 -0
- package/src/index.ts +401 -0
- package/src/ui/app.tsx +644 -0
- package/src/ui/commands/cases/catalog.ts +76 -0
- package/src/ui/commands/cases/misc.ts +293 -0
- package/src/ui/commands/cases/tasks.ts +115 -0
- package/src/ui/commands/runCommand.ts +178 -0
- package/src/ui/components/Banner.tsx +63 -0
- package/src/ui/components/CommandMenu.tsx +63 -0
- package/src/ui/components/ErrorBoundary.tsx +75 -0
- package/src/ui/components/InputBar.tsx +227 -0
- package/src/ui/components/KeysPanel.tsx +115 -0
- package/src/ui/components/MessageView.tsx +226 -0
- package/src/ui/components/Pickers.tsx +234 -0
- package/src/ui/components/SearchOverlay.tsx +65 -0
- package/src/ui/components/WorkingIndicator.tsx +35 -0
- package/src/ui/controls/ApiKeyEntry.tsx +29 -0
- package/src/ui/controls/MultiSelect.tsx +55 -0
- package/src/ui/hooks/useAgentPicker.ts +64 -0
- package/src/ui/hooks/useAuthFlow.ts +47 -0
- package/src/ui/hooks/useKeysFlow.ts +157 -0
- package/src/ui/hooks/useSessionPicker.ts +84 -0
- package/src/ui/hooks/useTerminalSize.ts +36 -0
- package/src/ui/input/keyRouter.ts +627 -0
- package/src/ui/layouts/ScreenLayout.tsx +202 -0
- package/src/ui/shared/types.ts +160 -0
- package/src/ui/theme.ts +53 -0
- package/src/ui/utils/markdown.ts +255 -0
- package/src/ui/utils/mentions.ts +40 -0
- package/src/ui/utils/terminal-text.ts +130 -0
- package/src/ui/utils/text.ts +174 -0
- package/test/commands.test.mjs +127 -0
- package/test/config.test.mjs +123 -0
- package/test/history.test.mjs +42 -0
- package/test/keyrouter.test.mjs +324 -0
- package/test/layout.test.mjs +271 -0
- package/test/markdown.test.mjs +92 -0
- package/test/mentions.test.mjs +51 -0
- package/test/permissions.test.mjs +130 -0
- package/test/provider.test.mjs +287 -0
- package/test/terminal-text.test.mjs +116 -0
- package/test/text.test.mjs +134 -0
- package/test/workspace.test.mjs +101 -0
- package/tsconfig.json +32 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { sanitize } from "./terminal-text.js";
|
|
2
|
+
const FENCE = /^\s*(```|~~~)\s*([\w+-]*)\s*$/;
|
|
3
|
+
const HEADING = /^\s{0,3}(#{1,6})\s+(.*)$/;
|
|
4
|
+
const BULLET = /^(\s*)([-*+]|\d{1,3}[.)])\s+(.*)$/;
|
|
5
|
+
const QUOTE = /^\s{0,3}>\s?(.*)$/;
|
|
6
|
+
const RULE = /^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/;
|
|
7
|
+
// GFM allows a single dash per column (`|:-:|` is a centered column), so the
|
|
8
|
+
// minimum is one, not two.
|
|
9
|
+
const TABLE_DIVIDER = /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)+\|?\s*$/;
|
|
10
|
+
/**
|
|
11
|
+
* Split inline markdown into styled runs. Unmatched delimiters stay literal,
|
|
12
|
+
* so a half-streamed `**bold` simply renders as text until it completes.
|
|
13
|
+
*/
|
|
14
|
+
export function parseInline(text) {
|
|
15
|
+
const runs = [];
|
|
16
|
+
let buffer = "";
|
|
17
|
+
const flush = () => {
|
|
18
|
+
if (buffer) {
|
|
19
|
+
runs.push({ text: buffer });
|
|
20
|
+
buffer = "";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
for (let i = 0; i < text.length; i++) {
|
|
24
|
+
const ch = text[i];
|
|
25
|
+
// `code` — highest precedence, no nested formatting inside.
|
|
26
|
+
if (ch === "`") {
|
|
27
|
+
const end = text.indexOf("`", i + 1);
|
|
28
|
+
if (end !== -1) {
|
|
29
|
+
flush();
|
|
30
|
+
runs.push({ text: text.slice(i + 1, end), code: true });
|
|
31
|
+
i = end;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// **bold** / __bold__
|
|
36
|
+
if ((ch === "*" || ch === "_") && text[i + 1] === ch) {
|
|
37
|
+
const marker = ch + ch;
|
|
38
|
+
const end = text.indexOf(marker, i + 2);
|
|
39
|
+
if (end !== -1 && end > i + 2) {
|
|
40
|
+
flush();
|
|
41
|
+
for (const inner of parseInline(text.slice(i + 2, end))) {
|
|
42
|
+
runs.push({ ...inner, bold: true });
|
|
43
|
+
}
|
|
44
|
+
i = end + 1;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// *italic* / _italic_ — a single marker, not part of a word for `_`.
|
|
49
|
+
if (ch === "*" || ch === "_") {
|
|
50
|
+
const prev = text[i - 1] ?? " ";
|
|
51
|
+
const next = text[i + 1] ?? " ";
|
|
52
|
+
const wordBoundary = ch === "*" || (!/\w/.test(prev) && !/\w/.test(next));
|
|
53
|
+
if (wordBoundary && next !== " ") {
|
|
54
|
+
const end = text.indexOf(ch, i + 1);
|
|
55
|
+
if (end !== -1 && end > i + 1) {
|
|
56
|
+
flush();
|
|
57
|
+
for (const inner of parseInline(text.slice(i + 1, end))) {
|
|
58
|
+
runs.push({ ...inner, italic: true });
|
|
59
|
+
}
|
|
60
|
+
i = end;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// ~~strike~~
|
|
66
|
+
if (ch === "~" && text[i + 1] === "~") {
|
|
67
|
+
const end = text.indexOf("~~", i + 2);
|
|
68
|
+
if (end !== -1 && end > i + 2) {
|
|
69
|
+
flush();
|
|
70
|
+
for (const inner of parseInline(text.slice(i + 2, end))) {
|
|
71
|
+
runs.push({ ...inner, strike: true });
|
|
72
|
+
}
|
|
73
|
+
i = end + 1;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// [label](url)
|
|
78
|
+
if (ch === "[") {
|
|
79
|
+
const close = text.indexOf("](", i + 1);
|
|
80
|
+
if (close !== -1) {
|
|
81
|
+
const urlEnd = text.indexOf(")", close + 2);
|
|
82
|
+
if (urlEnd !== -1) {
|
|
83
|
+
flush();
|
|
84
|
+
const label = text.slice(i + 1, close);
|
|
85
|
+
const url = text.slice(close + 2, urlEnd);
|
|
86
|
+
runs.push({ text: label || url, link: url, underline: true });
|
|
87
|
+
i = urlEnd;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
buffer += ch;
|
|
93
|
+
}
|
|
94
|
+
flush();
|
|
95
|
+
return runs;
|
|
96
|
+
}
|
|
97
|
+
/** Parse a full markdown string during streaming (an unclosed fence stays open). */
|
|
98
|
+
export function parseMarkdown(markdown) {
|
|
99
|
+
// Strip control sequences before parsing: model output is untrusted, and a
|
|
100
|
+
// raw `\x1b[2J` reaching Ink's output would clear or corrupt the screen.
|
|
101
|
+
return parseWithState(sanitize(markdown), { inCode: false, lang: "", codeLines: [] }).lines;
|
|
102
|
+
}
|
|
103
|
+
/** Internal: parse and expose residual fence state for incremental callers. */
|
|
104
|
+
export function parseWithState(markdown, initial) {
|
|
105
|
+
const out = [];
|
|
106
|
+
const state = { ...initial, codeLines: [...initial.codeLines] };
|
|
107
|
+
const lines = markdown.split("\n");
|
|
108
|
+
for (let i = 0; i < lines.length; i++) {
|
|
109
|
+
const line = lines[i];
|
|
110
|
+
const fence = line.match(FENCE);
|
|
111
|
+
if (state.inCode) {
|
|
112
|
+
if (fence) {
|
|
113
|
+
out.push({ kind: "code", lang: state.lang, lines: state.codeLines, open: false });
|
|
114
|
+
state.inCode = false;
|
|
115
|
+
state.lang = "";
|
|
116
|
+
state.codeLines = [];
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
state.codeLines.push(line);
|
|
120
|
+
}
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (fence) {
|
|
124
|
+
state.inCode = true;
|
|
125
|
+
state.lang = fence[2] ?? "";
|
|
126
|
+
state.codeLines = [];
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
// Table: a header row followed by a divider row.
|
|
130
|
+
if (line.includes("|") && i + 1 < lines.length && TABLE_DIVIDER.test(lines[i + 1])) {
|
|
131
|
+
const splitRow = (row) => row.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim());
|
|
132
|
+
const header = splitRow(line);
|
|
133
|
+
const divider = splitRow(lines[i + 1]);
|
|
134
|
+
const align = divider.map((cell) => cell.startsWith(":") && cell.endsWith(":") ? "center" : cell.endsWith(":") ? "right" : "left");
|
|
135
|
+
const rows = [];
|
|
136
|
+
i += 2;
|
|
137
|
+
while (i < lines.length && lines[i].includes("|") && lines[i].trim() !== "") {
|
|
138
|
+
rows.push(splitRow(lines[i]));
|
|
139
|
+
i++;
|
|
140
|
+
}
|
|
141
|
+
i--;
|
|
142
|
+
out.push({ kind: "table", header, rows, align });
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (!line.trim()) {
|
|
146
|
+
out.push({ kind: "blank" });
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const heading = line.match(HEADING);
|
|
150
|
+
if (heading) {
|
|
151
|
+
out.push({ kind: "heading", level: heading[1].length, runs: parseInline(heading[2]) });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (RULE.test(line)) {
|
|
155
|
+
out.push({ kind: "rule" });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const quote = line.match(QUOTE);
|
|
159
|
+
if (quote) {
|
|
160
|
+
out.push({ kind: "quote", runs: parseInline(quote[1]) });
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const bullet = line.match(BULLET);
|
|
164
|
+
if (bullet) {
|
|
165
|
+
const indent = bullet[1].replace(/\t/g, " ").length;
|
|
166
|
+
out.push({
|
|
167
|
+
kind: "bullet",
|
|
168
|
+
depth: Math.min(3, Math.floor(indent / 2)),
|
|
169
|
+
marker: /^\d/.test(bullet[2]) ? bullet[2] : "•",
|
|
170
|
+
runs: parseInline(bullet[3]),
|
|
171
|
+
});
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
out.push({ kind: "text", runs: parseInline(line) });
|
|
175
|
+
}
|
|
176
|
+
// A fence that hasn't closed yet is still rendered live while streaming.
|
|
177
|
+
// The final newline produces one empty trailing line — it is the line break
|
|
178
|
+
// after the last code row, not a blank row, so drop it.
|
|
179
|
+
if (state.inCode) {
|
|
180
|
+
const codeLines = state.codeLines;
|
|
181
|
+
if (codeLines.length > 0 && codeLines[codeLines.length - 1] === "")
|
|
182
|
+
codeLines.pop();
|
|
183
|
+
out.push({ kind: "code", lang: state.lang, lines: codeLines, open: true });
|
|
184
|
+
}
|
|
185
|
+
return { lines: out, state };
|
|
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,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;gBAC/C,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;aAC7B,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QAED,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,yEAAyE;IACzE,4EAA4E;IAC5E,wDAAwD;IACxD,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QAClC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE;YAAE,SAAS,CAAC,GAAG,EAAE,CAAC;QACpF,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file mention handling for submitted prompts.
|
|
3
|
+
* `@path/to/file` tokens are replaced with inline content blocks (capped at
|
|
4
|
+
* 20KB per file) so the agent sees the file contents as context.
|
|
5
|
+
*/
|
|
6
|
+
export interface MentionResult {
|
|
7
|
+
effective: string;
|
|
8
|
+
unreadable: string[];
|
|
9
|
+
}
|
|
10
|
+
/** Synchronous variant used by the REPL (node fs). */
|
|
11
|
+
export declare const expandMentions: (msg: string, readFileSync: (path: string, enc: "utf-8") => string, existsSync: (path: string) => boolean) => MentionResult;
|
|
12
|
+
//# sourceMappingURL=mentions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mentions.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/mentions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAID,sDAAsD;AACtD,eAAO,MAAM,cAAc,QACpB,MAAM,gBACG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,MAAM,cACxC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,KACpC,aAsBF,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const MAX_FILE_CHARS = 20_000;
|
|
2
|
+
/** Synchronous variant used by the REPL (node fs). */
|
|
3
|
+
export const expandMentions = (msg, readFileSync, existsSync) => {
|
|
4
|
+
const mentions = [...msg.matchAll(/(?:^|\s)@([^\s]+)/g)].map((m) => m[1]);
|
|
5
|
+
if (mentions.length === 0)
|
|
6
|
+
return { effective: msg, unreadable: [] };
|
|
7
|
+
const blocks = [];
|
|
8
|
+
const unreadable = [];
|
|
9
|
+
for (const mention of mentions) {
|
|
10
|
+
try {
|
|
11
|
+
if (!existsSync(mention))
|
|
12
|
+
throw new Error("not found");
|
|
13
|
+
const content = readFileSync(mention, "utf-8");
|
|
14
|
+
blocks.push(`--- @${mention} ---\n${content.slice(0, MAX_FILE_CHARS)}\n`);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
unreadable.push(mention);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (blocks.length === 0)
|
|
21
|
+
return { effective: msg, unreadable };
|
|
22
|
+
const stripped = msg.replace(/(?:^|\s)@[^\s]+/g, (m) => (m.startsWith(" ") ? " " : "")).trim();
|
|
23
|
+
return {
|
|
24
|
+
effective: `${stripped || "Review the attached file(s)."}\n\n${blocks.join("\n")}`,
|
|
25
|
+
unreadable,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=mentions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mentions.js","sourceRoot":"","sources":["../../../src/ui/utils/mentions.ts"],"names":[],"mappings":"AAUA,MAAM,cAAc,GAAG,MAAM,CAAC;AAE9B,sDAAsD;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,GAAW,EACX,YAAoD,EACpD,UAAqC,EACtB,EAAE;IACjB,MAAM,QAAQ,GAAG,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;IAErE,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC;YACvD,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC/C,MAAM,CAAC,IAAI,CAAC,QAAQ,OAAO,SAAS,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;QAC5E,CAAC;QAAC,MAAM,CAAC;YACP,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;IAE/D,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/F,OAAO;QACL,SAAS,EAAE,GAAG,QAAQ,IAAI,8BAA8B,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAClF,UAAU;KACX,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal-text hygiene: sanitization and display width.
|
|
3
|
+
*
|
|
4
|
+
* Two properties matter when rendering untrusted text (model output, file
|
|
5
|
+
* contents pulled in through @mentions, error messages from a remote server)
|
|
6
|
+
* into a terminal:
|
|
7
|
+
*
|
|
8
|
+
* 1. Escape sequences must never reach the terminal. A model reply
|
|
9
|
+
* containing `\x1b[2J` can clear the screen, `\x1b[?1049l` can drop the
|
|
10
|
+
* user out of the alternate buffer, and OSC 8/52 can rewrite the title or
|
|
11
|
+
* the clipboard. Ink has no sanitizer of its own.
|
|
12
|
+
* 2. Display width is not string length. Emoji and CJK glyphs occupy two
|
|
13
|
+
* columns; combining marks and zero-width joiners occupy none. Padding a
|
|
14
|
+
* table cell by `.length` misaligns every column after the first wide
|
|
15
|
+
* glyph, and a border drawn to a width computed in code units wraps.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Strip control sequences that could alter terminal state.
|
|
19
|
+
*
|
|
20
|
+
* Newlines and tabs are preserved (they are layout, not control), and so are
|
|
21
|
+
* carriage returns *only* when asked — a lone CR can overwrite the current
|
|
22
|
+
* line, so it is normalized away by default.
|
|
23
|
+
*/
|
|
24
|
+
export declare const sanitize: (text: string, keepNewlines?: boolean) => string;
|
|
25
|
+
/** True when the text contains something `sanitize` would remove. */
|
|
26
|
+
export declare const hasControlSequences: (text: string) => boolean;
|
|
27
|
+
/** Terminal columns occupied by `text` (assumes no escape sequences). */
|
|
28
|
+
export declare const displayWidth: (text: string) => number;
|
|
29
|
+
/** Truncate to `max` columns, appending `…` when anything was dropped. */
|
|
30
|
+
export declare const truncateToWidth: (text: string, max: number, ellipsis?: string) => string;
|
|
31
|
+
/** Pad to exactly `columns` display columns (left/right/center). */
|
|
32
|
+
export declare const padToWidth: (text: string, columns: number, align?: "left" | "right" | "center", fill?: string) => string;
|
|
33
|
+
//# sourceMappingURL=terminal-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-text.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/terminal-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAUH;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,SAAU,MAAM,6BAAwB,MAO5D,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,SAAU,MAAM,KAAG,OAAqC,CAAC;AAiDzF,yEAAyE;AACzE,eAAO,MAAM,YAAY,SAAU,MAAM,KAAG,MAI3C,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,eAAe,SAAU,MAAM,OAAO,MAAM,wBAAmB,MAa3E,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,UAAU,SACf,MAAM,WACH,MAAM,UACR,MAAM,GAAG,OAAO,GAAG,QAAQ,oBAEjC,MASF,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal-text hygiene: sanitization and display width.
|
|
3
|
+
*
|
|
4
|
+
* Two properties matter when rendering untrusted text (model output, file
|
|
5
|
+
* contents pulled in through @mentions, error messages from a remote server)
|
|
6
|
+
* into a terminal:
|
|
7
|
+
*
|
|
8
|
+
* 1. Escape sequences must never reach the terminal. A model reply
|
|
9
|
+
* containing `\x1b[2J` can clear the screen, `\x1b[?1049l` can drop the
|
|
10
|
+
* user out of the alternate buffer, and OSC 8/52 can rewrite the title or
|
|
11
|
+
* the clipboard. Ink has no sanitizer of its own.
|
|
12
|
+
* 2. Display width is not string length. Emoji and CJK glyphs occupy two
|
|
13
|
+
* columns; combining marks and zero-width joiners occupy none. Padding a
|
|
14
|
+
* table cell by `.length` misaligns every column after the first wide
|
|
15
|
+
* glyph, and a border drawn to a width computed in code units wraps.
|
|
16
|
+
*/
|
|
17
|
+
/* ── Sanitization ───────────────────────────────────────────────────────── */
|
|
18
|
+
// CSI: ESC [ params intermediates final
|
|
19
|
+
// OSC: ESC ] … (BEL | ESC \) DCS/PM/APC: ESC P|^|_ … (ESC \)
|
|
20
|
+
// Plus single-character ESC sequences and the C1 range.
|
|
21
|
+
// eslint-disable-next-line no-control-regex
|
|
22
|
+
const ESCAPE_SEQUENCE = /\x1B(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[P^_][\s\S]*?\x1B\\|[@-Z\\-_])|\x9B[0-?]*[ -/]*[@-~]|\x07/g;
|
|
23
|
+
/**
|
|
24
|
+
* Strip control sequences that could alter terminal state.
|
|
25
|
+
*
|
|
26
|
+
* Newlines and tabs are preserved (they are layout, not control), and so are
|
|
27
|
+
* carriage returns *only* when asked — a lone CR can overwrite the current
|
|
28
|
+
* line, so it is normalized away by default.
|
|
29
|
+
*/
|
|
30
|
+
export const sanitize = (text, keepNewlines = true) => {
|
|
31
|
+
let out = text.replace(ESCAPE_SEQUENCE, "");
|
|
32
|
+
// Other C0 control characters that would corrupt the frame. \n (0x0A) and
|
|
33
|
+
// \t (0x09) stay; \r (0x0D) goes — a bare CR rewrites the current line.
|
|
34
|
+
out = out.replace(/[\x00-\x08\x0B-\x1F\x7F]/g, "");
|
|
35
|
+
if (!keepNewlines)
|
|
36
|
+
out = out.replace(/\r?\n/g, " ");
|
|
37
|
+
return out;
|
|
38
|
+
};
|
|
39
|
+
/** True when the text contains something `sanitize` would remove. */
|
|
40
|
+
export const hasControlSequences = (text) => ESCAPE_SEQUENCE.test(text);
|
|
41
|
+
/* ── Display width ──────────────────────────────────────────────────────── */
|
|
42
|
+
/**
|
|
43
|
+
* Code points that occupy two terminal columns.
|
|
44
|
+
*
|
|
45
|
+
* This covers the East Asian Wide/Fullwidth ranges and the emoji blocks. It is
|
|
46
|
+
* deliberately a table rather than a dependency: `string-width` pulls in a
|
|
47
|
+
* regex engine and this list only needs to be right for what agents emit.
|
|
48
|
+
*/
|
|
49
|
+
const WIDE_RANGES = [
|
|
50
|
+
[0x1100, 0x115f], // Hangul Jamo init
|
|
51
|
+
[0x2e80, 0x303e], // CJK radicals, Kangxi, CJK symbols/punctuation
|
|
52
|
+
[0x3041, 0x33ff], // Hiragana, Katakana, Bopomofo, Hangul compat, CJK compat
|
|
53
|
+
[0x3400, 0x4dbf], // CJK ext A
|
|
54
|
+
[0x4e00, 0x9fff], // CJK unified ideographs
|
|
55
|
+
[0xa000, 0xa4cf], // Yi
|
|
56
|
+
[0xac00, 0xd7a3], // Hangul syllables
|
|
57
|
+
[0xf900, 0xfaff], // CJK compat ideographs
|
|
58
|
+
[0xfe10, 0xfe19], // Vertical forms
|
|
59
|
+
[0xfe30, 0xfe6f], // CJK compat forms
|
|
60
|
+
[0xff00, 0xff60], // Fullwidth forms
|
|
61
|
+
[0xffe0, 0xffe6], // Fullwidth signs
|
|
62
|
+
// Emoji: the whole pictographic block, including transport (🚀 U+1F680),
|
|
63
|
+
// supplemental symbols (U+1F900), and symbols extended-A (U+1FA70).
|
|
64
|
+
[0x1f300, 0x1faff],
|
|
65
|
+
[0x1f650, 0x1f67f], // ornamental dingbats
|
|
66
|
+
[0x1f680, 0x1f6ff], // transport and map symbols
|
|
67
|
+
[0x20000, 0x3fffd], // CJK ext B+
|
|
68
|
+
];
|
|
69
|
+
/** Zero-width code points: combining marks and joiners. */
|
|
70
|
+
const isZeroWidth = (cp) => (cp >= 0x0300 && cp <= 0x036f) || // combining diacritics
|
|
71
|
+
(cp >= 0x200b && cp <= 0x200f) || // ZWSP/ZWNJ/ZWJ/LRM/RLM
|
|
72
|
+
cp === 0xfeff || // BOM / zero-width no-break space
|
|
73
|
+
(cp >= 0xfe00 && cp <= 0xfe0f) || // variation selectors
|
|
74
|
+
(cp >= 0x1f3fb && cp <= 0x1f3ff); // emoji skin-tone modifiers
|
|
75
|
+
/** Column width of a single code point. */
|
|
76
|
+
const codePointWidth = (cp) => {
|
|
77
|
+
if (isZeroWidth(cp))
|
|
78
|
+
return 0;
|
|
79
|
+
for (const [lo, hi] of WIDE_RANGES) {
|
|
80
|
+
if (cp >= lo && cp <= hi)
|
|
81
|
+
return 2;
|
|
82
|
+
}
|
|
83
|
+
return 1;
|
|
84
|
+
};
|
|
85
|
+
/** Terminal columns occupied by `text` (assumes no escape sequences). */
|
|
86
|
+
export const displayWidth = (text) => {
|
|
87
|
+
let width = 0;
|
|
88
|
+
for (const ch of text)
|
|
89
|
+
width += codePointWidth(ch.codePointAt(0) ?? 0);
|
|
90
|
+
return width;
|
|
91
|
+
};
|
|
92
|
+
/** Truncate to `max` columns, appending `…` when anything was dropped. */
|
|
93
|
+
export const truncateToWidth = (text, max, ellipsis = "…") => {
|
|
94
|
+
if (max <= 0)
|
|
95
|
+
return "";
|
|
96
|
+
if (displayWidth(text) <= max)
|
|
97
|
+
return text;
|
|
98
|
+
const budget = max - displayWidth(ellipsis);
|
|
99
|
+
let out = "";
|
|
100
|
+
let used = 0;
|
|
101
|
+
for (const ch of text) {
|
|
102
|
+
const w = codePointWidth(ch.codePointAt(0) ?? 0);
|
|
103
|
+
if (used + w > budget)
|
|
104
|
+
break;
|
|
105
|
+
out += ch;
|
|
106
|
+
used += w;
|
|
107
|
+
}
|
|
108
|
+
return out + ellipsis;
|
|
109
|
+
};
|
|
110
|
+
/** Pad to exactly `columns` display columns (left/right/center). */
|
|
111
|
+
export const padToWidth = (text, columns, align = "left", fill = " ") => {
|
|
112
|
+
const gap = columns - displayWidth(text);
|
|
113
|
+
if (gap <= 0)
|
|
114
|
+
return text;
|
|
115
|
+
if (align === "right")
|
|
116
|
+
return fill.repeat(gap) + text;
|
|
117
|
+
if (align === "center") {
|
|
118
|
+
const left = Math.floor(gap / 2);
|
|
119
|
+
return fill.repeat(left) + text + fill.repeat(gap - left);
|
|
120
|
+
}
|
|
121
|
+
return text + fill.repeat(gap);
|
|
122
|
+
};
|
|
123
|
+
//# sourceMappingURL=terminal-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-text.js","sourceRoot":"","sources":["../../../src/ui/utils/terminal-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,+EAA+E;AAE/E,wCAAwC;AACxC,iEAAiE;AACjE,wDAAwD;AACxD,4CAA4C;AAC5C,MAAM,eAAe,GAAG,qHAAqH,CAAC;AAE9I;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,YAAY,GAAG,IAAI,EAAU,EAAE;IACpE,IAAI,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAC5C,0EAA0E;IAC1E,wEAAwE;IACxE,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,2BAA2B,EAAE,EAAE,CAAC,CAAC;IACnD,IAAI,CAAC,YAAY;QAAE,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACpD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEzF,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,WAAW,GAA6C;IAC5D,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,mBAAmB;IACrC,CAAC,MAAM,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C;AACxB,CAAC,CAAC;AAEF,oEAAoE;AACpE,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAY,EACZ,OAAe,EACf,KAAK,GAAgC,MAAM,EAC3C,IAAI,GAAG,GAAG,EACF,EAAE;IACV,MAAM,GAAG,GAAG,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,GAAG,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1B,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACtD,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Character-level helpers for the prompt editor.
|
|
3
|
+
*
|
|
4
|
+
* The REPL's input is a single line driven by raw key events, so cursor
|
|
5
|
+
* movement has to work on strings. Characters are iterated by code point to
|
|
6
|
+
* keep emoji intact when moving or deleting.
|
|
7
|
+
*/
|
|
8
|
+
/** Split into grapheme-ish units: surrogate pairs stay together. */
|
|
9
|
+
export declare const toChars: (text: string) => string[];
|
|
10
|
+
/** Clamp a cursor index to a string's length (in code points). */
|
|
11
|
+
export declare const clampCursor: (cursor: number, text: string) => number;
|
|
12
|
+
/** Move the cursor right by `n` characters. */
|
|
13
|
+
export declare const moveRight: (text: string, cursor: number, n?: number) => number;
|
|
14
|
+
/** Move the cursor left by `n` characters. */
|
|
15
|
+
export declare const moveLeft: (cursor: number, n?: number) => number;
|
|
16
|
+
/** Insert text at the cursor; returns the new value and cursor position. */
|
|
17
|
+
export declare const insertAt: (text: string, cursor: number, insert: string) => {
|
|
18
|
+
text: string;
|
|
19
|
+
cursor: number;
|
|
20
|
+
};
|
|
21
|
+
/** Delete the character before the cursor (backspace). */
|
|
22
|
+
export declare const deleteBefore: (text: string, cursor: number) => {
|
|
23
|
+
text: string;
|
|
24
|
+
cursor: number;
|
|
25
|
+
};
|
|
26
|
+
/** Delete the character at the cursor (delete key). */
|
|
27
|
+
export declare const deleteAt: (text: string, cursor: number) => {
|
|
28
|
+
text: string;
|
|
29
|
+
cursor: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Which token does the cursor sit in? Used by the slash menu so it opens for
|
|
33
|
+
* `/cmd` typed mid-prompt, not only at line start.
|
|
34
|
+
*/
|
|
35
|
+
export declare const wordAt: (text: string, cursor: number) => {
|
|
36
|
+
word: string;
|
|
37
|
+
start: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The whitespace-delimited token around the caret, as a half-open range.
|
|
41
|
+
*
|
|
42
|
+
* `wordAt` stops at the caret (it answers "what has been typed so far"), which
|
|
43
|
+
* is the wrong span for *replacing* a token: completing "/he|lp" needs the
|
|
44
|
+
* whole "/help", or the tail gets re-appended as if it were typed arguments.
|
|
45
|
+
*/
|
|
46
|
+
export declare const wordBounds: (text: string, cursor: number) => {
|
|
47
|
+
start: number;
|
|
48
|
+
end: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Case-insensitive subsequence score, or -1 when `query` is not a subsequence
|
|
52
|
+
* of `text`. Contiguous and word-start matches score higher so `h` ranks
|
|
53
|
+
* `/help` above `/history`. Code points, not UTF-16 units, so an emoji in a
|
|
54
|
+
* history entry cannot desynchronise the match.
|
|
55
|
+
*/
|
|
56
|
+
export declare const fuzzyScore: (text: string, query: string) => number;
|
|
57
|
+
/** Sort by descending score, keeping the original order on ties. */
|
|
58
|
+
export declare const fuzzyRank: <T>(items: T[], query: string, key: (item: T) => string) => T[];
|
|
59
|
+
/** Index of the first character on the cursor's line. */
|
|
60
|
+
export declare const lineStart: (text: string, cursor: number) => number;
|
|
61
|
+
/** Index of the line terminator (or end of text) after the cursor's line. */
|
|
62
|
+
export declare const lineEnd: (text: string, cursor: number) => number;
|
|
63
|
+
/** True when the cursor's line is the first / last one. */
|
|
64
|
+
export declare const onFirstLine: (text: string, cursor: number) => boolean;
|
|
65
|
+
export declare const onLastLine: (text: string, cursor: number) => boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Move the caret one line up (-1) or down (+1), keeping the column where it
|
|
68
|
+
* exists and clamping to the shorter line otherwise — the behavior every
|
|
69
|
+
* text editor has.
|
|
70
|
+
*/
|
|
71
|
+
export declare const moveVertical: (text: string, cursor: number, dir: -1 | 1) => number;
|
|
72
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/ui/utils/text.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oEAAoE;AACpE,eAAO,MAAM,OAAO,SAAU,MAAM,KAAG,MAAM,EAAsB,CAAC;AAEpE,kEAAkE;AAClE,eAAO,MAAM,WAAW,WAAY,MAAM,QAAQ,MAAM,KAAG,MAM1D,CAAC;AAEF,+CAA+C;AAC/C,eAAO,MAAM,SAAS,SAAU,MAAM,UAAU,MAAM,iBAAU,MACjC,CAAC;AAEhC,8CAA8C;AAC9C,eAAO,MAAM,QAAQ,WAAY,MAAM,iBAAU,MAAiC,CAAC;AAEnF,4EAA4E;AAC5E,eAAO,MAAM,QAAQ,SAAU,MAAM,UAAU,MAAM,UAAU,MAAM,KAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAKrG,CAAC;AAEF,0DAA0D;AAC1D,eAAO,MAAM,YAAY,SAAU,MAAM,UAAU,MAAM,KAA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