@heretek-ai/epistemic-swarm 0.7.25 → 1.0.2
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/index.ts +1 -0
- package/package.json +63 -139
- package/rpc.ts +1 -0
- package/server.ts +1 -0
- package/src/agents.ts +69 -0
- package/src/continue.ts +40 -0
- package/src/hooks.ts +283 -0
- package/src/panels.tsx +220 -0
- package/src/policy.ts +221 -0
- package/src/pr.ts +37 -0
- package/src/research.ts +63 -0
- package/src/rpc-def.ts +136 -0
- package/src/rpc.ts +331 -0
- package/src/runtime.ts +112 -0
- package/src/server.ts +311 -0
- package/src/session.ts +61 -0
- package/src/tools.ts +61 -0
- package/src/tui.tsx +206 -0
- package/tui.tsx +1 -0
- package/.agents/skills/brainstorming/SKILL.md +0 -19
- package/.agents/skills/code_audit/SKILL.md +0 -19
- package/.agents/skills/darkharvest/SKILL.md +0 -19
- package/.agents/skills/epistemic_search/SKILL.md +0 -19
- package/.agents/skills/factory/SKILL.md +0 -19
- package/.agents/skills/grilling/SKILL.md +0 -19
- package/.agents/skills/oss_scout/SKILL.md +0 -19
- package/.agents/skills/research_cache/SKILL.md +0 -19
- package/.agents/skills/swarm_config/SKILL.md +0 -19
- package/.claude-plugin/marketplace.json +0 -61
- package/.claude-plugin/plugin.json +0 -76
- package/.omp/README.md +0 -39
- package/.omp/SYSTEM.md +0 -17
- package/.omp/commands/audit.md +0 -10
- package/.omp/commands/brainstorming.md +0 -12
- package/.omp/commands/darkharvest.md +0 -11
- package/.omp/commands/domainexpansion.md +0 -9
- package/.omp/commands/factory.md +0 -9
- package/.omp/commands/grill.md +0 -9
- package/.omp/commands/scout.md +0 -10
- package/.omp/commands/swarm-config.md +0 -10
- package/.omp/commands/swarm.md +0 -9
- package/.omp/hooks/post/epistemic-audit.ts +0 -16
- package/.omp/hooks/pre/epistemic-redirect.ts +0 -21
- package/.omp/prompts/brainstorming.md +0 -8
- package/.omp/prompts/swarm.md +0 -8
- package/LICENSE +0 -126
- package/MARKETPLACE.md +0 -130
- package/README.md +0 -403
- package/bin/cli.js +0 -297
- package/config/claude-settings-patch.json +0 -10
- package/config/docker-compose.infra.yml +0 -23
- package/config/domain_packs/biopharma.json +0 -23
- package/config/domain_packs/legal.json +0 -19
- package/config/domain_packs/quant.json +0 -19
- package/config/mcp-research-servers.json +0 -33
- package/config/mcp_launcher.py +0 -153
- package/config/opencode-snippet.json +0 -156
- package/config/searxng_mcp.py +0 -92
- package/extensions/pi/index.js +0 -357
- package/hooks/hooks.json +0 -45
- package/install.sh +0 -473
- package/plugins/antigravity/README.md +0 -72
- package/plugins/antigravity/agents/alpha-thesis.md +0 -36
- package/plugins/antigravity/agents/beta-antithesis.md +0 -35
- package/plugins/antigravity/agents/brainstormer.md +0 -27
- package/plugins/antigravity/agents/code-auditor.md +0 -28
- package/plugins/antigravity/agents/darkharvester.md +0 -30
- package/plugins/antigravity/agents/epistemic-auditor.md +0 -28
- package/plugins/antigravity/agents/manager.md +0 -26
- package/plugins/antigravity/agents/oss-scout.md +0 -27
- package/plugins/antigravity/agents/programmer.md +0 -25
- package/plugins/antigravity/agents/qa-a.md +0 -22
- package/plugins/antigravity/agents/qa-b.md +0 -22
- package/plugins/antigravity/antigravity_hooks.py +0 -265
- package/plugins/antigravity/commands/audit.md +0 -11
- package/plugins/antigravity/commands/brainstorm.md +0 -9
- package/plugins/antigravity/commands/brainstorming.md +0 -10
- package/plugins/antigravity/commands/darkharvest.md +0 -12
- package/plugins/antigravity/commands/domainexpansion.md +0 -12
- package/plugins/antigravity/commands/factory.md +0 -14
- package/plugins/antigravity/commands/grill.md +0 -10
- package/plugins/antigravity/commands/scout.md +0 -11
- package/plugins/antigravity/commands/swarm-config.md +0 -9
- package/plugins/antigravity/commands/swarm.md +0 -12
- package/plugins/antigravity/hook_bus_bridge.js +0 -352
- package/plugins/antigravity/hooks.json +0 -44
- package/plugins/antigravity/mcp_config.json +0 -33
- package/plugins/antigravity/mcp_launcher.py +0 -58
- package/plugins/antigravity/plugin.json +0 -13
- package/plugins/antigravity/rules/AGENTS.md +0 -127
- package/plugins/antigravity/rules/epistemic-integrity.md +0 -16
- package/plugins/antigravity/skills/brainstorming/SKILL.md +0 -19
- package/plugins/antigravity/skills/code_audit/SKILL.md +0 -19
- package/plugins/antigravity/skills/darkharvest/SKILL.md +0 -19
- package/plugins/antigravity/skills/epistemic_search/SKILL.md +0 -19
- package/plugins/antigravity/skills/factory/SKILL.md +0 -19
- package/plugins/antigravity/skills/grilling/SKILL.md +0 -19
- package/plugins/antigravity/skills/oss_scout/SKILL.md +0 -19
- package/plugins/antigravity/skills/research_cache/SKILL.md +0 -19
- package/plugins/antigravity/skills/swarm_config/SKILL.md +0 -19
- package/plugins/codex/AGENTS.md.snippet +0 -10
- package/plugins/codex/README.md +0 -37
- package/plugins/codex/config.toml.snippet +0 -28
- package/plugins/codex/openai.yaml +0 -24
- package/plugins/codex/skills/brainstorming/SKILL.md +0 -19
- package/plugins/codex/skills/code_audit/SKILL.md +0 -19
- package/plugins/codex/skills/darkharvest/SKILL.md +0 -19
- package/plugins/codex/skills/epistemic_search/SKILL.md +0 -19
- package/plugins/codex/skills/factory/SKILL.md +0 -19
- package/plugins/codex/skills/grilling/SKILL.md +0 -19
- package/plugins/codex/skills/oss_scout/SKILL.md +0 -19
- package/plugins/codex/skills/research_cache/SKILL.md +0 -19
- package/plugins/codex/skills/swarm_config/SKILL.md +0 -19
- package/plugins/darkharvest/.claude-plugin/plugin.json +0 -15
- package/plugins/darkharvest/agents/harvest-proponent.md +0 -22
- package/plugins/darkharvest/agents/harvest-redteam.md +0 -20
- package/plugins/darkharvest/evals/teardown-verdict/graders/license-line.md +0 -6
- package/plugins/darkharvest/evals/teardown-verdict/graders/skill-fired.md +0 -5
- package/plugins/darkharvest/evals/teardown-verdict/prompt.md +0 -6
- package/plugins/darkharvest/skills/darkharvest/SKILL.md +0 -70
- package/plugins/darkharvest/skills/darkharvest/scripts/harvest.py +0 -289
- package/plugins/factory/.claude-plugin/plugin.json +0 -15
- package/plugins/factory/agents/factory-manager.md +0 -22
- package/plugins/factory/agents/programmer.md +0 -16
- package/plugins/factory/agents/qa-adversarial.md +0 -17
- package/plugins/factory/agents/qa-functional.md +0 -17
- package/plugins/factory/evals/gate-halt/graders/gates-first.md +0 -6
- package/plugins/factory/evals/gate-halt/graders/skill-fired.md +0 -5
- package/plugins/factory/evals/gate-halt/prompt.md +0 -6
- package/plugins/factory/skills/factory/SKILL.md +0 -61
- package/plugins/factory/skills/factory/scripts/factory.py +0 -300
- package/plugins/gemini/GEMINI.md +0 -16
- package/plugins/gemini/README.md +0 -20
- package/plugins/gemini/commands/audit.toml +0 -6
- package/plugins/gemini/commands/brainstorming.toml +0 -10
- package/plugins/gemini/commands/darkharvest.toml +0 -8
- package/plugins/gemini/commands/domainexpansion.toml +0 -7
- package/plugins/gemini/commands/factory.toml +0 -8
- package/plugins/gemini/commands/grill.toml +0 -6
- package/plugins/gemini/commands/scout.toml +0 -7
- package/plugins/gemini/commands/swarm-config.toml +0 -7
- package/plugins/gemini/commands/swarm.toml +0 -8
- package/plugins/gemini/gemini-extension.json +0 -38
- package/plugins/gemini/hooks/hooks.json +0 -11
- package/plugins/gemini/skills/brainstorming/SKILL.md +0 -19
- package/plugins/gemini/skills/code_audit/SKILL.md +0 -19
- package/plugins/gemini/skills/darkharvest/SKILL.md +0 -19
- package/plugins/gemini/skills/epistemic_search/SKILL.md +0 -19
- package/plugins/gemini/skills/factory/SKILL.md +0 -19
- package/plugins/gemini/skills/grilling/SKILL.md +0 -19
- package/plugins/gemini/skills/oss_scout/SKILL.md +0 -19
- package/plugins/gemini/skills/research_cache/SKILL.md +0 -19
- package/plugins/gemini/skills/swarm_config/SKILL.md +0 -19
- package/plugins/opencode/analysis-bridge.js +0 -620
- package/plugins/opencode/config-io.js +0 -1651
- package/plugins/opencode/dep-health.js +0 -1039
- package/plugins/opencode/hook-bus.js +0 -496
- package/plugins/opencode/index.js +0 -2992
- package/plugins/opencode/tui.js +0 -1551
- package/plugins/opencode/weight-baseline.json +0 -16
- package/plugins/opencode/weight-signals.js +0 -769
- package/plugins/research-cache/.claude-plugin/plugin.json +0 -15
- package/plugins/research-cache/skills/research_cache/SKILL.md +0 -36
- package/plugins/research-cache/skills/research_cache/__init__.py +0 -0
- package/plugins/research-cache/skills/research_cache/hasher.py +0 -302
- package/plugins/socratic-grilling/.claude-plugin/plugin.json +0 -15
- package/plugins/socratic-grilling/skills/grilling/SKILL.md +0 -61
- package/plugins/socratic-grilling/skills/grilling/__init__.py +0 -0
- package/plugins/socratic-grilling/skills/grilling/socratic_tree.py +0 -363
- package/prompts/agent_alpha_thesis.md +0 -70
- package/prompts/agent_beta_antithesis.md +0 -78
- package/prompts/agent_brainstormer.md +0 -143
- package/prompts/agent_code_auditor.md +0 -88
- package/prompts/agent_darkharvest.md +0 -140
- package/prompts/agent_oss_scout.md +0 -78
- package/prompts/antigravity_repo_factcheck.md +0 -143
- package/prompts/base_epistemic_system.md +0 -50
- package/prompts/epistemic_auditor.md +0 -74
- package/prompts/orchestrator.md +0 -70
- package/runner/__init__.py +0 -0
- package/runner/__pycache__/__init__.cpython-311.pyc +0 -0
- package/runner/__pycache__/auctioneer.cpython-311.pyc +0 -0
- package/runner/__pycache__/auditor_engine.cpython-311.pyc +0 -0
- package/runner/__pycache__/claim_store.cpython-311.pyc +0 -0
- package/runner/__pycache__/claim_witness.cpython-311.pyc +0 -0
- package/runner/__pycache__/darkharvest_claims.cpython-311.pyc +0 -0
- package/runner/__pycache__/errors.cpython-311.pyc +0 -0
- package/runner/__pycache__/living_dossiers.cpython-311.pyc +0 -0
- package/runner/__pycache__/mcp_protocol.cpython-311.pyc +0 -0
- package/runner/__pycache__/mcp_server.cpython-311.pyc +0 -0
- package/runner/__pycache__/path_safety.cpython-311.pyc +0 -0
- package/runner/__pycache__/pcrb.cpython-311.pyc +0 -0
- package/runner/__pycache__/pcrb_verify.cpython-311.pyc +0 -0
- package/runner/__pycache__/preflight.cpython-311.pyc +0 -0
- package/runner/__pycache__/refinement.cpython-311.pyc +0 -0
- package/runner/__pycache__/research_swarm.cpython-311.pyc +0 -0
- package/runner/__pycache__/retrieval_log.cpython-311.pyc +0 -0
- package/runner/__pycache__/schema_validate.cpython-311.pyc +0 -0
- package/runner/__pycache__/schemas.cpython-311.pyc +0 -0
- package/runner/__pycache__/state_machine.cpython-311.pyc +0 -0
- package/runner/antigravity_hooks.py +0 -265
- package/runner/auctioneer.py +0 -169
- package/runner/auditor_engine.py +0 -711
- package/runner/claim_store.py +0 -417
- package/runner/claim_witness.py +0 -412
- package/runner/darkharvest_claims.py +0 -358
- package/runner/errors.py +0 -51
- package/runner/living_dossiers.py +0 -395
- package/runner/mcp_protocol.py +0 -188
- package/runner/mcp_server.py +0 -1447
- package/runner/path_safety.py +0 -62
- package/runner/pcrb.py +0 -290
- package/runner/pcrb_verify.py +0 -267
- package/runner/preflight.py +0 -1011
- package/runner/refinement.py +0 -580
- package/runner/research_swarm.py +0 -1848
- package/runner/retrieval_log.py +0 -90
- package/runner/schema_validate.py +0 -193
- package/runner/schemas.py +0 -630
- package/runner/state_machine.py +0 -463
- package/runner/tests/__pycache__/test_analysis_bridge.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_antigravity_plugin.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_auction_order.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_backends.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_bet1_spike.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_claim_store.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_claim_witness.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_claude_plugin.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_config_schema.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_contract_tooling.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_darkharvest_audit.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_dep_health.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_domain_packs.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_dossier_contract.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_factory.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_fleet_seam.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_frontier_concurrency.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_frontier_mirror_standalone.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_grounding.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_hardening_contract.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_hook_bus.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_living_dossiers.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_manifest_concurrency.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_mcp_server.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_nk_hardening.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_opencode_ux.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_opencode_v2_registrars.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_pcrb.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_phase08_waiver_reopens.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_refinement.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_search_anomaly.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_search_provider.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_search_provider_plugin.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_swarm.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_swarm_config.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_sweep_regressions.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_webcache.cpython-311.pyc +0 -0
- package/runner/tests/__pycache__/test_weight_signals.cpython-311.pyc +0 -0
- package/runner/tests/fixtures/auction_objective.json +0 -35
- package/runner/tests/fixtures/borderline_claims.json +0 -27
- package/runner/tests/fixtures/config_validation_cases.json +0 -276
- package/runner/tests/fixtures/ddg_anomaly_page.html +0 -176
- package/runner/tests/fixtures/ddg_results_page.html +0 -28
- package/runner/tests/fixtures/divergence_objectives.json +0 -31
- package/runner/tests/test_analysis_bridge.py +0 -450
- package/runner/tests/test_antigravity_plugin.py +0 -361
- package/runner/tests/test_auction_order.py +0 -173
- package/runner/tests/test_backends.py +0 -457
- package/runner/tests/test_bet1_spike.py +0 -95
- package/runner/tests/test_claim_store.py +0 -162
- package/runner/tests/test_claim_witness.py +0 -186
- package/runner/tests/test_claude_plugin.py +0 -170
- package/runner/tests/test_config_schema.py +0 -879
- package/runner/tests/test_contract_tooling.py +0 -312
- package/runner/tests/test_darkharvest_audit.py +0 -395
- package/runner/tests/test_dep_health.py +0 -595
- package/runner/tests/test_domain_packs.py +0 -217
- package/runner/tests/test_dossier_contract.py +0 -196
- package/runner/tests/test_factory.py +0 -258
- package/runner/tests/test_fleet_seam.py +0 -113
- package/runner/tests/test_frontier_concurrency.py +0 -288
- package/runner/tests/test_frontier_mirror_standalone.py +0 -156
- package/runner/tests/test_grounding.py +0 -183
- package/runner/tests/test_hardening_contract.py +0 -391
- package/runner/tests/test_hook_bus.py +0 -956
- package/runner/tests/test_living_dossiers.py +0 -204
- package/runner/tests/test_manifest_concurrency.py +0 -187
- package/runner/tests/test_mcp_server.py +0 -257
- package/runner/tests/test_nk_hardening.py +0 -1046
- package/runner/tests/test_opencode_ux.py +0 -2438
- package/runner/tests/test_opencode_v2_registrars.py +0 -2157
- package/runner/tests/test_pcrb.py +0 -240
- package/runner/tests/test_phase08_waiver_reopens.py +0 -539
- package/runner/tests/test_refinement.py +0 -255
- package/runner/tests/test_search_anomaly.py +0 -342
- package/runner/tests/test_search_provider.py +0 -1534
- package/runner/tests/test_search_provider_plugin.py +0 -401
- package/runner/tests/test_swarm.py +0 -444
- package/runner/tests/test_swarm_config.py +0 -520
- package/runner/tests/test_sweep_regressions.py +0 -453
- package/runner/tests/test_webcache.py +0 -271
- package/runner/tests/test_weight_signals.py +0 -401
- package/schemas/alpha_dossier.schema.json +0 -204
- package/schemas/audit_report.schema.json +0 -79
- package/schemas/beta_dossier.schema.json +0 -214
- package/schemas/config.schema.json +0 -311
- package/schemas/frontier.schema.json +0 -61
- package/schemas/manifest.schema.json +0 -49
- package/schemas/scope_manifest.schema.json +0 -47
- package/scripts/__pycache__/bet1_advisory_spike.cpython-311.pyc +0 -0
- package/scripts/__pycache__/build_adapters.cpython-311.pyc +0 -0
- package/scripts/__pycache__/check_docs.cpython-311.pyc +0 -0
- package/scripts/__pycache__/divergence_experiment.cpython-311.pyc +0 -0
- package/scripts/__pycache__/gen_schemas.cpython-311.pyc +0 -0
- package/scripts/auction_experiment.py +0 -188
- package/scripts/bet1_advisory_spike.py +0 -442
- package/scripts/build_adapters.py +0 -417
- package/scripts/check_docs.py +0 -66
- package/scripts/divergence_experiment.py +0 -214
- package/scripts/gen_schemas.py +0 -69
- package/skills/brainstorming/SKILL.md +0 -106
- package/skills/brainstorming/__init__.py +0 -1
- package/skills/brainstorming/scripts/brainstorm.py +0 -201
- package/skills/code_audit/SKILL.md +0 -45
- package/skills/darkharvest/SKILL.md +0 -70
- package/skills/darkharvest/scripts/harvest.py +0 -289
- package/skills/epistemic_search/SKILL.md +0 -67
- package/skills/epistemic_search/__init__.py +0 -1
- package/skills/epistemic_search/scripts/__pycache__/search.cpython-311.pyc +0 -0
- package/skills/epistemic_search/scripts/fetch.py +0 -156
- package/skills/epistemic_search/scripts/search.py +0 -551
- package/skills/epistemic_search/scripts/webcache.py +0 -339
- package/skills/factory/SKILL.md +0 -61
- package/skills/factory/scripts/factory.py +0 -300
- package/skills/grilling/SKILL.md +0 -61
- package/skills/grilling/__init__.py +0 -0
- package/skills/grilling/__pycache__/__init__.cpython-311.pyc +0 -0
- package/skills/grilling/__pycache__/socratic_tree.cpython-311.pyc +0 -0
- package/skills/grilling/socratic_tree.py +0 -363
- package/skills/oss_scout/SKILL.md +0 -49
- package/skills/research_cache/SKILL.md +0 -36
- package/skills/research_cache/__init__.py +0 -0
- package/skills/research_cache/__pycache__/__init__.cpython-311.pyc +0 -0
- package/skills/research_cache/__pycache__/hasher.cpython-311.pyc +0 -0
- package/skills/research_cache/hasher.py +0 -302
- package/skills/swarm_config/SKILL.md +0 -178
- package/skills/swarm_config/__init__.py +0 -35
- package/skills/swarm_config/__pycache__/__init__.cpython-311.pyc +0 -0
- package/skills/swarm_config/__pycache__/configure.cpython-311.pyc +0 -0
- package/skills/swarm_config/configure.py +0 -1002
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./src/server.ts"
|
package/package.json
CHANGED
|
@@ -1,154 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heretek-ai/epistemic-swarm",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Epistemic Swarm: an AI build factory for OpenCode v2 — grill, research, spec, build, QA and release, gated mechanically.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Heretek-AI/IUMBTEMS.git",
|
|
10
|
+
"directory": "packages/opencode"
|
|
9
11
|
},
|
|
10
12
|
"exports": {
|
|
11
|
-
".":
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"./
|
|
16
|
-
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./index.ts",
|
|
15
|
+
"default": "./index.ts"
|
|
16
|
+
},
|
|
17
|
+
"./server": {
|
|
18
|
+
"types": "./server.ts",
|
|
19
|
+
"default": "./server.ts"
|
|
20
|
+
},
|
|
21
|
+
"./tui": {
|
|
22
|
+
"types": "./tui.tsx",
|
|
23
|
+
"default": "./tui.tsx"
|
|
24
|
+
},
|
|
25
|
+
"./rpc": {
|
|
26
|
+
"types": "./rpc.ts",
|
|
27
|
+
"default": "./rpc.ts"
|
|
28
|
+
}
|
|
17
29
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
30
|
+
"files": [
|
|
31
|
+
"index.ts",
|
|
32
|
+
"server.ts",
|
|
33
|
+
"tui.tsx",
|
|
34
|
+
"rpc.ts",
|
|
35
|
+
"src"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsc -b",
|
|
39
|
+
"test": "bun test"
|
|
20
40
|
},
|
|
21
41
|
"dependencies": {
|
|
22
|
-
"
|
|
23
|
-
"@
|
|
42
|
+
"@heretek-ai/es-core": "1.0.2",
|
|
43
|
+
"@opencode/plugin": "2.0.24"
|
|
24
44
|
},
|
|
25
|
-
"
|
|
26
|
-
"@
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@heretek-ai/es-testkit": "1.0.0",
|
|
47
|
+
"@opencode/sdk": "2.0.24",
|
|
48
|
+
"@opentui/core": "0.5.14",
|
|
49
|
+
"@opentui/solid": "0.5.14",
|
|
50
|
+
"solid-js": "1.9.15"
|
|
27
51
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=22"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@opentui/core": ">=0.5.14",
|
|
57
|
+
"@opentui/solid": ">=0.5.14",
|
|
58
|
+
"solid-js": ">=1.9.0"
|
|
31
59
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"@opentui/core": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"@opentui/solid": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"solid-js": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
34
70
|
},
|
|
35
|
-
"homepage": "https://github.com/Heretek-AI/IUMBTEMS#readme",
|
|
36
71
|
"keywords": [
|
|
37
|
-
"iumbtems",
|
|
38
|
-
"epistemic-swarm",
|
|
39
|
-
"i-use-my-brain-to-express-my-self",
|
|
40
|
-
"pi-package",
|
|
41
|
-
"omp-package",
|
|
42
72
|
"opencode",
|
|
43
73
|
"opencode-plugin",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
"oh-my-pi",
|
|
49
|
-
"omp",
|
|
50
|
-
"ai-agents",
|
|
51
|
-
"autonomous-agents",
|
|
52
|
-
"multi-agent-systems",
|
|
53
|
-
"dialectic-swarm",
|
|
54
|
-
"dialectic",
|
|
55
|
-
"epistemic-integrity",
|
|
56
|
-
"research-harness",
|
|
57
|
-
"research-agent",
|
|
58
|
-
"mcp",
|
|
59
|
-
"model-context-protocol",
|
|
60
|
-
"mcp-servers",
|
|
61
|
-
"deep-research",
|
|
62
|
-
"socratic-grilling",
|
|
63
|
-
"socratic-questioning",
|
|
64
|
-
"brainstorming",
|
|
65
|
-
"lateral-thinking",
|
|
66
|
-
"fact-checking",
|
|
67
|
-
"red-teaming",
|
|
68
|
-
"citation-validation",
|
|
69
|
-
"hallucination-prevention",
|
|
70
|
-
"swarm-intelligence",
|
|
71
|
-
"code-audit",
|
|
72
|
-
"oss-scout",
|
|
73
|
-
"clean-room-engineering",
|
|
74
|
-
"proof-carrying-briefs",
|
|
75
|
-
"living-dossiers"
|
|
76
|
-
],
|
|
77
|
-
"pi": {
|
|
78
|
-
"extensions": [
|
|
79
|
-
"./extensions/pi/index.js"
|
|
80
|
-
],
|
|
81
|
-
"skills": [
|
|
82
|
-
"./skills/grilling",
|
|
83
|
-
"./skills/research_cache",
|
|
84
|
-
"./skills/epistemic_search",
|
|
85
|
-
"./skills/swarm_config",
|
|
86
|
-
"./skills/code_audit",
|
|
87
|
-
"./skills/oss_scout",
|
|
88
|
-
"./skills/brainstorming",
|
|
89
|
-
"./skills/darkharvest",
|
|
90
|
-
"./skills/factory"
|
|
91
|
-
],
|
|
92
|
-
"prompts": [
|
|
93
|
-
"./prompts/*.md"
|
|
94
|
-
]
|
|
95
|
-
},
|
|
96
|
-
"omp": {
|
|
97
|
-
"extensions": [
|
|
98
|
-
"./extensions/pi/index.js"
|
|
99
|
-
],
|
|
100
|
-
"skills": [
|
|
101
|
-
"./skills/grilling",
|
|
102
|
-
"./skills/research_cache",
|
|
103
|
-
"./skills/epistemic_search",
|
|
104
|
-
"./skills/swarm_config",
|
|
105
|
-
"./skills/code_audit",
|
|
106
|
-
"./skills/oss_scout",
|
|
107
|
-
"./skills/brainstorming",
|
|
108
|
-
"./skills/darkharvest",
|
|
109
|
-
"./skills/factory"
|
|
110
|
-
],
|
|
111
|
-
"prompts": [
|
|
112
|
-
"./prompts/*.md"
|
|
113
|
-
],
|
|
114
|
-
"commands": [
|
|
115
|
-
"./.omp/commands/*.md"
|
|
116
|
-
]
|
|
117
|
-
},
|
|
118
|
-
"author": "Heretek AI",
|
|
119
|
-
"license": "Apache-2.0",
|
|
120
|
-
"files": [
|
|
121
|
-
"bin",
|
|
122
|
-
"prompts",
|
|
123
|
-
"skills",
|
|
124
|
-
"schemas",
|
|
125
|
-
"hooks",
|
|
126
|
-
"config",
|
|
127
|
-
"runner",
|
|
128
|
-
"extensions",
|
|
129
|
-
"plugins",
|
|
130
|
-
"scripts",
|
|
131
|
-
".agents",
|
|
132
|
-
".omp",
|
|
133
|
-
".claude-plugin",
|
|
134
|
-
"install.sh",
|
|
135
|
-
"README.md",
|
|
136
|
-
"MARKETPLACE.md",
|
|
137
|
-
"LICENSE"
|
|
138
|
-
],
|
|
139
|
-
"engines": {
|
|
140
|
-
"node": ">=18.0.0"
|
|
141
|
-
},
|
|
142
|
-
"scripts": {
|
|
143
|
-
"test": "python3 -m unittest discover -s runner/tests",
|
|
144
|
-
"build:adapters": "python3 scripts/build_adapters.py",
|
|
145
|
-
"check:adapters": "python3 scripts/build_adapters.py --check",
|
|
146
|
-
"validate:claude": "claude plugin validate --strict .claude-plugin/marketplace.json && claude plugin validate --strict .",
|
|
147
|
-
"prepack": "python3 scripts/build_adapters.py && python3 -m unittest discover -s runner/tests",
|
|
148
|
-
"install-local": "bash install.sh"
|
|
149
|
-
},
|
|
150
|
-
"devDependencies": {
|
|
151
|
-
"@biomejs/biome": "2.5.15",
|
|
152
|
-
"esbuild": "0.28.2"
|
|
153
|
-
}
|
|
74
|
+
"ai",
|
|
75
|
+
"agents",
|
|
76
|
+
"factory"
|
|
77
|
+
]
|
|
154
78
|
}
|
package/rpc.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EsRpc } from "./src/rpc-def.ts"
|
package/server.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./src/server.ts"
|
package/src/agents.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Compile the canonical agent registry into OpenCode v2 agents. Additive only:
|
|
2
|
+
// we add our own agents and never edit built-ins, default_agent or models.
|
|
3
|
+
// Per-agent tool/skill/MCP scoping is expressed as wildcard-deny permission
|
|
4
|
+
// rules (proven in M0: denied tools, MCP tools and skills are not advertised).
|
|
5
|
+
import { AGENTS, type AgentSpec, ALL_ES_TOOLS, loadPrompt } from "@heretek-ai/es-core"
|
|
6
|
+
import type { PluginOptions } from "./runtime.ts"
|
|
7
|
+
|
|
8
|
+
export interface CompiledAgent {
|
|
9
|
+
readonly spec: AgentSpec
|
|
10
|
+
readonly system: string
|
|
11
|
+
readonly permissions: Array<{ action: string; resource: string; effect: "allow" | "deny" | "ask" }>
|
|
12
|
+
readonly model?: { providerID: string; id: string }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function permissionRules(spec: AgentSpec, mcpServers: readonly string[]): CompiledAgent["permissions"] {
|
|
16
|
+
const rules: CompiledAgent["permissions"] = [
|
|
17
|
+
{ action: "es_*", resource: "*", effect: "deny" },
|
|
18
|
+
...spec.tools.map((tool) => ({ action: tool, resource: "*", effect: "allow" as const })),
|
|
19
|
+
{ action: "subagent", resource: "*", effect: "deny" },
|
|
20
|
+
...spec.spawns.map((agent) => ({ action: "subagent", resource: agent, effect: "allow" as const })),
|
|
21
|
+
{ action: "skill", resource: "*", effect: "deny" },
|
|
22
|
+
...spec.skills.map((skill) => ({ action: "skill", resource: skill, effect: "allow" as const })),
|
|
23
|
+
]
|
|
24
|
+
for (const server of mcpServers)
|
|
25
|
+
if (!spec.mcp.includes(server))
|
|
26
|
+
rules.push({ action: `${server.replace(/[^\w-]/g, "_")}_*`, resource: "*", effect: "deny" })
|
|
27
|
+
if (spec.mode === "subagent") {
|
|
28
|
+
// Autonomous seats never wait on a human: no questions, no paths outside the project except /tmp.
|
|
29
|
+
rules.push({ action: "question", resource: "*", effect: "deny" })
|
|
30
|
+
rules.push({ action: "external_directory", resource: "*", effect: "deny" })
|
|
31
|
+
// Sonar S5443 flags the /tmp literal; it governs creating temp files, while
|
|
32
|
+
// this only grants autonomous seats access to a scratch directory.
|
|
33
|
+
rules.push({ action: "external_directory", resource: "/tmp/*", effect: "allow" }) // NOSONAR
|
|
34
|
+
}
|
|
35
|
+
if (spec.writes.length === 0) rules.push({ action: "edit", resource: "*", effect: "deny" })
|
|
36
|
+
if (spec.lsp === "none") rules.push({ action: "lsp", resource: "*", effect: "deny" })
|
|
37
|
+
if (spec.lsp !== "full") rules.push({ action: "lsp_rename", resource: "*", effect: "deny" })
|
|
38
|
+
return rules
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function modelFor(spec: AgentSpec, options: PluginOptions) {
|
|
42
|
+
const ref = options.models?.agents?.[spec.id] ?? options.models?.[spec.tier]
|
|
43
|
+
const slash = ref?.indexOf("/") ?? -1
|
|
44
|
+
if (!ref || slash <= 0) return undefined
|
|
45
|
+
return { providerID: ref.slice(0, slash), id: ref.slice(slash + 1) }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function compileAgents(options: PluginOptions, mcpServers: readonly string[]): Promise<CompiledAgent[]> {
|
|
49
|
+
return Promise.all(
|
|
50
|
+
AGENTS.map(async (spec) => {
|
|
51
|
+
const prompt = await loadPrompt(spec.prompt)
|
|
52
|
+
const model = modelFor(spec, options)
|
|
53
|
+
return {
|
|
54
|
+
spec,
|
|
55
|
+
system: `${prompt.body}\n\n<!-- epistemic-swarm prompt ${prompt.meta.id} v${prompt.meta.version} -->`,
|
|
56
|
+
permissions: permissionRules(spec, mcpServers),
|
|
57
|
+
...(model ? { model } : {}),
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** es_* tools an agent may see. Agents outside the registry get only the read-only ones. */
|
|
64
|
+
export function visibleEsTools(agentId: string | undefined): readonly string[] {
|
|
65
|
+
const spec = AGENTS.find((agent) => agent.id === agentId)
|
|
66
|
+
return spec ? spec.tools : ["es_status", "es_gates_run"]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { ALL_ES_TOOLS }
|
package/src/continue.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Factory continuation: when the factory's own session finishes a turn while
|
|
2
|
+
// work remains (not halted, not waiting on a human approval or the grill), we
|
|
3
|
+
// re-prompt it to continue. Progress-aware: three idle turns without any state
|
|
4
|
+
// change stop the loop so a confused agent cannot spin on budget.
|
|
5
|
+
import { factorySummary, pendingApprovals } from "@heretek-ai/es-core"
|
|
6
|
+
import type { Runtime } from "./runtime.ts"
|
|
7
|
+
|
|
8
|
+
const ACTIVE = new Set(["RESEARCH", "SPEC", "BUILD", "QA", "RELEASE"])
|
|
9
|
+
const STALL_LIMIT = 3
|
|
10
|
+
|
|
11
|
+
export function createFactoryContinuation(
|
|
12
|
+
ctx: { session: { prompt(input: any): Promise<unknown> } },
|
|
13
|
+
runtime: Runtime,
|
|
14
|
+
) {
|
|
15
|
+
const stalls = new Map<string, { print: string; count: number }>()
|
|
16
|
+
return async (
|
|
17
|
+
event: { type: string; data?: { sessionID?: string } },
|
|
18
|
+
agentOf: (sessionID: string) => Promise<string | undefined>,
|
|
19
|
+
) => {
|
|
20
|
+
const sessionID = event.data?.sessionID
|
|
21
|
+
if (event.type !== "session.execution.succeeded" || !sessionID) return
|
|
22
|
+
if ((await agentOf(sessionID)) !== "factory") return
|
|
23
|
+
const state = await runtime.factory.read()
|
|
24
|
+
if (!state || !ACTIVE.has(state.stage)) return
|
|
25
|
+
if ((await pendingApprovals(runtime.root)).length) return
|
|
26
|
+
const print = JSON.stringify([
|
|
27
|
+
state.stage,
|
|
28
|
+
state.activePhase,
|
|
29
|
+
state.phases.map((phase) => [phase.status, phase.failures, phase.history.length]),
|
|
30
|
+
])
|
|
31
|
+
const previous = stalls.get(sessionID)
|
|
32
|
+
const count = previous?.print === print ? previous.count + 1 : 0
|
|
33
|
+
stalls.set(sessionID, { print, count })
|
|
34
|
+
if (count >= STALL_LIMIT) return
|
|
35
|
+
await ctx.session.prompt({
|
|
36
|
+
sessionID,
|
|
37
|
+
text: `${factorySummary(state)}\nThe factory run is not finished. Continue from the current stage (no human is needed unless an approval is due).`,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/hooks.ts
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
// Hook bridge: Claude Code hooks (from .opencode/hooks.json and
|
|
2
|
+
// .claude/settings*.json) running inside OpenCode v2.
|
|
3
|
+
//
|
|
4
|
+
// PreToolUse ← tool.execute.before (deny blocks; updatedInput rewrites;
|
|
5
|
+
// "ask" defers to the host permission prompt)
|
|
6
|
+
// PostToolUse(Failure)← tool.execute.after (feedback/context appended, output replaced)
|
|
7
|
+
// UserPromptSubmit ← session prompt admission (block rejects, context appended)
|
|
8
|
+
// SessionStart ← first prompt of a session (startup) and after compaction
|
|
9
|
+
// PermissionRequest ← permission.evaluate when the host would ask
|
|
10
|
+
// x-es.ShellPreExec ← shell.create.before
|
|
11
|
+
// Stop (emulated) ← session.execution.succeeded: a block re-prompts the
|
|
12
|
+
// session (8-continuation cap). ADVISORY for plain chat:
|
|
13
|
+
// the host has already ended the turn when we re-prompt.
|
|
14
|
+
import {
|
|
15
|
+
bwrapAvailable,
|
|
16
|
+
fromOpenCode,
|
|
17
|
+
HookEngine,
|
|
18
|
+
permissionActionTool,
|
|
19
|
+
shellQuote,
|
|
20
|
+
toOpenCodeInput,
|
|
21
|
+
} from "@heretek-ai/es-core"
|
|
22
|
+
import { Error as ToolError } from "@opencode/plugin/promise/tool"
|
|
23
|
+
import type { Runtime } from "./runtime.ts"
|
|
24
|
+
|
|
25
|
+
const PERMISSION_CHECKED = new Set([
|
|
26
|
+
"read",
|
|
27
|
+
"write",
|
|
28
|
+
"edit",
|
|
29
|
+
"patch",
|
|
30
|
+
"shell",
|
|
31
|
+
"glob",
|
|
32
|
+
"grep",
|
|
33
|
+
"webfetch",
|
|
34
|
+
"websearch",
|
|
35
|
+
"skill",
|
|
36
|
+
"subagent",
|
|
37
|
+
"question",
|
|
38
|
+
])
|
|
39
|
+
const STOP_CAP = 8
|
|
40
|
+
|
|
41
|
+
type Ctx = {
|
|
42
|
+
readonly generate: { text(input: any): Promise<{ text: string }> }
|
|
43
|
+
readonly session: {
|
|
44
|
+
prompt(input: any): Promise<unknown>
|
|
45
|
+
context(input: any): Promise<readonly any[]>
|
|
46
|
+
interrupt(input: any): Promise<unknown>
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface HookBridge {
|
|
51
|
+
readonly engine: HookEngine
|
|
52
|
+
before(event: { tool: string; agent: string; id: string; sessionID: string; input: unknown }): Promise<void>
|
|
53
|
+
after(event: {
|
|
54
|
+
tool: string
|
|
55
|
+
agent: string
|
|
56
|
+
id: string
|
|
57
|
+
sessionID: string
|
|
58
|
+
input: unknown
|
|
59
|
+
status: string
|
|
60
|
+
result?: any
|
|
61
|
+
error?: any
|
|
62
|
+
}): Promise<void>
|
|
63
|
+
prompt(event: { sessionID: string; prompt: { text: string } }, agent?: string): Promise<void>
|
|
64
|
+
context(event: { sessionID: string; agent: string; system: any[] }): Promise<void>
|
|
65
|
+
evaluate(event: {
|
|
66
|
+
sessionID: string
|
|
67
|
+
agent?: string
|
|
68
|
+
action: string
|
|
69
|
+
resources: readonly string[]
|
|
70
|
+
effect: string
|
|
71
|
+
message?: string
|
|
72
|
+
source?: { id: string }
|
|
73
|
+
}): Promise<void>
|
|
74
|
+
shell(event: { command: string; cwd: string }): Promise<void>
|
|
75
|
+
onEvent(
|
|
76
|
+
event: { type: string; data?: any },
|
|
77
|
+
agentOf: (sessionID: string) => Promise<string | undefined>,
|
|
78
|
+
): Promise<void>
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function lastAssistantText(context: readonly any[]): string {
|
|
82
|
+
for (let i = context.length - 1; i >= 0; i--) {
|
|
83
|
+
const message = context[i]
|
|
84
|
+
if (message?.type !== "assistant") continue
|
|
85
|
+
const text = (message.content ?? [])
|
|
86
|
+
.filter((part: any) => part?.type === "text")
|
|
87
|
+
.map((part: any) => part.text ?? "")
|
|
88
|
+
.join("")
|
|
89
|
+
if (text) return text
|
|
90
|
+
}
|
|
91
|
+
return ""
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function createHookBridge(
|
|
95
|
+
ctx: Ctx,
|
|
96
|
+
runtime: Runtime,
|
|
97
|
+
mcpServers: () => readonly string[],
|
|
98
|
+
): Promise<HookBridge> {
|
|
99
|
+
const engine = await HookEngine.create({
|
|
100
|
+
root: runtime.root,
|
|
101
|
+
stateDir: runtime.stateDir,
|
|
102
|
+
generate: async (prompt, model) => {
|
|
103
|
+
const slash = model?.indexOf("/") ?? -1
|
|
104
|
+
const ref = model && slash > 0 ? { providerID: model.slice(0, slash), id: model.slice(slash + 1) } : undefined
|
|
105
|
+
return (await ctx.generate.text({ prompt, ...(ref ? { model: ref } : {}) })).text
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
const pendingContext = new Map<string, string[]>()
|
|
109
|
+
const pendingAsk = new Map<string, string>()
|
|
110
|
+
const sessionContext = new Map<string, string[]>()
|
|
111
|
+
const startedSessions = new Set<string>()
|
|
112
|
+
const continuations = new Map<string, number>()
|
|
113
|
+
const base = (sessionId: string, agent?: string) => ({ sessionId, ...(agent ? { agent } : {}) })
|
|
114
|
+
|
|
115
|
+
const stash = (map: Map<string, string[]>, key: string, texts: readonly string[]) => {
|
|
116
|
+
if (texts.length) map.set(key, [...(map.get(key) ?? []), ...texts])
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
engine,
|
|
121
|
+
|
|
122
|
+
async before(event) {
|
|
123
|
+
await engine.refresh()
|
|
124
|
+
if (!engine.has("PreToolUse")) return
|
|
125
|
+
const tool = fromOpenCode(event.tool, event.input, runtime.root, mcpServers())
|
|
126
|
+
const decision = await engine.preToolUse(base(event.sessionID, event.agent), tool, event.id)
|
|
127
|
+
if (decision.stop) {
|
|
128
|
+
await ctx.session.interrupt({ sessionID: event.sessionID }).catch(() => undefined)
|
|
129
|
+
throw new ToolError({ message: `Stopped by a hook: ${decision.stop}` })
|
|
130
|
+
}
|
|
131
|
+
if (decision.decision === "deny") throw new ToolError({ message: decision.reason ?? "Denied by a hook" })
|
|
132
|
+
if (decision.decision === "defer")
|
|
133
|
+
throw new ToolError({ message: `Deferred by a hook${decision.reason ? `: ${decision.reason}` : ""}` })
|
|
134
|
+
if (decision.decision === "ask") {
|
|
135
|
+
const builtIn =
|
|
136
|
+
PERMISSION_CHECKED.has(event.tool) ||
|
|
137
|
+
mcpServers().some((server) => event.tool.startsWith(`${server.replace(/[^\w-]/g, "_")}_`))
|
|
138
|
+
if (!builtIn)
|
|
139
|
+
throw new ToolError({
|
|
140
|
+
message: `A hook asked for approval, but ${event.tool} has no permission prompt to ask with; denied.`,
|
|
141
|
+
})
|
|
142
|
+
pendingAsk.set(event.id, decision.reason ?? "A hook asked to confirm this call")
|
|
143
|
+
}
|
|
144
|
+
if (decision.updatedInput)
|
|
145
|
+
event.input = toOpenCodeInput(event.tool, decision.updatedInput, runtime.root, event.input)
|
|
146
|
+
stash(pendingContext, event.id, [
|
|
147
|
+
...decision.additionalContext,
|
|
148
|
+
...decision.systemMessages.map((text) => `Hook message: ${text}`),
|
|
149
|
+
])
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
async after(event) {
|
|
153
|
+
continuations.delete(event.sessionID)
|
|
154
|
+
pendingAsk.delete(event.id)
|
|
155
|
+
const earlier = pendingContext.get(event.id) ?? []
|
|
156
|
+
pendingContext.delete(event.id)
|
|
157
|
+
const failed = event.status !== "completed"
|
|
158
|
+
const texts = [...earlier]
|
|
159
|
+
let replacement: unknown
|
|
160
|
+
if (engine.has(failed ? "PostToolUseFailure" : "PostToolUse")) {
|
|
161
|
+
const tool = fromOpenCode(event.tool, event.input, runtime.root, mcpServers())
|
|
162
|
+
const response = failed
|
|
163
|
+
? (event.error?.message ?? "tool failed")
|
|
164
|
+
: (event.result?.output ?? event.result?.content)
|
|
165
|
+
const post = await engine.postToolUse(base(event.sessionID, event.agent), tool, event.id, response, failed)
|
|
166
|
+
texts.push(
|
|
167
|
+
...post.feedback,
|
|
168
|
+
...post.additionalContext,
|
|
169
|
+
...post.systemMessages.map((text) => `Hook message: ${text}`),
|
|
170
|
+
)
|
|
171
|
+
replacement = post.updatedToolOutput
|
|
172
|
+
if (post.stop) await ctx.session.interrupt({ sessionID: event.sessionID }).catch(() => undefined)
|
|
173
|
+
}
|
|
174
|
+
if (failed || (!texts.length && replacement === undefined)) return
|
|
175
|
+
const original =
|
|
176
|
+
replacement === undefined
|
|
177
|
+
? event.result?.content
|
|
178
|
+
: typeof replacement === "string"
|
|
179
|
+
? replacement
|
|
180
|
+
: JSON.stringify(replacement)
|
|
181
|
+
const block = texts.length ? `<hook-feedback>\n${texts.join("\n")}\n</hook-feedback>` : ""
|
|
182
|
+
const content =
|
|
183
|
+
typeof original === "string" || original === undefined
|
|
184
|
+
? [original ?? "", block].filter(Boolean).join("\n\n")
|
|
185
|
+
: [...original, ...(block ? [{ type: "text", text: block }] : [])]
|
|
186
|
+
event.result = { ...event.result, content }
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
async prompt(event, agent) {
|
|
190
|
+
await engine.refresh()
|
|
191
|
+
if (!startedSessions.has(event.sessionID)) {
|
|
192
|
+
startedSessions.add(event.sessionID)
|
|
193
|
+
if (engine.has("SessionStart"))
|
|
194
|
+
stash(
|
|
195
|
+
sessionContext,
|
|
196
|
+
event.sessionID,
|
|
197
|
+
(await engine.sessionStart(base(event.sessionID, agent), "startup")).additionalContext,
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
if (!engine.has("UserPromptSubmit")) return
|
|
201
|
+
const decision = await engine.userPromptSubmit(base(event.sessionID, agent), event.prompt.text)
|
|
202
|
+
if (decision.block) throw new Error(`Prompt blocked by a hook: ${decision.block}`)
|
|
203
|
+
const context = [...decision.additionalContext, ...decision.systemMessages.map((text) => `Hook message: ${text}`)]
|
|
204
|
+
if (context.length)
|
|
205
|
+
event.prompt.text = `${event.prompt.text}\n\n<system-reminder>\n${context.join("\n")}\n</system-reminder>`
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
context(event) {
|
|
209
|
+
const texts = sessionContext.get(event.sessionID)
|
|
210
|
+
if (texts?.length)
|
|
211
|
+
event.system.push({ type: "text", text: `<session-start-hooks>\n${texts.join("\n")}\n</session-start-hooks>` })
|
|
212
|
+
return Promise.resolve()
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
async evaluate(event) {
|
|
216
|
+
const asked = event.source ? pendingAsk.get(event.source.id) : undefined
|
|
217
|
+
if (event.effect === "deny") return
|
|
218
|
+
if (asked) {
|
|
219
|
+
event.effect = "ask"
|
|
220
|
+
event.message = asked
|
|
221
|
+
}
|
|
222
|
+
if (event.effect !== "ask" || !engine.has("PermissionRequest")) return
|
|
223
|
+
const tool = {
|
|
224
|
+
name: permissionActionTool(event.action),
|
|
225
|
+
aliases: [permissionActionTool(event.action), event.action],
|
|
226
|
+
input: { resources: [...event.resources] },
|
|
227
|
+
}
|
|
228
|
+
const decision = await engine.permissionRequest(base(event.sessionID, event.agent), tool)
|
|
229
|
+
if (decision.behavior === "deny") {
|
|
230
|
+
event.effect = "deny"
|
|
231
|
+
event.message = decision.message ?? "Denied by a hook"
|
|
232
|
+
} else if (decision.behavior === "allow" && !asked) event.effect = "allow"
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
async shell(event) {
|
|
236
|
+
if (!engine.has("x-es.ShellPreExec")) return
|
|
237
|
+
const decision = await engine.shellPreExec(base(""), { command: event.command, cwd: event.cwd })
|
|
238
|
+
if (decision.deny)
|
|
239
|
+
event.command = `printf '%s\\n' ${shellQuote(`Blocked by a hook: ${decision.deny}`)} >&2; exit 126`
|
|
240
|
+
else if (decision.command) event.command = decision.command
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
async onEvent(event, agentOf) {
|
|
244
|
+
const sessionID = event.data?.sessionID
|
|
245
|
+
if (!sessionID) return
|
|
246
|
+
if (event.type === "session.compaction.ended" && engine.has("SessionStart")) {
|
|
247
|
+
const agent = await agentOf(sessionID)
|
|
248
|
+
stash(
|
|
249
|
+
sessionContext,
|
|
250
|
+
sessionID,
|
|
251
|
+
(await engine.sessionStart(base(sessionID, agent), "compact")).additionalContext,
|
|
252
|
+
)
|
|
253
|
+
return
|
|
254
|
+
}
|
|
255
|
+
if (event.type !== "session.execution.succeeded" || !engine.has("Stop")) return
|
|
256
|
+
const count = continuations.get(sessionID) ?? 0
|
|
257
|
+
if (count >= STOP_CAP) {
|
|
258
|
+
continuations.delete(sessionID)
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
const agent = await agentOf(sessionID)
|
|
262
|
+
const context = await ctx.session.context({ sessionID }).catch(() => [] as any[])
|
|
263
|
+
const decision = await engine.stop(base(sessionID, agent), {
|
|
264
|
+
stopHookActive: count > 0,
|
|
265
|
+
lastAssistantMessage: lastAssistantText(context),
|
|
266
|
+
})
|
|
267
|
+
const feedback = [decision.block, ...decision.additionalContext].filter(Boolean)
|
|
268
|
+
if (!feedback.length) {
|
|
269
|
+
continuations.delete(sessionID)
|
|
270
|
+
return
|
|
271
|
+
}
|
|
272
|
+
continuations.set(sessionID, count + 1)
|
|
273
|
+
await ctx.session
|
|
274
|
+
.prompt({
|
|
275
|
+
sessionID,
|
|
276
|
+
text: `<system-reminder>\nStop hook feedback (continuing):\n${feedback.join("\n")}\n</system-reminder>`,
|
|
277
|
+
})
|
|
278
|
+
.catch(() => undefined)
|
|
279
|
+
},
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export { bwrapAvailable }
|