octocode-cli 1.3.0 → 1.5.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 +129 -28
- package/out/chunks/chunk-7476PETK.js +309 -0
- package/out/chunks/chunk-CVNNNSMQ.js +26 -0
- package/out/chunks/chunk-OQBJTZWK.js +60 -0
- package/out/chunks/chunk-UCZCF3BQ.js +9 -0
- package/out/chunks/command-help-specs-JZXVSLZ5.js +8 -0
- package/out/chunks/commands-XBFPLHSQ.js +8 -0
- package/out/chunks/help-P7TCOYAJ.js +10 -0
- package/out/chunks/main-help-ULF5PAQY.js +10 -0
- package/out/chunks/prompts-5E6VKRX5.js +8 -0
- package/out/chunks/spinner-URV2OX6O.js +8 -0
- package/out/chunks/tool-command-M6VA7P2F.js +8 -0
- package/out/octocode-cli.js +1 -1
- package/package.json +5 -3
- package/skills/README.md +60 -58
- package/skills/agentic-flow-best-practices/SKILL.md +280 -0
- package/skills/agentic-flow-best-practices/references/agent-collaboration-patterns.md +75 -0
- package/skills/agentic-flow-best-practices/references/pr-review-agent-example.md +47 -0
- package/skills/agentic-flow-best-practices/references/resources.md +112 -0
- package/skills/octocode-brainstorming/.env.example +11 -0
- package/skills/octocode-brainstorming/SKILL.md +262 -0
- package/skills/octocode-brainstorming/scripts/tavily-search.mjs +138 -0
- package/skills/octocode-chrome-devtools/README.md +541 -0
- package/skills/octocode-chrome-devtools/SKILL.md +197 -0
- package/skills/octocode-chrome-devtools/agents/openai.yaml +7 -0
- package/skills/octocode-chrome-devtools/references/CDP_AGENT_REFERENCE.md +401 -0
- package/skills/octocode-chrome-devtools/references/CHROME_FLAGS.md +234 -0
- package/skills/octocode-chrome-devtools/references/INTENTS.md +108 -0
- package/skills/octocode-chrome-devtools/references/INTENTS_AUTH.md +179 -0
- package/skills/octocode-chrome-devtools/references/INTENTS_AUTOMATION.md +214 -0
- package/skills/octocode-chrome-devtools/references/INTENTS_DEBUG.md +329 -0
- package/skills/octocode-chrome-devtools/references/INTENTS_ENVIRONMENT.md +237 -0
- package/skills/octocode-chrome-devtools/references/INTENTS_INSPECT.md +263 -0
- package/skills/octocode-chrome-devtools/references/INTENTS_STORAGE_CONSENT.md +214 -0
- package/skills/octocode-chrome-devtools/references/RECOVERY.md +39 -0
- package/skills/octocode-chrome-devtools/references/SCRIPT_PATTERNS.md +43 -0
- package/skills/octocode-chrome-devtools/references/SCRIPT_PATTERNS_ASYNC_WORKERS.md +345 -0
- package/skills/octocode-chrome-devtools/references/SCRIPT_PATTERNS_BROWSER.md +403 -0
- package/skills/octocode-chrome-devtools/references/SCRIPT_PATTERNS_OBSERVE.md +275 -0
- package/skills/octocode-chrome-devtools/references/SCRIPT_PATTERNS_SPECIAL.md +18 -0
- package/skills/octocode-chrome-devtools/scripts/cdp-runner.mjs +503 -0
- package/skills/octocode-chrome-devtools/scripts/cdp-sandbox.mjs +123 -0
- package/skills/octocode-chrome-devtools/scripts/cdp-template.mjs +81 -0
- package/skills/octocode-chrome-devtools/scripts/octocode-chrome-devtools.vpn.example.json +8 -0
- package/skills/octocode-chrome-devtools/scripts/open-browser.mjs +362 -0
- package/skills/octocode-chrome-devtools/scripts/sourcemap-resolver.mjs +193 -0
- package/skills/octocode-chrome-devtools/scripts/undercover.mjs +226 -0
- package/skills/octocode-design/README.md +2 -2
- package/skills/octocode-documentation-writer/README.md +1 -1
- package/skills/octocode-engineer/README.md +1 -1
- package/skills/octocode-engineer/SKILL.md +137 -306
- package/skills/octocode-engineer/references/cli-reference.md +13 -0
- package/skills/octocode-engineer/references/output-files.md +3 -3
- package/skills/octocode-engineer/scripts/run.js +146 -146
- package/skills/octocode-engineer/src/pipeline/main.ts +1 -17
- package/skills/octocode-engineer/src/pipeline/progress.ts +4 -0
- package/skills/octocode-engineer/src/reporting/summary-md.test.ts +48 -0
- package/skills/octocode-engineer/src/reporting/summary-md.ts +43 -2
- package/skills/octocode-install/SKILL.md +1 -1
- package/skills/octocode-pull-request-reviewer/README.md +5 -5
- package/skills/octocode-pull-request-reviewer/SKILL.md +1 -1
- package/skills/octocode-research/AGENTS.md +1 -1
- package/skills/octocode-research/README.md +2 -2
- package/skills/octocode-research/docs/ARCHITECTURE.md +1 -1
- package/skills/octocode-research/scripts/server.js +184 -239
- package/skills/octocode-research/src/routes/github.ts +4 -21
- package/skills/octocode-research/src/routes/local.ts +4 -21
- package/skills/octocode-research/src/utils/fileContentTransform.ts +44 -0
- package/skills/octocode-search-skill/SKILL.md +337 -0
- package/skills/octocode-search-skill/references/agent-skills-guide.md +177 -0
- package/skills/octocode-search-skill/references/discovery-surfaces.md +162 -0
- package/skills/octocode-search-skill/references/fetch-and-create-locally.md +57 -0
- package/skills/octocode-search-skill/references/install-reference.md +130 -0
- package/skills/octocode-search-skill/references/references-template.md +27 -0
- package/skills/octocode-search-skill/references/references.md +62 -0
- package/skills/octocode-slides/README.md +307 -0
- package/skills/octocode-slides/SKILL.md +410 -0
- package/skills/octocode-slides/references/01-brief.md +156 -0
- package/skills/octocode-slides/references/02-research.md +149 -0
- package/skills/octocode-slides/references/03-outline.md +172 -0
- package/skills/octocode-slides/references/04-design.md +301 -0
- package/skills/octocode-slides/references/05-implementation.md +213 -0
- package/skills/octocode-slides/references/06-review.md +258 -0
- package/skills/octocode-slides/references/animation.md +281 -0
- package/skills/octocode-slides/references/design-system.md +316 -0
- package/skills/octocode-slides/references/html-templates.md +673 -0
- package/skills/octocode-slides/references/image-generation.md +448 -0
- package/skills/octocode-slides/references/resources.md +840 -0
- package/skills/octocode-slides/references/slide-rules.md +541 -0
- package/skills/octocode-slides/references/wireframes.md +727 -0
- package/skills/octocode-slides/scripts/animation.js +182 -0
- package/skills/octocode-slides/scripts/base.css +353 -0
- package/skills/octocode-slides/scripts/base.html +655 -0
- package/skills/octocode-slides/scripts/generate_image.py +221 -0
- package/skills/octocode-slides/scripts/navbridge.js +79 -0
- package/skills/octocode-slides/scripts/presenter.js +316 -0
- package/skills/octocode-slides/scripts/slide.html +248 -0
- package/skills/octocode-stats/SKILL.md +73 -0
- package/skills/octocode-stats/assets/template.html +1332 -0
- package/skills/octocode-stats/scripts/build_dashboard.mjs +407 -0
- package/out/chunks/chunk-LH4AZJPA.js +0 -389
- package/out/chunks/command-help-specs-CQ3RBLP6.js +0 -8
- package/out/chunks/commands-M3QTWKWE.js +0 -51
- package/out/chunks/help-XPXP46ZT.js +0 -10
- package/out/chunks/main-help-HXFAFHPG.js +0 -10
- package/out/chunks/tool-command-VHFLPIHY.js +0 -8
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Agent Collaboration Patterns
|
|
2
|
+
|
|
3
|
+
Use this to reason about flows between agents, roles, ownership, and communication. Supervisor is one option; choose the collaboration shape that fits the work.
|
|
4
|
+
|
|
5
|
+
## Technique Map
|
|
6
|
+
|
|
7
|
+
| Technique | Shape | Use When | Watch For |
|
|
8
|
+
|---|---|---|---|
|
|
9
|
+
| Prompt roles | One agent, named internal roles | Separation is conceptual only | Fake multi-agent complexity |
|
|
10
|
+
| Router | `classify -> specialist/path` | Known categories map to tools/prompts/models | Overrouting ambiguous work |
|
|
11
|
+
| Agents as tools | Manager calls specialist and keeps control | Specialist returns artifact/result | Specialist leaking conversation control |
|
|
12
|
+
| Handoff | Agent transfers user-facing turn | Specialist should own next interaction | Full-history transfer, unclear return |
|
|
13
|
+
| Orchestrator-workers | Planner creates dynamic subtasks | Work is discovered at runtime | Weak task packets, duplicate work |
|
|
14
|
+
| Parallel specialists | Same/different facets run concurrently | Latency, coverage, independent evidence | Merge conflicts, inconsistent criteria |
|
|
15
|
+
| Reviewer/evaluator | Separate judge checks output | Quality/safety needs independent review | Self-approval |
|
|
16
|
+
| Debate/red-team | Advocate + critic + judge | High-stakes tradeoff or risk analysis | Performative disagreement |
|
|
17
|
+
| Blackboard | Agents read/write shared workspace | Coordination through artifacts/state | Concurrent writes, stale facts |
|
|
18
|
+
| Hierarchical team | Leads coordinate subteams | Large domain with nested ownership | Bottlenecks, hidden state |
|
|
19
|
+
| Human-gated team | Agent proposes, human approves | Trust, policy, cost, destructive action | Vague approval prompt |
|
|
20
|
+
| Background worker | Async consolidation/evals/memory | Work can happen after response | Hidden side effects |
|
|
21
|
+
|
|
22
|
+
Choose **agents-as-tools** when the manager should keep control and specialists return artifacts. Choose **handoff** when a specialist should own the next user-facing turn. Choose **blackboard/shared workspace** when agents coordinate through artifacts instead of direct conversation.
|
|
23
|
+
|
|
24
|
+
## Role Design
|
|
25
|
+
|
|
26
|
+
Define roles by responsibility, not titles:
|
|
27
|
+
|
|
28
|
+
- `owner`: one agent/node owns each state field and artifact.
|
|
29
|
+
- `planner`: decomposes work and assigns packets.
|
|
30
|
+
- `specialist`: performs bounded work with scoped tools/context.
|
|
31
|
+
- `reviewer`: checks output, evidence, risk, and schema.
|
|
32
|
+
- `memoryWriter`: approves durable memory writes.
|
|
33
|
+
- `actor`: performs side effects after gates.
|
|
34
|
+
- `observer`: traces, metrics, evals, cache/memory decisions.
|
|
35
|
+
|
|
36
|
+
Avoid roles that differ only by wording. If two roles share tools, context, and output type, they may be one role with a clearer prompt.
|
|
37
|
+
|
|
38
|
+
## Communication Protocol
|
|
39
|
+
|
|
40
|
+
Each agent boundary should use Zod-backed packets:
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
AgentTask: goal, inputs, knownFacts, constraints, allowedTools,
|
|
44
|
+
expectedOutput, stopConditions
|
|
45
|
+
|
|
46
|
+
AgentResult: status, output, evidence, unknowns, actionNeeded,
|
|
47
|
+
memoryCandidates, traceId
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Pass artifact references over full history. Pass decisions separately from evidence. Let workers make local choices inside bounds; return to coordinator when scope, tool permission, confidence, or side effects exceed bounds.
|
|
51
|
+
|
|
52
|
+
## Common Failure Fixes
|
|
53
|
+
|
|
54
|
+
| Failure | Fix |
|
|
55
|
+
|---|---|
|
|
56
|
+
| duplicate work | disjoint ownership and task ids |
|
|
57
|
+
| context bloat | packet + artifact refs + input filters |
|
|
58
|
+
| tool bleed | per-agent allowlists |
|
|
59
|
+
| infinite delegation | max turns, budget, terminal states |
|
|
60
|
+
| prose result | Zod-valid `AgentResult` |
|
|
61
|
+
| weak merge | evidence ids and conflict surfacing |
|
|
62
|
+
| memory pollution | one approved memory writer |
|
|
63
|
+
| self-approval | reviewer, eval, or human gate |
|
|
64
|
+
|
|
65
|
+
## Output Mini-Scheme
|
|
66
|
+
|
|
67
|
+
```markdown
|
|
68
|
+
Roles: <role -> responsibility/tools/context>
|
|
69
|
+
Collaboration: <router | agents-as-tools | handoff | orchestrator-workers | blackboard | reviewer | hybrid>
|
|
70
|
+
Packets: <AgentTask/AgentResult/Zod schemas>
|
|
71
|
+
State: <owner per field/artifact>
|
|
72
|
+
Flow: <agent -> agent/tool/artifact>
|
|
73
|
+
Gates: <approval/memory/side-effect stops>
|
|
74
|
+
Failure controls: <loop limits, conflict policy, retries>
|
|
75
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Worked Example: PR Review Agent
|
|
2
|
+
|
|
3
|
+
Compact build-ready example.
|
|
4
|
+
|
|
5
|
+
```markdown
|
|
6
|
+
## Flow: PR Review Agent
|
|
7
|
+
|
|
8
|
+
Goal: Fetch a GitHub PR diff/context, produce schema-valid findings, and post only after approval.
|
|
9
|
+
Architecture: Checkpointed workflow/LangGraph. Route is known; durable state and gates matter. Avoid multi-agent until review core works.
|
|
10
|
+
|
|
11
|
+
State:
|
|
12
|
+
- `prRef`: input, owner/repo/number/headSha
|
|
13
|
+
- `diff`, `contextChunks`, `risk`: working state
|
|
14
|
+
- `findings`: artifact, Zod-valid review output
|
|
15
|
+
- `repoFacts`: memory candidates after approval
|
|
16
|
+
|
|
17
|
+
Protocols (Zod):
|
|
18
|
+
- `FlowInput`, `DiffPayload`, `ReviewFinding`, `ReviewOutput`
|
|
19
|
+
- `CacheEntry`, `MemoryCandidate`, `HumanGate`, `TraceEvent`, `ErrorEnvelope`
|
|
20
|
+
|
|
21
|
+
Context packet:
|
|
22
|
+
- goal, summarized diff when large, top relevant chunks, risk, repo instructions
|
|
23
|
+
- constraints: changed lines plus nearby context; no approve/merge/close/post
|
|
24
|
+
- expected output: `ReviewOutput`
|
|
25
|
+
- unknowns: missing files/symbols
|
|
26
|
+
|
|
27
|
+
Cache/memory:
|
|
28
|
+
- cache by `pr:{owner}/{repo}/{number}:{headSha}`, scope repo/workspace
|
|
29
|
+
- invalidate on new push or changed base
|
|
30
|
+
- never store raw private diffs as memory
|
|
31
|
+
- write approved conventions/facts only, with source and retention
|
|
32
|
+
|
|
33
|
+
Flow:
|
|
34
|
+
1. `classify`: PR ref -> task/risk; stop if invalid
|
|
35
|
+
2. `retrieve`: diff/context; cache by headSha; retry transient fetch
|
|
36
|
+
3. `reason`: context packet -> `ReviewOutput`; retry once on schema failure
|
|
37
|
+
4. `review`: preview findings; gate post/memory
|
|
38
|
+
5. `act`: post approved comment with idempotency key
|
|
39
|
+
6. `observe`: trace route, tools, cache, errors, memory candidates
|
|
40
|
+
|
|
41
|
+
Verify:
|
|
42
|
+
- Zod tests for protocols
|
|
43
|
+
- cache hit/miss/stale tests
|
|
44
|
+
- golden SQL injection PR -> high/block finding
|
|
45
|
+
- should-not-remember rejects raw diff/unapproved facts
|
|
46
|
+
- tool failure leaves no partial public comment
|
|
47
|
+
```
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Agentic Flow Research Launchpad
|
|
2
|
+
|
|
3
|
+
Use this as seed material, not a fixed stack. Project-local conventions win. Start with official docs, then inspect GitHub/source when behavior affects design.
|
|
4
|
+
|
|
5
|
+
Use available source-search tooling first, such as Octocode local/GitHub search. If shell search is appropriate, a useful local query is:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
rg -n "MCP|OpenAI|ADK|LangGraph|context|memory|cache|handoff|eval|attention|schema|hooks|github" references/resources.md
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Research loop:
|
|
12
|
+
|
|
13
|
+
1. Open the relevant docs URL for concepts and terminology when external docs are allowed.
|
|
14
|
+
2. Search the GitHub/source repo for implementation details, examples, tests, and issues using Octocode or the available source-search tool.
|
|
15
|
+
3. Search within source for `tool`, `handoff`, `memory`, `session`, `callback`, `hook`, `trace`, `schema`, `eval`, `checkpoint`, `middleware`.
|
|
16
|
+
4. Carry forward findings that affect architecture, protocol, context, safety, or verification.
|
|
17
|
+
5. If the project uses another framework, search its official docs and GitHub source the same way.
|
|
18
|
+
|
|
19
|
+
## Core Patterns
|
|
20
|
+
|
|
21
|
+
- **Anthropic - Building Effective Agents**: https://www.anthropic.com/engineering/building-effective-agents
|
|
22
|
+
Patterns: augmented LLM, chains, routing, parallelization, orchestrator-workers, evaluator-optimizer, agents, tool design.
|
|
23
|
+
|
|
24
|
+
## Protocols And MCP
|
|
25
|
+
|
|
26
|
+
- **MCP Architecture**: https://modelcontextprotocol.io/docs/learn/architecture
|
|
27
|
+
Scope, participants, layers, primitives; MCP is context/tool protocol, not orchestration.
|
|
28
|
+
- **MCP Server Concepts**: https://modelcontextprotocol.io/docs/learn/server-concepts
|
|
29
|
+
Tools, resources, prompts, discovery.
|
|
30
|
+
- **MCP Prompts**: https://modelcontextprotocol.io/docs/concepts/prompts
|
|
31
|
+
Reusable prompt templates.
|
|
32
|
+
- **MCP GitHub**: https://github.com/modelcontextprotocol/modelcontextprotocol
|
|
33
|
+
Search source/spec for protocol behavior and examples.
|
|
34
|
+
|
|
35
|
+
## Agent SDKs And Runtimes
|
|
36
|
+
|
|
37
|
+
- **OpenAI Agents docs**: https://openai.github.io/openai-agents-python/agents/
|
|
38
|
+
Agents, tools, handoffs, guardrails, sessions, structured outputs.
|
|
39
|
+
- **OpenAI orchestration**: https://openai.github.io/openai-agents-python/multi_agent/
|
|
40
|
+
LLM-led vs code-led, agents-as-tools, handoffs, hybrids.
|
|
41
|
+
- **OpenAI lifecycle**: https://openai.github.io/openai-agents-python/ref/lifecycle/
|
|
42
|
+
RunHooks and AgentHooks around models, tools, agents, handoffs.
|
|
43
|
+
- **OpenAI Agents GitHub**: https://github.com/openai/openai-agents-python
|
|
44
|
+
Search examples/tests/source for handoff, lifecycle, tracing, tool behavior.
|
|
45
|
+
|
|
46
|
+
- **Google ADK sessions/state/memory**: https://adk.dev/sessions/
|
|
47
|
+
Session, state, searchable memory.
|
|
48
|
+
- **Google ADK callbacks**: https://google.github.io/adk-docs/callbacks/
|
|
49
|
+
Agent/model/tool lifecycle callbacks.
|
|
50
|
+
- **Google ADK GitHub**: https://github.com/google/adk-python
|
|
51
|
+
Search source/examples for runners, tools, callbacks, memory services.
|
|
52
|
+
|
|
53
|
+
- **LangGraph overview**: https://docs.langchain.com/oss/python/langgraph
|
|
54
|
+
Durable stateful agents, persistence, streaming, human-in-loop, memory, tracing.
|
|
55
|
+
- **LangGraph persistence**: https://docs.langchain.com/oss/python/langgraph/persistence
|
|
56
|
+
Threads, checkpoints, snapshots, cross-thread memory.
|
|
57
|
+
- **LangGraph GitHub**: https://github.com/langchain-ai/langgraph
|
|
58
|
+
Search source/examples for checkpoints, interrupts, commands, stores, middleware.
|
|
59
|
+
|
|
60
|
+
- **LangChain docs**: https://docs.langchain.com/
|
|
61
|
+
Model/tool abstractions, middleware, agents, retrieval, eval-related guides.
|
|
62
|
+
- **LangChain GitHub**: https://github.com/langchain-ai/langchain
|
|
63
|
+
Search source/examples for tools, structured output, middleware, retrievers.
|
|
64
|
+
|
|
65
|
+
## Schemas And Structured Output
|
|
66
|
+
|
|
67
|
+
- **Zod JSON Schema**: https://zod.dev/json-schema
|
|
68
|
+
Convert Zod to JSON Schema for model/tool/MCP structured-output APIs.
|
|
69
|
+
- **Zod GitHub**: https://github.com/colinhacks/zod
|
|
70
|
+
Search issues/source for JSON Schema, strict objects, discriminated unions.
|
|
71
|
+
- **JSON Schema**: https://json-schema.org/
|
|
72
|
+
Cross-language schema interoperability.
|
|
73
|
+
|
|
74
|
+
## Models, Prompts, Cache
|
|
75
|
+
|
|
76
|
+
- **OpenAI prompt caching**: https://platform.openai.com/docs/guides/prompt-caching
|
|
77
|
+
Static-before-dynamic prompts, cached tokens.
|
|
78
|
+
- **OpenAI prompting**: https://platform.openai.com/docs/guides/prompting
|
|
79
|
+
Prompt versions, variables, eval-linked iteration.
|
|
80
|
+
- **OpenAI reasoning models**: https://platform.openai.com/docs/guides/reasoning
|
|
81
|
+
Reasoning tokens, effort, output budget, incomplete responses.
|
|
82
|
+
- **OpenAI model comparison**: https://platform.openai.com/docs/models/compare
|
|
83
|
+
Current context windows, output limits, feature fit.
|
|
84
|
+
|
|
85
|
+
## Context Attention
|
|
86
|
+
|
|
87
|
+
- **Deep Agents context engineering**: https://docs.langchain.com/oss/javascript/deepagents/context-engineering
|
|
88
|
+
Input/runtime context, compression, offloading, summarization, context isolation, skills.
|
|
89
|
+
- **Lost in the Middle**: https://arxiv.org/abs/2307.03172
|
|
90
|
+
Long-context models can miss middle-position information.
|
|
91
|
+
- **Chroma Context Rot**: https://www.trychroma.com/research/context-rot
|
|
92
|
+
Adding tokens can degrade usefulness.
|
|
93
|
+
|
|
94
|
+
## Memory And RAG Baselines
|
|
95
|
+
|
|
96
|
+
- **LangGraph memory**: https://docs.langchain.com/oss/python/concepts/memory
|
|
97
|
+
Short-term/thread and long-term memory.
|
|
98
|
+
- **Deep Agents memory**: https://docs.langchain.com/oss/python/deepagents/long-term-memory
|
|
99
|
+
Agent/user/org memory, read-only vs writable, background consolidation.
|
|
100
|
+
- **mem0 GitHub**: https://github.com/mem0ai/mem0
|
|
101
|
+
Cross-session memory patterns.
|
|
102
|
+
- **RAG techniques GitHub**: https://github.com/NirDiamant/RAG_Techniques
|
|
103
|
+
Retrieval pattern examples and eval baselines.
|
|
104
|
+
|
|
105
|
+
## Collaboration And Interop
|
|
106
|
+
|
|
107
|
+
- **AutoGen GitHub**: https://github.com/microsoft/autogen
|
|
108
|
+
Multi-agent conversation and human-in-loop examples.
|
|
109
|
+
- **A2A GitHub**: https://github.com/a2aproject/A2A
|
|
110
|
+
Agent-to-agent interop protocol ideas.
|
|
111
|
+
- **OpenAI Cookbook GitHub**: https://github.com/openai/openai-cookbook
|
|
112
|
+
Practical examples for tools, structured outputs, retrieval, agents.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Environment variables for octocode-brainstorming
|
|
2
|
+
#
|
|
3
|
+
# Copy this file to .env in the same directory and fill in real values:
|
|
4
|
+
# cp .env.example .env
|
|
5
|
+
#
|
|
6
|
+
# Do NOT commit .env — it is gitignored.
|
|
7
|
+
# The skill detects Tavily availability by running: node scripts/tavily-search.mjs --check
|
|
8
|
+
|
|
9
|
+
# Tavily API key — enables AI-powered web research.
|
|
10
|
+
# Get a key at https://app.tavily.com/
|
|
11
|
+
TAVILY_API_KEY=tvly-REPLACE_ME
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: octocode-brainstorming
|
|
3
|
+
description: Idea brainstorming and validation grounded in evidence. Triggers on "brainstorm", "is this worth building", "has anyone built X", "validate my idea", "check if X exists", "research this idea", "what are the prior-art options for Y". Researches GitHub, npm/PyPI, and the web in parallel, then synthesizes a decision-ready brief — not code or designs.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Octocode Brainstorming — Idea Discovery & Validation
|
|
7
|
+
|
|
8
|
+
Research-first skill that turns a raw idea into a grounded brief by hitting **every available surface in parallel** — then synthesizes what exists, what's missing, and what's next. No designs, specs, or code.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Researcher Mindset
|
|
14
|
+
|
|
15
|
+
You are a **technical researcher**, not a search-engine wrapper.
|
|
16
|
+
|
|
17
|
+
- **Assume nothing is novel.** Find who tried it, where they stopped, and why.
|
|
18
|
+
- **Follow the trail.** README → blog → competitor → issues page → hard unsolved problem. Keep pulling threads.
|
|
19
|
+
- **Web ↔ Code cross-pollination.** Web and GitHub are not separate tracks — they feed each other. A blog post names a tool → search its repo on GitHub. A GitHub repo README links to docs → `WebFetch` those docs. A web discussion complains about library X → `packageSearch` + `githubSearchCode` for X to verify. Always use findings from one surface to refine queries on the other.
|
|
20
|
+
- **Go deep when results are thin.** Read code, check issue trackers, inspect PRs, check download trends. Shallow matches are starting points.
|
|
21
|
+
- **Use parallel agents aggressively.** Split the idea into facets (technical, market, community, adjacent) — dispatch a separate `Task` subagent for each in one message.
|
|
22
|
+
- **Force disagreement.** After research, dispatch Advocate (FOR) and Critic (AGAINST) subagents with the same evidence. Agreement = high confidence; disagreement = the real decision.
|
|
23
|
+
- **Synthesize, don't summarize.** Original analysis of what the landscape means, not just a link list.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Hard Gates
|
|
28
|
+
|
|
29
|
+
Stop and ask the user before proceeding past any of these. State the situation in 1–2 lines, name the options, and recommend one.
|
|
30
|
+
|
|
31
|
+
1. **Idea too broad** — the idea maps to 3+ unrelated problem spaces and cannot be meaningfully researched in one pass. Stop after the clarify step, before dispatching any subagents. Ask the user to pick one facet or confirm they want a shallow sweep.
|
|
32
|
+
2. **Zero results across surfaces** — after the parallel research phase, all three surfaces (GitHub, packages, web) returned <2 meaningful results each even after synonym expansion. Do not proceed to Advocate vs Critic. Present what you found, flag the gap, and ask: narrow the idea, broaden keywords further, or accept thin evidence?
|
|
33
|
+
3. **Contradictory evidence** — GitHub/packages show a crowded space but web sources say the problem is unsolved (or vice versa). Do not bury the contradiction in the brief. Stop, surface both sides with citations, and ask the user which signal to weight before synthesizing.
|
|
34
|
+
4. **Subagent ceiling reached** — maximum **5 `Task` subagents** per brainstorm session (web slices + Advocate + Critic combined). If more seem needed, synthesize what you have first and ask whether the user wants a second research pass.
|
|
35
|
+
|
|
36
|
+
Do not silently continue past a hard gate. Do not ask outside of gates — gates exist to reduce bad briefs, not to offload decisions.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Tools
|
|
41
|
+
|
|
42
|
+
### GitHub & packages — Octocode MCP
|
|
43
|
+
|
|
44
|
+
| Tool | Use for |
|
|
45
|
+
|------|---------|
|
|
46
|
+
| `packageSearch` | npm/PyPI libraries |
|
|
47
|
+
| `githubSearchRepositories` | Repos by topic, language, stars |
|
|
48
|
+
| `githubViewRepoStructure` | How a similar project is organized |
|
|
49
|
+
| `githubSearchCode` | Confirm a concept is actually implemented |
|
|
50
|
+
| `githubGetFileContent` | Read key files for specific answers |
|
|
51
|
+
| `githubSearchPullRequests` | How similar features were shipped (deep mode) |
|
|
52
|
+
|
|
53
|
+
**Smart querying:**
|
|
54
|
+
- **Semantic expansion** — don't search only the user's exact words. Generate 2–3 synonym/related queries (e.g. "code review" → also "pull request analysis", "diff feedback", "static analysis AI"). Run them in parallel.
|
|
55
|
+
- **Recency first** — sort by recently updated/pushed. Ignore repos inactive >2 years unless the user asks for historical context. Stale repos are prior art, not competition.
|
|
56
|
+
- **Quality filter** — skip forks, skeleton/tutorial repos, and <10-star repos unless they're the only match. Prefer repos with recent commits, open issues with engagement, and multiple contributors.
|
|
57
|
+
|
|
58
|
+
### Web — search scripts + WebFetch
|
|
59
|
+
|
|
60
|
+
Two layers: **search** (find URLs via Tavily) → **read** (`WebFetch` full content) → **follow** (chase leads). Use all three every time.
|
|
61
|
+
|
|
62
|
+
**Search script** in `scripts/`:
|
|
63
|
+
|
|
64
|
+
| Script | Key needed | Best for |
|
|
65
|
+
|--------|------------|----------|
|
|
66
|
+
| `tavily-search.mjs` | `TAVILY_API_KEY` | AI-curated, deep research mode |
|
|
67
|
+
|
|
68
|
+
**Startup — check Tavily:**
|
|
69
|
+
1. Run `node <skill_dir>/scripts/tavily-search.mjs --check`
|
|
70
|
+
2. Exit 0 → ready. Exit 1 → tell user once:
|
|
71
|
+
> Tavily not configured. Add your key to `<absolute_path_to_skill_dir>/.env`: `TAVILY_API_KEY=tvly-YOUR_KEY_HERE` (get one at https://app.tavily.com/)
|
|
72
|
+
|
|
73
|
+
**Run searches:**
|
|
74
|
+
```bash
|
|
75
|
+
node <skill_dir>/scripts/tavily-search.mjs --query "<query>" --depth advanced --max-results 8 --time-range year
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Tavily: `--depth basic|advanced`, `--topic general|news`, `--time-range day|week|month|year`, `--help`.
|
|
79
|
+
|
|
80
|
+
**Smart querying:**
|
|
81
|
+
- **Semantic expansion** — generate 2–3 synonym/reframed queries per search pass (e.g. "AI code review" → also "LLM pull request feedback", "automated diff analysis"). Run them in parallel.
|
|
82
|
+
- **Recency first** — default to `--time-range year`. Only widen to all-time if the user asks or the year window returns <3 results.
|
|
83
|
+
- **Quality filter** — prioritize: official docs > technical blog posts > HN/Reddit discussions > general articles. Skip SEO spam, listicles, and paywalled pages. When `WebFetch`-ing, verify the page has substantive content before citing it.
|
|
84
|
+
|
|
85
|
+
**Research loop:** run Tavily → `WebFetch` best URLs (quality over quantity) → follow leads in fetched pages → repeat until bedrock.
|
|
86
|
+
|
|
87
|
+
**Subagents:** spawn `Task` (subagent_type `generalPurpose`) for independent web slices. Each runs Tavily + `WebFetch`. Dispatch multiple in one message.
|
|
88
|
+
|
|
89
|
+
**Subagent template:**
|
|
90
|
+
> Research <slice> for "<idea>".
|
|
91
|
+
> 1. Run `node <skill_dir>/scripts/tavily-search.mjs --query "<q>" --depth advanced --max-results 8`
|
|
92
|
+
> 2. `WebFetch` best URLs.
|
|
93
|
+
> 3. Report: who's doing this, what they got right/wrong, gaps, best URLs with notes. Cite all sources.
|
|
94
|
+
|
|
95
|
+
### Tavily key setup
|
|
96
|
+
|
|
97
|
+
Script auto-loads `<skill_dir>/.env`. Set up: `cp <skill_dir>/.env.example <skill_dir>/.env` and fill in the key. Env vars override `.env`.
|
|
98
|
+
|
|
99
|
+
**Safety:** Never print/log/commit `TAVILY_API_KEY`. The `.env` is gitignored.
|
|
100
|
+
|
|
101
|
+
### Tavily-down fallback (web research without Tavily)
|
|
102
|
+
|
|
103
|
+
When Tavily is unavailable (missing key, 401/403, 429/5xx), do not abandon web research. Use this fallback chain:
|
|
104
|
+
|
|
105
|
+
1. **Seed URLs from GitHub** — GitHub repo READMEs, `awesome-*` lists, and package pages link to docs, blogs, and competitor products. `WebFetch` those URLs. This is your primary URL source when Tavily is down.
|
|
106
|
+
2. **`WebFetch` well-known aggregators** — try `WebFetch` on curated sources relevant to the idea:
|
|
107
|
+
|
|
108
|
+
Examples:
|
|
109
|
+
- `https://news.ycombinator.com/` + search path for the topic
|
|
110
|
+
- `https://www.producthunt.com/` for product-level prior art
|
|
111
|
+
- `https://alternativeto.net/` for competitive landscape
|
|
112
|
+
- `https://dev.to/search?q=<topic>` for community discussion
|
|
113
|
+
3. **Follow leads** — every `WebFetch`-ed page may contain links to deeper sources. Follow them the same way Tavily results are followed.
|
|
114
|
+
|
|
115
|
+
Fallback produces fewer results than Tavily. Flag in the TL;DR: "Web research limited — Tavily unavailable, results seeded from GitHub links and known aggregators."
|
|
116
|
+
|
|
117
|
+
**Error reporting:**
|
|
118
|
+
- Tavily 401/403 → key invalid. Tell user: update `<absolute_path>/.env`. Switch to fallback chain.
|
|
119
|
+
- Tavily 429/5xx → switch to fallback chain. Continue.
|
|
120
|
+
- Always print **absolute path** to `.env`. Never block on search failures.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Workflow
|
|
125
|
+
|
|
126
|
+
Clarify → Parallel research → Advocate vs Critic → Synthesize → Present.
|
|
127
|
+
|
|
128
|
+
### 1. Clarify
|
|
129
|
+
|
|
130
|
+
If ambiguous, ask one focused question. If clear enough to search, skip.
|
|
131
|
+
|
|
132
|
+
### 2. Parallel Research
|
|
133
|
+
|
|
134
|
+
**Every brainstorm must hit all three surfaces.** Main agent handles GitHub + packages via Octocode MCP; subagents handle web slices using Tavily + `WebFetch`.
|
|
135
|
+
|
|
136
|
+
| Track | Runner | Tools |
|
|
137
|
+
|-------|--------|-------|
|
|
138
|
+
| GitHub prior-art | Main agent | `githubSearchRepositories` → `githubViewRepoStructure` → `githubSearchCode` |
|
|
139
|
+
| Package landscape | Main agent | `packageSearch` |
|
|
140
|
+
| Web — products | Subagent | Tavily → `WebFetch` |
|
|
141
|
+
| Web — community | Subagent | Tavily → `WebFetch` |
|
|
142
|
+
| Web — adjacent angles | Subagent | Tavily → `WebFetch` |
|
|
143
|
+
|
|
144
|
+
**Cross-pollination pass:** after the initial parallel sweep, use each surface's findings to sharpen the other:
|
|
145
|
+
- Web mentions a tool/library name → `githubSearchRepositories` + `packageSearch` for it
|
|
146
|
+
- GitHub repo links to docs/blog/product page → `WebFetch` it
|
|
147
|
+
- Package README references competitors → search those on both web and GitHub
|
|
148
|
+
- Web discussion names an unsolved problem → `githubSearchCode` to see if anyone solved it in code
|
|
149
|
+
|
|
150
|
+
**CHECKPOINT — do not proceed to Advocate vs Critic until:**
|
|
151
|
+
1. At least **one cross-pollination query** has been dispatched per surface (web finding → GitHub search, GitHub finding → `WebFetch`, package finding → web or GitHub search).
|
|
152
|
+
2. Results from cross-pollination have been received and incorporated.
|
|
153
|
+
3. If a surface returned zero useful results, at least one synonym-expanded retry was attempted before marking it failed.
|
|
154
|
+
|
|
155
|
+
Skip cross-pollination only if the **Subagent ceiling** gate fires first — in that case, note "cross-pollination skipped (budget)" in the brief.
|
|
156
|
+
|
|
157
|
+
**Go deeper** if results are sparse: read code, check issues, inspect PRs, run synonym searches, check funding/traction. Spawn additional subagents (within the 5-subagent ceiling) rather than sequential follow-ups.
|
|
158
|
+
|
|
159
|
+
**Minimum bar:** findings from all three surfaces (GitHub, packages, web) with at least one cross-pollination pass. Flag explicitly if a track failed.
|
|
160
|
+
|
|
161
|
+
### 2b. Advocate vs Critic
|
|
162
|
+
|
|
163
|
+
After research, dispatch **two competing subagents** in one message with the same findings:
|
|
164
|
+
|
|
165
|
+
**Advocate:**
|
|
166
|
+
> You are the ADVOCATE for "<idea>". Build the strongest case FOR. Cite repos, packages, web sources. Bull case only — not balanced.
|
|
167
|
+
> Research findings: <paste>
|
|
168
|
+
|
|
169
|
+
**Critic:**
|
|
170
|
+
> You are the CRITIC of "<idea>". Build the strongest case AGAINST. Cite crowded competitors, abandoned repos, complaints, unsolved problems. Bear case only — not encouraging.
|
|
171
|
+
> Research findings: <paste>
|
|
172
|
+
|
|
173
|
+
### 3. Synthesize
|
|
174
|
+
|
|
175
|
+
Merge all tracks + Advocate vs Critic. Analyze, don't list.
|
|
176
|
+
|
|
177
|
+
- Both **agree** → high-confidence signal, lead with these
|
|
178
|
+
- They **disagree** → real decision points, present both sides with evidence
|
|
179
|
+
- Uncountered risk → flag as blocker. Unchallenged strength → flag as best direction.
|
|
180
|
+
|
|
181
|
+
Every claim needs a source (repo URL, npm page, web URL). Surface contradictions. Look for: prior art, gaps, risks, angles, traction signals.
|
|
182
|
+
|
|
183
|
+
### 4. Present
|
|
184
|
+
|
|
185
|
+
```markdown
|
|
186
|
+
# Idea: <one-line restatement>
|
|
187
|
+
|
|
188
|
+
## TL;DR
|
|
189
|
+
<Crowded, underserved, or contested? 2–3 sentences. Note any research limitations (e.g. Tavily unavailable, cross-pollination skipped).>
|
|
190
|
+
|
|
191
|
+
## Prior Art (GitHub)
|
|
192
|
+
- **<repo>** — <what, stars, activity>. `<confidence>` <URL>
|
|
193
|
+
|
|
194
|
+
## Prior Art (Packages)
|
|
195
|
+
- **<package>** — <what, downloads, maintenance>. `<confidence>` <URL>
|
|
196
|
+
|
|
197
|
+
## Prior Art (Web / Products)
|
|
198
|
+
- **<product>** — <positioning, pricing>. `<confidence>` <URL>
|
|
199
|
+
|
|
200
|
+
## Bull Case (Advocate)
|
|
201
|
+
<Strongest FOR arguments with evidence.>
|
|
202
|
+
|
|
203
|
+
## Bear Case (Critic)
|
|
204
|
+
<Strongest AGAINST arguments with evidence.>
|
|
205
|
+
|
|
206
|
+
## Verdict
|
|
207
|
+
<Agreement, disagreement, key unknowns.>
|
|
208
|
+
|
|
209
|
+
## Gaps & Opportunities
|
|
210
|
+
- <gap — with source>
|
|
211
|
+
|
|
212
|
+
## Risks / Known Hard Problems
|
|
213
|
+
- <risk — with source>
|
|
214
|
+
|
|
215
|
+
## Angles To Pursue
|
|
216
|
+
1. **<angle>** — <why>. Closest prior art: <repo/product/package>.
|
|
217
|
+
|
|
218
|
+
## Recommended Next Step
|
|
219
|
+
<e.g. "Prototype the hardest unknown first", "Too broad — narrow down", "Ready to build — start with X">
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Confidence markers** — every prior-art entry MUST carry one:
|
|
223
|
+
|
|
224
|
+
| Marker | Meaning | Criteria |
|
|
225
|
+
|--------|---------|----------|
|
|
226
|
+
| `strong` | Active, validated, high-signal | Stars >500 OR downloads >10k/week OR multiple independent sources confirm |
|
|
227
|
+
| `moderate` | Exists and relevant, but incomplete signal | Stars 50–500 OR downloads 1k–10k/week OR single credible source |
|
|
228
|
+
| `weak` | Thin evidence, stale, or tangential | Stars <50 OR inactive >1 year OR only marketing copy, no independent validation |
|
|
229
|
+
|
|
230
|
+
Do not omit the marker. If you cannot assess confidence, mark `weak` and note why.
|
|
231
|
+
|
|
232
|
+
Scale sections to real content — don't pad.
|
|
233
|
+
|
|
234
|
+
**Present in chat first.** Then ask:
|
|
235
|
+
> Want me to save this brief? I'll write it to `.octocode/brainstorming/<YYYY-MM-DD>-<topic-slug>.md`
|
|
236
|
+
|
|
237
|
+
Only write if confirmed.
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Evidence Rules
|
|
243
|
+
|
|
244
|
+
- GitHub → repo URL + file:line for code + confidence marker. Web → URL + date + confidence marker.
|
|
245
|
+
- Every prior-art claim carries `strong`, `moderate`, or `weak` (see Confidence markers table above).
|
|
246
|
+
- Contradictions → surface both sides, pick on recency/authority. If contradiction triggers the **Contradictory evidence** gate, stop and ask.
|
|
247
|
+
- Marketing copy ≠ validation — mark it `weak` regardless of source authority.
|
|
248
|
+
- Zero prior art is usually a red flag, not a moat. If zero across all surfaces, the **Zero results** gate fires.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Error Recovery
|
|
253
|
+
|
|
254
|
+
| Situation | Action |
|
|
255
|
+
|-----------|--------|
|
|
256
|
+
| Octocode MCP not installed | Tell user how to install; continue web-only |
|
|
257
|
+
| GitHub rate-limited | Reduce concurrency; continue |
|
|
258
|
+
| Tavily key missing/invalid | Switch to **Tavily-down fallback** chain; tell user absolute path to `.env` |
|
|
259
|
+
| All web tools down | GitHub-only; flag in TL;DR |
|
|
260
|
+
| Idea too broad | **Hard gate 1** fires — ask user to narrow before dispatching subagents |
|
|
261
|
+
| Zero prior art | Synonym-expand and retry once. If still zero, **Hard gate 2** fires — ask user before proceeding |
|
|
262
|
+
| Contradictory evidence across surfaces | **Hard gate 3** fires — surface both sides and ask user which signal to weight |
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Tavily web search for octocode-brainstorming.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* node tavily-search.mjs --query "prior art for X" [--depth basic|advanced] [--max-results 8] [--topic general|news] [--time-range month|year]
|
|
7
|
+
* node tavily-search.mjs --check # exits 0 if key is set, 1 otherwise
|
|
8
|
+
*
|
|
9
|
+
* Requires TAVILY_API_KEY in env or in <skill_dir>/.env
|
|
10
|
+
* Outputs JSON to stdout; progress/errors to stderr. Never prints the key.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { readFileSync } from 'node:fs';
|
|
14
|
+
import { resolve, dirname } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const SKILL_DIR = resolve(__dirname, '..');
|
|
19
|
+
const ENV_PATH = resolve(SKILL_DIR, '.env');
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const lines = readFileSync(ENV_PATH, 'utf8').split('\n');
|
|
23
|
+
for (const line of lines) {
|
|
24
|
+
const trimmed = line.trim();
|
|
25
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
26
|
+
const eqIdx = trimmed.indexOf('=');
|
|
27
|
+
if (eqIdx === -1) continue;
|
|
28
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
29
|
+
const val = trimmed.slice(eqIdx + 1).trim().replace(/^["']|["']$/g, '');
|
|
30
|
+
if (!process.env[key]) process.env[key] = val;
|
|
31
|
+
}
|
|
32
|
+
} catch { /* .env not present */ }
|
|
33
|
+
|
|
34
|
+
const ENDPOINT = 'https://api.tavily.com/search';
|
|
35
|
+
|
|
36
|
+
function die(msg, code = 1) {
|
|
37
|
+
process.stderr.write(`ERROR: ${msg}\n`);
|
|
38
|
+
process.exitCode = code;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseArgs(argv) {
|
|
42
|
+
const opts = { query: '', searchDepth: 'advanced', maxResults: 8, topic: 'general', timeRange: 'year', check: false, help: false };
|
|
43
|
+
for (let i = 0; i < argv.length; i++) {
|
|
44
|
+
const a = argv[i];
|
|
45
|
+
if (a === '--help' || a === '-h') { opts.help = true; continue; }
|
|
46
|
+
if (a === '--check') { opts.check = true; continue; }
|
|
47
|
+
if (a === '--query' || a === '-q') { opts.query = argv[++i] || ''; continue; }
|
|
48
|
+
if (a === '--depth') { opts.searchDepth = argv[++i] || 'advanced'; continue; }
|
|
49
|
+
if (a === '--max-results') { opts.maxResults = Number(argv[++i]) || 8; continue; }
|
|
50
|
+
if (a === '--topic') { opts.topic = argv[++i] || 'general'; continue; }
|
|
51
|
+
if (a === '--time-range') { opts.timeRange = argv[++i] || 'year'; continue; }
|
|
52
|
+
if (!opts.query) { opts.query = a; continue; }
|
|
53
|
+
die(`Unknown argument: ${a}`); return null;
|
|
54
|
+
}
|
|
55
|
+
return opts;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function search(opts, apiKey) {
|
|
59
|
+
const body = {
|
|
60
|
+
query: opts.query,
|
|
61
|
+
search_depth: opts.searchDepth,
|
|
62
|
+
topic: opts.topic,
|
|
63
|
+
max_results: opts.maxResults,
|
|
64
|
+
include_answer: true,
|
|
65
|
+
include_raw_content: false,
|
|
66
|
+
time_range: opts.timeRange,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const res = await fetch(ENDPOINT, {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' },
|
|
72
|
+
body: JSON.stringify(body),
|
|
73
|
+
signal: AbortSignal.timeout(30_000),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
if (!res.ok) {
|
|
77
|
+
const text = await res.text().catch(() => '');
|
|
78
|
+
die(`Tavily API ${res.status}: ${text}`);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return res.json();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function main() {
|
|
85
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
86
|
+
if (!opts) return;
|
|
87
|
+
|
|
88
|
+
if (opts.help) {
|
|
89
|
+
console.log(`Tavily web search — octocode-brainstorming
|
|
90
|
+
|
|
91
|
+
Usage:
|
|
92
|
+
node tavily-search.mjs --query "query" [options]
|
|
93
|
+
node tavily-search.mjs --check
|
|
94
|
+
|
|
95
|
+
Options:
|
|
96
|
+
--query, -q Search query (required unless --check)
|
|
97
|
+
--depth basic or advanced (default: advanced)
|
|
98
|
+
--max-results Number of results (default: 8)
|
|
99
|
+
--topic general or news (default: general)
|
|
100
|
+
--time-range day, week, month, or year (default: year)
|
|
101
|
+
--check Exit 0 if TAVILY_API_KEY is set, 1 otherwise
|
|
102
|
+
|
|
103
|
+
.env file: ${ENV_PATH}`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const apiKey = process.env.TAVILY_API_KEY;
|
|
108
|
+
|
|
109
|
+
if (opts.check) {
|
|
110
|
+
if (apiKey) {
|
|
111
|
+
console.log('tavily: available');
|
|
112
|
+
process.exitCode = 0;
|
|
113
|
+
} else {
|
|
114
|
+
console.log(`tavily: unavailable (TAVILY_API_KEY not set)`);
|
|
115
|
+
console.log(`Add TAVILY_API_KEY to: ${ENV_PATH}`);
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
}
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!apiKey) {
|
|
122
|
+
die(`TAVILY_API_KEY is not set. Add it to ${ENV_PATH} or export it in your shell.`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!opts.query) {
|
|
126
|
+
die('--query is required. Use --help for usage.');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
process.stderr.write(`Searching Tavily: "${opts.query}" (depth=${opts.searchDepth}, max=${opts.maxResults})\n`);
|
|
131
|
+
const result = await search(opts, apiKey);
|
|
132
|
+
if (result) {
|
|
133
|
+
result.engine = 'tavily';
|
|
134
|
+
console.log(JSON.stringify(result, null, 2));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
main().catch(err => die(err.message || String(err)));
|