@shakudo/kaji-setup-external 1.0.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/README.md +155 -0
- package/assets/skills/ci-cd/.claude-plugin/plugin.json +8 -0
- package/assets/skills/ci-cd/SKILL.md +573 -0
- package/assets/skills/ci-cd/assets/templates/github-actions/docker-build.yml +164 -0
- package/assets/skills/ci-cd/assets/templates/github-actions/go-ci.yml +420 -0
- package/assets/skills/ci-cd/assets/templates/github-actions/node-ci.yml +313 -0
- package/assets/skills/ci-cd/assets/templates/github-actions/python-ci.yml +388 -0
- package/assets/skills/ci-cd/assets/templates/github-actions/security-scan.yml +416 -0
- package/assets/skills/ci-cd/assets/templates/gitlab-ci/docker-build.yml +298 -0
- package/assets/skills/ci-cd/assets/templates/gitlab-ci/go-ci.yml +548 -0
- package/assets/skills/ci-cd/assets/templates/gitlab-ci/node-ci.yml +334 -0
- package/assets/skills/ci-cd/assets/templates/gitlab-ci/python-ci.yml +472 -0
- package/assets/skills/ci-cd/assets/templates/gitlab-ci/security-scan.yml +479 -0
- package/assets/skills/ci-cd/references/best_practices.md +675 -0
- package/assets/skills/ci-cd/references/devsecops.md +862 -0
- package/assets/skills/ci-cd/references/optimization.md +651 -0
- package/assets/skills/ci-cd/references/security.md +611 -0
- package/assets/skills/ci-cd/references/troubleshooting.md +656 -0
- package/assets/skills/ci-cd/scripts/ci_health.py +301 -0
- package/assets/skills/ci-cd/scripts/pipeline_analyzer.py +440 -0
- package/assets/skills/context-optimization/CONTRIBUTING.md +78 -0
- package/assets/skills/context-optimization/LICENSE +22 -0
- package/assets/skills/context-optimization/README.md +228 -0
- package/assets/skills/context-optimization/SKILL.md +104 -0
- package/assets/skills/context-optimization/docs/agentskills.md +1264 -0
- package/assets/skills/context-optimization/docs/blogs.md +1230 -0
- package/assets/skills/context-optimization/docs/claude_research.md +85 -0
- package/assets/skills/context-optimization/docs/compression.md +298 -0
- package/assets/skills/context-optimization/docs/gemini_research.md +22 -0
- package/assets/skills/context-optimization/docs/hncapsule.md +92 -0
- package/assets/skills/context-optimization/docs/netflix_context.md +10 -0
- package/assets/skills/context-optimization/docs/vercel_tool.md +140 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/README.md +78 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/SKILL.md +380 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/examples/gertrude-stein/README.md +168 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/examples/gertrude-stein/dataset_sample.jsonl +5 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/examples/gertrude-stein/pangram/Screenshot 2025-12-27 at 3.05.04/342/200/257AM.png +0 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/examples/gertrude-stein/pangram/Screenshot 2025-12-27 at 3.05.36/342/200/257AM.png +0 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/examples/gertrude-stein/pangram/Screenshot 2025-12-27 at 3.07.18/342/200/257AM.png +0 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/examples/gertrude-stein/sample_outputs.md +63 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/examples/gertrude-stein/training_config.json +80 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/references/segmentation-strategies.md +324 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/references/tinker-format.md +211 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/references/tinker.txt +3176 -0
- package/assets/skills/context-optimization/examples/book-sft-pipeline/scripts/pipeline_example.py +187 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/AGENT.md +35 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/HOW-SKILLS-BUILT-THIS.md +407 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/README.md +209 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/SKILL.md +203 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/SKILLS-MAPPING.md +219 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/agents/AGENTS.md +82 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/agents/scripts/content_ideas.py +132 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/agents/scripts/idea_to_draft.py +181 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/agents/scripts/stale_contacts.py +139 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/agents/scripts/weekly_review.py +121 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/content/CONTENT.md +88 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/content/calendar.md +108 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/content/engagement.jsonl +2 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/content/ideas.jsonl +2 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/content/posts.jsonl +2 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/content/templates/linkedin-post.md +102 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/content/templates/newsletter.md +92 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/content/templates/thread.md +73 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/examples/content-workflow.md +204 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/examples/meeting-prep.md +243 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/identity/IDENTITY.md +46 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/identity/bio-variants.md +101 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/identity/brand.md +165 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/identity/prompts/content-generation.xml +46 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/identity/prompts/reply-generator.xml +40 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/identity/values.yaml +60 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/identity/voice.md +165 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/knowledge/KNOWLEDGE.md +85 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/knowledge/bookmarks.jsonl +2 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/knowledge/competitors.md +117 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/knowledge/learning.yaml +74 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/knowledge/research/_template.md +79 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/network/NETWORK.md +110 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/network/circles.yaml +80 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/network/contacts.jsonl +2 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/network/interactions.jsonl +2 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/network/intros.md +92 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/operations/OPERATIONS.md +75 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/operations/goals.yaml +83 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/operations/meetings.jsonl +2 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/operations/metrics.jsonl +2 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/operations/reviews/_weekly_template.md +114 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/operations/todos.md +76 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/package.json +41 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/references/file-formats.md +386 -0
- package/assets/skills/context-optimization/examples/digital-brain-skill/scripts/install.sh +79 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/README.md +620 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/SKILL.md +221 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/docs/agentthinking.md +63 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/docs/interleavedthinking.md +610 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/docs/m2-1.md +224 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/examples/01_basic_capture.py +76 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/examples/02_tool_usage.py +187 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/examples/03_full_optimization.py +1222 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/generated_skills/comprehensive-research-agent/SKILL.md +90 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/generated_skills/comprehensive-research-agent/references/optimization_summary.json +9 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/generated_skills/comprehensive-research-agent/references/optimized_prompt.txt +1 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/generated_skills/comprehensive-research-agent/references/patterns_found.json +205 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/final_prompt.txt +67 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_1/analysis.txt +48 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_1/optimization.txt +15 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_1/optimized_prompt.txt +1 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_1/trace.txt +178 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_10/analysis.txt +47 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_10/trace.txt +162 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_2/analysis.txt +48 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_2/optimization.txt +130 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_2/optimized_prompt.txt +72 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_2/trace.txt +156 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_3/analysis.txt +46 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_3/optimization.txt +147 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_3/optimized_prompt.txt +84 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_3/trace.txt +159 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_4/analysis.txt +46 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_4/optimization.txt +134 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_4/optimized_prompt.txt +67 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_4/trace.txt +165 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_5/analysis.txt +50 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_5/optimization.txt +135 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_5/optimized_prompt.txt +71 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_5/trace.txt +146 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_6/analysis.txt +15 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_6/optimization.txt +15 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_6/optimized_prompt.txt +1 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_6/trace.txt +147 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_7/analysis.txt +46 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_7/optimization.txt +103 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_7/optimized_prompt.txt +45 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_7/trace.txt +134 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_8/analysis.txt +47 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_8/optimization.txt +114 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_8/optimized_prompt.txt +60 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_8/trace.txt +135 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_9/analysis.txt +44 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_9/optimization.txt +106 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_9/optimized_prompt.txt +51 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/iteration_9/trace.txt +170 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/optimization_artifacts/summary.json +11 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/pyproject.toml +70 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/reasoning_trace_optimizer/__init__.py +53 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/reasoning_trace_optimizer/analyzer.py +465 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/reasoning_trace_optimizer/capture.py +417 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/reasoning_trace_optimizer/cli.py +271 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/reasoning_trace_optimizer/loop.py +468 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/reasoning_trace_optimizer/models.py +193 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/reasoning_trace_optimizer/optimizer.py +449 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/reasoning_trace_optimizer/skill_generator.py +502 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/tests/__init__.py +1 -0
- package/assets/skills/context-optimization/examples/interleaved_thinking/tests/test_models.py +144 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/.prettierrc +8 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/CONTRIBUTING.md +78 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/LICENSE +21 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/README.md +659 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/agents/evaluator-agent/evaluator-agent.md +177 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/agents/index.md +114 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/agents/orchestrator-agent/orchestrator-agent.md +205 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/agents/research-agent/research-agent.md +183 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/env.example +6 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/eslint.config.js +18 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/examples/basic-evaluation.ts +89 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/examples/full-evaluation-workflow.ts +136 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/examples/generate-rubric.ts +67 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/examples/pairwise-comparison.ts +97 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/package.json +79 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/prompts/agent-system/orchestrator-prompt.md +197 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/prompts/evaluation/direct-scoring-prompt.md +153 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/prompts/evaluation/pairwise-comparison-prompt.md +200 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/prompts/index.md +138 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/prompts/research/research-synthesis-prompt.md +171 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/skills/context-fundamentals/context-fundamentals.md +114 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/skills/index.md +79 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/skills/llm-evaluator/llm-evaluator.md +77 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/skills/tool-design/tool-design.md +198 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/src/agents/evaluator.ts +112 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/src/agents/index.ts +3 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/src/config/index.ts +18 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/src/index.ts +19 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/src/tools/evaluation/direct-score.ts +164 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/src/tools/evaluation/generate-rubric.ts +161 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/src/tools/evaluation/index.ts +9 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/src/tools/evaluation/pairwise-compare.ts +255 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tests/evaluation.test.ts +233 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tests/setup.ts +27 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tests/skills.test.ts +213 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tools/evaluation/direct-score.md +159 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tools/evaluation/generate-rubric.md +189 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tools/evaluation/pairwise-compare.md +182 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tools/index.md +141 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tools/orchestration/delegate-to-agent.md +171 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tools/research/read-url.md +162 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tools/research/web-search.md +128 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/tsconfig.json +26 -0
- package/assets/skills/context-optimization/examples/llm-as-judge-skills/vitest.config.ts +20 -0
- package/assets/skills/context-optimization/examples/x-to-book-system/PRD.md +644 -0
- package/assets/skills/context-optimization/examples/x-to-book-system/README.md +181 -0
- package/assets/skills/context-optimization/examples/x-to-book-system/SKILLS-MAPPING.md +187 -0
- package/assets/skills/context-optimization/researcher/example_output.md +75 -0
- package/assets/skills/context-optimization/researcher/llm-as-a-judge.md +362 -0
- package/assets/skills/context-optimization/skills/advanced-evaluation/SKILL.md +454 -0
- package/assets/skills/context-optimization/skills/advanced-evaluation/references/bias-mitigation.md +288 -0
- package/assets/skills/context-optimization/skills/advanced-evaluation/references/implementation-patterns.md +315 -0
- package/assets/skills/context-optimization/skills/advanced-evaluation/references/metrics-guide.md +331 -0
- package/assets/skills/context-optimization/skills/advanced-evaluation/scripts/evaluation_example.py +337 -0
- package/assets/skills/context-optimization/skills/bdi-mental-states/SKILL.md +295 -0
- package/assets/skills/context-optimization/skills/bdi-mental-states/references/bdi-ontology-core.md +207 -0
- package/assets/skills/context-optimization/skills/bdi-mental-states/references/framework-integration.md +582 -0
- package/assets/skills/context-optimization/skills/bdi-mental-states/references/rdf-examples.md +315 -0
- package/assets/skills/context-optimization/skills/bdi-mental-states/references/sparql-competency.md +420 -0
- package/assets/skills/context-optimization/skills/context-compression/SKILL.md +265 -0
- package/assets/skills/context-optimization/skills/context-compression/references/evaluation-framework.md +213 -0
- package/assets/skills/context-optimization/skills/context-compression/scripts/compression_evaluator.py +658 -0
- package/assets/skills/context-optimization/skills/context-degradation/SKILL.md +231 -0
- package/assets/skills/context-optimization/skills/context-degradation/references/patterns.md +314 -0
- package/assets/skills/context-optimization/skills/context-degradation/scripts/degradation_detector.py +419 -0
- package/assets/skills/context-optimization/skills/context-fundamentals/SKILL.md +185 -0
- package/assets/skills/context-optimization/skills/context-fundamentals/references/context-components.md +283 -0
- package/assets/skills/context-optimization/skills/context-fundamentals/scripts/context_manager.py +370 -0
- package/assets/skills/context-optimization/skills/context-optimization/SKILL.md +179 -0
- package/assets/skills/context-optimization/skills/context-optimization/references/optimization_techniques.md +272 -0
- package/assets/skills/context-optimization/skills/context-optimization/scripts/compaction.py +379 -0
- package/assets/skills/context-optimization/skills/evaluation/SKILL.md +231 -0
- package/assets/skills/context-optimization/skills/evaluation/references/metrics.md +339 -0
- package/assets/skills/context-optimization/skills/evaluation/scripts/evaluator.py +474 -0
- package/assets/skills/context-optimization/skills/filesystem-context/SKILL.md +321 -0
- package/assets/skills/context-optimization/skills/filesystem-context/references/implementation-patterns.md +549 -0
- package/assets/skills/context-optimization/skills/filesystem-context/scripts/filesystem_context.py +353 -0
- package/assets/skills/context-optimization/skills/hosted-agents/SKILL.md +279 -0
- package/assets/skills/context-optimization/skills/hosted-agents/references/infrastructure-patterns.md +700 -0
- package/assets/skills/context-optimization/skills/hosted-agents/scripts/sandbox_manager.py +495 -0
- package/assets/skills/context-optimization/skills/memory-systems/SKILL.md +221 -0
- package/assets/skills/context-optimization/skills/memory-systems/references/implementation.md +458 -0
- package/assets/skills/context-optimization/skills/memory-systems/scripts/memory_store.py +396 -0
- package/assets/skills/context-optimization/skills/multi-agent-patterns/SKILL.md +255 -0
- package/assets/skills/context-optimization/skills/multi-agent-patterns/references/frameworks.md +433 -0
- package/assets/skills/context-optimization/skills/multi-agent-patterns/scripts/coordination.py +439 -0
- package/assets/skills/context-optimization/skills/project-development/SKILL.md +342 -0
- package/assets/skills/context-optimization/skills/project-development/references/case-studies.md +388 -0
- package/assets/skills/context-optimization/skills/project-development/references/pipeline-patterns.md +610 -0
- package/assets/skills/context-optimization/skills/project-development/scripts/pipeline_template.py +677 -0
- package/assets/skills/context-optimization/skills/tool-design/SKILL.md +311 -0
- package/assets/skills/context-optimization/skills/tool-design/references/architectural_reduction.md +210 -0
- package/assets/skills/context-optimization/skills/tool-design/references/best_practices.md +176 -0
- package/assets/skills/context-optimization/skills/tool-design/scripts/description_generator.py +237 -0
- package/assets/skills/context-optimization/template/SKILL.md +98 -0
- package/assets/skills/dremio-analytics/SKILL.md +287 -0
- package/assets/skills/elevenlabs-voice/SKILL.md +269 -0
- package/assets/skills/git-workflow/SKILL.md +266 -0
- package/assets/skills/gitops-workflows/.claude-plugin/plugin.json +8 -0
- package/assets/skills/gitops-workflows/SKILL.md +568 -0
- package/assets/skills/gitops-workflows/assets/applicationsets/cluster-generator.yaml +32 -0
- package/assets/skills/gitops-workflows/assets/argocd/install-argocd-3.x.yaml +92 -0
- package/assets/skills/gitops-workflows/assets/flux/flux-bootstrap-github.sh +49 -0
- package/assets/skills/gitops-workflows/assets/flux/oci-helmrelease.yaml +38 -0
- package/assets/skills/gitops-workflows/assets/progressive-delivery/argo-rollouts-canary.yaml +62 -0
- package/assets/skills/gitops-workflows/assets/secrets/sops-age-config.yaml +33 -0
- package/assets/skills/gitops-workflows/references/argocd_vs_flux.md +243 -0
- package/assets/skills/gitops-workflows/references/best_practices.md +160 -0
- package/assets/skills/gitops-workflows/references/multi_cluster.md +80 -0
- package/assets/skills/gitops-workflows/references/oci_artifacts.md +290 -0
- package/assets/skills/gitops-workflows/references/progressive_delivery.md +94 -0
- package/assets/skills/gitops-workflows/references/repo_patterns.md +184 -0
- package/assets/skills/gitops-workflows/references/secret_management.md +213 -0
- package/assets/skills/gitops-workflows/references/troubleshooting.md +134 -0
- package/assets/skills/gitops-workflows/scripts/applicationset_generator.py +156 -0
- package/assets/skills/gitops-workflows/scripts/check_argocd_health.py +275 -0
- package/assets/skills/gitops-workflows/scripts/check_flux_health.py +418 -0
- package/assets/skills/gitops-workflows/scripts/oci_artifact_checker.py +150 -0
- package/assets/skills/gitops-workflows/scripts/promotion_validator.py +88 -0
- package/assets/skills/gitops-workflows/scripts/secret_audit.py +178 -0
- package/assets/skills/gitops-workflows/scripts/sync_drift_detector.py +144 -0
- package/assets/skills/gitops-workflows/scripts/validate_gitops_repo.py +299 -0
- package/assets/skills/iac-terraform/.claude-plugin/plugin.json +8 -0
- package/assets/skills/iac-terraform/SKILL.md +653 -0
- package/assets/skills/iac-terraform/assets/templates/MODULE_TEMPLATE.md +386 -0
- package/assets/skills/iac-terraform/assets/workflows/github-actions-terraform.yml +224 -0
- package/assets/skills/iac-terraform/assets/workflows/github-actions-terragrunt.yml +236 -0
- package/assets/skills/iac-terraform/assets/workflows/gitlab-ci-terraform.yml +184 -0
- package/assets/skills/iac-terraform/references/best_practices.md +709 -0
- package/assets/skills/iac-terraform/references/cost_optimization.md +665 -0
- package/assets/skills/iac-terraform/references/troubleshooting.md +635 -0
- package/assets/skills/iac-terraform/scripts/init_module.py +319 -0
- package/assets/skills/iac-terraform/scripts/inspect_state.py +232 -0
- package/assets/skills/iac-terraform/scripts/validate_module.py +227 -0
- package/assets/skills/k8s-troubleshooter/.claude-plugin/plugin.json +8 -0
- package/assets/skills/k8s-troubleshooter/SKILL.md +336 -0
- package/assets/skills/k8s-troubleshooter/references/common_issues.md +582 -0
- package/assets/skills/k8s-troubleshooter/references/helm_troubleshooting.md +708 -0
- package/assets/skills/k8s-troubleshooter/references/incident_response.md +466 -0
- package/assets/skills/k8s-troubleshooter/references/performance_troubleshooting.md +687 -0
- package/assets/skills/k8s-troubleshooter/scripts/check_namespace.py +500 -0
- package/assets/skills/k8s-troubleshooter/scripts/cluster_health.py +223 -0
- package/assets/skills/k8s-troubleshooter/scripts/diagnose_pod.py +157 -0
- package/assets/skills/mattermost-notify/SKILL.md +248 -0
- package/assets/skills/monitoring-observability/SKILL.md +869 -0
- package/assets/skills/monitoring-observability/assets/templates/otel-config/collector-config.yaml +227 -0
- package/assets/skills/monitoring-observability/assets/templates/prometheus-alerts/kubernetes-alerts.yml +293 -0
- package/assets/skills/monitoring-observability/assets/templates/prometheus-alerts/webapp-alerts.yml +243 -0
- package/assets/skills/monitoring-observability/assets/templates/runbooks/incident-runbook-template.md +409 -0
- package/assets/skills/monitoring-observability/monitoring-observability.skill +0 -0
- package/assets/skills/monitoring-observability/references/alerting_best_practices.md +609 -0
- package/assets/skills/monitoring-observability/references/datadog_migration.md +649 -0
- package/assets/skills/monitoring-observability/references/dql_promql_translation.md +756 -0
- package/assets/skills/monitoring-observability/references/logging_guide.md +775 -0
- package/assets/skills/monitoring-observability/references/metrics_design.md +406 -0
- package/assets/skills/monitoring-observability/references/slo_sla_guide.md +652 -0
- package/assets/skills/monitoring-observability/references/tool_comparison.md +697 -0
- package/assets/skills/monitoring-observability/references/tracing_guide.md +663 -0
- package/assets/skills/monitoring-observability/scripts/alert_quality_checker.py +315 -0
- package/assets/skills/monitoring-observability/scripts/analyze_metrics.py +279 -0
- package/assets/skills/monitoring-observability/scripts/dashboard_generator.py +395 -0
- package/assets/skills/monitoring-observability/scripts/datadog_cost_analyzer.py +477 -0
- package/assets/skills/monitoring-observability/scripts/health_check_validator.py +297 -0
- package/assets/skills/monitoring-observability/scripts/log_analyzer.py +321 -0
- package/assets/skills/monitoring-observability/scripts/slo_calculator.py +365 -0
- package/assets/skills/neo4j-graph-rag/SKILL.md +258 -0
- package/assets/skills/pagerduty-ops/SKILL.md +380 -0
- package/assets/skills/playwright/API_REFERENCE.md +653 -0
- package/assets/skills/playwright/SKILL.md +453 -0
- package/assets/skills/playwright/lib/helpers.js +441 -0
- package/assets/skills/playwright/package.json +26 -0
- package/assets/skills/playwright/run.js +228 -0
- package/assets/skills/project-memory/README.md +687 -0
- package/assets/skills/project-memory/SKILL.md +298 -0
- package/assets/skills/project-memory/references/bugs_template.md +41 -0
- package/assets/skills/project-memory/references/decisions_template.md +92 -0
- package/assets/skills/project-memory/references/issues_template.md +76 -0
- package/assets/skills/project-memory/references/key_facts_template.md +158 -0
- package/assets/skills/recruit-workflow/SKILL.md +276 -0
- package/assets/skills/recruit-workflow/references/email-templates.md +347 -0
- package/assets/skills/recruit-workflow/references/workflow-stages.md +395 -0
- package/assets/skills/recruit-workflow/scripts/clay_client.py +188 -0
- package/assets/skills/recruit-workflow/scripts/lever_client.py +197 -0
- package/assets/skills/recruit-workflow/scripts/mailgun_client.py +245 -0
- package/assets/skills/recruit-workflow/scripts/minio_client.py +426 -0
- package/assets/skills/shakudo-microservice/SKILL.md +215 -0
- package/assets/skills/tmux/SKILL.md +631 -0
- package/assets/skills/tmux/references/direct-socket-control.md +108 -0
- package/assets/skills/tmux/references/session-lifecycle.md +503 -0
- package/assets/skills/tmux/references/session-registry.md +1484 -0
- package/assets/skills/tmux/tools/cleanup-sessions.sh +263 -0
- package/assets/skills/tmux/tools/create-session.sh +224 -0
- package/assets/skills/tmux/tools/find-sessions.sh +262 -0
- package/assets/skills/tmux/tools/kill-session.sh +308 -0
- package/assets/skills/tmux/tools/lib/registry.sh +437 -0
- package/assets/skills/tmux/tools/lib/time_utils.sh +54 -0
- package/assets/skills/tmux/tools/list-sessions.sh +255 -0
- package/assets/skills/tmux/tools/pane-health.sh +424 -0
- package/assets/skills/tmux/tools/safe-send.sh +503 -0
- package/assets/skills/tmux/tools/wait-for-text.sh +260 -0
- package/assets/skills/twilio-sms/SKILL.md +508 -0
- package/assets/skills/zellij/SKILL.md +274 -0
- package/assets/skills/zellij/references/actions.md +558 -0
- package/assets/skills/zellij/references/layouts.md +424 -0
- package/bin/cli.ts +46 -0
- package/package.json +43 -0
- package/src/alias.ts +108 -0
- package/src/backup.ts +51 -0
- package/src/config.ts +115 -0
- package/src/dependencies.ts +163 -0
- package/src/errors.ts +77 -0
- package/src/index.ts +207 -0
- package/src/prompts.ts +142 -0
- package/src/schemas.ts +21 -0
- package/src/skills.ts +45 -0
- package/src/speckit.ts +116 -0
- package/src/types.ts +106 -0
- package/src/utils.ts +110 -0
- package/src/vibe-git.ts +50 -0
- package/templates/.specify/memory/constitution.md +109 -0
- package/templates/.specify/scripts/bash/check-prerequisites.sh +262 -0
- package/templates/.specify/scripts/bash/common.sh +670 -0
- package/templates/.specify/scripts/bash/create-new-feature.sh +594 -0
- package/templates/.specify/scripts/bash/create-worktree-feature.sh +401 -0
- package/templates/.specify/scripts/bash/init-workspace.sh +433 -0
- package/templates/.specify/scripts/bash/list-spec-worktrees.sh +198 -0
- package/templates/.specify/scripts/bash/setup-plan.sh +105 -0
- package/templates/.specify/scripts/bash/test-workspace-rollup.sh +175 -0
- package/templates/.specify/scripts/bash/update-agent-context.sh +799 -0
- package/templates/.specify/templates/agent-file-template.md +28 -0
- package/templates/.specify/templates/checklist-template.md +40 -0
- package/templates/.specify/templates/commands/analyze.md +197 -0
- package/templates/.specify/templates/commands/checklist.md +306 -0
- package/templates/.specify/templates/commands/clarify.md +194 -0
- package/templates/.specify/templates/commands/constitution.md +97 -0
- package/templates/.specify/templates/commands/implement.md +149 -0
- package/templates/.specify/templates/commands/plan.md +123 -0
- package/templates/.specify/templates/commands/projects.md +48 -0
- package/templates/.specify/templates/commands/rollup.md +66 -0
- package/templates/.specify/templates/commands/specify.md +275 -0
- package/templates/.specify/templates/commands/specs.md +71 -0
- package/templates/.specify/templates/commands/tasks.md +151 -0
- package/templates/.specify/templates/commands/taskstoissues.md +35 -0
- package/templates/.specify/templates/commands/workspace.md +128 -0
- package/templates/.specify/templates/plan-template.md +104 -0
- package/templates/.specify/templates/spec-template.md +115 -0
- package/templates/.specify/templates/tasks-template.md +251 -0
- package/templates/.specify/templates/workspace.yaml +110 -0
- package/templates/.specify/workspace.yaml +95 -0
- package/templates/AGENTS.md +460 -0
- package/templates/oh-my-opencode.json +27 -0
- package/templates/opencode.json +383 -0
- package/templates/package.json +10 -0
- package/templates/project-memory/bugs.md +16 -0
- package/templates/project-memory/decisions.md +22 -0
- package/templates/project-memory/issues.md +15 -0
- package/templates/project-memory/key_facts.md +26 -0
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
# Pipeline Patterns for LLM Projects
|
|
2
|
+
|
|
3
|
+
This reference provides detailed patterns for structuring LLM processing pipelines. These patterns apply to batch processing, data analysis, content generation, and similar workloads.
|
|
4
|
+
|
|
5
|
+
## The Canonical Pipeline
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
acquire → prepare → process → parse → render
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Stage Characteristics
|
|
12
|
+
|
|
13
|
+
| Stage | Deterministic | Expensive | Parallelizable | Idempotent |
|
|
14
|
+
|-------|---------------|-----------|----------------|------------|
|
|
15
|
+
| Acquire | Yes | Low | Yes | Yes |
|
|
16
|
+
| Prepare | Yes | Low | Yes | Yes |
|
|
17
|
+
| Process | No | High | Yes | Yes (with caching) |
|
|
18
|
+
| Parse | Yes | Low | Yes | Yes |
|
|
19
|
+
| Render | Yes | Low | Partially | Yes |
|
|
20
|
+
|
|
21
|
+
The key insight: only the Process stage involves LLM calls. All other stages are deterministic transformations that can be debugged, tested, and iterated independently.
|
|
22
|
+
|
|
23
|
+
## File System State Management
|
|
24
|
+
|
|
25
|
+
### Directory Structure Pattern
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
project/
|
|
29
|
+
├── data/
|
|
30
|
+
│ └── {batch_id}/
|
|
31
|
+
│ └── {item_id}/
|
|
32
|
+
│ ├── raw.json # Acquire output
|
|
33
|
+
│ ├── prompt.md # Prepare output
|
|
34
|
+
│ ├── response.md # Process output
|
|
35
|
+
│ └── parsed.json # Parse output
|
|
36
|
+
├── output/
|
|
37
|
+
│ └── {batch_id}/
|
|
38
|
+
│ └── index.html # Render output
|
|
39
|
+
└── config/
|
|
40
|
+
└── prompts/
|
|
41
|
+
└── template.md # Prompt templates
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### State Checking Pattern
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
def needs_processing(item_dir: Path, stage: str) -> bool:
|
|
48
|
+
"""Check if an item needs processing for a given stage."""
|
|
49
|
+
stage_outputs = {
|
|
50
|
+
"acquire": ["raw.json"],
|
|
51
|
+
"prepare": ["prompt.md"],
|
|
52
|
+
"process": ["response.md"],
|
|
53
|
+
"parse": ["parsed.json"],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for output_file in stage_outputs[stage]:
|
|
57
|
+
if not (item_dir / output_file).exists():
|
|
58
|
+
return True
|
|
59
|
+
return False
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Clean/Retry Pattern
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
def clean_from_stage(item_dir: Path, stage: str):
|
|
66
|
+
"""Remove outputs from stage and all downstream stages."""
|
|
67
|
+
stage_order = ["acquire", "prepare", "process", "parse", "render"]
|
|
68
|
+
stage_outputs = {
|
|
69
|
+
"acquire": ["raw.json"],
|
|
70
|
+
"prepare": ["prompt.md"],
|
|
71
|
+
"process": ["response.md"],
|
|
72
|
+
"parse": ["parsed.json"],
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
start_idx = stage_order.index(stage)
|
|
76
|
+
for s in stage_order[start_idx:]:
|
|
77
|
+
for output_file in stage_outputs.get(s, []):
|
|
78
|
+
filepath = item_dir / output_file
|
|
79
|
+
if filepath.exists():
|
|
80
|
+
filepath.unlink()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Parallel Execution Patterns
|
|
84
|
+
|
|
85
|
+
### ThreadPoolExecutor for LLM Calls
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
89
|
+
|
|
90
|
+
def process_batch(items: list, max_workers: int = 10):
|
|
91
|
+
"""Process items in parallel with progress tracking."""
|
|
92
|
+
results = []
|
|
93
|
+
|
|
94
|
+
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
|
95
|
+
futures = {executor.submit(process_item, item): item for item in items}
|
|
96
|
+
|
|
97
|
+
for future in as_completed(futures):
|
|
98
|
+
item = futures[future]
|
|
99
|
+
try:
|
|
100
|
+
result = future.result()
|
|
101
|
+
results.append((item, result, None))
|
|
102
|
+
except Exception as e:
|
|
103
|
+
results.append((item, None, str(e)))
|
|
104
|
+
|
|
105
|
+
return results
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Batch Size Considerations
|
|
109
|
+
|
|
110
|
+
- **Small batches (1-10)**: Sequential processing is fine; overhead of parallelization not worth it
|
|
111
|
+
- **Medium batches (10-100)**: Parallelize with 5-15 workers depending on API rate limits
|
|
112
|
+
- **Large batches (100+)**: Consider chunking with checkpoints; implement resume capability
|
|
113
|
+
|
|
114
|
+
### Rate Limiting
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import time
|
|
118
|
+
from functools import wraps
|
|
119
|
+
|
|
120
|
+
def rate_limited(calls_per_second: float):
|
|
121
|
+
"""Decorator to rate limit function calls."""
|
|
122
|
+
min_interval = 1.0 / calls_per_second
|
|
123
|
+
last_call = [0.0]
|
|
124
|
+
|
|
125
|
+
def decorator(func):
|
|
126
|
+
@wraps(func)
|
|
127
|
+
def wrapper(*args, **kwargs):
|
|
128
|
+
elapsed = time.time() - last_call[0]
|
|
129
|
+
if elapsed < min_interval:
|
|
130
|
+
time.sleep(min_interval - elapsed)
|
|
131
|
+
result = func(*args, **kwargs)
|
|
132
|
+
last_call[0] = time.time()
|
|
133
|
+
return result
|
|
134
|
+
return wrapper
|
|
135
|
+
return decorator
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Structured Output Patterns
|
|
139
|
+
|
|
140
|
+
### Prompt Template Structure
|
|
141
|
+
|
|
142
|
+
```markdown
|
|
143
|
+
[INSTRUCTION BLOCK]
|
|
144
|
+
Analyze the following content and provide your response in exactly this format.
|
|
145
|
+
|
|
146
|
+
[FORMAT SPECIFICATION]
|
|
147
|
+
## Section 1: Summary
|
|
148
|
+
[Your summary here - 2-3 sentences]
|
|
149
|
+
|
|
150
|
+
## Section 2: Analysis
|
|
151
|
+
- Point 1
|
|
152
|
+
- Point 2
|
|
153
|
+
- Point 3
|
|
154
|
+
|
|
155
|
+
## Section 3: Score
|
|
156
|
+
Rating: [1-10]
|
|
157
|
+
Confidence: [low/medium/high]
|
|
158
|
+
|
|
159
|
+
[FORMAT ENFORCEMENT]
|
|
160
|
+
Follow this format exactly because I will be parsing it programmatically.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
[CONTENT BLOCK]
|
|
165
|
+
# Title: {title}
|
|
166
|
+
|
|
167
|
+
## Content
|
|
168
|
+
{content}
|
|
169
|
+
|
|
170
|
+
## Additional Context
|
|
171
|
+
{context}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Parsing Patterns
|
|
175
|
+
|
|
176
|
+
**Section Extraction**
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
import re
|
|
180
|
+
|
|
181
|
+
def extract_section(text: str, section_name: str) -> str | None:
|
|
182
|
+
"""Extract content between section headers."""
|
|
183
|
+
# Match section header with optional markdown formatting
|
|
184
|
+
pattern = rf'(?:^|\n)(?:#+ *)?{re.escape(section_name)}[:\s]*\n(.*?)(?=\n(?:#+ |\Z))'
|
|
185
|
+
match = re.search(pattern, text, re.IGNORECASE | re.DOTALL)
|
|
186
|
+
return match.group(1).strip() if match else None
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Structured Field Extraction**
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
def extract_field(text: str, field_name: str) -> str | None:
|
|
193
|
+
"""Extract value after field label."""
|
|
194
|
+
# Handle: "Field: value" or "Field - value" or "**Field**: value"
|
|
195
|
+
pattern = rf'(?:\*\*)?{re.escape(field_name)}(?:\*\*)?[\s:\-]+([^\n]+)'
|
|
196
|
+
match = re.search(pattern, text, re.IGNORECASE)
|
|
197
|
+
return match.group(1).strip() if match else None
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**List Extraction**
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
def extract_list_items(text: str, section_name: str) -> list[str]:
|
|
204
|
+
"""Extract bullet points from a section."""
|
|
205
|
+
section = extract_section(text, section_name)
|
|
206
|
+
if not section:
|
|
207
|
+
return []
|
|
208
|
+
|
|
209
|
+
# Match lines starting with -, *, or numbered
|
|
210
|
+
items = re.findall(r'^[\-\*\d\.]+\s*(.+)$', section, re.MULTILINE)
|
|
211
|
+
return [item.strip() for item in items]
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Score Extraction with Validation**
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
def extract_score(text: str, field_name: str, min_val: int, max_val: int) -> int | None:
|
|
218
|
+
"""Extract and validate numeric score."""
|
|
219
|
+
raw = extract_field(text, field_name)
|
|
220
|
+
if not raw:
|
|
221
|
+
return None
|
|
222
|
+
|
|
223
|
+
# Extract first number from the value
|
|
224
|
+
match = re.search(r'\d+', raw)
|
|
225
|
+
if not match:
|
|
226
|
+
return None
|
|
227
|
+
|
|
228
|
+
score = int(match.group())
|
|
229
|
+
return max(min_val, min(max_val, score)) # Clamp to valid range
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Graceful Degradation
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
@dataclass
|
|
236
|
+
class ParseResult:
|
|
237
|
+
summary: str = ""
|
|
238
|
+
score: int | None = None
|
|
239
|
+
items: list[str] = field(default_factory=list)
|
|
240
|
+
parse_errors: list[str] = field(default_factory=list)
|
|
241
|
+
|
|
242
|
+
def parse_response(text: str) -> ParseResult:
|
|
243
|
+
"""Parse LLM response with graceful error handling."""
|
|
244
|
+
result = ParseResult()
|
|
245
|
+
|
|
246
|
+
# Try each field, log errors but continue
|
|
247
|
+
try:
|
|
248
|
+
result.summary = extract_section(text, "Summary") or ""
|
|
249
|
+
except Exception as e:
|
|
250
|
+
result.parse_errors.append(f"Summary extraction failed: {e}")
|
|
251
|
+
|
|
252
|
+
try:
|
|
253
|
+
result.score = extract_score(text, "Rating", 1, 10)
|
|
254
|
+
except Exception as e:
|
|
255
|
+
result.parse_errors.append(f"Score extraction failed: {e}")
|
|
256
|
+
|
|
257
|
+
try:
|
|
258
|
+
result.items = extract_list_items(text, "Analysis")
|
|
259
|
+
except Exception as e:
|
|
260
|
+
result.parse_errors.append(f"Items extraction failed: {e}")
|
|
261
|
+
|
|
262
|
+
return result
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Error Handling Patterns
|
|
266
|
+
|
|
267
|
+
### Retry with Exponential Backoff
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
import time
|
|
271
|
+
from functools import wraps
|
|
272
|
+
|
|
273
|
+
def retry_with_backoff(max_retries: int = 3, base_delay: float = 1.0):
|
|
274
|
+
"""Retry decorator with exponential backoff."""
|
|
275
|
+
def decorator(func):
|
|
276
|
+
@wraps(func)
|
|
277
|
+
def wrapper(*args, **kwargs):
|
|
278
|
+
last_exception = None
|
|
279
|
+
for attempt in range(max_retries):
|
|
280
|
+
try:
|
|
281
|
+
return func(*args, **kwargs)
|
|
282
|
+
except Exception as e:
|
|
283
|
+
last_exception = e
|
|
284
|
+
if attempt < max_retries - 1:
|
|
285
|
+
delay = base_delay * (2 ** attempt)
|
|
286
|
+
time.sleep(delay)
|
|
287
|
+
raise last_exception
|
|
288
|
+
return wrapper
|
|
289
|
+
return decorator
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Error Logging Pattern
|
|
293
|
+
|
|
294
|
+
```python
|
|
295
|
+
import json
|
|
296
|
+
from datetime import datetime
|
|
297
|
+
|
|
298
|
+
def log_error(item_dir: Path, stage: str, error: str, context: dict = None):
|
|
299
|
+
"""Log error to file for later analysis."""
|
|
300
|
+
error_file = item_dir / "errors.jsonl"
|
|
301
|
+
|
|
302
|
+
error_record = {
|
|
303
|
+
"timestamp": datetime.now().isoformat(),
|
|
304
|
+
"stage": stage,
|
|
305
|
+
"error": error,
|
|
306
|
+
"context": context or {},
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
with open(error_file, "a") as f:
|
|
310
|
+
f.write(json.dumps(error_record) + "\n")
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Partial Success Handling
|
|
314
|
+
|
|
315
|
+
```python
|
|
316
|
+
def process_batch_with_partial_success(items: list) -> tuple[list, list]:
|
|
317
|
+
"""Process batch, separating successes from failures."""
|
|
318
|
+
successes = []
|
|
319
|
+
failures = []
|
|
320
|
+
|
|
321
|
+
for item in items:
|
|
322
|
+
try:
|
|
323
|
+
result = process_item(item)
|
|
324
|
+
successes.append((item, result))
|
|
325
|
+
except Exception as e:
|
|
326
|
+
failures.append((item, str(e)))
|
|
327
|
+
log_error(item.directory, "process", str(e))
|
|
328
|
+
|
|
329
|
+
# Report summary
|
|
330
|
+
print(f"Processed {len(items)} items: {len(successes)} succeeded, {len(failures)} failed")
|
|
331
|
+
|
|
332
|
+
return successes, failures
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Cost Estimation Patterns
|
|
336
|
+
|
|
337
|
+
### Token Counting
|
|
338
|
+
|
|
339
|
+
```python
|
|
340
|
+
import tiktoken
|
|
341
|
+
|
|
342
|
+
def count_tokens(text: str, model: str = "gpt-4") -> int:
|
|
343
|
+
"""Count tokens for cost estimation."""
|
|
344
|
+
try:
|
|
345
|
+
encoding = tiktoken.encoding_for_model(model)
|
|
346
|
+
except KeyError:
|
|
347
|
+
encoding = tiktoken.get_encoding("cl100k_base")
|
|
348
|
+
|
|
349
|
+
return len(encoding.encode(text))
|
|
350
|
+
|
|
351
|
+
def estimate_cost(
|
|
352
|
+
input_tokens: int,
|
|
353
|
+
output_tokens: int,
|
|
354
|
+
input_price_per_mtok: float,
|
|
355
|
+
output_price_per_mtok: float,
|
|
356
|
+
) -> float:
|
|
357
|
+
"""Estimate cost in dollars."""
|
|
358
|
+
input_cost = (input_tokens / 1_000_000) * input_price_per_mtok
|
|
359
|
+
output_cost = (output_tokens / 1_000_000) * output_price_per_mtok
|
|
360
|
+
return input_cost + output_cost
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Batch Cost Estimation
|
|
364
|
+
|
|
365
|
+
```python
|
|
366
|
+
def estimate_batch_cost(
|
|
367
|
+
items: list,
|
|
368
|
+
prompt_template: str,
|
|
369
|
+
avg_output_tokens: int = 1000,
|
|
370
|
+
model_pricing: dict = None,
|
|
371
|
+
) -> dict:
|
|
372
|
+
"""Estimate total cost for a batch."""
|
|
373
|
+
model_pricing = model_pricing or {
|
|
374
|
+
"input_price_per_mtok": 3.00, # Example: GPT-4 Turbo input
|
|
375
|
+
"output_price_per_mtok": 15.00, # Example: GPT-4 Turbo output
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
total_input_tokens = 0
|
|
379
|
+
for item in items:
|
|
380
|
+
prompt = format_prompt(prompt_template, item)
|
|
381
|
+
total_input_tokens += count_tokens(prompt)
|
|
382
|
+
|
|
383
|
+
total_output_tokens = len(items) * avg_output_tokens
|
|
384
|
+
|
|
385
|
+
estimated_cost = estimate_cost(
|
|
386
|
+
total_input_tokens,
|
|
387
|
+
total_output_tokens,
|
|
388
|
+
**model_pricing,
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
return {
|
|
392
|
+
"item_count": len(items),
|
|
393
|
+
"total_input_tokens": total_input_tokens,
|
|
394
|
+
"total_output_tokens": total_output_tokens,
|
|
395
|
+
"estimated_cost_usd": estimated_cost,
|
|
396
|
+
"avg_input_tokens_per_item": total_input_tokens / len(items),
|
|
397
|
+
"cost_per_item_usd": estimated_cost / len(items),
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
## CLI Pattern
|
|
402
|
+
|
|
403
|
+
### Standard CLI Structure
|
|
404
|
+
|
|
405
|
+
```python
|
|
406
|
+
import argparse
|
|
407
|
+
from datetime import date
|
|
408
|
+
|
|
409
|
+
def main():
|
|
410
|
+
parser = argparse.ArgumentParser(description="LLM Processing Pipeline")
|
|
411
|
+
|
|
412
|
+
parser.add_argument(
|
|
413
|
+
"stage",
|
|
414
|
+
choices=["acquire", "prepare", "process", "parse", "render", "all", "clean"],
|
|
415
|
+
help="Pipeline stage to run",
|
|
416
|
+
)
|
|
417
|
+
parser.add_argument(
|
|
418
|
+
"--batch-id",
|
|
419
|
+
default=None,
|
|
420
|
+
help="Batch identifier (default: today's date)",
|
|
421
|
+
)
|
|
422
|
+
parser.add_argument(
|
|
423
|
+
"--limit",
|
|
424
|
+
type=int,
|
|
425
|
+
default=None,
|
|
426
|
+
help="Limit number of items (for testing)",
|
|
427
|
+
)
|
|
428
|
+
parser.add_argument(
|
|
429
|
+
"--workers",
|
|
430
|
+
type=int,
|
|
431
|
+
default=10,
|
|
432
|
+
help="Number of parallel workers for processing",
|
|
433
|
+
)
|
|
434
|
+
parser.add_argument(
|
|
435
|
+
"--model",
|
|
436
|
+
default="gpt-4-turbo",
|
|
437
|
+
help="Model to use for processing",
|
|
438
|
+
)
|
|
439
|
+
parser.add_argument(
|
|
440
|
+
"--dry-run",
|
|
441
|
+
action="store_true",
|
|
442
|
+
help="Estimate costs without processing",
|
|
443
|
+
)
|
|
444
|
+
parser.add_argument(
|
|
445
|
+
"--clean-stage",
|
|
446
|
+
choices=["acquire", "prepare", "process", "parse"],
|
|
447
|
+
help="For clean: only clean this stage and downstream",
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
args = parser.parse_args()
|
|
451
|
+
|
|
452
|
+
batch_id = args.batch_id or date.today().isoformat()
|
|
453
|
+
|
|
454
|
+
if args.stage == "clean":
|
|
455
|
+
stage_clean(batch_id, args.clean_stage)
|
|
456
|
+
elif args.dry_run:
|
|
457
|
+
estimate_costs(batch_id, args.limit)
|
|
458
|
+
else:
|
|
459
|
+
run_pipeline(batch_id, args.stage, args.limit, args.workers, args.model)
|
|
460
|
+
|
|
461
|
+
if __name__ == "__main__":
|
|
462
|
+
main()
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
## Rendering Patterns
|
|
466
|
+
|
|
467
|
+
### Static HTML Output
|
|
468
|
+
|
|
469
|
+
```python
|
|
470
|
+
import html
|
|
471
|
+
import json
|
|
472
|
+
|
|
473
|
+
def render_html(data: list[dict], output_path: Path, template: str):
|
|
474
|
+
"""Render data to static HTML file."""
|
|
475
|
+
# Escape data for JavaScript embedding
|
|
476
|
+
data_json = json.dumps([
|
|
477
|
+
{k: html.escape(str(v)) if isinstance(v, str) else v
|
|
478
|
+
for k, v in item.items()}
|
|
479
|
+
for item in data
|
|
480
|
+
])
|
|
481
|
+
|
|
482
|
+
html_content = template.replace("{{DATA_JSON}}", data_json)
|
|
483
|
+
|
|
484
|
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
485
|
+
with open(output_path, "w") as f:
|
|
486
|
+
f.write(html_content)
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### Incremental Output
|
|
490
|
+
|
|
491
|
+
```python
|
|
492
|
+
def render_incremental(items: list, output_dir: Path):
|
|
493
|
+
"""Render each item as it completes, plus index."""
|
|
494
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
495
|
+
|
|
496
|
+
# Render individual item pages
|
|
497
|
+
for item in items:
|
|
498
|
+
item_html = render_item(item)
|
|
499
|
+
item_path = output_dir / f"{item.id}.html"
|
|
500
|
+
with open(item_path, "w") as f:
|
|
501
|
+
f.write(item_html)
|
|
502
|
+
|
|
503
|
+
# Render index linking to all items
|
|
504
|
+
index_html = render_index(items)
|
|
505
|
+
with open(output_dir / "index.html", "w") as f:
|
|
506
|
+
f.write(index_html)
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
## Checkpoint and Resume Pattern
|
|
510
|
+
|
|
511
|
+
For long-running pipelines:
|
|
512
|
+
|
|
513
|
+
```python
|
|
514
|
+
import json
|
|
515
|
+
from pathlib import Path
|
|
516
|
+
|
|
517
|
+
class PipelineCheckpoint:
|
|
518
|
+
def __init__(self, checkpoint_file: Path):
|
|
519
|
+
self.checkpoint_file = checkpoint_file
|
|
520
|
+
self.state = self._load()
|
|
521
|
+
|
|
522
|
+
def _load(self) -> dict:
|
|
523
|
+
if self.checkpoint_file.exists():
|
|
524
|
+
with open(self.checkpoint_file) as f:
|
|
525
|
+
return json.load(f)
|
|
526
|
+
return {"completed": [], "failed": [], "last_item": None}
|
|
527
|
+
|
|
528
|
+
def save(self):
|
|
529
|
+
with open(self.checkpoint_file, "w") as f:
|
|
530
|
+
json.dump(self.state, f, indent=2)
|
|
531
|
+
|
|
532
|
+
def mark_complete(self, item_id: str):
|
|
533
|
+
self.state["completed"].append(item_id)
|
|
534
|
+
self.state["last_item"] = item_id
|
|
535
|
+
self.save()
|
|
536
|
+
|
|
537
|
+
def mark_failed(self, item_id: str, error: str):
|
|
538
|
+
self.state["failed"].append({"id": item_id, "error": error})
|
|
539
|
+
self.save()
|
|
540
|
+
|
|
541
|
+
def get_remaining(self, all_items: list[str]) -> list[str]:
|
|
542
|
+
completed = set(self.state["completed"])
|
|
543
|
+
return [item for item in all_items if item not in completed]
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
## Testing Patterns
|
|
547
|
+
|
|
548
|
+
### Stage Unit Tests
|
|
549
|
+
|
|
550
|
+
```python
|
|
551
|
+
def test_prepare_stage():
|
|
552
|
+
"""Test prompt generation independently."""
|
|
553
|
+
test_item = {"id": "test", "content": "Sample content"}
|
|
554
|
+
prompt = prepare_prompt(test_item)
|
|
555
|
+
|
|
556
|
+
assert "Sample content" in prompt
|
|
557
|
+
assert "## Section 1" in prompt # Format markers present
|
|
558
|
+
|
|
559
|
+
def test_parse_stage():
|
|
560
|
+
"""Test parsing with known good output."""
|
|
561
|
+
test_response = """
|
|
562
|
+
## Summary
|
|
563
|
+
This is a test summary.
|
|
564
|
+
|
|
565
|
+
## Score
|
|
566
|
+
Rating: 7
|
|
567
|
+
"""
|
|
568
|
+
|
|
569
|
+
result = parse_response(test_response)
|
|
570
|
+
assert result.summary == "This is a test summary."
|
|
571
|
+
assert result.score == 7
|
|
572
|
+
|
|
573
|
+
def test_parse_stage_malformed():
|
|
574
|
+
"""Test parsing handles malformed output."""
|
|
575
|
+
test_response = "Some random text without sections"
|
|
576
|
+
|
|
577
|
+
result = parse_response(test_response)
|
|
578
|
+
assert result.summary == ""
|
|
579
|
+
assert result.score is None
|
|
580
|
+
assert len(result.parse_errors) > 0
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
### Integration Test Pattern
|
|
584
|
+
|
|
585
|
+
```python
|
|
586
|
+
def test_pipeline_end_to_end():
|
|
587
|
+
"""Test full pipeline with single item."""
|
|
588
|
+
test_dir = Path("test_data")
|
|
589
|
+
test_item = create_test_item()
|
|
590
|
+
|
|
591
|
+
try:
|
|
592
|
+
# Run each stage
|
|
593
|
+
acquire_result = stage_acquire(test_dir, [test_item])
|
|
594
|
+
assert (test_dir / test_item.id / "raw.json").exists()
|
|
595
|
+
|
|
596
|
+
prepare_result = stage_prepare(test_dir)
|
|
597
|
+
assert (test_dir / test_item.id / "prompt.md").exists()
|
|
598
|
+
|
|
599
|
+
# Skip process stage in unit tests (costs money)
|
|
600
|
+
# Create mock response instead
|
|
601
|
+
mock_response(test_dir / test_item.id)
|
|
602
|
+
|
|
603
|
+
parse_result = stage_parse(test_dir)
|
|
604
|
+
assert (test_dir / test_item.id / "parsed.json").exists()
|
|
605
|
+
|
|
606
|
+
finally:
|
|
607
|
+
# Cleanup
|
|
608
|
+
shutil.rmtree(test_dir, ignore_errors=True)
|
|
609
|
+
```
|
|
610
|
+
|