|
Download src/macjev/mac/RUNTIME_PATCH.md from VTN-TokenFactory/Telasap-0.8B-v1.0: direct link, hf CLI and curl.
- Browser
- Download file 12 kB
-
https://huggingface.co/VTN-TokenFactory/Telasap-0.8B-v1.0/resolve/main/src/macjev/mac/RUNTIME_PATCH.md
- Command line
-
hf download hf://VTN-TokenFactory/Telasap-0.8B-v1.0/src/macjev/mac/RUNTIME_PATCH.md
-
curl -L -o RUNTIME_PATCH.md https://huggingface.co/VTN-TokenFactory/Telasap-0.8B-v1.0/resolve/main/src/macjev/mac/RUNTIME_PATCH.md
12 kB
| # Runtime patch: route the Mac gate through `macjev.mac.runtime_adapter` | |
| Status: **proposed, not applied**. `src/mac_laya/**` belongs to the runtime/system-acceptance work stream | |
| and was not edited by the mac_gate package. Apply only while system acceptance is paused. | |
| Base (re-read 2026-09-23 22:50, after the runtime's 22:16 / 22:31 / 22:46 edits; gate contract unchanged): | |
| - `src/mac_laya/assistant.py` sha256 `99d5f1b7530336fa1fba4647f675f222404ecdf51210639641546cee91e3636f` | |
| - `src/mac_laya/fast_lane.py` sha256 `a4e1cd0cd72bee62cc7f6a338397ec72d8f9069ce1eb70cb82f7cf527e40135c` | |
| The runtime keeps changing: run `patch --dry-run` right before applying; if it rejects, re-create the edits | |
| listed below by hand. The same diff is stored as a plain file: `src/macjev/mac/RUNTIME_PATCH.diff`. | |
| cd /Users/jason/Desktop/mac-laya | |
| patch -p1 --dry-run < src/macjev/mac/RUNTIME_PATCH.diff # must apply without rejects | |
| patch -p1 < src/macjev/mac/RUNTIME_PATCH.diff | |
| PYTHONPATH=src .venv/bin/python -m pytest tests/macjev/mac -q | |
| ## What changes (and why) | |
| | Plan item (section 4.4, runtime sync) | Where | | |
| |---|---| | |
| | One scope-relative view shared by training and runtime (replaces the round-1 `model_view` basename collapse) | `decide_step` calls `runtime_adapter.gate_call`, which builds the state with `macjev.mac.view.gate_state`, the exact function `macjev.builders.mac_gate` uses for every train/dev/test row | | |
| | Same view for the fast lane | `fast_lane.decide` also calls `runtime_adapter.gate_call` (it used to send absolute paths, no registry and 200 bare names). `Assistant.fast_path` now passes a `FileScope` `list_files` result (files / folders / symlinks / `truncated`, first 100 entries) instead of `sorted(names)[:200]`, which cut a big folder silently and never said so; the training data only has FileScope-shaped listings | | |
| | History budget ~20K tokens (gate.HISTORY_TOKEN_BUDGET; 25,600-token input contract since 2026-09-24) with explicit truncation markers, no silent cut | the full `history` is passed (not `history[-4:]`); the view halves the longest strings/lists with `…[gate view truncated this text: k of n characters shown]` / `…[gate view: n more items not shown]` markers, drops the oldest results last and records `previous_results_omitted`; on an engine input-budget error it retries at 12000/6000/3000/1500/600 tokens and logs each failure; `None` (ask the user to narrow the request) only if 600 does not fit | | |
| | Drop the ~330-token static registry from the gate state | `registered_app_ids` / `window_app_aliases` list only the apps named by the goal, the proposed action or the visible history (an unregistered bundle therefore shows up as absent from `registered_app_ids`) | | |
| | Snapshot ages | `runtime_adapter.stamped(history)` is called at the START of every planning step (before the seconds-long planner call), so each result's receipt time is recorded when the loop gets it; the view shows `age_s`, so a >120 s window snapshot is visible to the model. (The previous version stamped entries only at the next gate call, which under-stated every age by one planner latency.) The runtime's dicts and the planner's input are untouched | | |
| | Log every gate call | `runs/macjev/gate_log/YYYY-MM-DD.jsonl`, one line per call: state, question, answer, probabilities, budget, view stats, latency | | |
| | Shadow question "goal satisfied?" (noul) | when the planner proposes `done`, `runtime_adapter.goal_done_shadow` asks `macjev.mac.gate.GOAL_DONE_QUESTION` on the same view and logs the answer; the return value is ignored, so it never ends or blocks a task | | |
| Unchanged: the planner's observation (still `history[-4:]` plus the full registry), the low-confidence | |
| override (`DECISION_BLOCK_THRESHOLD`), the `decide(state, question)` engine interface and the confirmation | |
| flow. `DecisionEngine` (Laya 4K) works as is (the 20K budget fails over to 12K, 6K and 3K); the new MLX engine only needs | |
| `decide(state, question)` and, for exact token counting, a HF `tokenizer` attribute. | |
| Known runtime-side gaps this patch does NOT close (see the mac_gate manifest `open_issues`): | |
| - `observation["open_sessions"]`: simulated since mac_gate-v3 (browser page sessions with the current snapshot and | |
| controls; LibreOffice / Obsidian / opened-file / UI summaries as label-neutral distractors) and read by oracle v3 | |
| (a browser tool with no open session of its browser is `ask`, like `runtime_browser._session`). The UNPATCHED | |
| runtime's last budget fallback still drops `open_sessions`; the patched view never does. | |
| - The planner is told to return only `tool` and `arguments` (optional `think`, dropped by the view); the data | |
| therefore carries a `reason` in only ~15% of rows. Fast-lane actions carry `"reason": "fast lane: ..."`. | |
| - An "inspect" on a source hidden by a truncated (>100 entries) listing makes the runtime list the scope again, | |
| which shows the same first 100 entries: the planner has to read the file directly or the step bound ends it. | |
| ## Gate contract pinned by the data | |
| `macjev.mac.gate.runtime_contract()` re-parses `assistant.py` (no import) and returns the question literal in | |
| `decide_step`, the observation keys built in `plan` and the optional keys added later (`open_sessions`); the | |
| data manifests store its sha256s (question `22d647ecb1d3c39ca93bd793ff81ff9be50d8540aac1ea41088fc98da13bca2a`). | |
| After this patch the literal lives only in `macjev.mac.gate.GATE_QUESTION` (byte-identical text) and | |
| `runtime_contract()` reports `question_source="macjev.mac.gate (via runtime_adapter)"`. | |
| ## Unified diff | |
| ```diff | |
| --- 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} | |
| ``` | |