@oh-story/dsh 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +1201 -0
- package/lib/client.js.map +7 -0
- package/lib/drama/LICENSE.upstream +21 -0
- package/lib/drama/manifest.json +1012 -0
- package/lib/drama/skills/short-drama/SKILL.md +153 -0
- package/lib/drama/skills/short-drama/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama/assets/creator-decision.example.jsonl +4 -0
- package/lib/drama/skills/short-drama/assets/production-observation.example.jsonl +2 -0
- package/lib/drama/skills/short-drama/assets/project-template/short-drama.json +36 -0
- package/lib/drama/skills/short-drama/assets/reference-observation.example.jsonl +2 -0
- package/lib/drama/skills/short-drama/references/audience-reveal.md +74 -0
- package/lib/drama/skills/short-drama/references/contract-and-ownership.md +94 -0
- package/lib/drama/skills/short-drama/references/creator-workflow.md +82 -0
- package/lib/drama/skills/short-drama/references/form-cards/Q/347/211/210/350/241/250/350/276/276.md +73 -0
- package/lib/drama/skills/short-drama/references/form-cards//344/272/214/347/273/264/345/212/250/346/200/201/346/274/253.md +74 -0
- package/lib/drama/skills/short-drama/references/form-cards//345/233/275/346/274/253/344/272/214/346/254/241/345/205/203.md +79 -0
- package/lib/drama/skills/short-drama/references/form-cards//345/256/236/346/213/215.md +75 -0
- package/lib/drama/skills/short-drama/references/form-cards//346/260/264/345/242/250/347/254/224/350/247/246.md +85 -0
- package/lib/drama/skills/short-drama/references/form-cards//351/243/216/346/240/274/345/214/226/344/270/211/347/273/264.md +72 -0
- package/lib/drama/skills/short-drama/references/knowhow-index.md +80 -0
- package/lib/drama/skills/short-drama/references/lifecycle-commands.md +130 -0
- package/lib/drama/skills/short-drama/references/look-development.md +52 -0
- package/lib/drama/skills/short-drama/references/pickup-and-alternate.md +58 -0
- package/lib/drama/skills/short-drama/references/production-form-profiles.md +126 -0
- package/lib/drama/skills/short-drama/references/reference-roles.md +142 -0
- package/lib/drama/skills/short-drama/references/runtime-preflight.md +27 -0
- package/lib/drama/skills/short-drama/scripts/project_tool.py +1963 -0
- package/lib/drama/skills/short-drama/scripts/selftest.py +287 -0
- package/lib/drama/skills/short-drama-assets/SKILL.md +187 -0
- package/lib/drama/skills/short-drama-assets/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-assets/assets/character-look.example.jsonl +3 -0
- package/lib/drama/skills/short-drama-assets/assets/continuity.example.jsonl +4 -0
- package/lib/drama/skills/short-drama-assets/assets/decisions.example.jsonl +5 -0
- package/lib/drama/skills/short-drama-assets/assets/location-view.example.jsonl +3 -0
- package/lib/drama/skills/short-drama-assets/assets/occurrences.example.jsonl +5 -0
- package/lib/drama/skills/short-drama-assets/assets/prop-state.example.jsonl +3 -0
- package/lib/drama/skills/short-drama-assets/examples/minimal/characters.jsonl +2 -0
- package/lib/drama/skills/short-drama-assets/examples/minimal/looks.jsonl +2 -0
- package/lib/drama/skills/short-drama-assets/references/asset-review-checklist.md +89 -0
- package/lib/drama/skills/short-drama-assets/references/character-and-look.md +164 -0
- package/lib/drama/skills/short-drama-assets/references/continuity-delta.md +123 -0
- package/lib/drama/skills/short-drama-assets/references/identity-vs-variant.md +146 -0
- package/lib/drama/skills/short-drama-assets/references/location-and-view.md +84 -0
- package/lib/drama/skills/short-drama-assets/references/occurrence-extraction.md +111 -0
- package/lib/drama/skills/short-drama-assets/references/prop-and-state.md +107 -0
- package/lib/drama/skills/short-drama-assets/references/stage-contract.md +136 -0
- package/lib/drama/skills/short-drama-assets/references/voice-direction.md +171 -0
- package/lib/drama/skills/short-drama-assets/scripts/asset_check.py +267 -0
- package/lib/drama/skills/short-drama-assets/scripts/selftest.py +89 -0
- package/lib/drama/skills/short-drama-develop/SKILL.md +157 -0
- package/lib/drama/skills/short-drama-develop/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-develop/assets/adaptation-map.example.jsonl +1 -0
- package/lib/drama/skills/short-drama-develop/assets/creative-brief.md +120 -0
- package/lib/drama/skills/short-drama-develop/assets/episode-map.jsonl +1 -0
- package/lib/drama/skills/short-drama-develop/assets/story-engine.md +181 -0
- package/lib/drama/skills/short-drama-develop/references/adaptation-craft.md +219 -0
- package/lib/drama/skills/short-drama-develop/references/creative-reference-intake.md +57 -0
- package/lib/drama/skills/short-drama-develop/references/director-brief-craft.md +113 -0
- package/lib/drama/skills/short-drama-develop/references/episode-design.md +509 -0
- package/lib/drama/skills/short-drama-develop/references/genre-and-hook-playbook.md +240 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//344/272/262/345/255/220/351/232/220/347/247/230.md +112 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//344/273/231/344/276/240/344/277/256/347/234/237.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//345/212/250/344/275/234/344/273/273/345/212/241.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//345/217/244/350/243/205/346/235/203/350/260/213.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//345/244/215/344/273/207/346/211/223/350/204/270.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//345/256/266/345/272/255/345/205/263/347/263/273.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//346/202/254/347/226/221/350/247/204/345/210/231.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//347/224/237/346/264/273/346/265/201.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//347/240/264/351/225/234/351/207/215/345/234/206.md +109 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//350/201/214/345/234/272/345/226/234/345/211/247.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//350/261/252/351/227/250/345/251/232/346/201/213.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards//350/272/253/344/273/275/351/224/231/344/275/215.md +51 -0
- package/lib/drama/skills/short-drama-develop/references/genre-cards.md +92 -0
- package/lib/drama/skills/short-drama-develop/references/mechanism-loop.md +282 -0
- package/lib/drama/skills/short-drama-develop/references/multi-episode-intake.md +128 -0
- package/lib/drama/skills/short-drama-develop/references/premise-devices.md +211 -0
- package/lib/drama/skills/short-drama-develop/references/reveal-reversal-payoff.md +99 -0
- package/lib/drama/skills/short-drama-develop/references/serial-character-and-memory.md +293 -0
- package/lib/drama/skills/short-drama-develop/references/stage-contract.md +88 -0
- package/lib/drama/skills/short-drama-develop/references/story-craft.md +359 -0
- package/lib/drama/skills/short-drama-develop/scripts/episode_intake.py +699 -0
- package/lib/drama/skills/short-drama-develop/scripts/selftest.py +47 -0
- package/lib/drama/skills/short-drama-image-prompts/SKILL.md +181 -0
- package/lib/drama/skills/short-drama-image-prompts/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-image-prompts/assets/image-prompt-spec.jsonl.md +187 -0
- package/lib/drama/skills/short-drama-image-prompts/assets/image-prompts.md +37 -0
- package/lib/drama/skills/short-drama-image-prompts/assets/lookdev-frame-spec.jsonl.md +128 -0
- package/lib/drama/skills/short-drama-image-prompts/assets/lookdev-prompts.md +31 -0
- package/lib/drama/skills/short-drama-image-prompts/examples/minimal-image-prompt-specs.jsonl +2 -0
- package/lib/drama/skills/short-drama-image-prompts/references/character-and-look.md +154 -0
- package/lib/drama/skills/short-drama-image-prompts/references/common-recipe.md +231 -0
- package/lib/drama/skills/short-drama-image-prompts/references/edit-and-revision.md +122 -0
- package/lib/drama/skills/short-drama-image-prompts/references/location-plate.md +152 -0
- package/lib/drama/skills/short-drama-image-prompts/references/look-and-state-variant.md +96 -0
- package/lib/drama/skills/short-drama-image-prompts/references/lookdev-frame.md +38 -0
- package/lib/drama/skills/short-drama-image-prompts/references/production-sheet-recipes.md +177 -0
- package/lib/drama/skills/short-drama-image-prompts/references/prop-plate.md +140 -0
- package/lib/drama/skills/short-drama-image-prompts/references/review-and-fixtures.md +92 -0
- package/lib/drama/skills/short-drama-image-prompts/references/stage-contract.md +89 -0
- package/lib/drama/skills/short-drama-image-prompts/scripts/image_prompt_check.py +443 -0
- package/lib/drama/skills/short-drama-image-prompts/scripts/selftest.py +93 -0
- package/lib/drama/skills/short-drama-novel-analyze/SKILL.md +245 -0
- package/lib/drama/skills/short-drama-novel-analyze/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-novel-analyze/assets/episode-candidate.example.jsonl +3 -0
- package/lib/drama/skills/short-drama-novel-analyze/references/adaptation-triage.md +116 -0
- package/lib/drama/skills/short-drama-novel-analyze/references/adaptation-value.md +124 -0
- package/lib/drama/skills/short-drama-novel-analyze/references/aggregation-and-entities.md +155 -0
- package/lib/drama/skills/short-drama-novel-analyze/references/chapter-extraction.md +141 -0
- package/lib/drama/skills/short-drama-novel-analyze/references/stage-contract.md +67 -0
- package/lib/drama/skills/short-drama-novel-analyze/scripts/novel_index.py +651 -0
- package/lib/drama/skills/short-drama-novel-analyze/scripts/selftest.py +51 -0
- package/lib/drama/skills/short-drama-produce/SKILL.md +103 -0
- package/lib/drama/skills/short-drama-produce/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-produce/references/adapter-contract.md +140 -0
- package/lib/drama/skills/short-drama-produce/references/providers/gpt-image-2.md +24 -0
- package/lib/drama/skills/short-drama-produce/references/providers/minimax-music.md +25 -0
- package/lib/drama/skills/short-drama-produce/references/providers/seedance.md +40 -0
- package/lib/drama/skills/short-drama-produce/scripts/fixture_adapter.py +60 -0
- package/lib/drama/skills/short-drama-produce/scripts/production_tool.py +1635 -0
- package/lib/drama/skills/short-drama-produce/scripts/provider_adapters.py +964 -0
- package/lib/drama/skills/short-drama-produce/scripts/selftest.py +134 -0
- package/lib/drama/skills/short-drama-review/SKILL.md +178 -0
- package/lib/drama/skills/short-drama-review/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-review/assets/finding-template.jsonl +2 -0
- package/lib/drama/skills/short-drama-review/assets/supersession-decision.example.json +42 -0
- package/lib/drama/skills/short-drama-review/assets/verdict-template.json +32 -0
- package/lib/drama/skills/short-drama-review/examples/minimal-findings.jsonl +2 -0
- package/lib/drama/skills/short-drama-review/examples/minimal-verdict.json +34 -0
- package/lib/drama/skills/short-drama-review/references/anti-template-repair.md +114 -0
- package/lib/drama/skills/short-drama-review/references/production-quality-gates.md +270 -0
- package/lib/drama/skills/short-drama-review/references/project-calibration.md +85 -0
- package/lib/drama/skills/short-drama-review/references/review-method.md +82 -0
- package/lib/drama/skills/short-drama-review/references/rubric-assets-prompts.md +115 -0
- package/lib/drama/skills/short-drama-review/references/rubric-source-analysis.md +108 -0
- package/lib/drama/skills/short-drama-review/references/rubric-story-script.md +164 -0
- package/lib/drama/skills/short-drama-review/references/rubric-visual-motion.md +166 -0
- package/lib/drama/skills/short-drama-review/references/stage-contract.md +87 -0
- package/lib/drama/skills/short-drama-review/scripts/review_check.py +325 -0
- package/lib/drama/skills/short-drama-review/scripts/selftest.py +87 -0
- package/lib/drama/skills/short-drama-storyboard/SKILL.md +264 -0
- package/lib/drama/skills/short-drama-storyboard/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-storyboard/assets/coverage-audition.example.jsonl +2 -0
- package/lib/drama/skills/short-drama-storyboard/assets/coverage-template.json +49 -0
- package/lib/drama/skills/short-drama-storyboard/assets/keyframe-prompts.md +32 -0
- package/lib/drama/skills/short-drama-storyboard/assets/keyframe-template.jsonl +2 -0
- package/lib/drama/skills/short-drama-storyboard/assets/revision-lineage.fragment.json +12 -0
- package/lib/drama/skills/short-drama-storyboard/assets/scene-visual-plan.example.jsonl +2 -0
- package/lib/drama/skills/short-drama-storyboard/assets/shot-template.jsonl +2 -0
- package/lib/drama/skills/short-drama-storyboard/references/blocking-playbooks.md +241 -0
- package/lib/drama/skills/short-drama-storyboard/references/coverage-audition.md +39 -0
- package/lib/drama/skills/short-drama-storyboard/references/keyframe-craft.md +169 -0
- package/lib/drama/skills/short-drama-storyboard/references/production-shot-grammar.md +264 -0
- package/lib/drama/skills/short-drama-storyboard/references/review-and-fixtures.md +70 -0
- package/lib/drama/skills/short-drama-storyboard/references/scene-visual-plan.md +39 -0
- package/lib/drama/skills/short-drama-storyboard/references/screenplay-to-keyframe-example.md +157 -0
- package/lib/drama/skills/short-drama-storyboard/references/shot-craft.md +192 -0
- package/lib/drama/skills/short-drama-storyboard/references/shot-revision-identity.md +29 -0
- package/lib/drama/skills/short-drama-storyboard/references/stage-contract.md +110 -0
- package/lib/drama/skills/short-drama-storyboard/scripts/selftest.py +191 -0
- package/lib/drama/skills/short-drama-storyboard/scripts/storyboard_check.py +824 -0
- package/lib/drama/skills/short-drama-video-prompts/SKILL.md +245 -0
- package/lib/drama/skills/short-drama-video-prompts/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-video-prompts/assets/coverage-scope.fragment.json +21 -0
- package/lib/drama/skills/short-drama-video-prompts/assets/delivery-container.jsonl.md +101 -0
- package/lib/drama/skills/short-drama-video-prompts/assets/motion-spec.jsonl.md +212 -0
- package/lib/drama/skills/short-drama-video-prompts/assets/motion-terminal.example.jsonl +2 -0
- package/lib/drama/skills/short-drama-video-prompts/assets/music-spec.jsonl.md +31 -0
- package/lib/drama/skills/short-drama-video-prompts/assets/performance.fragment.json +38 -0
- package/lib/drama/skills/short-drama-video-prompts/assets/video-prompts.md +46 -0
- package/lib/drama/skills/short-drama-video-prompts/examples/minimal-music-specs.jsonl +2 -0
- package/lib/drama/skills/short-drama-video-prompts/references/camera-audio-continuity.md +240 -0
- package/lib/drama/skills/short-drama-video-prompts/references/delivery-profile.md +255 -0
- package/lib/drama/skills/short-drama-video-prompts/references/generability.md +93 -0
- package/lib/drama/skills/short-drama-video-prompts/references/motion-recipe.md +304 -0
- package/lib/drama/skills/short-drama-video-prompts/references/performance-action-timing.md +191 -0
- package/lib/drama/skills/short-drama-video-prompts/references/production-prompt-grammar.md +312 -0
- package/lib/drama/skills/short-drama-video-prompts/references/review-and-fixtures.md +168 -0
- package/lib/drama/skills/short-drama-video-prompts/references/stage-contract.md +110 -0
- package/lib/drama/skills/short-drama-video-prompts/scripts/container_check.py +329 -0
- package/lib/drama/skills/short-drama-video-prompts/scripts/motion_timing_check.py +450 -0
- package/lib/drama/skills/short-drama-video-prompts/scripts/music_spec_check.py +327 -0
- package/lib/drama/skills/short-drama-video-prompts/scripts/selftest.py +82 -0
- package/lib/drama/skills/short-drama-write/SKILL.md +284 -0
- package/lib/drama/skills/short-drama-write/agents/openai.yaml +4 -0
- package/lib/drama/skills/short-drama-write/assets/beats.jsonl +2 -0
- package/lib/drama/skills/short-drama-write/assets/episode-card-standalone.json +120 -0
- package/lib/drama/skills/short-drama-write/assets/episode-card.json +55 -0
- package/lib/drama/skills/short-drama-write/assets/screenplay.md +36 -0
- package/lib/drama/skills/short-drama-write/assets/voice-record-sheet.jsonl.md +89 -0
- package/lib/drama/skills/short-drama-write/references/dialogue-craft.md +519 -0
- package/lib/drama/skills/short-drama-write/references/production-format-dialect.md +273 -0
- package/lib/drama/skills/short-drama-write/references/scene-handoff-capsule.md +51 -0
- package/lib/drama/skills/short-drama-write/references/scene-sound-dramaturgy.md +43 -0
- package/lib/drama/skills/short-drama-write/references/screenplay-format.md +260 -0
- package/lib/drama/skills/short-drama-write/references/script-craft.md +558 -0
- package/lib/drama/skills/short-drama-write/references/stage-contract.md +94 -0
- package/lib/drama/skills/short-drama-write/references/substitutable-realization.md +107 -0
- package/lib/drama/skills/short-drama-write/scripts/duration_estimate.py +309 -0
- package/lib/drama/skills/short-drama-write/scripts/screenplay_index.py +1091 -0
- package/lib/drama/skills/short-drama-write/scripts/selftest.py +229 -0
- package/lib/drama/skills/short-drama-write/scripts/voice_sheet_check.py +416 -0
- package/lib/index.js +756 -0
- package/lib/index.js.map +7 -0
- package/lib/oh-story/LICENSE.upstream +21 -0
- package/lib/oh-story/manifest.json +1351 -0
- package/lib/oh-story/roles/chapter-extractor.md +314 -0
- package/lib/oh-story/roles/character-designer.md +169 -0
- package/lib/oh-story/roles/consistency-checker.md +190 -0
- package/lib/oh-story/roles/narrative-writer.md +294 -0
- package/lib/oh-story/roles/story-architect.md +195 -0
- package/lib/oh-story/roles/story-explorer.md +364 -0
- package/lib/oh-story/roles/story-researcher.md +304 -0
- package/lib/oh-story/skills/browser-cdp/SKILL.md +175 -0
- package/lib/oh-story/skills/story/SKILL.md +116 -0
- package/lib/oh-story/skills/story/VERSION +1 -0
- package/lib/oh-story/skills/story-cover/SKILL.md +327 -0
- package/lib/oh-story/skills/story-cover/references/cover-styles.md +210 -0
- package/lib/oh-story/skills/story-deslop/SKILL.md +445 -0
- package/lib/oh-story/skills/story-deslop/references/anti-ai-writing.md +582 -0
- package/lib/oh-story/skills/story-deslop/references/banned-words.md +147 -0
- package/lib/oh-story/skills/story-deslop/scripts/check-ai-patterns.js +1371 -0
- package/lib/oh-story/skills/story-deslop/scripts/check-degeneration.js +330 -0
- package/lib/oh-story/skills/story-deslop/scripts/check-outline-copy.js +241 -0
- package/lib/oh-story/skills/story-deslop/scripts/normalize-punctuation.js +410 -0
- package/lib/oh-story/skills/story-import/SKILL.md +634 -0
- package/lib/oh-story/skills/story-import/references/character-state-reverse.md +82 -0
- package/lib/oh-story/skills/story-import/references/format-and-structure.md +169 -0
- package/lib/oh-story/skills/story-import/references/length-routing.md +134 -0
- package/lib/oh-story/skills/story-import/references/state-tracking.md +108 -0
- package/lib/oh-story/skills/story-import/references/structure-mapping-long.md +442 -0
- package/lib/oh-story/skills/story-import/references/structure-mapping-short.md +175 -0
- package/lib/oh-story/skills/story-import/references/tracking-transaction.md +161 -0
- package/lib/oh-story/skills/story-import/scripts/tracking_commit.py +1139 -0
- package/lib/oh-story/skills/story-long-analyze/SKILL.md +329 -0
- package/lib/oh-story/skills/story-long-analyze/references/deconstruction-notes.md +270 -0
- package/lib/oh-story/skills/story-long-analyze/references/material-decomposition.md +530 -0
- package/lib/oh-story/skills/story-long-analyze/references/output-templates.md +559 -0
- package/lib/oh-story/skills/story-long-analyze/references/pipeline-ops.md +80 -0
- package/lib/oh-story/skills/story-long-analyze/references/style-profile-generator.md +149 -0
- package/lib/oh-story/skills/story-long-analyze/references/style-profile-protocol.md +133 -0
- package/lib/oh-story/skills/story-long-scan/SKILL.md +342 -0
- package/lib/oh-story/skills/story-long-scan/references/genre-trends.md +197 -0
- package/lib/oh-story/skills/story-long-scan/references/publishing-guide.md +114 -0
- package/lib/oh-story/skills/story-long-scan/references/reader-profiling.md +105 -0
- package/lib/oh-story/skills/story-long-scan/references/scan-output-format.md +207 -0
- package/lib/oh-story/skills/story-long-scan/references/topic-decision.md +78 -0
- package/lib/oh-story/skills/story-long-write/SKILL.md +327 -0
- package/lib/oh-story/skills/story-long-write/references/anti-ai-writing.md +582 -0
- package/lib/oh-story/skills/story-long-write/references/artifact-protocols.md +302 -0
- package/lib/oh-story/skills/story-long-write/references/banned-words.md +147 -0
- package/lib/oh-story/skills/story-long-write/references/character-basics.md +445 -0
- package/lib/oh-story/skills/story-long-write/references/character-design-methods.md +428 -0
- package/lib/oh-story/skills/story-long-write/references/character-relations.md +385 -0
- package/lib/oh-story/skills/story-long-write/references/commercial-core-methods.md +502 -0
- package/lib/oh-story/skills/story-long-write/references/cross-book-recall.md +62 -0
- package/lib/oh-story/skills/story-long-write/references/dialogue-mastery.md +282 -0
- package/lib/oh-story/skills/story-long-write/references/emotional-arc-design.md +426 -0
- package/lib/oh-story/skills/story-long-write/references/emotional-methods.md +209 -0
- package/lib/oh-story/skills/story-long-write/references/female-audience-writing.md +188 -0
- package/lib/oh-story/skills/story-long-write/references/format-and-structure.md +169 -0
- package/lib/oh-story/skills/story-long-write/references/genre-catalog.md +480 -0
- package/lib/oh-story/skills/story-long-write/references/genre-core-mechanics.md +415 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//344/270/234/346/226/271/344/273/231/344/276/240.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//344/274/240/347/273/237/347/216/204/345/271/273.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/216/206/345/217/262/345/217/244/344/273/243.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/216/206/345/217/262/350/204/221/346/264/236.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/217/214/347/224/267/344/270/273.md +53 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/217/244/350/250/200/350/204/221/346/264/236.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/217/244/351/243/216/344/270/226/346/203/205.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/245/263/351/242/221/346/202/254/347/226/221.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/245/263/351/242/221/347/247/215/347/224/260.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/256/253/346/226/227/345/256/205/346/226/227.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/271/264/344/273/243.md +53 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//345/277/253/347/251/277.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//346/202/254/347/226/221/347/201/265/345/274/202.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//346/202/254/347/226/221/350/204/221/346/264/236.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//346/210/230/347/245/236/350/265/230/345/251/277.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//346/212/227/346/210/230/350/260/215/346/210/230.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//346/230/237/345/205/211/347/222/200/347/222/250.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//346/260/221/345/233/275/350/250/200/346/203/205.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//346/270/270/346/210/217/344/275/223/350/202/262.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//347/216/204/345/271/273/350/204/221/346/264/236.md +53 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//347/216/204/345/271/273/350/250/200/346/203/205.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//347/216/260/350/250/200/350/204/221/346/264/236.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//347/247/221/345/271/273/346/234/253/344/270/226.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//350/201/214/345/234/272/345/251/232/346/201/213.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//350/245/277/346/226/271/345/245/207/345/271/273.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//350/261/252/351/227/250/346/200/273/350/243/201.md +53 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//351/203/275/345/270/202/344/277/256/347/234/237.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//351/203/275/345/270/202/346/227/245/345/270/270.md +53 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//351/203/275/345/270/202/347/247/215/347/224/260.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//351/203/275/345/270/202/350/204/221/346/264/236.md +53 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//351/203/275/345/270/202/351/253/230/346/255/246.md +53 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards//351/235/222/346/230/245/347/224/234/345/256/240.md +51 -0
- package/lib/oh-story/skills/story-long-write/references/genre-prose-cards.md +91 -0
- package/lib/oh-story/skills/story-long-write/references/genre-readers.md +235 -0
- package/lib/oh-story/skills/story-long-write/references/genre-writing-formulas.md +444 -0
- package/lib/oh-story/skills/story-long-write/references/hooks-chapter.md +225 -0
- package/lib/oh-story/skills/story-long-write/references/hooks-paragraph.md +146 -0
- package/lib/oh-story/skills/story-long-write/references/hooks-suspense.md +352 -0
- package/lib/oh-story/skills/story-long-write/references/opening-design.md +349 -0
- package/lib/oh-story/skills/story-long-write/references/outline-conflict.md +457 -0
- package/lib/oh-story/skills/story-long-write/references/outline-methods.md +287 -0
- package/lib/oh-story/skills/story-long-write/references/outline-rhythm.md +389 -0
- package/lib/oh-story/skills/story-long-write/references/outline-structure-theory.md +326 -0
- package/lib/oh-story/skills/story-long-write/references/plot-core-methods.md +522 -0
- package/lib/oh-story/skills/story-long-write/references/plot-emotion-system.md +354 -0
- package/lib/oh-story/skills/story-long-write/references/plot-frameworks.md +711 -0
- package/lib/oh-story/skills/story-long-write/references/plot-special-topics.md +622 -0
- package/lib/oh-story/skills/story-long-write/references/quality-checklist.md +184 -0
- package/lib/oh-story/skills/story-long-write/references/reader-contract-and-progression.md +109 -0
- package/lib/oh-story/skills/story-long-write/references/reversal-toolkit.md +349 -0
- package/lib/oh-story/skills/story-long-write/references/state-tracking.md +108 -0
- package/lib/oh-story/skills/story-long-write/references/style-combat-face.md +409 -0
- package/lib/oh-story/skills/story-long-write/references/style-craft.md +347 -0
- package/lib/oh-story/skills/story-long-write/references/style-genre-modules.md +510 -0
- package/lib/oh-story/skills/story-long-write/references/tracking-transaction.md +161 -0
- package/lib/oh-story/skills/story-long-write/references/workflow-chapter.md +140 -0
- package/lib/oh-story/skills/story-long-write/references/workflow-daily.md +171 -0
- package/lib/oh-story/skills/story-long-write/references/workflow-revision.md +99 -0
- package/lib/oh-story/skills/story-long-write/references/workflow-setup.md +284 -0
- package/lib/oh-story/skills/story-long-write/references/writing-craft.md +421 -0
- package/lib/oh-story/skills/story-long-write/scripts/check-ai-patterns.js +1371 -0
- package/lib/oh-story/skills/story-long-write/scripts/check-degeneration.js +330 -0
- package/lib/oh-story/skills/story-long-write/scripts/check-outline-copy.js +241 -0
- package/lib/oh-story/skills/story-long-write/scripts/normalize-punctuation.js +410 -0
- package/lib/oh-story/skills/story-long-write/scripts/tracking_commit.py +1139 -0
- package/lib/oh-story/skills/story-review/SKILL.md +483 -0
- package/lib/oh-story/skills/story-review/references/anti-ai-writing.md +582 -0
- package/lib/oh-story/skills/story-review/references/banned-words.md +147 -0
- package/lib/oh-story/skills/story-review/references/character-relations.md +385 -0
- package/lib/oh-story/skills/story-review/references/dialogue-mastery.md +282 -0
- package/lib/oh-story/skills/story-review/references/plot-core-methods.md +522 -0
- package/lib/oh-story/skills/story-review/references/quality-checklist.md +250 -0
- package/lib/oh-story/skills/story-review/references/quality-rubric.md +55 -0
- package/lib/oh-story/skills/story-review/references/rubrics/fanqie.md +18 -0
- package/lib/oh-story/skills/story-review/references/rubrics/qidian.md +19 -0
- package/lib/oh-story/skills/story-review/references/rubrics/zhihu.md +20 -0
- package/lib/oh-story/skills/story-review/references/tracking-transaction.md +161 -0
- package/lib/oh-story/skills/story-review/scripts/check-ai-patterns.js +1371 -0
- package/lib/oh-story/skills/story-review/scripts/check-degeneration.js +330 -0
- package/lib/oh-story/skills/story-review/scripts/normalize-punctuation.js +410 -0
- package/lib/oh-story/skills/story-review/scripts/tracking_commit.py +1139 -0
- package/lib/oh-story/skills/story-setup/SKILL.md +495 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/anti-ai-writing.md +582 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/banned-words.md +147 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/character-basics.md +445 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/character-design-methods.md +428 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/character-relations.md +385 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/dialogue-mastery.md +282 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/emotional-arc-design.md +426 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/emotional-methods.md +179 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/format-and-structure.md +169 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-catalog.md +480 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-core-mechanics.md +415 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//344/270/234/346/226/271/344/273/231/344/276/240.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//344/274/240/347/273/237/347/216/204/345/271/273.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/216/206/345/217/262/345/217/244/344/273/243.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/216/206/345/217/262/350/204/221/346/264/236.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/217/214/347/224/267/344/270/273.md +53 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/217/244/350/250/200/350/204/221/346/264/236.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/217/244/351/243/216/344/270/226/346/203/205.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/245/263/351/242/221/346/202/254/347/226/221.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/245/263/351/242/221/347/247/215/347/224/260.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/256/253/346/226/227/345/256/205/346/226/227.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/271/264/344/273/243.md +53 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//345/277/253/347/251/277.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//346/202/254/347/226/221/347/201/265/345/274/202.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//346/202/254/347/226/221/350/204/221/346/264/236.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//346/210/230/347/245/236/350/265/230/345/251/277.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//346/212/227/346/210/230/350/260/215/346/210/230.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//346/230/237/345/205/211/347/222/200/347/222/250.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//346/260/221/345/233/275/350/250/200/346/203/205.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//346/270/270/346/210/217/344/275/223/350/202/262.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//347/216/204/345/271/273/350/204/221/346/264/236.md +53 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//347/216/204/345/271/273/350/250/200/346/203/205.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//347/216/260/350/250/200/350/204/221/346/264/236.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//347/247/221/345/271/273/346/234/253/344/270/226.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//350/201/214/345/234/272/345/251/232/346/201/213.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//350/245/277/346/226/271/345/245/207/345/271/273.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//350/261/252/351/227/250/346/200/273/350/243/201.md +53 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//351/203/275/345/270/202/344/277/256/347/234/237.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//351/203/275/345/270/202/346/227/245/345/270/270.md +53 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//351/203/275/345/270/202/347/247/215/347/224/260.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//351/203/275/345/270/202/350/204/221/346/264/236.md +53 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//351/203/275/345/270/202/351/253/230/346/255/246.md +53 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards//351/235/222/346/230/245/347/224/234/345/256/240.md +51 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-prose-cards.md +91 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-readers.md +235 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/genre-writing-formulas.md +444 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/hooks-chapter.md +225 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/hooks-suspense.md +352 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/opening-design.md +349 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/outline-conflict.md +457 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/outline-methods.md +287 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/outline-rhythm.md +389 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/plot-core-methods.md +522 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/quality-checklist.md +247 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/reversal-toolkit.md +349 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/style-combat-face.md +409 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/style-genre-modules.md +510 -0
- package/lib/oh-story/skills/story-setup/references/agent-references/writing-craft.md +421 -0
- package/lib/oh-story/skills/story-short-analyze/SKILL.md +278 -0
- package/lib/oh-story/skills/story-short-analyze/references/anti-ai-writing.md +582 -0
- package/lib/oh-story/skills/story-short-analyze/references/banned-words.md +147 -0
- package/lib/oh-story/skills/story-short-analyze/references/character-basics.md +453 -0
- package/lib/oh-story/skills/story-short-analyze/references/character-design-methods.md +438 -0
- package/lib/oh-story/skills/story-short-analyze/references/character-relations.md +395 -0
- package/lib/oh-story/skills/story-short-analyze/references/deconstruction-examples.md +79 -0
- package/lib/oh-story/skills/story-short-analyze/references/genre-catalog.md +490 -0
- package/lib/oh-story/skills/story-short-analyze/references/genre-core-mechanics.md +425 -0
- package/lib/oh-story/skills/story-short-analyze/references/genre-readers.md +245 -0
- package/lib/oh-story/skills/story-short-analyze/references/genre-writing-formulas.md +453 -0
- package/lib/oh-story/skills/story-short-analyze/references/genre-writing-techniques.md +475 -0
- package/lib/oh-story/skills/story-short-analyze/references/hooks-chapter.md +225 -0
- package/lib/oh-story/skills/story-short-analyze/references/hooks-paragraph.md +146 -0
- package/lib/oh-story/skills/story-short-analyze/references/hooks-suspense.md +352 -0
- package/lib/oh-story/skills/story-short-analyze/references/material-decomposition.md +685 -0
- package/lib/oh-story/skills/story-short-analyze/references/output-contract.md +165 -0
- package/lib/oh-story/skills/story-short-analyze/references/output-templates.md +561 -0
- package/lib/oh-story/skills/story-short-analyze/references/quality-checklist.md +242 -0
- package/lib/oh-story/skills/story-short-analyze/references/real-market-data.md +90 -0
- package/lib/oh-story/skills/story-short-analyze/references/zhihu-style.md +54 -0
- package/lib/oh-story/skills/story-short-scan/SKILL.md +212 -0
- package/lib/oh-story/skills/story-short-scan/references/real-market-data.md +90 -0
- package/lib/oh-story/skills/story-short-write/SKILL.md +433 -0
- package/lib/oh-story/skills/story-short-write/references/banned-words.md +147 -0
- package/lib/oh-story/skills/story-short-write/references/cross-book-recall.md +62 -0
- package/lib/oh-story/skills/story-short-write/references/dialogue-mastery.md +282 -0
- package/lib/oh-story/skills/story-short-write/references/emotional-methods.md +179 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//344/270/226/346/203/205/346/211/223/350/204/270.md +159 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//345/217/214/347/224/267/344/270/273.md +156 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//345/244/215/344/273/207/346/211/223/350/204/270.md +163 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//345/256/205/346/226/227/345/256/253/346/226/227.md +167 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//346/200/273/350/243/201/350/261/252/351/227/250.md +178 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//346/202/254/347/226/221.md +166 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//346/260/221/344/277/227/346/200/252/350/260/210.md +159 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//346/262/231/351/233/225/350/204/221/346/264/236.md +151 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//347/224/234/345/256/240.md +153 -0
- package/lib/oh-story/skills/story-short-write/references/genre-styles//350/277/275/345/246/273/347/201/253/350/221/254/345/234/272.md +210 -0
- package/lib/oh-story/skills/story-short-write/references/genre-writing-formulas.md +444 -0
- package/lib/oh-story/skills/story-short-write/references/genre-writing-techniques.md +488 -0
- package/lib/oh-story/skills/story-short-write/references/hooks-chapter.md +225 -0
- package/lib/oh-story/skills/story-short-write/references/hooks-paragraph.md +146 -0
- package/lib/oh-story/skills/story-short-write/references/hooks-suspense.md +352 -0
- package/lib/oh-story/skills/story-short-write/references/output-contract.md +165 -0
- package/lib/oh-story/skills/story-short-write/references/quality-checklist.md +222 -0
- package/lib/oh-story/skills/story-short-write/references/reversal-toolkit.md +349 -0
- package/lib/oh-story/skills/story-short-write/references/short-craft.md +185 -0
- package/lib/oh-story/skills/story-short-write/references/short-deslop.md +133 -0
- package/lib/oh-story/skills/story-short-write/references/short-format.md +167 -0
- package/lib/oh-story/skills/story-short-write/references/submission-craft.md +35 -0
- package/lib/oh-story/skills/story-short-write/references/villain-and-reveal.md +158 -0
- package/lib/oh-story/skills/story-short-write/references/writing-workflow.md +153 -0
- package/lib/oh-story/skills/story-short-write/scripts/check-ai-patterns.js +1371 -0
- package/lib/oh-story/skills/story-short-write/scripts/check-degeneration.js +330 -0
- package/lib/oh-story/skills/story-short-write/scripts/check-outline-copy.js +241 -0
- package/lib/oh-story/skills/story-short-write/scripts/normalize-punctuation.js +410 -0
- package/lib/types/client/file-activity.d.ts +30 -0
- package/lib/types/client/file-activity.d.ts.map +1 -0
- package/lib/types/client/file-tree.d.ts +20 -0
- package/lib/types/client/file-tree.d.ts.map +1 -0
- package/lib/types/client/index.d.ts +12 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/jsonl-preview.d.ts +15 -0
- package/lib/types/client/jsonl-preview.d.ts.map +1 -0
- package/lib/types/client/markdown-preview.d.ts +38 -0
- package/lib/types/client/markdown-preview.d.ts.map +1 -0
- package/lib/types/index.d.ts +25 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/native-hooks.d.ts +16 -0
- package/lib/types/native-hooks.d.ts.map +1 -0
- package/lib/types/role-provider.d.ts +6 -0
- package/lib/types/role-provider.d.ts.map +1 -0
- package/lib/types/role-tool.d.ts +10 -0
- package/lib/types/role-tool.d.ts.map +1 -0
- package/lib/types/skill-provider.d.ts +15 -0
- package/lib/types/skill-provider.d.ts.map +1 -0
- package/lib/types/workspace-request-trust.d.ts +13 -0
- package/lib/types/workspace-request-trust.d.ts.map +1 -0
- package/lib/types/workspace-route.d.ts +10 -0
- package/lib/types/workspace-route.d.ts.map +1 -0
- package/lib/types/workspace-security.d.ts +9 -0
- package/lib/types/workspace-security.d.ts.map +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Mechanical intake guards for a multi-episode screenplay source.
|
|
3
|
+
|
|
4
|
+
This tool deliberately does not interpret story content. It records exact byte
|
|
5
|
+
spans once, verifies them before every read, exposes one episode at a time, and
|
|
6
|
+
atomically merges agent-authored episode-map records in small configurable
|
|
7
|
+
batches. The episode map remains the completion truth; a progress checkpoint
|
|
8
|
+
is only a reproducible derived cache.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import argparse
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
import re
|
|
17
|
+
import sys
|
|
18
|
+
import tempfile
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any, Iterable
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
MINIMUM_PYTHON = (3, 9)
|
|
24
|
+
if sys.version_info < MINIMUM_PYTHON:
|
|
25
|
+
raise SystemExit(
|
|
26
|
+
"episode_intake.py requires Python {}.{} or newer; found {}.{}".format(
|
|
27
|
+
*MINIMUM_PYTHON, sys.version_info.major, sys.version_info.minor
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
SCHEMA_VERSION = "1.0.0"
|
|
32
|
+
CHINESE_DIGITS = {
|
|
33
|
+
"零": 0,
|
|
34
|
+
"一": 1,
|
|
35
|
+
"二": 2,
|
|
36
|
+
"两": 2,
|
|
37
|
+
"三": 3,
|
|
38
|
+
"四": 4,
|
|
39
|
+
"五": 5,
|
|
40
|
+
"六": 6,
|
|
41
|
+
"七": 7,
|
|
42
|
+
"八": 8,
|
|
43
|
+
"九": 9,
|
|
44
|
+
}
|
|
45
|
+
CHINESE_UNITS = {"十": 10, "百": 100, "千": 1000}
|
|
46
|
+
CHINESE_NUMBER = "零一二三四五六七八九十百千两"
|
|
47
|
+
CHINESE_HEADING_RE = re.compile(
|
|
48
|
+
r"^[ \t ]*第\s*([0-9]+|["
|
|
49
|
+
+ CHINESE_NUMBER
|
|
50
|
+
+ r"]+)\s*集(?:[ \t ]+\S.*|[::][ \t ]*\S.*)?[ \t ]*$"
|
|
51
|
+
)
|
|
52
|
+
EP_HEADING_RE = re.compile(
|
|
53
|
+
r"^[ \t]*#[ \t]+EP[ \t]*([0-9]+)(?:[ \t ]+\S.*)?[ \t ]*$",
|
|
54
|
+
re.IGNORECASE,
|
|
55
|
+
)
|
|
56
|
+
EPISODE_ID_RE = re.compile(r"^EP([0-9]{3}|[1-9][0-9]{3,})$")
|
|
57
|
+
MAX_HEADING_LENGTH = 80
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def chinese_to_int(text: str) -> int | None:
|
|
61
|
+
if not text:
|
|
62
|
+
return None
|
|
63
|
+
if text.isdigit():
|
|
64
|
+
return int(text)
|
|
65
|
+
total = 0
|
|
66
|
+
pending = 0
|
|
67
|
+
seen = False
|
|
68
|
+
for character in text:
|
|
69
|
+
if character in CHINESE_DIGITS:
|
|
70
|
+
pending = CHINESE_DIGITS[character]
|
|
71
|
+
seen = True
|
|
72
|
+
elif character in CHINESE_UNITS:
|
|
73
|
+
total += (pending or 1) * CHINESE_UNITS[character]
|
|
74
|
+
pending = 0
|
|
75
|
+
seen = True
|
|
76
|
+
else:
|
|
77
|
+
return None
|
|
78
|
+
return total + pending if seen else None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _line_table(data: bytes) -> tuple[list[bytes], list[int]]:
|
|
82
|
+
lines = data.splitlines(keepends=True)
|
|
83
|
+
if data and (not lines or sum(map(len, lines)) != len(data)):
|
|
84
|
+
raise ValueError("could not construct exact source line table")
|
|
85
|
+
offsets = [0]
|
|
86
|
+
for line in lines:
|
|
87
|
+
offsets.append(offsets[-1] + len(line))
|
|
88
|
+
return lines, offsets
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _heading_number(line: bytes) -> int | None:
|
|
92
|
+
text = line.decode("utf-8").removeprefix("\ufeff").rstrip("\r\n")
|
|
93
|
+
if len(text.strip()) > MAX_HEADING_LENGTH:
|
|
94
|
+
return None
|
|
95
|
+
match = CHINESE_HEADING_RE.fullmatch(text)
|
|
96
|
+
if match:
|
|
97
|
+
number = chinese_to_int(match.group(1))
|
|
98
|
+
return number if number and number > 0 else None
|
|
99
|
+
match = EP_HEADING_RE.fullmatch(text)
|
|
100
|
+
number = int(match.group(1)) if match else None
|
|
101
|
+
return number if number and number > 0 else None
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _episode_id(number: int) -> str:
|
|
105
|
+
if number <= 0:
|
|
106
|
+
raise ValueError("episode numbers must be positive")
|
|
107
|
+
return f"EP{number:03d}"
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _portable_source_ref(source: Path, source_ref: str | None) -> str:
|
|
111
|
+
value = source_ref or source.name
|
|
112
|
+
candidate = Path(value)
|
|
113
|
+
if (
|
|
114
|
+
not value
|
|
115
|
+
or candidate.is_absolute()
|
|
116
|
+
or ".." in candidate.parts
|
|
117
|
+
or "://" in value
|
|
118
|
+
or "\\" in value
|
|
119
|
+
or re.match(r"^[A-Za-z]:", value)
|
|
120
|
+
):
|
|
121
|
+
raise ValueError("source_ref must be a portable project-relative path")
|
|
122
|
+
return candidate.as_posix()
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _structural_problems(episodes: list[dict[str, Any]], data: bytes) -> list[str]:
|
|
126
|
+
problems: list[str] = []
|
|
127
|
+
numbers: list[int] = []
|
|
128
|
+
previous_end = 0
|
|
129
|
+
for position, row in enumerate(episodes, 1):
|
|
130
|
+
if not isinstance(row, dict):
|
|
131
|
+
problems.append(f"episode row {position} is not an object")
|
|
132
|
+
continue
|
|
133
|
+
match = EPISODE_ID_RE.fullmatch(str(row.get("episode_id", "")))
|
|
134
|
+
if not match:
|
|
135
|
+
problems.append(f"episode row {position} has an invalid episode_id")
|
|
136
|
+
continue
|
|
137
|
+
number = int(match.group(1))
|
|
138
|
+
if number <= 0:
|
|
139
|
+
problems.append(f"episode row {position} has a non-positive episode_id")
|
|
140
|
+
continue
|
|
141
|
+
numbers.append(number)
|
|
142
|
+
if row.get("source_number") != number:
|
|
143
|
+
problems.append(f"{row['episode_id']} source_number does not match episode_id")
|
|
144
|
+
start = row.get("byte_start")
|
|
145
|
+
end = row.get("byte_end")
|
|
146
|
+
if isinstance(start, int) and isinstance(end, int) and 0 <= start < end <= len(data):
|
|
147
|
+
if start < previous_end:
|
|
148
|
+
problems.append(f"episode row {position} overlaps or is out of source order")
|
|
149
|
+
previous_end = max(previous_end, end)
|
|
150
|
+
lines = data[start:end].splitlines(keepends=True)
|
|
151
|
+
if not b"".join(lines[1:]).strip():
|
|
152
|
+
problems.append(f"empty episode: {row['episode_id']}")
|
|
153
|
+
else:
|
|
154
|
+
problems.append(f"episode row {position} has an invalid byte span")
|
|
155
|
+
seen: set[int] = set()
|
|
156
|
+
duplicates: list[int] = []
|
|
157
|
+
for number in numbers:
|
|
158
|
+
if number in seen and number not in duplicates:
|
|
159
|
+
duplicates.append(number)
|
|
160
|
+
seen.add(number)
|
|
161
|
+
if duplicates:
|
|
162
|
+
problems.append("duplicate episode numbers: " + ", ".join(map(str, duplicates)))
|
|
163
|
+
if numbers:
|
|
164
|
+
if numbers != sorted(numbers):
|
|
165
|
+
problems.append("episode numbers are out of source order")
|
|
166
|
+
missing = sorted(set(range(min(numbers), max(numbers) + 1)) - set(numbers))
|
|
167
|
+
if min(numbers) != 1:
|
|
168
|
+
missing = sorted(set(range(1, min(numbers))) | set(missing))
|
|
169
|
+
if missing:
|
|
170
|
+
problems.append("missing episode numbers: " + ", ".join(map(str, missing)))
|
|
171
|
+
else:
|
|
172
|
+
problems.append("no episode headings found")
|
|
173
|
+
return problems
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def build_index(
|
|
177
|
+
source_path: str | Path, *, source_ref: str | None = None
|
|
178
|
+
) -> dict[str, Any]:
|
|
179
|
+
source = Path(source_path)
|
|
180
|
+
data = source.read_bytes()
|
|
181
|
+
lines, offsets = _line_table(data)
|
|
182
|
+
headings: list[tuple[int, int]] = []
|
|
183
|
+
for line_index, line in enumerate(lines):
|
|
184
|
+
number = _heading_number(line)
|
|
185
|
+
if number is not None:
|
|
186
|
+
headings.append((line_index, number))
|
|
187
|
+
episodes: list[dict[str, Any]] = []
|
|
188
|
+
for position, (line_index, number) in enumerate(headings):
|
|
189
|
+
next_line = headings[position + 1][0] if position + 1 < len(headings) else len(lines)
|
|
190
|
+
start = offsets[line_index]
|
|
191
|
+
end = offsets[next_line]
|
|
192
|
+
episodes.append(
|
|
193
|
+
{
|
|
194
|
+
"episode_id": _episode_id(number),
|
|
195
|
+
"source_number": number,
|
|
196
|
+
"line_start": line_index + 1,
|
|
197
|
+
"line_end": next_line,
|
|
198
|
+
"byte_start": start,
|
|
199
|
+
"byte_end": end,
|
|
200
|
+
"byte_length": end - start,
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
return {
|
|
204
|
+
"schema_version": SCHEMA_VERSION,
|
|
205
|
+
"record_type": "episode_intake_index",
|
|
206
|
+
"source_name": source.name,
|
|
207
|
+
"source_ref": _portable_source_ref(source, source_ref),
|
|
208
|
+
"source_byte_length": len(data),
|
|
209
|
+
"episode_count": len(episodes),
|
|
210
|
+
"episodes": episodes,
|
|
211
|
+
"unmapped_spans": _unmapped_spans(episodes, data, offsets),
|
|
212
|
+
"problems": _structural_problems(episodes, data),
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _line_number(offsets: list[int], byte_offset: int, *, end: bool = False) -> int:
|
|
217
|
+
if byte_offset not in offsets:
|
|
218
|
+
raise ValueError(f"byte offset {byte_offset} is not a line boundary")
|
|
219
|
+
index = offsets.index(byte_offset)
|
|
220
|
+
return index if end else index + 1
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _unmapped_spans(
|
|
224
|
+
episodes: list[dict[str, Any]], data: bytes, offsets: list[int]
|
|
225
|
+
) -> list[dict[str, Any]]:
|
|
226
|
+
"""Locate meaningful source bytes outside episode spans without copying them."""
|
|
227
|
+
|
|
228
|
+
spans: list[dict[str, Any]] = []
|
|
229
|
+
cursor = 0
|
|
230
|
+
ranges = [
|
|
231
|
+
(row.get("byte_start"), row.get("byte_end"))
|
|
232
|
+
for row in episodes
|
|
233
|
+
if isinstance(row, dict)
|
|
234
|
+
]
|
|
235
|
+
for start, end in ranges:
|
|
236
|
+
if not isinstance(start, int) or not isinstance(end, int):
|
|
237
|
+
continue
|
|
238
|
+
if start > cursor and data[cursor:start].strip():
|
|
239
|
+
spans.append(
|
|
240
|
+
{
|
|
241
|
+
"line_start": _line_number(offsets, cursor),
|
|
242
|
+
"line_end": _line_number(offsets, start, end=True),
|
|
243
|
+
"byte_start": cursor,
|
|
244
|
+
"byte_end": start,
|
|
245
|
+
"byte_length": start - cursor,
|
|
246
|
+
}
|
|
247
|
+
)
|
|
248
|
+
cursor = max(cursor, end)
|
|
249
|
+
if cursor < len(data) and data[cursor:].strip():
|
|
250
|
+
spans.append(
|
|
251
|
+
{
|
|
252
|
+
"line_start": _line_number(offsets, cursor),
|
|
253
|
+
"line_end": _line_number(offsets, len(data), end=True),
|
|
254
|
+
"byte_start": cursor,
|
|
255
|
+
"byte_end": len(data),
|
|
256
|
+
"byte_length": len(data) - cursor,
|
|
257
|
+
}
|
|
258
|
+
)
|
|
259
|
+
return spans
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def make_manual_index(
|
|
263
|
+
source_path: str | Path,
|
|
264
|
+
spans: Iterable[tuple[str, int, int]],
|
|
265
|
+
*,
|
|
266
|
+
source_ref: str | None = None,
|
|
267
|
+
) -> dict[str, Any]:
|
|
268
|
+
"""Create a verifiable index from agent-selected, line-aligned byte spans.
|
|
269
|
+
|
|
270
|
+
This is the escape hatch for nonstandard headings. The agent chooses the
|
|
271
|
+
boundaries; this function only binds those choices to exact source bytes.
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
source = Path(source_path)
|
|
275
|
+
data = source.read_bytes()
|
|
276
|
+
_, offsets = _line_table(data)
|
|
277
|
+
episodes: list[dict[str, Any]] = []
|
|
278
|
+
for episode_id, start, end in spans:
|
|
279
|
+
match = EPISODE_ID_RE.fullmatch(episode_id)
|
|
280
|
+
if not match or int(match.group(1)) <= 0:
|
|
281
|
+
raise ValueError(f"invalid episode_id: {episode_id}")
|
|
282
|
+
if not (0 <= start < end <= len(data)):
|
|
283
|
+
raise ValueError(f"invalid byte span for {episode_id}")
|
|
284
|
+
episodes.append(
|
|
285
|
+
{
|
|
286
|
+
"episode_id": episode_id,
|
|
287
|
+
"source_number": int(match.group(1)),
|
|
288
|
+
"line_start": _line_number(offsets, start),
|
|
289
|
+
"line_end": _line_number(offsets, end, end=True),
|
|
290
|
+
"byte_start": start,
|
|
291
|
+
"byte_end": end,
|
|
292
|
+
"byte_length": end - start,
|
|
293
|
+
}
|
|
294
|
+
)
|
|
295
|
+
document = {
|
|
296
|
+
"schema_version": SCHEMA_VERSION,
|
|
297
|
+
"record_type": "episode_intake_index",
|
|
298
|
+
"source_name": source.name,
|
|
299
|
+
"source_ref": _portable_source_ref(source, source_ref),
|
|
300
|
+
"source_byte_length": len(data),
|
|
301
|
+
"episode_count": len(episodes),
|
|
302
|
+
"episodes": episodes,
|
|
303
|
+
"unmapped_spans": _unmapped_spans(episodes, data, offsets),
|
|
304
|
+
"problems": [],
|
|
305
|
+
}
|
|
306
|
+
document["problems"] = _structural_problems(episodes, data)
|
|
307
|
+
return document
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def build_manual_index(
|
|
311
|
+
source_path: str | Path,
|
|
312
|
+
boundaries_path: str | Path,
|
|
313
|
+
*,
|
|
314
|
+
source_ref: str | None = None,
|
|
315
|
+
) -> dict[str, Any]:
|
|
316
|
+
"""Turn agent-selected one-based line starts into exact verified spans."""
|
|
317
|
+
|
|
318
|
+
source = Path(source_path)
|
|
319
|
+
data = source.read_bytes()
|
|
320
|
+
lines, offsets = _line_table(data)
|
|
321
|
+
boundaries = _read_jsonl(Path(boundaries_path))
|
|
322
|
+
if not boundaries:
|
|
323
|
+
raise ValueError("boundaries JSONL must contain at least one episode")
|
|
324
|
+
prepared: list[tuple[str, int, int | None]] = []
|
|
325
|
+
seen: set[str] = set()
|
|
326
|
+
for position, boundary in enumerate(boundaries, 1):
|
|
327
|
+
episode_id = boundary.get("episode_id")
|
|
328
|
+
line_start = boundary.get("line_start")
|
|
329
|
+
line_end = boundary.get("line_end")
|
|
330
|
+
if not isinstance(episode_id, str):
|
|
331
|
+
raise ValueError(f"boundary {position} has an invalid episode_id")
|
|
332
|
+
match = EPISODE_ID_RE.fullmatch(episode_id)
|
|
333
|
+
if match is None or int(match.group(1)) <= 0:
|
|
334
|
+
raise ValueError(f"boundary {position} has an invalid episode_id")
|
|
335
|
+
if episode_id in seen:
|
|
336
|
+
raise ValueError(f"boundaries contain duplicate episode_id {episode_id}")
|
|
337
|
+
seen.add(episode_id)
|
|
338
|
+
if not isinstance(line_start, int) or isinstance(line_start, bool):
|
|
339
|
+
raise ValueError(f"{episode_id} line_start must be an integer")
|
|
340
|
+
if line_end is not None and (
|
|
341
|
+
not isinstance(line_end, int) or isinstance(line_end, bool)
|
|
342
|
+
):
|
|
343
|
+
raise ValueError(f"{episode_id} line_end must be an integer")
|
|
344
|
+
prepared.append((episode_id, line_start, line_end))
|
|
345
|
+
spans: list[tuple[str, int, int]] = []
|
|
346
|
+
for position, (episode_id, line_start, explicit_end) in enumerate(prepared):
|
|
347
|
+
if not 1 <= line_start <= len(lines):
|
|
348
|
+
raise ValueError(f"{episode_id} line_start is outside the source")
|
|
349
|
+
next_start = prepared[position + 1][1] if position + 1 < len(prepared) else None
|
|
350
|
+
if next_start is not None and next_start <= line_start:
|
|
351
|
+
raise ValueError("boundary line_start values must be strictly increasing")
|
|
352
|
+
line_end = explicit_end if explicit_end is not None else (
|
|
353
|
+
next_start - 1 if next_start is not None else len(lines)
|
|
354
|
+
)
|
|
355
|
+
if not line_start <= line_end <= len(lines):
|
|
356
|
+
raise ValueError(f"{episode_id} line_end is outside its source span")
|
|
357
|
+
if next_start is not None and line_end >= next_start:
|
|
358
|
+
raise ValueError(f"{episode_id} line_end overlaps the next episode")
|
|
359
|
+
spans.append((episode_id, offsets[line_start - 1], offsets[line_end]))
|
|
360
|
+
return make_manual_index(source, spans, source_ref=source_ref)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def _json_bytes(document: Any) -> bytes:
|
|
364
|
+
return (json.dumps(document, ensure_ascii=False, sort_keys=True, separators=(",", ":")) + "\n").encode("utf-8")
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _atomic_write(path: Path, content: bytes) -> None:
|
|
368
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
369
|
+
descriptor, temporary_name = tempfile.mkstemp(prefix=f".{path.name}.", dir=path.parent)
|
|
370
|
+
temporary = Path(temporary_name)
|
|
371
|
+
try:
|
|
372
|
+
with os.fdopen(descriptor, "wb") as handle:
|
|
373
|
+
handle.write(content)
|
|
374
|
+
handle.flush()
|
|
375
|
+
os.fsync(handle.fileno())
|
|
376
|
+
os.replace(temporary, path)
|
|
377
|
+
finally:
|
|
378
|
+
temporary.unlink(missing_ok=True)
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def write_index(path: str | Path, document: dict[str, Any]) -> None:
|
|
382
|
+
_atomic_write(Path(path), _json_bytes(document))
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def _load_index(index_path: str | Path) -> dict[str, Any]:
|
|
386
|
+
document = json.loads(Path(index_path).read_text(encoding="utf-8"))
|
|
387
|
+
if not isinstance(document, dict) or not isinstance(document.get("episodes"), list):
|
|
388
|
+
raise ValueError("index must be a JSON object containing an episodes list")
|
|
389
|
+
return document
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def verify_index(index_path: str | Path, source_path: str | Path) -> dict[str, Any]:
|
|
393
|
+
problems: list[str] = []
|
|
394
|
+
try:
|
|
395
|
+
document = _load_index(index_path)
|
|
396
|
+
data = Path(source_path).read_bytes()
|
|
397
|
+
except (OSError, UnicodeError, json.JSONDecodeError, ValueError) as error:
|
|
398
|
+
return {"verified": False, "problems": [str(error)]}
|
|
399
|
+
if document.get("schema_version") != SCHEMA_VERSION:
|
|
400
|
+
problems.append("unsupported schema_version")
|
|
401
|
+
if document.get("record_type") != "episode_intake_index":
|
|
402
|
+
problems.append("record_type is not episode_intake_index")
|
|
403
|
+
if document.get("source_byte_length") != len(data):
|
|
404
|
+
problems.append("source_byte_length does not match")
|
|
405
|
+
try:
|
|
406
|
+
_portable_source_ref(Path(source_path), document.get("source_ref"))
|
|
407
|
+
except (TypeError, ValueError) as error:
|
|
408
|
+
problems.append(str(error))
|
|
409
|
+
episodes = document["episodes"]
|
|
410
|
+
if document.get("episode_count") != len(episodes):
|
|
411
|
+
problems.append("episode_count does not match episodes")
|
|
412
|
+
_, offsets = _line_table(data)
|
|
413
|
+
previous_end = -1
|
|
414
|
+
for position, row in enumerate(episodes, 1):
|
|
415
|
+
if not isinstance(row, dict):
|
|
416
|
+
problems.append(f"episode row {position} is not an object")
|
|
417
|
+
continue
|
|
418
|
+
label = str(row.get("episode_id", f"row {position}"))
|
|
419
|
+
start, end = row.get("byte_start"), row.get("byte_end")
|
|
420
|
+
if not isinstance(start, int) or not isinstance(end, int) or not (0 <= start < end <= len(data)):
|
|
421
|
+
problems.append(f"{label} has an invalid byte span")
|
|
422
|
+
continue
|
|
423
|
+
if start < previous_end:
|
|
424
|
+
problems.append(f"{label} overlaps or is out of source order")
|
|
425
|
+
previous_end = end
|
|
426
|
+
try:
|
|
427
|
+
expected_line_start = _line_number(offsets, start)
|
|
428
|
+
expected_line_end = _line_number(offsets, end, end=True)
|
|
429
|
+
except ValueError as error:
|
|
430
|
+
problems.append(f"{label}: {error}")
|
|
431
|
+
else:
|
|
432
|
+
if row.get("line_start") != expected_line_start or row.get("line_end") != expected_line_end:
|
|
433
|
+
problems.append(f"{label} line span does not match its byte span")
|
|
434
|
+
if row.get("byte_length") != end - start:
|
|
435
|
+
problems.append(f"{label} byte_length does not match its byte span")
|
|
436
|
+
problems.extend(_structural_problems(episodes, data))
|
|
437
|
+
if not any("byte span" in problem or "overlaps" in problem for problem in problems):
|
|
438
|
+
try:
|
|
439
|
+
expected_unmapped = _unmapped_spans(episodes, data, offsets)
|
|
440
|
+
except ValueError:
|
|
441
|
+
problems.append("unmapped spans cannot be located in the current source")
|
|
442
|
+
else:
|
|
443
|
+
if document.get("unmapped_spans") != expected_unmapped:
|
|
444
|
+
problems.append("unmapped_spans do not match bytes outside episode spans")
|
|
445
|
+
# Avoid multiplying an identical structural message if a hand-edited index
|
|
446
|
+
# already carried it in its advisory problems field.
|
|
447
|
+
problems = list(dict.fromkeys(problems))
|
|
448
|
+
return {"verified": not problems, "problems": problems}
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def _require_verified(index_path: str | Path, source_path: str | Path) -> dict[str, Any]:
|
|
452
|
+
result = verify_index(index_path, source_path)
|
|
453
|
+
if not result["verified"]:
|
|
454
|
+
raise ValueError("index verification failed: " + "; ".join(result["problems"]))
|
|
455
|
+
return _load_index(index_path)
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def slice_episode(
|
|
459
|
+
index_path: str | Path,
|
|
460
|
+
source_path: str | Path,
|
|
461
|
+
episode_id: str,
|
|
462
|
+
output_path: str | Path | None = None,
|
|
463
|
+
) -> bytes:
|
|
464
|
+
if output_path is not None and Path(output_path).resolve() in {
|
|
465
|
+
Path(index_path).resolve(),
|
|
466
|
+
Path(source_path).resolve(),
|
|
467
|
+
}:
|
|
468
|
+
raise ValueError("slice output must not replace its source or index")
|
|
469
|
+
document = _require_verified(index_path, source_path)
|
|
470
|
+
matches = [row for row in document["episodes"] if row.get("episode_id") == episode_id]
|
|
471
|
+
if len(matches) != 1:
|
|
472
|
+
raise ValueError(f"episode_id must identify exactly one span: {episode_id}")
|
|
473
|
+
data = Path(source_path).read_bytes()
|
|
474
|
+
row = matches[0]
|
|
475
|
+
content = data[row["byte_start"] : row["byte_end"]]
|
|
476
|
+
if output_path is not None:
|
|
477
|
+
_atomic_write(Path(output_path), content)
|
|
478
|
+
return content
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def _read_jsonl(path: Path, *, absent_ok: bool = False) -> list[dict[str, Any]]:
|
|
482
|
+
if absent_ok and not path.exists():
|
|
483
|
+
return []
|
|
484
|
+
records: list[dict[str, Any]] = []
|
|
485
|
+
for line_number, raw in enumerate(path.read_bytes().splitlines(), 1):
|
|
486
|
+
if not raw.strip():
|
|
487
|
+
continue
|
|
488
|
+
try:
|
|
489
|
+
record = json.loads(raw.decode("utf-8"))
|
|
490
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
|
491
|
+
raise ValueError(f"{path}: invalid JSONL line {line_number}: {error}") from error
|
|
492
|
+
if not isinstance(record, dict):
|
|
493
|
+
raise ValueError(f"{path}: JSONL line {line_number} is not an object")
|
|
494
|
+
records.append(record)
|
|
495
|
+
return records
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def _validated_records(records: list[dict[str, Any]], valid_ids: set[str], label: str) -> dict[str, dict[str, Any]]:
|
|
499
|
+
by_id: dict[str, dict[str, Any]] = {}
|
|
500
|
+
for position, record in enumerate(records, 1):
|
|
501
|
+
episode_id = record.get("episode_id")
|
|
502
|
+
if not isinstance(episode_id, str) or episode_id not in valid_ids:
|
|
503
|
+
raise ValueError(f"{label} record {position} has an episode_id outside the index")
|
|
504
|
+
if episode_id in by_id:
|
|
505
|
+
raise ValueError(f"{label} contains duplicate episode_id {episode_id}")
|
|
506
|
+
by_id[episode_id] = record
|
|
507
|
+
return by_id
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
def _jsonl_bytes(records: Iterable[dict[str, Any]]) -> bytes:
|
|
511
|
+
return b"".join(_json_bytes(record) for record in records)
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def progress(
|
|
515
|
+
index_path: str | Path,
|
|
516
|
+
source_path: str | Path,
|
|
517
|
+
map_path: str | Path,
|
|
518
|
+
checkpoint_path: str | Path | None = None,
|
|
519
|
+
*,
|
|
520
|
+
batch_size: int,
|
|
521
|
+
) -> dict[str, Any]:
|
|
522
|
+
if batch_size <= 0:
|
|
523
|
+
raise ValueError("batch_size must be positive")
|
|
524
|
+
if checkpoint_path is not None and Path(checkpoint_path).resolve() in {
|
|
525
|
+
Path(index_path).resolve(),
|
|
526
|
+
Path(source_path).resolve(),
|
|
527
|
+
Path(map_path).resolve(),
|
|
528
|
+
}:
|
|
529
|
+
raise ValueError("checkpoint must not replace the index, source, or episode-map")
|
|
530
|
+
document = _require_verified(index_path, source_path)
|
|
531
|
+
ordered_ids = [row["episode_id"] for row in document["episodes"]]
|
|
532
|
+
records = _read_jsonl(Path(map_path), absent_ok=True)
|
|
533
|
+
by_id = _validated_records(records, set(ordered_ids), "episode-map")
|
|
534
|
+
completed = [episode_id for episode_id in ordered_ids if episode_id in by_id]
|
|
535
|
+
pending = [episode_id for episode_id in ordered_ids if episode_id not in by_id]
|
|
536
|
+
checkpoint = {
|
|
537
|
+
"schema_version": SCHEMA_VERSION,
|
|
538
|
+
"record_type": "episode_intake_progress",
|
|
539
|
+
"completed": completed,
|
|
540
|
+
"pending": pending,
|
|
541
|
+
"next_batch": pending[:batch_size],
|
|
542
|
+
"complete": not pending,
|
|
543
|
+
}
|
|
544
|
+
if checkpoint_path is not None:
|
|
545
|
+
_atomic_write(Path(checkpoint_path), _json_bytes(checkpoint))
|
|
546
|
+
return checkpoint
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def merge_batch(
|
|
550
|
+
index_path: str | Path,
|
|
551
|
+
source_path: str | Path,
|
|
552
|
+
batch_path: str | Path,
|
|
553
|
+
current_map_path: str | Path,
|
|
554
|
+
output_path: str | Path,
|
|
555
|
+
checkpoint_path: str | Path | None = None,
|
|
556
|
+
*,
|
|
557
|
+
batch_size: int,
|
|
558
|
+
) -> dict[str, Any]:
|
|
559
|
+
if batch_size <= 0:
|
|
560
|
+
raise ValueError("batch_size must be positive")
|
|
561
|
+
protected = {
|
|
562
|
+
Path(index_path).resolve(),
|
|
563
|
+
Path(source_path).resolve(),
|
|
564
|
+
Path(batch_path).resolve(),
|
|
565
|
+
}
|
|
566
|
+
current_map = Path(current_map_path)
|
|
567
|
+
output = Path(output_path)
|
|
568
|
+
if current_map.resolve() in protected:
|
|
569
|
+
raise ValueError("current episode-map must not replace an index or source input")
|
|
570
|
+
if output.resolve() in {*protected, current_map.resolve()}:
|
|
571
|
+
raise ValueError("merged output must be separate from every input")
|
|
572
|
+
if checkpoint_path is not None and Path(checkpoint_path).resolve() in {
|
|
573
|
+
*protected,
|
|
574
|
+
current_map.resolve(),
|
|
575
|
+
output.resolve(),
|
|
576
|
+
}:
|
|
577
|
+
raise ValueError("checkpoint must not replace an input or merged output")
|
|
578
|
+
document = _require_verified(index_path, source_path)
|
|
579
|
+
ordered_ids = [row["episode_id"] for row in document["episodes"]]
|
|
580
|
+
valid_ids = set(ordered_ids)
|
|
581
|
+
batch_records = _read_jsonl(Path(batch_path))
|
|
582
|
+
if len(batch_records) > batch_size:
|
|
583
|
+
raise ValueError(f"batch contains {len(batch_records)} records; maximum is {batch_size}")
|
|
584
|
+
batch = _validated_records(batch_records, valid_ids, "batch")
|
|
585
|
+
existing_records = _read_jsonl(current_map, absent_ok=True)
|
|
586
|
+
existing = _validated_records(existing_records, valid_ids, "episode-map")
|
|
587
|
+
added: list[str] = []
|
|
588
|
+
for episode_id, record in batch.items():
|
|
589
|
+
if episode_id in existing:
|
|
590
|
+
if _json_bytes(existing[episode_id]) != _json_bytes(record):
|
|
591
|
+
raise ValueError(f"conflicting episode-map record: {episode_id}")
|
|
592
|
+
else:
|
|
593
|
+
existing[episode_id] = record
|
|
594
|
+
added.append(episode_id)
|
|
595
|
+
merged_records = [existing[episode_id] for episode_id in ordered_ids if episode_id in existing]
|
|
596
|
+
_atomic_write(output, _jsonl_bytes(merged_records))
|
|
597
|
+
derived = progress(
|
|
598
|
+
index_path,
|
|
599
|
+
source_path,
|
|
600
|
+
output,
|
|
601
|
+
checkpoint_path,
|
|
602
|
+
batch_size=batch_size,
|
|
603
|
+
)
|
|
604
|
+
return {
|
|
605
|
+
"output": str(output),
|
|
606
|
+
"added": [episode_id for episode_id in ordered_ids if episode_id in set(added)],
|
|
607
|
+
"progress": derived,
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
def _parser() -> argparse.ArgumentParser:
|
|
612
|
+
parser = argparse.ArgumentParser(description="Byte-accurate multi-episode screenplay intake guard")
|
|
613
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
614
|
+
index = commands.add_parser("index")
|
|
615
|
+
index.add_argument("source", type=Path)
|
|
616
|
+
index.add_argument("--out", type=Path, required=True)
|
|
617
|
+
index.add_argument("--source-ref")
|
|
618
|
+
manual = commands.add_parser("manual-index")
|
|
619
|
+
manual.add_argument("source", type=Path)
|
|
620
|
+
manual.add_argument("boundaries", type=Path)
|
|
621
|
+
manual.add_argument("--out", type=Path, required=True)
|
|
622
|
+
manual.add_argument("--source-ref")
|
|
623
|
+
verify = commands.add_parser("verify")
|
|
624
|
+
verify.add_argument("index", type=Path)
|
|
625
|
+
verify.add_argument("source", type=Path)
|
|
626
|
+
slice_command = commands.add_parser("slice")
|
|
627
|
+
slice_command.add_argument("index", type=Path)
|
|
628
|
+
slice_command.add_argument("source", type=Path)
|
|
629
|
+
slice_command.add_argument("episode_id")
|
|
630
|
+
slice_command.add_argument("--out", type=Path, required=True)
|
|
631
|
+
status = commands.add_parser("progress", aliases=["status"])
|
|
632
|
+
status.add_argument("index", type=Path)
|
|
633
|
+
status.add_argument("source", type=Path)
|
|
634
|
+
status.add_argument("episode_map", type=Path)
|
|
635
|
+
status.add_argument("--checkpoint", type=Path)
|
|
636
|
+
status.add_argument("--batch-size", type=int, required=True)
|
|
637
|
+
merge = commands.add_parser("merge")
|
|
638
|
+
merge.add_argument("index", type=Path)
|
|
639
|
+
merge.add_argument("source", type=Path)
|
|
640
|
+
merge.add_argument("batch", type=Path)
|
|
641
|
+
merge.add_argument("current_episode_map", type=Path)
|
|
642
|
+
merge.add_argument("--out", type=Path, required=True)
|
|
643
|
+
merge.add_argument("--checkpoint", type=Path)
|
|
644
|
+
merge.add_argument("--batch-size", type=int, required=True)
|
|
645
|
+
return parser
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
def main(argv: list[str] | None = None) -> int:
|
|
649
|
+
args = _parser().parse_args(argv)
|
|
650
|
+
try:
|
|
651
|
+
if args.command in {"index", "manual-index"}:
|
|
652
|
+
if args.source.resolve() == args.out.resolve():
|
|
653
|
+
raise ValueError("index output must not replace its source")
|
|
654
|
+
if args.command == "manual-index" and args.boundaries.resolve() == args.out.resolve():
|
|
655
|
+
raise ValueError("index output must not replace its boundaries input")
|
|
656
|
+
document = (
|
|
657
|
+
build_index(args.source, source_ref=args.source_ref)
|
|
658
|
+
if args.command == "index"
|
|
659
|
+
else build_manual_index(
|
|
660
|
+
args.source,
|
|
661
|
+
args.boundaries,
|
|
662
|
+
source_ref=args.source_ref,
|
|
663
|
+
)
|
|
664
|
+
)
|
|
665
|
+
write_index(args.out, document)
|
|
666
|
+
result: Any = {"output": str(args.out), "episode_count": document["episode_count"]}
|
|
667
|
+
if document["problems"]:
|
|
668
|
+
result["problems"] = document["problems"]
|
|
669
|
+
print(json.dumps(result, sort_keys=True))
|
|
670
|
+
return 2
|
|
671
|
+
elif args.command == "verify":
|
|
672
|
+
result = verify_index(args.index, args.source)
|
|
673
|
+
if not result["verified"]:
|
|
674
|
+
print(json.dumps(result, sort_keys=True), file=sys.stderr)
|
|
675
|
+
return 1
|
|
676
|
+
elif args.command == "slice":
|
|
677
|
+
content = slice_episode(args.index, args.source, args.episode_id, args.out)
|
|
678
|
+
result = {"output": str(args.out), "episode_id": args.episode_id, "byte_length": len(content)}
|
|
679
|
+
elif args.command in {"progress", "status"}:
|
|
680
|
+
result = progress(args.index, args.source, args.episode_map, args.checkpoint, batch_size=args.batch_size)
|
|
681
|
+
else:
|
|
682
|
+
result = merge_batch(
|
|
683
|
+
args.index,
|
|
684
|
+
args.source,
|
|
685
|
+
args.batch,
|
|
686
|
+
args.current_episode_map,
|
|
687
|
+
args.out,
|
|
688
|
+
args.checkpoint,
|
|
689
|
+
batch_size=args.batch_size,
|
|
690
|
+
)
|
|
691
|
+
except (OSError, UnicodeError, json.JSONDecodeError, ValueError) as error:
|
|
692
|
+
print(json.dumps({"error": str(error)}), file=sys.stderr)
|
|
693
|
+
return 1
|
|
694
|
+
print(json.dumps(result, sort_keys=True))
|
|
695
|
+
return 0
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
if __name__ == "__main__":
|
|
699
|
+
raise SystemExit(main())
|