feat(cognitive): implement real-time cognitive sensing, menu navigation, and single-task lock
This commit is contained in:
+74
-4
@@ -26,6 +26,11 @@ import hashlib
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
import agent_cognitive_probe as acp
|
||||
except ImportError:
|
||||
acp = None
|
||||
|
||||
# Color helpers
|
||||
USE_COLOR = sys.stdout.isatty() or os.environ.get("CLICOLOR_FORCE") == "1"
|
||||
|
||||
@@ -495,7 +500,7 @@ def cmd_status(args):
|
||||
uname = assignee.get("username")
|
||||
agent_active_issues[uname] = iss
|
||||
|
||||
headers = f"{'AGENT':<12} {'ROLE':<13} {'PORT':<6} {'TUNNEL':<8} {'SIGNAL':<10} {'ACTIVE WORK / ASSIGNMENT':<38} {'LAST CHAT'}"
|
||||
headers = f"{'AGENT':<10} {'ROLE':<12} {'PORT':<6} {'TUNNEL':<7} {'COGNITIVE':<15} {'ACTIVE WORK / ASSIGNMENT':<38} {'LAST CHAT'}"
|
||||
print(c_dim(headers))
|
||||
print(c_dim("-" * len(headers)))
|
||||
|
||||
@@ -512,6 +517,15 @@ def cmd_status(args):
|
||||
active_task = claimed_tasks.get(name)
|
||||
active_issue = agent_active_issues.get(name)
|
||||
|
||||
# Live cognitive probe
|
||||
cog_badge = "-"
|
||||
if acp and name != "muse-main":
|
||||
cog = acp.get_passive_cognitive_state(name)
|
||||
cog_status = cog.get("status", "DARK")
|
||||
cog_badge = acp.format_cognitive_badge(cog_status)
|
||||
elif name == "muse-main":
|
||||
cog_badge = c_dim("HOST")
|
||||
|
||||
if active_issue:
|
||||
num = active_issue.get("number")
|
||||
title = active_issue.get("title", "")[:32]
|
||||
@@ -542,7 +556,7 @@ def cmd_status(args):
|
||||
else:
|
||||
chat_str = c_dim("-")
|
||||
|
||||
print(f"{c_bold(name):<21} {role:<13} {port:<6} {tunnel_str:<17} {signal:<19} {work_desc:<38} {chat_str}")
|
||||
print(f"{c_bold(name):<19} {role:<12} {port:<6} {tunnel_str:<16} {cog_badge:<24} {work_desc:<38} {chat_str}")
|
||||
|
||||
print()
|
||||
|
||||
@@ -644,7 +658,17 @@ def cmd_start(args):
|
||||
agent = args.agent
|
||||
body = args.goal or f"Work task for {agent}: {title}"
|
||||
|
||||
# 0. Pre-flight health gate: Hatch, Restore, Git Config with Auto-Heal
|
||||
# 0a. Real-time Cognitive Sensing & Single-Task Lock Gate
|
||||
if acp and not getattr(args, "force", False):
|
||||
cog = acp.get_passive_cognitive_state(agent)
|
||||
if cog.get("cognitive_lock"):
|
||||
print(c_red(f"\n[COGNITIVE LOCK BLOCKED] Agent '{agent}' cannot receive new work right now ({cog['status']}):"))
|
||||
print(f" • Reason: {cog.get('lock_reason')}")
|
||||
print(c_yellow("\nCloud agents have single-threaded thought processes and get interrupted by concurrent tasks."))
|
||||
print(c_dim(f"To inspect active thoughts/menu: box work menu {agent}\nTo bypass lock: box work start '{title}' --to {agent} --force\n"))
|
||||
sys.exit(1)
|
||||
|
||||
# 0b. Pre-flight health gate: Hatch, Restore, Git Config with Auto-Heal
|
||||
preflight = check_agent_preflight(agent)
|
||||
if not preflight["ready"] and not getattr(args, "force", False):
|
||||
if getattr(args, "no_heal", False):
|
||||
@@ -734,7 +758,17 @@ def cmd_assign(args):
|
||||
issue_num = args.issue
|
||||
agent = args.agent
|
||||
|
||||
# 0. Pre-flight health gate: Hatch, Restore, Git Config with Auto-Heal
|
||||
# 0a. Real-time Cognitive Sensing & Single-Task Lock Gate
|
||||
if acp and not getattr(args, "force", False):
|
||||
cog = acp.get_passive_cognitive_state(agent)
|
||||
if cog.get("cognitive_lock"):
|
||||
print(c_red(f"\n[COGNITIVE LOCK BLOCKED] Agent '{agent}' cannot receive new work right now ({cog['status']}):"))
|
||||
print(f" • Reason: {cog.get('lock_reason')}")
|
||||
print(c_yellow("\nCloud agents have single-threaded thought processes and get interrupted by concurrent tasks."))
|
||||
print(c_dim(f"To inspect active thoughts/menu: box work menu {agent}\nTo bypass lock: box work assign {issue_num} --to {agent} --force\n"))
|
||||
sys.exit(1)
|
||||
|
||||
# 0b. Pre-flight health gate: Hatch, Restore, Git Config with Auto-Heal
|
||||
preflight = check_agent_preflight(agent)
|
||||
if not preflight["ready"] and not getattr(args, "force", False):
|
||||
if getattr(args, "no_heal", False):
|
||||
@@ -817,9 +851,23 @@ def cmd_chats(args):
|
||||
print(f"[{c_cyan(ag)} : {c_dim(tname)}] {c_dim(ts)} {c_bold(author)}:\n{text}\n" + c_dim("-" * 60))
|
||||
print()
|
||||
|
||||
def cmd_menu(args):
|
||||
if not acp:
|
||||
print(c_red("Error: agent_cognitive_probe module not found."))
|
||||
sys.exit(1)
|
||||
acp.cmd_menu(args)
|
||||
|
||||
def cmd_cognitive(args):
|
||||
if not acp:
|
||||
print(c_red("Error: agent_cognitive_probe module not found."))
|
||||
sys.exit(1)
|
||||
acp.cmd_status(args)
|
||||
|
||||
WORK_COMMAND_EXAMPLES = {
|
||||
"box work": [
|
||||
"box work # View fleet workspace dashboard & signals",
|
||||
"box work cognitive [agent...] # Live zero-click cognitive sensor probe across fleet",
|
||||
"box work menu <agent> [tab] # Inspect agent profile menu (tasks, timers, approvals)",
|
||||
"box work check [agent] # Audit pre-flight health gates",
|
||||
"box work heal <agent> # Automated remediation & chat nudge",
|
||||
"box work start \"<title>\" --to <agent> # Start & dispatch new build ticket",
|
||||
@@ -827,6 +875,15 @@ WORK_COMMAND_EXAMPLES = {
|
||||
"box work merge <pr#> # Verify tests and merge PR to master",
|
||||
"box work chats --agent <name> # View live multi-agent chat feed",
|
||||
],
|
||||
"box work menu": [
|
||||
"box work menu muse upcoming # Inspect timers & recurring cron loops",
|
||||
"box work menu 646 activity # Inspect recent tasks & active processes",
|
||||
"box work menu pip all # Dump all tabs (activity, upcoming, approvals)",
|
||||
],
|
||||
"box work cognitive": [
|
||||
"box work cognitive # Live cognitive sensor probe for all agents",
|
||||
"box work cognitive pip # Check if pip is generating / thinking",
|
||||
],
|
||||
"box work start": [
|
||||
"box work start \"Fix SSH perms\" --to 646",
|
||||
"box work start \"Build integration tests\" --to pip --goal \"Run pytest on endpoints\"",
|
||||
@@ -960,6 +1017,15 @@ def main():
|
||||
p_chats.add_argument("--agent", help="Filter by agent name")
|
||||
p_chats.add_argument("--limit", type=int, default=10, help="Number of messages to show")
|
||||
|
||||
p_menu = sub.add_parser("menu", help="Navigate agent profile menu (tasks, timers, approvals, identity)")
|
||||
p_menu.add_argument("agent", help="Agent username (muse, pip, 646, opm, dev, def)")
|
||||
p_menu.add_argument("tab", nargs="?", default="activity", choices=["activity", "upcoming", "approvals", "identity", "all"], help="Menu tab to view")
|
||||
p_menu.add_argument("--json", action="store_true", help="Output JSON")
|
||||
|
||||
p_cog = sub.add_parser("cognitive", help="Probe real-time cognitive sensor (thinking, generating, sidechats)")
|
||||
p_cog.add_argument("agents", nargs="*", help="Optional agent usernames")
|
||||
p_cog.add_argument("--json", action="store_true", help="Output JSON")
|
||||
|
||||
args = parser.parse_args()
|
||||
action = args.work_action
|
||||
|
||||
@@ -977,6 +1043,10 @@ def main():
|
||||
cmd_merge(args)
|
||||
elif action == "chats":
|
||||
cmd_chats(args)
|
||||
elif action == "menu":
|
||||
cmd_menu(args)
|
||||
elif action == "cognitive":
|
||||
cmd_cognitive(args)
|
||||
else:
|
||||
parser.print_help()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user