nolo-cli 0.144.0-alpha.1 → 0.145.0-alpha.1
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 +2 -0
- package/{_executeModel-VA7AOJ7I.js → _executeModel-M3FASQ2Z.js} +13 -13
- package/{agentDeleteCommand-Z3UO4OJU.js → agentDeleteCommand-K7GCEEVS.js} +3 -3
- package/{agentEmailCommands-73TKP5CA.js → agentEmailCommands-MNXRO36L.js} +14 -14
- package/{agentListCommands-Y7QPH22N.js → agentListCommands-KMZR6VVM.js} +3 -3
- package/{agentMachineCommands-NTV2CIGF.js → agentMachineCommands-75TIBYDY.js} +4 -4
- package/{agentRecordCommands-XOXZQYL3.js → agentRecordCommands-RDO5L3N4.js} +14 -14
- package/{agentRunCommand-6C7BR2AM.js → agentRunCommand-FVJJPL27.js} +14 -14
- package/{agentRuntimeLocal-3FUYPU7E.js → agentRuntimeLocal-DAK7RCER.js} +3 -3
- package/{agentSlice-FK2FY7UE.js → agentSlice-6MRJR2BJ.js} +1 -1
- package/{appDeleteCommands-L6IDOOI7.js → appDeleteCommands-JMMXK3XT.js} +3 -3
- package/{appDeployCommands-XTT6FWGB.js → appDeployCommands-JFU6GALI.js} +3 -3
- package/{appDeployStatusCommands-3USXE3N3.js → appDeployStatusCommands-AXTZ4GAN.js} +3 -3
- package/{appGetCommands-PHADWOLO.js → appGetCommands-CR2W3DCM.js} +3 -3
- package/{appListCommands-YM22HHY5.js → appListCommands-2TV6P3EU.js} +3 -3
- package/{authCommand-XLCNATZR.js → authCommand-UBJ4EWYZ.js} +1 -1
- package/{authCommands-GBIFZWD3.js → authCommands-H6WKKCRW.js} +1 -1
- package/{builtinSkillRegistry-HRI7DXC2.js → builtinSkillRegistry-ZMF6YGNO.js} +2 -2
- package/{chatQueueReduxAdapter-ZHUJO77G.js → chatQueueReduxAdapter-CDOHVTSE.js} +2 -2
- package/{chromeCommands-K27J4OVZ.js → chromeCommands-2N6MEWRU.js} +3 -3
- package/{chunk-LQNRUDVN.js → chunk-2TKVOEQF.js} +5 -5
- package/{chunk-3AOSNKIZ.js → chunk-5XYFIDFU.js} +5 -5
- package/{chunk-EM7HELS5.js → chunk-62XHRZG4.js} +2 -2
- package/{chunk-EMBK4B7D.js → chunk-6TPOEJMQ.js} +1 -1
- package/{chunk-BRCOB2YF.js → chunk-7YAK46ML.js} +2 -2
- package/{chunk-YFIUVDQY.js → chunk-A6FNUMCF.js} +46 -5
- package/{chunk-EP34KKT6.js → chunk-ANX7Z7Z2.js} +8 -8
- package/{chunk-MOFAGINP.js → chunk-B2XUQXQX.js} +1 -1
- package/chunk-GNMAFAIS.js +29 -0
- package/{chunk-6YSYZTKW.js → chunk-HKBFZONG.js} +1 -1
- package/{chunk-VPFEPRME.js → chunk-IVZJWTDI.js} +3 -0
- package/{chunk-AQTJUKN6.js → chunk-JLQKV2ZJ.js} +1 -1
- package/{chunk-3T6MH737.js → chunk-M76SRQ3H.js} +19 -9
- package/{chunk-L55HWODG.js → chunk-OKSJZ4UU.js} +10 -10
- package/{chunk-OJL4DA6B.js → chunk-QFZM5BFI.js} +1 -1
- package/{chunk-QMJG7UFL.js → chunk-RHDOQWXZ.js} +164 -10
- package/{chunk-6Z5V5T6Q.js → chunk-UMB7CHAY.js} +3 -3
- package/{chunk-XPV3S4HP.js → chunk-VJ4FUWPC.js} +3 -3
- package/{chunk-2KHRSBYS.js → chunk-VZVTPDPL.js} +3 -3
- package/{chunk-XGO2LIJZ.js → chunk-XNXNHAAP.js} +1 -1
- package/{chunk-TIPZHRUE.js → chunk-Y6XHJ4JJ.js} +19 -7
- package/{commandRegistry-VN3VYRTY.js → commandRegistry-ZF6YXQWV.js} +54 -54
- package/{contentThunks-GLALFCSA.js → contentThunks-6Y6ATG3A.js} +3 -3
- package/{createAgentAutomationAction-AJYCFU4M.js → createAgentAutomationAction-OQTLA2FC.js} +3 -3
- package/{createDialogAction-RHUDYILB.js → createDialogAction-IF5EZMBD.js} +5 -5
- package/{createPageAction-QNBURBCT.js → createPageAction-GU766R3L.js} +3 -3
- package/{dialogCommands-FUZOZGN2.js → dialogCommands-QV7XAX2V.js} +3 -3
- package/{dialogSlice-OXWSQS6J.js → dialogSlice-CVHMDSVV.js} +2 -2
- package/{docCreateCommands-TKWA2BQD.js → docCreateCommands-FSBANQTO.js} +3 -3
- package/{docDeleteCommands-BEBGKH2B.js → docDeleteCommands-4IR4YSGU.js} +3 -3
- package/{docReadCommands-5GWHRUJF.js → docReadCommands-4EYPGUE3.js} +3 -3
- package/{docStore-RMY3R4VP.js → docStore-RQOWPNON.js} +1 -1
- package/{docUpdateCommands-WTKBMMUQ.js → docUpdateCommands-RW2BYLSE.js} +3 -3
- package/{handleSendMessageAction-D7XLCRJJ.js → handleSendMessageAction-UDTPG5WK.js} +2 -2
- package/index.js +3 -3
- package/{machineCommands-DHJHXKIL.js → machineCommands-WBQ4TCPD.js} +14 -14
- package/{machineWsRunDispatch-KP636B54.js → machineWsRunDispatch-7DNDXUOS.js} +14 -14
- package/node_modules/abstract-level/CHANGELOG.md +150 -0
- package/node_modules/abstract-level/LICENSE +21 -0
- package/node_modules/abstract-level/README.md +1957 -0
- package/node_modules/abstract-level/UPGRADING.md +669 -0
- package/node_modules/abstract-level/abstract-chained-batch.js +397 -0
- package/node_modules/abstract-level/abstract-iterator.js +404 -0
- package/node_modules/abstract-level/abstract-level.js +1127 -0
- package/node_modules/abstract-level/abstract-snapshot.js +84 -0
- package/node_modules/abstract-level/index.d.ts +52 -0
- package/node_modules/abstract-level/index.js +9 -0
- package/node_modules/abstract-level/lib/abstract-sublevel-iterator.js +141 -0
- package/node_modules/abstract-level/lib/abstract-sublevel.js +290 -0
- package/node_modules/abstract-level/lib/common.js +33 -0
- package/node_modules/abstract-level/lib/default-chained-batch.js +29 -0
- package/node_modules/abstract-level/lib/default-kv-iterator.js +74 -0
- package/node_modules/abstract-level/lib/deferred-iterator.js +110 -0
- package/node_modules/abstract-level/lib/deferred-queue.js +84 -0
- package/node_modules/abstract-level/lib/errors.js +21 -0
- package/node_modules/abstract-level/lib/event-monitor.js +30 -0
- package/node_modules/abstract-level/lib/hooks.js +78 -0
- package/node_modules/abstract-level/lib/prefixes.js +21 -0
- package/node_modules/abstract-level/lib/prewrite-batch.js +96 -0
- package/node_modules/abstract-level/lib/range-options.js +26 -0
- package/node_modules/abstract-level/package.json +66 -0
- package/node_modules/abstract-level/test/async-iterator-test.js +132 -0
- package/node_modules/abstract-level/test/batch-test.js +214 -0
- package/node_modules/abstract-level/test/chained-batch-test.js +315 -0
- package/node_modules/abstract-level/test/clear-range-test.js +262 -0
- package/node_modules/abstract-level/test/clear-test.js +110 -0
- package/node_modules/abstract-level/test/common.js +90 -0
- package/node_modules/abstract-level/test/deferred-open-test.js +209 -0
- package/node_modules/abstract-level/test/del-test.js +65 -0
- package/node_modules/abstract-level/test/encoding-buffer-test.js +336 -0
- package/node_modules/abstract-level/test/encoding-custom-test.js +92 -0
- package/node_modules/abstract-level/test/encoding-decode-error-test.js +85 -0
- package/node_modules/abstract-level/test/encoding-json-test.js +75 -0
- package/node_modules/abstract-level/test/encoding-test.js +130 -0
- package/node_modules/abstract-level/test/events/write.js +132 -0
- package/node_modules/abstract-level/test/factory-test.js +36 -0
- package/node_modules/abstract-level/test/get-many-test.js +157 -0
- package/node_modules/abstract-level/test/get-sync-test.js +61 -0
- package/node_modules/abstract-level/test/get-test.js +83 -0
- package/node_modules/abstract-level/test/has-many-test.js +144 -0
- package/node_modules/abstract-level/test/has-test.js +81 -0
- package/node_modules/abstract-level/test/hooks/newsub.js +57 -0
- package/node_modules/abstract-level/test/hooks/postopen.js +229 -0
- package/node_modules/abstract-level/test/hooks/prewrite.js +816 -0
- package/node_modules/abstract-level/test/hooks/shared.js +38 -0
- package/node_modules/abstract-level/test/index.js +86 -0
- package/node_modules/abstract-level/test/iterator-explicit-snapshot-test.js +393 -0
- package/node_modules/abstract-level/test/iterator-no-snapshot-test.js +49 -0
- package/node_modules/abstract-level/test/iterator-range-test.js +277 -0
- package/node_modules/abstract-level/test/iterator-seek-test.js +335 -0
- package/node_modules/abstract-level/test/iterator-snapshot-test.js +56 -0
- package/node_modules/abstract-level/test/iterator-test.js +621 -0
- package/node_modules/abstract-level/test/manifest-test.js +21 -0
- package/node_modules/abstract-level/test/open-create-if-missing-test.js +39 -0
- package/node_modules/abstract-level/test/open-error-if-exists-test.js +25 -0
- package/node_modules/abstract-level/test/open-test.js +263 -0
- package/node_modules/abstract-level/test/put-get-del-test.js +97 -0
- package/node_modules/abstract-level/test/put-test.js +70 -0
- package/node_modules/abstract-level/test/self/abstract-iterator-test.js +182 -0
- package/node_modules/abstract-level/test/self/async-iterator-test.js +242 -0
- package/node_modules/abstract-level/test/self/attach-resource-test.js +74 -0
- package/node_modules/abstract-level/test/self/defer-test.js +140 -0
- package/node_modules/abstract-level/test/self/deferred-iterator-test.js +314 -0
- package/node_modules/abstract-level/test/self/deferred-operations-test.js +86 -0
- package/node_modules/abstract-level/test/self/deferred-queue-test.js +93 -0
- package/node_modules/abstract-level/test/self/encoding-test.js +391 -0
- package/node_modules/abstract-level/test/self/errors-test.js +11 -0
- package/node_modules/abstract-level/test/self/iterator-test.js +1050 -0
- package/node_modules/abstract-level/test/self/sublevel-test.js +1039 -0
- package/node_modules/abstract-level/test/self.js +905 -0
- package/node_modules/abstract-level/test/sublevel-test.js +209 -0
- package/node_modules/abstract-level/test/traits/closed.js +42 -0
- package/node_modules/abstract-level/test/traits/index.js +4 -0
- package/node_modules/abstract-level/test/traits/open.js +62 -0
- package/node_modules/abstract-level/test/util.js +275 -0
- package/node_modules/abstract-level/types/abstract-chained-batch.d.ts +124 -0
- package/node_modules/abstract-level/types/abstract-iterator.d.ts +241 -0
- package/node_modules/abstract-level/types/abstract-level.d.ts +636 -0
- package/node_modules/abstract-level/types/abstract-snapshot.d.ts +30 -0
- package/node_modules/abstract-level/types/abstract-sublevel.d.ts +76 -0
- package/node_modules/abstract-level/types/interfaces.d.ts +43 -0
- package/node_modules/base64-js/LICENSE +21 -0
- package/node_modules/base64-js/README.md +34 -0
- package/node_modules/base64-js/base64js.min.js +1 -0
- package/node_modules/base64-js/index.d.ts +3 -0
- package/node_modules/base64-js/index.js +150 -0
- package/node_modules/base64-js/package.json +47 -0
- package/node_modules/browser-level/CHANGELOG.md +44 -0
- package/node_modules/browser-level/LICENSE +21 -0
- package/node_modules/browser-level/README.md +124 -0
- package/node_modules/browser-level/UPGRADING.md +143 -0
- package/node_modules/browser-level/index.d.ts +108 -0
- package/node_modules/browser-level/index.js +323 -0
- package/node_modules/browser-level/iterator.js +239 -0
- package/node_modules/browser-level/package.json +48 -0
- package/node_modules/browser-level/util/clear.js +38 -0
- package/node_modules/browser-level/util/deserialize.js +17 -0
- package/node_modules/browser-level/util/key-range.js +20 -0
- package/node_modules/buffer/AUTHORS.md +73 -0
- package/node_modules/buffer/LICENSE +21 -0
- package/node_modules/buffer/README.md +410 -0
- package/node_modules/buffer/index.d.ts +194 -0
- package/node_modules/buffer/index.js +2106 -0
- package/node_modules/buffer/package.json +93 -0
- package/node_modules/classic-level/CHANGELOG.md +115 -0
- package/node_modules/classic-level/LICENSE +21 -0
- package/node_modules/classic-level/README.md +274 -0
- package/node_modules/classic-level/UPGRADING.md +131 -0
- package/node_modules/classic-level/binding.cc +2652 -0
- package/node_modules/classic-level/binding.gyp +71 -0
- package/node_modules/classic-level/binding.js +1 -0
- package/node_modules/classic-level/chained-batch.js +35 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/LICENSE +27 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/Makefile +424 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/build_detect_platform +256 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/autocompact_test.cc +118 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/builder.cc +88 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/builder.h +34 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/c.cc +595 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/c_test.c +390 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/corruption_test.cc +374 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_bench.cc +1020 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_impl.cc +1568 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_impl.h +212 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_iter.cc +317 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_iter.h +28 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/db_test.cc +2158 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/dbformat.cc +140 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/dbformat.h +230 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/dbformat_test.cc +112 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/dumpfile.cc +225 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/fault_injection_test.cc +554 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/filename.cc +144 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/filename.h +85 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/filename_test.cc +123 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/leveldbutil.cc +64 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_format.h +35 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_reader.cc +284 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_reader.h +113 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_test.cc +591 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_writer.cc +112 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/log_writer.h +54 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/memtable.cc +145 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/memtable.h +89 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/recovery_test.cc +324 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/repair.cc +461 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/skiplist.h +384 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/skiplist_test.cc +378 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/snapshot.h +67 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/table_cache.cc +127 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/table_cache.h +61 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_edit.cc +266 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_edit.h +107 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_edit_test.cc +46 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_set.cc +1535 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_set.h +399 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/version_set_test.cc +179 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/write_batch.cc +147 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/write_batch_internal.h +50 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/db/write_batch_test.cc +120 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/helpers/memenv/memenv.cc +398 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/helpers/memenv/memenv.h +20 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/helpers/memenv/memenv_test.cc +241 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/c.h +290 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/cache.h +110 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/comparator.h +63 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/db.h +164 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/dumpfile.h +25 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/env.h +351 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/filter_policy.h +70 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/iterator.h +100 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/options.h +213 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/slice.h +109 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/status.h +112 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/table.h +85 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/table_builder.h +92 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/value_sink.h +26 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/include/leveldb/write_batch.h +64 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/issues/issue178_test.cc +92 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/issues/issue200_test.cc +59 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/atomic_pointer.h +242 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port.h +21 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port_example.h +141 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port_posix.cc +53 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port_posix.h +156 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/port_posix_sse.cc +129 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/thread_annotations.h +60 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/port/win/stdint.h +24 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/block.cc +268 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/block.h +44 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/block_builder.cc +109 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/block_builder.h +57 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/filter_block.cc +111 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/filter_block.h +68 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/filter_block_test.cc +128 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/format.cc +144 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/format.h +108 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/iterator.cc +67 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/iterator_wrapper.h +66 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/merger.cc +197 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/merger.h +26 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/table.cc +285 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/table_builder.cc +270 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/table_test.cc +876 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/two_level_iterator.cc +182 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/table/two_level_iterator.h +34 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/arena.cc +68 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/arena.h +68 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/arena_test.cc +68 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/bloom.cc +95 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/bloom_test.cc +162 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/cache.cc +405 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/cache_test.cc +226 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/coding.cc +194 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/coding.h +104 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/coding_test.cc +196 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/comparator.cc +81 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/crc32c.cc +350 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/crc32c.h +45 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/crc32c_test.cc +72 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env.cc +100 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env_posix.cc +695 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env_posix_test.cc +66 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env_posix_test_helper.h +28 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/env_test.cc +106 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/filter_policy.cc +11 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/hash.cc +52 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/hash.h +19 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/hash_test.cc +54 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/histogram.cc +139 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/histogram.h +42 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/logging.cc +72 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/logging.h +43 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/mutexlock.h +41 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/options.cc +30 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/posix_logger.h +98 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/random.h +64 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/status.cc +75 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/testharness.cc +77 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/testharness.h +138 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/testutil.cc +51 -0
- package/node_modules/classic-level/deps/leveldb/leveldb-1.20/util/testutil.h +63 -0
- package/node_modules/classic-level/deps/leveldb/leveldb.gyp +282 -0
- package/node_modules/classic-level/deps/leveldb/patches/001-value-sink.patch +164 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/atomic_pointer_win.h +48 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/env_win.cc +692 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/port_uv.cc +36 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/port_uv.h +157 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/port_uv.h.bak +153 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/stdint-msvc2008.h +247 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/uv_condvar.h +45 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/uv_condvar_posix.cc +139 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/win_logger.cc +79 -0
- package/node_modules/classic-level/deps/leveldb/port-libuv/win_logger.h +28 -0
- package/node_modules/classic-level/deps/snappy/freebsd/config.h +135 -0
- package/node_modules/classic-level/deps/snappy/freebsd/snappy-stubs-public.h +100 -0
- package/node_modules/classic-level/deps/snappy/linux/config.h +135 -0
- package/node_modules/classic-level/deps/snappy/linux/snappy-stubs-public.h +100 -0
- package/node_modules/classic-level/deps/snappy/mac/config.h +137 -0
- package/node_modules/classic-level/deps/snappy/mac/snappy-stubs-public.h +100 -0
- package/node_modules/classic-level/deps/snappy/openbsd/config.h +135 -0
- package/node_modules/classic-level/deps/snappy/openbsd/snappy-stubs-public.h +100 -0
- package/node_modules/classic-level/deps/snappy/snappy/COPYING +54 -0
- package/node_modules/classic-level/deps/snappy/snappy/cmake/SnappyConfig.cmake +1 -0
- package/node_modules/classic-level/deps/snappy/snappy/cmake/config.h.in +62 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-c.cc +90 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-c.h +138 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-internal.h +224 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-sinksource.cc +104 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-sinksource.h +182 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-stubs-internal.cc +42 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-stubs-internal.h +561 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-stubs-public.h.in +94 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-test.cc +612 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy-test.h +573 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy.cc +1515 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy.h +203 -0
- package/node_modules/classic-level/deps/snappy/snappy/snappy_unittest.cc +1410 -0
- package/node_modules/classic-level/deps/snappy/snappy.gyp +119 -0
- package/node_modules/classic-level/deps/snappy/solaris/config.h +135 -0
- package/node_modules/classic-level/deps/snappy/solaris/snappy-stubs-public.h +100 -0
- package/node_modules/classic-level/deps/snappy/win32/config.h +29 -0
- package/node_modules/classic-level/deps/snappy/win32/snappy-stubs-public.h +100 -0
- package/node_modules/classic-level/index.d.ts +343 -0
- package/node_modules/classic-level/index.js +311 -0
- package/node_modules/classic-level/iterator.js +122 -0
- package/node_modules/classic-level/package.json +70 -0
- package/node_modules/classic-level/prebuilds/android-arm/classic-level.armv7.node +0 -0
- package/node_modules/classic-level/prebuilds/android-arm64/classic-level.armv8.node +0 -0
- package/node_modules/classic-level/prebuilds/darwin-x64+arm64/classic-level.node +0 -0
- package/node_modules/classic-level/prebuilds/linux-arm/classic-level.armv6.node +0 -0
- package/node_modules/classic-level/prebuilds/linux-arm/classic-level.armv7.node +0 -0
- package/node_modules/classic-level/prebuilds/linux-arm64/classic-level.armv8.node +0 -0
- package/node_modules/classic-level/prebuilds/linux-x64/classic-level.musl.node +0 -0
- package/node_modules/classic-level/prebuilds/linux-x64/classic-level.node +0 -0
- package/node_modules/classic-level/prebuilds/win32-ia32/classic-level.node +0 -0
- package/node_modules/classic-level/prebuilds/win32-x64/classic-level.node +0 -0
- package/node_modules/ieee754/LICENSE +11 -0
- package/node_modules/ieee754/README.md +51 -0
- package/node_modules/ieee754/index.d.ts +10 -0
- package/node_modules/ieee754/index.js +85 -0
- package/node_modules/ieee754/package.json +52 -0
- package/node_modules/is-buffer/LICENSE +21 -0
- package/node_modules/is-buffer/README.md +54 -0
- package/node_modules/is-buffer/index.d.ts +2 -0
- package/node_modules/is-buffer/index.js +11 -0
- package/node_modules/is-buffer/package.json +65 -0
- package/node_modules/level/CHANGELOG.md +532 -0
- package/node_modules/level/LICENSE +21 -0
- package/node_modules/level/README.md +107 -0
- package/node_modules/level/UPGRADING.md +413 -0
- package/node_modules/level/browser.js +1 -0
- package/node_modules/level/index.d.ts +75 -0
- package/node_modules/level/index.js +1 -0
- package/node_modules/level/package.json +62 -0
- package/node_modules/level-supports/CHANGELOG.md +140 -0
- package/node_modules/level-supports/LICENSE +21 -0
- package/node_modules/level-supports/README.md +276 -0
- package/node_modules/level-supports/index.d.ts +137 -0
- package/node_modules/level-supports/index.js +26 -0
- package/node_modules/level-supports/package.json +46 -0
- package/node_modules/level-supports/test/cloneable.js +26 -0
- package/node_modules/level-supports/test/index.js +24 -0
- package/node_modules/level-supports/test/self.js +86 -0
- package/node_modules/level-supports/test/shape.js +23 -0
- package/node_modules/level-transcoder/CHANGELOG.md +15 -0
- package/node_modules/level-transcoder/LICENSE +21 -0
- package/node_modules/level-transcoder/README.md +214 -0
- package/node_modules/level-transcoder/UPGRADING.md +13 -0
- package/node_modules/level-transcoder/index.d.ts +27 -0
- package/node_modules/level-transcoder/index.js +158 -0
- package/node_modules/level-transcoder/lib/encoding.d.ts +158 -0
- package/node_modules/level-transcoder/lib/encoding.js +105 -0
- package/node_modules/level-transcoder/lib/encodings.d.ts +9 -0
- package/node_modules/level-transcoder/lib/encodings.js +135 -0
- package/node_modules/level-transcoder/lib/formats.d.ts +13 -0
- package/node_modules/level-transcoder/lib/formats.js +111 -0
- package/node_modules/level-transcoder/lib/text-endec.d.ts +6 -0
- package/node_modules/level-transcoder/lib/text-endec.js +19 -0
- package/node_modules/level-transcoder/package.json +46 -0
- package/node_modules/maybe-combine-errors/LICENSE.md +21 -0
- package/node_modules/maybe-combine-errors/README.md +94 -0
- package/node_modules/maybe-combine-errors/index.js +60 -0
- package/node_modules/maybe-combine-errors/package.json +33 -0
- package/node_modules/module-error/CHANGELOG.md +23 -0
- package/node_modules/module-error/LICENSE +21 -0
- package/node_modules/module-error/README.md +89 -0
- package/node_modules/module-error/index.d.ts +18 -0
- package/node_modules/module-error/index.js +22 -0
- package/node_modules/module-error/package.json +36 -0
- package/node_modules/napi-macros/LICENSE +21 -0
- package/node_modules/napi-macros/README.md +277 -0
- package/node_modules/napi-macros/index.js +1 -0
- package/node_modules/napi-macros/napi-macros.h +255 -0
- package/node_modules/napi-macros/package.json +22 -0
- package/node_modules/node-gyp-build/LICENSE +21 -0
- package/node_modules/node-gyp-build/README.md +58 -0
- package/node_modules/node-gyp-build/SECURITY.md +5 -0
- package/node_modules/node-gyp-build/bin.js +84 -0
- package/node_modules/node-gyp-build/build-test.js +19 -0
- package/node_modules/node-gyp-build/index.js +6 -0
- package/node_modules/node-gyp-build/node-gyp-build.js +207 -0
- package/node_modules/node-gyp-build/optional.js +7 -0
- package/node_modules/node-gyp-build/package.json +43 -0
- package/package.json +6 -3
- package/{readlineWorkspace-5P24E57Z.js → readlineWorkspace-LO6ZLFTO.js} +1368 -1305
- package/{runAgentClientLoop-AXFKKSVY.js → runAgentClientLoop-KAYGKVTK.js} +11 -11
- package/{runtimeDoctorCommands-3USD722U.js → runtimeDoctorCommands-ID23PNNZ.js} +28 -0
- package/{spaceCommands-TRABD7YR.js → spaceCommands-FA6RCZ2Y.js} +3 -3
- package/{streamAgentChatTurn-RG7NWZWY.js → streamAgentChatTurn-DFNDU2UY.js} +12 -12
- package/{tools-GIXG5YIO.js → tools-6HKH75NT.js} +8 -8
- package/{tuiSummaryLlmCaller-RVWN63CP.js → tuiSummaryLlmCaller-CFFVXQWX.js} +1 -1
- package/{updateDialogTitleAction-JXZ2K54W.js → updateDialogTitleAction-FFSYTLBC.js} +3 -3
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import "./chunk-M3JEW6N6.js";
|
|
2
|
+
import {
|
|
3
|
+
resolveAuthGuidanceState
|
|
4
|
+
} from "./chunk-GNMAFAIS.js";
|
|
2
5
|
import {
|
|
3
6
|
formatQuotaSummary,
|
|
4
7
|
listFavoriteAgentIdsAcrossServers,
|
|
@@ -73,7 +76,7 @@ import {
|
|
|
73
76
|
wrapTextToLines,
|
|
74
77
|
wrapTranscriptLine,
|
|
75
78
|
wrapTranscriptLineWithLayout
|
|
76
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-Y6XHJ4JJ.js";
|
|
77
80
|
import "./chunk-VJVNU77E.js";
|
|
78
81
|
import "./chunk-BIDGLJQ3.js";
|
|
79
82
|
import {
|
|
@@ -85,7 +88,7 @@ import {
|
|
|
85
88
|
readTimestamp,
|
|
86
89
|
setCliLocale,
|
|
87
90
|
t
|
|
88
|
-
} from "./chunk-
|
|
91
|
+
} from "./chunk-M76SRQ3H.js";
|
|
89
92
|
import "./chunk-I4OPU5TK.js";
|
|
90
93
|
import "./chunk-YUNJN43V.js";
|
|
91
94
|
import "./chunk-62IL3KQV.js";
|
|
@@ -95,7 +98,7 @@ import {
|
|
|
95
98
|
import {
|
|
96
99
|
defaultOpenBrowser,
|
|
97
100
|
saveTokenLogin
|
|
98
|
-
} from "./chunk-
|
|
101
|
+
} from "./chunk-IVZJWTDI.js";
|
|
99
102
|
import "./chunk-ESHYE7WU.js";
|
|
100
103
|
import {
|
|
101
104
|
isScheduledDialog,
|
|
@@ -139,12 +142,12 @@ import "./chunk-ATNTHIZI.js";
|
|
|
139
142
|
import "./chunk-JEXVIMYZ.js";
|
|
140
143
|
import {
|
|
141
144
|
prepareTools
|
|
142
|
-
} from "./chunk-
|
|
145
|
+
} from "./chunk-7YAK46ML.js";
|
|
143
146
|
import {
|
|
144
147
|
buildResponseGuidelines
|
|
145
148
|
} from "./chunk-EOARMOVD.js";
|
|
146
149
|
import "./chunk-HS7MLR74.js";
|
|
147
|
-
import "./chunk-
|
|
150
|
+
import "./chunk-OKSJZ4UU.js";
|
|
148
151
|
import "./chunk-2EE5UD3N.js";
|
|
149
152
|
import "./chunk-5UTFL4QJ.js";
|
|
150
153
|
import "./chunk-KQHGZWSV.js";
|
|
@@ -163,12 +166,12 @@ import {
|
|
|
163
166
|
runShowsLogTail,
|
|
164
167
|
shortRunId
|
|
165
168
|
} from "./chunk-L4KXQ6QP.js";
|
|
166
|
-
import "./chunk-
|
|
169
|
+
import "./chunk-VZVTPDPL.js";
|
|
167
170
|
import "./chunk-HNRASX3X.js";
|
|
168
171
|
import "./chunk-YRRASA5Q.js";
|
|
169
172
|
import "./chunk-63W5N6P3.js";
|
|
170
173
|
import "./chunk-VF4K2QE6.js";
|
|
171
|
-
import "./chunk-
|
|
174
|
+
import "./chunk-62XHRZG4.js";
|
|
172
175
|
import "./chunk-Z7IZQF56.js";
|
|
173
176
|
import "./chunk-XPRWFQQK.js";
|
|
174
177
|
import {
|
|
@@ -178,15 +181,15 @@ import {
|
|
|
178
181
|
} from "./chunk-YPREESF4.js";
|
|
179
182
|
import "./chunk-BJUDYFV5.js";
|
|
180
183
|
import "./chunk-MEYIRKDN.js";
|
|
181
|
-
import "./chunk-
|
|
184
|
+
import "./chunk-HKBFZONG.js";
|
|
182
185
|
import "./chunk-ZJ7UHBJS.js";
|
|
183
186
|
import {
|
|
184
187
|
extractReferenceKeysFromMessage
|
|
185
|
-
} from "./chunk-
|
|
188
|
+
} from "./chunk-ANX7Z7Z2.js";
|
|
186
189
|
import "./chunk-MC4XLIJ7.js";
|
|
187
190
|
import "./chunk-YYLHWIW6.js";
|
|
188
191
|
import "./chunk-6O4IK4V2.js";
|
|
189
|
-
import "./chunk-
|
|
192
|
+
import "./chunk-UMB7CHAY.js";
|
|
190
193
|
import "./chunk-D76D3RTR.js";
|
|
191
194
|
import "./chunk-5RGU3J7P.js";
|
|
192
195
|
import "./chunk-M76ECQRD.js";
|
|
@@ -201,10 +204,10 @@ import {
|
|
|
201
204
|
buildSkillDiscoveryContextBlock,
|
|
202
205
|
buildSkillDiscoveryContextLayer
|
|
203
206
|
} from "./chunk-E4MARS3Q.js";
|
|
204
|
-
import "./chunk-
|
|
207
|
+
import "./chunk-B2XUQXQX.js";
|
|
205
208
|
import {
|
|
206
209
|
expandEnabledPacks
|
|
207
|
-
} from "./chunk-
|
|
210
|
+
} from "./chunk-6TPOEJMQ.js";
|
|
208
211
|
import "./chunk-AUDNYVRC.js";
|
|
209
212
|
import "./chunk-KHCLMKZZ.js";
|
|
210
213
|
import {
|
|
@@ -213,10 +216,10 @@ import {
|
|
|
213
216
|
formatToolOverflowMarker,
|
|
214
217
|
getProcessRegistry,
|
|
215
218
|
readCommandActionGatePayload
|
|
216
|
-
} from "./chunk-
|
|
219
|
+
} from "./chunk-RHDOQWXZ.js";
|
|
217
220
|
import "./chunk-P6GMCCAT.js";
|
|
218
221
|
import "./chunk-ZNFJWEN4.js";
|
|
219
|
-
import "./chunk-
|
|
222
|
+
import "./chunk-A6FNUMCF.js";
|
|
220
223
|
import "./chunk-GMZLP5DV.js";
|
|
221
224
|
import "./chunk-I4A26N52.js";
|
|
222
225
|
import "./chunk-5ZUL4CUO.js";
|
|
@@ -228,7 +231,7 @@ import {
|
|
|
228
231
|
buildIdentityBlock,
|
|
229
232
|
buildRuntimeGuidanceBlocks,
|
|
230
233
|
resolveToolGuidedSections
|
|
231
|
-
} from "./chunk-
|
|
234
|
+
} from "./chunk-JLQKV2ZJ.js";
|
|
232
235
|
import "./chunk-PUOC4YRO.js";
|
|
233
236
|
import "./chunk-RGNEEJ3Y.js";
|
|
234
237
|
import {
|
|
@@ -4311,10 +4314,10 @@ function findAgentCatalogEntry(entries, rawTarget) {
|
|
|
4311
4314
|
}
|
|
4312
4315
|
|
|
4313
4316
|
// packages/cli/tui/pasteImage.ts
|
|
4314
|
-
import { readFileSync, statSync } from "node:fs";
|
|
4317
|
+
import { readFileSync, statSync as statSync2 } from "node:fs";
|
|
4315
4318
|
import { readFile, stat } from "node:fs/promises";
|
|
4316
|
-
import { homedir } from "node:os";
|
|
4317
|
-
import { isAbsolute, resolve } from "node:path";
|
|
4319
|
+
import { homedir as homedir2 } from "node:os";
|
|
4320
|
+
import { isAbsolute, resolve as resolve2 } from "node:path";
|
|
4318
4321
|
|
|
4319
4322
|
// packages/cli/tui/compressImage.ts
|
|
4320
4323
|
var MAX_IMAGE_DIMENSION = 1568;
|
|
@@ -4512,1398 +4515,1412 @@ async function compressImage(input, mime, options = {}) {
|
|
|
4512
4515
|
}
|
|
4513
4516
|
}
|
|
4514
4517
|
|
|
4515
|
-
// packages/cli/tui/
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4518
|
+
// packages/cli/tui/sessionInput.ts
|
|
4519
|
+
import { readdirSync, statSync } from "node:fs";
|
|
4520
|
+
import { homedir } from "node:os";
|
|
4521
|
+
import { resolve } from "node:path";
|
|
4522
|
+
var PASTE_TOKEN_PREFIX = "\0PASTE\0";
|
|
4523
|
+
function applyTuiInputKey(buffer, sequence, key = {}, cursorPos, options) {
|
|
4524
|
+
const seq = sequence ?? "";
|
|
4525
|
+
const curPos = Math.max(0, Math.min(buffer.length, cursorPos ?? buffer.length));
|
|
4526
|
+
const pasteStore = options?.pasteStore;
|
|
4527
|
+
if (seq.startsWith(PASTE_TOKEN_PREFIX)) {
|
|
4528
|
+
const rawPayload = seq.slice(PASTE_TOKEN_PREFIX.length);
|
|
4529
|
+
const normalized = rawPayload.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
4530
|
+
const insertAt2 = snapCursorOutsidePasteChip(buffer, curPos);
|
|
4531
|
+
if (pasteStore && shouldCollapsePaste(normalized)) {
|
|
4532
|
+
const { placeholder } = allocateCollapsedPaste(pasteStore, normalized);
|
|
4533
|
+
const nextBuf3 = buffer.slice(0, insertAt2) + placeholder + buffer.slice(insertAt2);
|
|
4534
|
+
return { buffer: nextBuf3, cursorPos: insertAt2 + placeholder.length };
|
|
4535
|
+
}
|
|
4536
|
+
const nextBuf2 = buffer.slice(0, insertAt2) + normalized + buffer.slice(insertAt2);
|
|
4537
|
+
return { buffer: nextBuf2, cursorPos: insertAt2 + normalized.length };
|
|
4534
4538
|
}
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
const slash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
4538
|
-
const base = slash >= 0 ? path.slice(slash + 1) : path;
|
|
4539
|
-
const dot = base.lastIndexOf(".");
|
|
4540
|
-
if (dot <= 0) return "";
|
|
4541
|
-
return base.slice(dot + 1).toLowerCase();
|
|
4542
|
-
}
|
|
4543
|
-
function basenameOf(path) {
|
|
4544
|
-
const slash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
4545
|
-
return slash >= 0 ? path.slice(slash + 1) : path;
|
|
4546
|
-
}
|
|
4547
|
-
function isWslEnvironment() {
|
|
4548
|
-
if (process.env.WSL_DISTRO_NAME) return true;
|
|
4549
|
-
try {
|
|
4550
|
-
const version2 = readFileSync("/proc/version", "utf8");
|
|
4551
|
-
return /microsoft/i.test(version2);
|
|
4552
|
-
} catch {
|
|
4553
|
-
return false;
|
|
4539
|
+
if (seq === "" || key.ctrl && key.name === "c") {
|
|
4540
|
+
return { buffer, cursorPos: curPos, abort: true };
|
|
4554
4541
|
}
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
function mapWindowsPathToWsl(rawPath) {
|
|
4558
|
-
const m = WINDOWS_DRIVE_RE.exec(rawPath);
|
|
4559
|
-
if (!m) return rawPath;
|
|
4560
|
-
const drive = m[1].toLowerCase();
|
|
4561
|
-
const rest = m[2].replace(/[\\/]+/g, "/");
|
|
4562
|
-
return `/mnt/${drive}/${rest}`.replace(/\/+/g, "/");
|
|
4563
|
-
}
|
|
4564
|
-
function fileUriToPath(rawPath) {
|
|
4565
|
-
if (!/^file:\/\//i.test(rawPath)) return null;
|
|
4566
|
-
const rest = rawPath.slice("file://".length);
|
|
4567
|
-
const slash = rest.indexOf("/");
|
|
4568
|
-
if (slash < 0) return null;
|
|
4569
|
-
const pathPart = rest.slice(slash);
|
|
4570
|
-
try {
|
|
4571
|
-
return decodeURIComponent(pathPart);
|
|
4572
|
-
} catch {
|
|
4573
|
-
return pathPart;
|
|
4542
|
+
if (seq === "\f" || key.ctrl && key.name === "l") {
|
|
4543
|
+
return { buffer, cursorPos: curPos, redraw: true };
|
|
4574
4544
|
}
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
let candidate = rawPath.trim();
|
|
4578
|
-
if (!candidate) return candidate;
|
|
4579
|
-
if (candidate === "~") return homedir();
|
|
4580
|
-
if (candidate.startsWith("~/") || candidate.startsWith("~\\")) {
|
|
4581
|
-
return homedir() + candidate.slice(1);
|
|
4545
|
+
if (seq === "" || key.ctrl && key.name === "o") {
|
|
4546
|
+
return { buffer, cursorPos: curPos };
|
|
4582
4547
|
}
|
|
4583
|
-
if (
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
return IMAGE_EXTENSION_SET.has(extnameOf(path));
|
|
4588
|
-
}
|
|
4589
|
-
function isReadableFilePath(path) {
|
|
4590
|
-
try {
|
|
4591
|
-
statSync(path);
|
|
4592
|
-
return true;
|
|
4593
|
-
} catch {
|
|
4594
|
-
return false;
|
|
4548
|
+
if (seq === "\x1B[13;2~" || seq === "\x1B[27;2;13~" || seq === "\x1B\r" || key.shift && (key.name === "enter" || key.name === "return") || seq === "\n" || key.ctrl && key.name === "j") {
|
|
4549
|
+
const insertAt2 = snapCursorOutsidePasteChip(buffer, curPos);
|
|
4550
|
+
const nextBuf2 = buffer.slice(0, insertAt2) + "\n" + buffer.slice(insertAt2);
|
|
4551
|
+
return { buffer: nextBuf2, cursorPos: insertAt2 + 1 };
|
|
4595
4552
|
}
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
let candidate = token.decoded;
|
|
4604
|
-
const uriPath = fileUriToPath(candidate);
|
|
4605
|
-
if (uriPath !== null) candidate = uriPath;
|
|
4606
|
-
if (wsl) candidate = mapWindowsPathToWsl(candidate);
|
|
4607
|
-
const resolved = resolveImageSource(candidate, cwd);
|
|
4608
|
-
if (!isImagePath(resolved)) continue;
|
|
4609
|
-
if (!isReadableFilePath(resolved)) {
|
|
4610
|
-
out.push({ raw: token.raw, resolvedPath: resolved, unreadable: true });
|
|
4611
|
-
continue;
|
|
4553
|
+
if (key.name === "enter" || key.name === "return" || seq === "\r") {
|
|
4554
|
+
return { buffer: "", cursorPos: 0, submit: buffer };
|
|
4555
|
+
}
|
|
4556
|
+
if (isLeftArrowSequence(seq, key)) {
|
|
4557
|
+
const span = findCollapsedPasteSpanAt(buffer, curPos, { preferLeft: true });
|
|
4558
|
+
if (span && curPos > span.start && curPos <= span.end) {
|
|
4559
|
+
return { buffer, cursorPos: span.start };
|
|
4612
4560
|
}
|
|
4613
|
-
|
|
4561
|
+
return { buffer, cursorPos: Math.max(0, curPos - 1) };
|
|
4614
4562
|
}
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
const excluded = new Set(opts.exclude ?? []);
|
|
4620
|
-
const out = [];
|
|
4621
|
-
const seen = /* @__PURE__ */ new Set();
|
|
4622
|
-
for (const token of tokenizePasteLine(line)) {
|
|
4623
|
-
if (!token.raw || excluded.has(token.raw)) continue;
|
|
4624
|
-
let candidate = token.decoded;
|
|
4625
|
-
const uriPath = fileUriToPath(candidate);
|
|
4626
|
-
if (uriPath !== null) candidate = uriPath;
|
|
4627
|
-
if (wsl) candidate = mapWindowsPathToWsl(candidate);
|
|
4628
|
-
if (candidate.startsWith("~")) candidate = resolveImageSource(candidate, cwd);
|
|
4629
|
-
const looksLikePath = /[/\\]/.test(candidate) || candidate.startsWith("~") || /^[a-zA-Z]:/.test(candidate);
|
|
4630
|
-
if (!looksLikePath) continue;
|
|
4631
|
-
const ext = extnameOf(candidate);
|
|
4632
|
-
if (!/^[a-z0-9]{1,8}$/.test(ext)) continue;
|
|
4633
|
-
if (IMAGE_EXTENSION_SET.has(ext)) continue;
|
|
4634
|
-
const resolved = resolveImageSource(candidate, cwd);
|
|
4635
|
-
if (excluded.has(resolved) || seen.has(resolved)) continue;
|
|
4636
|
-
if (!isReadableFilePath(resolved)) continue;
|
|
4637
|
-
try {
|
|
4638
|
-
if (!statSync(resolved).isFile()) continue;
|
|
4639
|
-
} catch {
|
|
4640
|
-
continue;
|
|
4563
|
+
if (isRightArrowSequence(seq, key)) {
|
|
4564
|
+
const span = findCollapsedPasteSpanAt(buffer, curPos);
|
|
4565
|
+
if (span && curPos >= span.start && curPos < span.end) {
|
|
4566
|
+
return { buffer, cursorPos: span.end };
|
|
4641
4567
|
}
|
|
4642
|
-
|
|
4643
|
-
out.push({ raw: token.raw, resolvedPath: resolved });
|
|
4568
|
+
return { buffer, cursorPos: Math.min(buffer.length, curPos + 1) };
|
|
4644
4569
|
}
|
|
4645
|
-
|
|
4646
|
-
}
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4570
|
+
if (isHomeSequence(seq, key)) {
|
|
4571
|
+
return { buffer, cursorPos: 0 };
|
|
4572
|
+
}
|
|
4573
|
+
if (isEndSequence(seq, key)) {
|
|
4574
|
+
return { buffer, cursorPos: buffer.length };
|
|
4575
|
+
}
|
|
4576
|
+
if (isDeleteWordSequence(seq, key)) {
|
|
4577
|
+
if (curPos === 0) return { buffer, cursorPos: curPos };
|
|
4578
|
+
const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos, {
|
|
4579
|
+
preferLeft: true
|
|
4580
|
+
});
|
|
4581
|
+
if (pasteSpan && (curPos === pasteSpan.end || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
|
|
4582
|
+
return removePasteSpan(buffer, pasteSpan, pasteStore);
|
|
4657
4583
|
}
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
if (
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4584
|
+
const cutIdx = findWordStartLeft(buffer, curPos);
|
|
4585
|
+
return deleteBufferRange(buffer, cutIdx, curPos, pasteStore);
|
|
4586
|
+
}
|
|
4587
|
+
if (isKillToLineStartSequence(seq, key)) {
|
|
4588
|
+
if (curPos === 0) return { buffer, cursorPos: curPos };
|
|
4589
|
+
const lineStart = buffer.lastIndexOf("\n", curPos - 1) + 1;
|
|
4590
|
+
return deleteBufferRange(buffer, lineStart, curPos, pasteStore);
|
|
4591
|
+
}
|
|
4592
|
+
if (isKillToLineEndSequence(seq, key)) {
|
|
4593
|
+
const nlIdx = buffer.indexOf("\n", curPos);
|
|
4594
|
+
const lineEnd = nlIdx === -1 ? buffer.length : nlIdx;
|
|
4595
|
+
return deleteBufferRange(buffer, curPos, lineEnd, pasteStore);
|
|
4596
|
+
}
|
|
4597
|
+
if (isBackspaceSequence(seq, key)) {
|
|
4598
|
+
if (curPos > 0) {
|
|
4599
|
+
const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos, {
|
|
4600
|
+
preferLeft: true
|
|
4601
|
+
});
|
|
4602
|
+
if (pasteSpan && (curPos === pasteSpan.end || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
|
|
4603
|
+
return removePasteSpan(buffer, pasteSpan, pasteStore);
|
|
4673
4604
|
}
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
continue;
|
|
4677
|
-
}
|
|
4678
|
-
if (ch === "\\" && next !== void 0 && /\s/.test(next)) {
|
|
4679
|
-
rawBuf += ch + next;
|
|
4680
|
-
decBuf += next;
|
|
4681
|
-
i++;
|
|
4682
|
-
continue;
|
|
4605
|
+
const nextBuf2 = buffer.slice(0, curPos - 1) + buffer.slice(curPos);
|
|
4606
|
+
return { buffer: nextBuf2, cursorPos: curPos - 1 };
|
|
4683
4607
|
}
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4608
|
+
return { buffer, cursorPos: curPos };
|
|
4609
|
+
}
|
|
4610
|
+
if (isForwardDeleteSequence(seq, key)) {
|
|
4611
|
+
if (curPos < buffer.length) {
|
|
4612
|
+
const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos);
|
|
4613
|
+
if (pasteSpan && (curPos === pasteSpan.start || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
|
|
4614
|
+
return removePasteSpan(buffer, pasteSpan, pasteStore);
|
|
4615
|
+
}
|
|
4616
|
+
const nextBuf2 = buffer.slice(0, curPos) + buffer.slice(curPos + 1);
|
|
4617
|
+
return { buffer: nextBuf2, cursorPos: curPos };
|
|
4689
4618
|
}
|
|
4690
|
-
if (
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
continue;
|
|
4619
|
+
if (curPos > 0) {
|
|
4620
|
+
const nextBuf2 = buffer.slice(0, curPos - 1);
|
|
4621
|
+
return { buffer: nextBuf2, cursorPos: curPos - 1 };
|
|
4694
4622
|
}
|
|
4695
|
-
|
|
4696
|
-
push();
|
|
4697
|
-
continue;
|
|
4698
|
-
}
|
|
4699
|
-
rawBuf += ch;
|
|
4700
|
-
decBuf += ch;
|
|
4701
|
-
}
|
|
4702
|
-
push();
|
|
4703
|
-
return tokens;
|
|
4704
|
-
}
|
|
4705
|
-
async function readImageAsDataUrl(absolutePath, options = {}) {
|
|
4706
|
-
const maxBytes = options.maxBytes ?? DEFAULT_MAX_IMAGE_BYTES;
|
|
4707
|
-
let stats;
|
|
4708
|
-
try {
|
|
4709
|
-
stats = await stat(absolutePath);
|
|
4710
|
-
} catch (error) {
|
|
4711
|
-
throw classifyFsError(error, absolutePath);
|
|
4712
|
-
}
|
|
4713
|
-
if (stats.isDirectory()) {
|
|
4714
|
-
throw new ImageReadError(
|
|
4715
|
-
"is-directory",
|
|
4716
|
-
absolutePath,
|
|
4717
|
-
`path is a directory, not an image: ${absolutePath}`
|
|
4718
|
-
);
|
|
4719
|
-
}
|
|
4720
|
-
const ext = extnameOf(absolutePath);
|
|
4721
|
-
if (!ext || !IMAGE_EXTENSION_SET.has(ext)) {
|
|
4722
|
-
throw new ImageReadError(
|
|
4723
|
-
"unsupported-extension",
|
|
4724
|
-
absolutePath,
|
|
4725
|
-
`unsupported image extension: .${ext || "(none)"}`
|
|
4726
|
-
);
|
|
4623
|
+
return { buffer, cursorPos: curPos };
|
|
4727
4624
|
}
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4625
|
+
if (seq === " " || key.name === "tab") {
|
|
4626
|
+
if (options?.cwd) {
|
|
4627
|
+
const pathCandidates = completeSlashCommand(buffer, options.cwd);
|
|
4628
|
+
if (pathCandidates.length === 1) {
|
|
4629
|
+
const [only] = pathCandidates;
|
|
4630
|
+
return { buffer: only, cursorPos: only.length };
|
|
4631
|
+
}
|
|
4632
|
+
if (pathCandidates.length > 1) {
|
|
4633
|
+
return { buffer, cursorPos: curPos };
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
const completed = completeSlashPrefix(buffer) ?? buffer;
|
|
4637
|
+
return { buffer: completed, cursorPos: completed.length };
|
|
4733
4638
|
}
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
const finalBuffer = compressResult.buffer;
|
|
4737
|
-
const finalMime = compressResult.mime;
|
|
4738
|
-
const finalSizeBytes = finalBuffer.byteLength;
|
|
4739
|
-
if (finalSizeBytes > maxBytes) {
|
|
4740
|
-
throw new ImageReadError(
|
|
4741
|
-
"too-large",
|
|
4742
|
-
absolutePath,
|
|
4743
|
-
`image too large: ${formatBytes(finalSizeBytes)} (limit ${formatBytes(maxBytes)})`
|
|
4744
|
-
);
|
|
4639
|
+
if (!seq || key.ctrl || key.meta || seq.startsWith("\x1B")) {
|
|
4640
|
+
return { buffer, cursorPos: curPos };
|
|
4745
4641
|
}
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
filename: basenameOf(absolutePath),
|
|
4750
|
-
sourcePath: absolutePath,
|
|
4751
|
-
originalSizeBytes: compressResult.compressed ? compressResult.originalBytes : void 0
|
|
4752
|
-
});
|
|
4642
|
+
const insertAt = snapCursorOutsidePasteChip(buffer, curPos);
|
|
4643
|
+
const nextBuf = buffer.slice(0, insertAt) + seq + buffer.slice(insertAt);
|
|
4644
|
+
return { buffer: nextBuf, cursorPos: insertAt + seq.length };
|
|
4753
4645
|
}
|
|
4754
|
-
function
|
|
4755
|
-
const
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
case "ENOENT":
|
|
4759
|
-
return new ImageReadError("not-found", path, `image not found: ${path}`);
|
|
4760
|
-
case "EACCES":
|
|
4761
|
-
case "EPERM":
|
|
4762
|
-
return new ImageReadError(
|
|
4763
|
-
"permission-denied",
|
|
4764
|
-
path,
|
|
4765
|
-
`cannot read image (permission denied): ${path}`
|
|
4766
|
-
);
|
|
4767
|
-
case "EISDIR":
|
|
4768
|
-
return new ImageReadError(
|
|
4769
|
-
"is-directory",
|
|
4770
|
-
path,
|
|
4771
|
-
`path is a directory, not an image: ${path}`
|
|
4772
|
-
);
|
|
4773
|
-
default:
|
|
4774
|
-
return new ImageReadError("io-error", path, `failed to read image: ${message}`);
|
|
4775
|
-
}
|
|
4646
|
+
function snapCursorOutsidePasteChip(buffer, pos) {
|
|
4647
|
+
const span = findCollapsedPasteSpanAt(buffer, pos);
|
|
4648
|
+
if (span && pos > span.start && pos < span.end) return span.end;
|
|
4649
|
+
return pos;
|
|
4776
4650
|
}
|
|
4777
|
-
function
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
return {
|
|
4782
|
-
dataUrl,
|
|
4783
|
-
mime: params.mime,
|
|
4784
|
-
filename: params.filename,
|
|
4785
|
-
sizeBytes,
|
|
4786
|
-
sourcePath: params.sourcePath,
|
|
4787
|
-
...typeof params.originalSizeBytes === "number" && params.originalSizeBytes > sizeBytes ? { originalSizeBytes: params.originalSizeBytes } : {}
|
|
4788
|
-
};
|
|
4651
|
+
function isLeftArrowSequence(seq, key) {
|
|
4652
|
+
if (key.name === "left") return true;
|
|
4653
|
+
if (seq === "\x1B[D" || seq === "\x1B[1;2D" || seq === "\x1B[1;5D" || seq === "\x1BOD") return true;
|
|
4654
|
+
return false;
|
|
4789
4655
|
}
|
|
4790
|
-
function
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
return
|
|
4656
|
+
function isRightArrowSequence(seq, key) {
|
|
4657
|
+
if (key.name === "right") return true;
|
|
4658
|
+
if (seq === "\x1B[C" || seq === "\x1B[1;2C" || seq === "\x1B[1;5C" || seq === "\x1BOC") return true;
|
|
4659
|
+
return false;
|
|
4794
4660
|
}
|
|
4795
|
-
function
|
|
4796
|
-
if (
|
|
4797
|
-
if (
|
|
4798
|
-
|
|
4661
|
+
function isHomeSequence(seq, key) {
|
|
4662
|
+
if (key.name === "home") return true;
|
|
4663
|
+
if (key.ctrl && key.name === "a") return true;
|
|
4664
|
+
if (seq === "" || seq === "\x1B[H" || seq === "\x1B[1~" || seq === "\x1B[7~" || seq === "\x1BOH") return true;
|
|
4665
|
+
return false;
|
|
4799
4666
|
}
|
|
4800
|
-
function
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
const boxWidth = Math.max(40, titleRaw.length + 4, nameRaw.length + 4, sizeText.length + 4);
|
|
4806
|
-
const border = "\u250C" + "\u2500".repeat(boxWidth - 2) + "\u2510";
|
|
4807
|
-
const bottom = "\u2514" + "\u2500".repeat(boxWidth - 2) + "\u2518";
|
|
4808
|
-
const padLine = (content) => {
|
|
4809
|
-
const padded = content.padEnd(boxWidth - 4, " ");
|
|
4810
|
-
return `\u2502 ${padded} \u2502`;
|
|
4811
|
-
};
|
|
4812
|
-
const title = padLine(titleRaw);
|
|
4813
|
-
const name = padLine(nameRaw);
|
|
4814
|
-
const size = padLine(sizeText);
|
|
4815
|
-
const text = [
|
|
4816
|
-
border,
|
|
4817
|
-
title,
|
|
4818
|
-
name,
|
|
4819
|
-
size,
|
|
4820
|
-
bottom
|
|
4821
|
-
].join("\n");
|
|
4822
|
-
return themeText(text, "chrome", colorEnabled);
|
|
4667
|
+
function isEndSequence(seq, key) {
|
|
4668
|
+
if (key.name === "end") return true;
|
|
4669
|
+
if (key.ctrl && key.name === "e") return true;
|
|
4670
|
+
if (seq === "" || seq === "\x1B[F" || seq === "\x1B[4~" || seq === "\x1B[8~" || seq === "\x1BOF") return true;
|
|
4671
|
+
return false;
|
|
4823
4672
|
}
|
|
4824
|
-
function
|
|
4825
|
-
if (
|
|
4826
|
-
const
|
|
4827
|
-
|
|
4828
|
-
return extra > 0 ? `${head.join(", ")} +${extra}` : head.join(", ");
|
|
4673
|
+
function removePasteSpan(buffer, span, pasteStore) {
|
|
4674
|
+
if (pasteStore) releaseCollapsedPaste(pasteStore, span.id);
|
|
4675
|
+
const nextBuf = buffer.slice(0, span.start) + buffer.slice(span.end);
|
|
4676
|
+
return { buffer: nextBuf, cursorPos: span.start };
|
|
4829
4677
|
}
|
|
4830
|
-
function
|
|
4831
|
-
if (
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
};
|
|
4678
|
+
function deleteBufferRange(buffer, start, end, pasteStore) {
|
|
4679
|
+
if (start >= end) return { buffer, cursorPos: start };
|
|
4680
|
+
const range = expandRangeToCollapsedPasteChips(buffer, start, end);
|
|
4681
|
+
releasePastesInRange(buffer, range.start, range.end, pasteStore);
|
|
4682
|
+
const nextBuf = buffer.slice(0, range.start) + buffer.slice(range.end);
|
|
4683
|
+
return { buffer: nextBuf, cursorPos: range.start };
|
|
4837
4684
|
}
|
|
4838
|
-
function
|
|
4839
|
-
if (
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
for (const img of existing) {
|
|
4846
|
-
if (seen.has(img.sourcePath)) continue;
|
|
4847
|
-
const override = incomingByPath.get(img.sourcePath);
|
|
4848
|
-
out.push(override ?? img);
|
|
4849
|
-
seen.add(img.sourcePath);
|
|
4850
|
-
}
|
|
4851
|
-
for (const img of incoming) {
|
|
4852
|
-
if (seen.has(img.sourcePath)) continue;
|
|
4853
|
-
out.push(img);
|
|
4854
|
-
seen.add(img.sourcePath);
|
|
4685
|
+
function releasePastesInRange(buffer, start, end, pasteStore) {
|
|
4686
|
+
if (!pasteStore || start >= end) return;
|
|
4687
|
+
const slice = buffer.slice(start, end);
|
|
4688
|
+
COLLAPSED_PASTE_PLACEHOLDER_RE.lastIndex = 0;
|
|
4689
|
+
let match;
|
|
4690
|
+
while ((match = COLLAPSED_PASTE_PLACEHOLDER_RE.exec(slice)) !== null) {
|
|
4691
|
+
releaseCollapsedPaste(pasteStore, Number(match[1]));
|
|
4855
4692
|
}
|
|
4856
|
-
return out;
|
|
4857
4693
|
}
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
});
|
|
4869
|
-
images.push(img);
|
|
4870
|
-
options.onSuccess?.(img);
|
|
4871
|
-
} catch (error) {
|
|
4872
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
4873
|
-
if (!reportedFailures.has(absolute)) {
|
|
4874
|
-
reportedFailures.add(absolute);
|
|
4875
|
-
failures.push(absolute);
|
|
4876
|
-
options.onFailure?.(absolute, err);
|
|
4877
|
-
}
|
|
4878
|
-
}
|
|
4694
|
+
var CJK_CHAR = /[\u4e00-\u9fff\u3000-\u303f\uff00-\uffef]/;
|
|
4695
|
+
function findWordStartLeft(buffer, curPos) {
|
|
4696
|
+
let i = curPos;
|
|
4697
|
+
while (i > 0 && /\s/.test(buffer[i - 1])) i--;
|
|
4698
|
+
if (i === 0) return 0;
|
|
4699
|
+
const spanAtCursor = findCollapsedPasteSpanAt(buffer, i, {
|
|
4700
|
+
preferLeft: true
|
|
4701
|
+
});
|
|
4702
|
+
if (spanAtCursor && (i === spanAtCursor.end || i > spanAtCursor.start && i < spanAtCursor.end)) {
|
|
4703
|
+
return spanAtCursor.start;
|
|
4879
4704
|
}
|
|
4880
|
-
return
|
|
4705
|
+
if (CJK_CHAR.test(buffer[i - 1])) return i - 1;
|
|
4706
|
+
while (i > 0 && !/\s/.test(buffer[i - 1]) && !CJK_CHAR.test(buffer[i - 1])) {
|
|
4707
|
+
const span = findCollapsedPasteSpanAt(buffer, i, { preferLeft: true });
|
|
4708
|
+
if (span && i === span.end) break;
|
|
4709
|
+
i--;
|
|
4710
|
+
}
|
|
4711
|
+
return i;
|
|
4881
4712
|
}
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4713
|
+
function isDeleteWordSequence(seq, key) {
|
|
4714
|
+
if (key.ctrl && key.name === "w") return true;
|
|
4715
|
+
if ((key.ctrl || key.meta) && key.name === "backspace") return true;
|
|
4716
|
+
if (seq === "" || seq === "\x1B\x7F") return true;
|
|
4717
|
+
return false;
|
|
4718
|
+
}
|
|
4719
|
+
function isKillToLineStartSequence(seq, key) {
|
|
4720
|
+
if (key.ctrl && key.name === "u") return true;
|
|
4721
|
+
if (seq === "") return true;
|
|
4722
|
+
return false;
|
|
4723
|
+
}
|
|
4724
|
+
function isKillToLineEndSequence(seq, key) {
|
|
4725
|
+
if (key.ctrl && key.name === "k") return true;
|
|
4726
|
+
if (seq === "\v") return true;
|
|
4727
|
+
return false;
|
|
4728
|
+
}
|
|
4729
|
+
function isBackspaceSequence(seq, key) {
|
|
4730
|
+
if (key.name === "backspace") return true;
|
|
4731
|
+
if (seq === "\b" || seq === "\x7F") return true;
|
|
4732
|
+
return /^\x1b\[27;\d+;8~$/.test(seq);
|
|
4733
|
+
}
|
|
4734
|
+
function isForwardDeleteSequence(seq, key) {
|
|
4735
|
+
if (key.name === "delete") return true;
|
|
4736
|
+
return /^\x1b\[3(?:;\d+)*~$/.test(seq);
|
|
4737
|
+
}
|
|
4738
|
+
var SLASH_COMMANDS = [
|
|
4739
|
+
"/help",
|
|
4740
|
+
"/new",
|
|
4741
|
+
"/clear",
|
|
4742
|
+
"/compact",
|
|
4743
|
+
"/theme",
|
|
4744
|
+
"/context",
|
|
4745
|
+
"/ctx",
|
|
4746
|
+
"/credits",
|
|
4747
|
+
"/links",
|
|
4748
|
+
"/cd",
|
|
4749
|
+
"/runtime",
|
|
4750
|
+
"/auto",
|
|
4751
|
+
"/switch",
|
|
4752
|
+
"/agent",
|
|
4753
|
+
"/agents",
|
|
4754
|
+
"/history",
|
|
4755
|
+
"/resume",
|
|
4756
|
+
"/lang",
|
|
4757
|
+
"/copy",
|
|
4758
|
+
"/paste",
|
|
4759
|
+
"/mouse",
|
|
4760
|
+
"/math",
|
|
4761
|
+
"/doc",
|
|
4762
|
+
"/skill",
|
|
4763
|
+
"/customize",
|
|
4764
|
+
"/login",
|
|
4765
|
+
"/profile",
|
|
4766
|
+
"/update",
|
|
4767
|
+
"/version",
|
|
4768
|
+
"/logs",
|
|
4769
|
+
"/tasks",
|
|
4770
|
+
"/jobs",
|
|
4771
|
+
"/procs",
|
|
4772
|
+
"/stop",
|
|
4773
|
+
"/exit",
|
|
4774
|
+
"/quit"
|
|
4775
|
+
];
|
|
4776
|
+
function completeSlashPrefix(buffer) {
|
|
4777
|
+
if (!buffer.startsWith("/") || /\s/.test(buffer)) return null;
|
|
4778
|
+
const matches = SLASH_COMMANDS.filter((cmd) => cmd.startsWith(buffer));
|
|
4779
|
+
if (matches.length === 0) return null;
|
|
4780
|
+
if (matches.length === 1) {
|
|
4781
|
+
return `${matches[0]} `;
|
|
4897
4782
|
}
|
|
4898
|
-
|
|
4783
|
+
let prefix = matches[0];
|
|
4784
|
+
for (const cmd of matches) {
|
|
4785
|
+
while (!cmd.startsWith(prefix)) prefix = prefix.slice(0, -1);
|
|
4786
|
+
}
|
|
4787
|
+
return prefix.length > buffer.length ? prefix : null;
|
|
4788
|
+
}
|
|
4789
|
+
function completeSlashCommand(buffer, cwd) {
|
|
4790
|
+
if (!buffer.startsWith("/")) return [];
|
|
4791
|
+
const trimmed = buffer.trim();
|
|
4792
|
+
if (cwd && buffer.startsWith("/cd ")) {
|
|
4793
|
+
const prefix = buffer.slice("/cd ".length);
|
|
4794
|
+
return completeCdPathCandidates(prefix, cwd);
|
|
4795
|
+
}
|
|
4796
|
+
if (trimmed.includes(" ")) return [];
|
|
4797
|
+
return SLASH_COMMANDS.filter((cmd) => cmd.startsWith(trimmed) && cmd !== trimmed);
|
|
4798
|
+
}
|
|
4799
|
+
function completeCdPathCandidates(prefix, cwd) {
|
|
4800
|
+
const lastSlash = prefix.lastIndexOf("/");
|
|
4801
|
+
const head = lastSlash >= 0 ? prefix.slice(0, lastSlash + 1) : "";
|
|
4802
|
+
const baseName = lastSlash >= 0 ? prefix.slice(lastSlash + 1) : prefix;
|
|
4803
|
+
let dirPath;
|
|
4804
|
+
if (head === "~" || head === "~/" || head === "~\\") {
|
|
4805
|
+
dirPath = homedir();
|
|
4806
|
+
} else if (head.startsWith("~/") || head.startsWith("~\\")) {
|
|
4807
|
+
dirPath = resolve(homedir(), head.slice(2));
|
|
4808
|
+
} else {
|
|
4809
|
+
dirPath = head.startsWith("/") ? head : resolve(cwd, head);
|
|
4810
|
+
}
|
|
4811
|
+
let entries;
|
|
4812
|
+
try {
|
|
4813
|
+
entries = readdirSync(dirPath, { withFileTypes: true });
|
|
4814
|
+
} catch {
|
|
4815
|
+
return [];
|
|
4816
|
+
}
|
|
4817
|
+
const hiddenRequested = baseName.startsWith(".");
|
|
4818
|
+
const names = entries.filter((e) => {
|
|
4819
|
+
if (e.isDirectory()) return true;
|
|
4820
|
+
if (!e.isSymbolicLink()) return false;
|
|
4821
|
+
try {
|
|
4822
|
+
return statSync(resolve(dirPath, e.name)).isDirectory();
|
|
4823
|
+
} catch {
|
|
4824
|
+
return false;
|
|
4825
|
+
}
|
|
4826
|
+
}).map((e) => e.name).filter((name) => {
|
|
4827
|
+
if (!name.startsWith(baseName)) return false;
|
|
4828
|
+
return hiddenRequested || !name.startsWith(".");
|
|
4829
|
+
}).sort();
|
|
4830
|
+
return names.map((name) => `/cd ${head}${name}/`);
|
|
4831
|
+
}
|
|
4832
|
+
function isLikelySlashCommand(input) {
|
|
4833
|
+
const trimmed = input.trim();
|
|
4834
|
+
if (!trimmed.startsWith("/")) return false;
|
|
4835
|
+
const spaceIdx = trimmed.search(/\s/);
|
|
4836
|
+
const firstToken = spaceIdx === -1 ? trimmed : trimmed.slice(0, spaceIdx);
|
|
4837
|
+
return /^\/[a-zA-Z_][a-zA-Z0-9._:-]*$/.test(firstToken);
|
|
4838
|
+
}
|
|
4839
|
+
function stripImageTokens(input, hints) {
|
|
4840
|
+
if (hints.length === 0) return input;
|
|
4841
|
+
let out = input;
|
|
4842
|
+
for (const hint of hints) {
|
|
4843
|
+
if (!hint.raw) continue;
|
|
4844
|
+
const escaped = hint.raw.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4845
|
+
out = out.replace(new RegExp(escaped, "g"), "");
|
|
4846
|
+
}
|
|
4847
|
+
return compactWhitespace(out);
|
|
4899
4848
|
}
|
|
4900
4849
|
|
|
4901
|
-
// packages/cli/tui/
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4850
|
+
// packages/cli/tui/pasteImage.ts
|
|
4851
|
+
var IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "gif", "webp"];
|
|
4852
|
+
var IMAGE_EXTENSION_SET = new Set(IMAGE_EXTENSIONS.map((ext) => ext.toLowerCase()));
|
|
4853
|
+
var MIME_BY_EXTENSION = {
|
|
4854
|
+
png: "image/png",
|
|
4855
|
+
jpg: "image/jpeg",
|
|
4856
|
+
jpeg: "image/jpeg",
|
|
4857
|
+
gif: "image/gif",
|
|
4858
|
+
webp: "image/webp"
|
|
4859
|
+
};
|
|
4860
|
+
var DEFAULT_MAX_IMAGE_BYTES = 4 * 1024 * 1024;
|
|
4861
|
+
var ImageReadError = class extends Error {
|
|
4908
4862
|
code;
|
|
4909
|
-
|
|
4863
|
+
path;
|
|
4864
|
+
constructor(code, path, message) {
|
|
4910
4865
|
super(message);
|
|
4911
4866
|
this.code = code;
|
|
4912
|
-
this.
|
|
4867
|
+
this.path = path;
|
|
4868
|
+
this.name = "ImageReadError";
|
|
4913
4869
|
}
|
|
4914
4870
|
};
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
|
|
4918
|
-
|
|
4871
|
+
function extnameOf(path) {
|
|
4872
|
+
const slash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
4873
|
+
const base = slash >= 0 ? path.slice(slash + 1) : path;
|
|
4874
|
+
const dot = base.lastIndexOf(".");
|
|
4875
|
+
if (dot <= 0) return "";
|
|
4876
|
+
return base.slice(dot + 1).toLowerCase();
|
|
4919
4877
|
}
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4878
|
+
function basenameOf(path) {
|
|
4879
|
+
const slash = Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\"));
|
|
4880
|
+
return slash >= 0 ? path.slice(slash + 1) : path;
|
|
4881
|
+
}
|
|
4882
|
+
function isWslEnvironment() {
|
|
4883
|
+
if (process.env.WSL_DISTRO_NAME) return true;
|
|
4923
4884
|
try {
|
|
4924
|
-
const
|
|
4925
|
-
|
|
4926
|
-
const entries = await readdir(tempDir);
|
|
4927
|
-
let removed = 0;
|
|
4928
|
-
for (const name of entries) {
|
|
4929
|
-
if (!CLIPBOARD_SWEEP_FILE_RE.test(name)) continue;
|
|
4930
|
-
try {
|
|
4931
|
-
const fullPath = join(tempDir, name);
|
|
4932
|
-
const stats = await stat2(fullPath);
|
|
4933
|
-
if (stats.mtimeMs >= now - maxAgeMs) continue;
|
|
4934
|
-
await unlink(fullPath);
|
|
4935
|
-
removed += 1;
|
|
4936
|
-
} catch {
|
|
4937
|
-
}
|
|
4938
|
-
}
|
|
4939
|
-
return removed;
|
|
4885
|
+
const version2 = readFileSync("/proc/version", "utf8");
|
|
4886
|
+
return /microsoft/i.test(version2);
|
|
4940
4887
|
} catch {
|
|
4941
|
-
return
|
|
4888
|
+
return false;
|
|
4942
4889
|
}
|
|
4943
4890
|
}
|
|
4944
|
-
|
|
4945
|
-
|
|
4891
|
+
var WINDOWS_DRIVE_RE = /^([a-zA-Z]):[\\/](.*)$/s;
|
|
4892
|
+
function mapWindowsPathToWsl(rawPath) {
|
|
4893
|
+
const m = WINDOWS_DRIVE_RE.exec(rawPath);
|
|
4894
|
+
if (!m) return rawPath;
|
|
4895
|
+
const drive = m[1].toLowerCase();
|
|
4896
|
+
const rest = m[2].replace(/[\\/]+/g, "/");
|
|
4897
|
+
return `/mnt/${drive}/${rest}`.replace(/\/+/g, "/");
|
|
4946
4898
|
}
|
|
4947
|
-
function
|
|
4948
|
-
|
|
4949
|
-
const
|
|
4950
|
-
const
|
|
4951
|
-
if (
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4899
|
+
function fileUriToPath(rawPath) {
|
|
4900
|
+
if (!/^file:\/\//i.test(rawPath)) return null;
|
|
4901
|
+
const rest = rawPath.slice("file://".length);
|
|
4902
|
+
const slash = rest.indexOf("/");
|
|
4903
|
+
if (slash < 0) return null;
|
|
4904
|
+
const pathPart = rest.slice(slash);
|
|
4905
|
+
try {
|
|
4906
|
+
return decodeURIComponent(pathPart);
|
|
4907
|
+
} catch {
|
|
4908
|
+
return pathPart;
|
|
4956
4909
|
}
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
throw new ClipboardImageError(
|
|
4965
|
-
"binary-missing",
|
|
4966
|
-
"\u672A\u627E\u5230 pngpaste\uFF0C\u4E5F\u672A\u627E\u5230\u7CFB\u7EDF\u81EA\u5E26\u7684 osascript\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u526A\u8D34\u677F\u56FE\u50CF\u3002\u8BF7\u8FD0\u884C brew install pngpaste \u5B89\u88C5\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
|
|
4967
|
-
);
|
|
4968
|
-
}
|
|
4969
|
-
return {
|
|
4970
|
-
command: [osascript, "-e", "the clipboard as \xABclass PNGf\xBB"],
|
|
4971
|
-
outputFormat: "osascript-hex"
|
|
4972
|
-
};
|
|
4910
|
+
}
|
|
4911
|
+
function resolveImageSource(rawPath, cwd) {
|
|
4912
|
+
let candidate = rawPath.trim();
|
|
4913
|
+
if (!candidate) return candidate;
|
|
4914
|
+
if (candidate === "~") return homedir2();
|
|
4915
|
+
if (candidate.startsWith("~/") || candidate.startsWith("~\\")) {
|
|
4916
|
+
return homedir2() + candidate.slice(1);
|
|
4973
4917
|
}
|
|
4974
|
-
if (
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
"-NonInteractive",
|
|
4987
|
-
"-Command",
|
|
4988
|
-
"$img = Get-Clipboard -Format Image; if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [Console]::OpenStandardOutput().Write($ms.ToArray(), 0, $ms.Length) }"
|
|
4989
|
-
],
|
|
4990
|
-
outputFormat: "raw"
|
|
4991
|
-
};
|
|
4918
|
+
if (isAbsolute(candidate)) return candidate;
|
|
4919
|
+
return resolve2(cwd, candidate);
|
|
4920
|
+
}
|
|
4921
|
+
function isImagePath(path) {
|
|
4922
|
+
return IMAGE_EXTENSION_SET.has(extnameOf(path));
|
|
4923
|
+
}
|
|
4924
|
+
function isReadableFilePath(path) {
|
|
4925
|
+
try {
|
|
4926
|
+
statSync2(path);
|
|
4927
|
+
return true;
|
|
4928
|
+
} catch {
|
|
4929
|
+
return false;
|
|
4992
4930
|
}
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
if (
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
outputFormat: "raw"
|
|
5010
|
-
};
|
|
5011
|
-
}
|
|
5012
|
-
const wlPaste = which("wl-paste");
|
|
5013
|
-
if (wlPaste) {
|
|
5014
|
-
return { command: [wlPaste, "--type", "image/png"], outputFormat: "raw" };
|
|
4931
|
+
}
|
|
4932
|
+
function detectImagePaths(line, cwd, opts = {}) {
|
|
4933
|
+
const wsl = opts.wsl ?? isWslEnvironment();
|
|
4934
|
+
const tokens = tokenizePasteLine(line);
|
|
4935
|
+
const out = [];
|
|
4936
|
+
for (const token of tokens) {
|
|
4937
|
+
if (!token.raw) continue;
|
|
4938
|
+
let candidate = token.decoded;
|
|
4939
|
+
const uriPath = fileUriToPath(candidate);
|
|
4940
|
+
if (uriPath !== null) candidate = uriPath;
|
|
4941
|
+
if (wsl) candidate = mapWindowsPathToWsl(candidate);
|
|
4942
|
+
const resolved = resolveImageSource(candidate, cwd);
|
|
4943
|
+
if (!isImagePath(resolved)) continue;
|
|
4944
|
+
if (!isReadableFilePath(resolved)) {
|
|
4945
|
+
out.push({ raw: token.raw, resolvedPath: resolved, unreadable: true });
|
|
4946
|
+
continue;
|
|
5015
4947
|
}
|
|
5016
|
-
|
|
5017
|
-
"binary-missing",
|
|
5018
|
-
"\u672A\u627E\u5230 xclip\uFF0C\u8BF7\u5B89\u88C5 xclip (\u4F8B\u5982 sudo apt install xclip)\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
|
|
5019
|
-
);
|
|
4948
|
+
out.push({ raw: token.raw, resolvedPath: resolved });
|
|
5020
4949
|
}
|
|
5021
|
-
|
|
5022
|
-
"unsupported-platform",
|
|
5023
|
-
`\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u6682\u4E0D\u652F\u6301\u526A\u8D34\u677F\u56FE\u50CF\u8BFB\u53D6: ${platform}`
|
|
5024
|
-
);
|
|
4950
|
+
return out;
|
|
5025
4951
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
const
|
|
5029
|
-
|
|
5030
|
-
const
|
|
5031
|
-
const
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
4952
|
+
function detectFileReferences(line, cwd, opts = {}) {
|
|
4953
|
+
const wsl = opts.wsl ?? isWslEnvironment();
|
|
4954
|
+
const excluded = new Set(opts.exclude ?? []);
|
|
4955
|
+
const out = [];
|
|
4956
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4957
|
+
for (const token of tokenizePasteLine(line)) {
|
|
4958
|
+
if (!token.raw || excluded.has(token.raw)) continue;
|
|
4959
|
+
let candidate = token.decoded;
|
|
4960
|
+
const uriPath = fileUriToPath(candidate);
|
|
4961
|
+
if (uriPath !== null) candidate = uriPath;
|
|
4962
|
+
if (wsl) candidate = mapWindowsPathToWsl(candidate);
|
|
4963
|
+
if (candidate.startsWith("~")) candidate = resolveImageSource(candidate, cwd);
|
|
4964
|
+
const looksLikePath = /[/\\]/.test(candidate) || candidate.startsWith("~") || /^[a-zA-Z]:/.test(candidate);
|
|
4965
|
+
if (!looksLikePath) continue;
|
|
4966
|
+
const ext = extnameOf(candidate);
|
|
4967
|
+
if (!/^[a-z0-9]{1,8}$/.test(ext)) continue;
|
|
4968
|
+
if (IMAGE_EXTENSION_SET.has(ext)) continue;
|
|
4969
|
+
const resolved = resolveImageSource(candidate, cwd);
|
|
4970
|
+
if (excluded.has(resolved) || seen.has(resolved)) continue;
|
|
4971
|
+
if (!isReadableFilePath(resolved)) continue;
|
|
4972
|
+
try {
|
|
4973
|
+
if (!statSync2(resolved).isFile()) continue;
|
|
4974
|
+
} catch {
|
|
4975
|
+
continue;
|
|
4976
|
+
}
|
|
4977
|
+
seen.add(resolved);
|
|
4978
|
+
out.push({ raw: token.raw, resolvedPath: resolved });
|
|
5038
4979
|
}
|
|
5039
|
-
return
|
|
4980
|
+
return out;
|
|
5040
4981
|
}
|
|
5041
|
-
|
|
5042
|
-
const
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
const
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
5063
|
-
timeout = setTimeout(() => {
|
|
5064
|
-
proc.kill();
|
|
5065
|
-
reject(
|
|
5066
|
-
new ClipboardImageError(
|
|
5067
|
-
"read-failed",
|
|
5068
|
-
"\u8BFB\u53D6\u526A\u8D34\u677F\u8D85\u65F6\uFF0C\u526A\u8D34\u677F\u540E\u7AEF\u53EF\u80FD\u65E0\u54CD\u5E94"
|
|
5069
|
-
)
|
|
5070
|
-
);
|
|
5071
|
-
}, timeoutMs);
|
|
5072
|
-
});
|
|
5073
|
-
try {
|
|
5074
|
-
const [stdoutArrayBuffer, stderrText, exitCode] = await Promise.race([
|
|
5075
|
-
Promise.all([
|
|
5076
|
-
new Response(proc.stdout).arrayBuffer(),
|
|
5077
|
-
new Response(proc.stderr).text(),
|
|
5078
|
-
proc.exited
|
|
5079
|
-
]),
|
|
5080
|
-
timeoutPromise
|
|
5081
|
-
]);
|
|
5082
|
-
if (exitCode !== 0 || stdoutArrayBuffer.byteLength === 0) {
|
|
5083
|
-
if (outputFormat === "osascript-hex") {
|
|
5084
|
-
throw new ClipboardImageError(
|
|
5085
|
-
"empty-clipboard",
|
|
5086
|
-
OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE + (stderrText.trim() ? `: ${stderrText.trim()}` : "")
|
|
5087
|
-
);
|
|
5088
|
-
}
|
|
5089
|
-
throw new ClipboardImageError(
|
|
5090
|
-
"empty-clipboard",
|
|
5091
|
-
"\u526A\u8D34\u677F\u4E2D\u6CA1\u6709\u56FE\u50CF\u6570\u636E\uFF0C\u8BF7\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u8F93\u5165\u56FE\u7247\u8DEF\u5F84" + (stderrText.trim() ? `: ${stderrText.trim()}` : "")
|
|
5092
|
-
);
|
|
4982
|
+
function tokenizePasteLine(line) {
|
|
4983
|
+
const tokens = [];
|
|
4984
|
+
let rawBuf = "";
|
|
4985
|
+
let decBuf = "";
|
|
4986
|
+
let quote = null;
|
|
4987
|
+
const push = () => {
|
|
4988
|
+
if (rawBuf.length > 0) {
|
|
4989
|
+
tokens.push({ raw: rawBuf, decoded: decBuf });
|
|
4990
|
+
rawBuf = "";
|
|
4991
|
+
decBuf = "";
|
|
4992
|
+
}
|
|
4993
|
+
};
|
|
4994
|
+
for (let i = 0; i < line.length; i++) {
|
|
4995
|
+
const ch = line[i];
|
|
4996
|
+
const next = line[i + 1];
|
|
4997
|
+
if (quote) {
|
|
4998
|
+
if (ch === "\\" && next !== void 0) {
|
|
4999
|
+
rawBuf += ch + next;
|
|
5000
|
+
decBuf += next;
|
|
5001
|
+
i++;
|
|
5002
|
+
continue;
|
|
5093
5003
|
}
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5004
|
+
if (ch === quote) {
|
|
5005
|
+
quote = null;
|
|
5006
|
+
rawBuf += ch;
|
|
5007
|
+
continue;
|
|
5008
|
+
}
|
|
5009
|
+
rawBuf += ch;
|
|
5010
|
+
decBuf += ch;
|
|
5011
|
+
continue;
|
|
5097
5012
|
}
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5013
|
+
if (ch === "\\" && next !== void 0 && /\s/.test(next)) {
|
|
5014
|
+
rawBuf += ch + next;
|
|
5015
|
+
decBuf += next;
|
|
5016
|
+
i++;
|
|
5017
|
+
continue;
|
|
5101
5018
|
}
|
|
5102
|
-
|
|
5103
|
-
"
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
if (outputFormat === "osascript-hex") {
|
|
5108
|
-
const text = Buffer.from(stdoutBuf).toString("utf8");
|
|
5109
|
-
const decoded = decodeOsascriptPngHex(text);
|
|
5110
|
-
if (decoded.kind === "empty") {
|
|
5111
|
-
throw new ClipboardImageError(
|
|
5112
|
-
"empty-clipboard",
|
|
5113
|
-
OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE
|
|
5114
|
-
);
|
|
5019
|
+
if (ch === "\\" && next === "\\") {
|
|
5020
|
+
rawBuf += "\\\\";
|
|
5021
|
+
decBuf += "\\";
|
|
5022
|
+
i++;
|
|
5023
|
+
continue;
|
|
5115
5024
|
}
|
|
5116
|
-
if (
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
);
|
|
5025
|
+
if (ch === '"' || ch === "'") {
|
|
5026
|
+
quote = ch;
|
|
5027
|
+
rawBuf += ch;
|
|
5028
|
+
continue;
|
|
5121
5029
|
}
|
|
5122
|
-
|
|
5030
|
+
if (/\s/.test(ch)) {
|
|
5031
|
+
push();
|
|
5032
|
+
continue;
|
|
5033
|
+
}
|
|
5034
|
+
rawBuf += ch;
|
|
5035
|
+
decBuf += ch;
|
|
5123
5036
|
}
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5037
|
+
push();
|
|
5038
|
+
return tokens;
|
|
5039
|
+
}
|
|
5040
|
+
async function readImageAsDataUrl(absolutePath, options = {}) {
|
|
5041
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_IMAGE_BYTES;
|
|
5042
|
+
let stats;
|
|
5043
|
+
try {
|
|
5044
|
+
stats = await stat(absolutePath);
|
|
5045
|
+
} catch (error) {
|
|
5046
|
+
throw classifyFsError(error, absolutePath);
|
|
5047
|
+
}
|
|
5048
|
+
if (stats.isDirectory()) {
|
|
5049
|
+
throw new ImageReadError(
|
|
5050
|
+
"is-directory",
|
|
5051
|
+
absolutePath,
|
|
5052
|
+
`path is a directory, not an image: ${absolutePath}`
|
|
5053
|
+
);
|
|
5054
|
+
}
|
|
5055
|
+
const ext = extnameOf(absolutePath);
|
|
5056
|
+
if (!ext || !IMAGE_EXTENSION_SET.has(ext)) {
|
|
5057
|
+
throw new ImageReadError(
|
|
5058
|
+
"unsupported-extension",
|
|
5059
|
+
absolutePath,
|
|
5060
|
+
`unsupported image extension: .${ext || "(none)"}`
|
|
5061
|
+
);
|
|
5062
|
+
}
|
|
5063
|
+
let buffer;
|
|
5064
|
+
try {
|
|
5065
|
+
buffer = await readFile(absolutePath);
|
|
5066
|
+
} catch (error) {
|
|
5067
|
+
throw classifyFsError(error, absolutePath);
|
|
5068
|
+
}
|
|
5069
|
+
const rawMime = MIME_BY_EXTENSION[ext];
|
|
5070
|
+
const compressResult = await compressImage(buffer, rawMime);
|
|
5071
|
+
const finalBuffer = compressResult.buffer;
|
|
5072
|
+
const finalMime = compressResult.mime;
|
|
5073
|
+
const finalSizeBytes = finalBuffer.byteLength;
|
|
5074
|
+
if (finalSizeBytes > maxBytes) {
|
|
5075
|
+
throw new ImageReadError(
|
|
5076
|
+
"too-large",
|
|
5077
|
+
absolutePath,
|
|
5078
|
+
`image too large: ${formatBytes(finalSizeBytes)} (limit ${formatBytes(maxBytes)})`
|
|
5079
|
+
);
|
|
5133
5080
|
}
|
|
5134
|
-
const hash = createHash("sha256").update(finalBuf).digest("hex").slice(0, 12);
|
|
5135
|
-
const ext = mimeToExtension(finalMime);
|
|
5136
|
-
const filename = `clip-${hash}.${ext}`;
|
|
5137
|
-
mkdirSync(tempDir, { recursive: true });
|
|
5138
|
-
const filePath = join(tempDir, filename);
|
|
5139
|
-
await writeFile(filePath, finalBuf);
|
|
5140
5081
|
return buildAttachedImage({
|
|
5141
|
-
buffer:
|
|
5082
|
+
buffer: finalBuffer,
|
|
5142
5083
|
mime: finalMime,
|
|
5143
|
-
filename,
|
|
5144
|
-
sourcePath:
|
|
5084
|
+
filename: basenameOf(absolutePath),
|
|
5085
|
+
sourcePath: absolutePath,
|
|
5145
5086
|
originalSizeBytes: compressResult.compressed ? compressResult.originalBytes : void 0
|
|
5146
5087
|
});
|
|
5147
5088
|
}
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5089
|
+
function classifyFsError(error, path) {
|
|
5090
|
+
const code = error?.code;
|
|
5091
|
+
const message = toErrorMessage(error);
|
|
5092
|
+
switch (code) {
|
|
5093
|
+
case "ENOENT":
|
|
5094
|
+
return new ImageReadError("not-found", path, `image not found: ${path}`);
|
|
5095
|
+
case "EACCES":
|
|
5096
|
+
case "EPERM":
|
|
5097
|
+
return new ImageReadError(
|
|
5098
|
+
"permission-denied",
|
|
5099
|
+
path,
|
|
5100
|
+
`cannot read image (permission denied): ${path}`
|
|
5101
|
+
);
|
|
5102
|
+
case "EISDIR":
|
|
5103
|
+
return new ImageReadError(
|
|
5104
|
+
"is-directory",
|
|
5105
|
+
path,
|
|
5106
|
+
`path is a directory, not an image: ${path}`
|
|
5107
|
+
);
|
|
5108
|
+
default:
|
|
5109
|
+
return new ImageReadError("io-error", path, `failed to read image: ${message}`);
|
|
5110
|
+
}
|
|
5152
5111
|
}
|
|
5153
|
-
function
|
|
5154
|
-
|
|
5155
|
-
const
|
|
5156
|
-
|
|
5112
|
+
function buildAttachedImage(params) {
|
|
5113
|
+
const sizeBytes = params.buffer.byteLength;
|
|
5114
|
+
const base64 = Buffer.from(params.buffer).toString("base64");
|
|
5115
|
+
const dataUrl = `data:${params.mime};base64,${base64}`;
|
|
5116
|
+
return {
|
|
5117
|
+
dataUrl,
|
|
5118
|
+
mime: params.mime,
|
|
5119
|
+
filename: params.filename,
|
|
5120
|
+
sizeBytes,
|
|
5121
|
+
sourcePath: params.sourcePath,
|
|
5122
|
+
...typeof params.originalSizeBytes === "number" && params.originalSizeBytes > sizeBytes ? { originalSizeBytes: params.originalSizeBytes } : {}
|
|
5123
|
+
};
|
|
5157
5124
|
}
|
|
5158
|
-
function
|
|
5159
|
-
|
|
5125
|
+
function describeImageSize(img, options = {}) {
|
|
5126
|
+
const isCompressed = typeof img.originalSizeBytes === "number" && img.originalSizeBytes > img.sizeBytes;
|
|
5127
|
+
const core = isCompressed ? `${formatBytes(img.sizeBytes)} (\u5DF2\u538B\u7F29 ${formatBytes(img.originalSizeBytes)} \u2192 ${formatBytes(img.sizeBytes)})` : formatBytes(img.sizeBytes);
|
|
5128
|
+
return options.prefix ? `Size: ${core}` : core;
|
|
5160
5129
|
}
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
} catch (imageError) {
|
|
5166
|
-
const code = errorCodeOf(imageError);
|
|
5167
|
-
if (!isTextFallbackEligibleCode(code)) {
|
|
5168
|
-
return {
|
|
5169
|
-
kind: "error",
|
|
5170
|
-
code: code ?? "read-failed",
|
|
5171
|
-
message: messageOf(imageError)
|
|
5172
|
-
};
|
|
5173
|
-
}
|
|
5174
|
-
let text;
|
|
5175
|
-
try {
|
|
5176
|
-
text = await deps.readText();
|
|
5177
|
-
} catch (textError) {
|
|
5178
|
-
return {
|
|
5179
|
-
kind: "error",
|
|
5180
|
-
code: "text-read-failed",
|
|
5181
|
-
message: `${messageOf(textError)} (${messageOf(imageError)})`
|
|
5182
|
-
};
|
|
5183
|
-
}
|
|
5184
|
-
if (text.length > 0) {
|
|
5185
|
-
return { kind: "text", text };
|
|
5186
|
-
}
|
|
5187
|
-
return { kind: "empty", message: messageOf(imageError) };
|
|
5188
|
-
}
|
|
5130
|
+
function formatBytes(bytes) {
|
|
5131
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
5132
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
5133
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
5189
5134
|
}
|
|
5190
|
-
function
|
|
5191
|
-
|
|
5192
|
-
|
|
5135
|
+
function summarizeAttachment(img) {
|
|
5136
|
+
const colorEnabled = resolveCliColorEnabled();
|
|
5137
|
+
const sizeText = describeImageSize(img, { prefix: true });
|
|
5138
|
+
const titleRaw = "\u{1F4F7} [Attached Image]";
|
|
5139
|
+
const nameRaw = `Name: ${img.filename}`;
|
|
5140
|
+
const boxWidth = Math.max(40, titleRaw.length + 4, nameRaw.length + 4, sizeText.length + 4);
|
|
5141
|
+
const border = "\u250C" + "\u2500".repeat(boxWidth - 2) + "\u2510";
|
|
5142
|
+
const bottom = "\u2514" + "\u2500".repeat(boxWidth - 2) + "\u2518";
|
|
5143
|
+
const padLine = (content) => {
|
|
5144
|
+
const padded = content.padEnd(boxWidth - 4, " ");
|
|
5145
|
+
return `\u2502 ${padded} \u2502`;
|
|
5146
|
+
};
|
|
5147
|
+
const title = padLine(titleRaw);
|
|
5148
|
+
const name = padLine(nameRaw);
|
|
5149
|
+
const size = padLine(sizeText);
|
|
5150
|
+
const text = [
|
|
5151
|
+
border,
|
|
5152
|
+
title,
|
|
5153
|
+
name,
|
|
5154
|
+
size,
|
|
5155
|
+
bottom
|
|
5156
|
+
].join("\n");
|
|
5157
|
+
return themeText(text, "chrome", colorEnabled);
|
|
5193
5158
|
}
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
const
|
|
5198
|
-
|
|
5159
|
+
function formatComposerAttachmentLine(images) {
|
|
5160
|
+
if (images.length === 0) return null;
|
|
5161
|
+
const head = images.slice(0, 2).map((img) => `\u{1F4CE} ${img.filename} (${formatBytes(img.sizeBytes)})`);
|
|
5162
|
+
const extra = images.length - head.length;
|
|
5163
|
+
return extra > 0 ? `${head.join(", ")} +${extra}` : head.join(", ");
|
|
5199
5164
|
}
|
|
5200
|
-
|
|
5201
|
-
if (
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
return;
|
|
5208
|
-
}
|
|
5209
|
-
throw new Error(
|
|
5210
|
-
"Client clipboard is unavailable in a non-interactive remote session."
|
|
5211
|
-
);
|
|
5165
|
+
function popLastAttachedImage(images) {
|
|
5166
|
+
if (images.length === 0) return { handled: false, images };
|
|
5167
|
+
return {
|
|
5168
|
+
handled: true,
|
|
5169
|
+
images: images.slice(0, -1),
|
|
5170
|
+
removed: images[images.length - 1]
|
|
5171
|
+
};
|
|
5212
5172
|
}
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5173
|
+
function mergeAttachedImages(existing, incoming) {
|
|
5174
|
+
if (incoming.length === 0) return existing;
|
|
5175
|
+
if (existing.length === 0) return [...incoming];
|
|
5176
|
+
const incomingByPath = /* @__PURE__ */ new Map();
|
|
5177
|
+
for (const img of incoming) incomingByPath.set(img.sourcePath, img);
|
|
5178
|
+
const out = [];
|
|
5179
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5180
|
+
for (const img of existing) {
|
|
5181
|
+
if (seen.has(img.sourcePath)) continue;
|
|
5182
|
+
const override = incomingByPath.get(img.sourcePath);
|
|
5183
|
+
out.push(override ?? img);
|
|
5184
|
+
seen.add(img.sourcePath);
|
|
5219
5185
|
}
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
const flag = line[0];
|
|
5225
|
-
if (flag === "?") untracked += 1;
|
|
5226
|
-
else modified += 1;
|
|
5186
|
+
for (const img of incoming) {
|
|
5187
|
+
if (seen.has(img.sourcePath)) continue;
|
|
5188
|
+
out.push(img);
|
|
5189
|
+
seen.add(img.sourcePath);
|
|
5227
5190
|
}
|
|
5228
|
-
return
|
|
5229
|
-
}
|
|
5230
|
-
function execFileUtf8(file, args, cwd) {
|
|
5231
|
-
return new Promise((resolve4, reject) => {
|
|
5232
|
-
execFile(
|
|
5233
|
-
file,
|
|
5234
|
-
args,
|
|
5235
|
-
{ cwd, encoding: "utf8", timeout: 2e3 },
|
|
5236
|
-
(err, stdout) => {
|
|
5237
|
-
if (err) {
|
|
5238
|
-
reject(err);
|
|
5239
|
-
return;
|
|
5240
|
-
}
|
|
5241
|
-
resolve4(typeof stdout === "string" ? stdout : String(stdout ?? ""));
|
|
5242
|
-
}
|
|
5243
|
-
);
|
|
5244
|
-
});
|
|
5191
|
+
return out;
|
|
5245
5192
|
}
|
|
5246
|
-
function
|
|
5247
|
-
|
|
5193
|
+
async function readImagePaths(paths, options = {}) {
|
|
5194
|
+
const resolve4 = options.resolve ?? ((p) => p);
|
|
5195
|
+
const reportedFailures = /* @__PURE__ */ new Set();
|
|
5196
|
+
const images = [];
|
|
5197
|
+
const failures = [];
|
|
5198
|
+
for (const raw of paths) {
|
|
5199
|
+
const absolute = resolve4(raw);
|
|
5248
5200
|
try {
|
|
5249
|
-
const
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5201
|
+
const img = await readImageAsDataUrl(absolute, {
|
|
5202
|
+
...options.maxBytes !== void 0 ? { maxBytes: options.maxBytes } : {}
|
|
5203
|
+
});
|
|
5204
|
+
images.push(img);
|
|
5205
|
+
options.onSuccess?.(img);
|
|
5206
|
+
} catch (error) {
|
|
5207
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
5208
|
+
if (!reportedFailures.has(absolute)) {
|
|
5209
|
+
reportedFailures.add(absolute);
|
|
5210
|
+
failures.push(absolute);
|
|
5211
|
+
options.onFailure?.(absolute, err);
|
|
5212
|
+
}
|
|
5255
5213
|
}
|
|
5256
|
-
}
|
|
5214
|
+
}
|
|
5215
|
+
return { images, failures };
|
|
5257
5216
|
}
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5217
|
+
async function resolveAttachmentImageUrls({
|
|
5218
|
+
actionImagePaths,
|
|
5219
|
+
attachedImages,
|
|
5220
|
+
onFailure
|
|
5221
|
+
}) {
|
|
5222
|
+
const pathsToRead = [
|
|
5223
|
+
...actionImagePaths ?? [],
|
|
5224
|
+
...attachedImages.map((img) => img.sourcePath)
|
|
5225
|
+
];
|
|
5226
|
+
let imageUrls = [];
|
|
5227
|
+
if (pathsToRead.length > 0) {
|
|
5228
|
+
const readResult = await readImagePaths(pathsToRead, {
|
|
5229
|
+
onFailure
|
|
5230
|
+
});
|
|
5231
|
+
imageUrls = readResult.images.map((img) => img.dataUrl);
|
|
5232
|
+
}
|
|
5233
|
+
return { imageUrls };
|
|
5263
5234
|
}
|
|
5264
|
-
function
|
|
5265
|
-
|
|
5266
|
-
const
|
|
5267
|
-
const
|
|
5268
|
-
|
|
5269
|
-
const
|
|
5270
|
-
|
|
5271
|
-
|
|
5235
|
+
function detectSubmittedImagePaths(text, cwd, opts = {}) {
|
|
5236
|
+
const trimmed = text.trim();
|
|
5237
|
+
const hints = detectImagePaths(trimmed, cwd, opts);
|
|
5238
|
+
const readableHints = hints.filter((hint) => !hint.unreadable);
|
|
5239
|
+
const unreadableHints = hints.filter((hint) => hint.unreadable);
|
|
5240
|
+
const stripped = stripImageTokens(trimmed, readableHints);
|
|
5241
|
+
return {
|
|
5242
|
+
hints,
|
|
5243
|
+
imagePaths: readableHints.map((hint) => hint.resolvedPath),
|
|
5244
|
+
unreadableHints,
|
|
5245
|
+
message: stripped.length > 0 ? stripped : trimmed
|
|
5246
|
+
};
|
|
5272
5247
|
}
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5248
|
+
|
|
5249
|
+
// packages/cli/tui/clipboardImage.ts
|
|
5250
|
+
import { createHash } from "node:crypto";
|
|
5251
|
+
import { mkdirSync } from "node:fs";
|
|
5252
|
+
import { readdir, stat as stat2, unlink, writeFile } from "node:fs/promises";
|
|
5253
|
+
import { tmpdir } from "node:os";
|
|
5254
|
+
import { join } from "node:path";
|
|
5255
|
+
var ClipboardImageError = class extends Error {
|
|
5256
|
+
code;
|
|
5257
|
+
constructor(code, message) {
|
|
5258
|
+
super(message);
|
|
5259
|
+
this.code = code;
|
|
5260
|
+
this.name = "ClipboardImageError";
|
|
5277
5261
|
}
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5262
|
+
};
|
|
5263
|
+
var DEFAULT_CLIPBOARD_TIMEOUT_MS = 3e4;
|
|
5264
|
+
var CLIPBOARD_TEMP_DIR_NAME = "nolo-clipboard";
|
|
5265
|
+
function getDefaultClipboardTempDir() {
|
|
5266
|
+
return join(tmpdir(), CLIPBOARD_TEMP_DIR_NAME);
|
|
5282
5267
|
}
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5268
|
+
var CLIPBOARD_SWEEP_MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
5269
|
+
var CLIPBOARD_SWEEP_FILE_RE = /^clip-[0-9a-f]{8,}\.(png|jpg|jpeg|gif|webp)$/;
|
|
5270
|
+
async function sweepStaleClipboardFiles(tempDir, opts = {}) {
|
|
5271
|
+
try {
|
|
5272
|
+
const maxAgeMs = opts.maxAgeMs ?? CLIPBOARD_SWEEP_MAX_AGE_MS;
|
|
5273
|
+
const now = opts.now ?? Date.now();
|
|
5274
|
+
const entries = await readdir(tempDir);
|
|
5275
|
+
let removed = 0;
|
|
5276
|
+
for (const name of entries) {
|
|
5277
|
+
if (!CLIPBOARD_SWEEP_FILE_RE.test(name)) continue;
|
|
5278
|
+
try {
|
|
5279
|
+
const fullPath = join(tempDir, name);
|
|
5280
|
+
const stats = await stat2(fullPath);
|
|
5281
|
+
if (stats.mtimeMs >= now - maxAgeMs) continue;
|
|
5282
|
+
await unlink(fullPath);
|
|
5283
|
+
removed += 1;
|
|
5284
|
+
} catch {
|
|
5285
|
+
}
|
|
5286
|
+
}
|
|
5287
|
+
return removed;
|
|
5288
|
+
} catch {
|
|
5289
|
+
return 0;
|
|
5289
5290
|
}
|
|
5290
|
-
return (base ?? 0) + (session ?? 0) + (live ?? 0);
|
|
5291
5291
|
}
|
|
5292
|
-
function
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
const
|
|
5297
|
-
const
|
|
5298
|
-
const
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
const modifiedText = modified > 0 ? ` ${themeText(`*${modified}`, "danger", colorEnabled)}` : "";
|
|
5305
|
-
const untrackedText = untracked > 0 ? ` ${themeText(`?${untracked}`, "muted", colorEnabled)}` : "";
|
|
5306
|
-
parts.push(`${branchText}${modifiedText}${untrackedText}`);
|
|
5307
|
-
}
|
|
5308
|
-
const credits = resolveStatusLineCredits(state);
|
|
5309
|
-
const tokenSegment = themeText(
|
|
5310
|
-
renderComposerTokenChip(
|
|
5311
|
-
state.turnTokens,
|
|
5312
|
-
state.contextWindow,
|
|
5313
|
-
state.estimatedContextTokens
|
|
5314
|
-
),
|
|
5315
|
-
"muted",
|
|
5316
|
-
colorEnabled
|
|
5317
|
-
);
|
|
5318
|
-
const creditsSegment = credits !== void 0 && credits > 0 ? themeText(formatCreditsChip(credits), "muted", colorEnabled) : "";
|
|
5319
|
-
parts.push(tokenSegment);
|
|
5320
|
-
if (creditsSegment) parts.push(creditsSegment);
|
|
5321
|
-
const runningTaskCount = getProcessRegistry().listBackground().filter((p) => p.status === "running").length;
|
|
5322
|
-
if (runningTaskCount > 0) {
|
|
5323
|
-
parts.push(themeText(`\u2699 ${runningTaskCount} running`, "info", colorEnabled));
|
|
5324
|
-
}
|
|
5325
|
-
const pendingProcessCount = state.pendingProcessNotices?.length ?? 0;
|
|
5326
|
-
if (pendingProcessCount > 0) {
|
|
5327
|
-
parts.push(themeText(`\u2699 ${pendingProcessCount} finished`, "info", colorEnabled));
|
|
5292
|
+
function isRemoteSession(env = process.env) {
|
|
5293
|
+
return Boolean(env.SSH_CONNECTION || env.SSH_TTY || env.SSH_CLIENT);
|
|
5294
|
+
}
|
|
5295
|
+
function getClipboardImageCommand(deps = {}) {
|
|
5296
|
+
const env = deps.env ?? process.env;
|
|
5297
|
+
const platform = deps.platform ?? process.platform;
|
|
5298
|
+
const which = deps.which ?? Bun.which;
|
|
5299
|
+
if (isRemoteSession(env)) {
|
|
5300
|
+
throw new ClipboardImageError(
|
|
5301
|
+
"remote-session",
|
|
5302
|
+
"\u8FDC\u7A0B\u4F1A\u8BDD\u65E0\u6CD5\u8BFB\u53D6\u672C\u5730\u526A\u8D34\u677F\uFF0C\u8BF7\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u76F4\u63A5\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
|
|
5303
|
+
);
|
|
5328
5304
|
}
|
|
5329
|
-
if (
|
|
5330
|
-
|
|
5305
|
+
if (platform === "darwin") {
|
|
5306
|
+
const pngpaste = which("pngpaste");
|
|
5307
|
+
if (pngpaste) {
|
|
5308
|
+
return { command: [pngpaste, "-"], outputFormat: "raw" };
|
|
5309
|
+
}
|
|
5310
|
+
const osascript = which("osascript");
|
|
5311
|
+
if (!osascript) {
|
|
5312
|
+
throw new ClipboardImageError(
|
|
5313
|
+
"binary-missing",
|
|
5314
|
+
"\u672A\u627E\u5230 pngpaste\uFF0C\u4E5F\u672A\u627E\u5230\u7CFB\u7EDF\u81EA\u5E26\u7684 osascript\uFF0C\u65E0\u6CD5\u8BFB\u53D6\u526A\u8D34\u677F\u56FE\u50CF\u3002\u8BF7\u8FD0\u884C brew install pngpaste \u5B89\u88C5\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
|
|
5315
|
+
);
|
|
5316
|
+
}
|
|
5317
|
+
return {
|
|
5318
|
+
command: [osascript, "-e", "the clipboard as \xABclass PNGf\xBB"],
|
|
5319
|
+
outputFormat: "osascript-hex"
|
|
5320
|
+
};
|
|
5331
5321
|
}
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5322
|
+
if (platform === "win32") {
|
|
5323
|
+
const ps = which("powershell.exe") || which("powershell") || which("pwsh.exe") || which("pwsh");
|
|
5324
|
+
if (!ps) {
|
|
5325
|
+
throw new ClipboardImageError(
|
|
5326
|
+
"binary-missing",
|
|
5327
|
+
"\u672A\u627E\u5230 PowerShell\uFF0C\u65E0\u6CD5\u4ECE\u7CFB\u7EDF\u526A\u8D34\u677F\u8BFB\u53D6\u56FE\u50CF\uFF0C\u8BF7\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
|
|
5328
|
+
);
|
|
5339
5329
|
}
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5330
|
+
return {
|
|
5331
|
+
command: [
|
|
5332
|
+
ps,
|
|
5333
|
+
"-NoProfile",
|
|
5334
|
+
"-NonInteractive",
|
|
5335
|
+
"-Command",
|
|
5336
|
+
"$img = Get-Clipboard -Format Image; if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [Console]::OpenStandardOutput().Write($ms.ToArray(), 0, $ms.Length) }"
|
|
5337
|
+
],
|
|
5338
|
+
outputFormat: "raw"
|
|
5339
|
+
};
|
|
5340
|
+
}
|
|
5341
|
+
if (platform === "linux") {
|
|
5342
|
+
const isWayland = Boolean(env.WAYLAND_DISPLAY);
|
|
5343
|
+
if (isWayland) {
|
|
5344
|
+
const wlPaste2 = which("wl-paste");
|
|
5345
|
+
if (!wlPaste2) {
|
|
5346
|
+
throw new ClipboardImageError(
|
|
5347
|
+
"binary-missing",
|
|
5348
|
+
"\u672A\u627E\u5230 wl-paste\uFF0C\u8BF7\u5B89\u88C5 wl-clipboard (\u4F8B\u5982 sudo apt install wl-clipboard)\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
|
|
5348
5349
|
);
|
|
5349
|
-
visibleParts = visibleParts.with(gitIndex, compactDirty);
|
|
5350
5350
|
}
|
|
5351
|
+
return { command: [wlPaste2, "--type", "image/png"], outputFormat: "raw" };
|
|
5351
5352
|
}
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
const { modified, untracked } = state.gitStatus;
|
|
5363
|
-
emergency.push(themeText(
|
|
5364
|
-
`\u2442${modified > 0 ? `*${modified}` : ""}${untracked > 0 ? `?${untracked}` : ""}`,
|
|
5365
|
-
"warning",
|
|
5366
|
-
colorEnabled
|
|
5367
|
-
));
|
|
5368
|
-
}
|
|
5369
|
-
if (creditsSegment) {
|
|
5370
|
-
emergency.push(themeText(formatCreditsChip(credits ?? 0, { compact: true }), "muted", colorEnabled));
|
|
5371
|
-
}
|
|
5372
|
-
visibleParts = [emergency.join(" ")];
|
|
5353
|
+
const xclip = which("xclip");
|
|
5354
|
+
if (xclip) {
|
|
5355
|
+
return {
|
|
5356
|
+
command: [xclip, "-selection", "clipboard", "-t", "image/png", "-o"],
|
|
5357
|
+
outputFormat: "raw"
|
|
5358
|
+
};
|
|
5359
|
+
}
|
|
5360
|
+
const wlPaste = which("wl-paste");
|
|
5361
|
+
if (wlPaste) {
|
|
5362
|
+
return { command: [wlPaste, "--type", "image/png"], outputFormat: "raw" };
|
|
5373
5363
|
}
|
|
5364
|
+
throw new ClipboardImageError(
|
|
5365
|
+
"binary-missing",
|
|
5366
|
+
"\u672A\u627E\u5230 xclip\uFF0C\u8BF7\u5B89\u88C5 xclip (\u4F8B\u5982 sudo apt install xclip)\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
|
|
5367
|
+
);
|
|
5374
5368
|
}
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5369
|
+
throw new ClipboardImageError(
|
|
5370
|
+
"unsupported-platform",
|
|
5371
|
+
`\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u6682\u4E0D\u652F\u6301\u526A\u8D34\u677F\u56FE\u50CF\u8BFB\u53D6: ${platform}`
|
|
5372
|
+
);
|
|
5379
5373
|
}
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
const offset = frame % wavePattern.length;
|
|
5393
|
-
const wave = longWave.slice(offset, offset + 25);
|
|
5394
|
-
return [
|
|
5395
|
-
...skyLine ? [skyLine] : [],
|
|
5396
|
-
" \u2571\u2572 \u2588\u2584 \u2588 \u2584\u2580\u2580\u2584 \u2588 \u2584\u2580\u2580\u2584",
|
|
5397
|
-
" \u2571 \u2572 \u2571\u2572 \u2588 \u2580\u2588 \u2588 \u2588 \u2588 \u2588 \u2588",
|
|
5398
|
-
" \u2571 \u2572\u2571 \u2572 \u2580 \u2580 \u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580",
|
|
5399
|
-
` \u2571 \u2660 \u2572 ${wave}`,
|
|
5400
|
-
" \u2581\u2581\u2581\u2581\u2581\u2581\u2571 \u2660 \u2660 \u2572\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581"
|
|
5401
|
-
].join("\n");
|
|
5402
|
-
}
|
|
5403
|
-
function buildColoredScene(isDark, frame = 0, maxFrames = 0) {
|
|
5404
|
-
const pk = themeColorSequence("chrome");
|
|
5405
|
-
const sk = themeColorSequence("warning");
|
|
5406
|
-
const tr = themeColorSequence("success");
|
|
5407
|
-
const wv = themeColorSequence("info");
|
|
5408
|
-
const ac = themeColorSequence("accent");
|
|
5409
|
-
const mu = themeColorSequence("muted");
|
|
5410
|
-
const r = "\x1B[39m";
|
|
5411
|
-
const b = "\x1B[1m";
|
|
5412
|
-
const rs = "\x1B[0m";
|
|
5413
|
-
let skyLine = null;
|
|
5414
|
-
if (isDark === true) {
|
|
5415
|
-
const star1 = frame % 6 < 3 ? "\u2726" : "\u22C6";
|
|
5416
|
-
const star2 = frame % 4 < 2 ? "\u22C6" : "\xB7";
|
|
5417
|
-
const star3 = frame % 5 < 2 ? "\xB7" : "\u2726";
|
|
5418
|
-
skyLine = ` ${mu}${star1}${r} ${sk}\u263E${r} ${mu}${star2}${r} ${mu}${star3}${r}`;
|
|
5419
|
-
} else if (isDark === false) {
|
|
5420
|
-
skyLine = ` ${sk}\u2600${r}`;
|
|
5421
|
-
}
|
|
5422
|
-
const wavePattern = "_.~^~.";
|
|
5423
|
-
const longWave = wavePattern.repeat(10);
|
|
5424
|
-
const offset = frame % wavePattern.length;
|
|
5425
|
-
const wave = longWave.slice(offset, offset + 25);
|
|
5426
|
-
const waveStr = `${wv}${wave.slice(0, 20)}${r}${mu}${wave.slice(20, 25)}${r}`;
|
|
5427
|
-
const line1 = "\u2588\u2584 \u2588 \u2584\u2580\u2580\u2584 \u2588 \u2584\u2580\u2580\u2584";
|
|
5428
|
-
const line2 = "\u2588 \u2580\u2588 \u2588 \u2588 \u2588 \u2588 \u2588";
|
|
5429
|
-
const line3 = "\u2580 \u2580 \u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580";
|
|
5430
|
-
const sweepEndFrame = maxFrames > 3 ? maxFrames - 3 : maxFrames;
|
|
5431
|
-
const sweepLen = maxFrames === 0 ? 21 : Math.min(21, Math.floor(frame / sweepEndFrame * 21));
|
|
5432
|
-
const colorLine = (str, bold) => {
|
|
5433
|
-
const active = str.slice(0, sweepLen);
|
|
5434
|
-
const dimmed = str.slice(sweepLen);
|
|
5435
|
-
return `${bold ? b : ""}${ac}${active}${r}${mu}${dimmed}${r}${bold ? rs : ""}`;
|
|
5436
|
-
};
|
|
5437
|
-
const nolo1 = colorLine(line1, true);
|
|
5438
|
-
const nolo2 = colorLine(line2, false);
|
|
5439
|
-
const nolo3 = colorLine(line3, false);
|
|
5440
|
-
return [
|
|
5441
|
-
...skyLine ? [skyLine] : [],
|
|
5442
|
-
` ${pk}\u2571\u2572${r} ${nolo1}`,
|
|
5443
|
-
` ${pk}\u2571 \u2572 \u2571\u2572${r} ${nolo2}`,
|
|
5444
|
-
` ${pk}\u2571 \u2572\u2571 \u2572${r} ${nolo3}`,
|
|
5445
|
-
` ${pk}\u2571${r} ${tr}\u2660${r} ${pk}\u2572${r} ${waveStr}`,
|
|
5446
|
-
` ${pk}\u2581\u2581\u2581\u2581\u2581\u2581\u2571${r} ${tr}\u2660${r} ${tr}\u2660${r} ${pk}\u2572\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581${r}`
|
|
5447
|
-
].join("\n");
|
|
5448
|
-
}
|
|
5449
|
-
function renderWelcome(state, frame = 0, maxFrames = 0, columns) {
|
|
5450
|
-
const colorEnabled = resolveCliColorEnabled();
|
|
5451
|
-
const brightnessSignal = resolveTuiBrightnessSignal();
|
|
5452
|
-
const isDark = brightnessSignal === null ? null : brightnessSignal === "dark";
|
|
5453
|
-
let sceneArt = colorEnabled ? buildColoredScene(isDark, frame, maxFrames) : buildPlainScene(isDark, frame, maxFrames);
|
|
5454
|
-
if (typeof columns === "number" && columns > 0) {
|
|
5455
|
-
const widestSceneCol = sceneArt.split("\n").reduce((max, line) => Math.max(max, displayWidth(stripAnsi(line))), 0);
|
|
5456
|
-
if (columns < widestSceneCol) sceneArt = "";
|
|
5457
|
-
}
|
|
5458
|
-
const noloLabel = themeText("nolo", "accent", colorEnabled);
|
|
5459
|
-
const versionLine = `${noloLabel}${state.cliVersion ? ` ${state.cliVersion}` : ""} | server ${state.serverUrl}`;
|
|
5460
|
-
const updateLine = state.updateAvailable ? themeText(
|
|
5461
|
-
t("updateAvailable", state.updateAvailable.latestVersion),
|
|
5462
|
-
"accent",
|
|
5463
|
-
colorEnabled
|
|
5464
|
-
) : null;
|
|
5465
|
-
const body = sceneArt ? [sceneArt, versionLine, ...updateLine ? [updateLine] : [], dailyWelcomeTip(), ""] : [versionLine, ...updateLine ? [updateLine] : [], dailyWelcomeTip(), ""];
|
|
5466
|
-
return body.join("\n");
|
|
5467
|
-
}
|
|
5468
|
-
function renderPrompt(_state) {
|
|
5469
|
-
return t("promptLabel");
|
|
5470
|
-
}
|
|
5471
|
-
function renderTuiHelp(colorEnabled = resolveCliColorEnabled()) {
|
|
5472
|
-
const text = t("helpText");
|
|
5473
|
-
if (!colorEnabled) {
|
|
5474
|
-
return text;
|
|
5475
|
-
}
|
|
5476
|
-
const lines = text.split("\n");
|
|
5477
|
-
const commandRegex = /^(\s+)(\/\S+(?:\s+\S+)*?)(\s{2,})(.+)$/;
|
|
5478
|
-
const sectionRegex = /^\S.+[::]$/;
|
|
5479
|
-
return lines.map((line) => {
|
|
5480
|
-
if (!line.trim()) {
|
|
5481
|
-
return line;
|
|
5482
|
-
}
|
|
5483
|
-
if (sectionRegex.test(line)) {
|
|
5484
|
-
return renderDialogTitle(line, colorEnabled);
|
|
5485
|
-
}
|
|
5486
|
-
const match = line.match(commandRegex);
|
|
5487
|
-
if (match) {
|
|
5488
|
-
const [, indent, cmd, spacing, desc] = match;
|
|
5489
|
-
return `${indent}${themeText(cmd, "accent", colorEnabled)}${spacing}${themeText(desc, "muted", colorEnabled)}`;
|
|
5490
|
-
}
|
|
5491
|
-
return themeText(line, "muted", colorEnabled);
|
|
5492
|
-
}).join("\n");
|
|
5493
|
-
}
|
|
5494
|
-
function renderCreditsDebug(state, colorEnabled = resolveCliColorEnabled()) {
|
|
5495
|
-
const credits = resolveStatusLineCredits(state);
|
|
5496
|
-
const lines = [
|
|
5497
|
-
"[credits debug] \u79EF\u5206\u94FE\u8DEF\u771F\u503C",
|
|
5498
|
-
`\u2022 dialogCreditsBase : ${state.dialogCreditsBase?.toFixed(4) ?? "undefined\uFF08\u670D\u52A1\u7AEF\u57FA\u6570\u672A seed\u2014\u2014/pick \u540E\u9996\u6B21\u8BFB\u53D6\u5931\u8D25\u6216\u670D\u52A1\u7AEF\u672A\u5199 totalCost\uFF09"}`,
|
|
5499
|
-
`\u2022 sessionCredits : ${state.sessionCredits?.toFixed(4) ?? "undefined\uFF08\u672C\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u5E73\u53F0\u8BA1\u8D39\u8F6E\uFF09"}`,
|
|
5500
|
-
`\u2022 \u72B6\u6001\u884C\u663E\u793A : ${credits !== void 0 && credits > 0 ? formatCreditsChip(credits) : "\uFF08\u65E0 \u26A1\u2014\u2014\u4E24\u6BB5\u5408\u8BA1\u4E3A 0/undefined\uFF09"}`,
|
|
5501
|
-
`\u2022 turnTokens.credits: ${state.turnTokens?.credits?.toFixed(4) ?? "undefined"}\uFF08\u672C\u8F6E\u6700\u540E\u4E00\u6B21\u8C03\u7528\u7684\u6298\u7B97\u503C\uFF0C\u4EC5\u4F9B\u53C2\u8003\uFF0C\u4E0D\u8FDB\u72B6\u6001\u884C\uFF09`,
|
|
5502
|
-
`\u2022 contextWindow : ${state.contextWindow ?? "unknown"}`,
|
|
5503
|
-
'\u2022 \u5224\u5B9A\u53E3\u5F84\uFF1A\u53EA\u6709 billing_unit === "credits" \u7684\u5E73\u53F0\u8BA1\u8D39\u5E27\u624D\u7D2F\u8BA1\uFF1B\u81EA\u6709 API / \u8BA2\u9605\u5236\u6052\u4E3A undefined\u3002',
|
|
5504
|
-
"\u2022 \u82E5\u521A\u8DD1\u5B8C\u5E73\u53F0\u8BA1\u8D39\u8F6E\u4ECD\u65E0 \u26A1\uFF1A\u68C0\u67E5 runAgentTurn \u8FD4\u56DE\u662F\u5426\u5E26 turnCredits\uFF08foldLocalResultForTui \u767D\u540D\u5355\uFF09\u3002"
|
|
5505
|
-
];
|
|
5506
|
-
return lines.map((line) => colorEnabled ? themeText(line, "chrome") : line).join("\n");
|
|
5507
|
-
}
|
|
5508
|
-
function renderContextPanel(state, colorEnabled = resolveCliColorEnabled()) {
|
|
5509
|
-
const docs = state.attachedDocs.length ? state.attachedDocs.join(", ") : "none";
|
|
5510
|
-
const skills = state.attachedSkills.length ? state.attachedSkills.join(", ") : "none";
|
|
5511
|
-
const labels = [
|
|
5512
|
-
t("contextFieldAgent"),
|
|
5513
|
-
t("contextFieldTokens"),
|
|
5514
|
-
t("contextFieldDialog"),
|
|
5515
|
-
t("contextFieldDocs"),
|
|
5516
|
-
t("contextFieldSkills"),
|
|
5517
|
-
t("contextFieldProfile"),
|
|
5518
|
-
t("contextFieldRuntime"),
|
|
5519
|
-
t("contextFieldServer")
|
|
5520
|
-
];
|
|
5521
|
-
let maxW = 0;
|
|
5522
|
-
for (const l of labels) {
|
|
5523
|
-
const w = displayWidth(l);
|
|
5524
|
-
if (w > maxW) maxW = w;
|
|
5374
|
+
var OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE = "\u526A\u8D34\u677F\u4E2D\u6CA1\u6709\u56FE\u50CF\u6570\u636E\u3002\u53EF\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u3001\u8F93\u5165\u56FE\u7247\u8DEF\u5F84\uFF0C\u6216\u8FD0\u884C brew install pngpaste \u4EE5\u652F\u6301\u66F4\u591A\u56FE\u7247\u683C\u5F0F";
|
|
5375
|
+
function decodeOsascriptPngHex(text) {
|
|
5376
|
+
const match = /PNGf\s*([0-9A-Fa-f]*)/.exec(text);
|
|
5377
|
+
if (!match) return { kind: "empty" };
|
|
5378
|
+
const hex = match[1] ?? "";
|
|
5379
|
+
const tail = text.slice(match.index + match[0].length).replace(/[\s»]*$/, "");
|
|
5380
|
+
if (tail.length > 0) return { kind: "invalid" };
|
|
5381
|
+
if (hex.length === 0) return { kind: "empty" };
|
|
5382
|
+
if (hex.length % 2 !== 0) return { kind: "invalid" };
|
|
5383
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
5384
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
5385
|
+
bytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
5525
5386
|
}
|
|
5526
|
-
|
|
5527
|
-
const padLabel = (raw) => {
|
|
5528
|
-
const w = displayWidth(raw);
|
|
5529
|
-
const padding = " ".repeat(Math.max(0, targetWidth - w));
|
|
5530
|
-
return raw + padding;
|
|
5531
|
-
};
|
|
5532
|
-
const field = (rawLabel, value) => `${themeText(padLabel(rawLabel), "muted", colorEnabled)}${value}`;
|
|
5533
|
-
const next = (command, description) => ` ${themeText(command, "accent", colorEnabled)}${themeText(description, "muted", colorEnabled)}`;
|
|
5534
|
-
const titleText = t("contextTitle");
|
|
5535
|
-
const heading = colorEnabled ? [renderDialogTitle(titleText, true)] : [titleText, "\u2500".repeat(displayWidth(titleText))];
|
|
5536
|
-
return [
|
|
5537
|
-
...heading,
|
|
5538
|
-
field(labels[0], `${state.agentName} (${state.agentKey})`),
|
|
5539
|
-
field(labels[1], renderTokenStatus(state.turnTokens)),
|
|
5540
|
-
field(
|
|
5541
|
-
labels[2],
|
|
5542
|
-
state.dialogKey ?? (state.dialogId ? "unavailable" : state.dialogLabel)
|
|
5543
|
-
),
|
|
5544
|
-
field(labels[3], docs),
|
|
5545
|
-
field(labels[4], skills),
|
|
5546
|
-
field(labels[5], state.profileName),
|
|
5547
|
-
field(labels[6], state.runtimeMode),
|
|
5548
|
-
field(labels[7], state.serverUrl),
|
|
5549
|
-
"",
|
|
5550
|
-
themeText(t("contextNext"), "chrome", colorEnabled),
|
|
5551
|
-
next("/agents ", ` ${t("contextNextAgents")}`),
|
|
5552
|
-
next("/doc attach <doc> ", ` ${t("contextNextDoc")}`),
|
|
5553
|
-
next("/skill attach <ref>", ` ${t("contextNextSkill")}`),
|
|
5554
|
-
next("/new ", ` ${t("contextNextNew")}`),
|
|
5555
|
-
next("/clear ", ` ${t("contextNextClear")}`)
|
|
5556
|
-
].join("\n");
|
|
5557
|
-
}
|
|
5558
|
-
function renderKnownAgents(colorEnabled = resolveCliColorEnabled()) {
|
|
5559
|
-
return [
|
|
5560
|
-
renderDialogTitle(t("agentsTitle"), colorEnabled),
|
|
5561
|
-
...resolveCatalogPlatformAgents().map(
|
|
5562
|
-
(agent, index) => ` ${themeText(String(index + 1), "chrome", colorEnabled)} ${themeText(
|
|
5563
|
-
agent.name.padEnd(11),
|
|
5564
|
-
"accent",
|
|
5565
|
-
colorEnabled
|
|
5566
|
-
)} ${themeText(agent.description ?? "", "muted", colorEnabled)}`
|
|
5567
|
-
),
|
|
5568
|
-
"",
|
|
5569
|
-
themeText(
|
|
5570
|
-
t("agentsTip"),
|
|
5571
|
-
"muted",
|
|
5572
|
-
colorEnabled
|
|
5573
|
-
)
|
|
5574
|
-
].join("\n");
|
|
5387
|
+
return { kind: "bytes", bytes };
|
|
5575
5388
|
}
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
const
|
|
5584
|
-
const
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
const nextBuf2 = buffer.slice(0, insertAt2) + normalized + buffer.slice(insertAt2);
|
|
5596
|
-
return { buffer: nextBuf2, cursorPos: insertAt2 + normalized.length };
|
|
5597
|
-
}
|
|
5598
|
-
if (seq === "" || key.ctrl && key.name === "c") {
|
|
5599
|
-
return { buffer, cursorPos: curPos, abort: true };
|
|
5600
|
-
}
|
|
5601
|
-
if (seq === "\f" || key.ctrl && key.name === "l") {
|
|
5602
|
-
return { buffer, cursorPos: curPos, redraw: true };
|
|
5603
|
-
}
|
|
5604
|
-
if (seq === "" || key.ctrl && key.name === "o") {
|
|
5605
|
-
return { buffer, cursorPos: curPos };
|
|
5606
|
-
}
|
|
5607
|
-
if (seq === "\x1B[13;2~" || seq === "\x1B[27;2;13~" || seq === "\x1B\r" || key.shift && (key.name === "enter" || key.name === "return") || seq === "\n" || key.ctrl && key.name === "j") {
|
|
5608
|
-
const insertAt2 = snapCursorOutsidePasteChip(buffer, curPos);
|
|
5609
|
-
const nextBuf2 = buffer.slice(0, insertAt2) + "\n" + buffer.slice(insertAt2);
|
|
5610
|
-
return { buffer: nextBuf2, cursorPos: insertAt2 + 1 };
|
|
5611
|
-
}
|
|
5612
|
-
if (key.name === "enter" || key.name === "return" || seq === "\r") {
|
|
5613
|
-
return { buffer: "", cursorPos: 0, submit: buffer };
|
|
5614
|
-
}
|
|
5615
|
-
if (isLeftArrowSequence(seq, key)) {
|
|
5616
|
-
const span = findCollapsedPasteSpanAt(buffer, curPos, { preferLeft: true });
|
|
5617
|
-
if (span && curPos > span.start && curPos <= span.end) {
|
|
5618
|
-
return { buffer, cursorPos: span.start };
|
|
5619
|
-
}
|
|
5620
|
-
return { buffer, cursorPos: Math.max(0, curPos - 1) };
|
|
5621
|
-
}
|
|
5622
|
-
if (isRightArrowSequence(seq, key)) {
|
|
5623
|
-
const span = findCollapsedPasteSpanAt(buffer, curPos);
|
|
5624
|
-
if (span && curPos >= span.start && curPos < span.end) {
|
|
5625
|
-
return { buffer, cursorPos: span.end };
|
|
5626
|
-
}
|
|
5627
|
-
return { buffer, cursorPos: Math.min(buffer.length, curPos + 1) };
|
|
5628
|
-
}
|
|
5629
|
-
if (isHomeSequence(seq, key)) {
|
|
5630
|
-
return { buffer, cursorPos: 0 };
|
|
5631
|
-
}
|
|
5632
|
-
if (isEndSequence(seq, key)) {
|
|
5633
|
-
return { buffer, cursorPos: buffer.length };
|
|
5634
|
-
}
|
|
5635
|
-
if (isDeleteWordSequence(seq, key)) {
|
|
5636
|
-
if (curPos === 0) return { buffer, cursorPos: curPos };
|
|
5637
|
-
const pasteSpan = findCollapsedPasteSpanAt(buffer, curPos, {
|
|
5638
|
-
preferLeft: true
|
|
5389
|
+
async function readClipboardImage(deps = {}) {
|
|
5390
|
+
const env = deps.env ?? process.env;
|
|
5391
|
+
const platform = deps.platform ?? process.platform;
|
|
5392
|
+
const which = deps.which ?? Bun.which;
|
|
5393
|
+
const spawn = deps.spawn ?? Bun.spawn;
|
|
5394
|
+
const maxBytes = deps.maxBytes ?? DEFAULT_MAX_IMAGE_BYTES;
|
|
5395
|
+
const timeoutMs = deps.timeoutMs ?? DEFAULT_CLIPBOARD_TIMEOUT_MS;
|
|
5396
|
+
const tempDir = deps.tempDir ?? getDefaultClipboardTempDir();
|
|
5397
|
+
const { command, outputFormat } = getClipboardImageCommand({
|
|
5398
|
+
env,
|
|
5399
|
+
platform,
|
|
5400
|
+
which
|
|
5401
|
+
});
|
|
5402
|
+
let stdoutBuf;
|
|
5403
|
+
try {
|
|
5404
|
+
const proc = spawn(command, {
|
|
5405
|
+
stdin: "ignore",
|
|
5406
|
+
stdout: "pipe",
|
|
5407
|
+
stderr: "pipe"
|
|
5639
5408
|
});
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
if (
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
if (pasteSpan && (curPos === pasteSpan.start || curPos > pasteSpan.start && curPos < pasteSpan.end)) {
|
|
5673
|
-
return removePasteSpan(buffer, pasteSpan, pasteStore);
|
|
5409
|
+
let timeout;
|
|
5410
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
5411
|
+
timeout = setTimeout(() => {
|
|
5412
|
+
proc.kill();
|
|
5413
|
+
reject(
|
|
5414
|
+
new ClipboardImageError(
|
|
5415
|
+
"read-failed",
|
|
5416
|
+
"\u8BFB\u53D6\u526A\u8D34\u677F\u8D85\u65F6\uFF0C\u526A\u8D34\u677F\u540E\u7AEF\u53EF\u80FD\u65E0\u54CD\u5E94"
|
|
5417
|
+
)
|
|
5418
|
+
);
|
|
5419
|
+
}, timeoutMs);
|
|
5420
|
+
});
|
|
5421
|
+
try {
|
|
5422
|
+
const [stdoutArrayBuffer, stderrText, exitCode] = await Promise.race([
|
|
5423
|
+
Promise.all([
|
|
5424
|
+
new Response(proc.stdout).arrayBuffer(),
|
|
5425
|
+
new Response(proc.stderr).text(),
|
|
5426
|
+
proc.exited
|
|
5427
|
+
]),
|
|
5428
|
+
timeoutPromise
|
|
5429
|
+
]);
|
|
5430
|
+
if (exitCode !== 0 || stdoutArrayBuffer.byteLength === 0) {
|
|
5431
|
+
if (outputFormat === "osascript-hex") {
|
|
5432
|
+
throw new ClipboardImageError(
|
|
5433
|
+
"empty-clipboard",
|
|
5434
|
+
OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE + (stderrText.trim() ? `: ${stderrText.trim()}` : "")
|
|
5435
|
+
);
|
|
5436
|
+
}
|
|
5437
|
+
throw new ClipboardImageError(
|
|
5438
|
+
"empty-clipboard",
|
|
5439
|
+
"\u526A\u8D34\u677F\u4E2D\u6CA1\u6709\u56FE\u50CF\u6570\u636E\uFF0C\u8BF7\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6\u6216\u8F93\u5165\u56FE\u7247\u8DEF\u5F84" + (stderrText.trim() ? `: ${stderrText.trim()}` : "")
|
|
5440
|
+
);
|
|
5674
5441
|
}
|
|
5675
|
-
|
|
5676
|
-
|
|
5442
|
+
stdoutBuf = new Uint8Array(stdoutArrayBuffer);
|
|
5443
|
+
} finally {
|
|
5444
|
+
clearTimeout(timeout);
|
|
5677
5445
|
}
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5446
|
+
} catch (err) {
|
|
5447
|
+
if (err instanceof ClipboardImageError) {
|
|
5448
|
+
throw err;
|
|
5681
5449
|
}
|
|
5682
|
-
|
|
5450
|
+
throw new ClipboardImageError(
|
|
5451
|
+
"read-failed",
|
|
5452
|
+
`\u8BFB\u53D6\u526A\u8D34\u677F\u56FE\u50CF\u5931\u8D25: ${err instanceof Error ? err.message : String(err)}`
|
|
5453
|
+
);
|
|
5683
5454
|
}
|
|
5684
|
-
if (
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
return { buffer, cursorPos: curPos };
|
|
5693
|
-
}
|
|
5455
|
+
if (outputFormat === "osascript-hex") {
|
|
5456
|
+
const text = Buffer.from(stdoutBuf).toString("utf8");
|
|
5457
|
+
const decoded = decodeOsascriptPngHex(text);
|
|
5458
|
+
if (decoded.kind === "empty") {
|
|
5459
|
+
throw new ClipboardImageError(
|
|
5460
|
+
"empty-clipboard",
|
|
5461
|
+
OSASCRIPT_EMPTY_CLIPBOARD_MESSAGE
|
|
5462
|
+
);
|
|
5694
5463
|
}
|
|
5695
|
-
|
|
5696
|
-
|
|
5464
|
+
if (decoded.kind === "invalid") {
|
|
5465
|
+
throw new ClipboardImageError(
|
|
5466
|
+
"read-failed",
|
|
5467
|
+
"\u526A\u8D34\u677F\u56FE\u50CF\u6570\u636E\u65E0\u6CD5\u89E3\u6790\uFF08hex \u7F16\u7801\u635F\u574F\uFF09\uFF0C\u8BF7\u91CD\u65B0\u590D\u5236\u56FE\u7247\u540E\u91CD\u8BD5\uFF0C\u6216\u76F4\u63A5\u62D6\u5165\u56FE\u7247\u6587\u4EF6/\u8F93\u5165\u56FE\u7247\u8DEF\u5F84"
|
|
5468
|
+
);
|
|
5469
|
+
}
|
|
5470
|
+
stdoutBuf = decoded.bytes;
|
|
5697
5471
|
}
|
|
5698
|
-
|
|
5699
|
-
|
|
5472
|
+
const compressResult = await compressImage(stdoutBuf, "image/png");
|
|
5473
|
+
const finalBuf = compressResult.buffer;
|
|
5474
|
+
const finalMime = compressResult.mime;
|
|
5475
|
+
const finalSizeBytes = finalBuf.byteLength;
|
|
5476
|
+
if (finalSizeBytes > maxBytes) {
|
|
5477
|
+
throw new ClipboardImageError(
|
|
5478
|
+
"too-large",
|
|
5479
|
+
`\u526A\u8D34\u677F\u56FE\u50CF\u8FC7\u5927: ${formatBytes(finalSizeBytes)} (\u4E0A\u9650 ${formatBytes(maxBytes)})`
|
|
5480
|
+
);
|
|
5700
5481
|
}
|
|
5701
|
-
const
|
|
5702
|
-
const
|
|
5703
|
-
|
|
5704
|
-
}
|
|
5705
|
-
|
|
5706
|
-
|
|
5707
|
-
|
|
5708
|
-
|
|
5482
|
+
const hash = createHash("sha256").update(finalBuf).digest("hex").slice(0, 12);
|
|
5483
|
+
const ext = mimeToExtension(finalMime);
|
|
5484
|
+
const filename = `clip-${hash}.${ext}`;
|
|
5485
|
+
mkdirSync(tempDir, { recursive: true });
|
|
5486
|
+
const filePath = join(tempDir, filename);
|
|
5487
|
+
await writeFile(filePath, finalBuf);
|
|
5488
|
+
return buildAttachedImage({
|
|
5489
|
+
buffer: finalBuf,
|
|
5490
|
+
mime: finalMime,
|
|
5491
|
+
filename,
|
|
5492
|
+
sourcePath: filePath,
|
|
5493
|
+
originalSizeBytes: compressResult.compressed ? compressResult.originalBytes : void 0
|
|
5494
|
+
});
|
|
5709
5495
|
}
|
|
5710
|
-
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
return
|
|
5496
|
+
|
|
5497
|
+
// packages/cli/tui/pasteFlow.ts
|
|
5498
|
+
function isTextFallbackEligibleCode(code) {
|
|
5499
|
+
return code === "empty-clipboard" || code === "binary-missing" || code === "unsupported-platform";
|
|
5714
5500
|
}
|
|
5715
|
-
function
|
|
5716
|
-
if (
|
|
5717
|
-
|
|
5718
|
-
return
|
|
5501
|
+
function errorCodeOf(error) {
|
|
5502
|
+
if (typeof error !== "object" || error === null) return void 0;
|
|
5503
|
+
const code = error.code;
|
|
5504
|
+
return code === void 0 || code === null ? void 0 : String(code);
|
|
5719
5505
|
}
|
|
5720
|
-
function
|
|
5721
|
-
|
|
5722
|
-
if (key.ctrl && key.name === "a") return true;
|
|
5723
|
-
if (seq === "" || seq === "\x1B[H" || seq === "\x1B[1~" || seq === "\x1B[7~" || seq === "\x1BOH") return true;
|
|
5724
|
-
return false;
|
|
5506
|
+
function messageOf(error) {
|
|
5507
|
+
return error instanceof Error ? error.message : String(error);
|
|
5725
5508
|
}
|
|
5726
|
-
function
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5509
|
+
async function resolveClipboardPaste(deps) {
|
|
5510
|
+
try {
|
|
5511
|
+
const image = await deps.readImage();
|
|
5512
|
+
return { kind: "image", image };
|
|
5513
|
+
} catch (imageError) {
|
|
5514
|
+
const code = errorCodeOf(imageError);
|
|
5515
|
+
if (!isTextFallbackEligibleCode(code)) {
|
|
5516
|
+
return {
|
|
5517
|
+
kind: "error",
|
|
5518
|
+
code: code ?? "read-failed",
|
|
5519
|
+
message: messageOf(imageError)
|
|
5520
|
+
};
|
|
5521
|
+
}
|
|
5522
|
+
let text;
|
|
5523
|
+
try {
|
|
5524
|
+
text = await deps.readText();
|
|
5525
|
+
} catch (textError) {
|
|
5526
|
+
return {
|
|
5527
|
+
kind: "error",
|
|
5528
|
+
code: "text-read-failed",
|
|
5529
|
+
message: `${messageOf(textError)} (${messageOf(imageError)})`
|
|
5530
|
+
};
|
|
5531
|
+
}
|
|
5532
|
+
if (text.length > 0) {
|
|
5533
|
+
return { kind: "text", text };
|
|
5534
|
+
}
|
|
5535
|
+
return { kind: "empty", message: messageOf(imageError) };
|
|
5536
|
+
}
|
|
5731
5537
|
}
|
|
5732
|
-
function
|
|
5733
|
-
if (
|
|
5734
|
-
|
|
5735
|
-
return { buffer: nextBuf, cursorPos: span.start };
|
|
5538
|
+
function shouldApplyPastedResult(snapshot, current) {
|
|
5539
|
+
if (current.sessionEnded) return false;
|
|
5540
|
+
return snapshot.epoch === current.epoch;
|
|
5736
5541
|
}
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
return { buffer: nextBuf, cursorPos: range.start };
|
|
5542
|
+
|
|
5543
|
+
// packages/cli/tui/clipboard.ts
|
|
5544
|
+
function osc52SetClipboard(text, output) {
|
|
5545
|
+
const payload = Buffer.from(text, "utf8").toString("base64");
|
|
5546
|
+
output.write(`\x1B]52;c;${payload}\x07`);
|
|
5743
5547
|
}
|
|
5744
|
-
function
|
|
5745
|
-
if (
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5548
|
+
async function writeClipboard(text, target) {
|
|
5549
|
+
if (target.transport === "system") {
|
|
5550
|
+
await target.systemWrite(text);
|
|
5551
|
+
return;
|
|
5552
|
+
}
|
|
5553
|
+
if (target.transport === "osc52") {
|
|
5554
|
+
osc52SetClipboard(text, target.output);
|
|
5555
|
+
return;
|
|
5751
5556
|
}
|
|
5557
|
+
throw new Error(
|
|
5558
|
+
"Client clipboard is unavailable in a non-interactive remote session."
|
|
5559
|
+
);
|
|
5752
5560
|
}
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
if (
|
|
5758
|
-
|
|
5759
|
-
preferLeft: true
|
|
5760
|
-
});
|
|
5761
|
-
if (spanAtCursor && (i === spanAtCursor.end || i > spanAtCursor.start && i < spanAtCursor.end)) {
|
|
5762
|
-
return spanAtCursor.start;
|
|
5561
|
+
|
|
5562
|
+
// packages/cli/tui/gitStatus.ts
|
|
5563
|
+
import { execFile, execSync } from "node:child_process";
|
|
5564
|
+
function parseStatusOutput(branch, status) {
|
|
5565
|
+
if (!status) {
|
|
5566
|
+
return { branch, modified: 0, untracked: 0 };
|
|
5763
5567
|
}
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
if (
|
|
5768
|
-
|
|
5568
|
+
let modified = 0;
|
|
5569
|
+
let untracked = 0;
|
|
5570
|
+
for (const line of status.split("\n")) {
|
|
5571
|
+
if (!line) continue;
|
|
5572
|
+
const flag = line[0];
|
|
5573
|
+
if (flag === "?") untracked += 1;
|
|
5574
|
+
else modified += 1;
|
|
5769
5575
|
}
|
|
5770
|
-
return
|
|
5576
|
+
return { branch, modified, untracked };
|
|
5771
5577
|
}
|
|
5772
|
-
function
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5578
|
+
function execFileUtf8(file, args, cwd) {
|
|
5579
|
+
return new Promise((resolve4, reject) => {
|
|
5580
|
+
execFile(
|
|
5581
|
+
file,
|
|
5582
|
+
args,
|
|
5583
|
+
{ cwd, encoding: "utf8", timeout: 2e3 },
|
|
5584
|
+
(err, stdout) => {
|
|
5585
|
+
if (err) {
|
|
5586
|
+
reject(err);
|
|
5587
|
+
return;
|
|
5588
|
+
}
|
|
5589
|
+
resolve4(typeof stdout === "string" ? stdout : String(stdout ?? ""));
|
|
5590
|
+
}
|
|
5591
|
+
);
|
|
5592
|
+
});
|
|
5777
5593
|
}
|
|
5778
|
-
function
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5594
|
+
function detectGitStatusAsync(cwd) {
|
|
5595
|
+
return (async () => {
|
|
5596
|
+
try {
|
|
5597
|
+
const branch = (await execFileUtf8("git", ["rev-parse", "--abbrev-ref", "HEAD"], cwd)).trim();
|
|
5598
|
+
if (!branch) return void 0;
|
|
5599
|
+
const status = (await execFileUtf8("git", ["status", "--porcelain"], cwd)).trim();
|
|
5600
|
+
return parseStatusOutput(branch, status);
|
|
5601
|
+
} catch {
|
|
5602
|
+
return void 0;
|
|
5603
|
+
}
|
|
5604
|
+
})();
|
|
5782
5605
|
}
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5606
|
+
|
|
5607
|
+
// packages/cli/tui/sessionRender.ts
|
|
5608
|
+
function formatCwd(cwd) {
|
|
5609
|
+
const parts = cwd.split(/[/\\]/);
|
|
5610
|
+
return parts.pop() || cwd;
|
|
5787
5611
|
}
|
|
5788
|
-
function
|
|
5789
|
-
if (
|
|
5790
|
-
|
|
5791
|
-
|
|
5612
|
+
function formatElapsedSeconds(totalSeconds) {
|
|
5613
|
+
if (totalSeconds < 60) return `${totalSeconds}s`;
|
|
5614
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
5615
|
+
const seconds = totalSeconds % 60;
|
|
5616
|
+
if (minutes < 60) return `${minutes}m ${seconds}s`;
|
|
5617
|
+
const hours = Math.floor(minutes / 60);
|
|
5618
|
+
const mins = minutes % 60;
|
|
5619
|
+
return `${hours}h ${mins}m`;
|
|
5792
5620
|
}
|
|
5793
|
-
function
|
|
5794
|
-
|
|
5795
|
-
|
|
5621
|
+
function renderComposerTokenChip(tokens, fallbackContextWindow, estimatedContextTokens) {
|
|
5622
|
+
const cw = tokens?.contextWindow ?? fallbackContextWindow;
|
|
5623
|
+
if (!cw) {
|
|
5624
|
+
return "context: \u2014";
|
|
5625
|
+
}
|
|
5626
|
+
const used = tokens ? tokens.input + tokens.output : Math.max(0, estimatedContextTokens ?? 0);
|
|
5627
|
+
const pct = Math.min(100, used / cw * 100);
|
|
5628
|
+
const pctText = pct > 0 && pct < 10 ? pct.toFixed(1) : Math.round(pct).toString();
|
|
5629
|
+
return `context: ${pctText}% (${formatTokenCount(used)}/${formatTokenCount(cw)})`;
|
|
5796
5630
|
}
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
"/context",
|
|
5804
|
-
"/ctx",
|
|
5805
|
-
"/credits",
|
|
5806
|
-
"/links",
|
|
5807
|
-
"/cd",
|
|
5808
|
-
"/runtime",
|
|
5809
|
-
"/auto",
|
|
5810
|
-
"/switch",
|
|
5811
|
-
"/agent",
|
|
5812
|
-
"/agents",
|
|
5813
|
-
"/history",
|
|
5814
|
-
"/resume",
|
|
5815
|
-
"/lang",
|
|
5816
|
-
"/copy",
|
|
5817
|
-
"/paste",
|
|
5818
|
-
"/mouse",
|
|
5819
|
-
"/math",
|
|
5820
|
-
"/doc",
|
|
5821
|
-
"/skill",
|
|
5822
|
-
"/customize",
|
|
5823
|
-
"/login",
|
|
5824
|
-
"/profile",
|
|
5825
|
-
"/update",
|
|
5826
|
-
"/version",
|
|
5827
|
-
"/logs",
|
|
5828
|
-
"/tasks",
|
|
5829
|
-
"/jobs",
|
|
5830
|
-
"/procs",
|
|
5831
|
-
"/stop",
|
|
5832
|
-
"/exit",
|
|
5833
|
-
"/quit"
|
|
5834
|
-
];
|
|
5835
|
-
function completeSlashPrefix(buffer) {
|
|
5836
|
-
if (!buffer.startsWith("/") || /\s/.test(buffer)) return null;
|
|
5837
|
-
const matches = SLASH_COMMANDS.filter((cmd) => cmd.startsWith(buffer));
|
|
5838
|
-
if (matches.length === 0) return null;
|
|
5839
|
-
if (matches.length === 1) {
|
|
5840
|
-
return `${matches[0]} `;
|
|
5631
|
+
function resolveStatusLineCredits(state) {
|
|
5632
|
+
const base = state.dialogCreditsBase;
|
|
5633
|
+
const session = state.sessionCredits;
|
|
5634
|
+
const live = state.liveTurnCredits;
|
|
5635
|
+
if (base === void 0 && session === void 0 && live === void 0) {
|
|
5636
|
+
return void 0;
|
|
5841
5637
|
}
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5638
|
+
return (base ?? 0) + (session ?? 0) + (live ?? 0);
|
|
5639
|
+
}
|
|
5640
|
+
function renderStatusLine(state, maxWidth) {
|
|
5641
|
+
const colorEnabled = resolveCliColorEnabled();
|
|
5642
|
+
const sep = themeText(" \xB7 ", "chrome", colorEnabled);
|
|
5643
|
+
const agentDisplayName = state.agentName;
|
|
5644
|
+
const modeSuffix = state.modeLabel && state.modeLabel !== "auto" ? ` \xB7 ${state.modeLabel}` : "";
|
|
5645
|
+
const agentLabel = `\u2726 ${agentDisplayName}${modeSuffix}`;
|
|
5646
|
+
const agentSegment = themeText(agentLabel, "accent", colorEnabled);
|
|
5647
|
+
const cwdSegment = themeText(`\u{1F4C1} ${formatCwd(state.cwd)}`, "info", colorEnabled);
|
|
5648
|
+
const parts = [agentSegment, cwdSegment];
|
|
5649
|
+
if (state.gitStatus) {
|
|
5650
|
+
const { branch, modified, untracked } = state.gitStatus;
|
|
5651
|
+
const branchText = themeText(`\u2442 ${branch}`, "warning", colorEnabled);
|
|
5652
|
+
const modifiedText = modified > 0 ? ` ${themeText(`*${modified}`, "danger", colorEnabled)}` : "";
|
|
5653
|
+
const untrackedText = untracked > 0 ? ` ${themeText(`?${untracked}`, "muted", colorEnabled)}` : "";
|
|
5654
|
+
parts.push(`${branchText}${modifiedText}${untrackedText}`);
|
|
5655
|
+
}
|
|
5656
|
+
const credits = resolveStatusLineCredits(state);
|
|
5657
|
+
const tokenSegment = themeText(
|
|
5658
|
+
renderComposerTokenChip(
|
|
5659
|
+
state.turnTokens,
|
|
5660
|
+
state.contextWindow,
|
|
5661
|
+
state.estimatedContextTokens
|
|
5662
|
+
),
|
|
5663
|
+
"muted",
|
|
5664
|
+
colorEnabled
|
|
5665
|
+
);
|
|
5666
|
+
const creditsSegment = credits !== void 0 && credits > 0 ? themeText(formatCreditsChip(credits), "muted", colorEnabled) : "";
|
|
5667
|
+
parts.push(tokenSegment);
|
|
5668
|
+
if (creditsSegment) parts.push(creditsSegment);
|
|
5669
|
+
const runningTaskCount = getProcessRegistry().listBackground().filter((p) => p.status === "running").length;
|
|
5670
|
+
if (runningTaskCount > 0) {
|
|
5671
|
+
parts.push(themeText(`\u2699 ${runningTaskCount} running`, "info", colorEnabled));
|
|
5672
|
+
}
|
|
5673
|
+
const pendingProcessCount = state.pendingProcessNotices?.length ?? 0;
|
|
5674
|
+
if (pendingProcessCount > 0) {
|
|
5675
|
+
parts.push(themeText(`\u2699 ${pendingProcessCount} finished`, "info", colorEnabled));
|
|
5676
|
+
}
|
|
5677
|
+
if (state.autoConfirm === true) {
|
|
5678
|
+
parts.push(themeText("\u23F5 auto", "warning", colorEnabled));
|
|
5679
|
+
}
|
|
5680
|
+
let visibleParts = parts;
|
|
5681
|
+
if (maxWidth && maxWidth > 0) {
|
|
5682
|
+
const widthOf = (segments) => displayWidth(stripAnsi(segments.join(" \xB7 "))) + 2;
|
|
5683
|
+
for (const optional of [cwdSegment, agentSegment, tokenSegment, creditsSegment]) {
|
|
5684
|
+
if (!optional) continue;
|
|
5685
|
+
if (widthOf(visibleParts) <= maxWidth) break;
|
|
5686
|
+
visibleParts = visibleParts.filter((part) => part !== optional);
|
|
5687
|
+
}
|
|
5688
|
+
if (widthOf(visibleParts) > maxWidth && state.gitStatus) {
|
|
5689
|
+
const gitIndex = visibleParts.findIndex((part) => stripAnsi(part).startsWith("\u2442 "));
|
|
5690
|
+
if (gitIndex >= 0) {
|
|
5691
|
+
const { modified, untracked } = state.gitStatus;
|
|
5692
|
+
const compactDirty = themeText(
|
|
5693
|
+
`\u2442${modified > 0 ? ` *${modified}` : ""}${untracked > 0 ? ` ?${untracked}` : ""}`,
|
|
5694
|
+
"warning",
|
|
5695
|
+
colorEnabled
|
|
5696
|
+
);
|
|
5697
|
+
visibleParts = visibleParts.with(gitIndex, compactDirty);
|
|
5698
|
+
}
|
|
5699
|
+
}
|
|
5700
|
+
if (widthOf(visibleParts) > maxWidth) {
|
|
5701
|
+
const emergency = [];
|
|
5702
|
+
if (state.autoConfirm === true) {
|
|
5703
|
+
emergency.push(themeText("\u23F5", "warning", colorEnabled));
|
|
5704
|
+
}
|
|
5705
|
+
const runningTotal = runningTaskCount;
|
|
5706
|
+
if (runningTotal > 0) {
|
|
5707
|
+
emergency.push(themeText(`\u2699${runningTotal}`, "info", colorEnabled));
|
|
5708
|
+
}
|
|
5709
|
+
if (state.gitStatus) {
|
|
5710
|
+
const { modified, untracked } = state.gitStatus;
|
|
5711
|
+
emergency.push(themeText(
|
|
5712
|
+
`\u2442${modified > 0 ? `*${modified}` : ""}${untracked > 0 ? `?${untracked}` : ""}`,
|
|
5713
|
+
"warning",
|
|
5714
|
+
colorEnabled
|
|
5715
|
+
));
|
|
5716
|
+
}
|
|
5717
|
+
if (creditsSegment) {
|
|
5718
|
+
emergency.push(themeText(formatCreditsChip(credits ?? 0, { compact: true }), "muted", colorEnabled));
|
|
5719
|
+
}
|
|
5720
|
+
visibleParts = [emergency.join(" ")];
|
|
5721
|
+
}
|
|
5845
5722
|
}
|
|
5846
|
-
|
|
5723
|
+
const body = visibleParts.join(sep);
|
|
5724
|
+
const surface = colorEnabled ? surfaceBackgroundSequence() : "";
|
|
5725
|
+
if (!surface) return body;
|
|
5726
|
+
return `${surface} ${body} \x1B[49m`;
|
|
5847
5727
|
}
|
|
5848
|
-
function
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
const
|
|
5853
|
-
|
|
5728
|
+
function buildPlainScene(isDark, frame = 0, maxFrames = 0) {
|
|
5729
|
+
let skyLine = null;
|
|
5730
|
+
if (isDark === true) {
|
|
5731
|
+
const star1 = frame % 6 < 3 ? "\u2726" : "\u22C6";
|
|
5732
|
+
const star2 = frame % 4 < 2 ? "\u22C6" : "\xB7";
|
|
5733
|
+
const star3 = frame % 5 < 2 ? "\xB7" : "\u2726";
|
|
5734
|
+
skyLine = ` ${star1} \u263E ${star2} ${star3}`;
|
|
5735
|
+
} else if (isDark === false) {
|
|
5736
|
+
skyLine = ` \u2600`;
|
|
5854
5737
|
}
|
|
5855
|
-
|
|
5856
|
-
|
|
5738
|
+
const wavePattern = "_.~^~.";
|
|
5739
|
+
const longWave = wavePattern.repeat(10);
|
|
5740
|
+
const offset = frame % wavePattern.length;
|
|
5741
|
+
const wave = longWave.slice(offset, offset + 25);
|
|
5742
|
+
return [
|
|
5743
|
+
...skyLine ? [skyLine] : [],
|
|
5744
|
+
" \u2571\u2572 \u2588\u2584 \u2588 \u2584\u2580\u2580\u2584 \u2588 \u2584\u2580\u2580\u2584",
|
|
5745
|
+
" \u2571 \u2572 \u2571\u2572 \u2588 \u2580\u2588 \u2588 \u2588 \u2588 \u2588 \u2588",
|
|
5746
|
+
" \u2571 \u2572\u2571 \u2572 \u2580 \u2580 \u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580",
|
|
5747
|
+
` \u2571 \u2660 \u2572 ${wave}`,
|
|
5748
|
+
" \u2581\u2581\u2581\u2581\u2581\u2581\u2571 \u2660 \u2660 \u2572\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581"
|
|
5749
|
+
].join("\n");
|
|
5857
5750
|
}
|
|
5858
|
-
function
|
|
5859
|
-
const
|
|
5860
|
-
const
|
|
5861
|
-
const
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5751
|
+
function buildColoredScene(isDark, frame = 0, maxFrames = 0) {
|
|
5752
|
+
const pk = themeColorSequence("chrome");
|
|
5753
|
+
const sk = themeColorSequence("warning");
|
|
5754
|
+
const tr = themeColorSequence("success");
|
|
5755
|
+
const wv = themeColorSequence("info");
|
|
5756
|
+
const ac = themeColorSequence("accent");
|
|
5757
|
+
const mu = themeColorSequence("muted");
|
|
5758
|
+
const r = "\x1B[39m";
|
|
5759
|
+
const b = "\x1B[1m";
|
|
5760
|
+
const rs = "\x1B[0m";
|
|
5761
|
+
let skyLine = null;
|
|
5762
|
+
if (isDark === true) {
|
|
5763
|
+
const star1 = frame % 6 < 3 ? "\u2726" : "\u22C6";
|
|
5764
|
+
const star2 = frame % 4 < 2 ? "\u22C6" : "\xB7";
|
|
5765
|
+
const star3 = frame % 5 < 2 ? "\xB7" : "\u2726";
|
|
5766
|
+
skyLine = ` ${mu}${star1}${r} ${sk}\u263E${r} ${mu}${star2}${r} ${mu}${star3}${r}`;
|
|
5767
|
+
} else if (isDark === false) {
|
|
5768
|
+
skyLine = ` ${sk}\u2600${r}`;
|
|
5869
5769
|
}
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5770
|
+
const wavePattern = "_.~^~.";
|
|
5771
|
+
const longWave = wavePattern.repeat(10);
|
|
5772
|
+
const offset = frame % wavePattern.length;
|
|
5773
|
+
const wave = longWave.slice(offset, offset + 25);
|
|
5774
|
+
const waveStr = `${wv}${wave.slice(0, 20)}${r}${mu}${wave.slice(20, 25)}${r}`;
|
|
5775
|
+
const line1 = "\u2588\u2584 \u2588 \u2584\u2580\u2580\u2584 \u2588 \u2584\u2580\u2580\u2584";
|
|
5776
|
+
const line2 = "\u2588 \u2580\u2588 \u2588 \u2588 \u2588 \u2588 \u2588";
|
|
5777
|
+
const line3 = "\u2580 \u2580 \u2580\u2580 \u2580\u2580\u2580\u2580 \u2580\u2580";
|
|
5778
|
+
const sweepEndFrame = maxFrames > 3 ? maxFrames - 3 : maxFrames;
|
|
5779
|
+
const sweepLen = maxFrames === 0 ? 21 : Math.min(21, Math.floor(frame / sweepEndFrame * 21));
|
|
5780
|
+
const colorLine = (str, bold) => {
|
|
5781
|
+
const active = str.slice(0, sweepLen);
|
|
5782
|
+
const dimmed = str.slice(sweepLen);
|
|
5783
|
+
return `${bold ? b : ""}${ac}${active}${r}${mu}${dimmed}${r}${bold ? rs : ""}`;
|
|
5784
|
+
};
|
|
5785
|
+
const nolo1 = colorLine(line1, true);
|
|
5786
|
+
const nolo2 = colorLine(line2, false);
|
|
5787
|
+
const nolo3 = colorLine(line3, false);
|
|
5788
|
+
return [
|
|
5789
|
+
...skyLine ? [skyLine] : [],
|
|
5790
|
+
` ${pk}\u2571\u2572${r} ${nolo1}`,
|
|
5791
|
+
` ${pk}\u2571 \u2572 \u2571\u2572${r} ${nolo2}`,
|
|
5792
|
+
` ${pk}\u2571 \u2572\u2571 \u2572${r} ${nolo3}`,
|
|
5793
|
+
` ${pk}\u2571${r} ${tr}\u2660${r} ${pk}\u2572${r} ${waveStr}`,
|
|
5794
|
+
` ${pk}\u2581\u2581\u2581\u2581\u2581\u2581\u2571${r} ${tr}\u2660${r} ${tr}\u2660${r} ${pk}\u2572\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581${r}`
|
|
5795
|
+
].join("\n");
|
|
5796
|
+
}
|
|
5797
|
+
function renderWelcome(state, frame = 0, maxFrames = 0, columns) {
|
|
5798
|
+
const colorEnabled = resolveCliColorEnabled();
|
|
5799
|
+
const brightnessSignal = resolveTuiBrightnessSignal();
|
|
5800
|
+
const isDark = brightnessSignal === null ? null : brightnessSignal === "dark";
|
|
5801
|
+
let sceneArt = colorEnabled ? buildColoredScene(isDark, frame, maxFrames) : buildPlainScene(isDark, frame, maxFrames);
|
|
5802
|
+
if (typeof columns === "number" && columns > 0) {
|
|
5803
|
+
const widestSceneCol = sceneArt.split("\n").reduce((max, line) => Math.max(max, displayWidth(stripAnsi(line))), 0);
|
|
5804
|
+
if (columns < widestSceneCol) sceneArt = "";
|
|
5875
5805
|
}
|
|
5876
|
-
const
|
|
5877
|
-
const
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
|
|
5882
|
-
|
|
5883
|
-
|
|
5806
|
+
const noloLabel = themeText("nolo", "accent", colorEnabled);
|
|
5807
|
+
const versionLine = `${noloLabel}${state.cliVersion ? ` ${state.cliVersion}` : ""} | server ${state.serverUrl}`;
|
|
5808
|
+
const updateLine = state.updateAvailable ? themeText(
|
|
5809
|
+
t("updateAvailable", state.updateAvailable.latestVersion),
|
|
5810
|
+
"accent",
|
|
5811
|
+
colorEnabled
|
|
5812
|
+
) : null;
|
|
5813
|
+
const authGuidanceLine = state.showAuthGuidance ? t("welcomeAuthGuidance") : null;
|
|
5814
|
+
const body = sceneArt ? [sceneArt, versionLine, ...updateLine ? [updateLine] : [], ...authGuidanceLine ? [authGuidanceLine] : [], dailyWelcomeTip(), ""] : [versionLine, ...updateLine ? [updateLine] : [], ...authGuidanceLine ? [authGuidanceLine] : [], dailyWelcomeTip(), ""];
|
|
5815
|
+
return body.join("\n");
|
|
5816
|
+
}
|
|
5817
|
+
function renderPrompt(_state) {
|
|
5818
|
+
return t("promptLabel");
|
|
5819
|
+
}
|
|
5820
|
+
function renderTuiHelp(colorEnabled = resolveCliColorEnabled()) {
|
|
5821
|
+
const text = t("helpText");
|
|
5822
|
+
if (!colorEnabled) {
|
|
5823
|
+
return text;
|
|
5824
|
+
}
|
|
5825
|
+
const lines = text.split("\n");
|
|
5826
|
+
const commandRegex = /^(\s+)(\/\S+(?:\s+\S+)*?)(\s{2,})(.+)$/;
|
|
5827
|
+
const sectionRegex = /^\S.+[::]$/;
|
|
5828
|
+
return lines.map((line) => {
|
|
5829
|
+
if (!line.trim()) {
|
|
5830
|
+
return line;
|
|
5884
5831
|
}
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5832
|
+
if (sectionRegex.test(line)) {
|
|
5833
|
+
return renderDialogTitle(line, colorEnabled);
|
|
5834
|
+
}
|
|
5835
|
+
const match = line.match(commandRegex);
|
|
5836
|
+
if (match) {
|
|
5837
|
+
const [, indent, cmd, spacing, desc] = match;
|
|
5838
|
+
return `${indent}${themeText(cmd, "accent", colorEnabled)}${spacing}${themeText(desc, "muted", colorEnabled)}`;
|
|
5839
|
+
}
|
|
5840
|
+
return themeText(line, "muted", colorEnabled);
|
|
5841
|
+
}).join("\n");
|
|
5890
5842
|
}
|
|
5891
|
-
function
|
|
5892
|
-
const
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5843
|
+
function renderCreditsDebug(state, colorEnabled = resolveCliColorEnabled()) {
|
|
5844
|
+
const credits = resolveStatusLineCredits(state);
|
|
5845
|
+
const lines = [
|
|
5846
|
+
"[credits debug] \u79EF\u5206\u94FE\u8DEF\u771F\u503C",
|
|
5847
|
+
`\u2022 dialogCreditsBase : ${state.dialogCreditsBase?.toFixed(4) ?? "undefined\uFF08\u670D\u52A1\u7AEF\u57FA\u6570\u672A seed\u2014\u2014/pick \u540E\u9996\u6B21\u8BFB\u53D6\u5931\u8D25\u6216\u670D\u52A1\u7AEF\u672A\u5199 totalCost\uFF09"}`,
|
|
5848
|
+
`\u2022 sessionCredits : ${state.sessionCredits?.toFixed(4) ?? "undefined\uFF08\u672C\u4F1A\u8BDD\u8FD8\u6CA1\u6709\u5E73\u53F0\u8BA1\u8D39\u8F6E\uFF09"}`,
|
|
5849
|
+
`\u2022 \u72B6\u6001\u884C\u663E\u793A : ${credits !== void 0 && credits > 0 ? formatCreditsChip(credits) : "\uFF08\u65E0 \u26A1\u2014\u2014\u4E24\u6BB5\u5408\u8BA1\u4E3A 0/undefined\uFF09"}`,
|
|
5850
|
+
`\u2022 turnTokens.credits: ${state.turnTokens?.credits?.toFixed(4) ?? "undefined"}\uFF08\u672C\u8F6E\u6700\u540E\u4E00\u6B21\u8C03\u7528\u7684\u6298\u7B97\u503C\uFF0C\u4EC5\u4F9B\u53C2\u8003\uFF0C\u4E0D\u8FDB\u72B6\u6001\u884C\uFF09`,
|
|
5851
|
+
`\u2022 contextWindow : ${state.contextWindow ?? "unknown"}`,
|
|
5852
|
+
'\u2022 \u5224\u5B9A\u53E3\u5F84\uFF1A\u53EA\u6709 billing_unit === "credits" \u7684\u5E73\u53F0\u8BA1\u8D39\u5E27\u624D\u7D2F\u8BA1\uFF1B\u81EA\u6709 API / \u8BA2\u9605\u5236\u6052\u4E3A undefined\u3002',
|
|
5853
|
+
"\u2022 \u82E5\u521A\u8DD1\u5B8C\u5E73\u53F0\u8BA1\u8D39\u8F6E\u4ECD\u65E0 \u26A1\uFF1A\u68C0\u67E5 runAgentTurn \u8FD4\u56DE\u662F\u5426\u5E26 turnCredits\uFF08foldLocalResultForTui \u767D\u540D\u5355\uFF09\u3002"
|
|
5854
|
+
];
|
|
5855
|
+
return lines.map((line) => colorEnabled ? themeText(line, "chrome") : line).join("\n");
|
|
5897
5856
|
}
|
|
5898
|
-
function
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5857
|
+
function renderContextPanel(state, colorEnabled = resolveCliColorEnabled()) {
|
|
5858
|
+
const docs = state.attachedDocs.length ? state.attachedDocs.join(", ") : "none";
|
|
5859
|
+
const skills = state.attachedSkills.length ? state.attachedSkills.join(", ") : "none";
|
|
5860
|
+
const labels = [
|
|
5861
|
+
t("contextFieldAgent"),
|
|
5862
|
+
t("contextFieldTokens"),
|
|
5863
|
+
t("contextFieldDialog"),
|
|
5864
|
+
t("contextFieldDocs"),
|
|
5865
|
+
t("contextFieldSkills"),
|
|
5866
|
+
t("contextFieldProfile"),
|
|
5867
|
+
t("contextFieldRuntime"),
|
|
5868
|
+
t("contextFieldServer")
|
|
5869
|
+
];
|
|
5870
|
+
let maxW = 0;
|
|
5871
|
+
for (const l of labels) {
|
|
5872
|
+
const w = displayWidth(l);
|
|
5873
|
+
if (w > maxW) maxW = w;
|
|
5905
5874
|
}
|
|
5906
|
-
|
|
5875
|
+
const targetWidth = maxW >= 9 ? maxW + 1 : 9;
|
|
5876
|
+
const padLabel = (raw) => {
|
|
5877
|
+
const w = displayWidth(raw);
|
|
5878
|
+
const padding = " ".repeat(Math.max(0, targetWidth - w));
|
|
5879
|
+
return raw + padding;
|
|
5880
|
+
};
|
|
5881
|
+
const field = (rawLabel, value) => `${themeText(padLabel(rawLabel), "muted", colorEnabled)}${value}`;
|
|
5882
|
+
const next = (command, description) => ` ${themeText(command, "accent", colorEnabled)}${themeText(description, "muted", colorEnabled)}`;
|
|
5883
|
+
const titleText = t("contextTitle");
|
|
5884
|
+
const heading = colorEnabled ? [renderDialogTitle(titleText, true)] : [titleText, "\u2500".repeat(displayWidth(titleText))];
|
|
5885
|
+
return [
|
|
5886
|
+
...heading,
|
|
5887
|
+
field(labels[0], `${state.agentName} (${state.agentKey})`),
|
|
5888
|
+
field(labels[1], renderTokenStatus(state.turnTokens)),
|
|
5889
|
+
field(
|
|
5890
|
+
labels[2],
|
|
5891
|
+
state.dialogKey ?? (state.dialogId ? "unavailable" : state.dialogLabel)
|
|
5892
|
+
),
|
|
5893
|
+
field(labels[3], docs),
|
|
5894
|
+
field(labels[4], skills),
|
|
5895
|
+
field(labels[5], state.profileName),
|
|
5896
|
+
field(labels[6], state.runtimeMode),
|
|
5897
|
+
field(labels[7], state.serverUrl),
|
|
5898
|
+
"",
|
|
5899
|
+
themeText(t("contextNext"), "chrome", colorEnabled),
|
|
5900
|
+
next("/agents ", ` ${t("contextNextAgents")}`),
|
|
5901
|
+
next("/doc attach <doc> ", ` ${t("contextNextDoc")}`),
|
|
5902
|
+
next("/skill attach <ref>", ` ${t("contextNextSkill")}`),
|
|
5903
|
+
next("/new ", ` ${t("contextNextNew")}`),
|
|
5904
|
+
next("/clear ", ` ${t("contextNextClear")}`)
|
|
5905
|
+
].join("\n");
|
|
5906
|
+
}
|
|
5907
|
+
function renderKnownAgents(colorEnabled = resolveCliColorEnabled()) {
|
|
5908
|
+
return [
|
|
5909
|
+
renderDialogTitle(t("agentsTitle"), colorEnabled),
|
|
5910
|
+
...resolveCatalogPlatformAgents().map(
|
|
5911
|
+
(agent, index) => ` ${themeText(String(index + 1), "chrome", colorEnabled)} ${themeText(
|
|
5912
|
+
agent.name.padEnd(11),
|
|
5913
|
+
"accent",
|
|
5914
|
+
colorEnabled
|
|
5915
|
+
)} ${themeText(agent.description ?? "", "muted", colorEnabled)}`
|
|
5916
|
+
),
|
|
5917
|
+
"",
|
|
5918
|
+
themeText(
|
|
5919
|
+
t("agentsTip"),
|
|
5920
|
+
"muted",
|
|
5921
|
+
colorEnabled
|
|
5922
|
+
)
|
|
5923
|
+
].join("\n");
|
|
5907
5924
|
}
|
|
5908
5925
|
|
|
5909
5926
|
// packages/cli/tui/conversationLinks.ts
|
|
@@ -6182,6 +6199,7 @@ function createInitialTuiState(env = process.env) {
|
|
|
6182
6199
|
dialogOwnerId,
|
|
6183
6200
|
dialogLabel: dialogEnvValue ?? "new",
|
|
6184
6201
|
profileName: asOptionalTrimmedString(env.NOLO_PROFILE) ?? "local",
|
|
6202
|
+
showAuthGuidance: resolveAuthGuidanceState(env).guidanceNeeded,
|
|
6185
6203
|
serverUrl: (env.NOLO_SERVER || env.BASE_URL || DEFAULT_TUI_SERVER_URL).replace(
|
|
6186
6204
|
/\/+$/,
|
|
6187
6205
|
""
|
|
@@ -6253,12 +6271,9 @@ function handleTuiInput(input, state, historyTurns) {
|
|
|
6253
6271
|
};
|
|
6254
6272
|
}
|
|
6255
6273
|
if (!isLikelySlashCommand(trimmed)) {
|
|
6256
|
-
const
|
|
6257
|
-
const
|
|
6258
|
-
const
|
|
6259
|
-
const stripped = stripImageTokens(trimmed, readableHints);
|
|
6260
|
-
const finalMessage = stripped.length > 0 ? stripped : trimmed;
|
|
6261
|
-
const imagePaths = readableHints.map((hint) => hint.resolvedPath);
|
|
6274
|
+
const detected = detectSubmittedImagePaths(trimmed, state.cwd);
|
|
6275
|
+
const { hints, unreadableHints, imagePaths } = detected;
|
|
6276
|
+
const finalMessage = detected.message;
|
|
6262
6277
|
const fileRefs = detectFileReferences(trimmed, state.cwd, {
|
|
6263
6278
|
exclude: hints.map((hint) => hint.resolvedPath)
|
|
6264
6279
|
});
|
|
@@ -6745,13 +6760,6 @@ ${t("autoUsage")}`
|
|
|
6745
6760
|
output: t("customizeHint")
|
|
6746
6761
|
};
|
|
6747
6762
|
case "/login": {
|
|
6748
|
-
if (!argText) {
|
|
6749
|
-
return {
|
|
6750
|
-
nextState: state,
|
|
6751
|
-
output: `${t("loginHint")}
|
|
6752
|
-
${t("loginTuiStart")}`
|
|
6753
|
-
};
|
|
6754
|
-
}
|
|
6755
6763
|
return {
|
|
6756
6764
|
nextState: state,
|
|
6757
6765
|
output: "",
|
|
@@ -8055,10 +8063,14 @@ function projectChatQueueStatus({
|
|
|
8055
8063
|
function createChatQueueTuiBinding(runTurn) {
|
|
8056
8064
|
const runtime = createChatQueueRuntime();
|
|
8057
8065
|
let preemptArmed = null;
|
|
8058
|
-
const resolveSubmit = ({
|
|
8066
|
+
const resolveSubmit = ({
|
|
8067
|
+
text,
|
|
8068
|
+
isRunning,
|
|
8069
|
+
attachmentCount = 0
|
|
8070
|
+
}) => {
|
|
8059
8071
|
return resolveChatSendDecision({
|
|
8060
8072
|
text,
|
|
8061
|
-
imagePreviewCount:
|
|
8073
|
+
imagePreviewCount: attachmentCount,
|
|
8062
8074
|
pendingFileCount: 0,
|
|
8063
8075
|
isSendBlocked: false,
|
|
8064
8076
|
canMultiImg: true,
|
|
@@ -8144,13 +8156,17 @@ function createChatQueueTuiBinding(runTurn) {
|
|
|
8144
8156
|
preemptArmed = "stop";
|
|
8145
8157
|
return true;
|
|
8146
8158
|
};
|
|
8147
|
-
const
|
|
8159
|
+
const snapshotAndClearQueueWithImages = () => {
|
|
8148
8160
|
const status = runtime.getState();
|
|
8149
8161
|
if (status.queue.length === 0) return null;
|
|
8150
8162
|
const merged = status.queue.map((req) => req.text).join("\n");
|
|
8163
|
+
const imagePaths = [
|
|
8164
|
+
...new Set(status.queue.flatMap((req) => req.imagePaths ?? []))
|
|
8165
|
+
];
|
|
8151
8166
|
runtime.send({ type: "clear" });
|
|
8152
|
-
return merged;
|
|
8167
|
+
return { text: merged, imagePaths };
|
|
8153
8168
|
};
|
|
8169
|
+
const snapshotAndClearQueue = () => snapshotAndClearQueueWithImages()?.text ?? null;
|
|
8154
8170
|
const clear = () => {
|
|
8155
8171
|
runtime.send({ type: "clear" });
|
|
8156
8172
|
};
|
|
@@ -8174,6 +8190,7 @@ function createChatQueueTuiBinding(runTurn) {
|
|
|
8174
8190
|
preemptForDrain,
|
|
8175
8191
|
preemptForStop,
|
|
8176
8192
|
snapshotAndClearQueue,
|
|
8193
|
+
snapshotAndClearQueueWithImages,
|
|
8177
8194
|
clear,
|
|
8178
8195
|
recoverStaleRunning,
|
|
8179
8196
|
getStatus,
|
|
@@ -9498,10 +9515,30 @@ async function runOneAgentTurn(ctx, inputMsg, imageUrls, actionGateHandler, conf
|
|
|
9498
9515
|
}
|
|
9499
9516
|
}
|
|
9500
9517
|
}
|
|
9518
|
+
async function runDrainedQueueTurn(ctx, req, actionGateHandler, confirmDestructiveAction, runTurn = runOneAgentTurn) {
|
|
9519
|
+
let imageUrls = [];
|
|
9520
|
+
if (req.imagePaths && req.imagePaths.length > 0) {
|
|
9521
|
+
try {
|
|
9522
|
+
({ imageUrls } = await resolveAttachmentImageUrls({
|
|
9523
|
+
actionImagePaths: req.imagePaths,
|
|
9524
|
+
attachedImages: [],
|
|
9525
|
+
onFailure: (_path, err) => ctx.output.write(`[nolo] image skipped: ${err.message}
|
|
9526
|
+
`)
|
|
9527
|
+
}));
|
|
9528
|
+
} catch (err) {
|
|
9529
|
+
ctx.output.write(
|
|
9530
|
+
`[nolo] image skipped: ${err instanceof Error ? err.message : String(err)}
|
|
9531
|
+
`
|
|
9532
|
+
);
|
|
9533
|
+
imageUrls = [];
|
|
9534
|
+
}
|
|
9535
|
+
}
|
|
9536
|
+
return runTurn(ctx, req, imageUrls, actionGateHandler, confirmDestructiveAction);
|
|
9537
|
+
}
|
|
9501
9538
|
function ensureChatQueueBinding(ctx, actionGateHandler, confirmDestructiveAction) {
|
|
9502
9539
|
if (ctx.chatQueueBinding) return ctx.chatQueueBinding;
|
|
9503
|
-
ctx.chatQueueBinding = createChatQueueTuiBinding(async (
|
|
9504
|
-
return
|
|
9540
|
+
ctx.chatQueueBinding = createChatQueueTuiBinding(async (req) => {
|
|
9541
|
+
return runDrainedQueueTurn(ctx, req, actionGateHandler, confirmDestructiveAction);
|
|
9505
9542
|
});
|
|
9506
9543
|
return ctx.chatQueueBinding;
|
|
9507
9544
|
}
|
|
@@ -10713,6 +10750,7 @@ ${stderrText.trim()}
|
|
|
10713
10750
|
);
|
|
10714
10751
|
if (outcome.status === "success") {
|
|
10715
10752
|
env.AUTH_TOKEN = outcome.token;
|
|
10753
|
+
host.state = { ...host.state, showAuthGuidance: false };
|
|
10716
10754
|
}
|
|
10717
10755
|
}
|
|
10718
10756
|
if (result.action?.type === "chat") {
|
|
@@ -11830,6 +11868,7 @@ ${err.message}` : ""}`
|
|
|
11830
11868
|
});
|
|
11831
11869
|
if (outcome.status === "success") {
|
|
11832
11870
|
env.AUTH_TOKEN = outcome.token;
|
|
11871
|
+
state = { ...state, showAuthGuidance: false };
|
|
11833
11872
|
}
|
|
11834
11873
|
} else if (res.action) {
|
|
11835
11874
|
output.write(
|
|
@@ -11864,12 +11903,19 @@ ${hint}` : hint;
|
|
|
11864
11903
|
return;
|
|
11865
11904
|
}
|
|
11866
11905
|
const flushCount = chatQueueBinding.queueLength();
|
|
11867
|
-
const
|
|
11868
|
-
if (!
|
|
11906
|
+
const flushed = chatQueueBinding.snapshotAndClearQueueWithImages();
|
|
11907
|
+
if (!flushed) return;
|
|
11908
|
+
const merged = flushed.text;
|
|
11869
11909
|
const draftIncluded = !busy && buffer.trim() !== "";
|
|
11870
11910
|
const fullText = draftIncluded ? `${buffer}
|
|
11871
11911
|
${merged}` : merged;
|
|
11872
|
-
chatQueueBinding.enqueue(
|
|
11912
|
+
chatQueueBinding.enqueue(
|
|
11913
|
+
flushed.imagePaths.length > 0 ? {
|
|
11914
|
+
event: { kind: "user", text: fullText },
|
|
11915
|
+
text: fullText,
|
|
11916
|
+
imagePaths: flushed.imagePaths
|
|
11917
|
+
} : fullText
|
|
11918
|
+
);
|
|
11873
11919
|
const totalCount = flushCount + (draftIncluded ? 1 : 0);
|
|
11874
11920
|
emitCommandOutput(
|
|
11875
11921
|
t(busy ? "flushQueuedBusyHint" : "flushQueuedIdleHint", String(totalCount))
|
|
@@ -12068,16 +12114,33 @@ ${merged}` : merged;
|
|
|
12068
12114
|
}
|
|
12069
12115
|
const { actionGateHandler, confirmDestructiveAction } = buildInteractiveTurnHandlers();
|
|
12070
12116
|
const binding = ensureChatQueueBinding(turnCtx, actionGateHandler, confirmDestructiveAction);
|
|
12117
|
+
const busyImages = detectSubmittedImagePaths(submittedText, state.cwd);
|
|
12071
12118
|
const decision = binding.resolveSubmit({
|
|
12072
12119
|
text: submittedText,
|
|
12073
|
-
isRunning: true
|
|
12120
|
+
isRunning: true,
|
|
12121
|
+
attachmentCount: state.attachedImages.length
|
|
12074
12122
|
});
|
|
12075
12123
|
if (decision.kind === "queue-text") {
|
|
12076
|
-
|
|
12124
|
+
if (busyImages.imagePaths.length > 0) {
|
|
12125
|
+
const message = busyImages.message.trim();
|
|
12126
|
+
binding.enqueue({
|
|
12127
|
+
event: { kind: "user", text: message },
|
|
12128
|
+
text: message,
|
|
12129
|
+
imagePaths: busyImages.imagePaths
|
|
12130
|
+
});
|
|
12131
|
+
} else {
|
|
12132
|
+
binding.enqueue(decision.text);
|
|
12133
|
+
}
|
|
12077
12134
|
buffer = "";
|
|
12078
12135
|
cursorPos = 0;
|
|
12079
12136
|
fixedInput.repaint(buffer, cursorPos);
|
|
12080
12137
|
} else if (decision.kind === "queue-blocked") {
|
|
12138
|
+
if (state.attachedImages.length > 0) {
|
|
12139
|
+
emitCommandOutput(
|
|
12140
|
+
`[nolo] ${t("busyAttachmentsBlocked", String(state.attachedImages.length))}`
|
|
12141
|
+
);
|
|
12142
|
+
if (fixedInput.active) fixedInput.repaint(buffer, cursorPos);
|
|
12143
|
+
}
|
|
12081
12144
|
} else if (decision.kind === "noop" && !submittedText.trim() && binding.queueLength() > 0) {
|
|
12082
12145
|
preemptAndAbortForDrain(binding, activeTurnAbort);
|
|
12083
12146
|
}
|