memindex 1.4.5 → 1.5.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.qoder-plugin/plugin.json +1 -1
- package/README.md +8 -2
- package/dist/bug-report/index.js +94 -83
- package/dist/npx-cli/index.js +300 -299
- package/dist/opencode-plugin/index.js +40 -40
- package/dist/pi-extension/TYPEBOX-PROVENANCE.json +4 -4
- package/dist/pi-extension/index.js +9 -9
- package/integrations/dsh/lib/index.js +19 -19
- package/integrations/dsh/package.json +1 -1
- package/integrations/openclaw/install.sh +16 -10
- package/integrations/openclaw/openclaw.plugin.json +1 -5
- package/integrations/openclaw/test-install.sh +20 -13
- package/integrations/pi/TYPEBOX-PROVENANCE.json +4 -4
- package/package.json +5 -5
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.qoder-plugin/plugin.json +1 -1
- package/plugin/hooks/codex-hooks.json +12 -0
- package/plugin/package.json +1 -1
- package/plugin/scripts/context-generator.cjs +65 -63
- package/plugin/scripts/context-generator.cjs.map +3 -3
- package/plugin/scripts/mcp-server.cjs +71 -70
- package/plugin/scripts/mcp-server.cjs.map +3 -3
- package/plugin/scripts/statusline.cjs +1 -1
- package/plugin/scripts/transcript-watcher.cjs +36 -35
- package/plugin/scripts/transcript-watcher.cjs.map +3 -3
- package/plugin/scripts/worker-service.cjs +714 -674
- package/plugin/scripts/worker-service.cjs.map +3 -3
- package/plugin/skills/cloud-sync/SKILL.md +5 -5
- package/plugin/skills/distill/SKILL.md +22 -0
- package/plugin/skills/how-it-works/SKILL.md +1 -1
- package/plugin/skills/how-it-works/onboarding-explainer.md +1 -1
- package/plugin/skills/import-chats/SKILL.md +22 -0
- package/plugin/skills/import-jira/SKILL.md +22 -0
- package/plugin/skills/import-reviews/SKILL.md +22 -0
- package/plugin/skills/mode-creator/SKILL.md +7 -1
- package/plugin/skills/pin/SKILL.md +26 -0
- package/plugin/skills/savings/SKILL.md +22 -0
- package/plugin/skills/timeline-report/SKILL.md +8 -8
- package/plugin/skills/weekly-digests/SKILL.md +5 -5
- package/plugin/skills/worker-request.mjs +45 -0
- package/plugin/sqlite/SessionStore.js +109 -109
- package/plugin/sqlite/SessionStore.js.map +3 -3
- package/plugin/sqlite/observations/files.js +12 -9
- package/plugin/sqlite/observations/files.js.map +3 -3
- package/plugin/ui/viewer-bundle.js +18 -18
- package/integrations/openclaw/skills/agent-cost-report/CHECKSUMS.txt +0 -50
- package/integrations/openclaw/skills/agent-cost-report/SKILL.md +0 -241
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/__init__.py +0 -1
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/behavior.py +0 -303
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/classify.py +0 -83
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/costs.py +0 -119
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/devices.py +0 -88
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/evidence.py +0 -160
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/labels.py +0 -115
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/measure.py +0 -89
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/mistakes.py +0 -310
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/patterns.py +0 -391
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/period.py +0 -98
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/prices.py +0 -95
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/render.py +0 -586
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rollup.py +0 -355
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rules.json +0 -4
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/rules.py +0 -76
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/sample.py +0 -45
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/snapshot.py +0 -53
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/sync.py +0 -79
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/transcripts.py +0 -126
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr/wins.py +0 -341
- package/integrations/openclaw/skills/agent-cost-report/scripts/acr.py +0 -219
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/_db.py +0 -49
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/_paths.py +0 -9
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/codex/sessions/2026/09/18/rollout-codex-1.jsonl +0 -4
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/make_report_fixtures.py +0 -46
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/prices_sample.json +0 -6
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-a/sess-aaaa.jsonl +0 -8
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-b/sess-bbbb.jsonl +0 -1
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-1day.json +0 -823
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-30day.json +0 -2213
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-7day.json +0 -1252
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-empty.json +0 -536
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/fixtures/report-session.json +0 -662
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_behavior.py +0 -299
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_devices.py +0 -99
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_labels.py +0 -96
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_measure.py +0 -120
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_pdf_windows.py +0 -54
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_period.py +0 -137
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_prices.py +0 -126
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_render.py +0 -238
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_render_encoding.py +0 -70
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_rollup.py +0 -263
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_snapshot.py +0 -63
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_sync.py +0 -52
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_transcript_encoding.py +0 -109
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_transcripts.py +0 -151
- package/integrations/openclaw/skills/agent-cost-report/scripts/tests/test_wins.py +0 -222
- package/plugin/skills/agent-cost-report/CHECKSUMS.txt +0 -50
- package/plugin/skills/agent-cost-report/SKILL.md +0 -241
- package/plugin/skills/agent-cost-report/scripts/acr/__init__.py +0 -1
- package/plugin/skills/agent-cost-report/scripts/acr/behavior.py +0 -303
- package/plugin/skills/agent-cost-report/scripts/acr/classify.py +0 -83
- package/plugin/skills/agent-cost-report/scripts/acr/costs.py +0 -119
- package/plugin/skills/agent-cost-report/scripts/acr/devices.py +0 -88
- package/plugin/skills/agent-cost-report/scripts/acr/evidence.py +0 -160
- package/plugin/skills/agent-cost-report/scripts/acr/labels.py +0 -115
- package/plugin/skills/agent-cost-report/scripts/acr/measure.py +0 -89
- package/plugin/skills/agent-cost-report/scripts/acr/mistakes.py +0 -310
- package/plugin/skills/agent-cost-report/scripts/acr/patterns.py +0 -391
- package/plugin/skills/agent-cost-report/scripts/acr/period.py +0 -98
- package/plugin/skills/agent-cost-report/scripts/acr/prices.py +0 -95
- package/plugin/skills/agent-cost-report/scripts/acr/render.py +0 -586
- package/plugin/skills/agent-cost-report/scripts/acr/rollup.py +0 -355
- package/plugin/skills/agent-cost-report/scripts/acr/rules.json +0 -4
- package/plugin/skills/agent-cost-report/scripts/acr/rules.py +0 -76
- package/plugin/skills/agent-cost-report/scripts/acr/sample.py +0 -45
- package/plugin/skills/agent-cost-report/scripts/acr/snapshot.py +0 -53
- package/plugin/skills/agent-cost-report/scripts/acr/sync.py +0 -79
- package/plugin/skills/agent-cost-report/scripts/acr/transcripts.py +0 -126
- package/plugin/skills/agent-cost-report/scripts/acr/wins.py +0 -341
- package/plugin/skills/agent-cost-report/scripts/acr.py +0 -219
- package/plugin/skills/agent-cost-report/scripts/tests/_db.py +0 -49
- package/plugin/skills/agent-cost-report/scripts/tests/_paths.py +0 -9
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/codex/sessions/2026/09/18/rollout-codex-1.jsonl +0 -4
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/make_report_fixtures.py +0 -46
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/prices_sample.json +0 -6
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-a/sess-aaaa.jsonl +0 -8
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/projects/-workspace-proj-b/sess-bbbb.jsonl +0 -1
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-1day.json +0 -823
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-30day.json +0 -2213
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-7day.json +0 -1252
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-empty.json +0 -536
- package/plugin/skills/agent-cost-report/scripts/tests/fixtures/report-session.json +0 -662
- package/plugin/skills/agent-cost-report/scripts/tests/test_behavior.py +0 -299
- package/plugin/skills/agent-cost-report/scripts/tests/test_devices.py +0 -99
- package/plugin/skills/agent-cost-report/scripts/tests/test_labels.py +0 -96
- package/plugin/skills/agent-cost-report/scripts/tests/test_measure.py +0 -120
- package/plugin/skills/agent-cost-report/scripts/tests/test_pdf_windows.py +0 -54
- package/plugin/skills/agent-cost-report/scripts/tests/test_period.py +0 -137
- package/plugin/skills/agent-cost-report/scripts/tests/test_prices.py +0 -126
- package/plugin/skills/agent-cost-report/scripts/tests/test_render.py +0 -238
- package/plugin/skills/agent-cost-report/scripts/tests/test_render_encoding.py +0 -70
- package/plugin/skills/agent-cost-report/scripts/tests/test_rollup.py +0 -263
- package/plugin/skills/agent-cost-report/scripts/tests/test_snapshot.py +0 -63
- package/plugin/skills/agent-cost-report/scripts/tests/test_sync.py +0 -52
- package/plugin/skills/agent-cost-report/scripts/tests/test_transcript_encoding.py +0 -109
- package/plugin/skills/agent-cost-report/scripts/tests/test_transcripts.py +0 -151
- package/plugin/skills/agent-cost-report/scripts/tests/test_wins.py +0 -222
- package/plugin/skills/babysit/SKILL.md +0 -87
- package/plugin/skills/design-is/SKILL.md +0 -312
- package/plugin/skills/do/SKILL.md +0 -45
- package/plugin/skills/learn-codebase/SKILL.md +0 -21
- package/plugin/skills/make-plan/SKILL.md +0 -67
- package/plugin/skills/oh-my-issues/SKILL.md +0 -226
- package/plugin/skills/pathfinder/SKILL.md +0 -111
- package/plugin/skills/screenpipe/SKILL.md +0 -78
- package/plugin/skills/screenpipe/screenpipe.mjs +0 -196
- package/plugin/skills/smart-explore/SKILL.md +0 -193
- package/plugin/skills/standup/SKILL.md +0 -142
- package/plugin/skills/standup/agent-brief.md +0 -47
- package/plugin/skills/standup/standup.mjs +0 -586
- package/plugin/skills/what-the/SKILL.md +0 -6
- package/plugin/skills/wowerpoint/SKILL.md +0 -205
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
"""Behavior pattern detectors: P1–P12 plus the supporting metrics S1 (tool errors and retries) and
|
|
2
|
-
S2 (hedging: a caveat given when the answer was already available). Every detector is a heuristic
|
|
3
|
-
(count_basis "heuristic") until the optional classifier or a human review confirms it. Failure types
|
|
4
|
-
map onto the 16 in SKILL.md or stay empty; no new types.
|
|
5
|
-
|
|
6
|
-
Optional environment settings, all off by default:
|
|
7
|
-
ACR_OWNER_EMAIL the user's own address; an outbound send from it is flagged (P9)
|
|
8
|
-
ACR_DENY_INPUT a regex of tool inputs the user never wants used (accounts, contacts, sites) (P8)
|
|
9
|
-
ACR_ALLOWED_MODELS a regex of model ids that are never "wrong model" (P3); default: Claude models
|
|
10
|
-
|
|
11
|
-
A detector returns flags: dict(pattern, key, session, ts_ms, excerpt, basis, **extra). `key` is the
|
|
12
|
-
assistant turn key so the flag is priced by the same usage row Phase 1 counted. Human-phrase
|
|
13
|
-
detectors fire on human-tagged messages and flag the episode's wasted window (2B.1 pattern assignment).
|
|
14
|
-
"""
|
|
15
|
-
import collections
|
|
16
|
-
import hashlib
|
|
17
|
-
import os
|
|
18
|
-
import re
|
|
19
|
-
|
|
20
|
-
from . import behavior, costs, prices
|
|
21
|
-
|
|
22
|
-
FAILURE_TYPES = ("Looping", "Hedging", "Wrong turn", "Rework", "Regression", "Premature completion", "Unauthorized action",
|
|
23
|
-
"Suboptimal path", "Duplicate work", "Blocked work", "Missed requirement", "Unnecessary escalation",
|
|
24
|
-
"Context re-read", "Model thrash", "Fan-out waste", "Recovery after miss")
|
|
25
|
-
|
|
26
|
-
PATTERNS = [
|
|
27
|
-
("P1_invented_gates", "Invented human gates / asking instead of doing", 16, "Unnecessary escalation", "tile"),
|
|
28
|
-
("P2_broke_things", "Broke working things", 17, "Regression", "tile"),
|
|
29
|
-
("P3_wrong_model", "Wrong or expensive model", 18, "Model thrash", "tile"),
|
|
30
|
-
("P4_over_engineering", "Over-engineering / overthinking", 19, "Suboptimal path", "details"),
|
|
31
|
-
("P5_not_asked", "Did something not asked", 20, "Missed requirement", "details"),
|
|
32
|
-
("P6_fake_output", "Fake or invented output", 21, "Premature completion", "tile"),
|
|
33
|
-
("P7_false_done", "Skipped steps / false done", 22, "Premature completion", "tile"),
|
|
34
|
-
("P8_wrong_tool", "Wrong tool, account, or contact", 23, "Suboptimal path", "details"),
|
|
35
|
-
("P9_bad_outbound", "Bad outbound", 24, "Unauthorized action", "details"),
|
|
36
|
-
("P10_memory_loss", "Memory or rule loss", 25, "", "details"),
|
|
37
|
-
("P11_jargon", "Jargon / walls of text", 26, "", "details"),
|
|
38
|
-
("P12_unclear", "Unclear cause", 27, "", "details"),
|
|
39
|
-
("S1_tool_errors", "Tool errors and retries", None, "Recovery after miss", "details"),
|
|
40
|
-
("S2_hedging", "Hedging", None, "Hedging", "details"),
|
|
41
|
-
]
|
|
42
|
-
TILE_ORDER = ("P1_invented_gates", "P6_fake_output", "P7_false_done", "P2_broke_things", "P3_wrong_model")
|
|
43
|
-
MERGED_TILE = ("P6_fake_output", "P7_false_done")
|
|
44
|
-
NAMES = {k: n for k, n, *_ in PATTERNS}
|
|
45
|
-
assert all(ft in FAILURE_TYPES or ft == "" for _, _, _, ft, _ in PATTERNS)
|
|
46
|
-
|
|
47
|
-
P1_AGENT = re.compile(r"Blocked on (you|the user)|needs your sign-off|initials|please click|open this link and|when you get a chance|human gate", re.I)
|
|
48
|
-
P1_ASK = re.compile(r"(?i)would you like me to|do you want me to|want me to|should I\b|shall I\b|let me know if|can you (paste|provide|send|share|click|confirm|approve|log ?in)|"
|
|
49
|
-
r"please (paste|provide|click|approve|confirm|run)|I need you to|waiting (for|on) (you|your)|blocked on (you|the user)|needs? the user|human gate")
|
|
50
|
-
P1_ANNOYED = re.compile(r"(?i)already|I told you|just do it|stop asking|why do I have to|no .{0,20}human gate")
|
|
51
|
-
P1_HUMAN = re.compile(r"who (made|makes) up|no one said|you're allowed|just do it|(arbitrary|fake|invented|made.up) gate|human gates?\b", re.I)
|
|
52
|
-
P1_ANSWER_SHAPE = re.compile(r"sk-[\w-]{6,}|ghp_\w+|https?://\S+|/[\w.-]+/[\w./-]+|\bpassword\b|\bapproved?\b|\byes\b|\bgo ahead\b", re.I)
|
|
53
|
-
P1_REAL_GATE = re.compile(r"cold (allow|start)|payment method|wet[- ]ink|signature|2FA|two[- ]factor", re.I)
|
|
54
|
-
P2_HUMAN = re.compile(r"\b(broke|broken|crash\w*|regress\w*|was working)\b", re.I)
|
|
55
|
-
P2_REVERT = re.compile(r"^\s*git\s+revert\b|\bgh pr create\b.*\brevert\b", re.I | re.M)
|
|
56
|
-
P3_ALLOWED = re.compile(os.environ.get("ACR_ALLOWED_MODELS") or r"^anthropic/claude|^claude", re.I)
|
|
57
|
-
P3_FALLBACK_DEFAULT = "anthropic/claude-sonnet-5"
|
|
58
|
-
P3_HUMAN = re.compile(r"\b(gemini|gpt-5|why are you using|credits|spent)\b", re.I)
|
|
59
|
-
P4_HUMAN = re.compile(r"\b(happy path|overthink\w*|guards?|harden\w*|simple)\b", re.I)
|
|
60
|
-
P4_FILE = re.compile(r"(guard|harden|fallback|validator)[\w-]*\.(py|ts|js|sh|md)$", re.I)
|
|
61
|
-
P4_PLAN_LINES = 600
|
|
62
|
-
P5_HUMAN = re.compile(r"i did not ask|i didn't tell you|nobody said|I SAID|wrong (side|end|repo)|receiving end|sending end|why is there .{0,40}(in|from) that repo|not what I (asked|want)|feels? dumb", re.I)
|
|
63
|
-
P6_CLAIMED_SKILL = re.compile(r"(?:\bran|\brunning|\bexecuted|\bcompleted|\binvoked|\bused)\s+(?:the\s+)?`?(/[a-z][\w:-]+)`?|`?(/[a-z][\w:-]+)`?\s+(?:ran|has run|completed|finished|is done)", re.I)
|
|
64
|
-
P6_PLACEHOLDER = re.compile(r"\$0\.00\b|\blorem\b|\bTBD\b", re.I)
|
|
65
|
-
P7_CLAIM = re.compile(r"(?i)\b(done|fixed|works now|deployed|shipped|merged|all tests pass(ed)?|verified|100%|confirmed)\b")
|
|
66
|
-
P7_NEGATED = re.compile(r"(?i)\b(not|isn't|isn t|aren't|wasn't|never|once|will be|until|before|if|when|unless|after)\s+(?:\w+\s+){0,2}(done|fixed|works now|deployed|shipped|merged|verified|confirmed)\b|\b(done|fixed|deployed|shipped|merged|verified)\b\s*\?")
|
|
67
|
-
P7_PROOF_CMD = re.compile(r"pytest|unittest|vitest|jest|bun test|npm (run )?test|go test|cargo test|curl\b|gh pr (view|checks|merge)|git push|wrangler deploy|vercel|deploy", re.I)
|
|
68
|
-
P7_PROOF_OUT = re.compile(r"\bpassed\b|\bOK\b|\b(200|201|204)\b|MERGED|mergedAt|Deployed|https?://|\bmain -> main\b|->\s+\w+/\w+", re.I)
|
|
69
|
-
P7_PROD_CLAIM = re.compile(r"deployed|in production|live now|fixed in prod", re.I)
|
|
70
|
-
P7_MERGE_ONLY = re.compile(r"gh pr merge", re.I)
|
|
71
|
-
NEVER = re.compile(r"(?!)")
|
|
72
|
-
OWNER_EMAIL = (os.environ.get("ACR_OWNER_EMAIL") or "").strip()
|
|
73
|
-
P8_DENY_TOOL = re.compile(r"computer[_-]?use|mcp__.*computer", re.I)
|
|
74
|
-
P8_DENY_INPUT = re.compile(os.environ["ACR_DENY_INPUT"], re.I) if os.environ.get("ACR_DENY_INPUT") else NEVER
|
|
75
|
-
P9_SEND_TOOL = re.compile(r"(gmail|resend|mail|slack|telegram|sms|twilio|sendgrid|postmark).*?(send|reply|forward|broadcast)|(send|reply|forward).*?(email|broadcast)", re.I)
|
|
76
|
-
P9_NOT_OUTBOUND = re.compile(r"^(SendMessage|PushNotification|SendFeedback)$")
|
|
77
|
-
P9_APPROVAL = re.compile(r"\b(send it|go ahead|approved?|yes,? send|ship it|do it|fire away)\b", re.I)
|
|
78
|
-
P9_RECIPIENT_CAP = 10
|
|
79
|
-
EMAIL_RE = re.compile(r"[\w.+-]+@[\w-]+\.[\w.-]+")
|
|
80
|
-
P10_HUMAN = re.compile(r"I told you|100 times|8,?000 times|what's the rule|like i said", re.I)
|
|
81
|
-
P11_MAX_WORDS = 150
|
|
82
|
-
P11_JARGON = ("drain", "projection", "projected_seq", "head_seq", "poll-mode", "lag", "kill-switch", "BYOK", "face-wall", "chatty",
|
|
83
|
-
"Durable Object", "idempotent", "backfill", "TOCTOU")
|
|
84
|
-
P11_GLOSS = re.compile(r"\(|—|\bmeans\b|\bi\.e\.|\bthat is\b", re.I)
|
|
85
|
-
P11_HUMAN = re.compile(r"\b(jargon|9000 things|single answer|plain english)\b", re.I)
|
|
86
|
-
P11_PATH = re.compile(r"(?<![\w/])/(?:workspace|home|tmp|Users)/[\w./-]+")
|
|
87
|
-
S1_ERROR_TEXT = re.compile(r"(?i)^\W{0,3}(error|fatal)\b|traceback \(most recent|exit code [1-9]|command not found|no such file or directory|ENOENT|EACCES|timed out|"
|
|
88
|
-
r"(HTTP|status|code|error)\W{0,4}(429|5\d\d)\b|\brate.?limit(ed|s)?\b")
|
|
89
|
-
S1_DENIAL = re.compile(r"Permission to use .* has been denied|denied by (a )?(hook|rule|permission)|blocked by (a )?(hook|rule|permission)", re.I)
|
|
90
|
-
S1_RETRY_WINDOW = 5
|
|
91
|
-
S1_SIMILARITY = 0.8
|
|
92
|
-
S1_LOOP_N = 3
|
|
93
|
-
S2_LEXICON = re.compile(r"\b(might|may|could potentially|possibly|perhaps|it seems|it appears|appears to|probably|likely|I think|I believe|not sure|can't be sure|cannot be sure|"
|
|
94
|
-
r"no way to (know|tell)|hard to say|should work|should be (fine|fixed|good|working)|in theory|hopefully|if you want|would you like|depending on)\b", re.I)
|
|
95
|
-
S2_STATUS = re.compile(r"should be (fixed|deployed|working)|probably (works|fixed|deployed)|I think it'?s (done|fixed)", re.I)
|
|
96
|
-
S2_TARGET = re.compile(r"(/[\w.-]+/[\w./-]+|`[^`]{2,80}`|#\d{2,6}|https?://\S+|\btest_\w+|\b\d+(\.\d+)?%?)")
|
|
97
|
-
S2_ALLOW = re.compile(r"\b(estimated?|low confidence|unavailable|measured spend unavailable|unmeasured|extrapolated|heuristic)\b", re.I)
|
|
98
|
-
S2_FOLLOWUP = re.compile(r"(?i)is it|yes or no|did you|confirm|what do you mean|straight answer")
|
|
99
|
-
MASK_RE = re.compile(r"/tmp/\S+|\d+")
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
def flag(pattern, T, session, excerpt, basis, **extra):
|
|
103
|
-
return dict(pattern=pattern, key=T["key"] if T else None, session=session, ts_ms=T["ts_ms"] if T else extra.pop("ts_ms", None),
|
|
104
|
-
excerpt=behavior.scrub(excerpt), basis=basis, label_source="heuristic", **extra)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def _norm_input(s):
|
|
108
|
-
return " ".join(MASK_RE.sub("#", s or "").split())
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def _similar(a, b):
|
|
112
|
-
"""Normalized input similarity: Jaccard over tokens after whitespace collapse and number/temp-path masking."""
|
|
113
|
-
ta, tb = set(re.findall(r"\w+", _norm_input(a))), set(re.findall(r"\w+", _norm_input(b)))
|
|
114
|
-
return len(ta & tb) / len(ta | tb) if (ta or tb) else 1.0
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def user_facing_turns(S):
|
|
118
|
-
"""Each assistant turn's user-facing text (the last text before the next user prompt is what the user reads)."""
|
|
119
|
-
turns = behavior.ordered_turns(S)
|
|
120
|
-
prompts = sorted(u["ts_ms"] for u in S["users"] if u["text"] and not u["results"])
|
|
121
|
-
out = []
|
|
122
|
-
for i, T in enumerate(turns):
|
|
123
|
-
txt = behavior.user_facing(T["text"])
|
|
124
|
-
nxt_turn = turns[i + 1]["ts_ms"] if i + 1 < len(turns) else None
|
|
125
|
-
nxt_prompt = next((p for p in prompts if p > T["ts_ms"]), None)
|
|
126
|
-
final = txt and (nxt_turn is None or (nxt_prompt is not None and nxt_prompt < nxt_turn))
|
|
127
|
-
out.append((T, txt, bool(final), nxt_prompt))
|
|
128
|
-
return out
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def _events(S):
|
|
132
|
-
"""Interleaved (ts, kind, obj) with kind in {turn, user}."""
|
|
133
|
-
ev = [(T["ts_ms"], "turn", T) for T in S["turns"].values()] + [(u["ts_ms"], "user", u) for u in S["users"]]
|
|
134
|
-
return sorted(ev, key=lambda e: e[0])
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def _results_by_id(S):
|
|
138
|
-
out = {}
|
|
139
|
-
for u in S["users"]:
|
|
140
|
-
for r in u["results"]: out[r["tool_use_id"]] = (u["ts_ms"], r)
|
|
141
|
-
return out
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def detect_p1(S, sid, msgs):
|
|
145
|
-
flags = []; uf = user_facing_turns(S); turns = behavior.ordered_turns(S)
|
|
146
|
-
users = [u for u in S["users"] if u["text"] and not u["results"]]
|
|
147
|
-
for T, txt, final, nxt_prompt in uf:
|
|
148
|
-
if not txt or not final: continue
|
|
149
|
-
tail = txt[-600:]
|
|
150
|
-
hard = bool(P1_AGENT.search(tail)); cand = hard or tail.rstrip().endswith("?") or bool(P1_ASK.search(tail))
|
|
151
|
-
if not cand or P1_REAL_GATE.search(tail): continue
|
|
152
|
-
earlier = " ".join(u["text"] for u in users if u["ts_ms"] < T["ts_ms"])
|
|
153
|
-
boosts = []
|
|
154
|
-
if P1_ANSWER_SHAPE.search(earlier): boosts.append("already answered")
|
|
155
|
-
if S["entrypoint"] in behavior.HEADLESS and T is turns[-1]: boosts.append("nobody can answer (headless session ends on the ask)")
|
|
156
|
-
nxt = next((u for u in users if u["ts_ms"] > T["ts_ms"]), None)
|
|
157
|
-
if nxt and P1_ANNOYED.search(nxt["text"]): boosts.append("annoyed reply")
|
|
158
|
-
if not (hard or boosts):
|
|
159
|
-
flags.append(flag("P1_invented_gates", T, sid, tail[-160:], "candidate, no boost", unconfirmed=True)); continue
|
|
160
|
-
asked = "user" if S.get("tag") == "user_direct" else "agent"
|
|
161
|
-
wait_min = round((nxt["ts_ms"] - T["ts_ms"]) / 60_000, 1) if nxt else None
|
|
162
|
-
after = [x for x in turns if nxt and x["ts_ms"] > nxt["ts_ms"]][:2] if nxt else []
|
|
163
|
-
if S["entrypoint"] in behavior.HEADLESS and T is turns[-1]:
|
|
164
|
-
last_ok = max([ts for ts, r in _results_by_id(S).values() if not r["is_error"]] or [0])
|
|
165
|
-
after = [x for x in turns if x["ts_ms"] > last_ok and x is not T]
|
|
166
|
-
f = flag("P1_invented_gates", T, sid, tail[-160:], "agent text: " + ("gate phrase" if hard else "ask + " + ", ".join(boosts)),
|
|
167
|
-
asked=asked, waiting_minutes=wait_min, never_answered=nxt is None, extra_keys=[x["key"] for x in after])
|
|
168
|
-
flags.append(f)
|
|
169
|
-
return flags
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
def detect_p3(S, sid, default_model, pricer):
|
|
173
|
-
flags = []; not_logged = 0
|
|
174
|
-
for T in S["turns"].values():
|
|
175
|
-
if not T["usage"]: continue
|
|
176
|
-
if not T["model"]: not_logged += 1; continue
|
|
177
|
-
m = prices.norm(T["model"])
|
|
178
|
-
if m == "<synthetic>" or P3_ALLOWED.search(m): continue
|
|
179
|
-
rt_def = pricer.rate(default_model)
|
|
180
|
-
base = costs.api_equiv_x1e6(T["usage"], rt_def) if rt_def else None
|
|
181
|
-
delta = (T["x1e6"] - base) if (T["x1e6"] is not None and base is not None) else None
|
|
182
|
-
flags.append(flag("P3_wrong_model", T, sid, f"model {m} (default {default_model})", "message.model differs from the default (exact)",
|
|
183
|
-
model=m, default_model=default_model, delta_x1e6=delta))
|
|
184
|
-
return flags, not_logged
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
def detect_p4(S, sid):
|
|
188
|
-
flags = []
|
|
189
|
-
for T in S["turns"].values():
|
|
190
|
-
for tu in T["tool_uses"]:
|
|
191
|
-
if tu["name"] not in ("Write", "Edit", "MultiEdit"): continue
|
|
192
|
-
path = str(tu["input"].get("file_path") or "")
|
|
193
|
-
content = str(tu["input"].get("content") or "")
|
|
194
|
-
if P4_FILE.search(path): flags.append(flag("P4_over_engineering", T, sid, f"new file {path}", "new guard/harden/fallback/validator file"))
|
|
195
|
-
elif "/plans/" in path and content.count("\n") > P4_PLAN_LINES:
|
|
196
|
-
flags.append(flag("P4_over_engineering", T, sid, f"plan {path}: {content.count(chr(10))} lines", f"plan length over {P4_PLAN_LINES} lines"))
|
|
197
|
-
return flags
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def detect_p6(S, sid):
|
|
201
|
-
flags = []; skills = set()
|
|
202
|
-
for T in S["turns"].values():
|
|
203
|
-
for tu in T["tool_uses"]:
|
|
204
|
-
if tu["name"] == "Skill": skills.add("/" + str(tu["input"].get("skill") or "").lstrip("/"))
|
|
205
|
-
for T, txt, final, _ in user_facing_turns(S):
|
|
206
|
-
if not txt or not final: continue
|
|
207
|
-
for m in P6_CLAIMED_SKILL.finditer(txt):
|
|
208
|
-
name = (m.group(1) or m.group(2) or "").rstrip(".,:;")
|
|
209
|
-
if name and name not in skills and not any(s.endswith(name.lstrip("/")) for s in skills):
|
|
210
|
-
flags.append(flag("P6_fake_output", T, sid, m.group(0), f"claimed {name} ran, no Skill tool call", trust_flag=True)); break
|
|
211
|
-
if final and P6_PLACEHOLDER.search(txt):
|
|
212
|
-
flags.append(flag("P6_fake_output", T, sid, P6_PLACEHOLDER.search(txt).group(0), "placeholder value in the final text", trust_flag=True))
|
|
213
|
-
return flags
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
def detect_p7(S, sid):
|
|
217
|
-
flags = []; ev = _events(S); results = _results_by_id(S); finals = {T["key"] for T, t, f, _ in user_facing_turns(S) if f and t}
|
|
218
|
-
last_user = None; proof_since = None; last_edit = None; merge_only = False
|
|
219
|
-
for ts, kind, obj in ev:
|
|
220
|
-
if kind == "user":
|
|
221
|
-
if obj["text"] and not obj["results"]: last_user = ts; proof_since = None; last_edit = None; merge_only = False
|
|
222
|
-
continue
|
|
223
|
-
T = obj
|
|
224
|
-
for tu in T["tool_uses"]:
|
|
225
|
-
if tu["name"] in ("Write", "Edit", "MultiEdit"): last_edit = ts; proof_since = None; merge_only = False
|
|
226
|
-
res = results.get(tu["id"]); cmd = tu["input_s"]
|
|
227
|
-
if res and not res[1]["is_error"] and (P7_PROOF_CMD.search(cmd) or tu["name"] == "Skill") and (P7_PROOF_OUT.search(res[1]["content"]) or "test" in cmd.lower()):
|
|
228
|
-
if P7_MERGE_ONLY.search(cmd) and not re.search(r"deploy|wrangler|vercel", cmd, re.I): merge_only = True
|
|
229
|
-
else: proof_since = ts; merge_only = False
|
|
230
|
-
if T["key"] not in finals: continue
|
|
231
|
-
txt = behavior.user_facing(T["text"])
|
|
232
|
-
m = P7_CLAIM.search(txt or "")
|
|
233
|
-
if not m: continue
|
|
234
|
-
sent = txt[max(0, m.start() - 80): m.end() + 40]
|
|
235
|
-
if P7_NEGATED.search(sent): continue
|
|
236
|
-
if proof_since is not None and (last_edit is None or proof_since > last_edit): continue
|
|
237
|
-
special = bool(P7_PROD_CLAIM.search(txt)) and merge_only
|
|
238
|
-
flags.append(flag("P7_false_done", T, sid, sent, "merged, not deployed" if special else "claim with no proof since the last edit", claim=m.group(0)))
|
|
239
|
-
return flags
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def detect_p8(S, sid):
|
|
243
|
-
flags = []
|
|
244
|
-
for T in S["turns"].values():
|
|
245
|
-
for tu in T["tool_uses"]:
|
|
246
|
-
if P8_DENY_TOOL.search(tu["name"]) or P8_DENY_INPUT.search(tu["input_s"]):
|
|
247
|
-
outside = bool(re.search(r"send|email|deploy|publish|post", tu["name"] + tu["input_s"], re.I))
|
|
248
|
-
flags.append(flag("P8_wrong_tool", T, sid, f"{tu['name']} {tu['input_s'][:100]}", "tool/account/contact on the deny list",
|
|
249
|
-
failure_type="Unauthorized action" if outside else "Suboptimal path"))
|
|
250
|
-
return flags
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
SENDER_FIELDS = ("from", "sender", "from_email", "from_address", "sender_email", "send_as", "sendas", "reply_as")
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
def sent_as_owner(tool_input):
|
|
257
|
-
"""True when a sender field of the send call holds exactly ACR_OWNER_EMAIL (any case, display-name
|
|
258
|
-
forms such as `Me <me@example.com>` included). Recipients and the message body are never read: mail
|
|
259
|
-
sent to the user, or quoting their address, is not sent as them."""
|
|
260
|
-
owner = OWNER_EMAIL.lower()
|
|
261
|
-
if not owner or not isinstance(tool_input, dict): return False
|
|
262
|
-
return any(addr.lower() == owner for k, v in tool_input.items() if str(k).lower() in SENDER_FIELDS for addr in EMAIL_RE.findall(str(v)))
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
def detect_p9(S, sid):
|
|
266
|
-
flags = []; users = [u for u in S["users"] if u["text"] and not u["results"]]
|
|
267
|
-
for T in S["turns"].values():
|
|
268
|
-
for tu in T["tool_uses"]:
|
|
269
|
-
if P9_NOT_OUTBOUND.match(tu["name"]) or not P9_SEND_TOOL.search(tu["name"]): continue
|
|
270
|
-
prev = [u for u in users if u["ts_ms"] < T["ts_ms"]]
|
|
271
|
-
approved = bool(prev) and prev[-1].get("author") == "human" and bool(P9_APPROVAL.search(prev[-1]["text"]))
|
|
272
|
-
emails = set(EMAIL_RE.findall(tu["input_s"]))
|
|
273
|
-
n = len(emails) or (0 if "broadcast" not in tu["name"].lower() else None)
|
|
274
|
-
identity = sent_as_owner(tu["input"])
|
|
275
|
-
if approved and (n is not None and n <= P9_RECIPIENT_CAP) and not identity: continue
|
|
276
|
-
why = [w for w, c in (("no human approval in the preceding turn", not approved), ("recipient count above 10", n is None or n > P9_RECIPIENT_CAP), ("sent as the user", identity)) if c]
|
|
277
|
-
flags.append(flag("P9_bad_outbound", T, sid, f"{tu['name']} to {n if n is not None else 'unknown'} recipients", "; ".join(why), recipients=n))
|
|
278
|
-
return flags
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
def detect_p11(S, sid):
|
|
282
|
-
flags = []
|
|
283
|
-
for T, txt, final, _ in user_facing_turns(S):
|
|
284
|
-
if not final or not txt: continue
|
|
285
|
-
w = words(txt); paths = len(P11_PATH.findall(txt)); links = txt.count("http")
|
|
286
|
-
terms = []
|
|
287
|
-
for term in P11_JARGON:
|
|
288
|
-
for m in re.finditer(r"(?i)(?<![\w-])" + re.escape(term) + r"(?![\w-])", txt):
|
|
289
|
-
sent = txt[max(0, txt.rfind(".", 0, m.start()) + 1): txt.find(".", m.end()) if txt.find(".", m.end()) > 0 else len(txt)]
|
|
290
|
-
if not P11_GLOSS.search(sent): terms.append(term); break
|
|
291
|
-
reasons = []
|
|
292
|
-
if w > P11_MAX_WORDS: reasons.append(f"{w} words in the last message")
|
|
293
|
-
if terms: reasons.append("unexplained: " + ", ".join(terms))
|
|
294
|
-
if paths >= 3 and not links: reasons.append(f"{paths} file paths, no links")
|
|
295
|
-
if reasons: flags.append(flag("P11_jargon", T, sid, txt[:160], "; ".join(reasons), user_minutes=round(w / 200, 1), words=w))
|
|
296
|
-
return flags
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
def words(text):
|
|
300
|
-
return behavior.words(text)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
def detect_s1(S, sid):
|
|
304
|
-
"""Errors (is_error or text match), permission denials (separate, unpriced), retries (same tool,
|
|
305
|
-
similarity ≥0.8 within 5 turns) and loops (same name+normalized input ≥3 times)."""
|
|
306
|
-
flags = []; denials = []; results = _results_by_id(S); turns = behavior.ordered_turns(S)
|
|
307
|
-
calls = []
|
|
308
|
-
for i, T in enumerate(turns):
|
|
309
|
-
for tu in T["tool_uses"]:
|
|
310
|
-
res = results.get(tu["id"]); err = None
|
|
311
|
-
if res:
|
|
312
|
-
c = res[1]["content"] or ""
|
|
313
|
-
if S1_DENIAL.search(c): denials.append(dict(session=sid, ts_ms=T["ts_ms"], tool=tu["name"], excerpt=behavior.scrub(c))); calls.append((i, tu, "denied")); continue
|
|
314
|
-
if res[1]["is_error"]: err = "is_error"
|
|
315
|
-
elif S1_ERROR_TEXT.search(c[:2048]): err = "text"
|
|
316
|
-
calls.append((i, tu, err))
|
|
317
|
-
chains = 0; loops = 0; counter = collections.Counter((tu["name"], hashlib.sha1(_norm_input(tu["input_s"]).encode()).hexdigest()) for _, tu, _ in calls)
|
|
318
|
-
loop_keys = {k for k, n in counter.items() if n >= S1_LOOP_N}
|
|
319
|
-
for j, (i, tu, err) in enumerate(calls):
|
|
320
|
-
if err in (None, "denied"): continue
|
|
321
|
-
T = turns[i]; retries = []
|
|
322
|
-
for i2, tu2, err2 in calls[j + 1:]:
|
|
323
|
-
if i2 - i > S1_RETRY_WINDOW: break
|
|
324
|
-
if tu2["name"] == tu["name"] and _similar(tu["input_s"], tu2["input_s"]) >= S1_SIMILARITY:
|
|
325
|
-
retries.append((turns[i2]["key"], err2))
|
|
326
|
-
if err2 is None: break
|
|
327
|
-
chains += 1
|
|
328
|
-
recovered = bool(retries) and retries[-1][1] is None
|
|
329
|
-
flags.append(flag("S1_tool_errors", T, sid, f"{tu['name']}: {tu['input_s'][:80]}", f"tool error ({err}), {len(retries)} retries, " + ("recovered" if recovered else "never succeeded"),
|
|
330
|
-
confidence="high" if err == "is_error" else "medium", failure_type="Recovery after miss",
|
|
331
|
-
recovery_keys=[k for k, e in retries] if recovered else [], wasted_extra=[] if recovered else [k for k, e in retries]))
|
|
332
|
-
for k in loop_keys:
|
|
333
|
-
seen = [(i, tu) for i, tu, _ in calls if (tu["name"], hashlib.sha1(_norm_input(tu["input_s"]).encode()).hexdigest()) == k]
|
|
334
|
-
for i, tu in seen[1:]:
|
|
335
|
-
flags.append(flag("S1_tool_errors", turns[i], sid, f"{tu['name']}: {tu['input_s'][:80]}", f"same call {len(seen)} times (loop)", failure_type="Looping", loop=True)); loops += 1
|
|
336
|
-
return flags, denials, dict(error_chains=chains, loops=len(loop_keys))
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
def detect_s2(S, sid):
|
|
340
|
-
flags = []; unknown = 0; results = _results_by_id(S); users = [u for u in S["users"] if u["text"] and not u["results"]]
|
|
341
|
-
seen_targets = ""
|
|
342
|
-
ev = _events(S)
|
|
343
|
-
for ts, kind, obj in ev:
|
|
344
|
-
if kind == "user":
|
|
345
|
-
for r in obj["results"]: seen_targets += (r["content"] or "")[:1500] + "\n"
|
|
346
|
-
continue
|
|
347
|
-
T = obj; txt = behavior.user_facing(T["text"])
|
|
348
|
-
if not txt: continue
|
|
349
|
-
for sent in re.split(r"(?<=[.!?])\s+|\n+", txt):
|
|
350
|
-
if not S2_LEXICON.search(sent) or S2_ALLOW.search(sent): continue
|
|
351
|
-
tgt = S2_TARGET.search(sent)
|
|
352
|
-
if not (S2_STATUS.search(sent) or tgt): continue
|
|
353
|
-
target = (tgt.group(0).strip("`") if tgt else "")
|
|
354
|
-
available = bool(target) and len(target) > 2 and target in seen_targets
|
|
355
|
-
if not available: unknown += 1; continue
|
|
356
|
-
nxt = next((u for u in users if u["ts_ms"] > T["ts_ms"]), None)
|
|
357
|
-
caused = bool(nxt and S2_FOLLOWUP.search(nxt["text"]))
|
|
358
|
-
flags.append(flag("S2_hedging", T, sid, sent, "hedge on a claim whose answer was already in a tool result (G10)", failure_type="Hedging",
|
|
359
|
-
caused_followup=caused, priced=caused)); break
|
|
360
|
-
return flags, unknown
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
P6_HUMAN = re.compile(r"did you actually|made (that|it) up|\bfake\b|\bvibe\w*\b|where did .{0,30}number", re.I)
|
|
364
|
-
P7_HUMAN = re.compile(r"is it (100% )?fixed|did you (actually )?(fix|deploy|run|push|test)|can you confirm|is it (actually )?(done|deployed|merged)", re.I)
|
|
365
|
-
HUMAN_PHRASES = (("P6_fake_output", P6_HUMAN), ("P7_false_done", P7_HUMAN), ("P1_invented_gates", P1_HUMAN), ("P2_broke_things", P2_HUMAN),
|
|
366
|
-
("P3_wrong_model", P3_HUMAN), ("P5_not_asked", P5_HUMAN), ("P10_memory_loss", P10_HUMAN), ("P11_jargon", P11_HUMAN),
|
|
367
|
-
("P4_over_engineering", P4_HUMAN))
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
def human_phrase_patterns(text):
|
|
371
|
-
return [k for k, rx in HUMAN_PHRASES if rx.search(text or "")]
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
def detect_reverts(S, sid):
|
|
375
|
-
flags = []
|
|
376
|
-
for T in S["turns"].values():
|
|
377
|
-
for tu in T["tool_uses"]:
|
|
378
|
-
if tu["name"] == "Bash" and P2_REVERT.search(str(tu["input"].get("command") or "")):
|
|
379
|
-
flags.append(flag("P2_broke_things", T, sid, tu["input_s"][:120], "git revert in the session (objective)"))
|
|
380
|
-
return flags
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
def run_session(S, sid, msgs, default_model, pricer):
|
|
384
|
-
"""All agent-turn detectors for one session. Returns (flags, denials, stats)."""
|
|
385
|
-
flags = []; stats = {}
|
|
386
|
-
flags += detect_p1(S, sid, msgs)
|
|
387
|
-
f3, not_logged = detect_p3(S, sid, default_model, pricer); flags += f3; stats["model_not_logged"] = not_logged
|
|
388
|
-
flags += detect_p4(S, sid) + detect_p6(S, sid) + detect_p7(S, sid) + detect_p8(S, sid) + detect_p9(S, sid) + detect_p11(S, sid) + detect_reverts(S, sid)
|
|
389
|
-
f1, denials, s1 = detect_s1(S, sid); flags += f1; stats.update(s1)
|
|
390
|
-
f2, unknown = detect_s2(S, sid); flags += f2; stats["hedge_availability_unknown"] = unknown
|
|
391
|
-
return flags, denials, stats
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"""PT period window (plan Phase 1.2).
|
|
2
|
-
|
|
3
|
-
Period arguments copied from parse_transcripts.py:8-14 and
|
|
4
|
-
weekly_report.py:11-14 (PT calendar days, end exclusive, ZoneInfo only), with defaults added
|
|
5
|
-
per the plan (G3): last 7 full PT days, today excluded. No fixed UTC offsets anywhere.
|
|
6
|
-
"""
|
|
7
|
-
import datetime as dt
|
|
8
|
-
import re
|
|
9
|
-
from dataclasses import dataclass
|
|
10
|
-
from zoneinfo import ZoneInfo
|
|
11
|
-
|
|
12
|
-
PT = ZoneInfo("America/Los_Angeles")
|
|
13
|
-
|
|
14
|
-
DEFAULT_DAYS = 7
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
DAY_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def parse_day(text):
|
|
21
|
-
"""'YYYY-MM-DD' (a PT calendar day) -> aware datetime at PT midnight.
|
|
22
|
-
copied from parse_transcripts.py:10-11 / weekly_report.py:13-14:
|
|
23
|
-
dt.datetime.fromisoformat(x).replace(tzinfo=PT). Strict: anything but a bare calendar day is
|
|
24
|
-
rejected (datetime.fromisoformat would silently accept '2026-09-25+00:00' as a naive midnight)."""
|
|
25
|
-
if not DAY_RE.match(text or ""):
|
|
26
|
-
raise ValueError(f"expected a PT calendar day YYYY-MM-DD, got {text!r}")
|
|
27
|
-
return dt.datetime.fromisoformat(text).replace(tzinfo=PT)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def epoch_ms(d):
|
|
31
|
-
"""copied from weekly_report.py:13-14: int(<aware dt>.timestamp() * 1000) -> UTC epoch milliseconds."""
|
|
32
|
-
return int(d.timestamp() * 1000)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def pt_midnight(day):
|
|
36
|
-
"""Aware datetime at 00:00 PT on the given date (never ambiguous: DST switches at 02:00)."""
|
|
37
|
-
return dt.datetime.combine(day, dt.time(0), tzinfo=PT)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def now_pt():
|
|
41
|
-
return dt.datetime.now(PT)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@dataclass(frozen=True)
|
|
45
|
-
class Window:
|
|
46
|
-
start: dt.datetime
|
|
47
|
-
end: dt.datetime
|
|
48
|
-
generated_at: dt.datetime
|
|
49
|
-
|
|
50
|
-
@property
|
|
51
|
-
def start_pt(self):
|
|
52
|
-
return self.start.date().isoformat()
|
|
53
|
-
|
|
54
|
-
@property
|
|
55
|
-
def end_exclusive_pt(self):
|
|
56
|
-
return self.end.date().isoformat()
|
|
57
|
-
|
|
58
|
-
@property
|
|
59
|
-
def start_epoch_ms(self):
|
|
60
|
-
return epoch_ms(self.start)
|
|
61
|
-
|
|
62
|
-
@property
|
|
63
|
-
def end_epoch_ms(self):
|
|
64
|
-
return epoch_ms(self.end)
|
|
65
|
-
|
|
66
|
-
@property
|
|
67
|
-
def generated_at_pt(self):
|
|
68
|
-
return self.generated_at.strftime("%Y-%m-%d %H:%M PT")
|
|
69
|
-
|
|
70
|
-
@property
|
|
71
|
-
def partial_last_day(self):
|
|
72
|
-
return self.end.date() > self.generated_at.date()
|
|
73
|
-
|
|
74
|
-
def block(self):
|
|
75
|
-
"""The `window` block every output carries (shape after weekly_report.py:207-238 `window=`)."""
|
|
76
|
-
return dict(start_pt=self.start_pt, end_exclusive_pt=self.end_exclusive_pt,
|
|
77
|
-
start_epoch_ms=self.start_epoch_ms, end_epoch_ms=self.end_epoch_ms,
|
|
78
|
-
generated_at_pt=self.generated_at_pt, partial_last_day=self.partial_last_day)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def resolve_window(start=None, end=None, now=None):
|
|
82
|
-
"""Build the PT window from optional --start/--end strings.
|
|
83
|
-
|
|
84
|
-
Defaults (plan G3): end = the PT midnight that started today (today excluded);
|
|
85
|
-
start = end - 7 days. `now` is injectable for tests (an aware datetime)."""
|
|
86
|
-
now = (now or now_pt()).astimezone(PT)
|
|
87
|
-
e = parse_day(end) if end is not None else pt_midnight(now.date())
|
|
88
|
-
s = parse_day(start) if start is not None else pt_midnight(e.date() - dt.timedelta(days=DEFAULT_DAYS))
|
|
89
|
-
if not s < e:
|
|
90
|
-
raise ValueError(f"--start {s.date()} must be before --end {e.date()} (end is exclusive)")
|
|
91
|
-
return Window(s, e, now)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def session_block(session, now=None):
|
|
95
|
-
"""`window` block for --session runs: no period filter, so the bounds are null."""
|
|
96
|
-
now = (now or now_pt()).astimezone(PT)
|
|
97
|
-
return dict(start_pt=None, end_exclusive_pt=None, start_epoch_ms=None, end_epoch_ms=None,
|
|
98
|
-
generated_at_pt=now.strftime("%Y-%m-%d %H:%M PT"), partial_last_day=False, session=session)
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"""OpenRouter public price list and per-model rate lookup (plan Phase 1.5).
|
|
2
|
-
|
|
3
|
-
fetch() copied from fetch_prices.py:3-7 (extended with
|
|
4
|
-
cache_write_1h); norm()/rate() copied from weekly_report.py:23-42 with the PRICE-TABLE
|
|
5
|
-
fallback dropped (hard-coded path, plan Phase 0 A) and one rule change for 1h cache writes.
|
|
6
|
-
Never prices silently at zero: a failed fetch without --prices is an error.
|
|
7
|
-
"""
|
|
8
|
-
import datetime as dt
|
|
9
|
-
import json
|
|
10
|
-
import os
|
|
11
|
-
import re
|
|
12
|
-
import urllib.request
|
|
13
|
-
|
|
14
|
-
SOURCE_URL = "https://openrouter.ai/api/v1/models"
|
|
15
|
-
PRICES_FILE = "prices.json"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class PriceError(RuntimeError):
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def fetch(url=SOURCE_URL, timeout=60):
|
|
23
|
-
"""GET the public model list (no key) -> {fetched, source, models}. USD per 1M tokens.
|
|
24
|
-
The response is read as a stream into json.load; only the pricing fields are kept."""
|
|
25
|
-
try:
|
|
26
|
-
with urllib.request.urlopen(url, timeout=timeout) as resp:
|
|
27
|
-
d = json.load(resp)["data"]
|
|
28
|
-
except Exception as ex:
|
|
29
|
-
raise PriceError(f"could not fetch {url}: {ex}") from ex
|
|
30
|
-
f = lambda v: None if v in (None, "") else float(v) * 1e6
|
|
31
|
-
out = {m["id"]: dict(input=f((m.get("pricing") or {}).get("prompt")), output=f((m.get("pricing") or {}).get("completion")),
|
|
32
|
-
cache_read=f((m.get("pricing") or {}).get("input_cache_read")), cache_write=f((m.get("pricing") or {}).get("input_cache_write")),
|
|
33
|
-
cache_write_1h=f((m.get("pricing") or {}).get("input_cache_write_1h"))) for m in d}
|
|
34
|
-
del d
|
|
35
|
-
return dict(fetched=dt.datetime.now().astimezone().isoformat(), source=url, models=out)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def load(path):
|
|
39
|
-
"""A saved prices.json (from `acr.py prices`), for offline runs and the Phase 8 comparison."""
|
|
40
|
-
try:
|
|
41
|
-
with open(path, encoding="utf-8-sig") as fh:
|
|
42
|
-
p = json.load(fh)
|
|
43
|
-
except OSError as ex:
|
|
44
|
-
raise PriceError(f"could not read --prices file {path}: {ex}") from ex
|
|
45
|
-
except ValueError as ex:
|
|
46
|
-
raise PriceError(f"--prices file {path} is not valid JSON: {ex}") from ex
|
|
47
|
-
if not isinstance(p, dict) or not isinstance(p.get("models"), dict):
|
|
48
|
-
raise PriceError(f"--prices file {path} has no 'models' table")
|
|
49
|
-
p.setdefault("source", SOURCE_URL)
|
|
50
|
-
p.setdefault("fetched", None)
|
|
51
|
-
p["loaded_from"] = os.path.abspath(path)
|
|
52
|
-
return p
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def write(prices, outdir):
|
|
56
|
-
os.makedirs(outdir, exist_ok=True)
|
|
57
|
-
path = os.path.join(outdir, PRICES_FILE)
|
|
58
|
-
with open(path, "w", encoding="utf-8") as fh:
|
|
59
|
-
json.dump(prices, fh, indent=1)
|
|
60
|
-
return path
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def ensure(outdir, prices_file=None, url=SOURCE_URL):
|
|
64
|
-
"""Use --prices <file> when given, else fetch live. Writes <outdir>/prices.json. Raises PriceError."""
|
|
65
|
-
p = load(prices_file) if prices_file else fetch(url)
|
|
66
|
-
return write(p, outdir), p
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def norm(model, aliases=None):
|
|
70
|
-
m = (aliases or {}).get(model, model)
|
|
71
|
-
if "/" not in m:
|
|
72
|
-
m = re.sub(r"-(\d{8})$", "", m)
|
|
73
|
-
m = re.sub(r"(\d)-(\d)$", r"\1.\2", m)
|
|
74
|
-
pref = "anthropic/" if m.startswith("claude") else "openai/" if m.startswith("gpt") else "google/" if m.startswith("gemini") else ""
|
|
75
|
-
m = pref + m
|
|
76
|
-
return m
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def rate(model, models, aliases=None):
|
|
80
|
-
"""Returns dict(key, input_usd_per_mtok, output_usd_per_mtok, cache_read, cache_write, cache_write_1h,
|
|
81
|
-
source, price_source) in USD / 1M tokens, or None (unpriced)."""
|
|
82
|
-
if not model or model.startswith("<"): return None
|
|
83
|
-
k = norm(model, aliases)
|
|
84
|
-
if k in models and models[k].get("input") is not None:
|
|
85
|
-
r = models[k]; i = r["input"]; src = {}
|
|
86
|
-
if r.get("cache_read") is not None: cache_read = r["cache_read"]; src["cache_read"] = "listed"
|
|
87
|
-
else: cache_read = i * 0.1; src["cache_read"] = "input*0.1"
|
|
88
|
-
if r.get("cache_write") is not None: cache_write = r["cache_write"]; src["cache_write"] = "listed"
|
|
89
|
-
else: cache_write = i * 1.25; src["cache_write"] = "input*1.25"
|
|
90
|
-
if r.get("cache_write_1h") is not None: cache_write_1h = r["cache_write_1h"]; src["cache_write_1h"] = "listed"
|
|
91
|
-
else: cache_write_1h = i * 2; src["cache_write_1h"] = "input*2"
|
|
92
|
-
return dict(key=k, input_usd_per_mtok=i, output_usd_per_mtok=r.get("output"),
|
|
93
|
-
cache_read=cache_read, cache_write=cache_write, cache_write_1h=cache_write_1h,
|
|
94
|
-
source="openrouter-public-list", price_source=src)
|
|
95
|
-
return None
|