ltcai 9.9.5 → 10.0.0
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 +39 -37
- package/docs/CHANGELOG.md +234 -0
- package/docs/COMMUNITY_AND_PLUGINS.md +1 -1
- package/docs/DEVELOPMENT.md +1 -1
- package/docs/ONBOARDING.md +1 -1
- package/docs/OPERATIONS.md +3 -1
- package/docs/PERMISSION_MODE.md +107 -0
- package/docs/SURFACE_PARITY.md +38 -8
- package/docs/TRUST_MODEL.md +1 -1
- package/docs/WHY_LATTICE.md +1 -1
- package/docs/kg-schema.md +1 -1
- package/lattice_brain/__init__.py +1 -1
- package/lattice_brain/context.py +39 -4
- package/lattice_brain/graph/_kg_common.py +189 -14
- package/lattice_brain/graph/curator.py +62 -0
- package/lattice_brain/graph/discovery.py +76 -0
- package/lattice_brain/graph/ingest.py +37 -7
- package/lattice_brain/graph/retrieval_vector.py +10 -0
- package/lattice_brain/ingestion.py +9 -106
- package/lattice_brain/ingestion_jobs.py +133 -0
- package/lattice_brain/runtime/multi_agent.py +1 -1
- package/latticeai/__init__.py +1 -1
- package/latticeai/api/brain_intelligence.py +8 -0
- package/latticeai/api/chat.py +9 -0
- package/latticeai/api/chat_agent_http.py +119 -2
- package/latticeai/api/chat_contracts.py +9 -0
- package/latticeai/api/chat_documents.py +16 -0
- package/latticeai/api/evidence_actions.py +48 -0
- package/latticeai/api/permission_mode.py +61 -0
- package/latticeai/api/project_sessions.py +112 -0
- package/latticeai/api/voice_capture.py +89 -0
- package/latticeai/app_factory.py +53 -0
- package/latticeai/core/agent.py +381 -43
- package/latticeai/core/agent_permission.py +160 -0
- package/latticeai/core/agent_profiles.py +110 -0
- package/latticeai/core/artifact_ledger.py +109 -0
- package/latticeai/core/context_builder.py +101 -2
- package/latticeai/core/legacy_compatibility.py +1 -1
- package/latticeai/core/marketplace.py +1 -1
- package/latticeai/core/permission_mode.py +296 -0
- package/latticeai/core/project_sessions.py +337 -0
- package/latticeai/core/run_explain.py +421 -0
- package/latticeai/core/run_store.py +5 -0
- package/latticeai/core/workspace_os.py +15 -80
- package/latticeai/core/workspace_review_items.py +107 -0
- package/latticeai/integrations/telegram_bot.py +188 -0
- package/latticeai/runtime/chat_wiring.py +8 -0
- package/latticeai/runtime/context_runtime.py +11 -0
- package/latticeai/runtime/permission_mode_wiring.py +116 -0
- package/latticeai/runtime/router_registration.py +9 -0
- package/latticeai/services/app_context.py +3 -0
- package/latticeai/services/architecture_readiness.py +1 -1
- package/latticeai/services/brain_intelligence.py +105 -0
- package/latticeai/services/evidence_actions.py +254 -0
- package/latticeai/services/funnel_metrics.py +111 -16
- package/latticeai/services/local_knowledge.py +26 -0
- package/latticeai/services/memory_service.py +12 -0
- package/latticeai/services/permission_mode_service.py +170 -0
- package/latticeai/services/product_readiness.py +1 -1
- package/latticeai/services/tool_dispatch.py +73 -4
- package/latticeai/services/voice_capture.py +189 -0
- package/package.json +6 -4
- package/scripts/check_bundle_budget.mjs +11 -0
- package/scripts/check_current_release_docs.mjs +1 -1
- package/scripts/check_i18n_namespace_coverage.mjs +148 -0
- package/skills/meeting_notes/SKILL.md +82 -0
- package/skills/meeting_notes/examples.md +41 -0
- package/skills/meeting_notes/risk.json +9 -0
- package/skills/meeting_notes/schema.json +55 -0
- package/skills/weekly_review/SKILL.md +75 -0
- package/skills/weekly_review/examples.md +39 -0
- package/skills/weekly_review/risk.json +9 -0
- package/skills/weekly_review/schema.json +55 -0
- package/src-tauri/Cargo.lock +1 -1
- package/src-tauri/Cargo.toml +1 -1
- package/src-tauri/tauri.conf.json +1 -1
- package/static/app/asset-manifest.json +37 -29
- package/static/app/assets/Act-BtCREeN1.js +1 -0
- package/static/app/assets/AdminConsole-TPeeN18T.js +1 -0
- package/static/app/assets/Brain-BKs6JAp0.js +321 -0
- package/static/app/assets/BrainHome-BPGOvSd6.js +2 -0
- package/static/app/assets/BrainSignals-CtzQZ15J.js +1 -0
- package/static/app/assets/Capture-1_NaHWqB.js +1 -0
- package/static/app/assets/CommandPalette-pqvQOXe4.js +1 -0
- package/static/app/assets/Library-DhvoPvC7.js +1 -0
- package/static/app/assets/{LivingBrain-BVWk58MW.js → LivingBrain-DlQ20Q75.js} +1 -1
- package/static/app/assets/ProductFlow-BZvGDRi_.js +1 -0
- package/static/app/assets/ReviewCard-BWgI0D2s.js +3 -0
- package/static/app/assets/System-CSMdYLMy.js +1 -0
- package/static/app/assets/activity-Dlfk8YC7.js +1 -0
- package/static/app/assets/{bot-VmP0kkeA.js → bot-CDvUB76P.js} +1 -1
- package/static/app/assets/brain-xczrohrt.js +1 -0
- package/static/app/assets/button-SOdH3Oyf.js +1 -0
- package/static/app/assets/{circle-pause-T9POo4qy.js → circle-pause-CG1ythH4.js} +1 -1
- package/static/app/assets/{circle-play-Bz5iTD0p.js → circle-play-HXwvjS6W.js} +1 -1
- package/static/app/assets/{cpu-CJhjRtNq.js → cpu-B0d-rGyk.js} +1 -1
- package/static/app/assets/download-BGIkTQL6.js +1 -0
- package/static/app/assets/{folder-open-B2K_22VI.js → folder-open-Dst_Z0_K.js} +1 -1
- package/static/app/assets/{hard-drive-CjJtYqHf.js → hard-drive-D53MsWkV.js} +1 -1
- package/static/app/assets/index-C_IrlQMV.js +10 -0
- package/static/app/assets/index-FxDusbr0.css +2 -0
- package/static/app/assets/{input-CSi6OBJ9.js → input-C5m0riF6.js} +1 -1
- package/static/app/assets/{network-Ck1nqc-v.js → network-C5a-E5iS.js} +1 -1
- package/static/app/assets/primitives-vNXYf58F.js +1 -0
- package/static/app/assets/search-DhbSgW6m.js +1 -0
- package/static/app/assets/shield-alert-Cc-WVXqN.js +1 -0
- package/static/app/assets/{textarea-C4wM0D-Z.js → textarea-BkZ0EqVO.js} +1 -1
- package/static/app/assets/{useFocusTrap-CsnIhsDJ.js → useFocusTrap-CTtKbAOU.js} +1 -1
- package/static/app/assets/{navigation-BPQqEQwr.js → useQuery-Dx1fi4Wu.js} +1 -1
- package/static/app/assets/users-BFpQXtEF.js +1 -0
- package/static/app/assets/utils-BA_lmW3J.js +7 -0
- package/static/app/assets/workspace-DBPB0jkX.js +1 -0
- package/static/app/index.html +4 -4
- package/static/sw.js +1 -1
- package/static/app/assets/Act-DmxfbqBp.js +0 -1
- package/static/app/assets/Brain-DK_zKCda.js +0 -321
- package/static/app/assets/BrainHome-CCE_0hni.js +0 -2
- package/static/app/assets/BrainSignals-r_J68_zh.js +0 -1
- package/static/app/assets/Capture-CvxwzpJZ.js +0 -1
- package/static/app/assets/CommandPalette-CVLiFIQC.js +0 -1
- package/static/app/assets/Library-4As9VUvy.js +0 -1
- package/static/app/assets/ProductFlow-B-Tz0Um4.js +0 -1
- package/static/app/assets/ReviewCard-Va3fPQuj.js +0 -3
- package/static/app/assets/System-DSR2zKWd.js +0 -1
- package/static/app/assets/index-7FAfYm4v.css +0 -2
- package/static/app/assets/index-CEu0Wqjl.js +0 -10
- package/static/app/assets/primitives-B2f9N7Dh.js +0 -1
- package/static/app/assets/shield-alert-yA_Y8lOB.js +0 -1
- package/static/app/assets/utils-BqoznzGP.js +0 -7
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
"""Plain-language explanation of an agent run's outcome (v9.9.6).
|
|
2
|
+
|
|
3
|
+
The loop already records *what* happened — :class:`~latticeai.core.agent_trace.LoopTrace`
|
|
4
|
+
counters, the transcript, the terminal state. What it never produced was a
|
|
5
|
+
sentence a person can read: why a run ended as ``NEEDS_REVIEW`` rather than
|
|
6
|
+
``DONE``, or how much the model struggled with the tool-call format before it
|
|
7
|
+
got there. Weak local models (Gemma-class) routinely need three format
|
|
8
|
+
repairs and one correction hint to finish a task that a large model does in
|
|
9
|
+
one pass; the counters showed that, the UI did not.
|
|
10
|
+
|
|
11
|
+
This module turns the machine-readable signals into one honest, deterministic
|
|
12
|
+
summary::
|
|
13
|
+
|
|
14
|
+
{"code": "no_evidence",
|
|
15
|
+
"headline": {"ko": "...", "en": "..."},
|
|
16
|
+
"details": [{"ko": "...", "en": "..."}],
|
|
17
|
+
"model_strain": {"level": "moderate", "parse_errors": 2, ...}}
|
|
18
|
+
|
|
19
|
+
Rules the rest of the system relies on:
|
|
20
|
+
|
|
21
|
+
* **Deterministic.** No model call, no clock, no I/O — the same run always
|
|
22
|
+
explains the same way, so tests and the eval harness can assert on it.
|
|
23
|
+
* **Honest.** It never upgrades an outcome. A ``NEEDS_REVIEW`` explanation
|
|
24
|
+
says the result was not verified; it never reads as a soft success.
|
|
25
|
+
* **Advisory.** Building an explanation must never fail a run — callers get a
|
|
26
|
+
minimal payload rather than an exception.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
from typing import Any, Dict, List, Mapping, Optional, Sequence
|
|
32
|
+
|
|
33
|
+
__all__ = ["explain_run", "STRAIN_LEVELS"]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
STRAIN_LEVELS = ("none", "light", "moderate", "heavy")
|
|
37
|
+
|
|
38
|
+
# Repair names produced by ``extract_action_details`` / the artifact pipeline,
|
|
39
|
+
# grouped so the explanation says what the model got wrong, not which internal
|
|
40
|
+
# tolerance fired.
|
|
41
|
+
_REPAIR_GROUPS: Dict[str, tuple] = {
|
|
42
|
+
"format": ("fence", "slice", "think_strip", "trailing_comma", "python_literal"),
|
|
43
|
+
"plan": (
|
|
44
|
+
"plan_not_object",
|
|
45
|
+
"goal_defaulted",
|
|
46
|
+
"steps_filtered",
|
|
47
|
+
"estimated_steps_invalid",
|
|
48
|
+
"manifest_steps",
|
|
49
|
+
"manifest_rewrite",
|
|
50
|
+
"heuristic_file_step",
|
|
51
|
+
),
|
|
52
|
+
"artifact": ("artifact_sanitize", "artifact_repair"),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _phrase(ko: str, en: str) -> Dict[str, str]:
|
|
57
|
+
return {"ko": ko, "en": en}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _int(value: Any) -> int:
|
|
61
|
+
try:
|
|
62
|
+
return max(0, int(value))
|
|
63
|
+
except (TypeError, ValueError):
|
|
64
|
+
return 0
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _steps(transcript: Any) -> List[Mapping[str, Any]]:
|
|
68
|
+
if not isinstance(transcript, Sequence) or isinstance(transcript, (str, bytes)):
|
|
69
|
+
return []
|
|
70
|
+
return [step for step in transcript if isinstance(step, Mapping)]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _last_verdict(steps: Sequence[Mapping[str, Any]]) -> Optional[Mapping[str, Any]]:
|
|
74
|
+
for step in reversed(steps):
|
|
75
|
+
if step.get("state") == "VERIFYING":
|
|
76
|
+
return step
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _repaired_artifacts(steps: Sequence[Mapping[str, Any]]) -> List[str]:
|
|
81
|
+
"""Paths whose content the artifact pipeline had to repair into a scaffold."""
|
|
82
|
+
paths: List[str] = []
|
|
83
|
+
for step in steps:
|
|
84
|
+
meta = step.get("content_sanitize")
|
|
85
|
+
if not isinstance(meta, Mapping) or not meta.get("repaired"):
|
|
86
|
+
continue
|
|
87
|
+
result = step.get("result") if isinstance(step.get("result"), Mapping) else {}
|
|
88
|
+
args = step.get("args") if isinstance(step.get("args"), Mapping) else {}
|
|
89
|
+
path = result.get("path") or args.get("path")
|
|
90
|
+
if path and str(path) not in paths:
|
|
91
|
+
paths.append(str(path))
|
|
92
|
+
return paths
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _blocked_actions(steps: Sequence[Mapping[str, Any]]) -> List[str]:
|
|
96
|
+
blocked: List[str] = []
|
|
97
|
+
for step in steps:
|
|
98
|
+
error = str(step.get("error") or "")
|
|
99
|
+
if error.startswith("BLOCKED:") and step.get("action"):
|
|
100
|
+
name = str(step["action"])
|
|
101
|
+
if name not in blocked:
|
|
102
|
+
blocked.append(name)
|
|
103
|
+
return blocked
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _proposed_count(steps: Sequence[Mapping[str, Any]]) -> int:
|
|
107
|
+
return sum(
|
|
108
|
+
1
|
|
109
|
+
for step in steps
|
|
110
|
+
if isinstance(step.get("result"), Mapping) and step["result"].get("proposed")
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _repair_totals(loop: Mapping[str, Any]) -> Dict[str, int]:
|
|
115
|
+
repairs = loop.get("repairs")
|
|
116
|
+
repairs = repairs if isinstance(repairs, Mapping) else {}
|
|
117
|
+
totals = {group: 0 for group in _REPAIR_GROUPS}
|
|
118
|
+
totals["other"] = 0
|
|
119
|
+
for name, count in repairs.items():
|
|
120
|
+
amount = _int(count)
|
|
121
|
+
for group, members in _REPAIR_GROUPS.items():
|
|
122
|
+
if name in members:
|
|
123
|
+
totals[group] += amount
|
|
124
|
+
break
|
|
125
|
+
else:
|
|
126
|
+
totals["other"] += amount
|
|
127
|
+
return totals
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _strain_level(score: int) -> str:
|
|
131
|
+
if score <= 0:
|
|
132
|
+
return "none"
|
|
133
|
+
if score <= 2:
|
|
134
|
+
return "light"
|
|
135
|
+
if score <= 5:
|
|
136
|
+
return "moderate"
|
|
137
|
+
return "heavy"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _missing_files(steps: Sequence[Mapping[str, Any]]) -> List[str]:
|
|
141
|
+
"""Requested files the run never wrote (from the coverage check)."""
|
|
142
|
+
for step in reversed(steps):
|
|
143
|
+
coverage = step.get("requirement_coverage")
|
|
144
|
+
if isinstance(coverage, Mapping):
|
|
145
|
+
missing = coverage.get("missing_files")
|
|
146
|
+
if isinstance(missing, Sequence) and not isinstance(missing, (str, bytes)):
|
|
147
|
+
return [str(path) for path in missing if path]
|
|
148
|
+
return []
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _outcome(state: str, steps: Sequence[Mapping[str, Any]]) -> str:
|
|
152
|
+
"""Terminal-state reason code — the *why*, not just the state name."""
|
|
153
|
+
verdict_step = _last_verdict(steps)
|
|
154
|
+
if state == "DONE":
|
|
155
|
+
return "done"
|
|
156
|
+
if state == "NEEDS_REVIEW":
|
|
157
|
+
if _missing_files(steps):
|
|
158
|
+
return "missing_files"
|
|
159
|
+
if verdict_step is None:
|
|
160
|
+
return "needs_review"
|
|
161
|
+
if verdict_step.get("verdict") == "UNAVAILABLE":
|
|
162
|
+
return "verifier_unavailable"
|
|
163
|
+
if verdict_step.get("verdict") == "PASS" and not verdict_step.get("evidence"):
|
|
164
|
+
return "no_evidence"
|
|
165
|
+
if verdict_step.get("next_state") == "DONE":
|
|
166
|
+
return "inconsistent_verdict"
|
|
167
|
+
return "needs_review"
|
|
168
|
+
if state == "FAILED":
|
|
169
|
+
if any(step.get("state") == "ROLLBACK" for step in steps):
|
|
170
|
+
return "rolled_back"
|
|
171
|
+
for step in steps:
|
|
172
|
+
if step.get("state") == "WAITING_APPROVAL" and (
|
|
173
|
+
step.get("decision") == "blocked_pending_approval"
|
|
174
|
+
):
|
|
175
|
+
return "approval_required"
|
|
176
|
+
if verdict_step is not None and verdict_step.get("next_state") == "EXECUTING":
|
|
177
|
+
return "retry_budget"
|
|
178
|
+
return "failed"
|
|
179
|
+
return "unknown"
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
_HEADLINES: Dict[str, Dict[str, str]] = {
|
|
183
|
+
"done": _phrase(
|
|
184
|
+
"요청한 작업을 끝냈고 검증도 통과했습니다.",
|
|
185
|
+
"The task finished and passed verification.",
|
|
186
|
+
),
|
|
187
|
+
"verifier_unavailable": _phrase(
|
|
188
|
+
"작업은 실행됐지만 검증 모델의 답을 읽지 못해 '완료'로 처리하지 않았습니다.",
|
|
189
|
+
"The work ran, but the reviewing model's answer could not be read, so it was not marked complete.",
|
|
190
|
+
),
|
|
191
|
+
"no_evidence": _phrase(
|
|
192
|
+
"검증자는 통과라고 했지만 실제로 실행된 기록이 없어 '완료'로 처리하지 않았습니다.",
|
|
193
|
+
"The reviewer said PASS but there is no record of anything actually running, so it was not marked complete.",
|
|
194
|
+
),
|
|
195
|
+
"inconsistent_verdict": _phrase(
|
|
196
|
+
"검증 결과가 앞뒤가 맞지 않아 '완료'로 처리하지 않았습니다.",
|
|
197
|
+
"The verification verdict contradicted itself, so it was not marked complete.",
|
|
198
|
+
),
|
|
199
|
+
"missing_files": _phrase(
|
|
200
|
+
"요청한 파일 중 일부가 만들어지지 않아 '완료'로 처리하지 않았습니다.",
|
|
201
|
+
"Some requested files were never written, so it was not marked complete.",
|
|
202
|
+
),
|
|
203
|
+
"needs_review": _phrase(
|
|
204
|
+
"작업은 끝났지만 완료를 확인하지 못했습니다. 결과를 직접 확인해 주세요.",
|
|
205
|
+
"The run ended but completion could not be confirmed — please check the result yourself.",
|
|
206
|
+
),
|
|
207
|
+
"rolled_back": _phrase(
|
|
208
|
+
"실행이 실패해서 바꾼 파일을 되돌렸습니다.",
|
|
209
|
+
"Execution failed, so the changed files were rolled back.",
|
|
210
|
+
),
|
|
211
|
+
"approval_required": _phrase(
|
|
212
|
+
"승인이 필요한 도구가 있어 실행을 시작하지 못했습니다.",
|
|
213
|
+
"The run never started because it needed approval for a gated tool.",
|
|
214
|
+
),
|
|
215
|
+
"retry_budget": _phrase(
|
|
216
|
+
"검증자가 계속 다시 하라고 해서 재시도 한도까지 갔고, 끝내 완료하지 못했습니다.",
|
|
217
|
+
"The reviewer kept asking for another attempt until the retry budget ran out.",
|
|
218
|
+
),
|
|
219
|
+
"failed": _phrase(
|
|
220
|
+
"작업을 끝내지 못했습니다.",
|
|
221
|
+
"The task did not complete.",
|
|
222
|
+
),
|
|
223
|
+
"unknown": _phrase(
|
|
224
|
+
"실행 상태를 확인하지 못했습니다.",
|
|
225
|
+
"The run state could not be determined.",
|
|
226
|
+
),
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
_STRAIN_PHRASES: Dict[str, Dict[str, str]] = {
|
|
231
|
+
"light": _phrase(
|
|
232
|
+
"이 모델은 형식을 살짝 헷갈려 했지만 자동으로 정리했습니다.",
|
|
233
|
+
"The model slipped on the reply format once or twice; it was cleaned up automatically.",
|
|
234
|
+
),
|
|
235
|
+
"moderate": _phrase(
|
|
236
|
+
"이 모델은 형식을 자주 틀려서 자동 보정이 여러 번 필요했습니다. 더 큰 모델을 쓰면 결과가 안정적입니다.",
|
|
237
|
+
"The model needed several automatic format repairs. A larger model would be steadier.",
|
|
238
|
+
),
|
|
239
|
+
"heavy": _phrase(
|
|
240
|
+
"이 모델에게는 이 작업이 버거웠습니다 — 형식 오류와 보정이 많았습니다. 더 큰 모델로 다시 시도하는 것을 권합니다.",
|
|
241
|
+
"This task strained the model — many format errors and repairs. Consider retrying with a larger model.",
|
|
242
|
+
),
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def explain_run(
|
|
247
|
+
*,
|
|
248
|
+
state: Any,
|
|
249
|
+
loop: Optional[Mapping[str, Any]] = None,
|
|
250
|
+
transcript: Any = None,
|
|
251
|
+
max_retry: Optional[int] = None,
|
|
252
|
+
) -> Dict[str, Any]:
|
|
253
|
+
"""Explain one finished agent run in plain language.
|
|
254
|
+
|
|
255
|
+
``state`` is the terminal :class:`~latticeai.core.agent.AgentState` value
|
|
256
|
+
(or its ``.value`` string), ``loop`` a :meth:`LoopTrace.summary` payload,
|
|
257
|
+
``transcript`` the run transcript. Every argument is optional-tolerant:
|
|
258
|
+
a partial run still produces a usable payload rather than raising.
|
|
259
|
+
"""
|
|
260
|
+
state_name = str(getattr(state, "value", state) or "").upper()
|
|
261
|
+
loop = loop if isinstance(loop, Mapping) else {}
|
|
262
|
+
steps = _steps(transcript)
|
|
263
|
+
|
|
264
|
+
code = _outcome(state_name, steps)
|
|
265
|
+
parse_errors = _int(loop.get("parse_errors"))
|
|
266
|
+
parse_recovered = _int(loop.get("parse_recovered"))
|
|
267
|
+
corrections = _int(loop.get("corrections"))
|
|
268
|
+
retries = _int(loop.get("retries"))
|
|
269
|
+
repair_totals = _repair_totals(loop)
|
|
270
|
+
repair_sum = sum(repair_totals.values())
|
|
271
|
+
|
|
272
|
+
strain_score = parse_errors * 2 + corrections + retries + repair_totals["format"]
|
|
273
|
+
strain = {
|
|
274
|
+
"level": _strain_level(strain_score),
|
|
275
|
+
"score": strain_score,
|
|
276
|
+
"parse_errors": parse_errors,
|
|
277
|
+
"parse_recovered": parse_recovered,
|
|
278
|
+
"corrections": corrections,
|
|
279
|
+
"retries": retries,
|
|
280
|
+
"repairs": repair_totals,
|
|
281
|
+
"repair_total": repair_sum,
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
details: List[Dict[str, str]] = []
|
|
285
|
+
if parse_errors:
|
|
286
|
+
details.append(_phrase(
|
|
287
|
+
f"모델이 정해진 형식을 {parse_errors}번 벗어났고, 그중 {parse_recovered}번은 자동으로 복구했습니다.",
|
|
288
|
+
f"The model broke the required reply format {parse_errors} time(s); "
|
|
289
|
+
f"{parse_recovered} of those were recovered automatically.",
|
|
290
|
+
))
|
|
291
|
+
if repair_totals["format"]:
|
|
292
|
+
details.append(_phrase(
|
|
293
|
+
f"모델 응답을 {repair_totals['format']}번 자동으로 다듬어 읽었습니다 (코드블록·따옴표 정리 등).",
|
|
294
|
+
f"The model's reply needed {repair_totals['format']} automatic clean-up(s) "
|
|
295
|
+
"(code fences, quoting, stray text).",
|
|
296
|
+
))
|
|
297
|
+
if repair_totals["plan"]:
|
|
298
|
+
details.append(_phrase(
|
|
299
|
+
f"계획이 비어 있거나 요청한 파일을 빠뜨려서 {repair_totals['plan']}번 자동으로 보완했습니다.",
|
|
300
|
+
f"The plan was empty or missed requested files and was repaired {repair_totals['plan']} time(s).",
|
|
301
|
+
))
|
|
302
|
+
repaired_paths = _repaired_artifacts(steps)
|
|
303
|
+
if repaired_paths:
|
|
304
|
+
details.append(_phrase(
|
|
305
|
+
"다음 파일은 모델 출력이 온전하지 않아 기본 뼈대로 대신 저장했습니다 — 내용을 꼭 확인하세요: "
|
|
306
|
+
+ ", ".join(repaired_paths[:4]),
|
|
307
|
+
"These files were saved as a generated scaffold because the model output was "
|
|
308
|
+
"not usable — check them: " + ", ".join(repaired_paths[:4]),
|
|
309
|
+
))
|
|
310
|
+
if retries:
|
|
311
|
+
details.append(_phrase(
|
|
312
|
+
f"검증자가 {retries}번 다시 하라고 요청했습니다.",
|
|
313
|
+
f"The reviewer asked for another attempt {retries} time(s).",
|
|
314
|
+
))
|
|
315
|
+
proposed = _proposed_count(steps)
|
|
316
|
+
if proposed:
|
|
317
|
+
details.append(_phrase(
|
|
318
|
+
f"기존 내용을 바꾸는 작업 {proposed}건은 바로 적용하지 않고 변경 제안으로 저장했습니다. 검토함에서 승인하면 적용됩니다.",
|
|
319
|
+
f"{proposed} change(s) to existing content were staged as review proposals "
|
|
320
|
+
"instead of applied — approve them in the review center.",
|
|
321
|
+
))
|
|
322
|
+
blocked = _blocked_actions(steps)
|
|
323
|
+
if blocked:
|
|
324
|
+
details.append(_phrase(
|
|
325
|
+
"다음 도구는 정책상 막혀서 실행하지 않았습니다: " + ", ".join(blocked[:4]),
|
|
326
|
+
"These tools were blocked by policy and did not run: " + ", ".join(blocked[:4]),
|
|
327
|
+
))
|
|
328
|
+
if code == "retry_budget" and max_retry:
|
|
329
|
+
details.append(_phrase(
|
|
330
|
+
f"재시도 한도({max_retry}회)에 도달했습니다.",
|
|
331
|
+
f"The retry budget ({max_retry}) was exhausted.",
|
|
332
|
+
))
|
|
333
|
+
missing_files = _missing_files(steps)
|
|
334
|
+
if missing_files:
|
|
335
|
+
details.append(_phrase(
|
|
336
|
+
"만들어지지 않은 파일: " + ", ".join(missing_files[:4]),
|
|
337
|
+
"Files that were never written: " + ", ".join(missing_files[:4]),
|
|
338
|
+
))
|
|
339
|
+
strain_phrase = _STRAIN_PHRASES.get(strain["level"])
|
|
340
|
+
if strain_phrase is not None:
|
|
341
|
+
details.append(dict(strain_phrase))
|
|
342
|
+
|
|
343
|
+
return {
|
|
344
|
+
"code": code,
|
|
345
|
+
"state": state_name,
|
|
346
|
+
"ok": code == "done",
|
|
347
|
+
"headline": dict(_HEADLINES.get(code, _HEADLINES["unknown"])),
|
|
348
|
+
"details": details,
|
|
349
|
+
"model_strain": strain,
|
|
350
|
+
# Failure-learning surface (review 루프 §3): a structured "what to do
|
|
351
|
+
# differently", carried into the next plan by the project session
|
|
352
|
+
# instead of being lost with the run.
|
|
353
|
+
"next_step": _next_step(
|
|
354
|
+
code, missing_files=missing_files, blocked=blocked, strain=strain
|
|
355
|
+
),
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
_NEXT_STEPS: Dict[str, Dict[str, str]] = {
|
|
360
|
+
"verifier_unavailable": _phrase(
|
|
361
|
+
"검증 모델을 더 큰 모델로 바꾸거나, 결과를 직접 확인한 뒤 다시 실행하세요.",
|
|
362
|
+
"Switch the reviewing model to a larger one, or check the result yourself and re-run.",
|
|
363
|
+
),
|
|
364
|
+
"no_evidence": _phrase(
|
|
365
|
+
"요청을 더 구체적으로 (무엇을 어디에 만들지) 적어 다시 실행하세요.",
|
|
366
|
+
"Re-run with a more concrete request — what to build and where.",
|
|
367
|
+
),
|
|
368
|
+
"inconsistent_verdict": _phrase(
|
|
369
|
+
"결과를 확인한 뒤, 남은 부분만 다시 요청하세요.",
|
|
370
|
+
"Check the result, then re-request only what is still missing.",
|
|
371
|
+
),
|
|
372
|
+
"approval_required": _phrase(
|
|
373
|
+
"승인 흐름으로 다시 실행하거나, 승인이 필요 없는 범위로 요청을 줄이세요.",
|
|
374
|
+
"Re-run through the approval flow, or narrow the request to steps that need no approval.",
|
|
375
|
+
),
|
|
376
|
+
"rolled_back": _phrase(
|
|
377
|
+
"실패 원인을 확인한 뒤, 더 작은 단위로 나눠 다시 요청하세요.",
|
|
378
|
+
"Check what failed, then re-request in smaller steps.",
|
|
379
|
+
),
|
|
380
|
+
"retry_budget": _phrase(
|
|
381
|
+
"요청을 더 작은 단계로 나누거나 더 큰 모델로 다시 시도하세요.",
|
|
382
|
+
"Split the request into smaller steps, or retry with a larger model.",
|
|
383
|
+
),
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def _next_step(
|
|
388
|
+
code: str,
|
|
389
|
+
*,
|
|
390
|
+
missing_files: Sequence[str],
|
|
391
|
+
blocked: Sequence[str],
|
|
392
|
+
strain: Mapping[str, Any],
|
|
393
|
+
) -> Optional[Dict[str, str]]:
|
|
394
|
+
"""One concrete "do this next", or None when the run needs nothing.
|
|
395
|
+
|
|
396
|
+
Specific evidence beats a generic template: a named missing file or a
|
|
397
|
+
blocked tool says more than "try again".
|
|
398
|
+
"""
|
|
399
|
+
if code == "done" and str(strain.get("level")) in ("none", "light"):
|
|
400
|
+
return None
|
|
401
|
+
if missing_files:
|
|
402
|
+
names = ", ".join(list(missing_files)[:4])
|
|
403
|
+
return _phrase(
|
|
404
|
+
f"다음 파일만 다시 만들어 달라고 요청하세요: {names}",
|
|
405
|
+
f"Ask again for just these files: {names}",
|
|
406
|
+
)
|
|
407
|
+
if blocked:
|
|
408
|
+
names = ", ".join(list(blocked)[:3])
|
|
409
|
+
return _phrase(
|
|
410
|
+
f"막힌 도구({names}) 없이 할 수 있는 범위로 요청을 바꾸거나, 승인 후 다시 실행하세요.",
|
|
411
|
+
f"Rephrase the request to avoid the blocked tools ({names}), or approve them and re-run.",
|
|
412
|
+
)
|
|
413
|
+
specific = _NEXT_STEPS.get(code)
|
|
414
|
+
if specific is not None:
|
|
415
|
+
return dict(specific)
|
|
416
|
+
if str(strain.get("level")) == "heavy":
|
|
417
|
+
return _phrase(
|
|
418
|
+
"더 큰 모델로 다시 시도하면 성공률이 올라갑니다.",
|
|
419
|
+
"Retrying with a larger model will raise the success rate.",
|
|
420
|
+
)
|
|
421
|
+
return None
|
|
@@ -60,6 +60,9 @@ def serialize_run_context(ctx: AgentRunContext) -> Dict[str, Any]:
|
|
|
60
60
|
"executing_model": ctx.executing_model,
|
|
61
61
|
"reviewing_model": ctx.reviewing_model,
|
|
62
62
|
"approved_by_human": ctx.approved_by_human,
|
|
63
|
+
# A paused run resumes under the dial it was planned and approved with,
|
|
64
|
+
# not whatever the preference happens to be at resume time.
|
|
65
|
+
"permission_mode": ctx.permission_mode,
|
|
63
66
|
"trace": {"events": ctx.trace.events, "truncated": ctx.trace.truncated},
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -81,6 +84,8 @@ def restore_run_context(payload: Dict[str, Any]) -> AgentRunContext:
|
|
|
81
84
|
ctx.executing_model = payload.get("executing_model")
|
|
82
85
|
ctx.reviewing_model = payload.get("reviewing_model")
|
|
83
86
|
ctx.approved_by_human = bool(payload.get("approved_by_human"))
|
|
87
|
+
stored_mode = payload.get("permission_mode")
|
|
88
|
+
ctx.permission_mode = str(stored_mode) if stored_mode else None
|
|
84
89
|
trace_payload = payload.get("trace") or {}
|
|
85
90
|
trace = LoopTrace()
|
|
86
91
|
trace.events = list(trace_payload.get("events") or [])
|
|
@@ -31,6 +31,7 @@ from .workspace_plugins import WorkspacePluginManager
|
|
|
31
31
|
from .workspace_memory import WorkspaceMemory
|
|
32
32
|
from .workspace_snapshots import WorkspaceSnapshots
|
|
33
33
|
from .workspace_graph_trace import WorkspaceGraphTrace
|
|
34
|
+
from .workspace_review_items import WorkspaceReviewItems
|
|
34
35
|
from .workspace_runs import WorkspaceRuns
|
|
35
36
|
from .workspace_skills import WorkspaceSkills
|
|
36
37
|
|
|
@@ -49,7 +50,7 @@ __all__ = [
|
|
|
49
50
|
"remove_skill_directory",
|
|
50
51
|
]
|
|
51
52
|
|
|
52
|
-
WORKSPACE_OS_VERSION = "
|
|
53
|
+
WORKSPACE_OS_VERSION = "10.0.0"
|
|
53
54
|
|
|
54
55
|
# Workspace types separate single-user Personal workspaces from shared
|
|
55
56
|
# Organization workspaces. Both keep the same local-first JSON store; the type
|
|
@@ -189,6 +190,7 @@ class WorkspaceOSStore:
|
|
|
189
190
|
self.snapshots = WorkspaceSnapshots(self)
|
|
190
191
|
self.graph_trace = WorkspaceGraphTrace(self)
|
|
191
192
|
self.runs = WorkspaceRuns(self)
|
|
193
|
+
self.review_items = WorkspaceReviewItems(self)
|
|
192
194
|
self.skills = WorkspaceSkills(self)
|
|
193
195
|
|
|
194
196
|
def _connect_state_db(self) -> sqlite3.Connection:
|
|
@@ -1125,88 +1127,21 @@ class WorkspaceOSStore:
|
|
|
1125
1127
|
return self.runs.record_workflow_event(*args, **kwargs)
|
|
1126
1128
|
|
|
1127
1129
|
# ── review queue (5.6.0) ─────────────────────────────────────────────
|
|
1128
|
-
# Workspace-scoped suggestion inbox.
|
|
1129
|
-
#
|
|
1130
|
-
#
|
|
1130
|
+
# Workspace-scoped suggestion inbox. Persistence moved to
|
|
1131
|
+
# ``workspace_review_items.WorkspaceReviewItems`` (v9.9.6); the transition
|
|
1132
|
+
# policy still lives in ReviewQueueService (services/review_queue.py).
|
|
1131
1133
|
|
|
1132
|
-
def create_review_item(
|
|
1133
|
-
self,
|
|
1134
|
-
*,
|
|
1135
|
-
title: str,
|
|
1136
|
-
summary: str = "",
|
|
1137
|
-
source: str = "workflow_run",
|
|
1138
|
-
kind: str = "suggestion",
|
|
1139
|
-
payload: Optional[Dict[str, Any]] = None,
|
|
1140
|
-
provenance: Optional[Dict[str, Any]] = None,
|
|
1141
|
-
user_email: Optional[str] = None,
|
|
1142
|
-
workspace_id: Optional[str] = None,
|
|
1143
|
-
) -> Dict[str, Any]:
|
|
1144
|
-
if not str(title or "").strip():
|
|
1145
|
-
raise ValueError("title is required")
|
|
1146
|
-
state = self.load_state()
|
|
1147
|
-
resolved_workspace = self._resolve_scope(workspace_id, state)
|
|
1148
|
-
now = _now()
|
|
1149
|
-
item = {
|
|
1150
|
-
"id": f"review-{_json_hash([title, source, kind, user_email, now])[:16]}",
|
|
1151
|
-
"status": "pending",
|
|
1152
|
-
"title": title,
|
|
1153
|
-
"summary": summary or "",
|
|
1154
|
-
"source": source or "workflow_run",
|
|
1155
|
-
"kind": kind or "suggestion",
|
|
1156
|
-
"payload": dict(payload or {}),
|
|
1157
|
-
"provenance": dict(provenance or {}),
|
|
1158
|
-
"snoozed_until": None,
|
|
1159
|
-
"user_email": user_email,
|
|
1160
|
-
"workspace_id": resolved_workspace,
|
|
1161
|
-
"created_at": now,
|
|
1162
|
-
"updated_at": now,
|
|
1163
|
-
}
|
|
1164
|
-
state.setdefault("review_items", []).append(item)
|
|
1165
|
-
self.save_state(state)
|
|
1166
|
-
self.record_timeline_event(
|
|
1167
|
-
"review", "review_item_created",
|
|
1168
|
-
{"item_id": item["id"], "source": item["source"], "kind": item["kind"]},
|
|
1169
|
-
workspace_id=resolved_workspace,
|
|
1170
|
-
)
|
|
1171
|
-
return item
|
|
1134
|
+
def create_review_item(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
|
1135
|
+
return self.review_items.create_review_item(*args, **kwargs)
|
|
1172
1136
|
|
|
1173
|
-
def list_review_items(
|
|
1174
|
-
self,
|
|
1175
|
-
source: Optional[str] = None,
|
|
1176
|
-
) -> List[Dict[str, Any]]:
|
|
1177
|
-
items = self._scoped(_listify(self.load_state().get("review_items")), workspace_id)
|
|
1178
|
-
if user_email:
|
|
1179
|
-
items = [item for item in items if item.get("user_email") in {None, user_email}]
|
|
1180
|
-
if source:
|
|
1181
|
-
items = [item for item in items if item.get("source") == source]
|
|
1182
|
-
return list(reversed(items))
|
|
1183
|
-
|
|
1184
|
-
def get_review_item(self, item_id: str, *, workspace_id: Optional[str] = None) -> Dict[str, Any]:
|
|
1185
|
-
item = next(
|
|
1186
|
-
(it for it in _listify(self.load_state().get("review_items")) if it.get("id") == item_id),
|
|
1187
|
-
None,
|
|
1188
|
-
)
|
|
1189
|
-
if item is None or (workspace_id and self._record_workspace(item) != str(workspace_id)):
|
|
1190
|
-
raise FileNotFoundError(item_id)
|
|
1191
|
-
return item
|
|
1137
|
+
def list_review_items(self, *args: Any, **kwargs: Any) -> List[Dict[str, Any]]:
|
|
1138
|
+
return self.review_items.list_review_items(*args, **kwargs)
|
|
1192
1139
|
|
|
1193
|
-
def
|
|
1194
|
-
self,
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
if item is None or (workspace_id and self._record_workspace(item) != str(workspace_id)):
|
|
1199
|
-
raise FileNotFoundError(item_id)
|
|
1200
|
-
for key, value in fields.items():
|
|
1201
|
-
item[key] = value
|
|
1202
|
-
item["updated_at"] = _now()
|
|
1203
|
-
self.save_state(state)
|
|
1204
|
-
self.record_timeline_event(
|
|
1205
|
-
"review", "review_item_updated",
|
|
1206
|
-
{"item_id": item_id, "status": item.get("status")},
|
|
1207
|
-
workspace_id=self._record_workspace(item),
|
|
1208
|
-
)
|
|
1209
|
-
return item
|
|
1140
|
+
def get_review_item(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
|
1141
|
+
return self.review_items.get_review_item(*args, **kwargs)
|
|
1142
|
+
|
|
1143
|
+
def update_review_item(self, *args: Any, **kwargs: Any) -> Dict[str, Any]:
|
|
1144
|
+
return self.review_items.update_review_item(*args, **kwargs)
|
|
1210
1145
|
|
|
1211
1146
|
# ------------------------------------------------------------------
|
|
1212
1147
|
# Relationship explorer
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Review-queue persistence extracted from WorkspaceOSStore (v9.9.6).
|
|
2
|
+
|
|
3
|
+
Workspace-scoped suggestion inbox: automation/trigger runs write drafts here
|
|
4
|
+
for the user to approve/dismiss/snooze. **Persistence only** — the transition
|
|
5
|
+
policy lives in :mod:`latticeai.services.review_queue`.
|
|
6
|
+
|
|
7
|
+
Behaviour-preserving move (review 2026-07-27 P2 #8 "대형 모듈 추가 분해 —
|
|
8
|
+
동작 보존 이동 우선"): the store delegates the same method names to this
|
|
9
|
+
collaborator, following the existing ``WorkspaceRuns`` / ``WorkspaceGraphTrace``
|
|
10
|
+
pattern.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from typing import Any, Dict, List, Optional
|
|
15
|
+
|
|
16
|
+
from .timeutil import now_iso as _now
|
|
17
|
+
from .workspace_os_utils import _json_hash, _listify
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class WorkspaceReviewItems:
|
|
21
|
+
def __init__(self, store: Any):
|
|
22
|
+
self._store = store
|
|
23
|
+
|
|
24
|
+
def __getattr__(self, name: str) -> Any:
|
|
25
|
+
return getattr(self._store, name)
|
|
26
|
+
|
|
27
|
+
def create_review_item(
|
|
28
|
+
self,
|
|
29
|
+
*,
|
|
30
|
+
title: str,
|
|
31
|
+
summary: str = "",
|
|
32
|
+
source: str = "workflow_run",
|
|
33
|
+
kind: str = "suggestion",
|
|
34
|
+
payload: Optional[Dict[str, Any]] = None,
|
|
35
|
+
provenance: Optional[Dict[str, Any]] = None,
|
|
36
|
+
user_email: Optional[str] = None,
|
|
37
|
+
workspace_id: Optional[str] = None,
|
|
38
|
+
) -> Dict[str, Any]:
|
|
39
|
+
if not str(title or "").strip():
|
|
40
|
+
raise ValueError("title is required")
|
|
41
|
+
state = self.load_state()
|
|
42
|
+
resolved_workspace = self._resolve_scope(workspace_id, state)
|
|
43
|
+
now = _now()
|
|
44
|
+
item = {
|
|
45
|
+
"id": f"review-{_json_hash([title, source, kind, user_email, now])[:16]}",
|
|
46
|
+
"status": "pending",
|
|
47
|
+
"title": title,
|
|
48
|
+
"summary": summary or "",
|
|
49
|
+
"source": source or "workflow_run",
|
|
50
|
+
"kind": kind or "suggestion",
|
|
51
|
+
"payload": dict(payload or {}),
|
|
52
|
+
"provenance": dict(provenance or {}),
|
|
53
|
+
"snoozed_until": None,
|
|
54
|
+
"user_email": user_email,
|
|
55
|
+
"workspace_id": resolved_workspace,
|
|
56
|
+
"created_at": now,
|
|
57
|
+
"updated_at": now,
|
|
58
|
+
}
|
|
59
|
+
state.setdefault("review_items", []).append(item)
|
|
60
|
+
self.save_state(state)
|
|
61
|
+
self.record_timeline_event(
|
|
62
|
+
"review", "review_item_created",
|
|
63
|
+
{"item_id": item["id"], "source": item["source"], "kind": item["kind"]},
|
|
64
|
+
workspace_id=resolved_workspace,
|
|
65
|
+
)
|
|
66
|
+
return item
|
|
67
|
+
|
|
68
|
+
def list_review_items(
|
|
69
|
+
self, *, workspace_id: Optional[str] = None, user_email: Optional[str] = None,
|
|
70
|
+
source: Optional[str] = None,
|
|
71
|
+
) -> List[Dict[str, Any]]:
|
|
72
|
+
items = self._scoped(_listify(self.load_state().get("review_items")), workspace_id)
|
|
73
|
+
if user_email:
|
|
74
|
+
items = [item for item in items if item.get("user_email") in {None, user_email}]
|
|
75
|
+
if source:
|
|
76
|
+
items = [item for item in items if item.get("source") == source]
|
|
77
|
+
return list(reversed(items))
|
|
78
|
+
|
|
79
|
+
def get_review_item(self, item_id: str, *, workspace_id: Optional[str] = None) -> Dict[str, Any]:
|
|
80
|
+
item = next(
|
|
81
|
+
(it for it in _listify(self.load_state().get("review_items")) if it.get("id") == item_id),
|
|
82
|
+
None,
|
|
83
|
+
)
|
|
84
|
+
if item is None or (workspace_id and self._record_workspace(item) != str(workspace_id)):
|
|
85
|
+
raise FileNotFoundError(item_id)
|
|
86
|
+
return item
|
|
87
|
+
|
|
88
|
+
def update_review_item(
|
|
89
|
+
self, item_id: str, *, workspace_id: Optional[str] = None, **fields: Any,
|
|
90
|
+
) -> Dict[str, Any]:
|
|
91
|
+
state = self.load_state()
|
|
92
|
+
item = next((it for it in _listify(state.get("review_items")) if it.get("id") == item_id), None)
|
|
93
|
+
if item is None or (workspace_id and self._record_workspace(item) != str(workspace_id)):
|
|
94
|
+
raise FileNotFoundError(item_id)
|
|
95
|
+
for key, value in fields.items():
|
|
96
|
+
item[key] = value
|
|
97
|
+
item["updated_at"] = _now()
|
|
98
|
+
self.save_state(state)
|
|
99
|
+
self.record_timeline_event(
|
|
100
|
+
"review", "review_item_updated",
|
|
101
|
+
{"item_id": item_id, "status": item.get("status")},
|
|
102
|
+
workspace_id=self._record_workspace(item),
|
|
103
|
+
)
|
|
104
|
+
return item
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
__all__ = ["WorkspaceReviewItems"]
|