diff --git a/Cargo.lock b/Cargo.lock index b5ae587..34f641f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,29 +26,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "aes" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures 0.2.17", -] - -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.4" @@ -58,12 +35,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" - [[package]] name = "android_system_properties" version = "0.1.5" @@ -129,15 +100,6 @@ version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" -[[package]] -name = "ar_archive_writer" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb93bbb63b9c227414f6eb3a0adfddca591a8ce1e9b60661bb08969b87e340b" -dependencies = [ - "object", -] - [[package]] name = "async-channel" version = "1.9.0" @@ -231,9 +193,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.39.0" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fa7e52a4c5c547c741610a2c6f123f3881e409b714cd27e6798ef020c514f0a" +checksum = "83a25cf98105baa966497416dbd42565ce3a8cf8dbfd59803ec9ad46f3126399" dependencies = [ "cc", "cmake", @@ -339,6 +301,12 @@ version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "byteorder-lite" version = "0.1.0" @@ -351,20 +319,11 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" -[[package]] -name = "bzip2" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c" -dependencies = [ - "libbz2-rs-sys", -] - [[package]] name = "cc" -version = "1.2.57" +version = "1.2.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423" +checksum = "b7a4d3ec6524d28a329fc53654bbadc9bdd7b0431f5d65f1a56ffb28a1ee5283" dependencies = [ "find-msvc-tools", "jobserver", @@ -441,16 +400,6 @@ dependencies = [ "phf", ] -[[package]] -name = "chumsky" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eebd66744a15ded14960ab4ccdbfb51ad3b81f51f3f04a80adac98c985396c9" -dependencies = [ - "hashbrown 0.14.5", - "stacker", -] - [[package]] name = "cipher" version = "0.4.4" @@ -513,9 +462,9 @@ checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" [[package]] name = "cmake" -version = "0.1.57" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75443c44cd6b379beb8c5b45d85d0773baf31cce901fe7bb252f4eff3008ef7d" +checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678" dependencies = [ "cc", ] @@ -563,12 +512,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "constant_time_eq" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" - [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -636,21 +579,6 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea" -[[package]] -name = "deflate64" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac6b926516df9c60bfa16e107b21086399f8285a44ca9711344b9e553c5146e2" - -[[package]] -name = "deranged" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" -dependencies = [ - "powerfmt", -] - [[package]] name = "dialoguer" version = "0.12.0" @@ -813,9 +741,9 @@ checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" [[package]] name = "fastrand" -version = "2.3.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" [[package]] name = "fdeflate" @@ -851,7 +779,6 @@ checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" dependencies = [ "crc32fast", "miniz_oxide", - "zlib-rs", ] [[package]] @@ -1022,13 +949,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" dependencies = [ "cfg-if", - "js-sys", "libc", "r-efi 6.0.0", "rand_core 0.10.0", "wasip2", "wasip3", - "wasm-bindgen", ] [[package]] @@ -1056,16 +981,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" -dependencies = [ - "ahash", - "allocator-api2", -] - [[package]] name = "hashbrown" version = "0.15.5" @@ -1083,10 +998,11 @@ checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" [[package]] name = "hashify" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "149e3ea90eb5a26ad354cfe3cb7f7401b9329032d0235f2687d03a35f30e5d4c" +checksum = "dd1246c0e5493286aeb2dde35b1f4eb9c4ce00e628641210a5e553fc001a1f26" dependencies = [ + "indexmap", "proc-macro2", "quote", "syn", @@ -1180,9 +1096,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" dependencies = [ "atomic-waker", "bytes", @@ -1195,7 +1111,6 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "pin-utils", "smallvec", "tokio", "want", @@ -1267,12 +1182,13 @@ dependencies = [ [[package]] name = "icu_collections" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" dependencies = [ "displaydoc", "potential_utf", + "utf8_iter", "yoke", "zerofrom", "zerovec", @@ -1280,9 +1196,9 @@ dependencies = [ [[package]] name = "icu_locale_core" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" dependencies = [ "displaydoc", "litemap", @@ -1293,9 +1209,9 @@ dependencies = [ [[package]] name = "icu_normalizer" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" dependencies = [ "icu_collections", "icu_normalizer_data", @@ -1307,15 +1223,15 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" [[package]] name = "icu_properties" -version = "2.1.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" dependencies = [ "icu_collections", "icu_locale_core", @@ -1327,15 +1243,15 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.1.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" [[package]] name = "icu_provider" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" dependencies = [ "displaydoc", "icu_locale_core", @@ -1399,9 +1315,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.13.0" +version = "2.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "45a8a2b9cb3e0b0c1803dbb0758ffac5de2f425b23c28f518faabd9d805342ff" dependencies = [ "equivalent", "hashbrown 0.16.1", @@ -1439,9 +1355,9 @@ checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" [[package]] name = "iri-string" -version = "0.7.11" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e7418f59cc01c88316161279a7f665217ae316b388e58a0d10e29f54f1e5eb" +checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" dependencies = [ "memchr", "serde", @@ -1471,10 +1387,12 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.91" +version = "0.3.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +checksum = "2e04e2ef80ce82e13552136fabeef8a5ed1f985a96805761cbb9a2c34e7664d9" dependencies = [ + "cfg-if", + "futures-util", "once_cell", "wasm-bindgen", ] @@ -1493,12 +1411,11 @@ checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "lettre" -version = "0.11.19" +version = "0.11.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e13e10e8818f8b2a60f52cb127041d388b89f3a96a62be9ceaffa22262fef7f" +checksum = "dabda5859ee7c06b995b9d1165aa52c39110e079ef609db97178d86aeb051fa7" dependencies = [ "base64", - "chumsky", "email-encoding", "email_address", "fastrand", @@ -1515,17 +1432,11 @@ dependencies = [ "webpki-roots 1.0.6", ] -[[package]] -name = "libbz2-rs-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c4a545a15244c7d945065b5d392b2d2d7f21526fba56ce51467b06ed445e8f7" - [[package]] name = "libc" -version = "0.2.183" +version = "0.2.184" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af" [[package]] name = "libloading" @@ -1568,9 +1479,9 @@ checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "litemap" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "lock_api" @@ -1593,15 +1504,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" -[[package]] -name = "lzma-rust2" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47bb1e988e6fb779cf720ad431242d3f03167c1b3f2b1aae7f1a94b2495b36ae" -dependencies = [ - "sha2", -] - [[package]] name = "mail-parser" version = "0.11.2" @@ -1666,9 +1568,9 @@ dependencies = [ [[package]] name = "mio" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" dependencies = [ "libc", "wasi", @@ -1719,12 +1621,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "num-conv" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6673768db2d862beb9b39a78fdcb1a69439615d5794a1be50caa9bc92c81967" - [[package]] name = "num-traits" version = "0.2.19" @@ -1734,15 +1630,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "object" -version = "0.37.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.21.4" @@ -1796,16 +1683,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "pbkdf2" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" -dependencies = [ - "digest", - "hmac", -] - [[package]] name = "percent-encoding" version = "2.3.2" @@ -1906,25 +1783,13 @@ checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" [[package]] name = "potential_utf" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" dependencies = [ "zerovec", ] -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - -[[package]] -name = "ppmd-rust" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efca4c95a19a79d1c98f791f10aebd5c1363b473244630bb7dbde1dc98455a24" - [[package]] name = "ppv-lite86" version = "0.2.21" @@ -1953,16 +1818,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "psm" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3852766467df634d74f0b2d7819bf8dc483a0eb2e3b0f50f756f9cfe8b0d18d8" -dependencies = [ - "ar_archive_writer", - "cc", -] - [[package]] name = "pxfm" version = "0.1.28" @@ -2291,9 +2146,9 @@ dependencies = [ [[package]] name = "rustc-hash" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" [[package]] name = "rustix" @@ -2415,9 +2270,9 @@ checksum = "b12e76d157a900eb52e81bc6e9f3069344290341720e9178cde2407113ac8d89" [[package]] name = "semver" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" [[package]] name = "serde" @@ -2486,9 +2341,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876ac351060d4f882bb1032b6369eb0aef79ad9df1ea8bc404874d8cc3d0cd98" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" dependencies = [ "serde_core", ] @@ -2507,7 +2362,7 @@ dependencies = [ [[package]] name = "sgclaw" -version = "0.1.0" +version = "0.1.0-2026.4.9" dependencies = [ "anyhow", "async-trait", @@ -2525,7 +2380,7 @@ dependencies = [ "tungstenite 0.29.0", "uuid", "zeroclawlabs", - "zip", + "zip 0.6.6", ] [[package]] @@ -2592,9 +2447,9 @@ dependencies = [ [[package]] name = "simd-adler32" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" +checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214" [[package]] name = "siphasher" @@ -2630,20 +2485,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" -[[package]] -name = "stacker" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d74a23609d509411d10e2176dc2a4346e3b4aea2e7b1869f19fdedbc71c013" -dependencies = [ - "cc", - "cfg-if", - "libc", - "psm", - "windows-sys 0.52.0", - "windows-sys 0.59.0", -] - [[package]] name = "stop-token" version = "0.7.0" @@ -2772,31 +2613,11 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "time" -version = "0.3.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" -dependencies = [ - "deranged", - "js-sys", - "num-conv", - "powerfmt", - "serde_core", - "time-core", -] - -[[package]] -name = "time-core" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" - [[package]] name = "tinystr" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" dependencies = [ "displaydoc", "zerovec", @@ -2819,9 +2640,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.50.0" +version = "1.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27ad5e34374e03cfffefc301becb44e9dc3c17584f414349ebe29ed26661822d" +checksum = "f66bf9585cda4b724d3e78ab34b73fb2bbaba9011b9bfdf69dc836382ea13b8c" dependencies = [ "bytes", "libc", @@ -2835,9 +2656,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c55a2eff8b69ce66c84f85e1da1c233edc36ceb85a2058d11b0d6a3c7e7569c" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", @@ -2921,9 +2742,9 @@ dependencies = [ [[package]] name = "toml" -version = "1.1.0+spec-1.1.0" +version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8195ca05e4eb728f4ba94f3e3291661320af739c4e43779cbdfae82ab239fcc" +checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee" dependencies = [ "indexmap", "serde_core", @@ -2931,32 +2752,32 @@ dependencies = [ "toml_datetime", "toml_parser", "toml_writer", - "winnow 1.0.0", + "winnow 1.0.1", ] [[package]] name = "toml_datetime" -version = "1.1.0+spec-1.1.0" +version = "1.1.1+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97251a7c317e03ad83774a8752a7e81fb6067740609f75ea2b585b569a59198f" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" dependencies = [ "serde_core", ] [[package]] name = "toml_parser" -version = "1.1.0+spec-1.1.0" +version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2334f11ee363607eb04df9b8fc8a13ca1715a72ba8662a26ac285c98aabb4011" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" dependencies = [ - "winnow 1.0.0", + "winnow 1.0.1", ] [[package]] name = "toml_writer" -version = "1.1.0+spec-1.1.0" +version = "1.1.1+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d282ade6016312faf3e41e57ebbba0c073e4056dab1232ab1cb624199648f8ed" +checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db" [[package]] name = "tower" @@ -3177,9 +2998,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.22.0" +version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a68d3c8f01c0cfa54a75291d83601161799e4a89a39e0929f4b0354d88757a37" +checksum = "5ac8b6f42ead25368cf5b098aeb3dc8a1a2c05a3eee8a9a1a68c640edbfc79d9" dependencies = [ "getrandom 0.4.2", "js-sys", @@ -3243,9 +3064,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.114" +version = "0.2.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +checksum = "0551fc1bb415591e3372d0bc4780db7e587d84e2a7e79da121051c5c4b89d0b0" dependencies = [ "cfg-if", "once_cell", @@ -3256,23 +3077,19 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.64" +version = "0.4.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9c5522b3a28661442748e09d40924dfb9ca614b21c00d3fd135720e48b67db8" +checksum = "03623de6905b7206edd0a75f69f747f134b7f0a2323392d664448bf2d3c5d87e" dependencies = [ - "cfg-if", - "futures-util", "js-sys", - "once_cell", "wasm-bindgen", - "web-sys", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.114" +version = "0.2.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +checksum = "7fbdf9a35adf44786aecd5ff89b4563a90325f9da0923236f6104e603c7e86be" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3280,9 +3097,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.114" +version = "0.2.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +checksum = "dca9693ef2bab6d4e6707234500350d8dad079eb508dca05530c85dc3a529ff2" dependencies = [ "bumpalo", "proc-macro2", @@ -3293,9 +3110,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.114" +version = "0.2.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +checksum = "39129a682a6d2d841b6c429d0c51e5cb0ed1a03829d8b3d1e69a011e62cb3d3b" dependencies = [ "unicode-ident", ] @@ -3349,9 +3166,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.91" +version = "0.3.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854ba17bb104abfb26ba36da9729addc7ce7f06f5c0f90f3c391f8461cca21f9" +checksum = "cd70027e39b12f0849461e08ffc50b9cd7688d942c1c8e3c7b22273236b4dd0a" dependencies = [ "js-sys", "wasm-bindgen", @@ -3471,15 +3288,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets 0.52.6", -] - [[package]] name = "windows-sys" version = "0.60.2" @@ -3638,9 +3446,9 @@ dependencies = [ [[package]] name = "winnow" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a90e88e4667264a994d34e6d1ab2d26d398dcdca8b7f52bec8668957517fc7d8" +checksum = "09dac053f1cd375980747450bfc7250c264eaae0583872e845c0c7cd578872b5" [[package]] name = "wit-bindgen" @@ -3732,9 +3540,9 @@ dependencies = [ [[package]] name = "writeable" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" [[package]] name = "xattr" @@ -3748,9 +3556,9 @@ dependencies = [ [[package]] name = "yoke" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -3759,9 +3567,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" dependencies = [ "proc-macro2", "quote", @@ -3838,23 +3646,23 @@ dependencies = [ "uuid", "webpki-roots 1.0.6", "which", - "zip", + "zip 8.5.1", ] [[package]] name = "zerocopy" -version = "0.8.47" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbb2a062be311f2ba113ce66f697a4dc589f85e78a4aea276200804cea0ed87" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.47" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e8bc7269b54418e7aeeef514aa68f8690b8c0489a06b0136e5f57c4c5ccab89" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" dependencies = [ "proc-macro2", "quote", @@ -3863,18 +3671,18 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" dependencies = [ "proc-macro2", "quote", @@ -3890,9 +3698,9 @@ checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" [[package]] name = "zerotrie" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" dependencies = [ "displaydoc", "yoke", @@ -3901,9 +3709,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" dependencies = [ "yoke", "zerofrom", @@ -3912,9 +3720,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" dependencies = [ "proc-macro2", "quote", @@ -3923,36 +3731,28 @@ dependencies = [ [[package]] name = "zip" -version = "8.4.0" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7756d0206d058333667493c4014f545f4b9603c4330ccd6d9b3f86dcab59f7d9" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" dependencies = [ - "aes", - "bzip2", - "constant_time_eq", + "byteorder", "crc32fast", - "deflate64", + "crossbeam-utils", "flate2", - "getrandom 0.4.2", - "hmac", - "indexmap", - "lzma-rust2", - "memchr", - "pbkdf2", - "ppmd-rust", - "sha1", - "time", - "typed-path", - "zeroize", - "zopfli", - "zstd", ] [[package]] -name = "zlib-rs" -version = "0.6.3" +name = "zip" +version = "8.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be3d40e40a133f9c916ee3f9f4fa2d9d63435b5fbe1bfc6d9dae0aa0ada1513" +checksum = "dcab981e19633ebcf0b001ddd37dd802996098bc1864f90b7c5d970ce76c1d59" +dependencies = [ + "crc32fast", + "flate2", + "indexmap", + "memchr", + "typed-path", +] [[package]] name = "zmij" @@ -3960,46 +3760,6 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" -[[package]] -name = "zopfli" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" -dependencies = [ - "bumpalo", - "crc32fast", - "log", - "simd-adler32", -] - -[[package]] -name = "zstd" -version = "0.13.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" -dependencies = [ - "zstd-safe", -] - -[[package]] -name = "zstd-safe" -version = "7.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" -dependencies = [ - "zstd-sys", -] - -[[package]] -name = "zstd-sys" -version = "2.0.16+zstd.1.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" -dependencies = [ - "cc", - "pkg-config", -] - [[package]] name = "zune-core" version = "0.5.1" @@ -4008,9 +3768,9 @@ checksum = "cb8a0807f7c01457d0379ba880ba6322660448ddebc890ce29bb64da71fb40f9" [[package]] name = "zune-jpeg" -version = "0.5.14" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7a1c0af6e5d8d1363f4994b7a091ccf963d8b694f7da5b0b9cceb82da2c0a6" +checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296" dependencies = [ "zune-core", ] diff --git a/Cargo.toml b/Cargo.toml index 9f4bf24..709b21a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sgclaw" -version = "0.1.0" +version = "0.1.0-2026.4.9" edition = "2021" [dependencies] @@ -19,5 +19,5 @@ thiserror = "1" tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "macros"] } tungstenite = "0.29" uuid = { version = "1", features = ["v4"] } +zip = { version = "0.6.6", default-features = false, features = ["deflate"] } zeroclaw = { package = "zeroclawlabs", path = "third_party/zeroclaw", default-features = false } -zip = "8.4" diff --git a/docs/superpowers/plans/2026-04-09-config-owned-direct-skill-contract-plan.md b/docs/superpowers/plans/2026-04-09-config-owned-direct-skill-contract-plan.md new file mode 100644 index 0000000..043ce44 --- /dev/null +++ b/docs/superpowers/plans/2026-04-09-config-owned-direct-skill-contract-plan.md @@ -0,0 +1,281 @@ +# Config-Owned Direct Skill Contract Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Validate the `directSubmitSkill` control surface early and prevent malformed direct-skill configs from entering the submit routing path, without changing the current happy-path direct execution behavior. + +**Architecture:** Keep the existing direct-submit runtime and submit-task seam intact for valid configs. Move `directSubmitSkill` format validation into the normal `SgClawSettings` load path so malformed config fails before routing begins, while leaving valid-but-unresolvable `skill.tool` targets as direct runtime errors in the current direct path. + +**Tech Stack:** Rust 2021, `serde` config parsing, current `BrowserMessage::SubmitTask` path, current direct skill runtime, Rust integration tests. + +--- + +## Execution Context + +- Follow @superpowers:test-driven-development for the Rust code changes in this plan. +- Follow @superpowers:verification-before-completion before claiming any task is done. +- Do **not** create a git worktree unless the user explicitly asks. This project prefers staying in the current checkout. +- Keep scope tight: this plan does **not** add per-skill dispatch metadata, docs changes, intent classification, or LLM routing changes. + +## File Map + +### Existing files to modify + +- Modify: `src/config/settings.rs` + - validate `directSubmitSkill` during config normalization + - keep the stored field as `Option` so the current direct runtime API stays stable +- Modify: `tests/compat_config_test.rs` + - add a failing config-load regression for malformed `directSubmitSkill` +- Modify: `tests/agent_runtime_test.rs` + - add a failing submit-path regression proving malformed config is rejected before direct routing begins + +### Existing files to read but not broaden + +- Reuse without redesign: `src/agent/mod.rs` +- Reuse without redesign: `src/compat/direct_skill_runtime.rs` +- Reuse without redesign: `docs/superpowers/specs/2026-04-09-config-owned-direct-skill-dispatch-design.md` + +### No new files expected + +This slice should fit in the existing config and tests surfaces only. + +--- + +### Task 1: Validate `directSubmitSkill` Before Submit Routing + +**Files:** +- Modify: `tests/compat_config_test.rs` +- Modify: `tests/agent_runtime_test.rs` +- Modify: `src/config/settings.rs` +- Read only: `src/agent/mod.rs` +- Read only: `src/compat/direct_skill_runtime.rs` + +- [ ] **Step 1: Write the failing config test for malformed `directSubmitSkill`** + +Add this focused test to `tests/compat_config_test.rs`: + +```rust +#[test] +fn sgclaw_settings_reject_invalid_direct_submit_skill_format() { + let root = std::env::temp_dir().join(format!( + "sgclaw-invalid-direct-submit-skill-{}", + Uuid::new_v4() + )); + fs::create_dir_all(&root).unwrap(); + let config_path = root.join("sgclaw_config.json"); + + fs::write( + &config_path, + r#"{ + "providers": [], + "skillsDir": "skill_lib", + "directSubmitSkill": "fault-details-report" +}"#, + ) + .unwrap(); + + let err = SgClawSettings::load(Some(config_path.as_path())) + .expect_err("expected invalid directSubmitSkill format"); + let message = err.to_string(); + + assert!(message.contains("directSubmitSkill")); + assert!(message.contains("skill.tool")); +} +``` + +- [ ] **Step 2: Run the focused config test and verify it fails** + +Run: + +```bash +cargo test --test compat_config_test sgclaw_settings_reject_invalid_direct_submit_skill_format -- --nocapture +``` + +Expected: FAIL because the current config loader accepts the malformed string instead of rejecting it early. + +- [ ] **Step 3: Write the failing agent regression for malformed config** + +Add this focused test to `tests/agent_runtime_test.rs`: + +```rust +#[test] +fn submit_task_rejects_invalid_direct_submit_skill_config_before_routing() { + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + + let skill_root = build_direct_runtime_skill_root(); + let workspace_root = std::env::temp_dir().join(format!( + "sgclaw-invalid-direct-submit-workspace-{}", + Uuid::new_v4() + )); + fs::create_dir_all(&workspace_root).unwrap(); + let config_path = workspace_root.join("sgclaw_config.json"); + fs::write( + &config_path, + serde_json::json!({ + "providers": [], + "skillsDir": skill_root, + "directSubmitSkill": "fault-details-report" + }) + .to_string(), + ) + .unwrap(); + + let runtime_context = AgentRuntimeContext::new(Some(config_path), workspace_root); + let transport = Arc::new(MockTransport::new(vec![])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + handle_browser_message_with_context( + transport.as_ref(), + &browser_tool, + &runtime_context, + submit_fault_details_message(), + ) + .unwrap(); + + let sent = transport.sent_messages(); + assert!(matches!( + sent.last(), + Some(AgentMessage::TaskComplete { success, summary }) + if !success && summary.contains("skill.tool") + )); + assert!(direct_submit_mode_logs(&sent).is_empty()); + assert!(!sent.iter().any(|message| matches!(message, AgentMessage::Command { .. }))); +} +``` + +- [ ] **Step 4: Run the focused agent test and verify it fails** + +Run: + +```bash +cargo test --test agent_runtime_test submit_task_rejects_invalid_direct_submit_skill_config_before_routing -- --nocapture +``` + +Expected: FAIL because the malformed config currently loads, enters the direct-submit branch, and emits `direct_skill_primary` before failing later. + +- [ ] **Step 5: Implement the minimal config validation** + +In `src/config/settings.rs`, add a small helper that validates the normalized `directSubmitSkill` string during `SgClawSettings::new(...)`. + +Recommended implementation shape: + +```rust +fn normalize_direct_submit_skill(raw: Option) -> Result, ConfigError> { + let value = normalize_optional_value(raw); + let Some(value) = value.as_deref() else { + return Ok(None); + }; + + let Some((skill_name, tool_name)) = value.split_once('.') else { + return Err(ConfigError::InvalidValue( + "directSubmitSkill", + format!("must use skill.tool format, got {value}"), + )); + }; + + if skill_name.trim().is_empty() || tool_name.trim().is_empty() { + return Err(ConfigError::InvalidValue( + "directSubmitSkill", + format!("must use skill.tool format, got {value}"), + )); + } + + Ok(Some(value.to_string())) +} +``` + +Then use it here: + +```rust +let direct_submit_skill = normalize_direct_submit_skill(direct_submit_skill)?; +``` + +Rules: +- do not change the public field type from `Option` +- do not move parsing responsibility into `src/agent/mod.rs` +- do not redesign `src/compat/direct_skill_runtime.rs` +- keep valid-but-unresolvable `skill.tool` targets as runtime errors in the direct path + +- [ ] **Step 6: Re-run the two focused tests and verify they pass** + +Run: + +```bash +cargo test --test compat_config_test sgclaw_settings_reject_invalid_direct_submit_skill_format -- --nocapture +cargo test --test agent_runtime_test submit_task_rejects_invalid_direct_submit_skill_config_before_routing -- --nocapture +``` + +Expected: PASS. + +- [ ] **Step 7: Re-run the broader regression suites** + +Run: + +```bash +cargo test --test compat_config_test -- --nocapture +cargo test --test agent_runtime_test -- --nocapture +cargo test --test browser_script_skill_tool_test -- --nocapture +cargo build --bin sgclaw +``` + +Expected: PASS, including: +- the direct-submit happy path +- the existing no-LLM fallback behavior when `directSubmitSkill` is absent +- unchanged browser-script helper semantics +- clean binary build + +--- + +## Verification Checklist + +### Config validation + +```bash +cargo test --test compat_config_test -- --nocapture +``` + +Expected: malformed `directSubmitSkill` is rejected early, while the existing direct-only config shape still loads. + +### Submit-path behavior + +```bash +cargo test --test agent_runtime_test -- --nocapture +``` + +Expected: +- malformed `directSubmitSkill` never reaches direct routing +- valid configured direct skill still succeeds without LLM config +- no direct skill configured still returns the existing no-LLM message + +### Browser-script helper safety + +```bash +cargo test --test browser_script_skill_tool_test -- --nocapture +``` + +Expected: current browser-script execution semantics remain unchanged. + +### Build + +```bash +cargo build --bin sgclaw +``` + +Expected: the main binary compiles cleanly. + +--- + +## Notes For The Engineer + +- The paired spec is `docs/superpowers/specs/2026-04-09-config-owned-direct-skill-dispatch-design.md`. +- Do **not** add sgClaw-specific dispatch metadata under `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging` in this slice. +- Do **not** turn this into a per-skill registry task yet. This plan only hardens the current config-owned bootstrap contract. +- Keep the current direct target example as `fault-details-report.collect_fault_details`; avoid hard-coding that name into new generic APIs. +- If you discover a need for broader policy routing (`direct_browser` / `llm_agent` by skill), stop and write a new spec/plan instead of expanding this one. diff --git a/docs/superpowers/plans/2026-04-09-direct-skill-without-llm-plan.md b/docs/superpowers/plans/2026-04-09-direct-skill-without-llm-plan.md new file mode 100644 index 0000000..2ec867c --- /dev/null +++ b/docs/superpowers/plans/2026-04-09-direct-skill-without-llm-plan.md @@ -0,0 +1,520 @@ +# Direct Skill Invocation Without LLM Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Let the current pipe submit-task flow accept natural-language input but directly invoke one fixed staged browser skill without calling any model, while reserving a clean switch back to LLM-based routing later. + +**Architecture:** Keep the existing `BrowserMessage::SubmitTask` entrypoint and add one narrow pre-routing seam before the current compat/LLM chain. When a new config field points to a fixed direct-submit skill, sgClaw loads that skill package from the configured external skills root, finds the target `browser_script` tool, executes it through the existing browser-script wrapper, and returns the result directly. When the field is absent, the current behavior stays unchanged. This preserves a future path where each skill can later declare `direct_browser` or `llm_agent` dispatch without rewriting the submit pipeline again. + +**Tech Stack:** Rust 2021, existing `BrowserPipeTool`, current submit-task agent entrypoint, current browser-script skill executor, current sgClaw JSON config loader, `zeroclaw` skill manifest loader. + +--- + +## Recommended First Skill + +Use `fault-details-report.collect_fault_details` from: +- `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/scenes/fault-details-report/scene.json` +- `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/SKILL.toml` +- `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.js` + +Why this one first: +- it is clearly a report/export skill +- it exposes exactly one browser-script tool: `collect_fault_details` +- it has the smallest contract surface (`period` only) +- its current JS is deterministic and simple, so the first slice can focus on plumbing instead of browser scraping complexity + +## Scope Guardrails + +- Do **not** redesign the existing submit-task protocol. +- Do **not** remove or rewrite the current LLM/compat path; leave it as the fallback/default path. +- Do **not** introduce generic NL intent routing in this slice; this is one fixed direct skill only. +- Do **not** modify `third_party/zeroclaw` skill manifest schema in phase 1. +- Do **not** add Excel export wiring in the first slice unless a test explicitly requires it. +- Do **not** invent a new browser-script execution model; reuse the existing wrapper semantics. + +--- + +## File Map + +### Existing files to modify + +- Modify: `src/config/settings.rs` + - add a minimal config field for one direct-submit skill name +- Modify: `src/agent/mod.rs` + - add a narrow pre-routing branch before the current compat/LLM path +- Modify: `src/compat/browser_script_skill_tool.rs` + - expose the smallest reusable helper for direct browser-script execution +- Modify: `src/compat/mod.rs` or the nearest module export surface + - export the new narrow direct-skill runtime module if needed +- Modify: `tests/compat_config_test.rs` + - add config coverage for the new direct-submit field +- Modify: `tests/browser_script_skill_tool_test.rs` + - add coverage for the reusable direct-execution helper +- Modify: `tests/agent_runtime_test.rs` + - prove submit-task can bypass the model and directly invoke the fixed skill + +### New files to create + +- Create: `src/compat/direct_skill_runtime.rs` + - small runtime for loading one configured skill, resolving one configured tool, deriving minimal args, and executing it directly + +### Files to reuse without changing behavior + +- Reuse: `src/compat/runtime.rs` +- Reuse: `src/compat/orchestration.rs` +- Reuse: `src/compat/config_adapter.rs` +- Reuse: `third_party/zeroclaw/src/skills/mod.rs` + +--- + +### Task 1: Add A Minimal Direct-Submit Skill Config Field + +**Files:** +- Modify: `src/config/settings.rs` +- Modify: `tests/compat_config_test.rs` + +- [ ] **Step 1: Write the failing config test for the new field** + +In `tests/compat_config_test.rs`, add a focused config-load test proving the browser config file can declare one fixed direct-submit skill. + +Test shape: + +```rust +#[test] +fn sgclaw_settings_load_direct_submit_skill_from_browser_config() { + let root = std::env::temp_dir().join(format!("sgclaw-direct-skill-{}", uuid::Uuid::new_v4())); + std::fs::create_dir_all(&root).unwrap(); + let config_path = root.join("sgclaw_config.json"); + + std::fs::write( + &config_path, + r#"{ + "apiKey": "sk-runtime", + "baseUrl": "https://api.deepseek.com", + "model": "deepseek-chat", + "skillsDir": "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging", + "directSubmitSkill": "fault-details-report.collect_fault_details" +}"#, + ) + .unwrap(); + + let settings = sgclaw::config::SgClawSettings::load(Some(config_path.as_path())) + .unwrap() + .expect("expected sgclaw settings from config file"); + + assert_eq!( + settings.direct_submit_skill.as_deref(), + Some("fault-details-report.collect_fault_details") + ); +} +``` + +- [ ] **Step 2: Run the focused config test and verify it fails** + +Run: + +```bash +cargo test --test compat_config_test sgclaw_settings_load_direct_submit_skill_from_browser_config -- --nocapture +``` + +Expected: FAIL because the config field does not exist yet. + +- [ ] **Step 3: Implement the minimal config field** + +In `src/config/settings.rs`, add: +- `direct_submit_skill: Option` to `SgClawSettings` +- `direct_submit_skill: Option` to `RawSgClawSettings` +- field normalization in `SgClawSettings::new(...)` + +Recommended JSON key shape: + +```rust +#[serde(rename = "directSubmitSkill", alias = "direct_submit_skill", default)] +direct_submit_skill: Option, +``` + +Rules: +- trim empty values to `None` +- keep `DeepSeekSettings` unchanged for this slice unless a compile error proves it must mirror the field +- do not alter unrelated config semantics + +- [ ] **Step 4: Re-run the focused config test** + +Run: + +```bash +cargo test --test compat_config_test sgclaw_settings_load_direct_submit_skill_from_browser_config -- --nocapture +``` + +Expected: PASS. + +- [ ] **Step 5: Re-run the broader config file tests** + +Run: + +```bash +cargo test --test compat_config_test -- --nocapture +``` + +Expected: PASS. + +- [ ] **Step 6: Commit Task 1** + +```bash +git add src/config/settings.rs tests/compat_config_test.rs +git commit -m "feat: add direct submit skill config" +``` + +--- + +### Task 2: Extract A Reusable Browser-Script Direct Execution Helper + +**Files:** +- Modify: `src/compat/browser_script_skill_tool.rs` +- Modify: `tests/browser_script_skill_tool_test.rs` + +- [ ] **Step 1: Write the first failing helper test** + +In `tests/browser_script_skill_tool_test.rs`, add a focused test proving direct code can execute a packaged browser script without constructing a full `Tool` object first. + +Test shape: + +```rust +#[tokio::test] +async fn execute_browser_script_tool_runs_packaged_script_with_expected_domain() { + // build temp skill script + // call the helper directly + // assert Action::Eval was sent with wrapped args and normalized domain +} +``` + +Required assertions: +- the helper reads the packaged JS file +- it wraps args with `const args = ...` +- it normalizes URL-like `expected_domain` +- it returns the serialized payload string on success + +- [ ] **Step 2: Run the helper test and verify it fails** + +Run: + +```bash +cargo test --test browser_script_skill_tool_test execute_browser_script_tool_runs_packaged_script_with_expected_domain -- --nocapture +``` + +Expected: FAIL because the helper does not exist yet. + +- [ ] **Step 3: Add the second failing helper test for required-domain validation** + +Add a focused failure-path test proving the helper rejects missing or invalid `expected_domain` before any browser command is sent. + +- [ ] **Step 4: Run the validation test and verify it fails** + +Run: + +```bash +cargo test --test browser_script_skill_tool_test execute_browser_script_tool_rejects_missing_expected_domain -- --nocapture +``` + +Expected: FAIL because the helper does not exist yet. + +- [ ] **Step 5: Implement the minimal reusable helper** + +In `src/compat/browser_script_skill_tool.rs`, extract the smallest reusable function, for example: + +```rust +pub async fn execute_browser_script_tool( + tool: &SkillTool, + skill_root: &Path, + browser_tool: BrowserPipeTool, + args: Value, +) -> anyhow::Result +``` + +Rules: +- reuse the current path validation, script loading, wrapping, `Action::Eval`, and payload formatting logic already used by `BrowserScriptSkillTool::execute` +- do not change outward behavior of `BrowserScriptSkillTool` +- keep the helper narrow and browser-script-only + +- [ ] **Step 6: Refactor `BrowserScriptSkillTool::execute` to call the helper** + +Keep existing behavior and tests green while removing duplicate execution logic. + +- [ ] **Step 7: Re-run the browser-script tests** + +Run: + +```bash +cargo test --test browser_script_skill_tool_test -- --nocapture +``` + +Expected: PASS. + +- [ ] **Step 8: Commit Task 2** + +```bash +git add src/compat/browser_script_skill_tool.rs tests/browser_script_skill_tool_test.rs +git commit -m "refactor: extract direct browser script execution helper" +``` + +--- + +### Task 3: Add A Narrow Direct Skill Runtime For One Fixed Skill + +**Files:** +- Create: `src/compat/direct_skill_runtime.rs` +- Modify: `src/compat/mod.rs` or nearest module export point +- Reuse: `src/compat/config_adapter.rs` +- Reuse: `third_party/zeroclaw/src/skills/mod.rs` + +- [ ] **Step 1: Write the first failing direct-runtime test** + +Add a focused test in `tests/agent_runtime_test.rs` or a new narrow compat test proving code can resolve the configured external skills root, load `fault-details-report`, find `collect_fault_details`, and execute it directly. + +Recommended shape: + +```rust +#[test] +fn direct_skill_runtime_executes_fault_details_report_without_provider() { + // config points at skill_staging root + // direct_submit_skill points at fault-details-report.collect_fault_details + // browser response returns report-artifact payload + // assert no provider/http path is touched +} +``` + +- [ ] **Step 2: Run the focused direct-runtime test and verify it fails** + +Run the narrowest test command for the new test. + +Expected: FAIL because the direct runtime does not exist yet. + +- [ ] **Step 3: Implement `src/compat/direct_skill_runtime.rs`** + +Add a narrow runtime with responsibilities only to: +- resolve the configured skills dir with `resolve_skills_dir_from_sgclaw_settings(...)` +- load skills from that directory with `load_skills_from_directory(...)` +- parse the configured tool name into `skill_name` + `tool_name` +- find the matching skill and matching tool +- verify `tool.kind == "browser_script"` +- derive the minimal argument object +- call the new browser-script helper +- return the output string or a clear `PipeError` + +Do **not** add generic routing, scenes, or model fallback here. + +- [ ] **Step 4: Keep argument derivation intentionally minimal** + +For the first slice, derive only: +- `expected_domain` from `page_url` when present, otherwise fail with a clear message +- `period` from the instruction using a narrow deterministic pattern such as `YYYY-MM` + +If the period cannot be derived, return a concise error telling the user to provide it explicitly. Do not guess. + +- [ ] **Step 5: Re-run the focused direct-runtime test** + +Run the same test command again. + +Expected: PASS. + +- [ ] **Step 6: Commit Task 3** + +```bash +git add src/compat/direct_skill_runtime.rs src/compat/mod.rs tests/agent_runtime_test.rs +git commit -m "feat: add fixed direct skill runtime" +``` + +--- + +### Task 4: Insert The Pre-Routing Seam In Submit-Task Entry + +**Files:** +- Modify: `src/agent/mod.rs` +- Modify: `tests/agent_runtime_test.rs` + +- [ ] **Step 1: Write the first failing submit-path bypass test** + +In `tests/agent_runtime_test.rs`, add a focused regression proving that when `directSubmitSkill` is configured, `BrowserMessage::SubmitTask` can succeed without any model/provider being configured. + +Test shape: + +```rust +#[test] +fn submit_task_uses_direct_skill_mode_without_llm_configuration() { + // config contains skillsDir + directSubmitSkill, but no reachable provider + // natural-language instruction includes period and page_url + // expect TaskComplete success from direct skill result +} +``` + +Required assertions: +- task succeeds even if provider would be unavailable +- output contains the report artifact payload +- no summary like `未配置大语言模型` + +- [ ] **Step 2: Run the bypass test and verify it fails** + +Run: + +```bash +cargo test --test agent_runtime_test submit_task_uses_direct_skill_mode_without_llm_configuration -- --nocapture +``` + +Expected: FAIL because submit-task still goes into the current LLM-oriented path. + +- [ ] **Step 3: Add the second failing priority test** + +Add one focused test proving the direct-submit branch runs before the existing compat/LLM branch. + +The easiest assertion is that the mode log becomes something new like: +- `direct_skill_primary` + +and the normal mode logs do not appear for that turn. + +- [ ] **Step 4: Run the priority test and verify it fails** + +Run the narrow test command for the new test. + +Expected: FAIL because the mode does not exist yet. + +- [ ] **Step 5: Add the narrow pre-routing branch in `src/agent/mod.rs`** + +In `handle_browser_message_with_context(...)`, after config load/logging and before the existing `should_use_primary_orchestration(...)` / `compat::runtime` path: +- check `settings.direct_submit_skill` +- if present, emit mode log `direct_skill_primary` +- call the new direct runtime +- send `TaskComplete` and return immediately + +Rules: +- if `direct_submit_skill` is absent, keep existing behavior byte-for-byte where possible +- do not modify `compat::runtime.rs` or `compat::orchestration.rs` for this slice +- do not silently fall through to LLM when direct execution fails; return the direct error clearly so the first slice is debuggable + +- [ ] **Step 6: Re-run the focused submit-path tests** + +Run: + +```bash +cargo test --test agent_runtime_test submit_task_uses_direct_skill_mode_without_llm_configuration -- --nocapture +cargo test --test agent_runtime_test direct_skill_mode_logs_direct_skill_primary -- --nocapture +``` + +Expected: PASS. + +- [ ] **Step 7: Re-run existing no-LLM submit regression coverage** + +Run: + +```bash +cargo test --test agent_runtime_test -- --nocapture +``` + +Expected: PASS, including existing cases where no direct skill is configured and the old no-LLM failure still applies. + +- [ ] **Step 8: Commit Task 4** + +```bash +git add src/agent/mod.rs tests/agent_runtime_test.rs +git commit -m "feat: route submit tasks through fixed direct skill mode" +``` + +--- + +### Task 5: Lock The Future Migration Seam Without Implementing LLM Dispatch Yet + +**Files:** +- Modify only if needed: `src/config/settings.rs` +- Modify only if needed: `src/compat/direct_skill_runtime.rs` +- Reuse: docs/plan only unless code needs one tiny naming fix + +- [ ] **Step 1: Keep the config naming compatible with future per-skill dispatch** + +Document and preserve this future meaning in code naming: +- current field: one fixed direct skill for submit-task bootstrap +- future model: each skill can declare dispatch mode such as `direct_browser` or `llm_agent` + +Prefer neutral names in helper code like: +- `direct skill mode` +- `direct submit skill` + +Avoid hard-coding `fault_details` into generic APIs. + +- [ ] **Step 2: Add one small negative test for fallback behavior** + +Add a focused test proving that when `directSubmitSkill` is not configured, submit-task still behaves exactly as before and can still return the existing no-LLM message. + +If an existing test already proves this, keep it and do not add another. + +- [ ] **Step 3: Re-run the focused end-to-end verification set** + +Run: + +```bash +cargo test --test compat_config_test -- --nocapture +cargo test --test browser_script_skill_tool_test -- --nocapture +cargo test --test agent_runtime_test -- --nocapture +``` + +Expected: PASS. + +- [ ] **Step 4: Build the main binary** + +Run: + +```bash +cargo build --bin sgclaw +``` + +Expected: PASS. + +- [ ] **Step 5: Commit Task 5** + +```bash +git add src/config/settings.rs src/compat/direct_skill_runtime.rs src/compat/browser_script_skill_tool.rs src/agent/mod.rs tests/compat_config_test.rs tests/browser_script_skill_tool_test.rs tests/agent_runtime_test.rs +git commit -m "test: verify fixed direct skill submit path" +``` + +--- + +## Verification Checklist + +### Config loading + +```bash +cargo test --test compat_config_test -- --nocapture +``` + +Expected: `directSubmitSkill` loads correctly and existing config behavior remains intact. + +### Browser-script helper + +```bash +cargo test --test browser_script_skill_tool_test -- --nocapture +``` + +Expected: direct helper preserves the existing browser-script execution semantics. + +### Submit-path bypass + +```bash +cargo test --test agent_runtime_test -- --nocapture +``` + +Expected: configured direct skill bypasses the model path, while unconfigured submit-task behavior stays unchanged. + +### Build + +```bash +cargo build --bin sgclaw +``` + +Expected: the binary compiles cleanly. + +--- + +## Notes For The Engineer + +- The key to keeping this slice small is to avoid changing `compat::runtime.rs` and `compat::orchestration.rs`; they remain the future LLM path. +- `fault-details-report.collect_fault_details` is only the bootstrap skill. The plumbing must stay generic enough that the configured tool name can later point to another staged browser skill. +- Phase 1 should not add per-skill dispatch metadata to the external skill manifests yet. Keep that decision in sgClaw config first; move it into skill metadata only after the direct path is proven useful. +- Once the intranet model is ready, the clean next step is to add a dispatch policy layer that chooses between `direct_browser` and `llm_agent` before the current compat path is entered, reusing this same pre-routing seam. diff --git a/docs/superpowers/plans/2026-04-10-fault-details-full-skill-alignment-plan.md b/docs/superpowers/plans/2026-04-10-fault-details-full-skill-alignment-plan.md new file mode 100644 index 0000000..4b10566 --- /dev/null +++ b/docs/superpowers/plans/2026-04-10-fault-details-full-skill-alignment-plan.md @@ -0,0 +1,672 @@ +# Fault Details Full Skill Alignment Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Upgrade `fault-details-report.collect_fault_details` into a real staged browser skill that matches the original fault-details workflow, and make `claw-new` interpret the returned artifact status correctly in the direct-submit path. + +**Architecture:** Keep routing and direct-skill selection in `claw-new`, but move all fault-details collection, normalization, classification, summary, export, and report-log behavior into the staged skill under `skill_staging`. Implement the staged skill as a true browser-eval entrypoint that remains valid in page context, while exposing testable pure helpers through an environment-safe export guard for `node:test`; then add a narrow Rust artifact interpreter in `src/compat/direct_skill_runtime.rs` so `ok` / `partial` / `empty` map to successful task completion while `blocked` / `error` map to failed completion. + +**Tech Stack:** Rust 2021, `serde_json`, existing `BrowserPipeTool` / `browser_script` runtime, `node:test`, staged skill fixtures, Cargo integration tests. + +--- + +## Execution Context + +- Follow @superpowers:test-driven-development for every behavior change. +- Follow @superpowers:verification-before-completion before claiming each task is done. +- Do **not** create a git worktree unless the user explicitly asks. This repo preference is already established. +- Keep scope tight. Do **not** add a new browser protocol, new dispatch metadata, new UI opener behavior, or Rust-side fault classification logic. +- Keep the current direct path bootstrap requirement intact: the user instruction must still include an explicit `YYYY-MM`, but the staged skill must treat the page-selected range as the source of truth for collection once execution begins. +- Preserve parity with the original package’s real behavior: port the original classification table, `qxxcjl`-based reason heuristics, canonical detail mapping, summary aggregation rules, localhost export call, and report-log call into the staged skill rather than implementing a fixture-only subset. + +## File Map + +### Existing files to modify in `claw-new` + +- Modify: `src/compat/direct_skill_runtime.rs` + - add narrow structured artifact parsing and status-to-summary mapping + - keep direct-skill routing/config ownership unchanged +- Modify: `tests/agent_runtime_test.rs` + - add direct-submit regressions for `ok`, `partial`, `empty`, `blocked`, and `error` +- Modify: `tests/browser_script_skill_tool_test.rs` + - add browser-script execution-shape regression for browser-eval return payloads used by fault-details + +### Existing files to modify in `skill_staging` + +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.js` + - replace empty shell with browser-eval entrypoint plus parity helpers +- Create: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js` + - deterministic fixture coverage for normalization, classification, summary, artifact contract, export/logging degradation, and entrypoint shape helpers +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/SKILL.toml` + - align tool description with real collection/export/report-log behavior +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/SKILL.md` + - align written contract with actual runtime behavior and artifact fields +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/references/collection-flow.md` + - align flow with page-range/query/export/report-log sequence +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/references/data-quality.md` + - make canonical columns, original classification tables, reason heuristics, summary rules, and partial semantics explicit +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/scenes/fault-details-report/scene.json` + - keep scene output/state contract aligned with real staged artifact behavior + +### Existing files to read but not redesign + +- Read only: `docs/superpowers/specs/2026-04-10-fault-details-full-skill-alignment-design.md` +- Read only: `src/agent/mod.rs` +- Read only: `src/compat/browser_script_skill_tool.rs` +- Read only: `D:/desk/智能体资料/大四区报告监测项/故障明细/index.html` + +--- + +### Task 1: Add staged-skill red tests for normalization, summary, and artifact-contract semantics + +**Files:** +- Create: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js` +- Read only: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.js` +- Read only: `D:/desk/智能体资料/大四区报告监测项/故障明细/index.html` + +- [ ] **Step 1: Write the failing staged-skill test file** + +Add `collect_fault_details.test.js` using `node:test` and `assert/strict`. Cover these behaviors with fixed fixtures: + +```javascript +const test = require('node:test'); +const assert = require('node:assert/strict'); + +const { + DETAIL_COLUMNS, + SUMMARY_COLUMNS, + normalizeDetailRow, + deriveSummaryRows, + determineArtifactStatus, + buildFaultDetailsArtifact, + buildBrowserEntrypointResult +} = require('./collect_fault_details.js'); + +test('normalizeDetailRow maps canonical detail fields from raw repair rows', () => { + const row = normalizeDetailRow({ + qxdbh: 'QX-1', + bxsj: '2026-03-09 08:00:00', + cityName: '国网兰州供电公司', + maintOrgName: '城关供电服务班', + maintGroupName: '抢修一班', + bdzMc: '110kV东岗变', + xlmc10: '10kV东岗线', + byqmc: '东岗1号变', + yjflMc: '电网故障', + ejflMc: '线路故障', + sjflMc: '低压线路', + qxxcjl: '现场检查:低压线路断线,已处理完成', + gzms: '客户报修停电' + }, { + companyName: '国网兰州供电公司' + }); + + assert.equal(row.slsj, '2026-03-09 08:00:00'); + assert.equal(row.gssgs, '甘肃省电力公司'); + assert.equal(row.gddw, '城关供电服务班'); + assert.equal(row.gds, '抢修一班'); + assert.equal(row.clzt, '处理完成'); + assert.equal(row.bdz, '110kV东岗变'); + assert.equal(row.line, '10kV东岗线'); + assert.equal(row.pb, '东岗1号变'); +}); + +test('deriveSummaryRows groups normalized rows by gds and computes counters', () => { + const rows = [ + { gds: '抢修一班', gddw: '城关供电服务班', sgs: '国网兰州供电公司', sxfl1: '无效', sxfl2: '无效', gzsb: '' }, + { gds: '抢修一班', gddw: '城关供电服务班', sgs: '国网兰州供电公司', sxfl1: '有效', sxfl2: '用户侧', gzsb: '表后线' }, + { gds: '抢修一班', gddw: '城关供电服务班', sgs: '国网兰州供电公司', sxfl1: '有效', sxfl2: '电网侧', dwcFl: '低压故障', gzsb: '低压线路' } + ]; + + const summaryRows = deriveSummaryRows(rows, { companyName: '国网兰州供电公司' }); + assert.equal(summaryRows.length, 1); + assert.equal(summaryRows[0].className, '抢修一班'); + assert.equal(summaryRows[0].allCount, 3); + assert.equal(summaryRows[0].wxCount, 1); + assert.equal(summaryRows[0].khcCount, 0); + assert.equal(summaryRows[0].dyGzCount, 1); + assert.equal(summaryRows[0].dyxlCount, 1); + assert.equal(summaryRows[0].bhxCount, 1); +}); + +test('determineArtifactStatus follows blocked > error > partial > empty > ok precedence', () => { + assert.equal(determineArtifactStatus({ blockedReason: 'missing_session', fatalError: null, partialReasons: [], detailRows: [{}] }), 'blocked'); + assert.equal(determineArtifactStatus({ blockedReason: null, fatalError: 'parse_failed', partialReasons: [], detailRows: [{}] }), 'error'); + assert.equal(determineArtifactStatus({ blockedReason: null, fatalError: null, partialReasons: ['export_failed'], detailRows: [{}] }), 'partial'); + assert.equal(determineArtifactStatus({ blockedReason: null, fatalError: null, partialReasons: [], detailRows: [] }), 'empty'); + assert.equal(determineArtifactStatus({ blockedReason: null, fatalError: null, partialReasons: [], detailRows: [{}] }), 'ok'); +}); + +test('buildFaultDetailsArtifact keeps canonical fields, selected range, counts, and downstream results', () => { + const artifact = buildFaultDetailsArtifact({ + period: '2026-03', + selectedRange: { start: '2026-03-08 16:00:00', end: '2026-03-09 16:00:00' }, + detailRows: [{ qxdbh: 'QX-1' }], + summaryRows: [{ index: 1 }], + partialReasons: ['report_log_failed'], + downstream: { + export: { attempted: true, success: true, path: 'http://localhost/export.xlsx' }, + report_log: { attempted: true, success: false, error: '500' } + } + }); + + assert.equal(artifact.type, 'report-artifact'); + assert.equal(artifact.status, 'partial'); + assert.deepEqual(artifact.selected_range, { start: '2026-03-08 16:00:00', end: '2026-03-09 16:00:00' }); + assert.equal(artifact.counts.detail_rows, 1); + assert.equal(artifact.counts.summary_rows, 1); + assert.deepEqual(artifact.partial_reasons, ['report_log_failed']); +}); + +test('buildFaultDetailsArtifact keeps required top-level fields for blocked artifact', () => { + const artifact = buildFaultDetailsArtifact({ + period: '2026-03', + blockedReason: 'selected_range_unavailable', + partialReasons: ['selected_range_unavailable'] + }); + + assert.equal(artifact.type, 'report-artifact'); + assert.equal(artifact.report_name, 'fault-details-report'); + assert.equal(artifact.period, '2026-03'); + assert.equal(artifact.status, 'blocked'); + assert.deepEqual(artifact.partial_reasons, ['selected_range_unavailable']); + assert.equal('downstream' in artifact, false); +}); + +test('buildFaultDetailsArtifact keeps known selected range and counts on late error', () => { + const artifact = buildFaultDetailsArtifact({ + period: '2026-03', + selectedRange: { start: '2026-03-08 16:00:00', end: '2026-03-09 16:00:00' }, + detailRows: [], + summaryRows: [], + fatalError: 'summary_failed', + partialReasons: ['summary_failed'] + }); + + assert.equal(artifact.status, 'error'); + assert.deepEqual(artifact.selected_range, { start: '2026-03-08 16:00:00', end: '2026-03-09 16:00:00' }); + assert.equal(artifact.counts.detail_rows, 0); + assert.equal(artifact.counts.summary_rows, 0); +}); + +test('buildBrowserEntrypointResult returns blocked artifact when selected range is unavailable', async () => { + const artifact = await buildBrowserEntrypointResult({ + period: '2026-03' + }, { + readSelectedRange: async () => null + }); + + assert.equal(artifact.status, 'blocked'); + assert.ok(artifact.partial_reasons.includes('selected_range_unavailable')); +}); +``` + +- [ ] **Step 2: Run the staged-skill test file and verify it fails** + +Run: + +```bash +node "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js" +``` + +Expected: FAIL because `collect_fault_details.js` does not export these helpers yet and still only returns an empty shell. + +--- + +### Task 2: Implement staged-skill parity helpers and a valid browser entrypoint + +**Files:** +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.js` +- Test: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js` + +- [ ] **Step 1: Implement the helper exports and browser entrypoint shape needed to satisfy the red tests** + +Refactor `collect_fault_details.js` so the file remains a valid browser-eval script in page context while still supporting `node:test` through an environment-safe export guard. + +Required implementation pieces: + +```javascript +const DETAIL_COLUMNS = [/* existing canonical columns */]; +const SUMMARY_COLUMNS = [/* existing summary columns */]; + +function normalizeDetailRow(raw, context) { + // map qxdbh/gssgs/sgs/gddw/gds/slsj/clzt/bdz/line/pb + // derive sxfl1/sxfl2/sxfl3/gzsb/gzyy from the original package rules +} + +function deriveSummaryRows(detailRows, context) { + // group by gds and compute all original package counters +} + +function determineArtifactStatus({ blockedReason, fatalError, partialReasons, detailRows }) { + // blocked > error > partial > empty > ok +} + +function buildFaultDetailsArtifact({ + period, + selectedRange, + detailRows, + summaryRows, + partialReasons, + blockedReason, + fatalError, + downstream +}) { + // return report-artifact with columns, sections, counts, status, partial_reasons, downstream +} + +async function buildBrowserEntrypointResult(input, deps = defaultBrowserDeps()) { + // read selected range from page + // collect raw rows from page query + // normalize rows + // derive summary + // attempt export + report log + // return final artifact +} + +if (typeof module !== 'undefined' && module.exports) { + module.exports = { + DETAIL_COLUMNS, + SUMMARY_COLUMNS, + normalizeDetailRow, + deriveSummaryRows, + determineArtifactStatus, + buildFaultDetailsArtifact, + buildBrowserEntrypointResult + }; +} + +return await buildBrowserEntrypointResult(args); +``` + +Rules: +- keep `DETAIL_COLUMNS` and `SUMMARY_COLUMNS` canonical and stable +- keep helper functions self-contained in this file unless a separate pure helper file becomes necessary for runtime validity +- keep the browser entrypoint compatible with current `eval` wrapper +- keep browser runtime free of unguarded Node-only assumptions +- do **not** invent a new protocol or callback surface + +- [ ] **Step 2: Re-run the staged-skill test file and verify it now reaches deeper failures or passes the initial helper coverage** + +Run: + +```bash +node "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js" +``` + +Expected: either PASS for the Task 1 cases, or fail only on the still-missing full parity/export/history specifics added in Task 3. + +--- + +### Task 3: Add red tests for full classification parity, downstream partials, and empty-result export semantics + +**Files:** +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js` +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.js` +- Read only: `D:/desk/智能体资料/大四区报告监测项/故障明细/index.html` + +- [ ] **Step 1: Extend the staged-skill tests with failing parity and downstream cases** + +Add focused failing tests such as: + +```javascript +test('normalizeDetailRow derives gzyy from qxxcjl text heuristics', () => { + const row = normalizeDetailRow({ + qxxcjl: '现场检查:客户表后线烧损,已恢复送电', + ejflMc: '客户侧故障', + sjflMc: '表后线' + }, { companyName: '国网兰州供电公司' }); + + assert.equal(row.gzsb, '表后线'); + assert.equal(row.gzyy, '表后线烧损'); +}); + +test('buildBrowserEntrypointResult returns partial when export fails after detail collection succeeds', async () => { + const artifact = await buildBrowserEntrypointResult({ period: '2026-03' }, { + readSelectedRange: async () => ({ start: '2026-03-08 16:00:00', end: '2026-03-09 16:00:00' }), + queryFaultRows: async () => [{ qxdbh: 'QX-1', bxsj: '2026-03-09 08:00:00', maintGroupName: '抢修一班' }], + readCompanyContext: () => ({ companyName: '国网兰州供电公司' }), + exportWorkbook: async () => { + throw new Error('export_failed'); + }, + writeReportLog: async () => ({ success: true }) + }); + + assert.equal(artifact.status, 'partial'); + assert.ok(artifact.partial_reasons.includes('export_failed')); + assert.equal(artifact.counts.detail_rows, 1); + assert.equal(artifact.downstream.export.attempted, true); + assert.equal(artifact.downstream.export.success, false); +}); + +test('buildBrowserEntrypointResult returns error when normalized detail rows cannot be produced', async () => { + const artifact = await buildBrowserEntrypointResult({ period: '2026-03' }, { + readSelectedRange: async () => ({ start: '2026-03-08 16:00:00', end: '2026-03-09 16:00:00' }), + queryFaultRows: async () => [{ qxdbh: '', bxsj: '' }], + readCompanyContext: () => ({ companyName: '国网兰州供电公司' }) + }); + + assert.equal(artifact.status, 'error'); + assert.ok(artifact.partial_reasons.includes('detail_normalization_failed')); +}); + +test('buildBrowserEntrypointResult keeps canonical rows empty for empty result and omits downstream before attempts', async () => { + const artifact = await buildBrowserEntrypointResult({ period: '2026-03' }, { + readSelectedRange: async () => ({ start: '2026-03-08 16:00:00', end: '2026-03-09 16:00:00' }), + queryFaultRows: async () => [], + readCompanyContext: () => ({ companyName: '国网兰州供电公司' }) + }); + + assert.equal(artifact.status, 'empty'); + assert.deepEqual(artifact.rows, []); + assert.equal('downstream' in artifact, false); +}); +``` + +Also add fixture cases derived from the original package’s full classification table and summary counters so the staged skill is forced toward parity, not a subset implementation. + +- [ ] **Step 2: Run the staged-skill test file and verify it fails on the new cases** + +Run: + +```bash +node "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js" +``` + +Expected: FAIL on missing full classification parity or downstream partial/error behavior. + +- [ ] **Step 3: Implement the full business logic needed to satisfy the new tests** + +In `collect_fault_details.js`: +- port the original classification table and `qxxcjl` text heuristics for `sxfl1`, `sxfl2`, `sxfl3`, `gzsb`, `gzyy` +- port the original summary derivation rules and counters completely +- add required-field validation so structurally unusable normalized rows escalate to `error` +- add downstream `exportWorkbook` and `writeReportLog` stages that record `{attempted, success, path, error}` +- keep collection success distinct from downstream failures so export/logging failures become `partial`, not full failure +- keep placeholder rows, if needed for downstream empty-export payloads, downstream-only and never in canonical returned `rows` +- include both `period` and `selected_range` in the artifact +- omit `downstream` when export/report-log have not been attempted yet + +- [ ] **Step 4: Re-run the staged-skill test file and verify it passes** + +Run: + +```bash +node "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js" +``` + +Expected: PASS. + +--- + +### Task 4: Align staged-skill metadata and reference docs with the implemented behavior + +**Files:** +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/SKILL.toml` +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/SKILL.md` +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/references/collection-flow.md` +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/references/data-quality.md` +- Modify: `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/scenes/fault-details-report/scene.json` + +- [ ] **Step 1: Update the staged metadata/docs to match the implemented runtime contract** + +Required changes: +- `SKILL.toml`: description must say the tool collects rows, derives summary, attempts localhost export, and records report history +- `SKILL.md`: artifact example must include `selected_range`, `counts`, `status`, `partial_reasons`, and `downstream` +- `references/collection-flow.md`: sequence must explicitly include page-selected range -> raw query -> normalization -> summary -> export -> report-log +- `references/data-quality.md`: document the original classification tables, `qxxcjl` heuristics, summary rules, partial/error escalation rules, and empty-result semantics explicitly enough to match the implemented helpers +- `scene.json`: keep inputs/outputs/status semantics aligned with the richer artifact; do not add routing policy there + +- [ ] **Step 2: Read the updated staged docs and verify they match the implemented JS behavior** + +Read and confirm: +- descriptions no longer claim “artifact shell” behavior +- docs do not move routing ownership out of `claw-new` +- docs do not promise auto-opening/downloading behavior in this slice +- docs reflect blocked/error field-presence rules and downstream-attempt semantics + +Expected: staged metadata/docs accurately reflect the implemented collector. + +--- + +### Task 5: Add Rust red tests for artifact-status interpretation in the direct-submit runtime + +**Files:** +- Modify: `tests/agent_runtime_test.rs` +- Modify: `tests/browser_script_skill_tool_test.rs` +- Modify: `src/compat/direct_skill_runtime.rs` +- Read only: `src/compat/browser_script_skill_tool.rs` + +- [ ] **Step 1: Add failing direct-submit runtime tests for structured artifact statuses** + +Extend `tests/agent_runtime_test.rs` with focused regressions that use the existing temp skill-root harness but return real `report-artifact` payloads: + +```rust +#[test] +fn submit_task_treats_partial_report_artifact_as_success_with_warning_summary() { + let skill_root = build_direct_runtime_skill_root(); + let runtime_context = direct_submit_runtime_context(&skill_root); + let transport = Arc::new(MockTransport::new(vec![success_browser_response( + 1, + serde_json::json!({ + "text": { + "type": "report-artifact", + "report_name": "fault-details-report", + "period": "2026-03", + "selected_range": { "start": "2026-03-08 16:00:00", "end": "2026-03-09 16:00:00" }, + "columns": ["qxdbh"], + "rows": [{ "qxdbh": "QX-1" }], + "sections": [{ "name": "summary-sheet", "columns": ["index"], "rows": [{ "index": 1 }] }], + "counts": { "detail_rows": 1, "summary_rows": 1 }, + "status": "partial", + "partial_reasons": ["report_log_failed"], + "downstream": { + "export": { "attempted": true, "success": true, "path": "http://localhost/export.xlsx" }, + "report_log": { "attempted": true, "success": false, "error": "500" } + } + } + }), + )])); + // ... invoke handle_browser_message_with_context(...) + // assert TaskComplete.success == true + // assert summary contains partial/report_log_failed/detail_rows=1 +} + +#[test] +fn submit_task_treats_empty_report_artifact_as_success() { /* status=empty => success=true */ } + +#[test] +fn submit_task_treats_blocked_report_artifact_as_failure() { /* status=blocked => success=false */ } + +#[test] +fn submit_task_treats_error_report_artifact_as_failure() { /* status=error => success=false */ } +``` + +Also add one focused helper regression to `tests/browser_script_skill_tool_test.rs` that proves the browser-script helper can return a structured object payload used by the fault-details path without flattening required fields away. + +Suggested test name: + +```rust +#[tokio::test] +async fn execute_browser_script_tool_preserves_structured_report_artifact_payload() { /* ... */ } +``` + +- [ ] **Step 2: Run the focused Rust tests and verify they fail** + +Run: + +```bash +cargo test --test agent_runtime_test submit_task_treats_partial_report_artifact_as_success_with_warning_summary -- --nocapture +cargo test --test browser_script_skill_tool_test execute_browser_script_tool_preserves_structured_report_artifact_payload -- --nocapture +``` + +Expected: the new `agent_runtime_test` case fails because `execute_direct_submit_skill` still returns raw JSON text and `src/agent/mod.rs` still marks all direct-submit results as success when no Rust-side interpretation exists. + +--- + +### Task 6: Implement narrow Rust artifact interpretation without moving business rules into Rust + +**Files:** +- Modify: `src/compat/direct_skill_runtime.rs` +- Modify: `tests/agent_runtime_test.rs` +- Modify: `tests/browser_script_skill_tool_test.rs` + +- [ ] **Step 1: Implement a narrow structured-artifact interpreter in `src/compat/direct_skill_runtime.rs`** + +Add a small internal result type and parser, for example: + +```rust +struct DirectSubmitOutcome { + success: bool, + summary: String, +} + +fn interpret_direct_submit_output(output: &str) -> DirectSubmitOutcome { + // parse JSON if possible + // if type == "report-artifact", read status/counts/partial_reasons/downstream + // map ok/partial/empty => success=true + // map blocked/error => success=false + // build concise summary with report_name, period, detail_rows, summary_rows, status, partial reasons + // fall back to raw output text when payload is not a recognized artifact +} +``` + +Then change the public entrypoint shape from `Result` to a narrow result carrying `success` and `summary`, or add a second helper that `src/agent/mod.rs` can use without changing routing ownership. + +Rules: +- do **not** reimplement fault normalization/classification/summary in Rust +- do **not** add fault-specific branching in `src/agent/mod.rs` +- keep unrecognized non-artifact outputs working as before +- keep explicit `YYYY-MM` derivation and configured `skill.tool` resolution unchanged + +- [ ] **Step 2: Update the submit-path caller to use the interpreted success flag** + +Adjust the direct-submit branch so `TaskComplete.success` comes from the artifact interpretation instead of blindly treating every `Ok(summary)` as success. + +Implementation target: +- keep the direct path in `src/agent/mod.rs` +- keep error handling narrow +- if needed, return a dedicated direct-submit outcome from `execute_direct_submit_skill` + +- [ ] **Step 3: Re-run the focused Rust tests and verify they pass** + +Run: + +```bash +cargo test --test agent_runtime_test submit_task_treats_partial_report_artifact_as_success_with_warning_summary -- --nocapture +cargo test --test agent_runtime_test submit_task_treats_empty_report_artifact_as_success -- --nocapture +cargo test --test agent_runtime_test submit_task_treats_blocked_report_artifact_as_failure -- --nocapture +cargo test --test agent_runtime_test submit_task_treats_error_report_artifact_as_failure -- --nocapture +cargo test --test browser_script_skill_tool_test execute_browser_script_tool_preserves_structured_report_artifact_payload -- --nocapture +``` + +Expected: PASS. + +--- + +### Task 7: Run the full verification sweep for the staged skill and direct runtime + +**Files:** +- Verify only + +- [ ] **Step 1: Run the staged-skill deterministic test file** + +Run: + +```bash +node "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js" +``` + +Expected: PASS. + +- [ ] **Step 2: Run the relevant Rust regression suites** + +Run: + +```bash +cargo test --test browser_script_skill_tool_test -- --nocapture +cargo test --test agent_runtime_test -- --nocapture +``` + +Expected: PASS. + +- [ ] **Step 3: Run the broader compatibility coverage and build** + +Run: + +```bash +cargo test --test compat_runtime_test -- --nocapture +cargo test --test compat_config_test -- --nocapture +cargo build --bin sgclaw +``` + +Expected: PASS. + +- [ ] **Step 4: Manually verify the requirements against the approved spec** + +Checklist: +- staged skill now reads page-selected range instead of inventing a month window after entry +- staged skill returns canonical detail rows and summary rows +- staged skill ports the original classification table, `qxxcjl` heuristics, and summary counters with parity coverage +- staged skill records downstream export/report-log outcome +- staged skill distinguishes `ok` / `partial` / `empty` / `blocked` / `error` +- `blocked` / `error` artifacts keep the required top-level fields, and preserve known `selected_range` / `counts` when failure happens late enough +- `downstream` is omitted when export/report-log were not attempted and included with attempted/success flags once they were attempted +- empty-result canonical `rows` stay empty even if downstream export uses a placeholder transport row +- `claw-new` maps `ok` / `partial` / `empty` to success and `blocked` / `error` to failure +- no new routing metadata was added to `SKILL.toml` or `scene.json` +- no new browser protocol or opener/UI behavior was introduced + +Expected: all checklist items satisfied before calling the work complete. + +--- + +## Verification Checklist + +### Staged skill behavior + +```bash +node "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.test.js" +``` + +Expected: deterministic fixture coverage passes for normalization, full classification parity, summary derivation, artifact shape, empty semantics, and downstream partial semantics. + +### Direct-submit runtime mapping + +```bash +cargo test --test agent_runtime_test -- --nocapture +``` + +Expected: +- valid artifact `ok` / `partial` / `empty` completes successfully +- valid artifact `blocked` / `error` completes as failure +- existing invalid config regression still passes +- existing direct-submit happy path still passes + +### Browser-script helper safety + +```bash +cargo test --test browser_script_skill_tool_test -- --nocapture +``` + +Expected: current browser-script execution semantics remain intact while returning structured artifact payloads. + +### Compatibility/build + +```bash +cargo test --test compat_runtime_test -- --nocapture +cargo test --test compat_config_test -- --nocapture +cargo build --bin sgclaw +``` + +Expected: no regressions in compat execution/config loading; main binary builds cleanly. + +--- + +## Notes For The Engineer + +- The paired spec is `docs/superpowers/specs/2026-04-10-fault-details-full-skill-alignment-design.md`. +- Keep all fault business transforms in `skill_staging`, not in Rust. +- Keep direct routing config-owned via `skillsDir` + `directSubmitSkill`. +- Do **not** broaden this slice into LLM routing, generic dispatch policy, new browser opcodes, or export auto-open behavior. +- If the original package reveals extra classification rules that are needed for parity, add them only inside `collect_fault_details.js` and its staged references/tests, not in `claw-new`. diff --git a/docs/superpowers/plans/2026-04-11-main-into-ws-merge-v2-plan.md b/docs/superpowers/plans/2026-04-11-main-into-ws-merge-v2-plan.md new file mode 100644 index 0000000..f23d43e --- /dev/null +++ b/docs/superpowers/plans/2026-04-11-main-into-ws-merge-v2-plan.md @@ -0,0 +1,551 @@ +# Main → WS Merge v2 Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** 把最新 `origin/main` 合并到 `feature/claw-ws`,让 `ws` 分支最终同时保留 **pipe + ws** 两套通信能力、保留 Zhihu 行为,并用 `main` 上正式的 fault-details 实现替换 `ws` 上已 cleanup 删除的旧重复实现。 + +**Architecture:** 这次合并不是“把 cleanup 永久保持成没有 fault-details”,而是“先删除 ws 上旧重复实现,再吸收 main 上正式实现”。冲突裁决优先级是:**先保 pipe、再保 ws、再保 Zhihu、同时拒绝 ws 上旧重复 scene/fault-details 实现回流**。整个过程使用 `git merge --no-commit --no-ff origin/main`,冲突解决后只做聚焦验证,停在未提交状态。 + +**Tech Stack:** Git, Rust 2021, Cargo test, sgClaw pipe transport, ws transport, compat/runtime/orchestration stack, Zhihu direct workflow tests. + +--- + +## Preconditions + +- 当前分支必须是 `feature/claw-ws` +- `2026-04-09-ws-branch-scene-cleanup-plan.md` 已完成 +- 当前不在 merge 状态 +- 当前没有 tracked 未提交改动 +- 本次**不创建 worktree**,按当前仓库执行 +- 本次结束点是:**已合并、已验证、未提交** + +--- + +## Final Merge Principles + +### 1) `main` 是 pipe 主线 +合并后不能把 `main` 上现有的 pipe 管道通信破坏掉。 + +### 2) `ws` 分支最终要同时保留 pipe + ws +合并后不能让 `ws` 分支丢掉 websocket 路径,也不能只剩 pipe。 + +### 3) 两边都有 Zhihu +合并后不能把现有 Zhihu 行为合坏,尤其是 ws→Zhihu 保留路径。 + +### 4) fault-details 以 `main` 正式实现为准 +- `ws` 上那套旧重复实现:**不能回流** +- `main` 上正式实现:**应被合进来** +- 最终结果不是“没有 fault-details”,而是“没有 ws 那套旧 fault-details,只保留 main 正式版本” + +### 5) 不回流旧 scene plumbing +以下旧面不能作为最终结果保留: +- ws 自己那套旧 scene registry / old scene plumbing +- ws cleanup 已删掉的旧重复 route/contract +- 仅为旧 `skill_staging` 场景装配服务的残留逻辑 + +--- + +## File Map + +### A. 合并时重点观察的共享/高风险文件 +- `Cargo.toml` +- `Cargo.lock` +- `src/agent/mod.rs` +- `src/agent/task_runner.rs` +- `src/config/settings.rs` +- `src/compat/config_adapter.rs` +- `src/compat/runtime.rs` +- `src/compat/orchestration.rs` +- `src/compat/workflow_executor.rs` +- `src/compat/browser_script_skill_tool.rs` +- `src/compat/direct_skill_runtime.rs` +- `src/compat/openxml_office_tool.rs` + +### B. pipe / ws / Zhihu 保护面 +- `src/compat/runtime.rs` +- `src/compat/orchestration.rs` +- `src/compat/workflow_executor.rs` +- `src/agent/task_runner.rs` +- `tests/agent_runtime_test.rs` +- `tests/browser_ws_backend_test.rs` +- `tests/service_ws_session_test.rs` +- `tests/task_runner_test.rs` + +### C. cleanup 后仍需防止旧实现回流的文件 +- `src/runtime/mod.rs` +- `src/runtime/engine.rs` +- `src/config/settings.rs` +- `src/compat/config_adapter.rs` +- `tests/compat_runtime_test.rs` +- `tests/runtime_profile_test.rs` +- `tests/compat_config_test.rs` + +### D. 可能需要随 main 正式 fault-details 一起更新的测试面 +- `tests/compat_runtime_test.rs` +- `tests/compat_config_test.rs` +- `tests/browser_script_skill_tool_test.rs` +- `tests/compat_openxml_office_tool_test.rs` + +--- + +## Conflict Resolution Rule Table + +| 类别 | 最终保留原则 | +|---|---| +| pipe 主路径 | **优先保留可工作的 main 版本**,不能被 ws 改坏 | +| ws 路径 | **必须继续保留 ws 能力**,不能因吸收 main 而丢失 | +| Zhihu | 两边相关能力都不能合坏,至少保住现有 keep-path | +| fault-details | **保留 main 正式实现**,不保留 ws 旧重复实现 | +| old scene/95598 cleanup 残留 | 不允许以 ws 旧重复实现形式回流 | +| `skillsDir` / config | 以最终产品需要为准;若 main 正式实现不要求旧 array-style/scene expansion,则不回流 | +| 临时 merge 修补 | 一律不保留 | + +--- + +### Task 1: Confirm Merge Preconditions And Diff Surface + +**Files:** +- No code changes expected +- Observe repo state and branch diff only + +- [ ] **Step 1: Confirm current branch** + +Run: +```bash +git rev-parse --abbrev-ref HEAD +``` + +Expected: +```text +feature/claw-ws +``` + +- [ ] **Step 2: Confirm no merge is in progress** + +Run: +```bash +git rev-parse -q --verify MERGE_HEAD +``` + +Expected: exit code `1`. + +- [ ] **Step 3: Confirm no tracked local changes** + +Run: +```bash +git diff --name-only && printf '\n---STAGED---\n' && git diff --cached --name-only +``` + +Expected: +```text + +---STAGED--- +``` + +- [ ] **Step 4: List current untracked files** + +Run: +```bash +git status --short +``` + +Expected: only known local untracked items, or a clearly understood list. + +- [ ] **Step 5: Update `origin/main`** + +Run: +```bash +git fetch origin main +``` + +- [ ] **Step 6: Show ws vs main diff surface before merge** + +Run: +```bash +git diff --name-status HEAD...origin/main +``` + +Expected: clear file list to compare likely merge surface. + +- [ ] **Step 7: Stop if preconditions fail** + +Stop if: +- branch is wrong +- merge is in progress +- tracked changes exist +- untracked file collision with `origin/main` is found and unresolved + +--- + +### Task 2: Start The Merge Without Committing + +**Files:** +- Merge index / working tree only + +- [ ] **Step 1: Start no-commit merge** + +Run: +```bash +git merge --no-commit --no-ff origin/main +``` + +Expected: +- either auto-merge pauses before commit +- or Git reports conflicts + +- [ ] **Step 2: Capture merge surface immediately** + +Run: +```bash +git status --short +``` + +- [ ] **Step 3: Separate results into three buckets** +Create a working list of conflicted files under: +1. pipe-critical +2. ws/Zhihu-critical +3. shared infra / tests + +- [ ] **Step 4: If no conflicts, proceed directly to Task 4 verification** + +- [ ] **Step 5: If conflicts exist, proceed to Task 3** + +--- + +### Task 3: Resolve Conflicts By System Role, Not By Branch Bias + +**Files:** +- Only files reported by Git as conflicted + +#### Global conflict policy +For every conflicted hunk, answer these four questions in order: + +1. Does this hunk affect **pipe** correctness? +2. Does this hunk affect **ws** correctness? +3. Does this hunk affect **Zhihu** correctness? +4. Is this hunk part of **ws old duplicate fault-details/scene logic** or **main official implementation**? + +Then apply the rule: +- **pipe cannot break** +- **ws cannot break** +- **Zhihu cannot break** +- **ws old duplicate fault-details must stay deleted** +- **main official fault-details should come in** + +--- + +#### Task 3A: Resolve pipe-critical shared runtime files + +**Files:** +- `src/compat/runtime.rs` +- `src/agent/task_runner.rs` +- `src/agent/mod.rs` +- `src/config/settings.rs` +- `src/compat/config_adapter.rs` + +- [ ] **Step 1: For each conflict, keep the side that preserves main’s pipe behavior** + +- [ ] **Step 2: Reject ws-only duplicate business logic that main already owns** + +- [ ] **Step 3: Keep ws support if the file also serves ws path** +This is additive preservation, not “main wins everything”. + +- [ ] **Step 4: Verify each resolved file has no conflict markers** + +Run per file: +```bash +git diff --check -- +``` + +--- + +#### Task 3B: Resolve ws / Zhihu-critical routing files + +**Files:** +- `src/compat/workflow_executor.rs` +- `src/compat/orchestration.rs` + +- [ ] **Step 1: Bring in main’s official fault-details path if it lives here** + +- [ ] **Step 2: Do not reintroduce ws’s old duplicate fault-details path** + +- [ ] **Step 3: Preserve ws submit/browser websocket path** + +- [ ] **Step 4: Preserve Zhihu routing path** + +- [ ] **Step 5: Verify each resolved file has no conflict markers** + +Run per file: +```bash +git diff --check -- +``` + +--- + +#### Task 3C: Resolve shared infra files minimally + +**Files:** +- `Cargo.toml` +- `Cargo.lock` +- `src/compat/browser_script_skill_tool.rs` +- `src/compat/direct_skill_runtime.rs` +- `src/compat/openxml_office_tool.rs` + +- [ ] **Step 1: Keep only the dependency/code shape needed by the merged result** + +- [ ] **Step 2: Do not keep lines from prior failed merge attempts** + +- [ ] **Step 3: Accept main fixes unless they break pipe/ws/Zhihu behavior** + +- [ ] **Step 4: Verify each resolved file has no conflict markers** + +Run per file: +```bash +git diff --check -- +``` + +--- + +#### Task 3D: Resolve tests to reflect final intended product + +**Files:** +- `tests/compat_runtime_test.rs` +- `tests/runtime_profile_test.rs` +- `tests/compat_config_test.rs` +- `tests/agent_runtime_test.rs` +- `tests/browser_script_skill_tool_test.rs` +- `tests/compat_openxml_office_tool_test.rs` + +- [ ] **Step 1: Keep tests proving pipe path still works** + +- [ ] **Step 2: Keep tests proving ws path still works** + +- [ ] **Step 3: Keep Zhihu keep-path regression** + +- [ ] **Step 4: Replace cleanup-only “fault-details absent” assertions if final intended state is now “fault-details present via main official implementation”** + +- [ ] **Step 5: Do not keep assertions that only prove ws’s old duplicate implementation is absent if they now contradict the intended merged product** + +- [ ] **Step 6: Verify each resolved test file has no conflict markers** + +Run per file: +```bash +git diff --check -- +``` + +--- + +#### Task 3E: Confirm merge is fully resolved + +**Files:** +- No code changes expected + +- [ ] **Step 1: Confirm no unmerged entries remain** + +Run: +```bash +git diff --name-only --diff-filter=U +``` + +Expected: no output. + +- [ ] **Step 2: Show final resolved file list** + +Run: +```bash +git diff --cached --name-only +``` + +--- + +### Task 4: Verify Final Product Behavior, Not Cleanup Intermediate State + +**Files:** +- Test: `tests/agent_runtime_test.rs` +- Test: `tests/browser_ws_backend_test.rs` +- Test: `tests/service_ws_session_test.rs` +- Test: `tests/task_runner_test.rs` +- Test: `tests/compat_runtime_test.rs` +- Test: `tests/runtime_profile_test.rs` +- Test: `tests/compat_config_test.rs` +- Conditional: `tests/browser_script_skill_tool_test.rs` +- Conditional: `tests/compat_openxml_office_tool_test.rs` + +#### Verification goals +This task must prove all four: + +1. **pipe path still works** +2. **ws path still works** +3. **Zhihu still works** +4. **final fault-details implementation is the main version, not ws’s old duplicate** + +--- + +#### Task 4A: Verify pipe-related behavior + +- [ ] **Step 1: Run task runner coverage** + +Run: +```bash +cargo test --test task_runner_test -- --nocapture +``` + +- [ ] **Step 2: Run compat runtime suite relevant to main path** + +Run: +```bash +cargo test --test compat_runtime_test -- --nocapture +``` + +- [ ] **Step 3: If pipe-specific tests fail, stop and fix merge resolution before continuing** + +--- + +#### Task 4B: Verify ws-related behavior + +- [ ] **Step 1: Run browser websocket backend suite** + +Run: +```bash +cargo test --test browser_ws_backend_test -- --nocapture +``` + +- [ ] **Step 2: Run service websocket session suite** + +Run: +```bash +cargo test --test service_ws_session_test -- --nocapture +``` + +- [ ] **Step 3: If ws-specific tests fail, stop and fix merge resolution before continuing** + +--- + +#### Task 4C: Verify Zhihu behavior + +- [ ] **Step 1: Re-run ws→Zhihu keep-path regression** + +Run: +```bash +cargo test --test agent_runtime_test production_submit_task_routes_zhihu_through_ws_backend_without_helper_bootstrap -- --nocapture +``` + +Expected: +```text +1 passed; 0 failed +``` + +- [ ] **Step 2: If additional Zhihu tests were touched by conflicts, run the smallest affected test target** + +Run as needed: +```bash +cargo test --test agent_runtime_test -- --nocapture +``` + +--- + +#### Task 4D: Verify config/runtime contracts + +- [ ] **Step 1: Run runtime profile suite** + +Run: +```bash +cargo test --test runtime_profile_test -- --nocapture +``` + +- [ ] **Step 2: Run compat config suite** + +Run: +```bash +cargo test --test compat_config_test -- --nocapture +``` + +- [ ] **Step 3: Ensure contracts now reflect final merged product, not the cleanup-only intermediate** + +--- + +#### Task 4E: Verify shared infra if touched + +- [ ] **Step 1: If browser-script tool files were touched** + +Run: +```bash +cargo test --test browser_script_skill_tool_test -- --nocapture +``` + +- [ ] **Step 2: If openxml files were touched** + +Run: +```bash +cargo test --test compat_openxml_office_tool_test -- --nocapture +``` + +--- + +#### Task 4F: Compile guard + +- [ ] **Step 1: Run compile-only full test build** + +Run: +```bash +cargo test --no-run +``` + +Expected: exit code `0`. + +--- + +### Task 5: Confirm The Merge Outcome Matches The Principle + +**Files:** +- No code changes expected + +- [ ] **Step 1: Show final status** + +Run: +```bash +git status --short +``` + +Expected: +- no `UU` / `AA` / `DD` +- merged, validated, uncommitted state only + +- [ ] **Step 2: Show final staged summary** + +Run: +```bash +git diff --cached --stat +``` + +- [ ] **Step 3: Report the four required facts with command-backed evidence** +Only if verified: +1. pipe 没坏 +2. ws 没坏 +3. Zhihu 没坏 +4. 最终 fault-details 来自 main 正式实现,而不是 ws 旧重复实现 + +- [ ] **Step 4: Stop here** +Do **not** run: +```bash +git commit +git push +``` + +--- + +## Stop Conditions + +出现以下任一情况立即停止,不擅自扩展处理: + +- `origin/main` 的正式 fault-details 实现依赖 cleanup 已删掉的契约,而这已经超出简单 merge 范围 +- pipe 与 ws 同时依赖同一段共享代码,但两边要求已结构性冲突 +- Zhihu keep-path 失败 +- `cargo test --no-run` 失败且问题超出本次 merge surface +- 需要重新设计 pipe/ws 共存方式,而不是单纯合并 + +--- + +## One-line Execution Rule + +**这次 merge 的最终标准不是“继续保持 ws 没有 fault-details”,而是“保住 pipe、保住 ws、保住 Zhihu,并让 main 的正式 fault-details 替换 ws 旧重复实现”。** diff --git a/docs/superpowers/specs/2026-04-09-config-owned-direct-skill-dispatch-design.md b/docs/superpowers/specs/2026-04-09-config-owned-direct-skill-dispatch-design.md new file mode 100644 index 0000000..2ca3c3a --- /dev/null +++ b/docs/superpowers/specs/2026-04-09-config-owned-direct-skill-dispatch-design.md @@ -0,0 +1,125 @@ +# Config-Owned Direct Skill Dispatch Design + +**Goal:** Preserve the current minimal submit flow where sgClaw accepts natural-language input, directly invokes one configured staged browser skill without calling an LLM, and keeps dispatch ownership in sgClaw configuration rather than external skill metadata. + +**Status:** Approved design direction for the next slice. The current minimal direct-submit path already works; this document records the ownership boundary that future dispatch-policy work should follow. + +--- + +## Decision Summary + +1. Keep direct-skill selection in sgClaw configuration. +2. Continue using `skillsDir` plus `directSubmitSkill` as the only control surface for the no-LLM direct path. +3. Do not add sgClaw-specific dispatch fields to files under `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging` in this slice. +4. Keep the currently bound skill as `fault-details-report.collect_fault_details`. +5. When dispatch expands beyond one fixed skill, add the next policy layer on the sgClaw side first, not in `scene.json` or `SKILL.toml`. + +--- + +## Current Minimal Flow + +The intended user experience stays unchanged: +- the user types natural language into the input box +- sgClaw receives `BrowserMessage::SubmitTask` +- sgClaw loads runtime config +- if `directSubmitSkill` is configured, sgClaw bypasses LLM routing and directly resolves the configured staged skill from `skillsDir` +- sgClaw executes the target `browser_script` tool through the browser runtime and returns the result +- if `directSubmitSkill` is absent, sgClaw falls back to the existing orchestration / compat behavior + +This keeps the first slice small while preserving a clear seam for future expansion. + +--- + +## Ownership Boundary + +### sgClaw configuration owns dispatch choice + +sgClaw configuration is responsible for deciding whether submit-task should bypass the LLM path and which direct skill should run. + +For the current slice, that means: +- `skillsDir` tells sgClaw where to load staged skills from +- `directSubmitSkill` tells sgClaw which `skill.tool` should be used for the direct path + +Example: + +```json +{ + "skillsDir": "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging", + "directSubmitSkill": "fault-details-report.collect_fault_details" +} +``` + +### skill_staging owns skill identity and execution assets + +Files under `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging` remain responsible for describing the skill package, tool identity, and browser-script implementation. + +For the current bound skill: +- `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/scenes/fault-details-report/scene.json` +- `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/SKILL.toml` +- `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills/fault-details-report/scripts/collect_fault_details.js` + +These files already provide enough information for sgClaw to locate the package and run the tool. This slice does not add a new dispatch field inside them. + +--- + +## Why This Boundary Is Recommended + +### One source of truth for routing + +If sgClaw configuration owns the direct-skill decision, the operator can switch the direct skill by changing config only. There is no need to edit code and no need to mutate external skill assets just to change routing. + +### Avoid freezing external manifest semantics too early + +`skill_staging` is an external skill asset set. Adding sgClaw-specific dispatch metadata now would couple the staged-skill format to one integration strategy before the policy model is stable. + +### Preserve a clean migration path + +The current minimal path is intentionally narrow: one fixed configured direct skill, no LLM dispatch, no per-skill policy registry yet. Keeping dispatch control in sgClaw makes it easier to add a broader policy layer later without rewriting the staged-skill package format first. + +--- + +## Explicit Non-Goals + +This design does not do the following: +- redesign the submit-task protocol +- move dispatch control into `scene.json` or `SKILL.toml` +- require every staged skill to declare `direct_browser` or `llm_agent` right now +- expand the current direct path into generic natural-language intent classification +- change the browser-script execution model +- change the current fallback orchestration / compat execution semantics when `directSubmitSkill` is not configured + +--- + +## Current Skill Contract + +The current direct path remains intentionally deterministic. + +For `fault-details-report.collect_fault_details`, sgClaw derives only the minimum required arguments: +- `expected_domain` from the current `page_url` +- `period` from an explicit `YYYY-MM` token in the user's natural-language input + +That means the UX still looks like natural-language submission, but the runtime does not ask an LLM to infer intent or invent missing parameters. If the period is missing, sgClaw should return a clear error instead of guessing. + +--- + +## Future Dispatch Policy Direction + +When more than one staged skill needs routing control, the next layer should still begin on the sgClaw side. + +Recommended direction: +- keep `directSubmitSkill` as the current bootstrap switch for the minimal fixed-skill path +- introduce a sgClaw-owned registry or config mapping that can later express `skill.tool -> direct_browser | llm_agent` +- keep external skill manifests unchanged until the policy surface proves stable in real use + +Only after the routing model is stable should we consider whether external skill metadata needs a default dispatch hint. + +--- + +## Resulting Design Rule + +For this project, the direct-skill decision remains config-owned: +- sgClaw config decides whether submit-task bypasses the LLM path +- staged skill metadata identifies what the skill is and how its browser tool runs +- future per-skill dispatch policy should be added in sgClaw first, not in `skill_staging` + +This is the approved baseline for the next dispatch-policy slice. diff --git a/docs/superpowers/specs/2026-04-10-fault-details-full-skill-alignment-design.md b/docs/superpowers/specs/2026-04-10-fault-details-full-skill-alignment-design.md new file mode 100644 index 0000000..4795190 --- /dev/null +++ b/docs/superpowers/specs/2026-04-10-fault-details-full-skill-alignment-design.md @@ -0,0 +1,495 @@ +# Fault Details Full Skill Alignment Design + +**Goal:** Upgrade `fault-details-report.collect_fault_details` from an empty artifact shell into a real staged business skill that matches the original fault-details package's collection, normalization, summary, export, and report-history behavior, while keeping direct-skill routing config-owned in `claw-new`. + +**Status:** Approved design direction for the next remediation slice. + +--- + +## Decision Summary + +1. Keep direct-skill selection in `claw-new` via `skillsDir` + `directSubmitSkill`; do not move dispatch ownership into `skill_staging` manifests. +2. Put the fault-details business logic in `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging`, not in `claw-new`. +3. Align the staged skill with the original package's real behavior: query raw rows, normalize detail columns, derive summary rows, call localhost export, and write report history. +4. Keep the current browser-execution seam narrow: use the existing `browser_script` / browser-eval path, not a new browser protocol or new opcodes. +5. Add a narrow artifact interpreter in `claw-new` so structured fault-results map cleanly to `TaskComplete.success` and a readable completion summary. + +--- + +## Why This Slice Exists + +The current staged skill contract and the current staged skill implementation do not match. + +### What the original package actually does + +The original package under `D:/desk/智能体资料/大四区报告监测项/故障明细` does all of the following: + +- reads the selected date range from the page UI +- queries the D4 repair-order data source +- filters and normalizes raw rows into the canonical detail export schema +- derives grouped summary rows by `gds` +- calls `http://localhost:13313/SurfaceServices/personalBread/export/faultDetailsExportXLSXS` +- auto-opens/downloads the generated file +- writes report history through `http://localhost:13313/ReportServices/Api/setReportLog` + +### What the staged skill currently does + +The current staged `collect_fault_details.js` only returns an empty `report-artifact` shell with empty `rows` and empty summary `sections`. + +It also still uses a Node-style export shape instead of the browser-eval entrypoint shape that the current `browser_script` runtime expects. In practice, this means the staged script is not yet aligned with the real runtime contract even before business behavior is considered. + +This slice closes that gap by making the staged skill actually perform the work the original package performs, but through the current sgClaw direct-skill runtime. + +--- + +## Design Rules + +### 1. `claw-new` owns routing, not business transforms + +`claw-new` stays responsible for: + +- loading config +- deciding whether submit-task takes the direct-skill path +- resolving the configured staged skill +- executing the staged browser-script tool +- turning the returned artifact into `TaskComplete.success` + human-readable summary + +`claw-new` must **not** become the place where the original fault classification table, detail-row field mapping, or summary aggregation rules are reimplemented. + +### 2. `skill_staging` owns fault-details business behavior + +The staged skill package owns: + +- query orchestration inside the browser page context +- raw-row extraction +- canonical detail-row normalization +- classification and derived fields +- summary-sheet derivation +- localhost export request +- localhost report-log request +- structured result payload + +### 3. Keep the current browser seam narrow + +Do not introduce a new browser bridge, callback protocol, or skill-specific browser opcode for this slice. + +The implementation should continue using the current `browser_script` execution seam already wired through `claw-new/src/compat/browser_script_skill_tool.rs` and `claw-new/src/compat/direct_skill_runtime.rs`. + +### 4. Match business behavior, not the original shell verbatim + +The original package is a local HTML/Vue shell that uses `BrowserAction(...)`, timers, and hidden-browser choreography. That shell does **not** need to be recreated inside `claw-new`. + +What must be preserved is the business outcome: + +- same canonical detail columns +- same key field mappings +- same classification rules +- same summary metrics +- same downstream export/history behavior +- same distinction between empty, partial, blocked, and failed work + +--- + +## Ownership Boundary and Landing Zones + +### Staged skill changes + +These changes land in `D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging`. + +Primary files: + +- `skills/fault-details-report/scripts/collect_fault_details.js` + - becomes the real browser-eval entrypoint + - must directly `return` the final structured artifact from the wrapped browser script + - may contain internal helper functions, but should remain self-contained for the current runtime +- `skills/fault-details-report/SKILL.toml` + - keep `browser_script` + - tighten the tool description so it matches the real behavior + - do not turn `SKILL.toml` into the source of truth for classification rules or routing policy +- `skills/fault-details-report/SKILL.md` + - align the written contract with the implemented runtime behavior +- `skills/fault-details-report/references/collection-flow.md` + - align the staged flow with the implemented query/export/history sequence +- `skills/fault-details-report/references/data-quality.md` + - stay authoritative for canonical columns, required fields, classification tables, `qxxcjl`-based reason heuristics, summary rules, and partial semantics +- `scenes/fault-details-report/scene.json` + - keep the scene contract aligned with the actual output and state semantics + - do not move classification or routing policy into scene metadata + +### Caller/runtime changes + +These changes land in `D:/data/ideaSpace/rust/sgClaw/claw-new`. + +Primary files: + +- `src/compat/direct_skill_runtime.rs` + - keep configured direct-skill execution here + - add narrow structured-artifact interpretation after the browser-script returns +- `src/agent/mod.rs` + - keep the current direct-submit routing seam here + - do not add fault-specific business logic here +- `src/compat/browser_script_skill_tool.rs` + - keep the browser-script contract strict: browser-eval entrypoint, no Node-only assumptions +- `tests/agent_runtime_test.rs` + - direct-submit path and result-surface regressions +- `tests/browser_script_skill_tool_test.rs` + - browser-script execution-shape regressions + +If a new helper is needed in `claw-new`, it should be a narrow artifact-format/parser helper, not a new business-rules module. + +--- + +## Target Runtime Flow + +### Step 1: Submit-task stays config-owned + +The user still types natural language into the current sgClaw input. + +`claw-new`: + +- receives `BrowserMessage::SubmitTask` +- loads `SgClawSettings` +- sees `directSubmitSkill = "fault-details-report.collect_fault_details"` +- bypasses LLM routing exactly as it does now +- resolves the staged skill from `skillsDir` + +This preserves the already approved config-owned routing boundary. + +### Step 2: Browser-script tool executes as a true browser entrypoint + +`collect_fault_details.js` must be shaped for the current runtime: + +- the script runs inside the current browser page context through `eval` +- it must not rely on `module.exports` +- it must directly `return collectFaultDetails(args)` from the wrapped script body + +This is required because the current sgClaw browser-script runtime reads one script file and wraps it in a browser-side IIFE. + +### Step 3: The skill reads the page-selected time range + +The source-of-truth query window should come from the current page state, matching the original package behavior. + +Design rule: + +- read the selected start and end time from the business page controls or page state +- include that exact selected range in the returned artifact +- keep `period` as a bootstrap label from `claw-new`, not as a license to silently guess a different business range + +Compatibility rule with the current direct-submit seam: + +- the current `claw-new` direct path still requires an explicit `YYYY-MM` token in the user's instruction in order to enter the configured direct-skill flow +- that requirement remains in place for this slice +- once inside the skill, the browser page's selected start/end range is the source of truth for collection +- the returned artifact should include both the user-visible `period` label and the exact selected page range so mismatches are observable instead of hidden + +If the page-selected range cannot be read reliably, the skill should return `blocked` instead of inventing a month-wide query window from `period` alone. + +### Step 4: The skill collects raw rows and normalizes detail fields + +The staged skill must reproduce the original package's detail normalization logic inside the browser-executed script. + +That includes preserving the canonical detail schema from the original `excleIni[0].cols`, including the key transforms already present in the original package, such as: + +- `slsj = bxsj` +- `gssgs = "甘肃省电力公司"` +- `sgs` derived from the current company/city context +- `gddw = maintOrgName` +- `gds = maintGroupName` +- `clzt = "处理完成"` +- `bdz = bdzMc` +- `line = xlmc10` +- `pb = byqmc` + +The staged skill must also port the original classification/derivation logic that fills: + +- `sxfl1` +- `sxfl2` +- `sxfl3` +- `gzsb` +- `gzyy` + +That includes the original matching table and the `qxxcjl`-based text extraction heuristics that derive the fault reason. + +### Step 5: The skill derives summary rows from normalized detail rows + +The staged skill must derive the summary sheet from grouped detail rows, keyed around the same business totals the original package computes. + +At minimum that includes: + +- `index` +- `gsName` +- `fwDept` +- `className` +- `allCount` +- `wxCount` +- `khcCount` +- `sbdSbCount` +- `gyGzCount` +- `dyGzCount` +- `tqdzCount` +- `tqbxCount` +- `dyxlCount` +- `bqxCount` +- `jllCount` +- `bhxCount` +- `qftdCount` + +The summary derivation must stay in the staged skill so the same package can later be routed by LLM without moving business logic back into `claw-new`. + +### Step 6: The skill performs downstream export and report logging + +After detail rows and summary rows are available, the staged skill should reproduce the original package's downstream behavior: + +- build the export payload for `faultDetailsExportXLSXS` +- call the localhost export endpoint +- capture the returned export path/URL +- write report history via `setReportLog` + +Important boundary: + +- export/report-log are downstream side effects +- they do not redefine whether collection itself succeeded +- if collection succeeds but export/logging fails, the result is `partial`, not a full collection failure +- auto-opening/downloading the exported file is out of scope for this slice; this slice records the export path/result in the artifact but does not add new opener/UI behavior in `claw-new` + +### Step 7: The skill returns one structured artifact + +The staged skill should return one self-describing JSON artifact containing: + +- business identity (`type`, `report_name`) +- selected period label +- exact selected start/end range +- canonical detail columns + normalized rows +- summary section columns + rows +- counts +- business status +- partial reasons if any +- downstream export outcome +- downstream report-log outcome + +### Step 8: `claw-new` interprets the artifact, not the business rules + +After the browser-script returns, `claw-new` should parse the JSON artifact and map it into final submit-task behavior. + +Recommended mapping: + +- `status = ok` -> `TaskComplete.success = true` +- `status = partial` -> `TaskComplete.success = true`, with warnings in summary +- `status = empty` -> `TaskComplete.success = true`, clearly reported as empty-result +- `status = blocked` -> `TaskComplete.success = false` +- `status = error` -> `TaskComplete.success = false` + +This keeps business classification in the staged skill while preventing false-positive success in the direct path. + +--- + +## Artifact Contract + +The returned payload should stay `type = "report-artifact"`, but it must become rich enough to describe the real run. + +Recommended contract: + +```json +{ + "type": "report-artifact", + "report_name": "fault-details-report", + "period": "2026-03", + "selected_range": { + "start": "2026-03-08 16:00:00", + "end": "2026-03-09 16:00:00" + }, + "columns": ["qxdbh", "gssgs", "sgs", "gddw", "gds", "slsj", "yjflMc", "ejflMc", "sjflMc", "gzms", "yhbh", "yhmc", "lxr", "gzdd", "lxdh", "bxsj", "gdsj", "clzt", "qxxcjl", "bdz", "line", "pb", "sxfl1", "sxfl2", "sxfl3", "gzsb", "gzyy", "bz"], + "rows": [], + "sections": [ + { + "name": "summary-sheet", + "columns": ["index", "gsName", "fwDept", "className", "allCount", "wxCount", "khcCount", "sbdSbCount", "gyGzCount", "dyGzCount", "tqdzCount", "tqbxCount", "dyxlCount", "bqxCount", "jllCount", "bhxCount", "qftdCount"], + "rows": [] + } + ], + "counts": { + "detail_rows": 0, + "summary_rows": 0 + }, + "status": "ok", + "partial_reasons": [], + "downstream": { + "export": { + "attempted": true, + "success": true, + "path": "http://localhost:13313/.../fault-details.xlsx" + }, + "report_log": { + "attempted": true, + "success": true, + "report_name": "国网XX故障报修明细表(03月09日)", + "path": "http://localhost:13313/.../fault-details.xlsx" + } + } +} +``` + +### Contract notes + +- `rows` is the canonical returned detail table, not the export-service transport payload. +- If the export service still requires a placeholder row for an empty spreadsheet, that placeholder should be synthesized only for the downstream export call, not as the canonical returned `rows` contract. +- `counts` should be computed from the canonical returned tables. +- `selected_range`, `columns`, `sections`, `counts`, `status`, and `partial_reasons` should always be present for `ok`, `partial`, and `empty`. +- For `blocked` and `error`, the artifact should still include `type`, `report_name`, `period`, `status`, and `partial_reasons`; `selected_range`, `columns`, `sections`, and `counts` should be included whenever they were already known before the failure point. +- `downstream` should be omitted only when export/report-log were not attempted yet; otherwise include it with `attempted` / `success` flags and any available path or failure detail. + +--- + +## Error Handling and Status Semantics + +### `ok` + +Use `ok` when all of the following are true: + +- raw collection succeeded +- required detail-field normalization succeeded +- summary derivation succeeded +- export succeeded +- report-log write succeeded + +### `partial` + +Use `partial` when detail collection succeeded but at least one downstream stage degraded, including: + +- one or more required fields could not be normalized, but the row set still remains exportable and summary derivation can proceed with explicit gaps recorded +- summary derivation was incomplete, but the detail table is still available +- export failed after rows were available +- report-log write failed after rows/export were available + +Escalation rule: + +- if the raw query succeeds but required fields are missing so broadly that the canonical detail table cannot be produced at all, use `error`, not `partial` +- if summary derivation cannot even start because the normalized detail rows are structurally unusable, use `error`, not `partial` + +`partial_reasons` must name the degraded stage instead of hiding it. + +### `empty` + +Use `empty` when: + +- the query succeeds for the selected range +- zero real detail rows match + +This is not a failure. + +If the business flow still wants an empty export file or placeholder export payload, that happens downstream without changing the semantic meaning of the result. + +### `blocked` + +Use `blocked` when the page/session preconditions are not met, for example: + +- expected page/session is not available +- required page controls cannot be read +- login/session state is missing or expired +- required browser-visible APIs are unavailable in the current page context + +### `error` + +Use `error` when the run starts but fails due to operational or parsing problems, for example: + +- request failure +- page script failure +- raw response parse failure +- malformed export response + +### `claw-new` completion mapping + +`claw-new` should convert structured status into final submit completion behavior: + +- `ok` / `partial` / `empty`: return a success completion with a concise human summary +- `blocked` / `error`: return a failed completion with a concise human summary + +This avoids the current risk where a structured error-like payload could still be surfaced as a nominal success string. + +--- + +## Testing and Acceptance Strategy + +### Skill-side deterministic coverage + +Add deterministic coverage around the staged skill's business logic in `skill_staging` for: + +- canonical detail field mapping +- classification table parity +- `gzyy` extraction heuristics +- summary aggregation parity +- empty-result handling +- partial-result generation when downstream export/logging fails +- browser-script entrypoint shape (`return ...`, not `module.exports`) + +The classification/summary tests should use fixed raw-row fixtures so the business rules are validated without a live browser session. + +### `claw-new` runtime regressions + +Add Rust coverage in `claw-new` for: + +- direct-submit success with a populated `report-artifact` +- `partial` artifact mapping to `TaskComplete.success = true` +- `empty` artifact mapping to `TaskComplete.success = true` +- `blocked` / `error` artifact mapping to `TaskComplete.success = false` +- browser-script helper behavior for a real browser-eval return payload + +### Manual acceptance + +The live manual acceptance bar for this slice should be: + +1. Configure `skillsDir` to the staged skill root and `directSubmitSkill` to `fault-details-report.collect_fault_details`. +2. Attach sgClaw to the real target browser page/session. +3. Submit a natural-language fault-details request without LLM routing. +4. Verify the staged skill: + - reads the selected page range + - queries real fault rows + - produces populated detail rows + - produces populated summary rows + - exports the workbook through localhost + - writes report history +5. Verify the final sgClaw completion message reports the correct status, counts, and downstream file/log outcome. + +### Acceptance matrix + +At minimum, acceptance should cover: + +- normal populated result +- empty result with no matching rows +- partial result where export or report-log fails after collection +- blocked result where page/session preconditions are missing +- error result where parsing/query execution fails + +--- + +## Explicit Non-Goals + +This slice does **not**: + +- move routing ownership out of `claw-new` +- require LLM routing to be available first +- add per-skill dispatch metadata to external manifests for routing policy +- introduce a new browser protocol or browser opcode +- recreate the original Vue shell inside `claw-new` +- move fault classification logic into Rust +- redesign the submit-task protocol beyond better interpretation of the returned artifact + +--- + +## Resulting Design Rule + +For the fault-details path: + +- `claw-new` decides whether to invoke the fixed staged skill +- the staged skill performs the real fault business workflow +- the staged skill returns a structured artifact that describes collection + downstream outcomes +- `claw-new` interprets that artifact for submit-task success/failure and summary output + +That keeps routing config-owned, keeps business logic with the staged skill, and makes `fault-details-report.collect_fault_details` ready for both the current no-LLM path and a later LLM-routed path. + +--- + +## Document Landing Zones + +- Approved spec: `docs/superpowers/specs/2026-04-10-fault-details-full-skill-alignment-design.md` +- Follow-up implementation plan: `docs/superpowers/plans/2026-04-10-fault-details-full-skill-alignment-plan.md` diff --git a/resources/zhihu-hotlist-echarts.html b/resources/zhihu-hotlist-echarts.html new file mode 100644 index 0000000..1c864d8 --- /dev/null +++ b/resources/zhihu-hotlist-echarts.html @@ -0,0 +1,637 @@ + + + + + + 知乎热榜图表驾驶舱 + + + + +
+
+
+
Zhihu Hotlist Visual Command Center
+

知乎热榜图表驾驶舱

+

由 sgClaw screen_html_export 生成的本地静态展示页

+
+
+
+ 图表表达 + 同一份热榜数据同时映射为分类热度、头部热点、结构占比和热度散点,适合现场讲解图表能力。 +
+
+ 演示建议 + 优先讲解榜首热点、分类分布与热度层级,再向下展开全量榜单细节。 +
+
+
+ +
+
+
热榜条目数
+
0
+
Tracked items
+
+
+
主题分类数
+
0
+
Topic groups
+
+
+
累计热度
+
0
+
Total heat
+
+
+
头部峰值
+
0
+
Peak topic heat
+
+
+ +
+
+
+

分类总热度

+ 横向对比 +
+
+
+ +
+
+

Top10 热点

+ 柱状排行 +
+
+
+ +
+
+

分类占比

+ 环形结构 +
+
+
+ +
+
+

热度分层

+ 散点气泡 +
+
+
+ +
+
+

热榜明细

+ 按原始顺序保留 +
+
+ + + + + + + + + + +
排名标题分类热度
+
+
+
+ + +
+ + + diff --git a/src/agent/mod.rs b/src/agent/mod.rs index 7bc1c98..9c4c53e 100644 --- a/src/agent/mod.rs +++ b/src/agent/mod.rs @@ -95,8 +95,18 @@ pub fn handle_browser_message_with_context( page_url: normalize_optional_submit_field(page_url), page_title: normalize_optional_submit_field(page_title), }; - let browser_backend = browser_backend_for_submit(browser_tool, context, &request)?; - run_submit_task_with_browser_backend(transport, transport, browser_backend, context, request) + if configured_browser_ws_url(context).is_some() { + let browser_backend = browser_backend_for_submit(browser_tool, context, &request)?; + run_submit_task_with_browser_backend( + transport, + transport, + browser_backend, + context, + request, + ) + } else { + run_submit_task(transport, transport, browser_tool, context, request) + } } BrowserMessage::Init { .. } => { eprintln!("ignoring duplicate init after handshake"); diff --git a/src/agent/task_runner.rs b/src/agent/task_runner.rs index 03b01ab..9377824 100644 --- a/src/agent/task_runner.rs +++ b/src/agent/task_runner.rs @@ -198,6 +198,37 @@ pub fn run_submit_task( settings.runtime_profile, settings.skills_prompt_mode ), }); + if settings.direct_submit_skill.is_some() { + match crate::compat::direct_skill_runtime::execute_direct_submit_skill( + browser_tool.clone(), + &instruction, + &task_context, + &context.workspace_root, + &settings, + ) { + Ok(outcome) => { + let _ = send_mode_log(sink, "direct_skill_primary"); + return sink.send(&AgentMessage::TaskComplete { + success: outcome.success, + summary: outcome.summary, + }); + } + Err(PipeError::Protocol(message)) + if message.contains("must use skill.tool format") => + { + return sink.send(&AgentMessage::TaskComplete { + success: false, + summary: message, + }); + } + Err(err) => { + return sink.send(&AgentMessage::TaskComplete { + success: false, + summary: err.to_string(), + }); + } + } + } if RuntimeEngine::new(settings.runtime_profile).browser_surface_enabled() && crate::compat::orchestration::should_use_primary_orchestration( &instruction, diff --git a/src/browser/callback_host.rs b/src/browser/callback_host.rs index 5d60af0..4ad5fe7 100644 --- a/src/browser/callback_host.rs +++ b/src/browser/callback_host.rs @@ -667,7 +667,7 @@ fn normalize_callback_result( })) } "eval" if result.callback == EVAL_CALLBACK_NAME => { - let value = result.payload.get("value").and_then(Value::as_str)?; + let value = result.payload.get("value")?.clone(); Some(BrowserCallbackResponse::Success(BrowserCallbackSuccess { success: true, data: json!({ "text": value }), @@ -1403,4 +1403,36 @@ mod tests { other => panic!("expected Success, got {other:?}"), } } + + #[test] + fn normalize_callback_result_path_a_eval_accepts_structured_value_payload() { + let request = make_request("eval"); + let result = CallbackResult { + callback: "sgclawOnEval".to_string(), + request_url: "http://127.0.0.1:17888/sgclaw/browser-helper.html".to_string(), + target_url: Some("https://www.zhihu.com/hot".to_string()), + action: Some("sgBrowserExcuteJsCodeByDomain".to_string()), + payload: json!({ + "value": { + "source": "https://www.zhihu.com/hot", + "rows": [[1, "问题一", "344万"]] + } + }), + }; + + let response = normalize_callback_result(&request, result, Duration::from_millis(10)); + assert!(response.is_some(), "Path A eval should accept structured values"); + match response.unwrap() { + super::super::callback_backend::BrowserCallbackResponse::Success(s) => { + assert_eq!( + s.data.get("text").unwrap(), + &json!({ + "source": "https://www.zhihu.com/hot", + "rows": [[1, "问题一", "344万"]] + }) + ); + } + other => panic!("expected Success, got {other:?}"), + } + } } diff --git a/src/compat/browser_script_skill_tool.rs b/src/compat/browser_script_skill_tool.rs index f12603f..2bdfe0b 100644 --- a/src/compat/browser_script_skill_tool.rs +++ b/src/compat/browser_script_skill_tool.rs @@ -12,47 +12,15 @@ use zeroclaw::tools::{Tool, ToolResult}; use crate::browser::BrowserBackend; use crate::pipe::Action; -pub struct BrowserScriptInvocation<'a> { - pub tool: &'a SkillTool, - pub skill_root: &'a Path, -} - pub struct BrowserScriptSkillTool { tool_name: String, tool_description: String, - tool: SkillTool, skill_root: PathBuf, + script_path: PathBuf, args: HashMap, browser_tool: Arc, } -impl BrowserScriptInvocation<'_> { - fn script_path(&self) -> PathBuf { - self.skill_root.join(&self.tool.command) - } - - fn canonical_script_path(&self) -> anyhow::Result { - let script_path = self.script_path(); - let canonical_skill_root = self - .skill_root - .canonicalize() - .unwrap_or_else(|_| self.skill_root.to_path_buf()); - let canonical_script_path = script_path.canonicalize().map_err(|err| { - anyhow::anyhow!( - "failed to resolve browser script {}: {err}", - script_path.display() - ) - })?; - if !canonical_script_path.starts_with(&canonical_skill_root) { - anyhow::bail!( - "browser script path escapes skill root: {}", - canonical_script_path.display() - ); - } - Ok(canonical_script_path) - } -} - impl BrowserScriptSkillTool { pub fn new( skill_name: &str, @@ -60,14 +28,13 @@ impl BrowserScriptSkillTool { skill_root: &Path, browser_tool: Arc, ) -> anyhow::Result { - let invocation = BrowserScriptInvocation { tool, skill_root }; - invocation.canonical_script_path()?; + let script_path = resolve_browser_script_path(skill_root, &tool.command)?; Ok(Self { tool_name: format!("{}.{}", skill_name, tool.name), tool_description: tool.description.clone(), - tool: tool.clone(), skill_root: skill_root.to_path_buf(), + script_path, args: tool.args.clone(), browser_tool, }) @@ -119,12 +86,15 @@ impl Tool for BrowserScriptSkillTool { } async fn execute(&self, args: Value) -> anyhow::Result { - execute_browser_script_impl( - &self.tool, - &self.skill_root, - self.browser_tool.clone(), - args, - ) + let tool = SkillTool { + name: self.tool_name.clone(), + description: self.tool_description.clone(), + kind: "browser_script".to_string(), + command: self.script_path.to_string_lossy().into_owned(), + args: self.args.clone(), + }; + + execute_browser_script_tool(&tool, &self.skill_root, self.browser_tool.as_ref(), args).await } } @@ -165,20 +135,26 @@ pub fn build_browser_script_skill_tools( pub async fn execute_browser_script_tool( tool: &SkillTool, skill_root: &Path, - browser_tool: Arc, + browser_tool: &dyn BrowserBackend, args: Value, ) -> anyhow::Result { + if tool.kind != "browser_script" { + return Ok(failed_tool_result(format!( + "browser script tool kind must be browser_script, got {}", + tool.kind + ))); + } + execute_browser_script_impl(tool, skill_root, browser_tool, args) } fn execute_browser_script_impl( tool: &SkillTool, skill_root: &Path, - browser_tool: Arc, + browser_tool: &dyn BrowserBackend, args: Value, ) -> anyhow::Result { - let invocation = BrowserScriptInvocation { tool, skill_root }; - let script_path = invocation.canonical_script_path()?; + let script_path = resolve_browser_script_path(skill_root, &tool.command)?; let mut args = match args { Value::Object(args) => args, @@ -263,6 +239,32 @@ fn wrap_browser_script(script_body: &str, args: &Value) -> String { ) } +fn resolve_browser_script_path(skill_root: &Path, command: &str) -> anyhow::Result { + let script_path = PathBuf::from(command); + let script_path = if script_path.is_absolute() { + script_path + } else { + skill_root.join(script_path) + }; + let canonical_skill_root = skill_root + .canonicalize() + .unwrap_or_else(|_| skill_root.to_path_buf()); + let canonical_script_path = script_path.canonicalize().map_err(|err| { + anyhow::anyhow!( + "failed to resolve browser script {}: {err}", + script_path.display() + ) + })?; + if !canonical_script_path.starts_with(&canonical_skill_root) { + anyhow::bail!( + "browser script path escapes skill root: {}", + canonical_script_path.display() + ); + } + + Ok(canonical_script_path) +} + fn stringify_tool_payload(payload: &Value) -> anyhow::Result { Ok(match payload { Value::String(value) => value.clone(), diff --git a/src/compat/direct_skill_runtime.rs b/src/compat/direct_skill_runtime.rs new file mode 100644 index 0000000..cd57ee4 --- /dev/null +++ b/src/compat/direct_skill_runtime.rs @@ -0,0 +1,341 @@ +use std::path::Path; + +use reqwest::Url; +use serde_json::{Map, Value}; +use zeroclaw::skills::load_skills_from_directory; + +use crate::browser::PipeBrowserBackend; +use crate::compat::browser_script_skill_tool::execute_browser_script_tool; +use crate::compat::config_adapter::resolve_skills_dir_from_sgclaw_settings; +use crate::compat::runtime::CompatTaskContext; +use crate::config::SgClawSettings; +use crate::pipe::{BrowserPipeTool, PipeError, Transport}; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct DirectSubmitOutcome { + pub success: bool, + pub summary: String, +} + +pub fn execute_direct_submit_skill( + browser_tool: BrowserPipeTool, + instruction: &str, + task_context: &CompatTaskContext, + workspace_root: &Path, + settings: &SgClawSettings, +) -> Result { + let configured_tool = settings + .direct_submit_skill + .as_deref() + .map(str::trim) + .filter(|value| !value.is_empty()) + .ok_or_else(|| PipeError::Protocol("direct submit skill is not configured".to_string()))?; + let (skill_name, tool_name) = parse_configured_tool_name(configured_tool)?; + let expected_domain = derive_expected_domain(task_context)?; + let period = derive_period(instruction)?; + let skills_dir = resolve_skills_dir_from_sgclaw_settings(workspace_root, settings); + let skills = load_skills_from_directory(&skills_dir, true); + let skill = skills + .iter() + .find(|skill| skill.name == skill_name) + .ok_or_else(|| { + PipeError::Protocol(format!( + "direct submit skill {skill_name} was not found in {}", + skills_dir.display() + )) + })?; + let tool = skill + .tools + .iter() + .find(|tool| tool.name == tool_name) + .ok_or_else(|| { + PipeError::Protocol(format!( + "direct submit tool {configured_tool} was not found" + )) + })?; + + if tool.kind != "browser_script" { + return Err(PipeError::Protocol(format!( + "direct submit tool {configured_tool} must be browser_script, got {}", + tool.kind + ))); + } + + let skill_root = skill + .location + .as_deref() + .and_then(Path::parent) + .ok_or_else(|| { + PipeError::Protocol(format!( + "direct submit skill {skill_name} is missing a resolvable location" + )) + })?; + + let mut args = Map::new(); + args.insert("expected_domain".to_string(), Value::String(expected_domain)); + args.insert("period".to_string(), Value::String(period)); + + let runtime = tokio::runtime::Runtime::new() + .map_err(|err| PipeError::Protocol(format!("failed to create tokio runtime: {err}")))?; + let browser_backend = PipeBrowserBackend::from_inner(browser_tool); + let result = runtime + .block_on(execute_browser_script_tool( + tool, + skill_root, + &browser_backend, + Value::Object(args), + )) + .map_err(|err| PipeError::Protocol(err.to_string()))?; + + if result.success { + Ok(interpret_direct_submit_output(&result.output)) + } else { + Err(PipeError::Protocol( + result + .error + .unwrap_or_else(|| "direct submit skill execution failed".to_string()), + )) + } +} + +fn interpret_direct_submit_output(output: &str) -> DirectSubmitOutcome { + let Some(payload) = serde_json::from_str::(output).ok() else { + return DirectSubmitOutcome { + success: true, + summary: output.to_string(), + }; + }; + + let Some(artifact) = payload.as_object() else { + return DirectSubmitOutcome { + success: true, + summary: output.to_string(), + }; + }; + + if artifact.get("type").and_then(Value::as_str) != Some("report-artifact") { + return DirectSubmitOutcome { + success: true, + summary: output.to_string(), + }; + } + + let status = artifact + .get("status") + .and_then(Value::as_str) + .unwrap_or("ok"); + let success = matches!(status, "ok" | "partial" | "empty"); + let report_name = artifact + .get("report_name") + .and_then(Value::as_str) + .unwrap_or("report-artifact"); + let period = artifact + .get("period") + .and_then(Value::as_str) + .unwrap_or(""); + let detail_rows = count_rows(artifact.get("counts"), artifact.get("rows"), "detail_rows"); + let summary_rows = count_summary_rows(artifact.get("counts"), artifact.get("sections")); + let partial_reasons = artifact + .get("partial_reasons") + .and_then(Value::as_array) + .map(|reasons| { + reasons + .iter() + .filter_map(Value::as_str) + .filter(|value| !value.trim().is_empty()) + .collect::>() + }) + .unwrap_or_default(); + + let mut parts = vec![report_name.to_string()]; + if !period.trim().is_empty() { + parts.push(period.to_string()); + } + parts.push(format!("status={status}")); + parts.push(format!("detail_rows={detail_rows}")); + parts.push(format!("summary_rows={summary_rows}")); + if !partial_reasons.is_empty() { + parts.push(format!("partial_reasons={}", partial_reasons.join(","))); + } + + DirectSubmitOutcome { + success, + summary: parts.join(" "), + } +} + +fn count_rows(counts: Option<&Value>, rows: Option<&Value>, key: &str) -> usize { + counts + .and_then(Value::as_object) + .and_then(|counts| counts.get(key)) + .and_then(Value::as_u64) + .map(|count| count as usize) + .or_else(|| rows.and_then(Value::as_array).map(Vec::len)) + .unwrap_or(0) +} + +fn count_summary_rows(counts: Option<&Value>, sections: Option<&Value>) -> usize { + counts + .and_then(Value::as_object) + .and_then(|counts| counts.get("summary_rows")) + .and_then(Value::as_u64) + .map(|count| count as usize) + .or_else(|| { + sections + .and_then(Value::as_array) + .and_then(|sections| { + sections.iter().find_map(|section| { + section + .as_object() + .and_then(|section| section.get("rows")) + .and_then(Value::as_array) + .map(Vec::len) + }) + }) + }) + .unwrap_or(0) +} + +fn parse_configured_tool_name(configured_tool: &str) -> Result<(&str, &str), PipeError> { + let (skill_name, tool_name) = configured_tool.split_once('.').ok_or_else(|| { + PipeError::Protocol(format!( + "direct submit skill must use skill.tool format, got {configured_tool}" + )) + })?; + let skill_name = skill_name.trim(); + let tool_name = tool_name.trim(); + if skill_name.is_empty() || tool_name.is_empty() { + return Err(PipeError::Protocol(format!( + "direct submit skill must use skill.tool format, got {configured_tool}" + ))); + } + Ok((skill_name, tool_name)) +} + +fn derive_expected_domain(task_context: &CompatTaskContext) -> Result { + let page_url = task_context + .page_url + .as_deref() + .map(str::trim) + .filter(|value| !value.is_empty()) + .ok_or_else(|| { + PipeError::Protocol( + "direct submit skill requires page_url so expected_domain can be derived" + .to_string(), + ) + })?; + + Url::parse(page_url) + .ok() + .and_then(|url| url.host_str().map(|host| host.to_ascii_lowercase())) + .ok_or_else(|| { + PipeError::Protocol(format!( + "direct submit skill could not derive expected_domain from page_url {page_url:?}" + )) + }) +} + +fn derive_period(instruction: &str) -> Result { + let chars = instruction.chars().collect::>(); + if chars.len() < 7 { + return Err(PipeError::Protocol( + "direct submit skill requires an explicit YYYY-MM period in the instruction" + .to_string(), + )); + } + + for start in 0..=chars.len() - 7 { + let candidate = chars[start..start + 7].iter().collect::(); + if is_year_month(&candidate) { + return Ok(candidate); + } + } + + Err(PipeError::Protocol( + "direct submit skill requires an explicit YYYY-MM period in the instruction" + .to_string(), + )) +} + +fn is_year_month(candidate: &str) -> bool { + let bytes = candidate.as_bytes(); + bytes.len() == 7 + && bytes[0..4].iter().all(u8::is_ascii_digit) + && bytes[4] == b'-' + && bytes[5..7].iter().all(u8::is_ascii_digit) + && matches!((bytes[5] - b'0') * 10 + (bytes[6] - b'0'), 1..=12) +} + +#[cfg(test)] +mod tests { + use super::{ + count_rows, count_summary_rows, derive_period, interpret_direct_submit_output, + is_year_month, parse_configured_tool_name, + }; + use serde_json::json; + + #[test] + fn parse_configured_tool_name_requires_skill_and_tool() { + assert_eq!( + parse_configured_tool_name("fault-details-report.collect_fault_details") + .unwrap(), + ("fault-details-report", "collect_fault_details") + ); + assert!(parse_configured_tool_name("fault-details-report").is_err()); + } + + #[test] + fn derive_period_requires_explicit_year_month() { + assert_eq!(derive_period("收集 2026-03 故障明细").unwrap(), "2026-03"); + assert!(derive_period("收集三月故障明细").is_err()); + } + + #[test] + fn year_month_validation_rejects_invalid_month() { + assert!(is_year_month("2026-12")); + assert!(!is_year_month("2026-00")); + assert!(!is_year_month("2026-13")); + } + + #[test] + fn interpret_direct_submit_output_maps_report_artifact_statuses() { + let partial = interpret_direct_submit_output( + &json!({ + "type": "report-artifact", + "report_name": "fault-details-report", + "period": "2026-03", + "counts": { "detail_rows": 1, "summary_rows": 1 }, + "status": "partial", + "partial_reasons": ["report_log_failed"] + }) + .to_string(), + ); + assert!(partial.success); + assert!(partial.summary.contains("status=partial")); + assert!(partial.summary.contains("report_log_failed")); + + let blocked = interpret_direct_submit_output( + &json!({ + "type": "report-artifact", + "report_name": "fault-details-report", + "status": "blocked", + "partial_reasons": ["selected_range_unavailable"] + }) + .to_string(), + ); + assert!(!blocked.success); + assert!(blocked.summary.contains("status=blocked")); + } + + #[test] + fn row_count_helpers_fall_back_to_payload_shapes() { + assert_eq!( + count_rows(None, Some(&json!([{ "qxdbh": "QX-1" }, { "qxdbh": "QX-2" }])), "detail_rows"), + 2 + ); + assert_eq!( + count_summary_rows(None, Some(&json!([{ "name": "summary-sheet", "rows": [{ "index": 1 }] }]))), + 1 + ); + } +} diff --git a/src/compat/mod.rs b/src/compat/mod.rs index 595298a..1701c3c 100644 --- a/src/compat/mod.rs +++ b/src/compat/mod.rs @@ -3,6 +3,7 @@ pub mod browser_script_skill_tool; pub mod browser_tool_adapter; pub mod config_adapter; pub mod cron_adapter; +pub mod direct_skill_runtime; pub mod event_bridge; pub mod memory_adapter; pub mod openxml_office_tool; diff --git a/src/compat/openxml_office_tool.rs b/src/compat/openxml_office_tool.rs index bea1860..92ad3b5 100644 --- a/src/compat/openxml_office_tool.rs +++ b/src/compat/openxml_office_tool.rs @@ -4,12 +4,12 @@ use serde_json::{json, Value}; use std::collections::BTreeMap; use std::collections::BTreeSet; use std::fs; -use std::io::Write; +use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use std::process::Command; use std::time::{SystemTime, UNIX_EPOCH}; use zeroclaw::tools::{Tool, ToolResult}; -use zip::write::SimpleFileOptions; +use zip::write::FileOptions; use zip::{CompressionMethod, ZipWriter}; const OPENXML_OFFICE_TOOL_NAME: &str = "openxml_office"; @@ -131,9 +131,8 @@ impl Tool for OpenXmlOfficeTool { write_payload_json(&payload_path, &normalized_rows)?; write_request_json(&request_path, &template_path, &payload_path, &output_path)?; - let rendered = run_openxml_cli(&request_path).or_else(|_| { - render_locally(&template_path, &payload_path, &output_path) - })?; + let rendered = run_openxml_cli(&request_path) + .or_else(|_| render_locally(&template_path, &payload_path, &output_path))?; let artifact_path = rendered["data"]["artifact"]["path"] .as_str() .map(str::to_string) @@ -163,9 +162,7 @@ fn failed_tool_result(error: String) -> ToolResult { fn create_job_root(workspace_root: &Path) -> anyhow::Result { let nanos = SystemTime::now().duration_since(UNIX_EPOCH)?.as_nanos(); - let path = workspace_root - .join(".sgclaw-openxml") - .join(format!("{nanos}")); + let path = workspace_root.join(".sgclaw-openxml").join(format!("{nanos}")); fs::create_dir_all(&path)?; Ok(path) } @@ -223,10 +220,7 @@ fn canonicalize_column_name(value: &str) -> Option<&'static str> { } fn reorder_row(row: &[Value], column_order: &[usize]) -> Vec { - column_order - .iter() - .map(|index| row[*index].clone()) - .collect() + column_order.iter().map(|index| row[*index].clone()).collect() } fn write_payload_json(path: &Path, rows: &[Vec]) -> anyhow::Result<()> { @@ -285,18 +279,8 @@ fn run_openxml_cli(request_path: &Path) -> anyhow::Result { .parent() .map(|path| path.join("openxml_cli").join("Cargo.toml")) .ok_or_else(|| anyhow::anyhow!("failed to resolve openxml_cli manifest path"))?; - let binary_name = if cfg!(windows) { - "openxml-cli.exe" - } else { - "openxml-cli" - }; - let binary_path = manifest_path - .parent() - .map(|path| path.join("target").join("debug").join(binary_name)) - .ok_or_else(|| anyhow::anyhow!("failed to resolve openxml_cli binary path"))?; - - let output = if binary_path.exists() { - Command::new(&binary_path) + let output = if let Some(binary_path) = resolve_openxml_cli_binary(&manifest_path) { + Command::new(binary_path) .args([ "template", "render", @@ -358,14 +342,11 @@ fn worksheet_xml_from_xlsx(path: &Path) -> anyhow::Result { let mut archive = zip::ZipArchive::new(file)?; let mut sheet = archive.by_name("xl/worksheets/sheet1.xml")?; let mut xml = String::new(); - std::io::Read::read_to_string(&mut sheet, &mut xml)?; + sheet.read_to_string(&mut xml)?; Ok(xml) } -fn render_template_xml( - template: &str, - variables: &serde_json::Map, -) -> String { +fn render_template_xml(template: &str, variables: &serde_json::Map) -> String { let mut rendered = template.to_string(); for (key, value) in variables { let placeholder = format!("{{{{{key}}}}}"); @@ -392,7 +373,7 @@ fn write_rendered_xlsx( let mut archive = zip::ZipArchive::new(input)?; let output = fs::File::create(output_path)?; let mut writer = ZipWriter::new(output); - let options = SimpleFileOptions::default().compression_method(CompressionMethod::Stored); + let options = FileOptions::default().compression_method(CompressionMethod::Stored); for index in 0..archive.len() { let mut entry = archive.by_index(index)?; @@ -416,6 +397,34 @@ fn xml_escape(value: &str) -> String { .replace('>', ">") } +fn resolve_openxml_cli_binary(manifest_path: &Path) -> Option { + let cli_dir = manifest_path.parent()?; + openxml_cli_candidate_paths(cli_dir) + .into_iter() + .find(|path| path.exists()) +} + +fn openxml_cli_candidate_paths(cli_dir: &Path) -> Vec { + let mut paths = Vec::new(); + for profile in ["release", "debug"] { + paths.push( + cli_dir + .join("target") + .join(profile) + .join(openxml_cli_binary_name()), + ); + } + paths +} + +fn openxml_cli_binary_name() -> &'static str { + if cfg!(windows) { + "openxml-cli.exe" + } else { + "openxml-cli" + } +} + fn value_to_string(value: &Value) -> String { match value { Value::String(text) => text.clone(), @@ -427,34 +436,39 @@ fn value_to_string(value: &Value) -> String { } fn write_hotlist_template(path: &Path, row_count: usize) -> anyhow::Result<()> { - write_zip_file(&path, &[Content { - path: "[Content_Types].xml", - body: content_types_xml().to_string(), - }, - Content { - path: "_rels/.rels", - body: root_rels_xml().to_string(), - }, - Content { - path: "docProps/app.xml", - body: app_xml().to_string(), - }, - Content { - path: "docProps/core.xml", - body: core_xml().to_string(), - }, - Content { - path: "xl/workbook.xml", - body: workbook_xml().to_string(), - }, - Content { - path: "xl/_rels/workbook.xml.rels", - body: workbook_rels_xml().to_string(), - }, - Content { - path: "xl/worksheets/sheet1.xml", - body: worksheet_xml(row_count), - }])?; + write_zip_file( + &path, + &[ + Content { + path: "[Content_Types].xml", + body: content_types_xml().to_string(), + }, + Content { + path: "_rels/.rels", + body: root_rels_xml().to_string(), + }, + Content { + path: "docProps/app.xml", + body: app_xml().to_string(), + }, + Content { + path: "docProps/core.xml", + body: core_xml().to_string(), + }, + Content { + path: "xl/workbook.xml", + body: workbook_xml().to_string(), + }, + Content { + path: "xl/_rels/workbook.xml.rels", + body: workbook_rels_xml().to_string(), + }, + Content { + path: "xl/worksheets/sheet1.xml", + body: worksheet_xml(row_count), + }, + ], + )?; Ok(()) } @@ -473,7 +487,7 @@ fn write_zip_file(path: &Path, entries: &[Content<'_>]) -> anyhow::Result<()> { let file = fs::File::create(path)?; let mut zip = ZipWriter::new(file); - let options = SimpleFileOptions::default().compression_method(CompressionMethod::Stored); + let options = FileOptions::default().compression_method(CompressionMethod::Stored); for entry in entries { zip.start_file(entry.path, options)?; zip.write_all(entry.body.as_bytes())?; @@ -482,6 +496,42 @@ fn write_zip_file(path: &Path, entries: &[Content<'_>]) -> anyhow::Result<()> { Ok(()) } +#[cfg(test)] +mod tests { + use super::{openxml_cli_binary_name, openxml_cli_candidate_paths, zip_entry_name}; + use std::path::Path; + + #[test] + fn openxml_cli_candidates_prefer_release_before_debug() { + let paths = openxml_cli_candidate_paths(Path::new("E:\\coding\\codex\\openxml_cli")); + assert_eq!(paths.len(), 2); + assert_eq!( + paths[0], + Path::new("E:\\coding\\codex\\openxml_cli") + .join("target") + .join("release") + .join(openxml_cli_binary_name()) + ); + assert_eq!( + paths[1], + Path::new("E:\\coding\\codex\\openxml_cli") + .join("target") + .join("debug") + .join(openxml_cli_binary_name()) + ); + } + + #[test] + fn zip_entry_name_normalizes_windows_separators() { + let rel = Path::new("xl\\worksheets\\sheet1.xml"); + assert_eq!(zip_entry_name(rel), "xl/worksheets/sheet1.xml"); + } +} + +fn zip_entry_name(path: &Path) -> String { + path.to_string_lossy().replace('\\', "/") +} + fn worksheet_xml(row_count: usize) -> String { let mut rows = Vec::new(); rows.push( diff --git a/src/compat/orchestration.rs b/src/compat/orchestration.rs index 88675d7..0f2474b 100644 --- a/src/compat/orchestration.rs +++ b/src/compat/orchestration.rs @@ -2,6 +2,7 @@ use std::path::Path; use std::sync::Arc; use crate::browser::BrowserBackend; +use crate::compat::config_adapter::resolve_skills_dir_from_sgclaw_settings; use crate::compat::runtime::CompatTaskContext; use crate::config::SgClawSettings; use crate::pipe::{BrowserPipeTool, PipeError, Transport}; @@ -36,6 +37,7 @@ pub fn execute_task_with_browser_backend( workspace_root: &Path, settings: &SgClawSettings, ) -> Result { + let skills_dir = resolve_skills_dir_from_sgclaw_settings(workspace_root, settings); let route = crate::compat::workflow_executor::detect_route( instruction, task_context.page_url.as_deref(), @@ -47,6 +49,7 @@ pub fn execute_task_with_browser_backend( transport, browser_backend.clone(), workspace_root, + &skills_dir, instruction, task_context, route, @@ -73,6 +76,7 @@ pub fn execute_task_with_browser_backend( transport, browser_backend, workspace_root, + &skills_dir, instruction, task_context, route, @@ -84,6 +88,7 @@ pub fn execute_task_with_browser_backend( transport, browser_backend, workspace_root, + &skills_dir, instruction, task_context, route, @@ -101,6 +106,7 @@ pub fn execute_task_with_sgclaw_settings( workspace_root: &Path, settings: &SgClawSettings, ) -> Result { + let skills_dir = resolve_skills_dir_from_sgclaw_settings(workspace_root, settings); let route = crate::compat::workflow_executor::detect_route( instruction, task_context.page_url.as_deref(), @@ -112,6 +118,7 @@ pub fn execute_task_with_sgclaw_settings( transport, &browser_tool, workspace_root, + &skills_dir, instruction, task_context, route, @@ -138,6 +145,7 @@ pub fn execute_task_with_sgclaw_settings( transport, &browser_tool, workspace_root, + &skills_dir, instruction, task_context, route, @@ -149,6 +157,7 @@ pub fn execute_task_with_sgclaw_settings( transport, &browser_tool, workspace_root, + &skills_dir, instruction, task_context, route, diff --git a/src/compat/screen_html_export_tool.rs b/src/compat/screen_html_export_tool.rs index e4a54c3..5107db4 100644 --- a/src/compat/screen_html_export_tool.rs +++ b/src/compat/screen_html_export_tool.rs @@ -12,10 +12,10 @@ const SCREEN_HTML_EXPORT_TOOL_NAME: &str = "screen_html_export"; const DEFAULT_SCREEN_TITLE: &str = "知乎热榜主题分类分析大屏"; const TEMPLATE: &str = include_str!(concat!( env!("CARGO_MANIFEST_DIR"), - "/../skill_lib/skills/zhihu-hotlist-screen/assets/zhihu-hotlist-echarts.html" + "/resources/zhihu-hotlist-echarts.html" )); const PAYLOAD_START_MARKER: &str = " const defaultPayload = "; -const PAYLOAD_END_MARKER: &str = "\n\n const themeMeta = {"; +const PAYLOAD_END_MARKER: &str = "const themeMeta = {"; pub struct ScreenHtmlExportTool { workspace_root: PathBuf, diff --git a/src/compat/workflow_executor.rs b/src/compat/workflow_executor.rs index 5675f56..aca5b4e 100644 --- a/src/compat/workflow_executor.rs +++ b/src/compat/workflow_executor.rs @@ -132,6 +132,7 @@ pub fn execute_route_with_browser_backend( transport: &dyn crate::agent::AgentEventSink, browser_backend: Arc, workspace_root: &Path, + skills_dir: &Path, instruction: &str, task_context: &CompatTaskContext, route: WorkflowRoute, @@ -140,7 +141,13 @@ pub fn execute_route_with_browser_backend( match route { WorkflowRoute::ZhihuHotlistExportXlsx | WorkflowRoute::ZhihuHotlistScreen => { let top_n = extract_top_n(instruction); - let items = collect_hotlist_items(transport, browser_backend.as_ref(), top_n, task_context)?; + let items = collect_hotlist_items( + transport, + browser_backend.as_ref(), + skills_dir, + top_n, + task_context, + )?; if items.is_empty() { return Err(PipeError::Protocol( "知乎热榜采集失败:未能从页面文本中解析到热榜条目".to_string(), @@ -155,11 +162,12 @@ pub fn execute_route_with_browser_backend( } } WorkflowRoute::ZhihuArticleEntry => { - execute_zhihu_article_entry_route(transport, browser_backend.as_ref()) + execute_zhihu_article_entry_route(transport, browser_backend.as_ref(), skills_dir) } WorkflowRoute::ZhihuArticleDraft => execute_zhihu_article_route( transport, browser_backend.as_ref(), + skills_dir, instruction, task_context, false, @@ -169,6 +177,7 @@ pub fn execute_route_with_browser_backend( WorkflowRoute::ZhihuArticlePublish => execute_zhihu_article_route( transport, browser_backend.as_ref(), + skills_dir, instruction, task_context, true, @@ -179,6 +188,7 @@ pub fn execute_route_with_browser_backend( execute_generated_zhihu_article_publish_route( transport, browser_backend.as_ref(), + skills_dir, instruction, task_context, workspace_root, @@ -192,6 +202,7 @@ pub fn execute_route( transport: &T, browser_tool: &BrowserPipeTool, workspace_root: &Path, + skills_dir: &Path, instruction: &str, task_context: &CompatTaskContext, route: WorkflowRoute, @@ -203,6 +214,7 @@ pub fn execute_route( transport, browser_backend, workspace_root, + skills_dir, instruction, task_context, route, @@ -213,10 +225,13 @@ pub fn execute_route( fn collect_hotlist_items( transport: &dyn crate::agent::AgentEventSink, browser_tool: &dyn BrowserBackend, + skills_dir: &Path, top_n: usize, task_context: &CompatTaskContext, ) -> Result, PipeError> { - if let Some(items) = ensure_hotlist_page_ready(transport, browser_tool, top_n, task_context)? { + if let Some(items) = + ensure_hotlist_page_ready(transport, browser_tool, skills_dir, top_n, task_context)? + { return Ok(items); } transport.send(&AgentMessage::LogEntry { @@ -225,7 +240,7 @@ fn collect_hotlist_items( })?; let response = browser_tool.invoke( Action::Eval, - json!({ "script": load_hotlist_extractor_script(top_n)? }), + json!({ "script": load_hotlist_extractor_script(skills_dir, top_n)? }), ZHIHU_DOMAIN, )?; if !response.success { @@ -246,6 +261,7 @@ fn collect_hotlist_items( fn ensure_hotlist_page_ready( transport: &dyn crate::agent::AgentEventSink, browser_tool: &dyn BrowserBackend, + skills_dir: &Path, top_n: usize, task_context: &CompatTaskContext, ) -> Result>, PipeError> { @@ -268,7 +284,7 @@ fn ensure_hotlist_page_ready( // Best-effort wait for content to appear; ignore the boolean result – // we always follow up with the probe. let _ = poll_for_hotlist_readiness(browser_tool); - if let Some(items) = probe_hotlist_extractor(transport, browser_tool, top_n)? { + if let Some(items) = probe_hotlist_extractor(transport, browser_tool, skills_dir, top_n)? { return Ok(Some(items)); } } @@ -277,7 +293,7 @@ fn ensure_hotlist_page_ready( for attempt in 0..2 { navigate_hotlist_page(transport, browser_tool)?; let _ = poll_for_hotlist_readiness(browser_tool); - if let Some(items) = probe_hotlist_extractor(transport, browser_tool, top_n)? { + if let Some(items) = probe_hotlist_extractor(transport, browser_tool, skills_dir, top_n)? { return Ok(Some(items)); } last_error = Some(format!( @@ -304,6 +320,7 @@ fn ensure_hotlist_page_ready( /// reports "editor_unavailable". fn poll_for_editor_readiness( browser_tool: &dyn BrowserBackend, + skills_dir: &Path, desired_mode: &str, ) -> Result { let args = json!({ "desired_mode": desired_mode }); @@ -312,6 +329,7 @@ fn poll_for_editor_readiness( for attempt in 0..EDITOR_READY_POLL_ATTEMPTS { match execute_browser_skill_script( browser_tool, + skills_dir, "zhihu-write", "prepare_article_editor.js", args.clone(), @@ -325,9 +343,7 @@ fn poll_for_editor_readiness( last_state = Some(state); } Err(PipeError::PipeClosed) => return Err(PipeError::PipeClosed), - Err(_) => { - // Script may fail while the page is still navigating; tolerate. - } + Err(_) => {} } if attempt + 1 < EDITOR_READY_POLL_ATTEMPTS { @@ -335,12 +351,11 @@ fn poll_for_editor_readiness( } } - // Return the last observed state so the caller can surface the - // "editor_unavailable" message; or make one final attempt. match last_state { Some(state) => Ok(state), None => execute_browser_skill_script( browser_tool, + skills_dir, "zhihu-write", "prepare_article_editor.js", args, @@ -352,6 +367,7 @@ fn poll_for_editor_readiness( fn probe_hotlist_extractor( transport: &dyn crate::agent::AgentEventSink, browser_tool: &dyn BrowserBackend, + skills_dir: &Path, top_n: usize, ) -> Result>, PipeError> { transport.send(&AgentMessage::LogEntry { @@ -360,7 +376,7 @@ fn probe_hotlist_extractor( })?; let response = browser_tool.invoke( Action::Eval, - json!({ "script": load_hotlist_extractor_script(top_n)? }), + json!({ "script": load_hotlist_extractor_script(skills_dir, top_n)? }), ZHIHU_DOMAIN, )?; if !response.success { @@ -535,6 +551,7 @@ pub fn finalize_screen_export( fn execute_zhihu_article_route( transport: &dyn crate::agent::AgentEventSink, browser_tool: &dyn BrowserBackend, + skills_dir: &Path, instruction: &str, task_context: &CompatTaskContext, publish_mode: bool, @@ -559,6 +576,7 @@ fn execute_zhihu_article_route( })?; let creator_state = execute_browser_skill_script( browser_tool, + skills_dir, "zhihu-navigate", "open_creator_entry.js", json!({ "desired_target": "article_editor" }), @@ -582,6 +600,7 @@ fn execute_zhihu_article_route( })?; let editor_state = poll_for_editor_readiness( browser_tool, + skills_dir, if publish_mode { "publish" } else { "draft" }, )?; if is_login_required_payload(&editor_state) { @@ -600,10 +619,11 @@ fn execute_zhihu_article_route( message: "call zhihu-write.fill_article_draft".to_string(), })?; let fill_result = if browser_tool.supports_live_input() { - execute_zhihu_fill_via_live_input(browser_tool, &article, publish_mode)? + execute_zhihu_fill_via_live_input(browser_tool, skills_dir, &article, publish_mode)? } else { execute_browser_skill_script( browser_tool, + skills_dir, "zhihu-write", "fill_article_draft.js", json!({ @@ -641,6 +661,7 @@ fn execute_zhihu_article_route( fn execute_generated_zhihu_article_publish_route( transport: &dyn crate::agent::AgentEventSink, browser_tool: &dyn BrowserBackend, + skills_dir: &Path, instruction: &str, task_context: &CompatTaskContext, workspace_root: &Path, @@ -661,6 +682,7 @@ fn execute_generated_zhihu_article_publish_route( execute_zhihu_article_route( transport, browser_tool, + skills_dir, instruction, task_context, true, @@ -701,6 +723,7 @@ fn task_requests_zhihu_generated_article_publish( fn execute_zhihu_article_entry_route( transport: &dyn crate::agent::AgentEventSink, browser_tool: &dyn BrowserBackend, + skills_dir: &Path, ) -> Result { navigate_zhihu_page(transport, browser_tool, ZHIHU_CREATOR_URL)?; transport.send(&AgentMessage::LogEntry { @@ -709,6 +732,7 @@ fn execute_zhihu_article_entry_route( })?; let creator_state = execute_browser_skill_script( browser_tool, + skills_dir, "zhihu-navigate", "open_creator_entry.js", json!({ "desired_target": "article_editor" }), @@ -730,10 +754,7 @@ fn execute_zhihu_article_entry_route( level: "info".to_string(), message: "call zhihu-write.prepare_article_editor".to_string(), })?; - let editor_state = poll_for_editor_readiness( - browser_tool, - "draft", - )?; + let editor_state = poll_for_editor_readiness(browser_tool, skills_dir, "draft")?; if is_login_required_payload(&editor_state) { return Ok(build_login_block_message(payload_current_url( &editor_state, @@ -748,8 +769,9 @@ fn execute_zhihu_article_entry_route( ))) } -fn load_hotlist_extractor_script(top_n: usize) -> Result { +fn load_hotlist_extractor_script(skills_dir: &Path, top_n: usize) -> Result { load_browser_skill_script( + skills_dir, "zhihu-hotlist", "extract_hotlist.js", json!({ "top_n": top_n.to_string() }), @@ -834,12 +856,14 @@ fn navigate_zhihu_page( fn execute_browser_skill_script( browser_tool: &dyn BrowserBackend, + skills_dir: &Path, skill_name: &str, script_name: &str, args: Value, expected_domain: &str, ) -> Result { - let wrapped_script = load_browser_skill_script(skill_name, script_name, args)?; + let wrapped_script = + load_browser_skill_script(skills_dir, skill_name, script_name, args)?; let response = browser_tool.invoke( Action::Eval, json!({ "script": wrapped_script }), @@ -866,6 +890,7 @@ fn live_input_probe_script(selector_candidates: &[&str]) -> String { fn execute_zhihu_fill_via_live_input( browser_tool: &dyn BrowserBackend, + skills_dir: &Path, article: &ArticleDraft, publish_mode: bool, ) -> Result { @@ -1003,6 +1028,7 @@ return JSON.stringify({{status:'ok',chunks:chunks.length}}); // enable the button after the content fill updates the editor state. let fill_result = execute_browser_skill_script( browser_tool, + skills_dir, "zhihu-write", "fill_article_draft.js", json!({ @@ -1107,6 +1133,10 @@ mod tests { .unwrap() } + fn test_skills_dir() -> &'static Path { + Path::new("D:/data/ideaSpace/rust/sgClaw/claw/claw/skills") + } + struct MockWorkflowTransport { sent: Mutex>, responses: Mutex>, @@ -1266,6 +1296,7 @@ mod tests { transport.as_ref(), backend.clone(), Path::new("."), + test_skills_dir(), "打开知乎写文章页面", &CompatTaskContext::default(), WorkflowRoute::ZhihuArticleEntry, @@ -1286,6 +1317,7 @@ mod tests { Action::Eval, json!({ "script": load_browser_skill_script( + test_skills_dir(), "zhihu-navigate", "open_creator_entry.js", json!({ "desired_target": "article_editor" }) @@ -1298,6 +1330,7 @@ mod tests { Action::Eval, json!({ "script": load_browser_skill_script( + test_skills_dir(), "zhihu-write", "prepare_article_editor.js", json!({ "desired_mode": "draft" }) @@ -1370,6 +1403,7 @@ mod tests { transport.as_ref(), backend.clone(), Path::new("."), + test_skills_dir(), "打开知乎写文章页面", &CompatTaskContext::default(), WorkflowRoute::ZhihuArticleEntry, @@ -1390,6 +1424,7 @@ mod tests { Action::Eval, json!({ "script": load_browser_skill_script( + test_skills_dir(), "zhihu-navigate", "open_creator_entry.js", json!({ "desired_target": "article_editor" }) @@ -1407,6 +1442,7 @@ mod tests { Action::Eval, json!({ "script": load_browser_skill_script( + test_skills_dir(), "zhihu-write", "prepare_article_editor.js", json!({ "desired_mode": "draft" }) @@ -1495,6 +1531,7 @@ mod tests { let summary = execute_zhihu_article_route( transport.as_ref(), backend.as_ref(), + test_skills_dir(), "标题:测试标题\n正文:第一段内容", &CompatTaskContext::default(), false, @@ -1625,6 +1662,7 @@ mod tests { let summary = execute_zhihu_article_route( transport.as_ref(), backend.as_ref(), + test_skills_dir(), "标题:测试标题\n正文:第一段内容", &CompatTaskContext::default(), false, @@ -1655,6 +1693,7 @@ mod tests { assert_eq!(invocations[8].0, Action::Eval); assert_eq!(invocations[8].1["script"], json!( load_browser_skill_script( + test_skills_dir(), "zhihu-write", "fill_article_draft.js", json!({ @@ -1753,6 +1792,7 @@ mod tests { let _ = execute_zhihu_article_route( transport.as_ref(), backend.as_ref(), + test_skills_dir(), "标题:测试标题\n正文:第一段内容\n第二段内容", &CompatTaskContext::default(), false, @@ -1771,6 +1811,7 @@ mod tests { #[test] fn zhihu_fill_script_checks_live_input_before_dom_fill_fallback() { let script = load_browser_skill_script( + test_skills_dir(), "zhihu-write", "fill_article_draft.js", json!({ @@ -1805,6 +1846,7 @@ mod tests { #[test] fn zhihu_fill_script_live_input_uses_editor_content_instead_of_whole_page_text() { let script = load_browser_skill_script( + test_skills_dir(), "zhihu-write", "fill_article_draft.js", json!({ @@ -1897,6 +1939,7 @@ mod tests { transport.as_ref(), backend.clone(), Path::new("."), + test_skills_dir(), "打开知乎写文章页面", &CompatTaskContext::default(), WorkflowRoute::ZhihuArticleEntry, @@ -1917,6 +1960,7 @@ mod tests { Action::Eval, json!({ "script": load_browser_skill_script( + test_skills_dir(), "zhihu-navigate", "open_creator_entry.js", json!({ "desired_target": "article_editor" }) @@ -1934,6 +1978,7 @@ mod tests { Action::Eval, json!({ "script": load_browser_skill_script( + test_skills_dir(), "zhihu-write", "prepare_article_editor.js", json!({ "desired_mode": "draft" }) @@ -1975,7 +2020,13 @@ mod tests { }; let browser_backend = PipeBrowserBackend::from_inner(browser_tool); - let items = collect_hotlist_items(transport.as_ref(), &browser_backend, 10, &task_context) + let items = collect_hotlist_items( + transport.as_ref(), + &browser_backend, + test_skills_dir(), + 10, + &task_context, + ) .expect("hotlist collection should succeed"); assert_eq!(items.len(), 2); @@ -2029,7 +2080,13 @@ mod tests { }; let browser_backend = PipeBrowserBackend::from_inner(browser_tool); - let items = collect_hotlist_items(transport.as_ref(), &browser_backend, 10, &task_context) + let items = collect_hotlist_items( + transport.as_ref(), + &browser_backend, + test_skills_dir(), + 10, + &task_context, + ) .expect("hotlist collection should succeed after readiness polling"); assert_eq!(items.len(), 1); @@ -2098,7 +2155,13 @@ mod tests { }; let browser_backend = PipeBrowserBackend::from_inner(browser_tool); - let items = collect_hotlist_items(transport.as_ref(), &browser_backend, 10, &task_context) + let items = collect_hotlist_items( + transport.as_ref(), + &browser_backend, + test_skills_dir(), + 10, + &task_context, + ) .expect("hotlist collection should succeed after one navigation retry"); assert_eq!(items.len(), 1); @@ -2165,7 +2228,13 @@ mod tests { }; let browser_backend = PipeBrowserBackend::from_inner(browser_tool); - let items = collect_hotlist_items(transport.as_ref(), &browser_backend, 10, &task_context) + let items = collect_hotlist_items( + transport.as_ref(), + &browser_backend, + test_skills_dir(), + 10, + &task_context, + ) .expect("hotlist collection should succeed via extractor probe"); assert_eq!(items.len(), 1); @@ -2184,15 +2253,12 @@ mod tests { } fn load_browser_skill_script( + skills_dir: &Path, skill_name: &str, script_name: &str, args: Value, ) -> Result { - let script_path = Path::new(env!("CARGO_MANIFEST_DIR")) - .parent() - .unwrap_or_else(|| Path::new(env!("CARGO_MANIFEST_DIR"))) - .join("skill_lib") - .join("skills") + let script_path = skills_dir .join(skill_name) .join("scripts") .join(script_name); diff --git a/src/config/settings.rs b/src/config/settings.rs index dc60e58..5b61080 100644 --- a/src/config/settings.rs +++ b/src/config/settings.rs @@ -10,6 +10,10 @@ pub use zeroclaw::config::SkillsPromptInjectionMode as SkillsPromptMode; const DEFAULT_DEEPSEEK_BASE_URL: &str = "https://api.deepseek.com"; const DEFAULT_DEEPSEEK_MODEL: &str = "deepseek-chat"; const DEFAULT_PROVIDER_ID: &str = "deepseek"; +const DIRECT_SUBMIT_PROVIDER_ID: &str = "direct-submit"; +const DIRECT_SUBMIT_BASE_URL: &str = "http://127.0.0.1/direct-submit"; +const DIRECT_SUBMIT_MODEL: &str = "direct-submit-placeholder-model"; +const DIRECT_SUBMIT_API_KEY: &str = "direct-submit-placeholder-key"; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum PlannerMode { @@ -66,6 +70,19 @@ impl ProviderSettings { }) } + fn direct_submit_placeholder() -> Self { + Self { + id: DIRECT_SUBMIT_PROVIDER_ID.to_string(), + provider: DIRECT_SUBMIT_PROVIDER_ID.to_string(), + api_key: DIRECT_SUBMIT_API_KEY.to_string(), + base_url: Some(DIRECT_SUBMIT_BASE_URL.to_string()), + model: DIRECT_SUBMIT_MODEL.to_string(), + api_path: None, + wire_api: None, + requires_openai_auth: false, + } + } + fn from_raw(raw: RawProviderSettings) -> Result { let id = raw.id.trim().to_string(); if id.is_empty() { @@ -125,6 +142,7 @@ pub struct SgClawSettings { pub provider_base_url: String, pub provider_model: String, pub skills_dir: Option, + pub direct_submit_skill: Option, pub skills_prompt_mode: SkillsPromptMode, pub runtime_profile: RuntimeProfile, pub planner_mode: PlannerMode, @@ -165,6 +183,7 @@ impl SgClawSettings { None, None, None, + None, Vec::new(), None, None, @@ -202,6 +221,7 @@ impl SgClawSettings { None, None, None, + None, Vec::new(), None, None, @@ -284,6 +304,7 @@ impl SgClawSettings { config.base_url, config.model, resolve_configured_skills_dir(config.skills_dir, config_dir), + config.direct_submit_skill, skills_prompt_mode, runtime_profile, planner_mode, @@ -302,6 +323,7 @@ impl SgClawSettings { base_url: String, model: String, skills_dir: Option, + direct_submit_skill: Option, skills_prompt_mode: Option, runtime_profile: Option, planner_mode: Option, @@ -312,10 +334,15 @@ impl SgClawSettings { browser_ws_url: Option, service_ws_listen_addr: Option, ) -> Result { + let direct_submit_skill = normalize_direct_submit_skill(direct_submit_skill)?; let providers = if providers.is_empty() { - vec![ProviderSettings::from_legacy_deepseek( - api_key, base_url, model, - )?] + if direct_submit_skill.is_some() { + vec![ProviderSettings::direct_submit_placeholder()] + } else { + vec![ProviderSettings::from_legacy_deepseek( + api_key, base_url, model, + )?] + } } else { providers }; @@ -339,6 +366,7 @@ impl SgClawSettings { .unwrap_or_default(), provider_model: active_provider_settings.model.clone(), skills_dir, + direct_submit_skill, skills_prompt_mode: skills_prompt_mode.unwrap_or(SkillsPromptMode::Compact), runtime_profile: runtime_profile.unwrap_or(RuntimeProfile::BrowserAttached), planner_mode: planner_mode.unwrap_or(PlannerMode::ZeroclawPlanFirst), @@ -452,6 +480,29 @@ fn normalize_optional_value(raw: Option) -> Option { .filter(|value| !value.is_empty()) } +fn normalize_direct_submit_skill(raw: Option) -> Result, ConfigError> { + let value = normalize_optional_value(raw); + let Some(value) = value.as_deref() else { + return Ok(None); + }; + + let Some((skill_name, tool_name)) = value.split_once('.') else { + return Err(ConfigError::InvalidValue( + "directSubmitSkill", + format!("must use skill.tool format, got {value}"), + )); + }; + + if skill_name.trim().is_empty() || tool_name.trim().is_empty() { + return Err(ConfigError::InvalidValue( + "directSubmitSkill", + format!("must use skill.tool format, got {value}"), + )); + } + + Ok(Some(value.to_string())) +} + fn normalize_base_url(raw: String) -> String { let trimmed = raw.trim(); if trimmed.is_empty() { @@ -488,6 +539,8 @@ struct RawSgClawSettings { model: String, #[serde(rename = "skillsDir", alias = "skills_dir", default)] skills_dir: Option, + #[serde(rename = "directSubmitSkill", alias = "direct_submit_skill", default)] + direct_submit_skill: Option, #[serde(rename = "skillsPromptMode", alias = "skills_prompt_mode", default)] skills_prompt_mode: Option, #[serde(rename = "runtimeProfile", alias = "runtime_profile", default)] diff --git a/tests/agent_runtime_test.rs b/tests/agent_runtime_test.rs index 6852b34..9c6f0cd 100644 --- a/tests/agent_runtime_test.rs +++ b/tests/agent_runtime_test.rs @@ -7,15 +7,18 @@ use std::sync::{Arc, Mutex, OnceLock}; use std::thread; use std::time::Duration; -use common::MockTransport; use serde_json::{json, Value}; +use uuid::Uuid; + +use common::MockTransport; use sgclaw::agent::{ handle_browser_message, handle_browser_message_with_context, AgentRuntimeContext, }; -use sgclaw::pipe::{AgentMessage, BrowserMessage, BrowserPipeTool, Timing}; +use sgclaw::compat::runtime::CompatTaskContext; +use sgclaw::config::SgClawSettings; +use sgclaw::pipe::{Action, AgentMessage, BrowserMessage, BrowserPipeTool, Timing}; use sgclaw::security::MacPolicy; -use tungstenite::{accept, Message}; -use uuid::Uuid; +use tungstenite::{accept, error::ProtocolError, Message}; fn env_lock() -> &'static Mutex<()> { static LOCK: OnceLock> = OnceLock::new(); @@ -34,6 +37,7 @@ fn write_config( base_url: &str, model: &str, skills_dir: Option<&str>, + browser_ws_url: Option<&str>, ) -> PathBuf { let config_path = root.join("sgclaw_config.json"); let mut payload = json!({ @@ -45,6 +49,9 @@ fn write_config( if let Some(skills_dir) = skills_dir { payload["skillsDir"] = json!(skills_dir); } + if let Some(browser_ws_url) = browser_ws_url { + payload["browserWsUrl"] = json!(browser_ws_url); + } fs::write(&config_path, serde_json::to_string_pretty(&payload).unwrap()).unwrap(); config_path } @@ -80,7 +87,10 @@ fn start_browser_ws_server() -> (String, Arc>>, thread::JoinHa let message = match socket.read() { Ok(message) => message, Err(tungstenite::Error::ConnectionClosed) - | Err(tungstenite::Error::AlreadyClosed) => break, + | Err(tungstenite::Error::AlreadyClosed) + | Err(tungstenite::Error::Protocol( + ProtocolError::ResetWithoutClosingHandshake, + )) => break, Err(err) => panic!("browser ws test server read failed: {err}"), }; let payload = match message { @@ -155,20 +165,567 @@ fn start_browser_ws_server() -> (String, Arc>>, thread::JoinHa (format!("ws://{address}"), frames, handle) } +#[test] +fn browser_ws_server_treats_reset_without_closing_handshake_as_disconnect() { + let err = tungstenite::Error::Protocol(ProtocolError::ResetWithoutClosingHandshake); + assert!(matches!( + err, + tungstenite::Error::Protocol(ProtocolError::ResetWithoutClosingHandshake) + )); +} + +fn provider_path_test_policy() -> MacPolicy { + policy_for_domains(&["www.baidu.com"]) +} + +fn direct_runtime_test_policy() -> MacPolicy { + policy_for_domains(&["95598.sgcc.com.cn"]) +} + fn test_policy() -> MacPolicy { + policy_for_domains(&["www.zhihu.com"]) +} + +fn policy_for_domains(domains: &[&str]) -> MacPolicy { MacPolicy::from_json_str( - r#"{ + &serde_json::json!({ "version": "1.0", - "domains": { "allowed": ["www.baidu.com", "www.zhihu.com"] }, + "domains": { "allowed": domains }, "pipe_actions": { "allowed": ["click", "type", "navigate", "getText", "eval"], "blocked": [] } - }"#, + }) + .to_string(), ) .unwrap() } +fn build_direct_runtime_skill_root() -> PathBuf { + let root = std::env::temp_dir().join(format!( + "sgclaw-agent-runtime-skill-root-{}", + Uuid::new_v4() + )); + let skill_dir = root.join("fault-details-report"); + let script_dir = skill_dir.join("scripts"); + + fs::create_dir_all(&script_dir).unwrap(); + fs::write( + skill_dir.join("SKILL.toml"), + r#" +[skill] +name = "fault-details-report" +description = "Collect 95598 fault detail data via browser eval." +version = "0.1.0" + +[[tools]] +name = "collect_fault_details" +description = "Collect structured fault detail rows for a specific period." +kind = "browser_script" +command = "scripts/collect_fault_details.js" + +[tools.args] +period = "YYYY-MM period to collect." +"#, + ) + .unwrap(); + fs::write( + script_dir.join("collect_fault_details.js"), + r#" +return { + fault_type: "outage", + observed_at: `${args.period}-15 09:00`, + affected_scope: "line-7", + expected_domain: args.expected_domain, + artifact_payload: "report artifact payload" +}; +"#, + ) + .unwrap(); + + root +} + +fn write_direct_submit_config(workspace_root: &std::path::Path, skill_root: &std::path::Path) -> PathBuf { + let config_path = workspace_root.join("sgclaw_config.json"); + fs::write( + &config_path, + serde_json::json!({ + "providers": [], + "skillsDir": skill_root, + "directSubmitSkill": "fault-details-report.collect_fault_details" + }) + .to_string(), + ) + .unwrap(); + config_path +} + +fn direct_submit_runtime_context(skill_root: &std::path::Path) -> AgentRuntimeContext { + let workspace_root = std::env::temp_dir().join(format!( + "sgclaw-agent-runtime-workspace-{}", + Uuid::new_v4() + )); + fs::create_dir_all(&workspace_root).unwrap(); + let config_path = write_direct_submit_config(&workspace_root, skill_root); + AgentRuntimeContext::new(Some(config_path), workspace_root) +} + +fn submit_fault_details_message() -> BrowserMessage { + BrowserMessage::SubmitTask { + instruction: "请采集 2026-03 的故障明细并返回结果".to_string(), + conversation_id: String::new(), + messages: vec![], + page_url: "https://95598.sgcc.com.cn/".to_string(), + page_title: "网上国网".to_string(), + } +} + +fn direct_submit_mode_logs(sent: &[AgentMessage]) -> Vec { + sent.iter() + .filter_map(|message| match message { + AgentMessage::LogEntry { level, message } if level == "mode" => Some(message.clone()), + _ => None, + }) + .collect() +} + +fn direct_submit_completion(sent: &[AgentMessage]) -> Option<(bool, String)> { + sent.iter().find_map(|message| match message { + AgentMessage::TaskComplete { success, summary } => Some((*success, summary.clone())), + _ => None, + }) +} + +fn success_browser_response(seq: u64, data: serde_json::Value) -> BrowserMessage { + BrowserMessage::Response { + seq, + success: true, + data, + aom_snapshot: vec![], + timing: Timing { + queue_ms: 1, + exec_ms: 10, + }, + } +} + +fn report_artifact_browser_response( + seq: u64, + status: &str, + partial_reasons: &[&str], + detail_rows: Vec, + summary_rows: Vec, +) -> BrowserMessage { + success_browser_response( + seq, + serde_json::json!({ + "text": { + "type": "report-artifact", + "report_name": "fault-details-report", + "period": "2026-03", + "selected_range": { + "start": "2026-03-08 16:00:00", + "end": "2026-03-09 16:00:00" + }, + "columns": ["qxdbh"], + "rows": detail_rows, + "sections": [{ + "name": "summary-sheet", + "columns": ["index"], + "rows": summary_rows + }], + "counts": { + "detail_rows": detail_rows.len(), + "summary_rows": summary_rows.len() + }, + "status": status, + "partial_reasons": partial_reasons, + "downstream": { + "export": { + "attempted": true, + "success": status != "blocked" && status != "error", + "path": "http://localhost/export.xlsx" + }, + "report_log": { + "attempted": true, + "success": partial_reasons.is_empty(), + "error": partial_reasons + .first() + .copied() + .unwrap_or("") + } + } + } + }), + ) +} + +#[test] +fn direct_submit_runtime_executes_fault_details_skill_without_provider_path() { + let skill_root = build_direct_runtime_skill_root(); + let transport = Arc::new(MockTransport::new(vec![success_browser_response( + 1, + serde_json::json!({ + "text": { + "fault_type": "outage", + "observed_at": "2026-03-15 09:00", + "affected_scope": "line-7" + } + }), + )])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + let mut settings = SgClawSettings::from_legacy_deepseek_fields( + "unused-key".to_string(), + "http://127.0.0.1:9".to_string(), + "unused-model".to_string(), + Some(skill_root.clone()), + ) + .unwrap(); + settings.direct_submit_skill = Some("fault-details-report.collect_fault_details".to_string()); + + let summary = sgclaw::compat::direct_skill_runtime::execute_direct_submit_skill( + browser_tool, + "请采集 2026-03 的故障明细并返回结果", + &CompatTaskContext { + page_url: Some("https://95598.sgcc.com.cn/".to_string()), + ..CompatTaskContext::default() + }, + PathBuf::from(env!("CARGO_MANIFEST_DIR")).as_path(), + &settings, + ) + .unwrap(); + + assert!(summary.success); + assert!(summary.summary.contains("fault_type")); + let sent = transport.sent_messages(); + assert!(sent.iter().all(|message| !matches!(message, AgentMessage::LogEntry { level, message } if level == "info" && message.contains("DeepSeek config loaded")))); + assert!(matches!( + &sent[0], + AgentMessage::Command { + seq, + action, + params, + security, + } if *seq == 1 + && action == &Action::Eval + && security.expected_domain == "95598.sgcc.com.cn" + && params["script"].as_str().is_some_and(|script| script.contains("2026-03")) + )); +} + +#[test] +fn submit_task_uses_direct_skill_mode_without_llm_configuration() { + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + + let skill_root = build_direct_runtime_skill_root(); + let runtime_context = direct_submit_runtime_context(&skill_root); + let transport = Arc::new(MockTransport::new(vec![success_browser_response( + 1, + serde_json::json!({ + "text": { + "fault_type": "outage", + "observed_at": "2026-03-15 09:00", + "affected_scope": "line-7", + "artifact_payload": "report artifact payload" + } + }), + )])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + handle_browser_message_with_context( + transport.as_ref(), + &browser_tool, + &runtime_context, + submit_fault_details_message(), + ) + .unwrap(); + + let sent = transport.sent_messages(); + let completion = direct_submit_completion(&sent).expect("task completion"); + + assert!(completion.0, "expected direct submit task to succeed: {sent:?}"); + assert!( + completion.1.contains("report artifact payload"), + "expected report artifact payload in summary: {}", + completion.1 + ); + assert!( + !completion.1.contains("未配置大语言模型"), + "did not expect missing-llm summary: {}", + completion.1 + ); +} + +#[test] +fn submit_task_rejects_invalid_direct_submit_skill_config_before_routing() { + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + + let skill_root = build_direct_runtime_skill_root(); + let workspace_root = std::env::temp_dir().join(format!( + "sgclaw-invalid-direct-submit-workspace-{}", + Uuid::new_v4() + )); + fs::create_dir_all(&workspace_root).unwrap(); + let config_path = workspace_root.join("sgclaw_config.json"); + fs::write( + &config_path, + serde_json::json!({ + "providers": [], + "skillsDir": skill_root, + "directSubmitSkill": "fault-details-report" + }) + .to_string(), + ) + .unwrap(); + + let runtime_context = AgentRuntimeContext::new(Some(config_path), workspace_root); + let transport = Arc::new(MockTransport::new(vec![])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + handle_browser_message_with_context( + transport.as_ref(), + &browser_tool, + &runtime_context, + submit_fault_details_message(), + ) + .unwrap(); + + let sent = transport.sent_messages(); + assert!(matches!( + sent.last(), + Some(AgentMessage::TaskComplete { success, summary }) + if !success && summary.contains("skill.tool") + )); + assert!(direct_submit_mode_logs(&sent).is_empty()); + assert!(!sent.iter().any(|message| matches!(message, AgentMessage::Command { .. }))); +} + +#[test] +fn submit_task_treats_partial_report_artifact_as_success_with_warning_summary() { + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + + let skill_root = build_direct_runtime_skill_root(); + let runtime_context = direct_submit_runtime_context(&skill_root); + let transport = Arc::new(MockTransport::new(vec![report_artifact_browser_response( + 1, + "partial", + &["report_log_failed"], + vec![serde_json::json!({ "qxdbh": "QX-1" })], + vec![serde_json::json!({ "index": 1 })], + )])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + handle_browser_message_with_context( + transport.as_ref(), + &browser_tool, + &runtime_context, + submit_fault_details_message(), + ) + .unwrap(); + + let sent = transport.sent_messages(); + let completion = direct_submit_completion(&sent).expect("task completion"); + + assert!(completion.0, "expected partial artifact to succeed: {sent:?}"); + assert!(completion.1.contains("fault-details-report")); + assert!(completion.1.contains("2026-03")); + assert!(completion.1.contains("status=partial")); + assert!(completion.1.contains("detail_rows=1")); + assert!(completion.1.contains("summary_rows=1")); + assert!(completion.1.contains("report_log_failed")); +} + +#[test] +fn submit_task_treats_empty_report_artifact_as_success() { + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + + let skill_root = build_direct_runtime_skill_root(); + let runtime_context = direct_submit_runtime_context(&skill_root); + let transport = Arc::new(MockTransport::new(vec![report_artifact_browser_response( + 1, + "empty", + &[], + vec![], + vec![], + )])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + handle_browser_message_with_context( + transport.as_ref(), + &browser_tool, + &runtime_context, + submit_fault_details_message(), + ) + .unwrap(); + + let sent = transport.sent_messages(); + let completion = direct_submit_completion(&sent).expect("task completion"); + + assert!(completion.0, "expected empty artifact to succeed: {sent:?}"); + assert!(completion.1.contains("status=empty")); + assert!(completion.1.contains("detail_rows=0")); +} + +#[test] +fn submit_task_treats_blocked_report_artifact_as_failure() { + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + + let skill_root = build_direct_runtime_skill_root(); + let runtime_context = direct_submit_runtime_context(&skill_root); + let transport = Arc::new(MockTransport::new(vec![report_artifact_browser_response( + 1, + "blocked", + &["selected_range_unavailable"], + vec![], + vec![], + )])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + handle_browser_message_with_context( + transport.as_ref(), + &browser_tool, + &runtime_context, + submit_fault_details_message(), + ) + .unwrap(); + + let sent = transport.sent_messages(); + let completion = direct_submit_completion(&sent).expect("task completion"); + + assert!(!completion.0, "expected blocked artifact to fail: {sent:?}"); + assert!(completion.1.contains("status=blocked")); + assert!(completion.1.contains("selected_range_unavailable")); +} + +#[test] +fn submit_task_treats_error_report_artifact_as_failure() { + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + + let skill_root = build_direct_runtime_skill_root(); + let runtime_context = direct_submit_runtime_context(&skill_root); + let transport = Arc::new(MockTransport::new(vec![report_artifact_browser_response( + 1, + "error", + &["detail_normalization_failed"], + vec![], + vec![], + )])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + handle_browser_message_with_context( + transport.as_ref(), + &browser_tool, + &runtime_context, + submit_fault_details_message(), + ) + .unwrap(); + + let sent = transport.sent_messages(); + let completion = direct_submit_completion(&sent).expect("task completion"); + + assert!(!completion.0, "expected error artifact to fail: {sent:?}"); + assert!(completion.1.contains("status=error")); + assert!(completion.1.contains("detail_normalization_failed")); +} + +#[test] +fn direct_skill_mode_logs_direct_skill_primary() { + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + + let skill_root = build_direct_runtime_skill_root(); + let runtime_context = direct_submit_runtime_context(&skill_root); + let transport = Arc::new(MockTransport::new(vec![success_browser_response( + 1, + serde_json::json!({ + "text": { + "fault_type": "outage", + "observed_at": "2026-03-15 09:00", + "affected_scope": "line-7", + "artifact_payload": "report artifact payload" + } + }), + )])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + direct_runtime_test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + handle_browser_message_with_context( + transport.as_ref(), + &browser_tool, + &runtime_context, + submit_fault_details_message(), + ) + .unwrap(); + + let sent = transport.sent_messages(); + let mode_logs = direct_submit_mode_logs(&sent); + + assert_eq!(mode_logs, vec!["direct_skill_primary".to_string()]); + assert!( + !mode_logs.iter().any(|mode| mode == "compat_llm_primary"), + "unexpected compat mode logs: {mode_logs:?}" + ); + assert!( + !mode_logs + .iter() + .any(|mode| mode == "zeroclaw_process_message_primary"), + "unexpected zeroclaw mode logs: {mode_logs:?}" + ); +} + #[test] fn production_submit_task_routes_zhihu_through_ws_backend_without_helper_bootstrap() { let _guard = env_lock().lock().unwrap_or_else(|err| err.into_inner()); @@ -179,17 +736,16 @@ fn production_submit_task_routes_zhihu_through_ws_backend_without_helper_bootstr std::env::remove_var("DEEPSEEK_MODEL"); let workspace_root = temp_workspace_root(); + let (ws_url, frames, ws_handle) = start_browser_ws_server(); let config_path = write_config( &workspace_root, "deepseek-test-key", "http://127.0.0.1:9", "deepseek-chat", Some(real_skill_lib_root().to_str().unwrap()), + Some(&ws_url), ); - let (ws_url, frames, ws_handle) = start_browser_ws_server(); - std::env::set_var("SGCLAW_BROWSER_WS_URL", &ws_url); - let transport = Arc::new(MockTransport::new(vec![])); let browser_tool = BrowserPipeTool::new( transport.clone(), @@ -306,7 +862,7 @@ fn production_submit_task_does_not_route_into_legacy_runtime_without_llm_config( let transport = Arc::new(MockTransport::new(vec![])); let browser_tool = BrowserPipeTool::new( transport.clone(), - test_policy(), + provider_path_test_policy(), vec![1, 2, 3, 4, 5, 6, 7, 8], ) .with_response_timeout(Duration::from_secs(1)); diff --git a/tests/browser_script_skill_tool_test.rs b/tests/browser_script_skill_tool_test.rs index 091101a..fbb48b7 100644 --- a/tests/browser_script_skill_tool_test.rs +++ b/tests/browser_script_skill_tool_test.rs @@ -32,6 +32,174 @@ fn test_policy() -> MacPolicy { .unwrap() } +#[tokio::test] +async fn execute_browser_script_tool_runs_packaged_script_with_expected_domain() { + let skill_dir = unique_temp_dir("sgclaw-browser-script-helper"); + let scripts_dir = skill_dir.join("scripts"); + fs::create_dir_all(&scripts_dir).unwrap(); + fs::write( + scripts_dir.join("extract_hotlist.js"), + "return { wrapped_args: args, source: \"packaged script\" };\n", + ) + .unwrap(); + + let transport = Arc::new(MockTransport::new(vec![BrowserMessage::Response { + seq: 1, + success: true, + data: json!({ + "text": { + "sheet_name": "知乎热榜", + "rows": [[1, "标题", "10条"]] + } + }), + aom_snapshot: vec![], + timing: Timing { + queue_ms: 1, + exec_ms: 5, + }, + }])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + let mut tool_args = HashMap::new(); + tool_args.insert("top_n".to_string(), "How many rows to extract".to_string()); + let skill_tool = SkillTool { + name: "extract_hotlist".to_string(), + description: "Extract structured hotlist rows".to_string(), + kind: "browser_script".to_string(), + command: "scripts/extract_hotlist.js".to_string(), + args: tool_args, + }; + + let result = execute_browser_script_tool( + &skill_tool, + &skill_dir, + &PipeBrowserBackend::from_inner(browser_tool), + json!({ + "expected_domain": "https://WWW.ZHIHU.COM/hot?foo=bar", + "top_n": "10" + }), + ) + .await + .unwrap(); + + let sent = transport.sent_messages(); + assert!(result.success); + assert_eq!( + serde_json::from_str::(&result.output).unwrap(), + json!({ + "sheet_name": "知乎热榜", + "rows": [[1, "标题", "10条"]] + }) + ); + assert!(matches!( + &sent[0], + AgentMessage::Command { + action, + params, + security, + .. + } if action == &Action::Eval + && security.expected_domain == "www.zhihu.com" + && params["script"].as_str().unwrap().contains("const args = {\"top_n\":\"10\"};") + && params["script"].as_str().unwrap().contains("source: \"packaged script\"") + )); +} + +#[tokio::test] +async fn execute_browser_script_tool_rejects_non_browser_script_tool_kind() { + let skill_dir = unique_temp_dir("sgclaw-browser-script-helper-invalid-kind"); + let scripts_dir = skill_dir.join("scripts"); + fs::create_dir_all(&scripts_dir).unwrap(); + fs::write(scripts_dir.join("extract_hotlist.js"), "return 'unused';\n").unwrap(); + + let transport = Arc::new(MockTransport::new(vec![])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + let mut tool_args = HashMap::new(); + tool_args.insert("top_n".to_string(), "How many rows to extract".to_string()); + let skill_tool = SkillTool { + name: "extract_hotlist".to_string(), + description: "Extract structured hotlist rows".to_string(), + kind: "shell".to_string(), + command: "scripts/extract_hotlist.js".to_string(), + args: tool_args, + }; + + let result = execute_browser_script_tool( + &skill_tool, + &skill_dir, + &PipeBrowserBackend::from_inner(browser_tool), + json!({ + "expected_domain": "www.zhihu.com", + "top_n": "10" + }), + ) + .await + .unwrap(); + + assert!(!result.success); + assert_eq!( + result.error.as_deref(), + Some("browser script tool kind must be browser_script, got shell") + ); + assert!(transport.sent_messages().is_empty()); +} + +#[tokio::test] +async fn execute_browser_script_tool_rejects_missing_expected_domain() { + let skill_dir = unique_temp_dir("sgclaw-browser-script-helper-invalid-domain"); + let scripts_dir = skill_dir.join("scripts"); + fs::create_dir_all(&scripts_dir).unwrap(); + fs::write(scripts_dir.join("extract_hotlist.js"), "return 'unused';\n").unwrap(); + + let transport = Arc::new(MockTransport::new(vec![])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + + let mut tool_args = HashMap::new(); + tool_args.insert("top_n".to_string(), "How many rows to extract".to_string()); + let skill_tool = SkillTool { + name: "extract_hotlist".to_string(), + description: "Extract structured hotlist rows".to_string(), + kind: "browser_script".to_string(), + command: "scripts/extract_hotlist.js".to_string(), + args: tool_args, + }; + + let result = execute_browser_script_tool( + &skill_tool, + &skill_dir, + &PipeBrowserBackend::from_inner(browser_tool), + json!({ + "expected_domain": " ", + "top_n": "10" + }), + ) + .await + .unwrap(); + + assert!(!result.success); + assert_eq!( + result.error.as_deref(), + Some("expected_domain must be a non-empty string, got \" \"") + ); + assert!(transport.sent_messages().is_empty()); +} + #[tokio::test] async fn browser_script_skill_tool_executes_packaged_script_via_eval() { let skill_dir = unique_temp_dir("sgclaw-browser-script-skill"); @@ -115,9 +283,91 @@ return { )); } +#[tokio::test] +async fn browser_script_skill_tool_executes_script_directly_under_skill_root() { + let skill_root = unique_temp_dir("sgclaw-browser-script-direct-root"); + let script_name = "extract_hotlist_direct.js"; + let script_path = skill_root.join(script_name); + fs::write( + &script_path, + r#" +return { + sheet_name: "知乎热榜", + rows: [[1, "标题", args.top_n]] +}; +"#, + ) + .unwrap(); + + let transport = Arc::new(MockTransport::new(vec![BrowserMessage::Response { + seq: 1, + success: true, + data: json!({ + "text": { + "sheet_name": "知乎热榜", + "rows": [[1, "标题", "10条"]] + } + }), + aom_snapshot: vec![], + timing: Timing { + queue_ms: 1, + exec_ms: 5, + }, + }])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + let backend: Arc = Arc::new(PipeBrowserBackend::from_inner(browser_tool)); + + let mut args = HashMap::new(); + args.insert("top_n".to_string(), "How many rows to extract".to_string()); + let skill_tool = SkillTool { + name: "extract_hotlist".to_string(), + description: "Extract structured hotlist rows".to_string(), + kind: "browser_script".to_string(), + command: script_name.to_string(), + args, + }; + let tool = BrowserScriptSkillTool::new("zhihu-hotlist", &skill_tool, &skill_root, backend) + .unwrap(); + + let result = tool + .execute(json!({ + "expected_domain": "https://www.zhihu.com/hot", + "top_n": "10条" + })) + .await + .unwrap(); + + let sent = transport.sent_messages(); + assert!(result.success); + assert_eq!( + serde_json::from_str::(&result.output).unwrap(), + json!({ + "sheet_name": "知乎热榜", + "rows": [[1, "标题", "10条"]] + }) + ); + assert!(matches!( + &sent[0], + AgentMessage::Command { + action, + params, + security, + .. + } if action == &Action::Eval + && security.expected_domain == "www.zhihu.com" + && params["script"].as_str().unwrap().contains("const args = {\"top_n\":\"10条\"};") + && params["script"].as_str().unwrap().contains("rows: [[1, \"标题\", args.top_n]]") + )); +} + #[tokio::test] async fn browser_script_helper_executes_packaged_script_via_eval() { - let skill_dir = unique_temp_dir("sgclaw-browser-script-helper"); + let skill_dir = unique_temp_dir("sgclaw-browser-script-helper-fault-details"); let scripts_dir = skill_dir.join("scripts"); fs::create_dir_all(&scripts_dir).unwrap(); fs::write( @@ -152,7 +402,7 @@ return { vec![1, 2, 3, 4, 5, 6, 7, 8], ) .with_response_timeout(Duration::from_secs(1)); - let backend: Arc = Arc::new(PipeBrowserBackend::from_inner(browser_tool)); + let backend = PipeBrowserBackend::from_inner(browser_tool); let mut args = HashMap::new(); args.insert("period".to_string(), "Target report period".to_string()); @@ -164,10 +414,15 @@ return { args, }; - let result = execute_browser_script_tool(&skill_tool, &skill_dir, backend, json!({ - "expected_domain": "https://www.zhihu.com/hot", - "period": "2026-04" - })) + let result = execute_browser_script_tool( + &skill_tool, + &skill_dir, + &backend, + json!({ + "expected_domain": "https://www.zhihu.com/hot", + "period": "2026-04" + }), + ) .await .unwrap(); @@ -208,7 +463,7 @@ async fn browser_script_helper_requires_expected_domain() { vec![1, 2, 3, 4, 5, 6, 7, 8], ) .with_response_timeout(Duration::from_secs(1)); - let backend: Arc = Arc::new(PipeBrowserBackend::from_inner(browser_tool)); + let backend = PipeBrowserBackend::from_inner(browser_tool); let mut args = HashMap::new(); args.insert("period".to_string(), "Target report period".to_string()); @@ -220,9 +475,14 @@ async fn browser_script_helper_requires_expected_domain() { args, }; - let result = execute_browser_script_tool(&skill_tool, &skill_dir, backend, json!({ - "period": "2026-04" - })) + let result = execute_browser_script_tool( + &skill_tool, + &skill_dir, + &backend, + json!({ + "period": "2026-04" + }), + ) .await .unwrap(); @@ -234,6 +494,122 @@ async fn browser_script_helper_requires_expected_domain() { assert!(transport.sent_messages().is_empty()); } +#[tokio::test] +async fn execute_browser_script_tool_preserves_structured_report_artifact_payload() { + let skill_dir = unique_temp_dir("sgclaw-browser-script-helper-report-artifact"); + let scripts_dir = skill_dir.join("scripts"); + fs::create_dir_all(&scripts_dir).unwrap(); + fs::write( + scripts_dir.join("collect_fault_details.js"), + r#" +return { + type: "report-artifact", + report_name: "fault-details-report", + period: args.period, + selected_range: { + start: "2026-03-08 16:00:00", + end: "2026-03-09 16:00:00" + }, + columns: ["qxdbh"], + rows: [{ qxdbh: "QX-1" }], + sections: [{ name: "summary-sheet", columns: ["index"], rows: [{ index: 1 }] }], + counts: { detail_rows: 1, summary_rows: 1 }, + status: "partial", + partial_reasons: ["report_log_failed"], + downstream: { + export: { attempted: true, success: true, path: "http://localhost/export.xlsx" }, + report_log: { attempted: true, success: false, error: "500" } + } +}; +"#, + ) + .unwrap(); + + let transport = Arc::new(MockTransport::new(vec![BrowserMessage::Response { + seq: 1, + success: true, + data: json!({ + "text": { + "type": "report-artifact", + "report_name": "fault-details-report", + "period": "2026-03", + "selected_range": { + "start": "2026-03-08 16:00:00", + "end": "2026-03-09 16:00:00" + }, + "columns": ["qxdbh"], + "rows": [{ "qxdbh": "QX-1" }], + "sections": [{ "name": "summary-sheet", "columns": ["index"], "rows": [{ "index": 1 }] }], + "counts": { "detail_rows": 1, "summary_rows": 1 }, + "status": "partial", + "partial_reasons": ["report_log_failed"], + "downstream": { + "export": { "attempted": true, "success": true, "path": "http://localhost/export.xlsx" }, + "report_log": { "attempted": true, "success": false, "error": "500" } + } + } + }), + aom_snapshot: vec![], + timing: Timing { + queue_ms: 1, + exec_ms: 5, + }, + }])); + let browser_tool = BrowserPipeTool::new( + transport.clone(), + test_policy(), + vec![1, 2, 3, 4, 5, 6, 7, 8], + ) + .with_response_timeout(Duration::from_secs(1)); + let backend = PipeBrowserBackend::from_inner(browser_tool); + + let mut tool_args = HashMap::new(); + tool_args.insert("period".to_string(), "YYYY-MM period to collect".to_string()); + let skill_tool = SkillTool { + name: "collect_fault_details".to_string(), + description: "Collect structured fault details".to_string(), + kind: "browser_script".to_string(), + command: "scripts/collect_fault_details.js".to_string(), + args: tool_args, + }; + + let result = execute_browser_script_tool( + &skill_tool, + &skill_dir, + &backend, + json!({ + "expected_domain": "https://www.zhihu.com/", + "period": "2026-03" + }), + ) + .await + .unwrap(); + + assert!(result.success); + assert_eq!( + serde_json::from_str::(&result.output).unwrap(), + json!({ + "type": "report-artifact", + "report_name": "fault-details-report", + "period": "2026-03", + "selected_range": { + "start": "2026-03-08 16:00:00", + "end": "2026-03-09 16:00:00" + }, + "columns": ["qxdbh"], + "rows": [{ "qxdbh": "QX-1" }], + "sections": [{ "name": "summary-sheet", "columns": ["index"], "rows": [{ "index": 1 }] }], + "counts": { "detail_rows": 1, "summary_rows": 1 }, + "status": "partial", + "partial_reasons": ["report_log_failed"], + "downstream": { + "export": { "attempted": true, "success": true, "path": "http://localhost/export.xlsx" }, + "report_log": { "attempted": true, "success": false, "error": "500" } + } + }) + ); +} + fn unique_temp_dir(prefix: &str) -> PathBuf { let nanos = SystemTime::now() .duration_since(UNIX_EPOCH) diff --git a/tests/compat_config_test.rs b/tests/compat_config_test.rs index 31d6b3a..cec9979 100644 --- a/tests/compat_config_test.rs +++ b/tests/compat_config_test.rs @@ -161,6 +161,60 @@ fn sgclaw_settings_default_to_compact_skills_and_browser_attached_profile() { assert_eq!(settings.skills_prompt_mode, SkillsPromptMode::Compact); } +#[test] +fn sgclaw_settings_load_direct_submit_only_config_and_resolve_relative_skills_dir() { + let root = std::env::temp_dir().join(format!("sgclaw-direct-submit-only-config-{}", Uuid::new_v4())); + fs::create_dir_all(&root).unwrap(); + let config_path = root.join("sgclaw_config.json"); + + fs::write( + &config_path, + r#"{ + "providers": [], + "skillsDir": "skill_lib", + "directSubmitSkill": "fault-details-report.collect_fault_details" +}"#, + ) + .unwrap(); + + let settings = SgClawSettings::load(Some(config_path.as_path())) + .unwrap() + .expect("expected sgclaw settings from config file"); + + assert_eq!( + settings.direct_submit_skill.as_deref(), + Some("fault-details-report.collect_fault_details") + ); + assert_eq!(settings.skills_dir, Some(root.join("skill_lib"))); +} + +#[test] +fn sgclaw_settings_reject_invalid_direct_submit_skill_format() { + let root = std::env::temp_dir().join(format!( + "sgclaw-invalid-direct-submit-skill-{}", + Uuid::new_v4() + )); + fs::create_dir_all(&root).unwrap(); + let config_path = root.join("sgclaw_config.json"); + + fs::write( + &config_path, + r#"{ + "providers": [], + "skillsDir": "skill_lib", + "directSubmitSkill": "fault-details-report" +}"#, + ) + .unwrap(); + + let err = SgClawSettings::load(Some(config_path.as_path())) + .expect_err("expected invalid directSubmitSkill format"); + let message = err.to_string(); + + assert!(message.contains("directSubmitSkill")); + assert!(message.contains("skill.tool")); +} + #[test] fn sgclaw_settings_load_new_runtime_fields_from_browser_config() { let root = std::env::temp_dir().join(format!("sgclaw-runtime-config-{}", Uuid::new_v4())); diff --git a/tests/compat_openxml_office_tool_test.rs b/tests/compat_openxml_office_tool_test.rs index 8649b35..33d7d4b 100644 --- a/tests/compat_openxml_office_tool_test.rs +++ b/tests/compat_openxml_office_tool_test.rs @@ -1,10 +1,12 @@ +use std::fs::File; +use std::io::Read; use std::path::PathBuf; -use std::process::Command as ProcessCommand; use serde_json::json; use sgclaw::compat::openxml_office_tool::OpenXmlOfficeTool; use uuid::Uuid; use zeroclaw::tools::Tool; +use zip::ZipArchive; fn temp_workspace_root() -> PathBuf { let root = std::env::temp_dir().join(format!("sgclaw-openxml-office-{}", Uuid::new_v4())); @@ -12,6 +14,15 @@ fn temp_workspace_root() -> PathBuf { root } +fn read_sheet_xml(output_path: &std::path::Path) -> String { + let file = File::open(output_path).unwrap(); + let mut archive = ZipArchive::new(file).unwrap(); + let mut entry = archive.by_name("xl/worksheets/sheet1.xml").unwrap(); + let mut xml = String::new(); + entry.read_to_string(&mut xml).unwrap(); + xml +} + #[tokio::test] async fn openxml_office_tool_renders_hotlist_xlsx_from_rows() { let workspace_root = temp_workspace_root(); @@ -33,20 +44,12 @@ async fn openxml_office_tool_renders_hotlist_xlsx_from_rows() { assert!(result.success, "{result:?}"); assert!(output_path.exists()); - let payload: serde_json::Value = serde_json::from_str(&result.output).unwrap(); - assert_eq!(payload["output_path"], json!(output_path.to_str().unwrap())); + let output_json: serde_json::Value = serde_json::from_str(&result.output).unwrap(); + assert_eq!(output_json["row_count"], 2); + assert_eq!(output_json["renderer"], "openxml_office"); + assert_eq!(output_json["output_path"], json!(output_path.to_str().unwrap())); - let unzip = ProcessCommand::new("unzip") - .args([ - "-p", - output_path.to_str().unwrap(), - "xl/worksheets/sheet1.xml", - ]) - .output() - .unwrap(); - assert!(unzip.status.success()); - - let xml = String::from_utf8(unzip.stdout).unwrap(); + let xml = read_sheet_xml(&output_path); assert!(xml.contains("问题一")); assert!(xml.contains("344万")); assert!(xml.contains("问题二")); @@ -75,17 +78,7 @@ async fn openxml_office_tool_accepts_reordered_columns_when_rows_are_structured( assert!(result.success, "{result:?}"); assert!(output_path.exists()); - let unzip = ProcessCommand::new("unzip") - .args([ - "-p", - output_path.to_str().unwrap(), - "xl/worksheets/sheet1.xml", - ]) - .output() - .unwrap(); - assert!(unzip.status.success()); - - let xml = String::from_utf8(unzip.stdout).unwrap(); + let xml = read_sheet_xml(&output_path); assert!(xml.contains("问题一")); assert!(xml.contains("344万")); assert!(xml.contains(">1<")); @@ -113,17 +106,7 @@ async fn openxml_office_tool_accepts_localized_hotlist_column_aliases() { assert!(result.success, "{result:?}"); assert!(output_path.exists()); - let unzip = ProcessCommand::new("unzip") - .args([ - "-p", - output_path.to_str().unwrap(), - "xl/worksheets/sheet1.xml", - ]) - .output() - .unwrap(); - assert!(unzip.status.success()); - - let xml = String::from_utf8(unzip.stdout).unwrap(); + let xml = read_sheet_xml(&output_path); assert!(xml.contains("问题一")); assert!(xml.contains("344万")); assert!(xml.contains(">1<")); diff --git a/tests/compat_runtime_test.rs b/tests/compat_runtime_test.rs index 475efe2..3a8afa2 100644 --- a/tests/compat_runtime_test.rs +++ b/tests/compat_runtime_test.rs @@ -112,10 +112,15 @@ fn write_skill_script(skill_dir: &std::path::Path, relative_path: &str, body: &s } fn real_skill_lib_root() -> PathBuf { - PathBuf::from(env!("CARGO_MANIFEST_DIR")) + let repo_parent = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .parent() .unwrap() - .join("skill_lib") + .to_path_buf(); + let hyphenated = repo_parent.join("skill-lib"); + if hyphenated.exists() { + return hyphenated; + } + repo_parent.join("skill_lib") } fn success_browser_response(seq: u64, data: Value) -> BrowserMessage { @@ -349,6 +354,9 @@ fn compat_runtime_uses_zeroclaw_provider_path_and_executes_browser_actions() { server_handle.join().unwrap(); let request_bodies = requests.lock().unwrap().clone(); + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); let sent = transport.sent_messages(); assert_eq!(summary, "已通过 ZeroClaw 执行任务: 打开百度搜索天气"); @@ -676,7 +684,10 @@ fn handle_browser_message_routes_supported_instruction_to_compat_runtime_when_ll message, AgentMessage::LogEntry { level, message } if level == "info" && - message == "sgclaw runtime version=0.1.0 protocol=1.0" + message == &format!( + "sgclaw runtime version={} protocol=1.0", + env!("CARGO_PKG_VERSION") + ) ) })); assert!(sent.iter().any(|message| { @@ -883,6 +894,11 @@ fn handle_browser_message_falls_back_to_compat_runtime_for_unsupported_instructi #[test] fn handle_browser_message_requires_llm_configuration_when_no_model_is_available() { + let _guard = env_lock().lock().unwrap_or_else(|err| err.into_inner()); + std::env::remove_var("DEEPSEEK_API_KEY"); + std::env::remove_var("DEEPSEEK_BASE_URL"); + std::env::remove_var("DEEPSEEK_MODEL"); + let transport = Arc::new(MockTransport::new(vec![])); let browser_tool = BrowserPipeTool::new( transport.clone(), diff --git a/tests/compat_screen_html_export_tool_test.rs b/tests/compat_screen_html_export_tool_test.rs index 59b214a..e749f01 100644 --- a/tests/compat_screen_html_export_tool_test.rs +++ b/tests/compat_screen_html_export_tool_test.rs @@ -43,17 +43,18 @@ async fn screen_html_export_tool_renders_dashboard_html_with_presentation_contra .as_str() .unwrap() .starts_with("file://")); + assert!(html.contains("知乎热榜图表驾驶舱")); assert!(html.contains("snapshot-20260329")); assert!(html.contains("问题一")); assert!(html.contains("344万")); assert!(html.contains("const defaultPayload =")); - assert!(html.contains("汇报摘要")); - assert!(html.contains("fitScreenToViewport")); - assert!(html.contains("dashboard-canvas")); - assert!(html.contains("themeSwitcher")); - assert!(html.contains("gov_blue_gold")); - assert!(html.contains("tech_cyan_blue")); - assert!(html.contains("industry_ink_green")); - assert!(html.contains("meeting_red_gold")); - assert!(html.contains("localStorage.setItem(\"zhihu-hotlist-theme\"")); + assert!(html.contains("lead-summary")); + assert!(html.contains("bar-chart")); + assert!(html.contains("top-chart")); + assert!(html.contains("pie-chart")); + assert!(html.contains("bubble-chart")); + assert!(html.contains("metric-categories")); + assert!(html.contains("themeMeta")); + assert!(html.contains("screen_html_export")); + assert!(html.contains("table-note")); } diff --git a/tests/runtime_task_flow_test.rs b/tests/runtime_task_flow_test.rs index 15925aa..d4dd6f0 100644 --- a/tests/runtime_task_flow_test.rs +++ b/tests/runtime_task_flow_test.rs @@ -51,7 +51,12 @@ fn submit_task_without_llm_configuration_returns_clear_error() { assert!(matches!( &sent[0], AgentMessage::LogEntry { level, message } - if level == "info" && message == "sgclaw runtime version=0.1.0 protocol=1.0" + if level == "info" + && message + == &format!( + "sgclaw runtime version={} protocol=1.0", + env!("CARGO_PKG_VERSION") + ) )); assert!(matches!( &sent[1], diff --git a/tests/service_task_flow_test.rs b/tests/service_task_flow_test.rs index a093966..23a5c0a 100644 --- a/tests/service_task_flow_test.rs +++ b/tests/service_task_flow_test.rs @@ -12,6 +12,8 @@ use tungstenite::{accept, Message}; const RUNTIME_DROP_PANIC_TEXT: &str = "Cannot drop a runtime in a context where blocking is not allowed"; + const TEST_ZHIHU_SKILLS_DIR: &str = "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills"; + fn read_ws_text(stream: &mut tungstenite::WebSocket) -> String { match stream.read().unwrap() { Message::Text(text) => text.to_string(), @@ -756,6 +758,7 @@ fn client_to_service_regression_routes_zhihu_through_callback_host_without_inval "apiKey": "sk-runtime", "baseUrl": "http://127.0.0.1:9", "model": "deepseek-chat", + "skillsDir": "{TEST_ZHIHU_SKILLS_DIR}", "browserWsUrl": "{browser_ws_url}", "serviceWsListenAddr": "{service_addr}" }}"# diff --git a/tests/service_ws_session_test.rs b/tests/service_ws_session_test.rs index a273f2e..7931f97 100644 --- a/tests/service_ws_session_test.rs +++ b/tests/service_ws_session_test.rs @@ -14,6 +14,7 @@ use sgclaw::service::{ClientMessage, ServiceEventSink, ServiceMessage, ServiceSe const RUNTIME_DROP_PANIC_TEXT: &str = "Cannot drop a runtime in a context where blocking is not allowed"; +const TEST_ZHIHU_SKILLS_DIR: &str = "D:/data/ideaSpace/rust/sgClaw/claw/claw/skills"; fn read_ws_text(stream: &mut tungstenite::WebSocket) -> String where @@ -808,6 +809,7 @@ fn service_binary_submit_flow_routes_zhihu_through_callback_host() { "apiKey": "sk-runtime", "baseUrl": "http://127.0.0.1:9", "model": "deepseek-chat", + "skillsDir": "{TEST_ZHIHU_SKILLS_DIR}", "browserWsUrl": "{browser_ws_url}", "serviceWsListenAddr": "{service_addr}" }}"# @@ -981,6 +983,7 @@ fn service_binary_submit_flow_uses_callback_host_command_semantics_for_zhihu() { "apiKey": "sk-runtime", "baseUrl": "http://127.0.0.1:9", "model": "deepseek-chat", + "skillsDir": "{TEST_ZHIHU_SKILLS_DIR}", "browserWsUrl": "{browser_ws_url}", "serviceWsListenAddr": "{service_addr}" }}"#