File size: 6,459 Bytes
72c7148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
--- a/src/mac_laya/assistant.py
+++ b/src/mac_laya/assistant.py
@@ -349,28 +349,25 @@
             effect_scope=str(TOOL_OWNERS[action["tool"]].validate(action["tool"],arguments,self.context(goal)))
         return effect_scope
 
-    def decide_step(self,goal,observation,action):
-        """MacJev's execute/inspect/ask decision with the observation shrunk to fit its 4096-token input."""
-        from .model import InputBudgetError
-        question={"t":"choice","ins":"Choose the next step that best advances the original user goal with the available information.",
-                  "crit":{"execute":"Execute the proposed registered action after deterministic scope and precondition checks",
-                          "inspect":"Inspect the explicitly named app window or approved directory for more information before acting",
-                          "ask":"Ask the user to resolve missing information or ambiguity"}}
-        history=observation.get("previous_results",[])
-        variants=[observation,{**observation,"previous_results":history[-2:]},{**observation,"previous_results":history[-1:]},
-                  {k:v for k,v in {**observation,"previous_results":history[-1:]}.items() if k not in {"open_sessions","window_app_aliases","registered_app_ids"}}]
-        for variant in variants:
-            try:return self.engine.decide({"user_goal":goal,"observation":variant,"proposed_action":action},question)
-            except InputBudgetError:continue
-        return None
+    def decide_step(self,goal,observation,action,history=None):
+        """MacJev's execute/inspect/ask decision on the shared scope-relative view (macjev.mac.view).
 
+        The full history is sent within a ~20K-token budget with explicit truncation markers (smaller
+        budgets are tried on an input-budget error; nothing is cut silently), the static app registry is
+        replaced by the apps the goal/action/history name, and every call is logged to runs/macjev/gate_log/.
+        """
+        from macjev.mac import runtime_adapter
+        if history is not None:
+            observation={**observation,"previous_results":runtime_adapter.stamped(history)}
+        return runtime_adapter.gate_call(self.engine,goal,observation,action)
+
     def fast_path(self,goal,asr):
         """Single-step commands: deterministic parse + one MacJev decision, no 8B planner."""
         from .fast_lane import decide as fast_decide
         from .inference import DecisionEngine
         if self.engine is None:self.engine=DecisionEngine()
         scope=Path(self.scope)
-        listing=sorted(p.name for p in scope.iterdir())[:200] if scope.is_dir() else []
+        listing=FileScope(scope).execute("list_files",{"directory":str(scope)}) if scope.is_dir() else {"directory":str(scope),"entries":[],"truncated":False}
         fast=fast_decide(goal,scope,self.engine,listing)
         if fast is None:return None
         if "needs_user" in fast:
@@ -393,7 +390,9 @@
         if self.fast_lane and start_step==0 and not history:
             fast=self.fast_path(goal,asr)
             if fast is not None:return fast
+        from macjev.mac import runtime_adapter
         for step in range(start_step,self.max_steps):
+            runtime_adapter.stamped(history)  # record receipt times now (before the planner's seconds-long call)
             observation={"approved_scope":str(self.scope),"registered_app_ids":sorted(set(APPS.values())),
                          "window_app_aliases":WINDOW_APPS,"previous_results":history[-4:]}
             sessions=self.session_summary(goal)
@@ -411,7 +410,7 @@
             if action["tool"] not in {"ask_user","done"}:
                 from .inference import DecisionEngine
                 if self.engine is None:self.engine=DecisionEngine()
-                decision=self.decide_step(goal,observation,action)
+                decision=self.decide_step(goal,observation,action,history)
                 if decision is None:
                     return {"goal":goal,"asr":asr,"history":history,"needs_user":"The current observation is too large for the local decision model; please narrow the request."}
                 if decision["answer"]!="execute" and decision["top_probability"]<DECISION_BLOCK_THRESHOLD:
@@ -461,6 +460,10 @@
             history.append({"action":action,"result":result})
             if "needs_user" in result:return {"goal":goal,"asr":asr,"history":history,"needs_user":result["needs_user"]}
             if action["tool"]=="done":
+                # Shadow question (logged only; never ends or blocks a task).
+                if self.engine is not None:
+                    from macjev.mac import runtime_adapter
+                    runtime_adapter.goal_done_shadow(self.engine,goal,{**observation,"previous_results":runtime_adapter.stamped(history[:-1])},action)
                 return {"goal":goal,"asr":asr,"history":history,"status":"planner_finished_with_observable_results","not_an_independent_whole_goal_success_claim":True}
         return {"goal":goal,"asr":asr,"history":history,"needs_user":f"Reached the {self.max_steps}-step bound; inspect the verified results before continuing."}
 
--- a/src/mac_laya/fast_lane.py
+++ b/src/mac_laya/fast_lane.py
@@ -172,9 +172,12 @@
         return None
     candidate, _, _, absolute = runnable[0]
     action = {"tool": candidate["tool"], "arguments": absolute, "reason": "fast lane: " + describe(candidate)}
+    result = listing if isinstance(listing, dict) else {"entries": listing}
     observation = {"approved_scope": str(scope), "previous_results": [
-        {"action": {"tool": "list_files", "arguments": {"directory": str(scope)}}, "result": {"entries": listing}}]}
-    decision = engine.decide({"user_goal": goal, "observation": observation, "proposed_action": action}, STEP_QUESTION)
-    if decision["answer"] != "execute" or decision["top_probability"] < MIN_CONFIDENCE:
+        {"action": {"tool": "list_files", "arguments": {"directory": str(scope)}}, "result": result}]}
+    # Same scope-relative view, question and gate log as the planner loop (macjev.mac.runtime_adapter).
+    from macjev.mac import runtime_adapter
+    decision = runtime_adapter.gate_call(engine, goal, observation, action)
+    if decision is None or decision["answer"] != "execute" or decision["top_probability"] < MIN_CONFIDENCE:
         return None
     return {"action": action, "decision": decision, "fast_lane": True}