@runweave/server-linux-x64 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/manifest.json +1482 -151
- package/native.tar.gz +0 -0
- package/package.json +1 -1
- package/payload/.agents/plugins/marketplace.json +20 -0
- package/payload/app-server/build-info.json +3 -3
- package/payload/app-server/index.cjs +1 -1
- package/payload/backend/build-info.json +4 -4
- package/payload/backend/index.cjs +45 -9
- package/payload/backend/ios-simulators/pool.py +3 -3
- package/payload/frontend/dist/assets/{_baseUniq-vo4uuhMd.js → _baseUniq-qHFga5V8.js} +1 -1
- package/payload/frontend/dist/assets/{access-_jCu7Rgu.js → access-DgHvmn15.js} +1 -1
- package/payload/frontend/dist/assets/{advanced-CqOhObYj.js → advanced-C1Fh14vw.js} +1 -1
- package/payload/frontend/dist/assets/{appearance-CrrD5gzC.js → appearance-Bs7cSXqO.js} +1 -1
- package/payload/frontend/dist/assets/{arc-dbfyHSF0.js → arc-E3iYHQG_.js} +1 -1
- package/payload/frontend/dist/assets/{architectureDiagram-Q4EWVU46-CntSCAsO.js → architectureDiagram-Q4EWVU46-DgpYpTb9.js} +1 -1
- package/payload/frontend/dist/assets/{blockDiagram-DXYQGD6D-Chp0D4qy.js → blockDiagram-DXYQGD6D-CfFOEKZ7.js} +1 -1
- package/payload/frontend/dist/assets/{c4Diagram-AHTNJAMY-CF91pOuW.js → c4Diagram-AHTNJAMY-BxlHBUj3.js} +1 -1
- package/payload/frontend/dist/assets/channel-amxyNKnk.js +1 -0
- package/payload/frontend/dist/assets/{chunk-4BX2VUAB-B1gxlVu2.js → chunk-4BX2VUAB-xWocgDo8.js} +1 -1
- package/payload/frontend/dist/assets/{chunk-4TB4RGXK-Cxt3mj9b.js → chunk-4TB4RGXK-Bl1cNICf.js} +1 -1
- package/payload/frontend/dist/assets/{chunk-55IACEB6-BJT6qNik.js → chunk-55IACEB6-DVtE836u.js} +1 -1
- package/payload/frontend/dist/assets/{chunk-EDXVE4YY-yI59bCa0.js → chunk-EDXVE4YY-Dbd3tDCr.js} +1 -1
- package/payload/frontend/dist/assets/{chunk-FMBD7UC4-CDvncKKJ.js → chunk-FMBD7UC4-MPJaTsyN.js} +1 -1
- package/payload/frontend/dist/assets/{chunk-OYMX7WX6-BblOIU57.js → chunk-OYMX7WX6-D3LuudlW.js} +1 -1
- package/payload/frontend/dist/assets/{chunk-QZHKN3VN-rODzNdO0.js → chunk-QZHKN3VN-Dn1aF6iQ.js} +1 -1
- package/payload/frontend/dist/assets/{chunk-YZCP3GAM-B6D4wQwk.js → chunk-YZCP3GAM-jZYbHnCw.js} +1 -1
- package/payload/frontend/dist/assets/classDiagram-6PBFFD2Q-B8cTijjT.js +1 -0
- package/payload/frontend/dist/assets/classDiagram-v2-HSJHXN6E-B8cTijjT.js +1 -0
- package/payload/frontend/dist/assets/clone-xzI2eGRI.js +1 -0
- package/payload/frontend/dist/assets/connection-V2iI-6rM.js +12 -0
- package/payload/frontend/dist/assets/{connections-DqDmxS-O.js → connections-G_Q7342g.js} +1 -1
- package/payload/frontend/dist/assets/{cose-bilkent-S5V4N54A-BvwVWp29.js → cose-bilkent-S5V4N54A-75FLD3RS.js} +1 -1
- package/payload/frontend/dist/assets/{dagre-KV5264BT-h_K1TH11.js → dagre-KV5264BT-DEm-DpJL.js} +1 -1
- package/payload/frontend/dist/assets/{desktop-BQ3kGtKG.js → desktop-g5JC-CQd.js} +1 -1
- package/payload/frontend/dist/assets/{diagram-5BDNPKRD-B8g2SV6L.js → diagram-5BDNPKRD-BV6P2UTy.js} +1 -1
- package/payload/frontend/dist/assets/{diagram-G4DWMVQ6-BOEnrqYm.js → diagram-G4DWMVQ6-DuCK-MM2.js} +1 -1
- package/payload/frontend/dist/assets/{diagram-MMDJMWI5-DlaN_z71.js → diagram-MMDJMWI5-D5_GlPgO.js} +1 -1
- package/payload/frontend/dist/assets/{diagram-TYMM5635-C_pSKftn.js → diagram-TYMM5635-QRbOYR1P.js} +1 -1
- package/payload/frontend/dist/assets/{erDiagram-SMLLAGMA-C2dL-h3I.js → erDiagram-SMLLAGMA-DefCheAw.js} +1 -1
- package/payload/frontend/dist/assets/{flowDiagram-DWJPFMVM-BmXhKWFj.js → flowDiagram-DWJPFMVM-DVzyWIso.js} +1 -1
- package/payload/frontend/dist/assets/{ganttDiagram-T4ZO3ILL-D_Odnssf.js → ganttDiagram-T4ZO3ILL-BJaClUEF.js} +1 -1
- package/payload/frontend/dist/assets/{gitGraphDiagram-UUTBAWPF-DcQdcwKZ.js → gitGraphDiagram-UUTBAWPF-BLfbApNz.js} +1 -1
- package/payload/frontend/dist/assets/{graph-C_XsxefA.js → graph-C-YqFh68.js} +1 -1
- package/payload/frontend/dist/assets/{image-D3hgVr8O.js → image-CZo_2Awc.js} +1 -1
- package/payload/frontend/dist/assets/{index-CEUsFFQq.js → index-6q2aeqkt.js} +95 -105
- package/payload/frontend/dist/assets/{infoDiagram-42DDH7IO-C6TnRyMi.js → infoDiagram-42DDH7IO-BakVOutT.js} +1 -1
- package/payload/frontend/dist/assets/{ishikawaDiagram-UXIWVN3A-BL7rfALJ.js → ishikawaDiagram-UXIWVN3A-D_1Oa5Dc.js} +1 -1
- package/payload/frontend/dist/assets/{journeyDiagram-VCZTEJTY-C_6407GW.js → journeyDiagram-VCZTEJTY-Y8TVFv6B.js} +1 -1
- package/payload/frontend/dist/assets/{kanban-definition-6JOO6SKY-CK61Fd0p.js → kanban-definition-6JOO6SKY-DxeNhTIB.js} +1 -1
- package/payload/frontend/dist/assets/{layout-DVn6JKbl.js → layout-5cMeOTAp.js} +1 -1
- package/payload/frontend/dist/assets/{linear-DyWskq8H.js → linear-Bnc3ev5g.js} +1 -1
- package/payload/frontend/dist/assets/main-3TPtEl66.js +706 -0
- package/payload/frontend/dist/assets/main-D4_uoZQa.css +33 -0
- package/payload/frontend/dist/assets/{min-apbLpSJ3.js → min-BRXKkrS8.js} +1 -1
- package/payload/frontend/dist/assets/{mindmap-definition-QFDTVHPH-MVHZZbma.js → mindmap-definition-QFDTVHPH-RYZO_BEr.js} +1 -1
- package/payload/frontend/dist/assets/{monitoring-BApsVez_.js → monitoring-Fv7kZ4s6.js} +1 -1
- package/payload/frontend/dist/assets/{notifications-CjxSNLU1.js → notifications-BzrYqyMH.js} +1 -1
- package/payload/frontend/dist/assets/{pieDiagram-DEJITSTG-Dhbb0AYU.js → pieDiagram-DEJITSTG-Bzw0dhjz.js} +1 -1
- package/payload/frontend/dist/assets/{quadrantDiagram-34T5L4WZ-Yk6LOF0S.js → quadrantDiagram-34T5L4WZ-CQJY_msa.js} +1 -1
- package/payload/frontend/dist/assets/{record-content-BCJ80KS5.js → record-content-B7-6olQt.js} +1 -1
- package/payload/frontend/dist/assets/{requirementDiagram-MS252O5E-BUhS0PEq.js → requirementDiagram-MS252O5E-DuP8hAV8.js} +1 -1
- package/payload/frontend/dist/assets/{sankeyDiagram-XADWPNL6-D2sdxz14.js → sankeyDiagram-XADWPNL6-D-fQnCZZ.js} +1 -1
- package/payload/frontend/dist/assets/{sequenceDiagram-FGHM5R23-CRere4Fy.js → sequenceDiagram-FGHM5R23-DaZNEccV.js} +1 -1
- package/payload/frontend/dist/assets/{stateDiagram-FHFEXIEX-_pk-OMlm.js → stateDiagram-FHFEXIEX-CkOLt5R1.js} +1 -1
- package/payload/frontend/dist/assets/stateDiagram-v2-QKLJ7IA2-atg1K4nB.js +1 -0
- package/payload/frontend/dist/assets/{status-Dk5rRVQF.js → status-CIIPajZp.js} +1 -1
- package/payload/frontend/dist/assets/suiji-C453W-Sg.js +1 -0
- package/payload/frontend/dist/assets/{svg-X7YkMMvx.js → svg-BUqAWGtg.js} +1 -1
- package/payload/frontend/dist/assets/{tabs-BmKbcPVh.js → tabs-Cwlp1Meu.js} +1 -1
- package/payload/frontend/dist/assets/{timeline-definition-GMOUNBTQ-BPsI2pMC.js → timeline-definition-GMOUNBTQ-BOKDMwHS.js} +1 -1
- package/payload/frontend/dist/assets/{vennDiagram-DHZGUBPP-BNJkZ1Az.js → vennDiagram-DHZGUBPP-fSZjDS41.js} +1 -1
- package/payload/frontend/dist/assets/{wardley-RL74JXVD-CVcYeATS.js → wardley-RL74JXVD-D1KIsvoD.js} +1 -1
- package/payload/frontend/dist/assets/{wardleyDiagram-NUSXRM2D-BpLJ0alk.js → wardleyDiagram-NUSXRM2D-FMe67dwE.js} +1 -1
- package/payload/frontend/dist/assets/{xychartDiagram-5P7HB3ND-BdsYYk4M.js → xychartDiagram-5P7HB3ND-B9AM9_9w.js} +1 -1
- package/payload/frontend/dist/build-info.json +4 -4
- package/payload/frontend/dist/companion.html +1 -1
- package/payload/frontend/dist/index.html +3 -3
- package/payload/packages/agent-bridge/src/install-pi.mjs +81 -0
- package/payload/plugins/pi/dist/SKILL.md +22 -0
- package/payload/plugins/pi/dist/bridge/app-server-client.cjs +82 -0
- package/payload/plugins/pi/dist/bridge/feishu_stop_notify.sh +169 -0
- package/payload/plugins/pi/dist/bridge/runweave-hook-bridge.cjs +583 -0
- package/payload/plugins/pi/dist/bridge/runweave-hook-completion.cjs +42 -0
- package/payload/plugins/pi/dist/bridge/runweave-hook-payload.cjs +578 -0
- package/payload/plugins/pi/dist/bridge/runweave-task-supervision.cjs +167 -0
- package/payload/plugins/pi/dist/runweave.js +316 -0
- package/payload/plugins/toolkit/.codex-plugin/plugin.json +31 -0
- package/payload/plugins/toolkit/README.md +185 -0
- package/payload/plugins/toolkit/hooks/AGENTS.md +6 -0
- package/payload/plugins/toolkit/hooks/app-server-client.cjs +82 -0
- package/payload/plugins/toolkit/hooks/feishu_stop_notify.sh +169 -0
- package/payload/plugins/toolkit/hooks/runweave-hook-bridge.cjs +583 -0
- package/payload/plugins/toolkit/hooks/runweave-hook-completion.cjs +42 -0
- package/payload/plugins/toolkit/hooks/runweave-hook-dispatch.cjs +123 -0
- package/payload/plugins/toolkit/hooks/runweave-hook-payload.cjs +578 -0
- package/payload/plugins/toolkit/hooks/runweave-task-supervision.cjs +167 -0
- package/payload/plugins/toolkit/hooks.json +108 -0
- package/payload/plugins/toolkit/skills/acceptance/SKILL.md +70 -0
- package/payload/plugins/toolkit/skills/acceptance/agents/openai.yaml +4 -0
- package/payload/plugins/toolkit/skills/acceptance/references/capture.md +38 -0
- package/payload/plugins/toolkit/skills/acceptance/references/delivery.md +54 -0
- package/payload/plugins/toolkit/skills/acceptance/references/gallery-contract.md +84 -0
- package/payload/plugins/toolkit/skills/acceptance/references/gallery-copy.md +34 -0
- package/payload/plugins/toolkit/skills/acceptance/references/video.md +52 -0
- package/payload/plugins/toolkit/skills/acceptance/scripts/capture.py +137 -0
- package/payload/plugins/toolkit/skills/acceptance/scripts/common.py +63 -0
- package/payload/plugins/toolkit/skills/acceptance/scripts/gallery.py +353 -0
- package/payload/plugins/toolkit/skills/acceptance/scripts/preview.py +109 -0
- package/payload/plugins/toolkit/skills/acceptance/scripts/video.py +283 -0
- package/payload/plugins/toolkit/skills/acceptance/templates/reader.css +576 -0
- package/payload/plugins/toolkit/skills/acceptance/templates/reader.html +63 -0
- package/payload/plugins/toolkit/skills/acceptance/templates/reader.js +326 -0
- package/payload/plugins/toolkit/skills/acceptance/templates/viewer.css +55 -0
- package/payload/plugins/toolkit/skills/acceptance-gallery/SKILL.md +8 -0
- package/payload/plugins/toolkit/skills/acceptance-gallery/agents/openai.yaml +6 -0
- package/payload/plugins/toolkit/skills/acceptance-gallery/references/capture-and-copy.md +3 -0
- package/payload/plugins/toolkit/skills/acceptance-gallery/references/content-contract.md +3 -0
- package/payload/plugins/toolkit/skills/acceptance-gallery/scripts/gallery.py +9 -0
- package/payload/plugins/toolkit/skills/acceptance-video/SKILL.md +8 -0
- package/payload/plugins/toolkit/skills/acceptance-video/agents/openai.yaml +6 -0
- package/payload/plugins/toolkit/skills/acceptance-video/references/input-and-capture.md +3 -0
- package/payload/plugins/toolkit/skills/acceptance-video/references/mobile-review.md +3 -0
- package/payload/plugins/toolkit/skills/acceptance-video/scripts/capture.py +9 -0
- package/payload/plugins/toolkit/skills/acceptance-video/scripts/video.py +9 -0
- package/payload/plugins/toolkit/skills/agent-device/SKILL.md +86 -0
- package/payload/plugins/toolkit/skills/agent-device/agents/openai.yaml +4 -0
- package/payload/plugins/toolkit/skills/agent-device/references/ios-setup.md +36 -0
- package/payload/plugins/toolkit/skills/agent-device/scripts/device.py +398 -0
- package/payload/plugins/toolkit/skills/agent-device/scripts/resources.py +248 -0
- package/payload/plugins/toolkit/skills/architecture-flow-prototyping/SKILL.md +128 -0
- package/payload/plugins/toolkit/skills/architecture-flow-prototyping/agents/openai.yaml +4 -0
- package/payload/plugins/toolkit/skills/architecture-flow-prototyping/references/architecture-flow-checklist.md +59 -0
- package/payload/plugins/toolkit/skills/architecture-flow-prototyping/references/architecture-flow-guide.md +135 -0
- package/payload/plugins/toolkit/skills/architecture-flow-prototyping/references/architecture-flow-handoff-template.md +57 -0
- package/payload/plugins/toolkit/skills/ask-first/SKILL.md +81 -0
- package/payload/plugins/toolkit/skills/brainstorming/SKILL.md +41 -0
- package/payload/plugins/toolkit/skills/browse-record/SKILL.md +35 -0
- package/payload/plugins/toolkit/skills/browse-record/references/app-usage.md +19 -0
- package/payload/plugins/toolkit/skills/browse-record/references/daily-reporting.md +115 -0
- package/payload/plugins/toolkit/skills/browse-record/references/zhihu.md +33 -0
- package/payload/plugins/toolkit/skills/browse-record/scripts/app_usage.py +110 -0
- package/payload/plugins/toolkit/skills/browse-record/scripts/browse_job.py +385 -0
- package/payload/plugins/toolkit/skills/browse-record/scripts/zhihu-read.js +126 -0
- package/payload/plugins/toolkit/skills/browse-record/scripts/zhihu_http.py +273 -0
- package/payload/plugins/toolkit/skills/clear-technical-explanations/LICENSE +21 -0
- package/payload/plugins/toolkit/skills/clear-technical-explanations/SKILL.md +103 -0
- package/payload/plugins/toolkit/skills/code-grounded-requirements/SKILL.md +54 -0
- package/payload/plugins/toolkit/skills/daily-doc-maintenance/SKILL.md +151 -0
- package/payload/plugins/toolkit/skills/daily-record/SKILL.md +63 -0
- package/payload/plugins/toolkit/skills/daily-record/agents/openai.yaml +4 -0
- package/payload/plugins/toolkit/skills/daily-record/references/browser-history.md +6 -0
- package/payload/plugins/toolkit/skills/daily-record/references/feishu.md +90 -0
- package/payload/plugins/toolkit/skills/daily-record/references/scheduled-reporting.md +144 -0
- package/payload/plugins/toolkit/skills/daily-record/references/scheduled-task.template.json +15 -0
- package/payload/plugins/toolkit/skills/daily-record/references/suiji-work-records.md +57 -0
- package/payload/plugins/toolkit/skills/daily-record/scripts/feishu.py +280 -0
- package/payload/plugins/toolkit/skills/daily-record/scripts/job.py +416 -0
- package/payload/plugins/toolkit/skills/daily-record/scripts/job_browser.py +77 -0
- package/payload/plugins/toolkit/skills/daily-record/scripts/job_facts.py +132 -0
- package/payload/plugins/toolkit/skills/daily-record/scripts/job_isolation.py +69 -0
- package/payload/plugins/toolkit/skills/daily-record/scripts/job_materials.py +154 -0
- package/payload/plugins/toolkit/skills/daily-record/scripts/job_screen.py +77 -0
- package/payload/plugins/toolkit/skills/daily-record/scripts/job_state.py +309 -0
- package/payload/plugins/toolkit/skills/daily-refactor/SKILL.md +101 -0
- package/payload/plugins/toolkit/skills/daily-refactor/scripts/compare-architecture-reports.mjs +168 -0
- package/payload/plugins/toolkit/skills/debugging-strategies/SKILL.md +38 -0
- package/payload/plugins/toolkit/skills/debugging-strategies/resources/implementation-playbook.md +520 -0
- package/payload/plugins/toolkit/skills/diagnostic-log-debugging/SKILL.md +79 -0
- package/payload/plugins/toolkit/skills/doc-coauthoring/SKILL.md +64 -0
- package/payload/plugins/toolkit/skills/eli5/LICENSE +21 -0
- package/payload/plugins/toolkit/skills/eli5/SKILL.md +18 -0
- package/payload/plugins/toolkit/skills/experience/SKILL.md +71 -0
- package/payload/plugins/toolkit/skills/experience/package.json +13 -0
- package/payload/plugins/toolkit/skills/git-advanced-workflows/SKILL.md +457 -0
- package/payload/plugins/toolkit/skills/github-pr/SKILL.md +109 -0
- package/payload/plugins/toolkit/skills/github-pr/scripts/github-access.mjs +292 -0
- package/payload/plugins/toolkit/skills/github-pr/scripts/preflight.mjs +191 -0
- package/payload/plugins/toolkit/skills/github-pr/scripts/source-worktree.mjs +354 -0
- package/payload/plugins/toolkit/skills/grill-with-docs/SKILL.md +66 -0
- package/payload/plugins/toolkit/skills/grill-with-docs/agents/openai.yaml +6 -0
- package/payload/plugins/toolkit/skills/grilling/SKILL.md +14 -0
- package/payload/plugins/toolkit/skills/handoff/SKILL.md +98 -0
- package/payload/plugins/toolkit/skills/karpathy-guidelines/SKILL.md +73 -0
- package/payload/plugins/toolkit/skills/playwright-cli/SKILL.md +562 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/element-attributes.md +23 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/playwright-tests.md +39 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/request-mocking.md +87 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/running-code.md +240 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/session-management.md +226 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/spec-driven-testing.md +312 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/storage-state.md +275 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/test-generation.md +138 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/tracing.md +142 -0
- package/payload/plugins/toolkit/skills/playwright-cli/references/video-recording.md +157 -0
- package/payload/plugins/toolkit/skills/playwright-cli/templates/standalone.config.json +7 -0
- package/payload/plugins/toolkit/skills/product-exploration/SKILL.md +64 -0
- package/payload/plugins/toolkit/skills/product-exploration/agents/openai.yaml +5 -0
- package/payload/plugins/toolkit/skills/prototype-first-development/SKILL.md +134 -0
- package/payload/plugins/toolkit/skills/prototype-first-development/references/html-prototype-template/README.md +88 -0
- package/payload/plugins/toolkit/skills/prototype-first-development/references/html-prototype-template/app.js +145 -0
- package/payload/plugins/toolkit/skills/prototype-first-development/references/html-prototype-template/index.html +229 -0
- package/payload/plugins/toolkit/skills/prototype-first-development/references/html-prototype-template/mock-state.json +60 -0
- package/payload/plugins/toolkit/skills/prototype-first-development/references/implementation-plan-handoff-template.md +61 -0
- package/payload/plugins/toolkit/skills/prototype-first-development/references/prototype-workflow-checklist.md +64 -0
- package/payload/plugins/toolkit/skills/publish-runweave-server/SKILL.md +64 -0
- package/payload/plugins/toolkit/skills/publish-runweave-server/agents/openai.yaml +4 -0
- package/payload/plugins/toolkit/skills/react-best-practices/AGENTS.md +3227 -0
- package/payload/plugins/toolkit/skills/react-best-practices/README.md +127 -0
- package/payload/plugins/toolkit/skills/react-best-practices/SKILL.md +143 -0
- package/payload/plugins/toolkit/skills/react-best-practices/metadata.json +15 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/advanced/event-handler-refs.md +55 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/advanced/init-once.md +42 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/advanced/use-latest.md +39 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/async/api-routes.md +38 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/async/defer-await.md +80 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/async/dependencies.md +52 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/async/parallel.md +28 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/async/suspense-boundaries.md +99 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/bundle/barrel-imports.md +59 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/bundle/conditional.md +37 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/bundle/defer-third-party.md +49 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/bundle/dynamic-imports.md +35 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/bundle/preload.md +46 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/client/event-listeners.md +78 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/client/localstorage-schema.md +77 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/client/passive-event-listeners.md +48 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/client/swr-dedup.md +56 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/batch-dom-css.md +110 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/cache-function-results.md +80 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/cache-property-access.md +28 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/cache-storage.md +70 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/combine-iterations.md +32 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/early-exit.md +50 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/flatmap-filter.md +55 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/hoist-regexp.md +45 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/index-maps.md +37 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/length-check-first.md +50 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/min-max-loop.md +82 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/set-map-lookups.md +24 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/js/tosorted-immutable.md +57 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/meta/sections.md +46 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/meta/template.md +28 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/activity.md +26 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/animate-svg-wrapper.md +38 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/conditional-render.md +32 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/content-visibility.md +38 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/hoist-jsx.md +36 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/hydration-no-flicker.md +72 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/hydration-suppress-warning.md +26 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/resource-hints.md +89 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/script-defer-async.md +71 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/svg-precision.md +28 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rendering/usetransition-loading.md +75 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/defer-reads.md +39 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/dependencies.md +45 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/derived-state-no-effect.md +40 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/derived-state.md +29 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/functional-setstate.md +77 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/lazy-state-init.md +58 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/memo-with-default-value.md +36 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/memo.md +44 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/move-effect-to-event.md +45 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/no-inline-components.md +83 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/simple-expression-in-memo.md +35 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/transitions.md +40 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/rerender/use-ref-transient-values.md +73 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/server/after-nonblocking.md +74 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/server/auth-actions.md +96 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/server/cache-lru.md +41 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/server/cache-react.md +76 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/server/dedup-props.md +65 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/server/hoist-static-io.md +139 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/server/parallel-fetching.md +83 -0
- package/payload/plugins/toolkit/skills/react-best-practices/rules/server/serialization.md +38 -0
- package/payload/plugins/toolkit/skills/recorded-browser-mcp-verification/SKILL.md +8 -0
- package/payload/plugins/toolkit/skills/recorded-browser-mcp-verification/agents/openai.yaml +6 -0
- package/payload/plugins/toolkit/skills/reproduce-before-fix/SKILL.md +93 -0
- package/payload/plugins/toolkit/skills/reproduce-before-fix/agents/openai.yaml +7 -0
- package/payload/plugins/toolkit/skills/review-only/SKILL.md +72 -0
- package/payload/plugins/toolkit/skills/review-with-runtime-evidence/SKILL.md +134 -0
- package/payload/plugins/toolkit/skills/review-with-runtime-evidence/agents/openai.yaml +7 -0
- package/payload/plugins/toolkit/skills/review-with-runtime-evidence/references/contracts.md +114 -0
- package/payload/plugins/toolkit/skills/review-with-runtime-evidence/scripts/classify-runtime-verdict.mjs +140 -0
- package/payload/plugins/toolkit/skills/review-with-runtime-evidence/scripts/run-static-review.mjs +389 -0
- package/payload/plugins/toolkit/skills/review-with-runtime-evidence/scripts/static-review-contract.mjs +243 -0
- package/payload/plugins/toolkit/skills/run-test-cases/SKILL.md +63 -0
- package/payload/plugins/toolkit/skills/runweave-change-validation/SKILL.md +196 -0
- package/payload/plugins/toolkit/skills/runweave-change-validation/agents/openai.yaml +7 -0
- package/payload/plugins/toolkit/skills/runweave-change-validation/scripts/assert-dev-session-status.mjs +181 -0
- package/payload/plugins/toolkit/skills/runweave-dev-session/SKILL.md +126 -0
- package/payload/plugins/toolkit/skills/runweave-dev-session/agents/openai.yaml +7 -0
- package/payload/plugins/toolkit/skills/runweave-management/SKILL.md +47 -0
- package/payload/plugins/toolkit/skills/scheduled-task/SKILL.md +35 -0
- package/payload/plugins/toolkit/skills/shadcn/SKILL.md +245 -0
- package/payload/plugins/toolkit/skills/shadcn/agents/openai.yml +5 -0
- package/payload/plugins/toolkit/skills/shadcn/assets/shadcn-small.png +0 -0
- package/payload/plugins/toolkit/skills/shadcn/assets/shadcn.png +0 -0
- package/payload/plugins/toolkit/skills/shadcn/cli.md +276 -0
- package/payload/plugins/toolkit/skills/shadcn/customization.md +209 -0
- package/payload/plugins/toolkit/skills/shadcn/evals/evals.json +47 -0
- package/payload/plugins/toolkit/skills/shadcn/mcp.md +94 -0
- package/payload/plugins/toolkit/skills/shadcn/rules/base-vs-radix.md +310 -0
- package/payload/plugins/toolkit/skills/shadcn/rules/composition.md +197 -0
- package/payload/plugins/toolkit/skills/shadcn/rules/forms.md +198 -0
- package/payload/plugins/toolkit/skills/shadcn/rules/icons.md +101 -0
- package/payload/plugins/toolkit/skills/shadcn/rules/styling.md +163 -0
- package/payload/plugins/toolkit/skills/suiji/SKILL.md +54 -0
- package/payload/plugins/toolkit/skills/suiji/references/api.md +72 -0
- package/payload/plugins/toolkit/skills/suiji/references/source-adapter.md +40 -0
- package/payload/plugins/toolkit/skills/suiji/references/work-records.md +36 -0
- package/payload/plugins/toolkit/skills/suiji/scripts/source_adapter.py +46 -0
- package/payload/plugins/toolkit/skills/suiji/scripts/suiji.py +358 -0
- package/payload/plugins/toolkit/skills/suiji/scripts/work_records.py +328 -0
- package/payload/plugins/toolkit/skills/suiji/scripts/work_reports.py +75 -0
- package/payload/plugins/toolkit/skills/sync-branch-hard-reset/SKILL.md +59 -0
- package/payload/plugins/toolkit/skills/update-runweave-backend/SKILL.md +90 -0
- package/payload/plugins/toolkit/skills/update-runweave-backend/agents/openai.yaml +4 -0
- package/payload/plugins/toolkit/skills/update-runweave-backend/references/npm-update.md +68 -0
- package/payload/plugins/toolkit/skills/update-runweave-backend/references/systemd.md +34 -0
- package/payload/plugins/toolkit/skills/update-runweave-desktop/SKILL.md +102 -0
- package/payload/plugins/toolkit/skills/update-runweave-ios/SKILL.md +16 -0
- package/payload/plugins/toolkit/skills/update-runweave-ios/references/ios-wireless-recovery.md +54 -0
- package/payload/plugins/toolkit/skills/using-rw/SKILL.md +265 -0
- package/payload/plugins/toolkit/skills/write-plan/SKILL.md +72 -0
- package/payload/plugins/toolkit/skills/write-test-cases/SKILL.md +100 -0
- package/payload/plugins/toolkit/skills/write-test-cases/assets/test-plan-template.yaml +15 -0
- package/payload/plugins/toolkit/skills/write-test-cases/references/coverage-checklist.md +75 -0
- package/payload/plugins/toolkit/skills/write-test-cases/references/design-techniques.md +91 -0
- package/payload/plugins/toolkit/skills/youtube-reading/SKILL.md +35 -0
- package/payload/plugins/toolkit/skills/youtube-reading/agents/openai.yaml +4 -0
- package/payload/plugins/toolkit/skills/youtube-reading/assets/runtime-lock.json +92 -0
- package/payload/plugins/toolkit/skills/youtube-reading/references/content-contract.md +52 -0
- package/payload/plugins/toolkit/skills/youtube-reading/references/setup.md +70 -0
- package/payload/plugins/toolkit/skills/youtube-reading/requirements.lock +9 -0
- package/payload/plugins/toolkit/skills/youtube-reading/scripts/artifacts.py +206 -0
- package/payload/plugins/toolkit/skills/youtube-reading/scripts/runtime.py +424 -0
- package/payload/plugins/toolkit/skills/youtube-reading/scripts/youtube_reading.py +314 -0
- package/payload/plugins/toolkit-release.json +1 -0
- package/payload/scripts/toolkit/codex-state.mjs +75 -0
- package/payload/scripts/toolkit/release.mjs +210 -0
- package/payload/scripts/toolkit/sync-runtime.mjs +108 -0
- package/payload/scripts/toolkit/sync.mjs +585 -0
- package/payload/frontend/dist/assets/channel-Bf3IeONI.js +0 -1
- package/payload/frontend/dist/assets/classDiagram-6PBFFD2Q-CFsG2SvG.js +0 -1
- package/payload/frontend/dist/assets/classDiagram-v2-HSJHXN6E-CFsG2SvG.js +0 -1
- package/payload/frontend/dist/assets/clone-CeQXm2YN.js +0 -1
- package/payload/frontend/dist/assets/connection-XriXysSc.js +0 -12
- package/payload/frontend/dist/assets/main-Cg6Oo1xK.css +0 -33
- package/payload/frontend/dist/assets/main-H5R-3_w1.js +0 -696
- package/payload/frontend/dist/assets/stateDiagram-v2-QKLJ7IA2-CzpdUl_0.js +0 -1
- package/payload/frontend/dist/assets/suiji-CO_L5W1X.js +0 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""Versioned artifacts, atomic writes and mechanical (not semantic) review gates."""
|
|
2
|
+
import contextlib
|
|
3
|
+
import fcntl
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import re
|
|
9
|
+
import tempfile
|
|
10
|
+
from datetime import datetime, timezone
|
|
11
|
+
|
|
12
|
+
SCHEMA_VERSION = 1
|
|
13
|
+
PROMPT_VERSION = '1'
|
|
14
|
+
CONTRACT_VERSION = '1'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class JobError(Exception):
|
|
18
|
+
def __init__(self, code, message):
|
|
19
|
+
super().__init__(message)
|
|
20
|
+
self.code = code
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def now():
|
|
24
|
+
return datetime.now(timezone.utc).isoformat()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def digest(path):
|
|
28
|
+
h = hashlib.sha256()
|
|
29
|
+
with Path(path).open('rb') as f:
|
|
30
|
+
for block in iter(lambda: f.read(1024 * 1024), b''):
|
|
31
|
+
h.update(block)
|
|
32
|
+
return h.hexdigest()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def identity(value):
|
|
36
|
+
return hashlib.sha256(json.dumps(value, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def read_json(path):
|
|
40
|
+
return json.loads(Path(path).read_text(encoding='utf-8'))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def atomic_write(path, content):
|
|
44
|
+
path = Path(path)
|
|
45
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
46
|
+
fd, tmp = tempfile.mkstemp(prefix='.' + path.name, dir=path.parent)
|
|
47
|
+
try:
|
|
48
|
+
with os.fdopen(fd, 'w', encoding='utf-8') as f:
|
|
49
|
+
f.write(content)
|
|
50
|
+
f.flush()
|
|
51
|
+
os.fsync(f.fileno())
|
|
52
|
+
os.replace(tmp, path)
|
|
53
|
+
finally:
|
|
54
|
+
if os.path.exists(tmp):
|
|
55
|
+
os.unlink(tmp)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def write_json(path, value):
|
|
59
|
+
atomic_write(path, json.dumps(value, ensure_ascii=False, indent=2) + '\n')
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@contextlib.contextmanager
|
|
63
|
+
def job_lock(directory):
|
|
64
|
+
directory = Path(directory)
|
|
65
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
66
|
+
# Keep the inode: flock releases on death, including SIGKILL, without stale
|
|
67
|
+
# PID reuse or lock-unlink races between competing writers.
|
|
68
|
+
with (directory / '.lock').open('a+') as f:
|
|
69
|
+
try:
|
|
70
|
+
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
71
|
+
except BlockingIOError:
|
|
72
|
+
raise JobError('JOB_BUSY', '任务正在运行,请稍后 resume。')
|
|
73
|
+
try:
|
|
74
|
+
f.seek(0)
|
|
75
|
+
f.truncate()
|
|
76
|
+
f.write(json.dumps({'pid': os.getpid(), 'acquired_at': now()}))
|
|
77
|
+
f.flush()
|
|
78
|
+
yield
|
|
79
|
+
finally:
|
|
80
|
+
fcntl.flock(f, fcntl.LOCK_UN)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def validate_source(source):
|
|
84
|
+
if not isinstance(source, dict) or source.get('schema_version') != SCHEMA_VERSION:
|
|
85
|
+
raise JobError('SOURCE_SCHEMA', '不支持的 source schema。')
|
|
86
|
+
previous = -1
|
|
87
|
+
ids = set()
|
|
88
|
+
if not isinstance(source.get('segments'), list) or not all(isinstance(s, dict) for s in source['segments']):
|
|
89
|
+
raise JobError('SOURCE_SCHEMA', 'segments 必须为段落对象数组。')
|
|
90
|
+
for s in source['segments']:
|
|
91
|
+
if (not isinstance(s['id'], str) or s['id'] in ids or
|
|
92
|
+
not isinstance(s['text'], str) or not s['text'].strip() or
|
|
93
|
+
not isinstance(s['start_ms'], int) or not isinstance(s['end_ms'], int) or
|
|
94
|
+
s['start_ms'] < 0 or s['start_ms'] < previous or s['end_ms'] <= s['start_ms']):
|
|
95
|
+
raise JobError('SOURCE_INVALID', '来源 ID、时间顺序或文本无效。')
|
|
96
|
+
ids.add(s['id'])
|
|
97
|
+
previous = s['start_ms']
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def chunk_source(source_path, work_dir):
|
|
101
|
+
source = read_json(source_path)
|
|
102
|
+
validate_source(source)
|
|
103
|
+
segments = source['segments']
|
|
104
|
+
groups, current, size = [], [], 0
|
|
105
|
+
for s in segments:
|
|
106
|
+
if len(s['text']) > 6000:
|
|
107
|
+
raise JobError('SEGMENT_TOO_LARGE', '单个来源段超过 6000 字符;先按来源时间拆段。')
|
|
108
|
+
if current and size + len(s['text']) > 6000:
|
|
109
|
+
groups.append(current)
|
|
110
|
+
current, size = [], 0
|
|
111
|
+
current.append(s)
|
|
112
|
+
size += len(s['text'])
|
|
113
|
+
if current:
|
|
114
|
+
groups.append(current)
|
|
115
|
+
out, offset = [], 0
|
|
116
|
+
root = Path(work_dir) / 'chunks'
|
|
117
|
+
root.mkdir(parents=True, exist_ok=True)
|
|
118
|
+
for i, group in enumerate(groups):
|
|
119
|
+
path = root / f'{i:04d}.json'
|
|
120
|
+
write_json(path, {'schema_version': 1, 'source_sha256': digest(source_path),
|
|
121
|
+
'core': group, 'context_read_only': {
|
|
122
|
+
'before': segments[max(0, offset-2):offset],
|
|
123
|
+
'after': segments[offset+len(group):offset+len(group)+2]}})
|
|
124
|
+
out.append({'path': str(path), 'sha256': digest(path), 'segment_ids': [s['id'] for s in group]})
|
|
125
|
+
offset += len(group)
|
|
126
|
+
for stale in root.glob('*.json'):
|
|
127
|
+
if stale.name not in {Path(x['path']).name for x in out}:
|
|
128
|
+
stale.unlink()
|
|
129
|
+
return out
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def timestamp(ms):
|
|
133
|
+
seconds = ms // 1000
|
|
134
|
+
return f'{seconds//3600:02d}:{seconds//60%60:02d}:{seconds%60:02d}'
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def plain(text):
|
|
138
|
+
# External text is data, including Markdown headings and HTML from videos.
|
|
139
|
+
return re.sub(r'([\\*_{}\[\]<>#])', r'\\\1', ' '.join(text.split())).replace(chr(96), '\\' + chr(96))
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def validate_review(source, review, manifest, work_dir):
|
|
143
|
+
validate_source(source)
|
|
144
|
+
if not isinstance(review, dict):
|
|
145
|
+
raise JobError('REVIEW_SCHEMA', 'review 必须为 JSON 对象。')
|
|
146
|
+
if (review.get('schema_version') != 1 or
|
|
147
|
+
review.get('source_sha256') != manifest['source_sha256'] or
|
|
148
|
+
review.get('prompt_version') != PROMPT_VERSION or
|
|
149
|
+
review.get('contract_version') != CONTRACT_VERSION):
|
|
150
|
+
raise JobError('REVIEW_VERSION', '校对来源摘要或处理版本不匹配。')
|
|
151
|
+
rows = review.get('segments', [])
|
|
152
|
+
if not isinstance(rows, list) or not all(isinstance(r, dict) for r in rows):
|
|
153
|
+
raise JobError('REVIEW_SCHEMA', 'segments 必须为校对对象数组。')
|
|
154
|
+
if [r.get('segment_id') for r in rows] != [s['id'] for s in source['segments']]:
|
|
155
|
+
raise JobError('REVIEW_COVERAGE', '每个来源段必须按顺序恰好映射一次。')
|
|
156
|
+
kept = {r['segment_id'] for r in rows if r.get('action') != 'remove_duplicate'}
|
|
157
|
+
by_id = {s['id']: s for s in source['segments']}
|
|
158
|
+
changes = []
|
|
159
|
+
for s, r in zip(source['segments'], rows):
|
|
160
|
+
action, text = r.get('action'), r.get('text_zh')
|
|
161
|
+
if action not in {'keep', 'correct', 'translate', 'uncertain', 'remove_duplicate'} or not isinstance(text, str):
|
|
162
|
+
raise JobError('REVIEW_INVALID', '无效的 action 或 text_zh。')
|
|
163
|
+
if not isinstance(r.get('reason'), str) or (action != 'keep' and not r['reason'].strip()):
|
|
164
|
+
raise JobError('REVIEW_REASON', '修改必须解释依据。')
|
|
165
|
+
if action == 'remove_duplicate':
|
|
166
|
+
record_id = r.get('retranscription_id', '')
|
|
167
|
+
if not re.fullmatch(r'retry-\d+-\d+', record_id):
|
|
168
|
+
raise JobError('DUPLICATE_EVIDENCE', '删除重复必须引用局部重识别记录。')
|
|
169
|
+
p = Path(work_dir) / 'retranscriptions' / (record_id + '.json')
|
|
170
|
+
evidence = read_json(p) if p.exists() else {}
|
|
171
|
+
retained = by_id.get(r.get('retained_segment_id'))
|
|
172
|
+
if (r.get('retained_segment_id') not in kept or not retained or
|
|
173
|
+
evidence.get('source_sha256') != manifest['source_sha256'] or
|
|
174
|
+
not evidence.get('segments') or
|
|
175
|
+
not all(evidence.get('start_ms', 1) <= x['start_ms'] < x['end_ms'] <= evidence.get('end_ms', 0)
|
|
176
|
+
for x in (s, retained))):
|
|
177
|
+
raise JobError('DUPLICATE_EVIDENCE', '证据必须覆盖删除段和保留段且对应当前来源。')
|
|
178
|
+
elif not text.strip():
|
|
179
|
+
raise JobError('REVIEW_EMPTY', '正文不能为空。')
|
|
180
|
+
if action == 'keep' and text != s['text']:
|
|
181
|
+
raise JobError('REVIEW_ACTION', 'keep 不得修改原文。')
|
|
182
|
+
if action == 'uncertain' and not re.search(r'\[听辨不清,\d{2,}:[0-5]\d:[0-5]\d\]', text):
|
|
183
|
+
raise JobError('UNCERTAINTY_MARKER', '不确定段必须保留带时间的听辨不清标记。')
|
|
184
|
+
before = re.findall(r'\d+(?:[.,]\d+)*|不|没|无|未|别|not\b|never\b|no\b', s['text'], re.I)
|
|
185
|
+
after = re.findall(r'\d+(?:[.,]\d+)*|不|没|无|未|别|not\b|never\b|no\b', text, re.I)
|
|
186
|
+
if before != after and action != 'remove_duplicate':
|
|
187
|
+
if not str(r.get('reason', '')).strip():
|
|
188
|
+
raise JobError('INVARIANT_EXPLANATION', '数字或否定变化需要解释。')
|
|
189
|
+
changes.append({'segment_id': s['id'], 'before': before, 'after': after, 'reason': r['reason']})
|
|
190
|
+
return changes
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def render(manifest, source, review, guide):
|
|
194
|
+
if not guide.strip() or re.search(r'^\s*#{1,6}\s|<\s*/?\s*h[1-6]\b', guide, re.M | re.I):
|
|
195
|
+
raise JobError('GUIDE_STRUCTURE', '导读必须为不带标题的正文。')
|
|
196
|
+
lines = ['# ' + plain(manifest['title']), '',
|
|
197
|
+
f"来源:{manifest['canonical_url']};频道:{plain(manifest.get('channel') or '未知')};时长:{timestamp(manifest['duration_ms'])}", '']
|
|
198
|
+
if manifest.get('quality_hints') or any(r['action'] == 'uncertain' for r in review['segments']):
|
|
199
|
+
lines += ['说明:存在待核对片段;材料完整性与听辨标记请结合原视频核对。', '']
|
|
200
|
+
lines += ['## 导读', '', plain(guide), '', '## 正文', '']
|
|
201
|
+
for s, r in zip(source['segments'], review['segments']):
|
|
202
|
+
if r['action'] != 'remove_duplicate':
|
|
203
|
+
lines += [f"[{timestamp(s['start_ms'])}] {plain(r['text_zh'])}", '']
|
|
204
|
+
if not source['segments']:
|
|
205
|
+
lines += ['未识别到可确认的口述内容。', '']
|
|
206
|
+
return '\n'.join(lines)
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
"""Private macOS runtime and bounded network/ASR operations. No shell commands."""
|
|
2
|
+
import importlib.metadata
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import platform
|
|
7
|
+
import re
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
import tarfile
|
|
12
|
+
import time
|
|
13
|
+
import uuid
|
|
14
|
+
import wave
|
|
15
|
+
|
|
16
|
+
from artifacts import JobError, digest, identity, job_lock, now, read_json, write_json
|
|
17
|
+
|
|
18
|
+
SKILL_ROOT = Path(__file__).resolve().parent.parent
|
|
19
|
+
DEFAULT_ROOT = Path.home() / 'Library/Application Support/youtube-reading'
|
|
20
|
+
LOCK = read_json(SKILL_ROOT / 'assets/runtime-lock.json')
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def run(args, log, timeout=120):
|
|
24
|
+
log = Path(log)
|
|
25
|
+
log.parent.mkdir(parents=True, exist_ok=True)
|
|
26
|
+
with log.open('a', encoding='utf-8') as f:
|
|
27
|
+
try:
|
|
28
|
+
p = subprocess.run([str(a) for a in args], stdout=f, stderr=f, timeout=timeout)
|
|
29
|
+
except subprocess.TimeoutExpired:
|
|
30
|
+
raise JobError('PROCESS_TIMEOUT', f'进程超时;日志:{log}')
|
|
31
|
+
if p.returncode:
|
|
32
|
+
raise JobError('PROCESS_FAILED', f'进程退出 {p.returncode};日志:{log}')
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def active(root):
|
|
36
|
+
path = Path(root) / 'active.json'
|
|
37
|
+
if not path.exists():
|
|
38
|
+
raise JobError('RUNTIME_MISSING', '尚未安装专用运行时,请执行 setup。')
|
|
39
|
+
release = read_json(path)['release']
|
|
40
|
+
if not re.fullmatch(r'[a-zA-Z0-9-]+', release):
|
|
41
|
+
raise JobError('RUNTIME_INVALID', '运行时版本指针无效。')
|
|
42
|
+
return Path(root) / 'releases' / release
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def tool_version(tool):
|
|
46
|
+
path = shutil.which(tool)
|
|
47
|
+
if not path:
|
|
48
|
+
return {'path': None, 'version': None}
|
|
49
|
+
flag = '-version' if tool in {'ffmpeg', 'ffprobe'} else '--version'
|
|
50
|
+
try:
|
|
51
|
+
p = subprocess.run([path, flag], capture_output=True, text=True, timeout=15)
|
|
52
|
+
return {'path': path, 'version': (p.stdout or p.stderr).splitlines()[0]}
|
|
53
|
+
except (OSError, subprocess.SubprocessError, IndexError):
|
|
54
|
+
return {'path': path, 'version': None}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def doctor(root=DEFAULT_ROOT, release=None):
|
|
58
|
+
issues, checks = [], {}
|
|
59
|
+
if platform.system() != 'Darwin' or platform.machine() != 'arm64':
|
|
60
|
+
issues.append('requires macOS Apple Silicon')
|
|
61
|
+
if sys.version_info < (3, 10):
|
|
62
|
+
issues.append('requires Python >=3.10')
|
|
63
|
+
for tool in ('ffmpeg', 'ffprobe', 'cmake', 'node', 'clang', 'curl'):
|
|
64
|
+
checks[tool] = tool_version(tool)
|
|
65
|
+
if not checks[tool]['version']:
|
|
66
|
+
issues.append('missing tool: ' + tool)
|
|
67
|
+
for tool, minimum in [('ffmpeg', (7, 0)), ('ffprobe', (7, 0)), ('node', (22, 0)), ('cmake', (3, 21))]:
|
|
68
|
+
version = checks[tool]['version'] or ''
|
|
69
|
+
match = re.search(r'(\d+)\.(\d+)', version)
|
|
70
|
+
if match and tuple(map(int, match.groups())) < minimum:
|
|
71
|
+
issues.append(f'{tool} requires >= {minimum[0]}.{minimum[1]}')
|
|
72
|
+
try:
|
|
73
|
+
release = Path(release) if release else active(root)
|
|
74
|
+
receipt = read_json(release / 'receipt.json')
|
|
75
|
+
if receipt['lock_sha256'] != identity(LOCK):
|
|
76
|
+
issues.append('runtime lock changed; run setup')
|
|
77
|
+
for rel, expected in receipt['files'].items():
|
|
78
|
+
file = release / rel
|
|
79
|
+
if not file.is_file() or digest(file) != expected:
|
|
80
|
+
issues.append('checksum mismatch: ' + rel)
|
|
81
|
+
for model in LOCK['models']:
|
|
82
|
+
file = release / 'models' / model['name']
|
|
83
|
+
checks[model['name']] = {'sha256': digest(file) if file.exists() else None,
|
|
84
|
+
'expected': model['sha256']}
|
|
85
|
+
if checks[model['name']]['sha256'] != model['sha256']:
|
|
86
|
+
issues.append('model checksum mismatch: ' + model['name'])
|
|
87
|
+
code = 'import importlib.metadata,json; print(json.dumps({n:importlib.metadata.version(n) for n in ' + repr([x['name'] for x in LOCK['python_packages']]) + '}))'
|
|
88
|
+
p = subprocess.run([str(release / 'venv/bin/python'), '-c', code], capture_output=True, text=True, timeout=20)
|
|
89
|
+
versions = json.loads(p.stdout) if p.returncode == 0 else {}
|
|
90
|
+
checks['python_packages'] = versions
|
|
91
|
+
for x in LOCK['python_packages']:
|
|
92
|
+
if versions.get(x['name']) != x['version']:
|
|
93
|
+
issues.append('package version mismatch: ' + x['name'])
|
|
94
|
+
binary = release / 'whisper/build/bin/whisper-cli'
|
|
95
|
+
version = subprocess.run([str(binary), '--version'], capture_output=True, text=True, timeout=15)
|
|
96
|
+
checks['whisper_binary_version'] = (version.stdout + version.stderr).strip()
|
|
97
|
+
if version.returncode or LOCK['whisper']['version'] not in checks['whisper_binary_version']:
|
|
98
|
+
issues.append('whisper binary version mismatch')
|
|
99
|
+
checks['release'] = str(release)
|
|
100
|
+
checks['whisper'] = LOCK['whisper']
|
|
101
|
+
except (JobError, OSError, ValueError, KeyError, subprocess.SubprocessError) as e:
|
|
102
|
+
issues.append(str(e))
|
|
103
|
+
return {'ok': not issues, 'runtime_root': str(Path(root).resolve()), 'checks': checks, 'issues': issues}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def download(url, path, sha256, log):
|
|
107
|
+
path = Path(path)
|
|
108
|
+
if path.exists() and digest(path) == sha256:
|
|
109
|
+
return
|
|
110
|
+
temp = path.with_suffix(path.suffix + '.part')
|
|
111
|
+
run(['curl', '-4', '--http1.1', '--fail', '--location', '--silent', '--show-error',
|
|
112
|
+
'--connect-timeout', '15', '--max-time', '900', '--retry', '2',
|
|
113
|
+
'--output', temp, url], log, timeout=2750)
|
|
114
|
+
if digest(temp) != sha256:
|
|
115
|
+
raise JobError('CHECKSUM_MISMATCH', f'下载摘要不匹配:{path.name}')
|
|
116
|
+
os.replace(temp, path)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def setup(root=DEFAULT_ROOT):
|
|
120
|
+
root = Path(root).expanduser().resolve()
|
|
121
|
+
with job_lock(root):
|
|
122
|
+
existing = doctor(root)
|
|
123
|
+
if existing['ok']:
|
|
124
|
+
return {**existing, 'cache_hit': True}
|
|
125
|
+
missing = [x for x in existing['issues'] if x.startswith(('requires ', 'missing tool:')) or ' requires >= ' in x]
|
|
126
|
+
if missing:
|
|
127
|
+
raise JobError('SETUP_PREREQUISITE', '; '.join(missing))
|
|
128
|
+
release = root / 'releases' / (identity(LOCK)[:12] + '-' + uuid.uuid4().hex[:8])
|
|
129
|
+
release.mkdir(parents=True)
|
|
130
|
+
cache = root / 'downloads'
|
|
131
|
+
cache.mkdir(exist_ok=True)
|
|
132
|
+
log = release / 'setup.log'
|
|
133
|
+
run([sys.executable, '-m', 'venv', release / 'venv'], log)
|
|
134
|
+
for x in LOCK['python_packages']:
|
|
135
|
+
download(x['url'], cache / x['filename'], x['sha256'], log)
|
|
136
|
+
run([release / 'venv/bin/python', '-m', 'pip', 'install', '--no-index', '--no-deps',
|
|
137
|
+
'--require-hashes', '--find-links', cache, '-r', SKILL_ROOT / 'requirements.lock'], log)
|
|
138
|
+
archive = cache / (LOCK['whisper']['commit'] + '.tar.gz')
|
|
139
|
+
download(LOCK['whisper']['url'], archive, LOCK['whisper']['sha256'], log)
|
|
140
|
+
source = release / 'whisper'
|
|
141
|
+
source.mkdir()
|
|
142
|
+
with tarfile.open(archive) as tar:
|
|
143
|
+
# Extract files only, dropping archive prefix and forbidding links/traversal.
|
|
144
|
+
for member in tar.getmembers():
|
|
145
|
+
if not member.isfile():
|
|
146
|
+
continue
|
|
147
|
+
rel = Path(*Path(member.name).parts[1:])
|
|
148
|
+
if rel.is_absolute() or '..' in rel.parts:
|
|
149
|
+
raise JobError('ARCHIVE_INVALID', '源码归档含不安全路径。')
|
|
150
|
+
dest = source / rel
|
|
151
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
152
|
+
with tar.extractfile(member) as src, dest.open('wb') as out:
|
|
153
|
+
shutil.copyfileobj(src, out)
|
|
154
|
+
run(['cmake', '-S', source, '-B', source / 'build', '-DCMAKE_BUILD_TYPE=Release',
|
|
155
|
+
'-DGGML_METAL=ON', '-DWHISPER_BUILD_TESTS=OFF', '-DWHISPER_BUILD_SERVER=OFF',
|
|
156
|
+
'-DWHISPER_BUILD_COMMIT=' + LOCK['whisper']['commit']], log, 180)
|
|
157
|
+
run(['cmake', '--build', source / 'build', '--config', 'Release', '-j', '4'], log, 600)
|
|
158
|
+
(release / 'models').mkdir()
|
|
159
|
+
for model in LOCK['models']:
|
|
160
|
+
download(model['url'], cache / model['name'], model['sha256'], log)
|
|
161
|
+
shutil.copy2(cache / model['name'], release / 'models' / model['name'])
|
|
162
|
+
files = {}
|
|
163
|
+
for file in (source / 'build').rglob('*'):
|
|
164
|
+
if file.is_file() and (file.suffix == '.dylib' or file.name == 'whisper-cli'):
|
|
165
|
+
files[str(file.relative_to(release))] = digest(file)
|
|
166
|
+
write_json(release / 'receipt.json', {'schema_version': 1, 'lock_sha256': identity(LOCK),
|
|
167
|
+
'installed_at': now(), 'files': files})
|
|
168
|
+
result = doctor(root, release)
|
|
169
|
+
if not result['ok']:
|
|
170
|
+
raise JobError('SETUP_VERIFICATION', '; '.join(result['issues']))
|
|
171
|
+
write_json(root / 'active.json', {'release': release.name})
|
|
172
|
+
return result
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def activate_python(root):
|
|
176
|
+
release = active(root)
|
|
177
|
+
site = list((release / 'venv/lib').glob('python*/site-packages'))
|
|
178
|
+
if not site:
|
|
179
|
+
raise JobError('RUNTIME_MISSING', '缺少 Python 专用环境。')
|
|
180
|
+
sys.path.insert(0, str(site[0]))
|
|
181
|
+
return release
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class NetworkAdapter:
|
|
185
|
+
"""Inject this boundary for isolated failures; production uses real requests."""
|
|
186
|
+
def __init__(self, root, work):
|
|
187
|
+
activate_python(root)
|
|
188
|
+
import requests
|
|
189
|
+
import urllib3.util.connection
|
|
190
|
+
urllib3.util.connection.HAS_IPV6 = False
|
|
191
|
+
class Session(requests.Session):
|
|
192
|
+
def request(self, *args, **kwargs):
|
|
193
|
+
kwargs['timeout'] = 15
|
|
194
|
+
for attempt in range(3):
|
|
195
|
+
try:
|
|
196
|
+
response = super().request(*args, **kwargs)
|
|
197
|
+
response.raise_for_status()
|
|
198
|
+
return response
|
|
199
|
+
except (requests.Timeout, requests.ConnectionError):
|
|
200
|
+
if attempt == 2:
|
|
201
|
+
raise
|
|
202
|
+
self.session = Session()
|
|
203
|
+
self.work = Path(work)
|
|
204
|
+
|
|
205
|
+
def metadata(self, url):
|
|
206
|
+
import yt_dlp
|
|
207
|
+
with yt_dlp.YoutubeDL(self.options()) as ydl:
|
|
208
|
+
return ydl.extract_info(url, download=False)
|
|
209
|
+
|
|
210
|
+
def options(self):
|
|
211
|
+
adapter = self
|
|
212
|
+
class Logger:
|
|
213
|
+
def debug(self, msg):
|
|
214
|
+
pass
|
|
215
|
+
def warning(self, msg):
|
|
216
|
+
self.error(msg)
|
|
217
|
+
def error(self, msg):
|
|
218
|
+
with (adapter.work / 'network.log').open('a') as f:
|
|
219
|
+
f.write(msg + '\n')
|
|
220
|
+
return {'quiet': True, 'no_warnings': True, 'logger': Logger(), 'noplaylist': True,
|
|
221
|
+
'source_address': '0.0.0.0', 'socket_timeout': 15, 'retries': 2,
|
|
222
|
+
'fragment_retries': 2, 'extractor_retries': 2, 'file_access_retries': 2,
|
|
223
|
+
'js_runtimes': {'node': {'path': shutil.which('node')}},
|
|
224
|
+
'cachedir': str(self.work / 'yt-cache')}
|
|
225
|
+
|
|
226
|
+
def transcripts(self, video_id, language):
|
|
227
|
+
from youtube_transcript_api import YouTubeTranscriptApi
|
|
228
|
+
from youtube_transcript_api._errors import TranscriptsDisabled, NoTranscriptFound
|
|
229
|
+
try:
|
|
230
|
+
tracks = list(YouTubeTranscriptApi(http_client=self.session).list(video_id))
|
|
231
|
+
except (TranscriptsDisabled, NoTranscriptFound):
|
|
232
|
+
return {'tracks': [], 'segments': [], 'language': language, 'source_kind': None}
|
|
233
|
+
inventory = [{'language': t.language_code, 'generated': t.is_generated} for t in tracks]
|
|
234
|
+
# A known original language is mandatory; do not choose translated manual tracks.
|
|
235
|
+
prefix = (language or '').split('-')[0]
|
|
236
|
+
matching = [t for t in tracks if prefix and t.language_code.split('-')[0] == prefix]
|
|
237
|
+
matching.sort(key=lambda t: t.is_generated)
|
|
238
|
+
if not matching:
|
|
239
|
+
return {'tracks': inventory, 'segments': [], 'language': language, 'source_kind': None}
|
|
240
|
+
t = matching[0]
|
|
241
|
+
rows = t.fetch().to_raw_data()
|
|
242
|
+
return {'tracks': inventory, 'segments': rows, 'language': t.language_code,
|
|
243
|
+
'source_kind': 'automatic_caption' if t.is_generated else 'manual_caption'}
|
|
244
|
+
|
|
245
|
+
def audio(self, url):
|
|
246
|
+
import yt_dlp
|
|
247
|
+
options = {**self.options(), 'format': 'bestaudio/best',
|
|
248
|
+
'outtmpl': str(self.work / 'audio.%(ext)s')}
|
|
249
|
+
with yt_dlp.YoutubeDL(options) as ydl:
|
|
250
|
+
info = ydl.extract_info(url, download=True)
|
|
251
|
+
return Path(ydl.prepare_filename(info))
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def acquire_metadata(url, adapter):
|
|
255
|
+
# Adapters own request retries (three attempts, 15 s each). Do not multiply retries.
|
|
256
|
+
try:
|
|
257
|
+
return adapter.metadata(url)
|
|
258
|
+
except Exception as e:
|
|
259
|
+
name = type(e).__name__
|
|
260
|
+
code = 'NETWORK_TIMEOUT' if 'timeout' in name.lower() else 'ACQUISITION_DENIED'
|
|
261
|
+
raise JobError(code, '获取元数据失败:' + name) from e
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def convert_audio(audio, work):
|
|
265
|
+
dest = Path(work) / 'audio.wav'
|
|
266
|
+
stamp = Path(work) / 'audio-conversion.json'
|
|
267
|
+
input_hash = digest(audio)
|
|
268
|
+
if stamp.exists() and dest.exists():
|
|
269
|
+
saved = read_json(stamp)
|
|
270
|
+
if saved.get('input_sha256') == input_hash and saved.get('sha256') == digest(dest):
|
|
271
|
+
return dest
|
|
272
|
+
temp = dest.with_name('audio.pending.wav')
|
|
273
|
+
run(['ffmpeg', '-v', 'error', '-y', '-i', audio, '-ar', '16000', '-ac', '1', '-c:a', 'pcm_s16le', temp],
|
|
274
|
+
Path(work) / 'ffmpeg.log', 600)
|
|
275
|
+
os.replace(temp, dest)
|
|
276
|
+
write_json(stamp, {'input_sha256': input_hash, 'sha256': digest(dest)})
|
|
277
|
+
return dest
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def audio_duration(path):
|
|
281
|
+
with wave.open(str(path), 'rb') as wav:
|
|
282
|
+
return round(wav.getnframes() / wav.getframerate() * 1000)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def transcribe_audio(audio_path, work_dir, options):
|
|
286
|
+
"""Same resumable core for CLI and local audio acceptance. options: runtime_root,
|
|
287
|
+
language (auto default), start_ms/end_ms, vad, timeout_seconds, on_chunk callback.
|
|
288
|
+
Each core <=600 s; reconcile unowned boundary candidates after all cores finish.
|
|
289
|
+
"""
|
|
290
|
+
work = Path(work_dir)
|
|
291
|
+
work.mkdir(parents=True, exist_ok=True)
|
|
292
|
+
release = active(options.get('runtime_root', DEFAULT_ROOT))
|
|
293
|
+
duration = audio_duration(audio_path)
|
|
294
|
+
start = options.get('start_ms', 0)
|
|
295
|
+
end = min(options.get('end_ms', duration), duration)
|
|
296
|
+
if not 0 <= start < end:
|
|
297
|
+
raise JobError('AUDIO_RANGE', '无效音频时间区间。')
|
|
298
|
+
settings = {k: v for k, v in options.items() if k not in {'on_chunk', 'runtime_root'}}
|
|
299
|
+
key = identity({'audio_sha256': digest(audio_path), 'lock': identity(LOCK),
|
|
300
|
+
'settings': settings, 'boundary_version': 1})
|
|
301
|
+
result, boundary_candidates = [], []
|
|
302
|
+
for core_start in range(start, end, 600000):
|
|
303
|
+
core_end = min(core_start + 600000, end)
|
|
304
|
+
context = options.get('context_ms', 2000)
|
|
305
|
+
clip_start = max(0, core_start - context)
|
|
306
|
+
clip_end = min(duration, core_end + context)
|
|
307
|
+
name = f'{core_start}-{core_end}'
|
|
308
|
+
directory = work / key[:16]
|
|
309
|
+
directory.mkdir(exist_ok=True)
|
|
310
|
+
receipt = directory / (name + '.done.json')
|
|
311
|
+
if receipt.exists():
|
|
312
|
+
saved = read_json(receipt)
|
|
313
|
+
output = directory / (name + '.json')
|
|
314
|
+
if saved.get('key') == key and output.exists() and digest(output) == saved['sha256']:
|
|
315
|
+
result.extend(saved['segments'])
|
|
316
|
+
boundary_candidates.extend(saved['boundary_candidates'])
|
|
317
|
+
if options.get('on_chunk'):
|
|
318
|
+
options['on_chunk'](saved, True)
|
|
319
|
+
continue
|
|
320
|
+
clip = directory / (name + '.wav')
|
|
321
|
+
with wave.open(str(audio_path), 'rb') as src, wave.open(str(clip), 'wb') as out:
|
|
322
|
+
out.setparams(src.getparams())
|
|
323
|
+
src.setpos(round(clip_start * src.getframerate() / 1000))
|
|
324
|
+
out.writeframes(src.readframes(round((clip_end-clip_start) * src.getframerate() / 1000)))
|
|
325
|
+
output_prefix = directory / name
|
|
326
|
+
timeout = options.get('timeout_seconds') or max(120, (clip_end-clip_start) / 2000)
|
|
327
|
+
args = [release / 'whisper/build/bin/whisper-cli', '-m', release / 'models' / LOCK['models'][0]['name'],
|
|
328
|
+
'-f', clip, '-l', options.get('language', 'auto'), '-t', '4', '-oj', '-of', output_prefix]
|
|
329
|
+
if options.get('vad', True):
|
|
330
|
+
args += ['--vad', '-vm', release / 'models' / LOCK['models'][1]['name']]
|
|
331
|
+
started = time.monotonic()
|
|
332
|
+
try:
|
|
333
|
+
run(args, directory / (name + '.log'), timeout)
|
|
334
|
+
except JobError as e:
|
|
335
|
+
if e.code == 'PROCESS_TIMEOUT':
|
|
336
|
+
raise JobError('ASR_TIMEOUT', str(e)) from e
|
|
337
|
+
raise
|
|
338
|
+
raw = read_json(directory / (name + '.json'))
|
|
339
|
+
rows, candidates = [], []
|
|
340
|
+
for item in raw.get('transcription', []):
|
|
341
|
+
a = clip_start + item['offsets']['from']
|
|
342
|
+
b = min(clip_end, clip_start + item['offsets']['to'])
|
|
343
|
+
text = item['text'].strip()
|
|
344
|
+
if text and b > a and a < core_end and b > core_start:
|
|
345
|
+
target = rows if core_start <= (a+b)/2 < core_end else candidates
|
|
346
|
+
target.append({'start_ms': a, 'end_ms': b, 'text': text,
|
|
347
|
+
'language': raw.get('result', {}).get('language', options.get('language', 'auto')),
|
|
348
|
+
'source_kind': 'ASR', 'core_start_ms': core_start,
|
|
349
|
+
'raw_path': str(directory / (name + '.json'))})
|
|
350
|
+
saved = {'key': key, 'sha256': digest(directory / (name + '.json')), 'segments': rows,
|
|
351
|
+
'boundary_candidates': candidates,
|
|
352
|
+
'core_start_ms': core_start, 'core_end_ms': core_end, 'timeout_seconds': timeout,
|
|
353
|
+
'elapsed_seconds': round(time.monotonic()-started, 3), 'completed_at': now()}
|
|
354
|
+
write_json(receipt, saved)
|
|
355
|
+
result.extend(rows)
|
|
356
|
+
boundary_candidates.extend(candidates)
|
|
357
|
+
if options.get('on_chunk'):
|
|
358
|
+
options['on_chunk'](saved, False)
|
|
359
|
+
# Independent timestamps can put the same sentence outside BOTH owning
|
|
360
|
+
# cores. Retain those candidates until all cores are available; restoring
|
|
361
|
+
# a candidate also covers its counterpart, so it is not restored twice.
|
|
362
|
+
for candidate in sorted(boundary_candidates, key=lambda x: x['end_ms']-x['start_ms'], reverse=True):
|
|
363
|
+
midpoint = (candidate['start_ms'] + candidate['end_ms']) / 2
|
|
364
|
+
if start <= midpoint < end and not any(s['start_ms'] <= midpoint < s['end_ms'] for s in result):
|
|
365
|
+
result.append({**candidate, 'boundary_recovery': True})
|
|
366
|
+
result.sort(key=lambda x: x['start_ms'])
|
|
367
|
+
# Only trim a literal repeated boundary prefix when different core windows
|
|
368
|
+
# claim the same audio time. Keep raw text/times as provenance. Ordinary
|
|
369
|
+
# repetitions within one window or at distinct times remain untouched.
|
|
370
|
+
for previous, current in zip(result, result[1:]):
|
|
371
|
+
overlap = previous['end_ms'] - current['start_ms']
|
|
372
|
+
if previous['core_start_ms'] == current['core_start_ms'] or overlap < 500:
|
|
373
|
+
continue
|
|
374
|
+
left = re.sub(r'[\s,,。.!!??]', '', previous['text'])
|
|
375
|
+
right = current['text']
|
|
376
|
+
for n in range(min(len(left), len(right)), 3, -1):
|
|
377
|
+
if left.endswith(right[:n]) and n < len(right):
|
|
378
|
+
current['boundary_overlap'] = {
|
|
379
|
+
'original_text': right, 'removed_prefix': right[:n],
|
|
380
|
+
'overlap_ms': overlap, 'retained_raw_path': previous['raw_path']}
|
|
381
|
+
current['text'] = right[n:].lstrip(',,。 ')
|
|
382
|
+
current['start_ms'] = previous['end_ms']
|
|
383
|
+
break
|
|
384
|
+
if options.get('vad', True) and options.get('recover_gaps', True):
|
|
385
|
+
# Language can change mid-clip. Re-detect language in uncovered intervals
|
|
386
|
+
# using VAD, once only; silence remains empty rather than hallucinated.
|
|
387
|
+
covered = [{'start_ms': max(start, x['start_ms'])-start,
|
|
388
|
+
'end_ms': min(end, x['end_ms'])-start} for x in result]
|
|
389
|
+
for gap_start, gap_end in caption_gaps(covered, end-start):
|
|
390
|
+
recovered = transcribe_audio(audio_path, work / 'coverage', {
|
|
391
|
+
**options, 'start_ms': start+gap_start, 'end_ms': start+gap_end,
|
|
392
|
+
'language': 'auto', 'context_ms': 0, 'recover_gaps': False})
|
|
393
|
+
for segment in recovered:
|
|
394
|
+
segment['coverage_recovery'] = True
|
|
395
|
+
result.extend(recovered)
|
|
396
|
+
result.sort(key=lambda x: x['start_ms'])
|
|
397
|
+
return result
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def caption_gaps(segments, duration_ms):
|
|
401
|
+
cursor, gaps = 0, []
|
|
402
|
+
for s in sorted(segments, key=lambda x: x['start_ms']):
|
|
403
|
+
if s['start_ms']-cursor > 3000:
|
|
404
|
+
gaps.append((cursor, s['start_ms']))
|
|
405
|
+
cursor = max(cursor, s['end_ms'])
|
|
406
|
+
if duration_ms-cursor > 3000:
|
|
407
|
+
gaps.append((cursor, duration_ms))
|
|
408
|
+
return gaps
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def fill_gaps(segments, audio, work, options):
|
|
412
|
+
gaps = caption_gaps(segments, audio_duration(audio))
|
|
413
|
+
additions = []
|
|
414
|
+
for a, b in gaps:
|
|
415
|
+
rows = transcribe_audio(audio, Path(work) / 'gaps', {
|
|
416
|
+
**options, 'start_ms': a, 'end_ms': b, 'vad': True, 'context_ms': 0})
|
|
417
|
+
# Feed only missing audio: clipping timestamps cannot remove words
|
|
418
|
+
# spoken in neighbouring captions. Keep ASR timestamps as provenance.
|
|
419
|
+
for r in rows:
|
|
420
|
+
r = {**r, 'source_kind': 'gap_fill'}
|
|
421
|
+
if r['end_ms'] > r['start_ms']:
|
|
422
|
+
additions.append(r)
|
|
423
|
+
write_json(Path(work) / 'gap-check.json', {'schema_version': 1, 'candidates': gaps, 'additions': additions})
|
|
424
|
+
return sorted(segments + additions, key=lambda x: x['start_ms'])
|