logic-agent-mcp 0.0.0-stage → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.cmd +5 -0
- package/CAPTURE.cmd +8 -0
- package/CHECK.cmd +7 -0
- package/FIRMWARE-RECOVER.cmd +6 -0
- package/FIRMWARE-STATUS.cmd +8 -0
- package/INSTALL-DRIVER.cmd +6 -0
- package/INSTALL-MCP.cmd +16 -0
- package/LICENSE +31 -0
- package/MCP.cmd +5 -0
- package/README.md +127 -2
- package/SELF-TEST.cmd +6 -0
- package/THIRD-PARTY-NOTICES.md +32 -0
- package/VERIFY-FILES.cmd +6 -0
- package/VERSION.txt +17 -0
- package/VIEW.cmd +16 -0
- package/checksums.sha256 +449 -0
- package/docs/DRIVER.md +54 -0
- package/docs/DSLOGIC-PLUS.md +180 -0
- package/docs/FIRMWARE.md +53 -0
- package/docs/INSTALL.md +74 -0
- package/docs/MCP-CLIENTS.md +213 -0
- package/docs/PROTOCOLS.md +200 -0
- package/docs/TROUBLESHOOTING.md +41 -0
- package/docs/UPSTREAM-SYNC.md +141 -0
- package/docs/WAVEFORM-VIEWER.md +48 -0
- package/firmware/DSLogicPlus.fw +0 -0
- package/firmware/LICENSE-DreamSourceLab.txt +20 -0
- package/launcher/logic-agent-mcp.mjs +106 -0
- package/package.json +56 -6
- package/runtime/app/logic_agent/__init__.py +4 -0
- package/runtime/app/logic_agent/analysis.py +84 -0
- package/runtime/app/logic_agent/backends/__init__.py +7 -0
- package/runtime/app/logic_agent/backends/base.py +37 -0
- package/runtime/app/logic_agent/backends/dslab.py +278 -0
- package/runtime/app/logic_agent/backends/mock.py +101 -0
- package/runtime/app/logic_agent/backends/sigrok.py +252 -0
- package/runtime/app/logic_agent/cli.py +387 -0
- package/runtime/app/logic_agent/decoders.py +868 -0
- package/runtime/app/logic_agent/errors.py +50 -0
- package/runtime/app/logic_agent/importer.py +129 -0
- package/runtime/app/logic_agent/mcp_clients.py +956 -0
- package/runtime/app/logic_agent/mcp_server.py +345 -0
- package/runtime/app/logic_agent/models.py +150 -0
- package/runtime/app/logic_agent/protocols.py +233 -0
- package/runtime/app/logic_agent/service.py +378 -0
- package/runtime/app/logic_agent/signal.py +206 -0
- package/runtime/app/logic_agent/store.py +197 -0
- package/runtime/bin/_bz2.pyd +0 -0
- package/runtime/bin/_ctypes.pyd +0 -0
- package/runtime/bin/_decimal.pyd +0 -0
- package/runtime/bin/_elementtree.pyd +0 -0
- package/runtime/bin/_hashlib.pyd +0 -0
- package/runtime/bin/_lzma.pyd +0 -0
- package/runtime/bin/_multiprocessing.pyd +0 -0
- package/runtime/bin/_socket.pyd +0 -0
- package/runtime/bin/_sqlite3.pyd +0 -0
- package/runtime/bin/_ssl.pyd +0 -0
- package/runtime/bin/dslab.exe +0 -0
- package/runtime/bin/libglib-2.0-0.dll +0 -0
- package/runtime/bin/libiconv-2.dll +0 -0
- package/runtime/bin/libintl-8.dll +0 -0
- package/runtime/bin/libpcre2-8-0.dll +0 -0
- package/runtime/bin/libusb-1.0.dll +0 -0
- package/runtime/bin/libwinpthread-1.dll +0 -0
- package/runtime/bin/libz-1.dll +0 -0
- package/runtime/bin/msvcp100.dll +0 -0
- package/runtime/bin/msvcr100.dll +0 -0
- package/runtime/bin/pyexpat.pyd +0 -0
- package/runtime/bin/python34.dll +0 -0
- package/runtime/bin/python34.zip +0 -0
- package/runtime/bin/res/DSCope.bin +0 -0
- package/runtime/bin/res/DSCope.fw +0 -0
- package/runtime/bin/res/DSCope1.def.dsc +88 -0
- package/runtime/bin/res/DSCope2.def.dsc +54 -0
- package/runtime/bin/res/DSCope20.bin +0 -0
- package/runtime/bin/res/DSCope20.fw +0 -0
- package/runtime/bin/res/DSCopeC20B.bin +0 -0
- package/runtime/bin/res/DSCopeC20P.bin +0 -0
- package/runtime/bin/res/DSCopeU2B100.bin +0 -0
- package/runtime/bin/res/DSCopeU2B20.bin +0 -0
- package/runtime/bin/res/DSCopeU2P20.bin +0 -0
- package/runtime/bin/res/DSCopeU3P100.bin +0 -0
- package/runtime/bin/res/DSLogic.fw +0 -0
- package/runtime/bin/res/DSLogic0.def.dsc +297 -0
- package/runtime/bin/res/DSLogic1.def.dsc +82 -0
- package/runtime/bin/res/DSLogic2.def.dsc +52 -0
- package/runtime/bin/res/DSLogic33.bin +0 -0
- package/runtime/bin/res/DSLogic50.bin +0 -0
- package/runtime/bin/res/DSLogicBasic.bin +0 -0
- package/runtime/bin/res/DSLogicPlus-pgl12-2.bin +0 -0
- package/runtime/bin/res/DSLogicPlus-pgl12.bin +0 -0
- package/runtime/bin/res/DSLogicPlus.bin +0 -0
- package/runtime/bin/res/DSLogicPlus.fw +0 -0
- package/runtime/bin/res/DSLogicPro.bin +0 -0
- package/runtime/bin/res/DSLogicPro.fw +0 -0
- package/runtime/bin/res/DSLogicU2Basic-pgl12-2.bin +0 -0
- package/runtime/bin/res/DSLogicU2Basic-pgl12.bin +0 -0
- package/runtime/bin/res/DSLogicU2Basic.bin +0 -0
- package/runtime/bin/res/DSLogicU2Pro16.bin +0 -0
- package/runtime/bin/res/DSLogicU3Pro16.bin +0 -0
- package/runtime/bin/res/DSLogicU3Pro32.bin +0 -0
- package/runtime/bin/res/license.txt +20 -0
- package/runtime/bin/res/virtual-demo1.dsc +68 -0
- package/runtime/bin/select.pyd +0 -0
- package/runtime/bin/sigrok-cli.exe +0 -0
- package/runtime/bin/unicodedata.pyd +0 -0
- package/runtime/bin/winsound.pyd +0 -0
- package/runtime/decoders/ac97/__init__.py +38 -0
- package/runtime/decoders/ac97/pd.py +477 -0
- package/runtime/decoders/ad5626/__init__.py +25 -0
- package/runtime/decoders/ad5626/pd.py +62 -0
- package/runtime/decoders/ad79x0/__init__.py +25 -0
- package/runtime/decoders/ad79x0/pd.py +137 -0
- package/runtime/decoders/ade77xx/__init__.py +31 -0
- package/runtime/decoders/ade77xx/lists.py +102 -0
- package/runtime/decoders/ade77xx/pd.py +131 -0
- package/runtime/decoders/adf435x/__init__.py +29 -0
- package/runtime/decoders/adf435x/pd.py +230 -0
- package/runtime/decoders/adns5020/__init__.py +27 -0
- package/runtime/decoders/adns5020/pd.py +116 -0
- package/runtime/decoders/adxl345/__init__.py +26 -0
- package/runtime/decoders/adxl345/lists.py +96 -0
- package/runtime/decoders/adxl345/pd.py +453 -0
- package/runtime/decoders/am230x/__init__.py +36 -0
- package/runtime/decoders/am230x/pd.py +229 -0
- package/runtime/decoders/amulet_ascii/__init__.py +28 -0
- package/runtime/decoders/amulet_ascii/lists.py +73 -0
- package/runtime/decoders/amulet_ascii/pd.py +699 -0
- package/runtime/decoders/arm_etmv3/__init__.py +25 -0
- package/runtime/decoders/arm_etmv3/pd.py +567 -0
- package/runtime/decoders/arm_itm/__init__.py +25 -0
- package/runtime/decoders/arm_itm/pd.py +373 -0
- package/runtime/decoders/arm_tpiu/__init__.py +28 -0
- package/runtime/decoders/arm_tpiu/pd.py +131 -0
- package/runtime/decoders/atsha204a/__init__.py +30 -0
- package/runtime/decoders/atsha204a/pd.py +323 -0
- package/runtime/decoders/aud/__init__.py +31 -0
- package/runtime/decoders/aud/pd.py +108 -0
- package/runtime/decoders/avr_isp/__init__.py +25 -0
- package/runtime/decoders/avr_isp/parts.py +163 -0
- package/runtime/decoders/avr_isp/pd.py +278 -0
- package/runtime/decoders/avr_pdi/__init__.py +42 -0
- package/runtime/decoders/avr_pdi/pd.py +574 -0
- package/runtime/decoders/caliper/__init__.py +36 -0
- package/runtime/decoders/caliper/pd.py +146 -0
- package/runtime/decoders/can/__init__.py +31 -0
- package/runtime/decoders/can/pd.py +519 -0
- package/runtime/decoders/cc1101/__init__.py +28 -0
- package/runtime/decoders/cc1101/lists.py +115 -0
- package/runtime/decoders/cc1101/pd.py +294 -0
- package/runtime/decoders/cec/__init__.py +25 -0
- package/runtime/decoders/cec/pd.py +311 -0
- package/runtime/decoders/cec/protocoldata.py +117 -0
- package/runtime/decoders/cfp/__init__.py +34 -0
- package/runtime/decoders/cfp/pd.py +110 -0
- package/runtime/decoders/cjtag/__init__.py +36 -0
- package/runtime/decoders/cjtag/pd.py +323 -0
- package/runtime/decoders/common/__init__.py +19 -0
- package/runtime/decoders/common/plugtrx/__init__.py +20 -0
- package/runtime/decoders/common/plugtrx/mod.py +192 -0
- package/runtime/decoders/common/sdcard/__init__.py +20 -0
- package/runtime/decoders/common/sdcard/mod.py +150 -0
- package/runtime/decoders/common/srdhelper/__init__.py +20 -0
- package/runtime/decoders/common/srdhelper/mod.py +98 -0
- package/runtime/decoders/counter/__init__.py +28 -0
- package/runtime/decoders/counter/pd.py +145 -0
- package/runtime/decoders/dali/__init__.py +24 -0
- package/runtime/decoders/dali/lists.py +98 -0
- package/runtime/decoders/dali/pd.py +244 -0
- package/runtime/decoders/dcf77/__init__.py +28 -0
- package/runtime/decoders/dcf77/pd.py +311 -0
- package/runtime/decoders/dmx512/__init__.py +25 -0
- package/runtime/decoders/dmx512/pd.py +361 -0
- package/runtime/decoders/ds1307/__init__.py +25 -0
- package/runtime/decoders/ds1307/pd.py +270 -0
- package/runtime/decoders/ds2408/__init__.py +25 -0
- package/runtime/decoders/ds2408/pd.py +129 -0
- package/runtime/decoders/ds243x/__init__.py +25 -0
- package/runtime/decoders/ds243x/pd.py +270 -0
- package/runtime/decoders/ds28ea00/__init__.py +25 -0
- package/runtime/decoders/ds28ea00/pd.py +93 -0
- package/runtime/decoders/dsi/__init__.py +24 -0
- package/runtime/decoders/dsi/pd.py +157 -0
- package/runtime/decoders/edid/__init__.py +35 -0
- package/runtime/decoders/edid/pd.py +671 -0
- package/runtime/decoders/edid/pnpids.txt +2135 -0
- package/runtime/decoders/eeprom24xx/__init__.py +25 -0
- package/runtime/decoders/eeprom24xx/lists.py +214 -0
- package/runtime/decoders/eeprom24xx/pd.py +443 -0
- package/runtime/decoders/eeprom93xx/__init__.py +32 -0
- package/runtime/decoders/eeprom93xx/pd.py +163 -0
- package/runtime/decoders/em4100/__init__.py +24 -0
- package/runtime/decoders/em4100/pd.py +238 -0
- package/runtime/decoders/em4305/__init__.py +24 -0
- package/runtime/decoders/em4305/pd.py +394 -0
- package/runtime/decoders/enc28j60/__init__.py +32 -0
- package/runtime/decoders/enc28j60/lists.py +161 -0
- package/runtime/decoders/enc28j60/pd.py +294 -0
- package/runtime/decoders/flexray/__init__.py +32 -0
- package/runtime/decoders/flexray/pd.py +413 -0
- package/runtime/decoders/graycode/__init__.py +24 -0
- package/runtime/decoders/graycode/pd.py +197 -0
- package/runtime/decoders/guess_bitrate/__init__.py +40 -0
- package/runtime/decoders/guess_bitrate/pd.py +79 -0
- package/runtime/decoders/hdcp/__init__.py +27 -0
- package/runtime/decoders/hdcp/pd.py +191 -0
- package/runtime/decoders/i2c/__init__.py +25 -0
- package/runtime/decoders/i2c/pd.py +364 -0
- package/runtime/decoders/i2cdemux/__init__.py +27 -0
- package/runtime/decoders/i2cdemux/pd.py +80 -0
- package/runtime/decoders/i2cfilter/__init__.py +37 -0
- package/runtime/decoders/i2cfilter/pd.py +106 -0
- package/runtime/decoders/i2s/__init__.py +29 -0
- package/runtime/decoders/i2s/pd.py +179 -0
- package/runtime/decoders/ieee488/__init__.py +26 -0
- package/runtime/decoders/ieee488/pd.py +849 -0
- package/runtime/decoders/ir_irmp/__init__.py +25 -0
- package/runtime/decoders/ir_irmp/irmp_library.py +168 -0
- package/runtime/decoders/ir_irmp/pd.py +139 -0
- package/runtime/decoders/ir_nec/__init__.py +25 -0
- package/runtime/decoders/ir_nec/lists.py +93 -0
- package/runtime/decoders/ir_nec/pd.py +300 -0
- package/runtime/decoders/ir_rc5/__init__.py +24 -0
- package/runtime/decoders/ir_rc5/lists.py +93 -0
- package/runtime/decoders/ir_rc5/pd.py +182 -0
- package/runtime/decoders/ir_rc6/__init__.py +24 -0
- package/runtime/decoders/ir_rc6/pd.py +205 -0
- package/runtime/decoders/ir_sirc/__init__.py +26 -0
- package/runtime/decoders/ir_sirc/lists.py +201 -0
- package/runtime/decoders/ir_sirc/pd.py +215 -0
- package/runtime/decoders/jitter/__init__.py +29 -0
- package/runtime/decoders/jitter/pd.py +198 -0
- package/runtime/decoders/jtag/__init__.py +30 -0
- package/runtime/decoders/jtag/pd.py +235 -0
- package/runtime/decoders/jtag_ejtag/__init__.py +25 -0
- package/runtime/decoders/jtag_ejtag/pd.py +408 -0
- package/runtime/decoders/jtag_stm32/__init__.py +29 -0
- package/runtime/decoders/jtag_stm32/pd.py +269 -0
- package/runtime/decoders/lfast/__init__.py +35 -0
- package/runtime/decoders/lfast/pd.py +335 -0
- package/runtime/decoders/lin/__init__.py +28 -0
- package/runtime/decoders/lin/pd.py +247 -0
- package/runtime/decoders/lm75/__init__.py +25 -0
- package/runtime/decoders/lm75/pd.py +186 -0
- package/runtime/decoders/lpc/__init__.py +25 -0
- package/runtime/decoders/lpc/pd.py +365 -0
- package/runtime/decoders/ltc242x/__init__.py +25 -0
- package/runtime/decoders/ltc242x/pd.py +86 -0
- package/runtime/decoders/ltc26x7/__init__.py +25 -0
- package/runtime/decoders/ltc26x7/pd.py +187 -0
- package/runtime/decoders/maple_bus/__init__.py +25 -0
- package/runtime/decoders/maple_bus/pd.py +222 -0
- package/runtime/decoders/max72xx/__init__.py +25 -0
- package/runtime/decoders/max72xx/pd.py +130 -0
- package/runtime/decoders/mcp230xx/__init__.py +25 -0
- package/runtime/decoders/mcp230xx/pd.py +143 -0
- package/runtime/decoders/mcs48/__init__.py +31 -0
- package/runtime/decoders/mcs48/pd.py +126 -0
- package/runtime/decoders/mdio/__init__.py +39 -0
- package/runtime/decoders/mdio/pd.py +325 -0
- package/runtime/decoders/microwire/__init__.py +40 -0
- package/runtime/decoders/microwire/pd.py +194 -0
- package/runtime/decoders/midi/__init__.py +28 -0
- package/runtime/decoders/midi/lists.py +840 -0
- package/runtime/decoders/midi/pd.py +627 -0
- package/runtime/decoders/miller/__init__.py +26 -0
- package/runtime/decoders/miller/pd.py +190 -0
- package/runtime/decoders/mlx90614/__init__.py +25 -0
- package/runtime/decoders/mlx90614/pd.py +82 -0
- package/runtime/decoders/modbus/__init__.py +28 -0
- package/runtime/decoders/modbus/pd.py +941 -0
- package/runtime/decoders/morse/__init__.py +28 -0
- package/runtime/decoders/morse/pd.py +250 -0
- package/runtime/decoders/mrf24j40/__init__.py +25 -0
- package/runtime/decoders/mrf24j40/lists.py +165 -0
- package/runtime/decoders/mrf24j40/pd.py +188 -0
- package/runtime/decoders/mxc6225xu/__init__.py +28 -0
- package/runtime/decoders/mxc6225xu/pd.py +217 -0
- package/runtime/decoders/nes_gamepad/__init__.py +54 -0
- package/runtime/decoders/nes_gamepad/pd.py +92 -0
- package/runtime/decoders/nrf24l01/__init__.py +29 -0
- package/runtime/decoders/nrf24l01/pd.py +332 -0
- package/runtime/decoders/nrf905/__init__.py +26 -0
- package/runtime/decoders/nrf905/pd.py +301 -0
- package/runtime/decoders/numbers_and_state/__init__.py +41 -0
- package/runtime/decoders/numbers_and_state/pd.py +377 -0
- package/runtime/decoders/nunchuk/__init__.py +30 -0
- package/runtime/decoders/nunchuk/pd.py +207 -0
- package/runtime/decoders/onewire_link/__init__.py +56 -0
- package/runtime/decoders/onewire_link/pd.py +347 -0
- package/runtime/decoders/onewire_network/__init__.py +56 -0
- package/runtime/decoders/onewire_network/pd.py +185 -0
- package/runtime/decoders/ook/__init__.py +36 -0
- package/runtime/decoders/ook/pd.py +484 -0
- package/runtime/decoders/ook_oregon/__init__.py +25 -0
- package/runtime/decoders/ook_oregon/lists.py +75 -0
- package/runtime/decoders/ook_oregon/pd.py +389 -0
- package/runtime/decoders/ook_vis/__init__.py +25 -0
- package/runtime/decoders/ook_vis/pd.py +194 -0
- package/runtime/decoders/pan1321/__init__.py +25 -0
- package/runtime/decoders/pan1321/pd.py +164 -0
- package/runtime/decoders/parallel/__init__.py +45 -0
- package/runtime/decoders/parallel/pd.py +285 -0
- package/runtime/decoders/pca9571/__init__.py +25 -0
- package/runtime/decoders/pca9571/pd.py +122 -0
- package/runtime/decoders/pjdl/__init__.py +27 -0
- package/runtime/decoders/pjdl/pd.py +723 -0
- package/runtime/decoders/pjon/__init__.py +25 -0
- package/runtime/decoders/pjon/pd.py +603 -0
- package/runtime/decoders/ps2/__init__.py +26 -0
- package/runtime/decoders/ps2/pd.py +126 -0
- package/runtime/decoders/pwm/__init__.py +24 -0
- package/runtime/decoders/pwm/pd.py +167 -0
- package/runtime/decoders/qi/__init__.py +25 -0
- package/runtime/decoders/qi/pd.py +244 -0
- package/runtime/decoders/rc_encode/__init__.py +40 -0
- package/runtime/decoders/rc_encode/pd.py +215 -0
- package/runtime/decoders/rfm12/__init__.py +25 -0
- package/runtime/decoders/rfm12/pd.py +497 -0
- package/runtime/decoders/rgb_led_spi/__init__.py +25 -0
- package/runtime/decoders/rgb_led_spi/pd.py +72 -0
- package/runtime/decoders/rgb_led_ws281x/__init__.py +27 -0
- package/runtime/decoders/rgb_led_ws281x/pd.py +267 -0
- package/runtime/decoders/rtc8564/__init__.py +25 -0
- package/runtime/decoders/rtc8564/pd.py +254 -0
- package/runtime/decoders/sae_j1850_vpw/__init__.py +24 -0
- package/runtime/decoders/sae_j1850_vpw/pd.py +296 -0
- package/runtime/decoders/sbus_futaba/__init__.py +35 -0
- package/runtime/decoders/sbus_futaba/pd.py +273 -0
- package/runtime/decoders/sda2506/__init__.py +24 -0
- package/runtime/decoders/sda2506/pd.py +146 -0
- package/runtime/decoders/sdcard_sd/__init__.py +24 -0
- package/runtime/decoders/sdcard_sd/pd.py +554 -0
- package/runtime/decoders/sdcard_spi/__init__.py +68 -0
- package/runtime/decoders/sdcard_spi/pd.py +518 -0
- package/runtime/decoders/sdq/__init__.py +28 -0
- package/runtime/decoders/sdq/pd.py +131 -0
- package/runtime/decoders/seven_segment/__init__.py +24 -0
- package/runtime/decoders/seven_segment/pd.py +186 -0
- package/runtime/decoders/signature/__init__.py +25 -0
- package/runtime/decoders/signature/pd.py +142 -0
- package/runtime/decoders/sipi/__init__.py +30 -0
- package/runtime/decoders/sipi/pd.py +181 -0
- package/runtime/decoders/sle44xx/__init__.py +26 -0
- package/runtime/decoders/sle44xx/pd.py +541 -0
- package/runtime/decoders/smart_qspi/PORTING.md +22 -0
- package/runtime/decoders/smart_qspi/__init__.py +1 -0
- package/runtime/decoders/smart_qspi/pd.py +826 -0
- package/runtime/decoders/spdif/__init__.py +25 -0
- package/runtime/decoders/spdif/pd.py +295 -0
- package/runtime/decoders/spi/__init__.py +32 -0
- package/runtime/decoders/spi/pd.py +347 -0
- package/runtime/decoders/spiflash/__init__.py +30 -0
- package/runtime/decoders/spiflash/lists.py +178 -0
- package/runtime/decoders/spiflash/pd.py +537 -0
- package/runtime/decoders/ssi32/__init__.py +28 -0
- package/runtime/decoders/ssi32/pd.py +127 -0
- package/runtime/decoders/st25r39xx_spi/__init__.py +31 -0
- package/runtime/decoders/st25r39xx_spi/lists.py +231 -0
- package/runtime/decoders/st25r39xx_spi/pd.py +360 -0
- package/runtime/decoders/st7735/__init__.py +27 -0
- package/runtime/decoders/st7735/pd.py +173 -0
- package/runtime/decoders/stepper_motor/__init__.py +25 -0
- package/runtime/decoders/stepper_motor/pd.py +95 -0
- package/runtime/decoders/swd/__init__.py +34 -0
- package/runtime/decoders/swd/pd.py +350 -0
- package/runtime/decoders/swim/__init__.py +28 -0
- package/runtime/decoders/swim/pd.py +303 -0
- package/runtime/decoders/t55xx/__init__.py +25 -0
- package/runtime/decoders/t55xx/pd.py +326 -0
- package/runtime/decoders/tca6408a/__init__.py +25 -0
- package/runtime/decoders/tca6408a/pd.py +157 -0
- package/runtime/decoders/tdm_audio/__init__.py +25 -0
- package/runtime/decoders/tdm_audio/pd.py +116 -0
- package/runtime/decoders/timing/__init__.py +24 -0
- package/runtime/decoders/timing/pd.py +194 -0
- package/runtime/decoders/tlc5620/__init__.py +24 -0
- package/runtime/decoders/tlc5620/pd.py +212 -0
- package/runtime/decoders/uart/__init__.py +40 -0
- package/runtime/decoders/uart/pd.py +635 -0
- package/runtime/decoders/usb_packet/__init__.py +43 -0
- package/runtime/decoders/usb_packet/pd.py +401 -0
- package/runtime/decoders/usb_power_delivery/__init__.py +24 -0
- package/runtime/decoders/usb_power_delivery/pd.py +642 -0
- package/runtime/decoders/usb_request/__init__.py +49 -0
- package/runtime/decoders/usb_request/pd.py +386 -0
- package/runtime/decoders/usb_signalling/__init__.py +50 -0
- package/runtime/decoders/usb_signalling/pd.py +348 -0
- package/runtime/decoders/wiegand/__init__.py +28 -0
- package/runtime/decoders/wiegand/pd.py +148 -0
- package/runtime/decoders/x2444m/__init__.py +25 -0
- package/runtime/decoders/x2444m/pd.py +111 -0
- package/runtime/decoders/xfp/__init__.py +38 -0
- package/runtime/decoders/xfp/pd.py +486 -0
- package/runtime/decoders/xy2-100/__init__.py +28 -0
- package/runtime/decoders/xy2-100/pd.py +242 -0
- package/runtime/decoders/z80/__init__.py +36 -0
- package/runtime/decoders/z80/pd.py +358 -0
- package/runtime/decoders/z80/tables.py +1083 -0
- package/runtime/dslab.cmd +5 -0
- package/runtime/licenses/DreamSourceLab-res-MIT.txt +20 -0
- package/runtime/licenses/dslab-GPL-3.0.txt +674 -0
- package/runtime/licenses/logic-agent-MIT.txt +31 -0
- package/runtime/licenses/python-PSF.txt +645 -0
- package/runtime/licenses/sigrok-cli-GPL-3.0.txt +674 -0
- package/runtime/licenses/smart_qspi-PORTING.md +22 -0
- package/runtime/licenses/source/patches/dsview-v1.3.2-dslab.patch +124 -0
- package/runtime/logic-agent-mcp.cmd +9 -0
- package/runtime/logic-agent.cmd +9 -0
- package/runtime/python/LICENSE.txt +645 -0
- package/runtime/python/_asyncio.pyd +0 -0
- package/runtime/python/_bz2.pyd +0 -0
- package/runtime/python/_ctypes.pyd +0 -0
- package/runtime/python/_decimal.pyd +0 -0
- package/runtime/python/_elementtree.pyd +0 -0
- package/runtime/python/_hashlib.pyd +0 -0
- package/runtime/python/_lzma.pyd +0 -0
- package/runtime/python/_multiprocessing.pyd +0 -0
- package/runtime/python/_overlapped.pyd +0 -0
- package/runtime/python/_queue.pyd +0 -0
- package/runtime/python/_socket.pyd +0 -0
- package/runtime/python/_sqlite3.pyd +0 -0
- package/runtime/python/_ssl.pyd +0 -0
- package/runtime/python/_uuid.pyd +0 -0
- package/runtime/python/_wmi.pyd +0 -0
- package/runtime/python/_zoneinfo.pyd +0 -0
- package/runtime/python/libcrypto-3.dll +0 -0
- package/runtime/python/libffi-8.dll +0 -0
- package/runtime/python/libssl-3.dll +0 -0
- package/runtime/python/pyexpat.pyd +0 -0
- package/runtime/python/python.cat +0 -0
- package/runtime/python/python.exe +0 -0
- package/runtime/python/python3.dll +0 -0
- package/runtime/python/python313._pth +3 -0
- package/runtime/python/python313.dll +0 -0
- package/runtime/python/python313.zip +0 -0
- package/runtime/python/pythonw.exe +0 -0
- package/runtime/python/select.pyd +0 -0
- package/runtime/python/sqlite3.dll +0 -0
- package/runtime/python/unicodedata.pyd +0 -0
- package/runtime/python/vcruntime140.dll +0 -0
- package/runtime/python/vcruntime140_1.dll +0 -0
- package/runtime/python/winsound.pyd +0 -0
- package/runtime/scripts/deploy-check.ps1 +171 -0
- package/scripts/check.ps1 +14 -0
- package/scripts/firmware-recover.ps1 +27 -0
- package/scripts/install-driver.ps1 +30 -0
- package/scripts/self-test.ps1 +14 -0
- package/scripts/verify-files.py +39 -0
|
@@ -0,0 +1,956 @@
|
|
|
1
|
+
"""Register the logic-analyzer MCP server with the local AI agents.
|
|
2
|
+
|
|
3
|
+
One command writes the right config file for every agent it can find: Codex CLI,
|
|
4
|
+
Claude Code, Claude Desktop, GitHub Copilot (VS Code and the Copilot CLI), Cursor,
|
|
5
|
+
Kiro, Windsurf and Cline. The launch command is the bundled Python interpreter
|
|
6
|
+
running ``-m logic_agent.mcp_server``, so no shell, ``cmd.exe`` or environment
|
|
7
|
+
variables are involved: a client that spawns argv directly starts the server.
|
|
8
|
+
|
|
9
|
+
Design rules:
|
|
10
|
+
|
|
11
|
+
* Config files are merged, never replaced. Unrelated servers and keys survive.
|
|
12
|
+
* A file that cannot be parsed is reported and left untouched; nothing is
|
|
13
|
+
written over a config we do not understand.
|
|
14
|
+
* The installed server can be verified end to end (initialize + capabilities)
|
|
15
|
+
before the caller ever opens the agent.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import shutil
|
|
24
|
+
import subprocess
|
|
25
|
+
import sys
|
|
26
|
+
import tempfile
|
|
27
|
+
import tomllib
|
|
28
|
+
from dataclasses import dataclass, field
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
from typing import Any, Iterable
|
|
31
|
+
|
|
32
|
+
from . import __version__
|
|
33
|
+
from .errors import ConfigError
|
|
34
|
+
|
|
35
|
+
# JSON clients use a hyphenated name (it becomes a tool prefix such as
|
|
36
|
+
# mcp__logic-analyzer__capture); Codex tables stay underscored (bare TOML key).
|
|
37
|
+
SERVER_NAME = "logic-analyzer"
|
|
38
|
+
CODEX_SERVER_NAME = "logic_analyzer"
|
|
39
|
+
SCOPES = ("user", "project")
|
|
40
|
+
|
|
41
|
+
# DeepSeek Harness stores MCP servers as a Cordis YAML patch layer. We own one
|
|
42
|
+
# delimited entry so repeat runs replace it and --remove deletes exactly that.
|
|
43
|
+
DSH_SERVER_NAME = "logic"
|
|
44
|
+
DSH_ITEM_ID = "mcp-logic-agent"
|
|
45
|
+
DSH_MARK_START = "# >>> logic-agent (managed by INSTALL-MCP.cmd) >>>"
|
|
46
|
+
DSH_MARK_END = "# <<< logic-agent <<<"
|
|
47
|
+
DSH_MANAGED = re.compile(
|
|
48
|
+
r"# >>> logic-agent[^\n]*\n.*?# <<< logic-agent[^\n]*\n?",
|
|
49
|
+
re.DOTALL,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# --------------------------------------------------------------------------- locations
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True)
|
|
57
|
+
class Locations:
|
|
58
|
+
"""Where each client keeps its config, and what counts as installed."""
|
|
59
|
+
|
|
60
|
+
home: Path
|
|
61
|
+
appdata: Path
|
|
62
|
+
copilot: Path
|
|
63
|
+
cwd: Path
|
|
64
|
+
binaries: bool = True
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def detect(
|
|
68
|
+
cls,
|
|
69
|
+
home: str | Path | None = None,
|
|
70
|
+
cwd: str | Path | None = None,
|
|
71
|
+
*,
|
|
72
|
+
binaries: bool = True,
|
|
73
|
+
) -> "Locations":
|
|
74
|
+
real_home = Path.home().resolve()
|
|
75
|
+
chosen = Path(home).expanduser().resolve() if home else real_home
|
|
76
|
+
overridden = chosen != real_home
|
|
77
|
+
if os.name == "nt":
|
|
78
|
+
default_appdata = chosen / "AppData" / "Roaming"
|
|
79
|
+
appdata = default_appdata if overridden else Path(os.environ.get("APPDATA") or default_appdata)
|
|
80
|
+
elif sys.platform == "darwin":
|
|
81
|
+
appdata = chosen / "Library" / "Application Support"
|
|
82
|
+
else:
|
|
83
|
+
default_appdata = chosen / ".config"
|
|
84
|
+
appdata = default_appdata if overridden else Path(os.environ.get("XDG_CONFIG_HOME") or default_appdata)
|
|
85
|
+
copilot = chosen / ".copilot" if overridden else Path(os.environ.get("COPILOT_HOME") or chosen / ".copilot")
|
|
86
|
+
return cls(
|
|
87
|
+
home=chosen,
|
|
88
|
+
appdata=appdata.resolve(),
|
|
89
|
+
copilot=copilot.resolve(),
|
|
90
|
+
cwd=(Path(cwd).expanduser().resolve() if cwd else Path.cwd()),
|
|
91
|
+
binaries=binaries,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _expand(template: str, loc: Locations) -> Path:
|
|
96
|
+
text = template.format(
|
|
97
|
+
home=loc.home.as_posix(),
|
|
98
|
+
appdata=loc.appdata.as_posix(),
|
|
99
|
+
copilot=loc.copilot.as_posix(),
|
|
100
|
+
cwd=loc.cwd.as_posix(),
|
|
101
|
+
)
|
|
102
|
+
path = Path(text)
|
|
103
|
+
return path if path.is_absolute() else loc.cwd / path
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# --------------------------------------------------------------------------- clients
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@dataclass(frozen=True)
|
|
110
|
+
class ClientSpec:
|
|
111
|
+
"""One MCP-capable agent and the file(s) it reads."""
|
|
112
|
+
|
|
113
|
+
id: str
|
|
114
|
+
label: str
|
|
115
|
+
fmt: str # "json" | "toml" | "yaml"
|
|
116
|
+
container: str # JSON key or TOML table that holds the servers
|
|
117
|
+
user: str # user-scope config path template
|
|
118
|
+
project: str | None # project-scope config path template (None: user only)
|
|
119
|
+
detect: tuple[str, ...] # paths whose existence proves the client is installed
|
|
120
|
+
binary: str | None # CLI name that proves the client is installed
|
|
121
|
+
stype: str | None # "type" field some clients require ("stdio" for VS Code)
|
|
122
|
+
extra: dict[str, Any] # extra entry fields that client expects
|
|
123
|
+
hint: str # how the user restarts/verifies it
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
CLIENTS: tuple[ClientSpec, ...] = (
|
|
127
|
+
ClientSpec(
|
|
128
|
+
id="codex",
|
|
129
|
+
label="Codex CLI",
|
|
130
|
+
fmt="toml",
|
|
131
|
+
container="mcp_servers",
|
|
132
|
+
user="{home}/.codex/config.toml",
|
|
133
|
+
project=None,
|
|
134
|
+
detect=("{home}/.codex",),
|
|
135
|
+
binary="codex",
|
|
136
|
+
stype=None,
|
|
137
|
+
extra={},
|
|
138
|
+
hint="restart Codex, then /mcp (or `codex mcp list`)",
|
|
139
|
+
),
|
|
140
|
+
ClientSpec(
|
|
141
|
+
id="deepseek-harness",
|
|
142
|
+
label="DeepSeek Harness",
|
|
143
|
+
fmt="yaml",
|
|
144
|
+
container="insert",
|
|
145
|
+
user="{home}/.dsh/profiles/desktop/cordis.patch.yml",
|
|
146
|
+
project=None,
|
|
147
|
+
detect=("{home}/.dsh/profiles/desktop",),
|
|
148
|
+
binary=None,
|
|
149
|
+
stype=None,
|
|
150
|
+
extra={},
|
|
151
|
+
hint="restart DeepSeek Harness; the tools show up as mcp__logic__*",
|
|
152
|
+
),
|
|
153
|
+
ClientSpec(
|
|
154
|
+
id="claude-code",
|
|
155
|
+
label="Claude Code",
|
|
156
|
+
fmt="json",
|
|
157
|
+
container="mcpServers",
|
|
158
|
+
user="{home}/.claude.json",
|
|
159
|
+
project=".mcp.json",
|
|
160
|
+
detect=("{home}/.claude.json", "{home}/.claude"),
|
|
161
|
+
binary="claude",
|
|
162
|
+
stype=None,
|
|
163
|
+
extra={},
|
|
164
|
+
hint="restart Claude Code, then `claude mcp list`",
|
|
165
|
+
),
|
|
166
|
+
ClientSpec(
|
|
167
|
+
id="claude-desktop",
|
|
168
|
+
label="Claude Desktop",
|
|
169
|
+
fmt="json",
|
|
170
|
+
container="mcpServers",
|
|
171
|
+
user="{appdata}/Claude/claude_desktop_config.json",
|
|
172
|
+
project=None,
|
|
173
|
+
detect=("{appdata}/Claude",),
|
|
174
|
+
binary=None,
|
|
175
|
+
stype=None,
|
|
176
|
+
extra={},
|
|
177
|
+
hint="quit Claude Desktop completely (tray icon) and reopen it",
|
|
178
|
+
),
|
|
179
|
+
ClientSpec(
|
|
180
|
+
id="copilot-cli",
|
|
181
|
+
label="GitHub Copilot CLI",
|
|
182
|
+
fmt="json",
|
|
183
|
+
container="mcpServers",
|
|
184
|
+
user="{copilot}/mcp-config.json",
|
|
185
|
+
project=".mcp.json",
|
|
186
|
+
detect=("{copilot}",),
|
|
187
|
+
binary="copilot",
|
|
188
|
+
stype="local",
|
|
189
|
+
extra={"tools": ["*"]},
|
|
190
|
+
hint="start `copilot`, then /mcp",
|
|
191
|
+
),
|
|
192
|
+
ClientSpec(
|
|
193
|
+
id="vscode",
|
|
194
|
+
label="VS Code Copilot",
|
|
195
|
+
fmt="json",
|
|
196
|
+
container="servers",
|
|
197
|
+
user="{appdata}/Code/User/mcp.json",
|
|
198
|
+
project=".vscode/mcp.json",
|
|
199
|
+
detect=("{appdata}/Code/User",),
|
|
200
|
+
binary="code",
|
|
201
|
+
stype="stdio",
|
|
202
|
+
extra={},
|
|
203
|
+
hint="run the command 'MCP: List Servers' and start logic-analyzer",
|
|
204
|
+
),
|
|
205
|
+
ClientSpec(
|
|
206
|
+
id="cursor",
|
|
207
|
+
label="Cursor",
|
|
208
|
+
fmt="json",
|
|
209
|
+
container="mcpServers",
|
|
210
|
+
user="{home}/.cursor/mcp.json",
|
|
211
|
+
project=".cursor/mcp.json",
|
|
212
|
+
detect=("{home}/.cursor",),
|
|
213
|
+
binary="cursor",
|
|
214
|
+
stype=None,
|
|
215
|
+
extra={},
|
|
216
|
+
hint="Cursor Settings > MCP: the server should be listed and green",
|
|
217
|
+
),
|
|
218
|
+
ClientSpec(
|
|
219
|
+
id="kiro",
|
|
220
|
+
label="Kiro",
|
|
221
|
+
fmt="json",
|
|
222
|
+
container="mcpServers",
|
|
223
|
+
user="{home}/.kiro/settings/mcp.json",
|
|
224
|
+
project=None,
|
|
225
|
+
detect=("{home}/.kiro",),
|
|
226
|
+
binary="kiro",
|
|
227
|
+
stype=None,
|
|
228
|
+
extra={},
|
|
229
|
+
hint="open the Kiro MCP panel and reconnect logic-analyzer",
|
|
230
|
+
),
|
|
231
|
+
ClientSpec(
|
|
232
|
+
id="windsurf",
|
|
233
|
+
label="Windsurf",
|
|
234
|
+
fmt="json",
|
|
235
|
+
container="mcpServers",
|
|
236
|
+
user="{home}/.codeium/windsurf/mcp_config.json",
|
|
237
|
+
project=None,
|
|
238
|
+
detect=("{home}/.codeium/windsurf",),
|
|
239
|
+
binary="windsurf",
|
|
240
|
+
stype=None,
|
|
241
|
+
extra={},
|
|
242
|
+
hint="Windsurf > MCP: refresh the server list",
|
|
243
|
+
),
|
|
244
|
+
ClientSpec(
|
|
245
|
+
id="cline",
|
|
246
|
+
label="Cline (VS Code)",
|
|
247
|
+
fmt="json",
|
|
248
|
+
container="mcpServers",
|
|
249
|
+
user="{appdata}/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json",
|
|
250
|
+
project=None,
|
|
251
|
+
detect=("{appdata}/Code/User/globalStorage/saoudrizwan.claude-dev",),
|
|
252
|
+
binary=None,
|
|
253
|
+
stype=None,
|
|
254
|
+
extra={"disabled": False, "autoApprove": []},
|
|
255
|
+
hint="Cline > MCP Servers: restart the server",
|
|
256
|
+
),
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
CLIENT_IDS: tuple[str, ...] = tuple(client.id for client in CLIENTS)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def client_by_id(client_id: str) -> ClientSpec:
|
|
263
|
+
for spec in CLIENTS:
|
|
264
|
+
if spec.id == client_id:
|
|
265
|
+
return spec
|
|
266
|
+
raise ConfigError(
|
|
267
|
+
f"unknown client: {client_id}",
|
|
268
|
+
details={"known_clients": list(CLIENT_IDS)},
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
# --------------------------------------------------------------------------- launch spec
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
@dataclass(frozen=True)
|
|
276
|
+
class LaunchSpec:
|
|
277
|
+
"""Exact argv a client should spawn, plus the environment it needs."""
|
|
278
|
+
|
|
279
|
+
command: str
|
|
280
|
+
args: list[str]
|
|
281
|
+
env: dict[str, str]
|
|
282
|
+
mode: str # "bundle" | "source"
|
|
283
|
+
data_dir: str
|
|
284
|
+
root: str | None = None
|
|
285
|
+
|
|
286
|
+
@property
|
|
287
|
+
def command_line(self) -> str:
|
|
288
|
+
return " ".join([_quote(self.command), *(_quote(item) for item in self.args)])
|
|
289
|
+
|
|
290
|
+
def as_dict(self) -> dict[str, Any]:
|
|
291
|
+
return {
|
|
292
|
+
"command": self.command,
|
|
293
|
+
"args": list(self.args),
|
|
294
|
+
"env": dict(self.env),
|
|
295
|
+
"mode": self.mode,
|
|
296
|
+
"data_dir": self.data_dir,
|
|
297
|
+
"root": self.root,
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def _quote(value: str) -> str:
|
|
302
|
+
return f'"{value}"' if " " in value else value
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def bundle_root() -> Path | None:
|
|
306
|
+
"""Return the portable bundle root, or None when running from a checkout."""
|
|
307
|
+
package = Path(__file__).resolve().parent # <root>/runtime/app/logic_agent
|
|
308
|
+
if package.parent.name != "app":
|
|
309
|
+
return None
|
|
310
|
+
runtime = package.parent.parent
|
|
311
|
+
if not (runtime / "python").is_dir():
|
|
312
|
+
return None
|
|
313
|
+
return runtime.parent
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def _python_in(directory: Path) -> Path | None:
|
|
317
|
+
for name in ("python.exe", "python3", "python"):
|
|
318
|
+
candidate = directory / name
|
|
319
|
+
if candidate.is_file():
|
|
320
|
+
return candidate
|
|
321
|
+
return None
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def build_launch_spec(
|
|
325
|
+
*,
|
|
326
|
+
data_dir: str | Path | None = None,
|
|
327
|
+
backend: str | None = None,
|
|
328
|
+
root: str | Path | None = None,
|
|
329
|
+
home: str | Path | None = None,
|
|
330
|
+
) -> LaunchSpec:
|
|
331
|
+
"""Build the argv clients should use. Never depends on the current directory."""
|
|
332
|
+
portable = Path(root).expanduser().resolve() if root else bundle_root()
|
|
333
|
+
python: Path | None = None
|
|
334
|
+
environment = {"PYTHONDONTWRITEBYTECODE": "1"}
|
|
335
|
+
if portable is not None:
|
|
336
|
+
python = _python_in(portable / "runtime" / "python")
|
|
337
|
+
chosen_data = Path(data_dir).expanduser() if data_dir else portable / "data" / "captures"
|
|
338
|
+
mode = "bundle"
|
|
339
|
+
else:
|
|
340
|
+
portable = None
|
|
341
|
+
base_home = Path(home).expanduser() if home else Path.home()
|
|
342
|
+
chosen_data = Path(data_dir).expanduser() if data_dir else base_home / ".logic_agent_data"
|
|
343
|
+
mode = "source"
|
|
344
|
+
# Clients start the server from an arbitrary directory; make the package
|
|
345
|
+
# importable without relying on the caller's cwd or an editable install.
|
|
346
|
+
package_root = Path(__file__).resolve().parent.parent
|
|
347
|
+
if package_root.name not in {"site-packages", "dist-packages"}:
|
|
348
|
+
environment["PYTHONPATH"] = str(package_root)
|
|
349
|
+
executable = python or Path(sys.executable)
|
|
350
|
+
resolved_data = chosen_data.resolve()
|
|
351
|
+
args = ["-m", "logic_agent.mcp_server", "--data-dir", str(resolved_data)]
|
|
352
|
+
if backend:
|
|
353
|
+
args += ["--backend", backend]
|
|
354
|
+
return LaunchSpec(
|
|
355
|
+
command=str(executable),
|
|
356
|
+
args=args,
|
|
357
|
+
env=environment,
|
|
358
|
+
mode=mode,
|
|
359
|
+
data_dir=str(resolved_data),
|
|
360
|
+
root=str(portable) if portable is not None else None,
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
# --------------------------------------------------------------------------- config I/O
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def server_entry(spec: ClientSpec, launch: LaunchSpec) -> dict[str, Any]:
|
|
368
|
+
entry: dict[str, Any] = {}
|
|
369
|
+
if spec.stype:
|
|
370
|
+
entry["type"] = spec.stype
|
|
371
|
+
entry["command"] = launch.command
|
|
372
|
+
entry["args"] = list(launch.args)
|
|
373
|
+
if launch.env:
|
|
374
|
+
entry["env"] = dict(launch.env)
|
|
375
|
+
for key, value in spec.extra.items():
|
|
376
|
+
entry.setdefault(key, value)
|
|
377
|
+
return entry
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def toml_block(spec: ClientSpec, launch: LaunchSpec) -> str:
|
|
381
|
+
lines = [
|
|
382
|
+
f"[{spec.container}.{CODEX_SERVER_NAME}]",
|
|
383
|
+
f"command = {_toml_string(launch.command)}",
|
|
384
|
+
"args = [" + ", ".join(_toml_string(item) for item in launch.args) + "]",
|
|
385
|
+
]
|
|
386
|
+
if launch.env:
|
|
387
|
+
pairs = ", ".join(f"{key} = {_toml_string(value)}" for key, value in launch.env.items())
|
|
388
|
+
lines.append(f"env = {{ {pairs} }}")
|
|
389
|
+
return "\n".join(lines) + "\n"
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def _toml_string(value: str) -> str:
|
|
393
|
+
escaped = (
|
|
394
|
+
value.replace("\\", "\\\\")
|
|
395
|
+
.replace('"', '\\"')
|
|
396
|
+
.replace("\n", "\\n")
|
|
397
|
+
.replace("\r", "\\r")
|
|
398
|
+
.replace("\t", "\\t")
|
|
399
|
+
)
|
|
400
|
+
return f'"{escaped}"'
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def _read_text(path: Path) -> str:
|
|
404
|
+
try:
|
|
405
|
+
return path.read_text(encoding="utf-8-sig")
|
|
406
|
+
except UnicodeDecodeError as exc:
|
|
407
|
+
raise ConfigError(f"{path} is not UTF-8: {exc}") from exc
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def _atomic_write(path: Path, text: str) -> None:
|
|
411
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
412
|
+
handle, temporary = tempfile.mkstemp(prefix=path.name + ".", suffix=".tmp", dir=str(path.parent))
|
|
413
|
+
try:
|
|
414
|
+
with os.fdopen(handle, "w", encoding="utf-8", newline="\n") as stream:
|
|
415
|
+
stream.write(text)
|
|
416
|
+
os.replace(temporary, path)
|
|
417
|
+
except BaseException:
|
|
418
|
+
try:
|
|
419
|
+
os.unlink(temporary)
|
|
420
|
+
except OSError:
|
|
421
|
+
pass
|
|
422
|
+
raise
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
def _load_json(path: Path) -> dict[str, Any]:
|
|
426
|
+
if not path.exists():
|
|
427
|
+
return {}
|
|
428
|
+
text = _read_text(path)
|
|
429
|
+
if not text.strip():
|
|
430
|
+
return {}
|
|
431
|
+
try:
|
|
432
|
+
data = json.loads(text)
|
|
433
|
+
except json.JSONDecodeError as exc:
|
|
434
|
+
raise ConfigError(f"{path} is not valid JSON ({exc}); left unchanged") from exc
|
|
435
|
+
if not isinstance(data, dict):
|
|
436
|
+
raise ConfigError(f"{path} does not contain a JSON object; left unchanged")
|
|
437
|
+
return data
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def install_json(path: Path, spec: ClientSpec, launch: LaunchSpec, *, remove: bool = False) -> str:
|
|
441
|
+
data = _load_json(path)
|
|
442
|
+
before = json.dumps(data, indent=2, ensure_ascii=False)
|
|
443
|
+
servers = data.get(spec.container)
|
|
444
|
+
if servers is None:
|
|
445
|
+
if remove:
|
|
446
|
+
return "absent"
|
|
447
|
+
servers = {}
|
|
448
|
+
if not isinstance(servers, dict):
|
|
449
|
+
raise ConfigError(f'"{spec.container}" in {path} is not a JSON object; left unchanged')
|
|
450
|
+
if remove:
|
|
451
|
+
if SERVER_NAME not in servers:
|
|
452
|
+
return "absent"
|
|
453
|
+
del servers[SERVER_NAME]
|
|
454
|
+
if servers:
|
|
455
|
+
data[spec.container] = servers
|
|
456
|
+
else:
|
|
457
|
+
data.pop(spec.container, None)
|
|
458
|
+
# Removing the last entry should undo the install, not leave a "{}" file.
|
|
459
|
+
if not data:
|
|
460
|
+
path.unlink(missing_ok=True)
|
|
461
|
+
return "written"
|
|
462
|
+
else:
|
|
463
|
+
servers[SERVER_NAME] = server_entry(spec, launch)
|
|
464
|
+
data[spec.container] = servers
|
|
465
|
+
after = json.dumps(data, indent=2, ensure_ascii=False)
|
|
466
|
+
if after == before:
|
|
467
|
+
return "unchanged"
|
|
468
|
+
_atomic_write(path, after + "\n")
|
|
469
|
+
return "written"
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def _is_codex_header(line: str, table: str, name: str) -> bool:
|
|
473
|
+
body = line.strip().split("#", 1)[0].strip()
|
|
474
|
+
if not body.startswith("[") or body.startswith("[[") or not body.endswith("]"):
|
|
475
|
+
return False
|
|
476
|
+
inner = body[1:-1].strip()
|
|
477
|
+
for candidate in (f"{table}.{name}", f'{table}."{name}"', f"{table}.'{name}'"):
|
|
478
|
+
if inner == candidate or inner.startswith(candidate + "."):
|
|
479
|
+
return True
|
|
480
|
+
return False
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def strip_toml_table(text: str, table: str, name: str) -> tuple[str, bool]:
|
|
484
|
+
"""Remove ``[table.name]`` and its sub-tables; keep everything else verbatim."""
|
|
485
|
+
kept: list[str] = []
|
|
486
|
+
skipping = False
|
|
487
|
+
removed = False
|
|
488
|
+
for line in text.splitlines(keepends=True):
|
|
489
|
+
if line.lstrip().startswith("["):
|
|
490
|
+
skipping = _is_codex_header(line, table, name)
|
|
491
|
+
removed = removed or skipping
|
|
492
|
+
if not skipping:
|
|
493
|
+
kept.append(line)
|
|
494
|
+
result = "".join(kept)
|
|
495
|
+
if removed:
|
|
496
|
+
result = result.rstrip("\n")
|
|
497
|
+
result = re.sub(r"\n{3,}", "\n\n", result)
|
|
498
|
+
result = result + "\n" if result else ""
|
|
499
|
+
return result, removed
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def install_toml(path: Path, spec: ClientSpec, launch: LaunchSpec, *, remove: bool = False) -> str:
|
|
503
|
+
text = _read_text(path) if path.exists() else ""
|
|
504
|
+
remaining, found = strip_toml_table(text, spec.container, CODEX_SERVER_NAME)
|
|
505
|
+
if remove:
|
|
506
|
+
if not found:
|
|
507
|
+
return "absent"
|
|
508
|
+
result = remaining
|
|
509
|
+
else:
|
|
510
|
+
block = toml_block(spec, launch)
|
|
511
|
+
result = (remaining.rstrip("\n") + "\n\n" + block) if remaining.strip() else block
|
|
512
|
+
try:
|
|
513
|
+
parsed = tomllib.loads(result)
|
|
514
|
+
except tomllib.TOMLDecodeError as exc:
|
|
515
|
+
raise ConfigError(f"{path} cannot be parsed as TOML ({exc}); left unchanged") from exc
|
|
516
|
+
if remove:
|
|
517
|
+
# Removing the last table should undo the install, not leave an empty file.
|
|
518
|
+
if not result.strip():
|
|
519
|
+
path.unlink(missing_ok=True)
|
|
520
|
+
return "written"
|
|
521
|
+
_atomic_write(path, result)
|
|
522
|
+
return "written"
|
|
523
|
+
table = parsed.get(spec.container)
|
|
524
|
+
entry = table.get(CODEX_SERVER_NAME) if isinstance(table, dict) else None
|
|
525
|
+
if not isinstance(entry, dict) or entry.get("command") != launch.command:
|
|
526
|
+
raise ConfigError(f"could not add [{spec.container}.{CODEX_SERVER_NAME}] to {path}; left unchanged")
|
|
527
|
+
if result == text:
|
|
528
|
+
return "unchanged"
|
|
529
|
+
_atomic_write(path, result)
|
|
530
|
+
return "written"
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
def _yaml_string(value: str) -> str:
|
|
534
|
+
escaped = value.replace("\\", "\\\\").replace('"', '\\"')
|
|
535
|
+
return f'"{escaped}"'
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def dsh_item(launch: LaunchSpec) -> str:
|
|
539
|
+
"""The Cordis patch entry that gives DeepSeek Harness the logic analyzer."""
|
|
540
|
+
cwd = launch.root or str(Path(__file__).resolve().parent.parent)
|
|
541
|
+
lines = [
|
|
542
|
+
"- insert:",
|
|
543
|
+
f" - id: {DSH_ITEM_ID}",
|
|
544
|
+
' name: "@deepseek-ai/dsh-mcp-client"',
|
|
545
|
+
" config:",
|
|
546
|
+
f" serverName: {DSH_SERVER_NAME}",
|
|
547
|
+
" transport: stdio",
|
|
548
|
+
f" command: {_yaml_string(launch.command)}",
|
|
549
|
+
" args:",
|
|
550
|
+
*(f" - {_yaml_string(item)}" for item in launch.args),
|
|
551
|
+
f" cwd: {_yaml_string(cwd)}",
|
|
552
|
+
" toolCallTimeoutMs: 120000",
|
|
553
|
+
" failOnStartupError: false",
|
|
554
|
+
]
|
|
555
|
+
return "\n".join(lines) + "\n"
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
def dsh_block(launch: LaunchSpec) -> str:
|
|
559
|
+
return f"{DSH_MARK_START}\n{dsh_item(launch)}{DSH_MARK_END}\n"
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
def _strip_managed_yaml(text: str) -> tuple[str, bool]:
|
|
563
|
+
if DSH_MARK_START not in text:
|
|
564
|
+
return text, False
|
|
565
|
+
stripped = DSH_MANAGED.sub("", text)
|
|
566
|
+
stripped = re.sub(r"\n{3,}", "\n\n", stripped).rstrip("\n")
|
|
567
|
+
return (stripped + "\n") if stripped else "", True
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
def _is_yaml_sequence(text: str) -> bool:
|
|
571
|
+
"""Accept empty files, ``[]`` and documents whose first token is a sequence item."""
|
|
572
|
+
for line in text.splitlines():
|
|
573
|
+
stripped = line.strip()
|
|
574
|
+
if not stripped or stripped.startswith("#"):
|
|
575
|
+
continue
|
|
576
|
+
return stripped.startswith("- ") or stripped == "-" or stripped.startswith("[")
|
|
577
|
+
return True
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
def _yaml_items(text: str) -> list[tuple[int, int]]:
|
|
581
|
+
"""(start, end) line ranges of the top-level ``- ...`` entries."""
|
|
582
|
+
lines = text.splitlines(keepends=True)
|
|
583
|
+
starts = [index for index, line in enumerate(lines) if line.startswith("- ")]
|
|
584
|
+
spans: list[tuple[int, int]] = []
|
|
585
|
+
for position, start in enumerate(starts):
|
|
586
|
+
end = starts[position + 1] if position + 1 < len(starts) else len(lines)
|
|
587
|
+
spans.append((start, end))
|
|
588
|
+
return spans
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def _find_dsh_item(text: str) -> tuple[int, int] | None:
|
|
592
|
+
"""Locate a hand-written logic-analyzer entry so we can adopt it instead of duplicating."""
|
|
593
|
+
lines = text.splitlines(keepends=True)
|
|
594
|
+
for start, end in _yaml_items(text):
|
|
595
|
+
chunk = "".join(lines[start:end])
|
|
596
|
+
if "@deepseek-ai/dsh-mcp-client" not in chunk:
|
|
597
|
+
continue
|
|
598
|
+
if f"id: {DSH_ITEM_ID}" in chunk or f"serverName: {DSH_SERVER_NAME}" in chunk:
|
|
599
|
+
return start, end
|
|
600
|
+
return None
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
def _backup(path: Path, text: str) -> None:
|
|
604
|
+
if not text.strip():
|
|
605
|
+
return
|
|
606
|
+
_atomic_write(path.with_name(path.name + ".bak"), text)
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
def install_yaml(path: Path, spec: ClientSpec, launch: LaunchSpec, *, remove: bool = False) -> str:
|
|
610
|
+
text = _read_text(path) if path.exists() else ""
|
|
611
|
+
remaining, had_block = _strip_managed_yaml(text)
|
|
612
|
+
if remove:
|
|
613
|
+
if not had_block:
|
|
614
|
+
return "absent"
|
|
615
|
+
_atomic_write(path, remaining if remaining.strip() else "[]\n")
|
|
616
|
+
return "written"
|
|
617
|
+
|
|
618
|
+
if not _is_yaml_sequence(remaining):
|
|
619
|
+
raise ConfigError(f"{path} 的顶层不是 YAML 列表,拒绝写入(未修改)")
|
|
620
|
+
|
|
621
|
+
block = dsh_block(launch)
|
|
622
|
+
if had_block:
|
|
623
|
+
result = (remaining.rstrip("\n") + "\n\n" + block) if remaining.strip() else block
|
|
624
|
+
else:
|
|
625
|
+
span = _find_dsh_item(text)
|
|
626
|
+
if span is not None:
|
|
627
|
+
# Adopt the hand-written entry: same server, but now owned by the installer.
|
|
628
|
+
start, end = span
|
|
629
|
+
lines = text.splitlines(keepends=True)
|
|
630
|
+
suffix = "".join(lines[end:])
|
|
631
|
+
result = "".join(lines[:start]) + block + ("\n" + suffix if suffix.strip() else "")
|
|
632
|
+
_backup(path, text)
|
|
633
|
+
elif text.strip():
|
|
634
|
+
result = text.rstrip("\n") + "\n\n" + block
|
|
635
|
+
_backup(path, text)
|
|
636
|
+
else:
|
|
637
|
+
result = block
|
|
638
|
+
|
|
639
|
+
if result == text:
|
|
640
|
+
return "unchanged"
|
|
641
|
+
if not _is_yaml_sequence(result):
|
|
642
|
+
raise ConfigError(f"{path}: 写入后不再是 YAML 列表,已放弃(未修改)")
|
|
643
|
+
_atomic_write(path, result)
|
|
644
|
+
return "written"
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
def apply_client(
|
|
648
|
+
spec: ClientSpec,
|
|
649
|
+
launch: LaunchSpec,
|
|
650
|
+
path: Path,
|
|
651
|
+
*,
|
|
652
|
+
remove: bool = False,
|
|
653
|
+
dry_run: bool = False,
|
|
654
|
+
) -> tuple[str, str]:
|
|
655
|
+
if dry_run:
|
|
656
|
+
return "dry-run", snippet(spec, launch, path)
|
|
657
|
+
if spec.fmt == "toml":
|
|
658
|
+
status = install_toml(path, spec, launch, remove=remove)
|
|
659
|
+
elif spec.fmt == "yaml":
|
|
660
|
+
status = install_yaml(path, spec, launch, remove=remove)
|
|
661
|
+
else:
|
|
662
|
+
status = install_json(path, spec, launch, remove=remove)
|
|
663
|
+
if remove and status == "written":
|
|
664
|
+
status = "removed"
|
|
665
|
+
return status, ""
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
def snippet(spec: ClientSpec, launch: LaunchSpec, path: Path) -> str:
|
|
669
|
+
if spec.fmt == "toml":
|
|
670
|
+
return f"# {path}\n" + toml_block(spec, launch)
|
|
671
|
+
if spec.fmt == "yaml":
|
|
672
|
+
return f"# {path}\n" + dsh_block(launch)
|
|
673
|
+
document = {spec.container: {SERVER_NAME: server_entry(spec, launch)}}
|
|
674
|
+
return f"// {path}\n" + json.dumps(document, indent=2, ensure_ascii=False)
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
# --------------------------------------------------------------------------- reporting
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
@dataclass
|
|
681
|
+
class Result:
|
|
682
|
+
id: str
|
|
683
|
+
label: str
|
|
684
|
+
status: str
|
|
685
|
+
path: str | None = None
|
|
686
|
+
detail: str = ""
|
|
687
|
+
hint: str = ""
|
|
688
|
+
|
|
689
|
+
def as_dict(self) -> dict[str, Any]:
|
|
690
|
+
return {
|
|
691
|
+
"id": self.id,
|
|
692
|
+
"label": self.label,
|
|
693
|
+
"status": self.status,
|
|
694
|
+
"path": self.path,
|
|
695
|
+
"detail": self.detail,
|
|
696
|
+
"hint": self.hint,
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
@dataclass
|
|
701
|
+
class Installation:
|
|
702
|
+
launch: LaunchSpec
|
|
703
|
+
results: list[Result] = field(default_factory=list)
|
|
704
|
+
detected: list[str] = field(default_factory=list)
|
|
705
|
+
not_detected: list[str] = field(default_factory=list)
|
|
706
|
+
verification: dict[str, Any] | None = None
|
|
707
|
+
removed: bool = False
|
|
708
|
+
include_all: bool = False
|
|
709
|
+
explicit: bool = False
|
|
710
|
+
|
|
711
|
+
@property
|
|
712
|
+
def ok(self) -> bool:
|
|
713
|
+
if any(item.status == "error" for item in self.results):
|
|
714
|
+
return False
|
|
715
|
+
if self.verification is not None and not self.verification.get("ok"):
|
|
716
|
+
return False
|
|
717
|
+
return True
|
|
718
|
+
|
|
719
|
+
def as_dict(self) -> dict[str, Any]:
|
|
720
|
+
return {
|
|
721
|
+
"ok": self.ok,
|
|
722
|
+
"launch": self.launch.as_dict(),
|
|
723
|
+
"removed": self.removed,
|
|
724
|
+
"clients": [item.as_dict() for item in self.results],
|
|
725
|
+
"detected": self.detected,
|
|
726
|
+
"not_detected": self.not_detected,
|
|
727
|
+
"verification": self.verification,
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
def detect_clients(loc: Locations) -> list[ClientSpec]:
|
|
732
|
+
return [spec for spec in CLIENTS if _is_detected(spec, loc)]
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
def _is_detected(spec: ClientSpec, loc: Locations) -> bool:
|
|
736
|
+
if any(_expand(template, loc).exists() for template in spec.detect):
|
|
737
|
+
return True
|
|
738
|
+
if spec.binary and loc.binaries and shutil.which(spec.binary):
|
|
739
|
+
return True
|
|
740
|
+
return False
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
def list_clients(loc: Locations) -> list[dict[str, Any]]:
|
|
744
|
+
"""Describe every supported client: detected or not, and exactly where its config lives."""
|
|
745
|
+
rows: list[dict[str, Any]] = []
|
|
746
|
+
for spec in CLIENTS:
|
|
747
|
+
rows.append(
|
|
748
|
+
{
|
|
749
|
+
"id": spec.id,
|
|
750
|
+
"label": spec.label,
|
|
751
|
+
"detected": _is_detected(spec, loc),
|
|
752
|
+
"format": spec.fmt,
|
|
753
|
+
"user_config": str(_expand(spec.user, loc)),
|
|
754
|
+
"project_config": str(_expand(spec.project, loc)) if spec.project else None,
|
|
755
|
+
"hint": spec.hint,
|
|
756
|
+
}
|
|
757
|
+
)
|
|
758
|
+
return rows
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
def format_clients(rows: list[dict[str, Any]]) -> str:
|
|
762
|
+
width = max(len(str(row["id"])) for row in rows) + 2
|
|
763
|
+
lines = ["Supported agents ('yes' means it was found on this machine):", ""]
|
|
764
|
+
for row in rows:
|
|
765
|
+
mark = "yes" if row["detected"] else "no "
|
|
766
|
+
lines.append(f" {row['id']:<{width}}{mark:<4}{row['user_config']}")
|
|
767
|
+
lines.append("")
|
|
768
|
+
lines.append("Add one with `logic-agent mcp-install <id>`, or every detected agent with `logic-agent mcp-install`.")
|
|
769
|
+
return "\n".join(lines)
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
# --------------------------------------------------------------------------- verification
|
|
773
|
+
|
|
774
|
+
def verify_launch(launch: LaunchSpec, *, timeout_s: float = 60.0) -> dict[str, Any]:
|
|
775
|
+
"""Spawn the server exactly as a client would and require a real handshake."""
|
|
776
|
+
command = Path(launch.command)
|
|
777
|
+
if not (command.is_file() or shutil.which(launch.command)):
|
|
778
|
+
return {"ok": False, "detail": f"command not found: {launch.command}"}
|
|
779
|
+
requests = [
|
|
780
|
+
{
|
|
781
|
+
"jsonrpc": "2.0",
|
|
782
|
+
"id": 1,
|
|
783
|
+
"method": "initialize",
|
|
784
|
+
"params": {
|
|
785
|
+
"protocolVersion": "2024-11-05",
|
|
786
|
+
"capabilities": {},
|
|
787
|
+
"clientInfo": {"name": "logic-agent-setup", "version": __version__},
|
|
788
|
+
},
|
|
789
|
+
},
|
|
790
|
+
{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "capabilities", "arguments": {}}},
|
|
791
|
+
]
|
|
792
|
+
payload = "\n".join(json.dumps(item) for item in requests) + "\n"
|
|
793
|
+
environment = os.environ.copy()
|
|
794
|
+
environment.update(launch.env)
|
|
795
|
+
try:
|
|
796
|
+
completed = subprocess.run(
|
|
797
|
+
[launch.command, *launch.args],
|
|
798
|
+
input=payload,
|
|
799
|
+
capture_output=True,
|
|
800
|
+
text=True,
|
|
801
|
+
timeout=timeout_s,
|
|
802
|
+
env=environment,
|
|
803
|
+
# A client may start the server from any directory; prove that it works.
|
|
804
|
+
cwd=tempfile.gettempdir(),
|
|
805
|
+
)
|
|
806
|
+
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
807
|
+
return {"ok": False, "detail": f"{type(exc).__name__}: {exc}"}
|
|
808
|
+
if "logic-agent" not in completed.stdout:
|
|
809
|
+
detail = (completed.stderr or completed.stdout or "").strip()[-600:]
|
|
810
|
+
return {"ok": False, "detail": detail or f"exit code {completed.returncode}, no MCP reply"}
|
|
811
|
+
backends: dict[str, Any] = {}
|
|
812
|
+
protocol_count = None
|
|
813
|
+
for line in completed.stdout.splitlines():
|
|
814
|
+
if not line.strip():
|
|
815
|
+
continue
|
|
816
|
+
try:
|
|
817
|
+
message = json.loads(line)
|
|
818
|
+
except json.JSONDecodeError:
|
|
819
|
+
continue
|
|
820
|
+
if message.get("id") != 2:
|
|
821
|
+
continue
|
|
822
|
+
structured = (message.get("result") or {}).get("structuredContent") or {}
|
|
823
|
+
backends = {
|
|
824
|
+
name: bool(value.get("available")) for name, value in (structured.get("backends") or {}).items()
|
|
825
|
+
}
|
|
826
|
+
protocols = (structured.get("protocol_decoding") or {}).get("supported_protocols") or []
|
|
827
|
+
protocol_count = len(protocols)
|
|
828
|
+
if not backends:
|
|
829
|
+
return {"ok": False, "detail": "server answered initialize but not capabilities"}
|
|
830
|
+
return {"ok": True, "backends": backends, "protocols": protocol_count}
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
# --------------------------------------------------------------------------- entry point
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
def install(
|
|
837
|
+
*,
|
|
838
|
+
locations: Locations | None = None,
|
|
839
|
+
scope: str = "user",
|
|
840
|
+
only: Iterable[str] = (),
|
|
841
|
+
include_all: bool = False,
|
|
842
|
+
remove: bool = False,
|
|
843
|
+
dry_run: bool = False,
|
|
844
|
+
verify: bool = True,
|
|
845
|
+
data_dir: str | Path | None = None,
|
|
846
|
+
backend: str | None = None,
|
|
847
|
+
root: str | Path | None = None,
|
|
848
|
+
) -> Installation:
|
|
849
|
+
if scope not in SCOPES:
|
|
850
|
+
raise ConfigError(f"unknown scope: {scope}", details={"scopes": list(SCOPES)})
|
|
851
|
+
loc = locations or Locations.detect()
|
|
852
|
+
requested = [client_by_id(item) for item in only]
|
|
853
|
+
installation = Installation(
|
|
854
|
+
launch=build_launch_spec(data_dir=data_dir, backend=backend, root=root, home=loc.home),
|
|
855
|
+
include_all=include_all,
|
|
856
|
+
explicit=bool(requested),
|
|
857
|
+
)
|
|
858
|
+
installation.detected = [spec.id for spec in detect_clients(loc)]
|
|
859
|
+
installation.not_detected = [spec.id for spec in CLIENTS if spec.id not in installation.detected]
|
|
860
|
+
installation.removed = remove
|
|
861
|
+
|
|
862
|
+
for spec in requested or CLIENTS:
|
|
863
|
+
if requested and scope == "project" and spec.project is None:
|
|
864
|
+
installation.results.append(Result(spec.id, spec.label, "skipped", detail="no project-scope config"))
|
|
865
|
+
continue
|
|
866
|
+
if not requested and not include_all and scope == "user" and spec.id not in installation.detected:
|
|
867
|
+
continue
|
|
868
|
+
template = spec.user if scope == "user" else spec.project
|
|
869
|
+
if template is None:
|
|
870
|
+
installation.results.append(Result(spec.id, spec.label, "skipped", detail="no project-scope config"))
|
|
871
|
+
continue
|
|
872
|
+
target = _expand(template, loc)
|
|
873
|
+
try:
|
|
874
|
+
status, detail = apply_client(spec, installation.launch, target, remove=remove, dry_run=dry_run)
|
|
875
|
+
except (OSError, ConfigError) as exc:
|
|
876
|
+
installation.results.append(Result(spec.id, spec.label, "error", str(target), str(exc), spec.hint))
|
|
877
|
+
continue
|
|
878
|
+
installation.results.append(Result(spec.id, spec.label, status, str(target), detail, spec.hint))
|
|
879
|
+
|
|
880
|
+
wrote = any(item.status in {"written", "unchanged"} for item in installation.results)
|
|
881
|
+
if verify and not dry_run and not remove and wrote:
|
|
882
|
+
installation.verification = verify_launch(installation.launch)
|
|
883
|
+
return installation
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
# --------------------------------------------------------------------------- text output
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
_MARKERS = {
|
|
890
|
+
"written": "added",
|
|
891
|
+
"unchanged": "ok",
|
|
892
|
+
"removed": "removed",
|
|
893
|
+
"absent": "absent",
|
|
894
|
+
"skipped": "skipped",
|
|
895
|
+
"dry-run": "preview",
|
|
896
|
+
"error": "ERROR",
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
def format_report(installation: Installation, *, dry_run: bool = False) -> str:
|
|
901
|
+
launch = installation.launch
|
|
902
|
+
lines = [
|
|
903
|
+
"logic-agent MCP setup",
|
|
904
|
+
f" mode : {launch.mode}" + (f" ({launch.root})" if launch.root else ""),
|
|
905
|
+
f" command : {launch.command_line}",
|
|
906
|
+
"",
|
|
907
|
+
]
|
|
908
|
+
if dry_run:
|
|
909
|
+
lines.append("Copy-paste preview (nothing was written):")
|
|
910
|
+
for item in installation.results:
|
|
911
|
+
lines.append("")
|
|
912
|
+
lines.append(item.detail)
|
|
913
|
+
lines.append("")
|
|
914
|
+
lines.append("Write them automatically by running this command without --dry-run.")
|
|
915
|
+
return "\n".join(lines)
|
|
916
|
+
|
|
917
|
+
if installation.results:
|
|
918
|
+
lines.append("Remove" if installation.removed else "Install")
|
|
919
|
+
width = max(len(item.id) for item in installation.results) + 2
|
|
920
|
+
for item in installation.results:
|
|
921
|
+
marker = _MARKERS.get(item.status, item.status)
|
|
922
|
+
target = item.path or ""
|
|
923
|
+
lines.append(f" {item.id:<{width}}{marker:<9}{target}")
|
|
924
|
+
if item.detail and item.status == "error":
|
|
925
|
+
for chunk in item.detail.splitlines():
|
|
926
|
+
lines.append(f" {'':<{width}}{'':<9}{chunk}")
|
|
927
|
+
lines.append("")
|
|
928
|
+
if installation.verification:
|
|
929
|
+
check = installation.verification
|
|
930
|
+
if check.get("ok"):
|
|
931
|
+
backends = ", ".join(f"{name}={'yes' if up else 'no'}" for name, up in (check.get("backends") or {}).items())
|
|
932
|
+
protocols = check.get("protocols")
|
|
933
|
+
suffix = f"; {protocols} protocols" if protocols else ""
|
|
934
|
+
lines.append(f"Verified: the server starts and answers capabilities ({backends}{suffix}).")
|
|
935
|
+
else:
|
|
936
|
+
lines.append(f"Verification FAILED: {check.get('detail')}")
|
|
937
|
+
lines.append("")
|
|
938
|
+
if installation.removed and installation.results:
|
|
939
|
+
lines.append("Restart the app if it is open: the logic-analyzer entry is gone.")
|
|
940
|
+
lines.append("")
|
|
941
|
+
elif installation.results:
|
|
942
|
+
hints = sorted({item.hint for item in installation.results if item.hint})
|
|
943
|
+
lines.append('Next: restart the app, then ask the agent to call the "capabilities" tool.')
|
|
944
|
+
if len(hints) <= 4:
|
|
945
|
+
for hint in hints:
|
|
946
|
+
lines.append(f" - {hint}")
|
|
947
|
+
else:
|
|
948
|
+
lines.append(" - quit the client completely (Claude Desktop: use the tray icon) and reopen it")
|
|
949
|
+
lines.append("")
|
|
950
|
+
if installation.not_detected and not installation.include_all and not installation.explicit:
|
|
951
|
+
lines.append("Not detected: " + ", ".join(installation.not_detected))
|
|
952
|
+
lines.append(" `--all` configures them anyway; `--dry-run` prints copy-paste snippets.")
|
|
953
|
+
lines.append("")
|
|
954
|
+
if not installation.results and not installation.not_detected:
|
|
955
|
+
lines.append("No agent was configured.")
|
|
956
|
+
return "\n".join(lines).rstrip() + "\n"
|