Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
78 lines (64 loc) · 3.24 KB
/
Copy path__init__.py
File metadata and controls
78 lines (64 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Index Network Hermes plugin."""
from __future__ import annotations
import shutil
from pathlib import Path
from . import schemas, tools
from .bridge import HermesBridge
from .cli import index_command, register_cli
from .sidecar import Sidecar
def _remove_unmarked_desktop_copy(home: Path) -> None:
"""Drop a copy this plugin used to write itself.
Hermes installs `desktop/plugin.js` and stamps `.hermes-package.json`. A
folder without that marker was copied by an older register() and loads
enabled. A marked folder belongs to Hermes.
"""
dest = Path(home) / "desktop-plugins" / "index-network"
if (dest / ".hermes-package.json").is_file() or not dest.exists():
return
shutil.rmtree(dest, ignore_errors=True)
_sidecar: Sidecar | None = None
def register(ctx):
global _sidecar
from hermes_constants import get_hermes_home
from . import events
from .morning import sync_morning_cron
home = get_hermes_home()
_remove_unmarked_desktop_copy(home)
bridge = HermesBridge()
def custom_negotiator() -> bool:
try:
return ctx.get_config("custom_negotiator") is True
except Exception: # noqa: BLE001 - an older Hermes or unreadable config stays off.
return False
sidecar = Sidecar(bridge, home, custom_negotiator)
_sidecar = sidecar
bridge.sidecar = sidecar
events.watch(sidecar)
for name, schema, handler in (
("index_read_intents", schemas.INDEX_READ_INTENTS, tools.index_read_intents),
("index_create_intent", schemas.INDEX_CREATE_INTENT, tools.index_create_intent),
("index_update_intent", schemas.INDEX_UPDATE_INTENT, tools.index_update_intent),
("index_list_intent_networks", schemas.INDEX_LIST_INTENT_NETWORKS, tools.index_list_intent_networks),
("index_add_intent_to_network", schemas.INDEX_ADD_INTENT_TO_NETWORK, tools.index_add_intent_to_network),
("index_read_networks", schemas.INDEX_READ_NETWORKS, tools.index_read_networks),
("index_read_network_memberships", schemas.INDEX_READ_NETWORK_MEMBERSHIPS, tools.index_read_network_memberships),
("index_create_network", schemas.INDEX_CREATE_NETWORK, tools.index_create_network),
("index_update_network", schemas.INDEX_UPDATE_NETWORK, tools.index_update_network),
("index_join_network", schemas.INDEX_JOIN_NETWORK, tools.index_join_network),
("index_list_opportunities", schemas.INDEX_LIST_OPPORTUNITIES, tools.index_list_opportunities),
("index_update_opportunity", schemas.INDEX_UPDATE_OPPORTUNITY, tools.index_update_opportunity),
("index_research_profile", schemas.INDEX_RESEARCH_PROFILE, tools.index_research_profile),
("index_read_docs", schemas.INDEX_READ_DOCS, tools.index_read_docs),
("index_agent_me", schemas.INDEX_AGENT_ME, tools.index_agent_me),
("index_open_app", schemas.INDEX_OPEN_APP, tools.index_open_app),
):
ctx.register_tool(name=name, toolset="index-network", schema=schema, handler=handler)
ctx.register_cli_command(
name="index",
help="Sign in to Index",
setup_fn=register_cli,
handler_fn=index_command,
)
from .mcp import sync_index_mcp
sync_index_mcp()
ctx.on_unload(lambda: sync_morning_cron(home, False))