nexo-brain 0.9.0 → 0.10.0-beta.1
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 +4 -2
- package/package.json +1 -1
- package/src/cognitive.py +2 -2
- package/src/dashboard/__pycache__/__init__.cpython-314.pyc +0 -0
- package/src/dashboard/__pycache__/app.cpython-314.pyc +0 -0
- package/src/db.py +50 -0
- package/src/plugins/artifact_registry.py +450 -0
- package/src/plugins/episodic_memory.py +5 -5
- package/src/tools_menu.py +2 -2
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# NEXO Brain — Your AI Gets a Brain
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/nexo-brain)
|
|
4
4
|
[](https://github.com/wazionapps/nexo/blob/main/benchmarks/locomo/results/)
|
|
5
5
|
[](https://github.com/snap-research/locomo/issues/33)
|
|
6
6
|
[](https://github.com/wazionapps/nexo/stargazers)
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
|
|
9
|
-
> **v0.
|
|
9
|
+
> **v0.10.0-beta.1** — Artifact Registry (structured recall for services, dashboards, scripts), Retrieval Ladder (alias → port → path → fuzzy → semantic), User-Language Alias Learning. Plus everything from v0.9.0.
|
|
10
|
+
>
|
|
11
|
+
> Install beta: `npx nexo-brain@beta` | Stable: `npx nexo-brain`
|
|
10
12
|
|
|
11
13
|
**NEXO Brain transforms any MCP-compatible AI agent from a stateless assistant into a cognitive partner that remembers, learns, forgets, adapts, and builds a relationship with you over time.**
|
|
12
14
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexo-brain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-beta.1",
|
|
4
4
|
"mcpName": "io.github.wazionapps/nexo",
|
|
5
5
|
"description": "NEXO — Cognitive co-operator for Claude Code. Atkinson-Shiffrin memory, semantic RAG, trust scoring, and metacognitive error prevention.",
|
|
6
6
|
"bin": {
|
package/src/cognitive.py
CHANGED
|
@@ -30,13 +30,13 @@ DISCRIMINATING_ENTITIES = {
|
|
|
30
30
|
# OS / Environment
|
|
31
31
|
"linux", "mac", "macos", "windows", "darwin", "ubuntu", "debian", "alpine",
|
|
32
32
|
# Platforms
|
|
33
|
-
"shopify", "wazion", "
|
|
33
|
+
"shopify", "wazion", "project-a", "project-b", "whatsapp", "chrome", "firefox",
|
|
34
34
|
# Languages / Runtimes
|
|
35
35
|
"python", "php", "javascript", "typescript", "node", "deno", "ruby",
|
|
36
36
|
# Versions
|
|
37
37
|
"v1", "v2", "v3", "v4", "v5", "5.6", "7.4", "8.0", "8.1", "8.2",
|
|
38
38
|
# Infrastructure
|
|
39
|
-
"
|
|
39
|
+
"server", "cloudrun", "gcloud", "vps", "local", "production", "staging",
|
|
40
40
|
# DB
|
|
41
41
|
"mysql", "sqlite", "postgresql", "postgres", "redis",
|
|
42
42
|
}
|
|
Binary file
|
|
Binary file
|
package/src/db.py
CHANGED
|
@@ -928,6 +928,55 @@ def _m10_diary_archive(conn):
|
|
|
928
928
|
""")
|
|
929
929
|
|
|
930
930
|
|
|
931
|
+
def _m11_artifact_registry(conn):
|
|
932
|
+
"""Artifact Registry — structured index of things the agent creates/deploys.
|
|
933
|
+
|
|
934
|
+
Solves 'recent work amnesia': agents build services, dashboards, scripts, APIs
|
|
935
|
+
but can't find them hours later because semantic search fails on operational
|
|
936
|
+
vocabulary mismatches (e.g., 'backend' vs 'FastAPI localhost:6174').
|
|
937
|
+
|
|
938
|
+
Design informed by multi-AI debate (GPT-5.4 + Gemini 3.1 Pro + Claude Opus 4.6).
|
|
939
|
+
"""
|
|
940
|
+
conn.execute("""
|
|
941
|
+
CREATE TABLE IF NOT EXISTS artifact_registry (
|
|
942
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
943
|
+
kind TEXT NOT NULL,
|
|
944
|
+
canonical_name TEXT NOT NULL,
|
|
945
|
+
aliases TEXT DEFAULT '[]',
|
|
946
|
+
description TEXT DEFAULT '',
|
|
947
|
+
uri TEXT DEFAULT '',
|
|
948
|
+
ports TEXT DEFAULT '[]',
|
|
949
|
+
paths TEXT DEFAULT '[]',
|
|
950
|
+
run_cmd TEXT DEFAULT '',
|
|
951
|
+
repo TEXT DEFAULT '',
|
|
952
|
+
domain TEXT DEFAULT '',
|
|
953
|
+
state TEXT DEFAULT 'active',
|
|
954
|
+
session_id TEXT DEFAULT '',
|
|
955
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
956
|
+
last_touched_at TEXT DEFAULT (datetime('now')),
|
|
957
|
+
last_verified_at TEXT DEFAULT NULL,
|
|
958
|
+
metadata TEXT DEFAULT '{}'
|
|
959
|
+
)
|
|
960
|
+
""")
|
|
961
|
+
conn.execute("""
|
|
962
|
+
CREATE TABLE IF NOT EXISTS artifact_aliases (
|
|
963
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
964
|
+
artifact_id INTEGER NOT NULL REFERENCES artifact_registry(id) ON DELETE CASCADE,
|
|
965
|
+
phrase TEXT NOT NULL,
|
|
966
|
+
source TEXT DEFAULT 'manual',
|
|
967
|
+
confidence REAL DEFAULT 1.0,
|
|
968
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
969
|
+
UNIQUE(artifact_id, phrase)
|
|
970
|
+
)
|
|
971
|
+
""")
|
|
972
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_artifact_state ON artifact_registry(state)")
|
|
973
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_artifact_kind ON artifact_registry(kind)")
|
|
974
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_artifact_domain ON artifact_registry(domain)")
|
|
975
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_artifact_last_touched ON artifact_registry(last_touched_at)")
|
|
976
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_artifact_aliases_phrase ON artifact_aliases(phrase)")
|
|
977
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_artifact_aliases_aid ON artifact_aliases(artifact_id)")
|
|
978
|
+
|
|
979
|
+
|
|
931
980
|
def _m9_maintenance_schedule(conn):
|
|
932
981
|
conn.execute("""
|
|
933
982
|
CREATE TABLE IF NOT EXISTS maintenance_schedule (
|
|
@@ -962,6 +1011,7 @@ MIGRATIONS = [
|
|
|
962
1011
|
(8, "adaptive_log_and_somatic", _m8_adaptive_log_and_somatic),
|
|
963
1012
|
(9, "maintenance_schedule", _m9_maintenance_schedule),
|
|
964
1013
|
(10, "diary_archive", _m10_diary_archive),
|
|
1014
|
+
(11, "artifact_registry", _m11_artifact_registry),
|
|
965
1015
|
]
|
|
966
1016
|
|
|
967
1017
|
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
"""Artifact Registry plugin — structured index of things NEXO creates/deploys.
|
|
2
|
+
|
|
3
|
+
Solves 'recent work amnesia': NEXO builds services, dashboards, scripts, APIs
|
|
4
|
+
but can't find them hours later because semantic search ('backend') doesn't
|
|
5
|
+
match operational terms ('FastAPI localhost:6174').
|
|
6
|
+
|
|
7
|
+
Architecture (from 3-way AI debate — GPT-5.4 + Gemini 3.1 Pro + Claude Opus 4.6):
|
|
8
|
+
1. Structured SQLite table with aliases, ports, paths, run commands
|
|
9
|
+
2. Retrieval ladder: exact alias → port/path match → fuzzy token → semantic fallback
|
|
10
|
+
3. User-language alias learning: when the user says 'backend' and it resolves
|
|
11
|
+
to dashboard:6174, store that mapping for O(1) next time
|
|
12
|
+
4. Temporal filtering: 'last night' → hard SQL constraint before any search
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
import datetime
|
|
17
|
+
from db import get_db
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Valid artifact kinds
|
|
21
|
+
VALID_KINDS = {
|
|
22
|
+
'service', 'dashboard', 'script', 'api', 'cron', 'website',
|
|
23
|
+
'database', 'repo', 'config', 'tool', 'plugin', 'other',
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
VALID_STATES = {'active', 'inactive', 'broken', 'archived'}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _cognitive_ingest_safe(content, source_type, source_id="", source_title="", domain=""):
|
|
30
|
+
"""Ingest to cognitive STM. Silently fails if cognitive engine unavailable."""
|
|
31
|
+
try:
|
|
32
|
+
import cognitive
|
|
33
|
+
cognitive.ingest(content, source_type, source_id, source_title, domain)
|
|
34
|
+
except Exception:
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def handle_artifact_create(
|
|
39
|
+
kind: str,
|
|
40
|
+
canonical_name: str,
|
|
41
|
+
aliases: str = '[]',
|
|
42
|
+
description: str = '',
|
|
43
|
+
uri: str = '',
|
|
44
|
+
ports: str = '[]',
|
|
45
|
+
paths: str = '[]',
|
|
46
|
+
run_cmd: str = '',
|
|
47
|
+
repo: str = '',
|
|
48
|
+
domain: str = '',
|
|
49
|
+
session_id: str = '',
|
|
50
|
+
metadata: str = '{}',
|
|
51
|
+
) -> str:
|
|
52
|
+
"""Register a new artifact (service, dashboard, script, API, etc.).
|
|
53
|
+
|
|
54
|
+
Call this whenever NEXO creates, deploys, or discovers a runnable/accessible artifact.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
kind: Type — service, dashboard, script, api, cron, website, database, repo, config, tool, plugin, other
|
|
58
|
+
canonical_name: Primary name (e.g., 'NEXO Brain Dashboard')
|
|
59
|
+
aliases: JSON array of alternative names users might use (e.g., '["backend", "dashboard", "nexo web"]')
|
|
60
|
+
description: What it does (1-2 sentences)
|
|
61
|
+
uri: Access URL or address (e.g., 'localhost:6174', 'nexo-brain.com')
|
|
62
|
+
ports: JSON array of ports (e.g., '[6174]')
|
|
63
|
+
paths: JSON array of file paths (e.g., '["/Users/x/nexo/src/dashboard/app.py"]')
|
|
64
|
+
run_cmd: Command to start/open it (e.g., 'python3 -m dashboard.app --port 6174')
|
|
65
|
+
repo: Repository path or URL
|
|
66
|
+
domain: Project domain (project-a, project-b, etc.)
|
|
67
|
+
session_id: Current session ID
|
|
68
|
+
metadata: JSON object with extra key-value pairs
|
|
69
|
+
"""
|
|
70
|
+
if kind not in VALID_KINDS:
|
|
71
|
+
return f"ERROR: kind must be one of: {', '.join(sorted(VALID_KINDS))}"
|
|
72
|
+
|
|
73
|
+
# Parse aliases
|
|
74
|
+
try:
|
|
75
|
+
alias_list = json.loads(aliases) if aliases and aliases != '[]' else []
|
|
76
|
+
except (json.JSONDecodeError, TypeError):
|
|
77
|
+
alias_list = [a.strip() for a in aliases.split(',') if a.strip()]
|
|
78
|
+
|
|
79
|
+
conn = get_db()
|
|
80
|
+
cur = conn.execute(
|
|
81
|
+
"""INSERT INTO artifact_registry
|
|
82
|
+
(kind, canonical_name, aliases, description, uri, ports, paths,
|
|
83
|
+
run_cmd, repo, domain, state, session_id, metadata)
|
|
84
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, ?)""",
|
|
85
|
+
(kind, canonical_name, json.dumps(alias_list), description, uri, ports,
|
|
86
|
+
paths, run_cmd, repo, domain, session_id, metadata),
|
|
87
|
+
)
|
|
88
|
+
artifact_id = cur.lastrowid
|
|
89
|
+
conn.commit()
|
|
90
|
+
|
|
91
|
+
# Insert aliases into lookup table
|
|
92
|
+
for alias in alias_list + [canonical_name.lower()]:
|
|
93
|
+
alias_clean = alias.strip().lower()
|
|
94
|
+
if alias_clean:
|
|
95
|
+
try:
|
|
96
|
+
conn.execute(
|
|
97
|
+
"INSERT OR IGNORE INTO artifact_aliases (artifact_id, phrase, source) VALUES (?, ?, 'create')",
|
|
98
|
+
(artifact_id, alias_clean),
|
|
99
|
+
)
|
|
100
|
+
except Exception:
|
|
101
|
+
pass
|
|
102
|
+
conn.commit()
|
|
103
|
+
|
|
104
|
+
# Ingest to cognitive memory
|
|
105
|
+
content = f"Artifact: {canonical_name} ({kind}). {description}. URI: {uri}. Aliases: {', '.join(alias_list)}"
|
|
106
|
+
_cognitive_ingest_safe(content, "artifact", f"A{artifact_id}", canonical_name[:80], domain)
|
|
107
|
+
|
|
108
|
+
return f"Artifact #{artifact_id} created: {canonical_name} ({kind}) — {uri or 'no URI'}"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def handle_artifact_find(query: str, kind: str = '', state: str = 'active') -> str:
|
|
112
|
+
"""Find artifacts using the retrieval ladder: exact alias → port/path → fuzzy token → all recent.
|
|
113
|
+
|
|
114
|
+
This is the PRIMARY retrieval tool. Use it when the user references something
|
|
115
|
+
they or NEXO built/deployed/created. Designed for natural language like
|
|
116
|
+
'the backend', 'that script from yesterday', 'localhost something'.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
query: What to search for — name, alias, port, path, or description fragment
|
|
120
|
+
kind: Filter by kind (optional)
|
|
121
|
+
state: Filter by state — default 'active'. Use 'all' for everything.
|
|
122
|
+
"""
|
|
123
|
+
conn = get_db()
|
|
124
|
+
results = []
|
|
125
|
+
query_lower = query.strip().lower()
|
|
126
|
+
|
|
127
|
+
state_filter = "AND state = ?" if state != 'all' else ""
|
|
128
|
+
state_params = (state,) if state != 'all' else ()
|
|
129
|
+
|
|
130
|
+
kind_filter = "AND kind = ?" if kind else ""
|
|
131
|
+
kind_params = (kind,) if kind else ()
|
|
132
|
+
|
|
133
|
+
extra_filters = state_filter + " " + kind_filter
|
|
134
|
+
extra_params = state_params + kind_params
|
|
135
|
+
|
|
136
|
+
# --- STAGE 1: Exact alias match (fastest, O(1)) ---
|
|
137
|
+
rows = conn.execute(
|
|
138
|
+
f"""SELECT DISTINCT r.* FROM artifact_registry r
|
|
139
|
+
JOIN artifact_aliases a ON a.artifact_id = r.id
|
|
140
|
+
WHERE a.phrase = ? {extra_filters}
|
|
141
|
+
ORDER BY r.last_touched_at DESC LIMIT 5""",
|
|
142
|
+
(query_lower,) + extra_params,
|
|
143
|
+
).fetchall()
|
|
144
|
+
if rows:
|
|
145
|
+
results = [dict(r) for r in rows]
|
|
146
|
+
return _format_results(results, "alias match", query)
|
|
147
|
+
|
|
148
|
+
# --- STAGE 2: Port or URI match ---
|
|
149
|
+
rows = conn.execute(
|
|
150
|
+
f"""SELECT * FROM artifact_registry
|
|
151
|
+
WHERE (uri LIKE ? OR ports LIKE ?) {extra_filters}
|
|
152
|
+
ORDER BY last_touched_at DESC LIMIT 5""",
|
|
153
|
+
(f"%{query_lower}%", f"%{query_lower}%") + extra_params,
|
|
154
|
+
).fetchall()
|
|
155
|
+
if rows:
|
|
156
|
+
results = [dict(r) for r in rows]
|
|
157
|
+
return _format_results(results, "URI/port match", query)
|
|
158
|
+
|
|
159
|
+
# --- STAGE 3: Path match ---
|
|
160
|
+
rows = conn.execute(
|
|
161
|
+
f"""SELECT * FROM artifact_registry
|
|
162
|
+
WHERE paths LIKE ? {extra_filters}
|
|
163
|
+
ORDER BY last_touched_at DESC LIMIT 5""",
|
|
164
|
+
(f"%{query_lower}%",) + extra_params,
|
|
165
|
+
).fetchall()
|
|
166
|
+
if rows:
|
|
167
|
+
results = [dict(r) for r in rows]
|
|
168
|
+
return _format_results(results, "path match", query)
|
|
169
|
+
|
|
170
|
+
# --- STAGE 4: Fuzzy token match on name, description, aliases ---
|
|
171
|
+
tokens = query_lower.split()
|
|
172
|
+
if tokens:
|
|
173
|
+
conditions = " AND ".join(
|
|
174
|
+
"(LOWER(canonical_name) LIKE ? OR LOWER(description) LIKE ? OR LOWER(aliases) LIKE ?)"
|
|
175
|
+
for _ in tokens
|
|
176
|
+
)
|
|
177
|
+
params = []
|
|
178
|
+
for t in tokens:
|
|
179
|
+
p = f"%{t}%"
|
|
180
|
+
params.extend([p, p, p])
|
|
181
|
+
rows = conn.execute(
|
|
182
|
+
f"""SELECT * FROM artifact_registry
|
|
183
|
+
WHERE {conditions} {extra_filters}
|
|
184
|
+
ORDER BY last_touched_at DESC LIMIT 10""",
|
|
185
|
+
tuple(params) + extra_params,
|
|
186
|
+
).fetchall()
|
|
187
|
+
if rows:
|
|
188
|
+
results = [dict(r) for r in rows]
|
|
189
|
+
return _format_results(results, "token match", query)
|
|
190
|
+
|
|
191
|
+
# --- STAGE 5: Recent artifacts (last 72h) as fallback ---
|
|
192
|
+
cutoff = (datetime.datetime.now() - datetime.timedelta(hours=72)).isoformat()
|
|
193
|
+
rows = conn.execute(
|
|
194
|
+
f"""SELECT * FROM artifact_registry
|
|
195
|
+
WHERE last_touched_at >= ? {extra_filters}
|
|
196
|
+
ORDER BY last_touched_at DESC LIMIT 10""",
|
|
197
|
+
(cutoff,) + extra_params,
|
|
198
|
+
).fetchall()
|
|
199
|
+
if rows:
|
|
200
|
+
results = [dict(r) for r in rows]
|
|
201
|
+
return _format_results(results, "recent (72h)", query)
|
|
202
|
+
|
|
203
|
+
return f"No artifacts found for '{query}'. Use artifact_list to see all registered artifacts."
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def handle_artifact_update(
|
|
207
|
+
id: int,
|
|
208
|
+
canonical_name: str = '',
|
|
209
|
+
aliases: str = '',
|
|
210
|
+
description: str = '',
|
|
211
|
+
uri: str = '',
|
|
212
|
+
ports: str = '',
|
|
213
|
+
paths: str = '',
|
|
214
|
+
run_cmd: str = '',
|
|
215
|
+
state: str = '',
|
|
216
|
+
domain: str = '',
|
|
217
|
+
metadata: str = '',
|
|
218
|
+
) -> str:
|
|
219
|
+
"""Update an artifact. Only non-empty fields are changed.
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
id: Artifact ID to update
|
|
223
|
+
canonical_name: New primary name
|
|
224
|
+
aliases: New JSON array of aliases (replaces existing)
|
|
225
|
+
description: New description
|
|
226
|
+
uri: New URI
|
|
227
|
+
ports: New ports JSON array
|
|
228
|
+
paths: New paths JSON array
|
|
229
|
+
run_cmd: New run command
|
|
230
|
+
state: New state (active, inactive, broken, archived)
|
|
231
|
+
domain: New domain
|
|
232
|
+
metadata: New metadata JSON (merged with existing)
|
|
233
|
+
"""
|
|
234
|
+
conn = get_db()
|
|
235
|
+
row = conn.execute("SELECT * FROM artifact_registry WHERE id = ?", (id,)).fetchone()
|
|
236
|
+
if not row:
|
|
237
|
+
return f"ERROR: Artifact #{id} not found."
|
|
238
|
+
|
|
239
|
+
updates = []
|
|
240
|
+
params = []
|
|
241
|
+
|
|
242
|
+
if canonical_name:
|
|
243
|
+
updates.append("canonical_name = ?"); params.append(canonical_name)
|
|
244
|
+
if description:
|
|
245
|
+
updates.append("description = ?"); params.append(description)
|
|
246
|
+
if uri:
|
|
247
|
+
updates.append("uri = ?"); params.append(uri)
|
|
248
|
+
if ports:
|
|
249
|
+
updates.append("ports = ?"); params.append(ports)
|
|
250
|
+
if paths:
|
|
251
|
+
updates.append("paths = ?"); params.append(paths)
|
|
252
|
+
if run_cmd:
|
|
253
|
+
updates.append("run_cmd = ?"); params.append(run_cmd)
|
|
254
|
+
if domain:
|
|
255
|
+
updates.append("domain = ?"); params.append(domain)
|
|
256
|
+
if state:
|
|
257
|
+
if state not in VALID_STATES:
|
|
258
|
+
return f"ERROR: state must be one of: {', '.join(sorted(VALID_STATES))}"
|
|
259
|
+
updates.append("state = ?"); params.append(state)
|
|
260
|
+
if metadata:
|
|
261
|
+
try:
|
|
262
|
+
existing = json.loads(row["metadata"] or '{}')
|
|
263
|
+
new = json.loads(metadata)
|
|
264
|
+
existing.update(new)
|
|
265
|
+
updates.append("metadata = ?"); params.append(json.dumps(existing))
|
|
266
|
+
except (json.JSONDecodeError, TypeError):
|
|
267
|
+
pass
|
|
268
|
+
|
|
269
|
+
if aliases:
|
|
270
|
+
try:
|
|
271
|
+
alias_list = json.loads(aliases) if aliases.startswith('[') else [a.strip() for a in aliases.split(',')]
|
|
272
|
+
except (json.JSONDecodeError, TypeError):
|
|
273
|
+
alias_list = [a.strip() for a in aliases.split(',')]
|
|
274
|
+
updates.append("aliases = ?"); params.append(json.dumps(alias_list))
|
|
275
|
+
# Rebuild alias lookup table
|
|
276
|
+
conn.execute("DELETE FROM artifact_aliases WHERE artifact_id = ?", (id,))
|
|
277
|
+
for alias in alias_list:
|
|
278
|
+
alias_clean = alias.strip().lower()
|
|
279
|
+
if alias_clean:
|
|
280
|
+
conn.execute(
|
|
281
|
+
"INSERT OR IGNORE INTO artifact_aliases (artifact_id, phrase, source) VALUES (?, ?, 'update')",
|
|
282
|
+
(id, alias_clean),
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
if not updates:
|
|
286
|
+
return "Nothing to update."
|
|
287
|
+
|
|
288
|
+
updates.append("last_touched_at = datetime('now')")
|
|
289
|
+
params.append(id)
|
|
290
|
+
conn.execute(f"UPDATE artifact_registry SET {', '.join(updates)} WHERE id = ?", tuple(params))
|
|
291
|
+
conn.commit()
|
|
292
|
+
return f"Artifact #{id} updated."
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def handle_artifact_learn_alias(id: int, phrase: str) -> str:
|
|
296
|
+
"""Learn a new alias from user language. Call this when the user refers to an
|
|
297
|
+
artifact with a term not yet registered (e.g., the user says 'backend' for dashboard:6174).
|
|
298
|
+
|
|
299
|
+
Args:
|
|
300
|
+
id: Artifact ID
|
|
301
|
+
phrase: The user's term (e.g., 'backend', 'that api thing')
|
|
302
|
+
"""
|
|
303
|
+
conn = get_db()
|
|
304
|
+
row = conn.execute("SELECT * FROM artifact_registry WHERE id = ?", (id,)).fetchone()
|
|
305
|
+
if not row:
|
|
306
|
+
return f"ERROR: Artifact #{id} not found."
|
|
307
|
+
|
|
308
|
+
phrase_clean = phrase.strip().lower()
|
|
309
|
+
if not phrase_clean:
|
|
310
|
+
return "ERROR: Empty phrase."
|
|
311
|
+
|
|
312
|
+
# Add to alias lookup table
|
|
313
|
+
conn.execute(
|
|
314
|
+
"INSERT OR IGNORE INTO artifact_aliases (artifact_id, phrase, source) VALUES (?, ?, 'user_language')",
|
|
315
|
+
(id, phrase_clean),
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
# Also add to the artifact's aliases JSON array
|
|
319
|
+
try:
|
|
320
|
+
existing = json.loads(row["aliases"] or '[]')
|
|
321
|
+
except (json.JSONDecodeError, TypeError):
|
|
322
|
+
existing = []
|
|
323
|
+
if phrase_clean not in [a.lower() for a in existing]:
|
|
324
|
+
existing.append(phrase_clean)
|
|
325
|
+
conn.execute(
|
|
326
|
+
"UPDATE artifact_registry SET aliases = ?, last_touched_at = datetime('now') WHERE id = ?",
|
|
327
|
+
(json.dumps(existing), id),
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
conn.commit()
|
|
331
|
+
return f"Alias '{phrase_clean}' learned for artifact #{id} ({row['canonical_name']})."
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def handle_artifact_list(kind: str = '', state: str = 'active', recent_hours: int = 0) -> str:
|
|
335
|
+
"""List all artifacts, optionally filtered.
|
|
336
|
+
|
|
337
|
+
Args:
|
|
338
|
+
kind: Filter by kind (service, dashboard, script, etc.)
|
|
339
|
+
state: Filter by state — 'active' (default), 'all', 'inactive', 'broken', 'archived'
|
|
340
|
+
recent_hours: If >0, only show artifacts touched in the last N hours
|
|
341
|
+
"""
|
|
342
|
+
conn = get_db()
|
|
343
|
+
conditions = []
|
|
344
|
+
params = []
|
|
345
|
+
|
|
346
|
+
if state != 'all':
|
|
347
|
+
conditions.append("state = ?"); params.append(state)
|
|
348
|
+
if kind:
|
|
349
|
+
conditions.append("kind = ?"); params.append(kind)
|
|
350
|
+
if recent_hours > 0:
|
|
351
|
+
cutoff = (datetime.datetime.now() - datetime.timedelta(hours=recent_hours)).isoformat()
|
|
352
|
+
conditions.append("last_touched_at >= ?"); params.append(cutoff)
|
|
353
|
+
|
|
354
|
+
where = "WHERE " + " AND ".join(conditions) if conditions else ""
|
|
355
|
+
rows = conn.execute(
|
|
356
|
+
f"SELECT * FROM artifact_registry {where} ORDER BY last_touched_at DESC",
|
|
357
|
+
tuple(params),
|
|
358
|
+
).fetchall()
|
|
359
|
+
|
|
360
|
+
if not rows:
|
|
361
|
+
filters = []
|
|
362
|
+
if kind: filters.append(f"kind={kind}")
|
|
363
|
+
if state != 'all': filters.append(f"state={state}")
|
|
364
|
+
if recent_hours: filters.append(f"last {recent_hours}h")
|
|
365
|
+
return f"No artifacts found{' (' + ', '.join(filters) + ')' if filters else ''}."
|
|
366
|
+
|
|
367
|
+
lines = [f"ARTIFACT REGISTRY ({len(rows)}):"]
|
|
368
|
+
for r in rows:
|
|
369
|
+
r = dict(r)
|
|
370
|
+
aliases_str = ""
|
|
371
|
+
try:
|
|
372
|
+
aliases = json.loads(r.get("aliases", "[]"))
|
|
373
|
+
if aliases:
|
|
374
|
+
aliases_str = f" aka [{', '.join(aliases[:3])}]"
|
|
375
|
+
except (json.JSONDecodeError, TypeError):
|
|
376
|
+
pass
|
|
377
|
+
uri_str = f" → {r['uri']}" if r.get("uri") else ""
|
|
378
|
+
cmd_str = f" | cmd: {r['run_cmd'][:60]}" if r.get("run_cmd") else ""
|
|
379
|
+
touched = r.get("last_touched_at", "")[:16]
|
|
380
|
+
lines.append(
|
|
381
|
+
f" #{r['id']} [{r['kind']}] {r['canonical_name']}{aliases_str}{uri_str}{cmd_str} "
|
|
382
|
+
f"({r['state']}, {touched})"
|
|
383
|
+
)
|
|
384
|
+
return "\n".join(lines)
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def handle_artifact_delete(id: int) -> str:
|
|
388
|
+
"""Delete an artifact from the registry.
|
|
389
|
+
|
|
390
|
+
Args:
|
|
391
|
+
id: Artifact ID to delete
|
|
392
|
+
"""
|
|
393
|
+
conn = get_db()
|
|
394
|
+
row = conn.execute("SELECT canonical_name FROM artifact_registry WHERE id = ?", (id,)).fetchone()
|
|
395
|
+
if not row:
|
|
396
|
+
return f"ERROR: Artifact #{id} not found."
|
|
397
|
+
name = row["canonical_name"]
|
|
398
|
+
conn.execute("DELETE FROM artifact_aliases WHERE artifact_id = ?", (id,))
|
|
399
|
+
conn.execute("DELETE FROM artifact_registry WHERE id = ?", (id,))
|
|
400
|
+
conn.commit()
|
|
401
|
+
return f"Artifact #{id} ({name}) deleted."
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def _format_results(results, method, query):
|
|
405
|
+
"""Format search results for display."""
|
|
406
|
+
lines = [f"ARTIFACTS FOUND ({len(results)}, via {method} for '{query}'):"]
|
|
407
|
+
for r in results:
|
|
408
|
+
aliases_str = ""
|
|
409
|
+
try:
|
|
410
|
+
aliases = json.loads(r.get("aliases", "[]"))
|
|
411
|
+
if aliases:
|
|
412
|
+
aliases_str = f" aka [{', '.join(aliases[:4])}]"
|
|
413
|
+
except (json.JSONDecodeError, TypeError):
|
|
414
|
+
pass
|
|
415
|
+
uri_str = f" → {r['uri']}" if r.get("uri") else ""
|
|
416
|
+
cmd_str = f"\n Run: {r['run_cmd']}" if r.get("run_cmd") else ""
|
|
417
|
+
paths_str = ""
|
|
418
|
+
try:
|
|
419
|
+
paths = json.loads(r.get("paths", "[]"))
|
|
420
|
+
if paths:
|
|
421
|
+
paths_str = f"\n Paths: {', '.join(paths[:3])}"
|
|
422
|
+
except (json.JSONDecodeError, TypeError):
|
|
423
|
+
pass
|
|
424
|
+
touched = r.get("last_touched_at", "")[:16]
|
|
425
|
+
lines.append(
|
|
426
|
+
f" #{r['id']} [{r['kind']}] {r['canonical_name']}{aliases_str}{uri_str} "
|
|
427
|
+
f"({r['state']}, {touched}){cmd_str}{paths_str}"
|
|
428
|
+
)
|
|
429
|
+
return "\n".join(lines)
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
# Plugin registration — TOOLS array consumed by plugin_loader.py
|
|
433
|
+
TOOLS = [
|
|
434
|
+
(handle_artifact_create, "nexo_artifact_create",
|
|
435
|
+
"Register a new artifact (service, dashboard, script, API, etc.) in the Artifact Registry. "
|
|
436
|
+
"Call this whenever NEXO creates, deploys, or discovers a runnable/accessible artifact."),
|
|
437
|
+
(handle_artifact_find, "nexo_artifact_find",
|
|
438
|
+
"Find artifacts using the retrieval ladder: exact alias → port/path → fuzzy token → recent. "
|
|
439
|
+
"PRIMARY retrieval tool for when users reference something built/deployed. Handles natural "
|
|
440
|
+
"language like 'the backend', 'that script', 'localhost something'."),
|
|
441
|
+
(handle_artifact_update, "nexo_artifact_update",
|
|
442
|
+
"Update an existing artifact. Only non-empty fields are changed."),
|
|
443
|
+
(handle_artifact_learn_alias, "nexo_artifact_learn_alias",
|
|
444
|
+
"Learn a new alias from user language. Call when the user refers to an artifact with "
|
|
445
|
+
"an unregistered term (e.g., 'backend' for the NEXO Brain Dashboard)."),
|
|
446
|
+
(handle_artifact_list, "nexo_artifact_list",
|
|
447
|
+
"List all registered artifacts, optionally filtered by kind, state, or recency."),
|
|
448
|
+
(handle_artifact_delete, "nexo_artifact_delete",
|
|
449
|
+
"Delete an artifact from the registry."),
|
|
450
|
+
]
|
|
@@ -27,7 +27,7 @@ def handle_decision_log(domain: str, decision: str, alternatives: str = '',
|
|
|
27
27
|
"""Log a non-trivial decision with reasoning context.
|
|
28
28
|
|
|
29
29
|
Args:
|
|
30
|
-
domain: Area (ads, shopify, server, wazion, nexo,
|
|
30
|
+
domain: Area (ads, shopify, server, wazion, nexo, project, other)
|
|
31
31
|
decision: What was decided
|
|
32
32
|
alternatives: JSON array or text of options considered and why discarded
|
|
33
33
|
based_on: Data, metrics, or observations that informed this decision
|
|
@@ -35,7 +35,7 @@ def handle_decision_log(domain: str, decision: str, alternatives: str = '',
|
|
|
35
35
|
context_ref: Related followup/reminder ID (e.g., NF-ADS1, R71)
|
|
36
36
|
session_id: Current session ID (auto-filled if empty)
|
|
37
37
|
"""
|
|
38
|
-
valid_domains = {'ads', 'shopify', 'server', 'wazion', 'nexo', '
|
|
38
|
+
valid_domains = {'ads', 'shopify', 'server', 'wazion', 'nexo', 'project', 'other'}
|
|
39
39
|
if domain not in valid_domains:
|
|
40
40
|
return f"ERROR: domain debe ser uno de: {', '.join(sorted(valid_domains))}"
|
|
41
41
|
if confidence not in ('high', 'medium', 'low'):
|
|
@@ -92,10 +92,10 @@ def handle_decision_search(query: str = '', domain: str = '', days: int = 30) ->
|
|
|
92
92
|
|
|
93
93
|
Args:
|
|
94
94
|
query: Text to search in decision, alternatives, based_on, outcome
|
|
95
|
-
domain: Filter by area (ads, shopify, server, wazion, nexo,
|
|
95
|
+
domain: Filter by area (ads, shopify, server, wazion, nexo, project, other)
|
|
96
96
|
days: Look back N days (default 30)
|
|
97
97
|
"""
|
|
98
|
-
valid_domains = {'ads', 'shopify', 'server', 'wazion', 'nexo', '
|
|
98
|
+
valid_domains = {'ads', 'shopify', 'server', 'wazion', 'nexo', 'project', 'other'}
|
|
99
99
|
if domain and domain not in valid_domains:
|
|
100
100
|
return f"ERROR: domain debe ser uno de: {', '.join(sorted(valid_domains))}"
|
|
101
101
|
results = search_decisions(query, domain, days)
|
|
@@ -235,7 +235,7 @@ def handle_session_diary_read(session_id: str = '', last_n: int = 3, last_day: b
|
|
|
235
235
|
session_id: Specific session ID to read (optional)
|
|
236
236
|
last_n: Number of recent entries to return (default 3)
|
|
237
237
|
last_day: If true, returns ALL entries from the most recent day (multi-terminal aware). Use this at startup.
|
|
238
|
-
domain: Filter by project context:
|
|
238
|
+
domain: Filter by project context: project-a, project-b, nexo, project-c, server, other
|
|
239
239
|
"""
|
|
240
240
|
results = read_session_diary(session_id, last_n, last_day, domain)
|
|
241
241
|
if not results:
|
package/src/tools_menu.py
CHANGED
|
@@ -39,8 +39,8 @@ MENU_ITEMS = [
|
|
|
39
39
|
("6", "Cambiar Promocion Shopify"),
|
|
40
40
|
]),
|
|
41
41
|
("Servidor e Infraestructura", [
|
|
42
|
-
("2", "Servidor - Chequeo
|
|
43
|
-
("3", "WhatsApp Logs -
|
|
42
|
+
("2", "Servidor - Chequeo server health check"),
|
|
43
|
+
("3", "WhatsApp Logs - Review WhatsApp logs"),
|
|
44
44
|
("11", "File Tracker - Reporte archivos PHP"),
|
|
45
45
|
("12", "Google Cloud - Gasto, consumo y estado GCP"),
|
|
46
46
|
]),
|