@antoneeo/kb-agentic-skill 1.34.0 → 1.35.1
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/CHANGELOG.md +36 -0
- package/README.md +3 -7
- package/gemini-extension.json +1 -1
- package/package.json +1 -1
- package/scripts/init.js +6 -6
- package/skills/kb-agentic-skill/ENFORCEMENT.md +10 -0
- package/skills/kb-agentic-skill/SKILL.md +1 -1
- package/skills/kb-agentic-skill/scripts/sdlc_core.py +377 -25
- package/skills/kb-agentic-skill/templates.md +1 -1
- package/skills/kb-agentic-skill/vision.md +308 -308
|
@@ -35,6 +35,7 @@ but are deprecated: new documents should use the English forms.
|
|
|
35
35
|
Standard library only (Python >= 3.8). Windows and POSIX compatible.
|
|
36
36
|
"""
|
|
37
37
|
import argparse
|
|
38
|
+
import base64
|
|
38
39
|
import hashlib
|
|
39
40
|
import json
|
|
40
41
|
import os
|
|
@@ -1377,9 +1378,12 @@ def _open_units(root):
|
|
|
1377
1378
|
return units
|
|
1378
1379
|
|
|
1379
1380
|
|
|
1380
|
-
def _git_out(root, *args, timeout=30):
|
|
1381
|
+
def _git_out(root, *args, timeout=30, env=None):
|
|
1382
|
+
# `env` is merged into the inherited environment, never a replacement: a bare
|
|
1383
|
+
# dict would drop PATH and fail silently on Windows.
|
|
1381
1384
|
r = subprocess.run(["git", *args], cwd=str(root), capture_output=True, text=True,
|
|
1382
|
-
encoding="utf-8", errors="replace", timeout=timeout
|
|
1385
|
+
encoding="utf-8", errors="replace", timeout=timeout,
|
|
1386
|
+
env={**os.environ, **env} if env else None)
|
|
1383
1387
|
return r.stdout if r.returncode == 0 else None
|
|
1384
1388
|
|
|
1385
1389
|
|
|
@@ -2314,6 +2318,29 @@ ORIENT_HOOK_CONFIG_CAP = 1024 * 1024 # settings are tiny; cap pathological file
|
|
|
2314
2318
|
_ORIENT_HOOK_CMD_RE = re.compile(r" orient(\s|$)")
|
|
2315
2319
|
_ORIENT_HOOK_TOKEN_RE = re.compile(r'"([^"]*)"|(\S+)')
|
|
2316
2320
|
|
|
2321
|
+
# Same fixed, versioned carrier as scripts/lib.js; only JSON data is decoded.
|
|
2322
|
+
_CODEX_HOOK_WRAPPER = "import base64,json,subprocess,sys;d=json.loads(base64.b64decode(sys.argv[2]));subprocess.run([sys.executable,d['validator'],*d['argv']],input=sys.stdin.buffer.read())"
|
|
2323
|
+
|
|
2324
|
+
|
|
2325
|
+
def _decode_hook_invocation(command):
|
|
2326
|
+
middle = ' -c "' + _CODEX_HOOK_WRAPPER + '" agentic-sdlc-hook-v1 '
|
|
2327
|
+
if not isinstance(command, str) or middle not in command:
|
|
2328
|
+
return None
|
|
2329
|
+
prefix, encoded = command.split(middle, 1)
|
|
2330
|
+
if not re.fullmatch(r'[\w.-]+|"[^"$`\r\n]+"', prefix):
|
|
2331
|
+
return None
|
|
2332
|
+
try:
|
|
2333
|
+
data = json.loads(base64.b64decode(encoded, validate=True))
|
|
2334
|
+
if (not isinstance(data, dict) or data.get("client") != "codex"
|
|
2335
|
+
or not isinstance(data.get("validator"), str)
|
|
2336
|
+
or not isinstance(data.get("argv"), list) or not data["argv"]
|
|
2337
|
+
or not all(isinstance(a, str) for a in data["argv"])
|
|
2338
|
+
or data["argv"][0] not in ("orient", "remind", "verdict", "constraints")):
|
|
2339
|
+
return None
|
|
2340
|
+
return data
|
|
2341
|
+
except (ValueError, TypeError):
|
|
2342
|
+
return None
|
|
2343
|
+
|
|
2317
2344
|
|
|
2318
2345
|
def _orient_entries_in(p):
|
|
2319
2346
|
"""Yield the SessionStart commands invoking an orient entry point from ONE
|
|
@@ -2324,11 +2351,20 @@ def _orient_entries_in(p):
|
|
|
2324
2351
|
try:
|
|
2325
2352
|
if not p.is_file() or p.stat().st_size > ORIENT_HOOK_CONFIG_CAP:
|
|
2326
2353
|
return
|
|
2327
|
-
|
|
2354
|
+
if p.suffix == ".toml":
|
|
2355
|
+
import tomllib
|
|
2356
|
+
data = tomllib.loads(p.read_text(encoding="utf-8-sig"))
|
|
2357
|
+
else:
|
|
2358
|
+
data = json.loads(p.read_text(encoding="utf-8-sig"))
|
|
2328
2359
|
except Exception:
|
|
2329
2360
|
return
|
|
2330
2361
|
if not isinstance(data, dict):
|
|
2331
2362
|
return
|
|
2363
|
+
features = data.get("features")
|
|
2364
|
+
if p.name in ("hooks.json", "config.toml") and (
|
|
2365
|
+
isinstance(features, dict) and features.get("hooks") is False
|
|
2366
|
+
or data.get("allow_managed_hooks_only") is True):
|
|
2367
|
+
return
|
|
2332
2368
|
hooks = data.get("hooks")
|
|
2333
2369
|
groups = hooks.get("SessionStart") if isinstance(hooks, dict) else None
|
|
2334
2370
|
if groups is None:
|
|
@@ -2338,12 +2374,20 @@ def _orient_entries_in(p):
|
|
|
2338
2374
|
for group in groups:
|
|
2339
2375
|
if not isinstance(group, dict):
|
|
2340
2376
|
continue
|
|
2377
|
+
codex = p.name in ("hooks.json", "config.toml")
|
|
2378
|
+
if codex and group.get("enabled") is False:
|
|
2379
|
+
continue
|
|
2341
2380
|
inner = group.get("hooks")
|
|
2342
2381
|
for h in inner if isinstance(inner, list) else [group]:
|
|
2382
|
+
if codex and (not isinstance(h, dict) or h.get("enabled") is False or h.get("type") != "command"):
|
|
2383
|
+
continue
|
|
2343
2384
|
cmd = h.get("command") if isinstance(h, dict) else None
|
|
2344
|
-
if
|
|
2345
|
-
|
|
2346
|
-
|
|
2385
|
+
if isinstance(h, dict) and p.name in ("hooks.json", "config.toml") and os.name == "nt":
|
|
2386
|
+
cmd = h.get("commandWindows") or h.get("command_windows") or cmd
|
|
2387
|
+
invocation = _decode_hook_invocation(cmd)
|
|
2388
|
+
if ((invocation and invocation["argv"][0] == "orient") or
|
|
2389
|
+
(isinstance(cmd, str) and any(n in cmd for n in ORIENT_HOOK_ENTRY_POINTS)
|
|
2390
|
+
and _ORIENT_HOOK_CMD_RE.search(cmd))):
|
|
2347
2391
|
yield cmd
|
|
2348
2392
|
|
|
2349
2393
|
|
|
@@ -2362,17 +2406,69 @@ def _orient_user_settings_path():
|
|
|
2362
2406
|
return (Path(cfg) if cfg else Path.home() / ".claude") / "settings.json"
|
|
2363
2407
|
|
|
2364
2408
|
|
|
2409
|
+
def _codex_hook_config(root):
|
|
2410
|
+
"""Observable Codex policy across sources; no trust or execution assertion."""
|
|
2411
|
+
home = Path(os.environ.get("CODEX_HOME") or Path.home() / ".codex")
|
|
2412
|
+
disabled, unverified, disabled_entries = False, False, False
|
|
2413
|
+
for directory in (home, Path(root) / ".codex"):
|
|
2414
|
+
for name in ("hooks.json", "config.toml"):
|
|
2415
|
+
p = directory / name
|
|
2416
|
+
if not p.exists():
|
|
2417
|
+
continue
|
|
2418
|
+
try:
|
|
2419
|
+
if not p.is_file() or p.stat().st_size > ORIENT_HOOK_CONFIG_CAP:
|
|
2420
|
+
raise ValueError("unreadable configuration")
|
|
2421
|
+
text = p.read_text(encoding="utf-8-sig")
|
|
2422
|
+
if p.suffix == ".toml":
|
|
2423
|
+
import tomllib
|
|
2424
|
+
data = tomllib.loads(text)
|
|
2425
|
+
else:
|
|
2426
|
+
data = json.loads(text)
|
|
2427
|
+
if not isinstance(data, dict):
|
|
2428
|
+
raise ValueError("unknown configuration shape")
|
|
2429
|
+
features = data.get("features", {})
|
|
2430
|
+
hooks = data.get("hooks", {})
|
|
2431
|
+
if not isinstance(features, dict) or not isinstance(hooks, dict):
|
|
2432
|
+
raise ValueError("unknown policy or hooks shape")
|
|
2433
|
+
disabled |= features.get("hooks") is False or data.get("allow_managed_hooks_only") is True
|
|
2434
|
+
groups = hooks.get("SessionStart", data.get("SessionStart", []))
|
|
2435
|
+
if not isinstance(groups, list):
|
|
2436
|
+
raise ValueError("unknown hook groups")
|
|
2437
|
+
for group in groups:
|
|
2438
|
+
if not isinstance(group, dict):
|
|
2439
|
+
raise ValueError("unknown hook group")
|
|
2440
|
+
inner = group.get("hooks", [group])
|
|
2441
|
+
if not isinstance(inner, list) or not all(isinstance(h, dict) for h in inner):
|
|
2442
|
+
raise ValueError("unknown handlers")
|
|
2443
|
+
disabled_entries |= group.get("enabled") is False or any(h.get("enabled") is False for h in inner)
|
|
2444
|
+
except Exception:
|
|
2445
|
+
unverified = True
|
|
2446
|
+
policy = "disabled-by-policy" if disabled else "unverified" if unverified else "enabled"
|
|
2447
|
+
return {"policy": policy, "disabled_entries": disabled_entries}
|
|
2448
|
+
|
|
2449
|
+
|
|
2365
2450
|
def _orient_hook_commands(root):
|
|
2366
2451
|
"""Yield (command, at_user_level, place) across every known client config:
|
|
2367
2452
|
the three project-relative files, then the machine-global user settings --
|
|
2368
2453
|
the file the installer wires (F-042), without which a fixed machine's
|
|
2369
2454
|
projects would read as unwired forever. `place` is a display label, never a
|
|
2370
2455
|
home path (F-075 prints it)."""
|
|
2456
|
+
codex_policy = _codex_hook_config(root)["policy"]
|
|
2371
2457
|
for rel in ORIENT_HOOK_CONFIG_FILES:
|
|
2458
|
+
if rel.startswith(".codex/") and codex_policy != "enabled":
|
|
2459
|
+
continue
|
|
2372
2460
|
for cmd in _orient_entries_in(Path(root) / rel):
|
|
2373
2461
|
yield cmd, False, rel
|
|
2374
2462
|
for cmd in _orient_entries_in(_orient_user_settings_path()):
|
|
2375
2463
|
yield cmd, True, "user settings"
|
|
2464
|
+
if codex_policy != "enabled":
|
|
2465
|
+
return
|
|
2466
|
+
home = Path(os.environ.get("CODEX_HOME") or Path.home() / ".codex")
|
|
2467
|
+
for name in ("hooks.json", "config.toml"):
|
|
2468
|
+
for cmd in _orient_entries_in(home / name):
|
|
2469
|
+
yield cmd, True, "codex user " + name
|
|
2470
|
+
for cmd in _orient_entries_in(Path(root) / ".codex" / name) if name == "config.toml" else ():
|
|
2471
|
+
yield cmd, False, ".codex/" + name
|
|
2376
2472
|
|
|
2377
2473
|
|
|
2378
2474
|
def _orient_entry_live(root, cmd, at_user_level):
|
|
@@ -2383,7 +2479,8 @@ def _orient_entry_live(root, cmd, at_user_level):
|
|
|
2383
2479
|
tokens resolve against the project root (the vendored-validator
|
|
2384
2480
|
convention); a USER-level relative token has no cwd to resolve against and
|
|
2385
2481
|
is treated as cannot-tell."""
|
|
2386
|
-
|
|
2482
|
+
invocation = _decode_hook_invocation(cmd)
|
|
2483
|
+
token = invocation["validator"] if invocation else None
|
|
2387
2484
|
for m in _ORIENT_HOOK_TOKEN_RE.finditer(cmd):
|
|
2388
2485
|
tok = m.group(1) if m.group(1) is not None else m.group(2)
|
|
2389
2486
|
if any(tok.endswith(n) for n in ORIENT_HOOK_ENTRY_POINTS):
|
|
@@ -2410,7 +2507,7 @@ def orient_wiring(root):
|
|
|
2410
2507
|
for cmd, at_user_level, place in _orient_hook_commands(root):
|
|
2411
2508
|
if not _orient_entry_live(root, cmd, at_user_level):
|
|
2412
2509
|
continue
|
|
2413
|
-
client = "codex" if place.startswith(".codex") else "claude"
|
|
2510
|
+
client = "codex" if place.startswith((".codex", "codex ")) else "claude"
|
|
2414
2511
|
out.setdefault(client, {}).setdefault(cmd.strip(), place)
|
|
2415
2512
|
return out
|
|
2416
2513
|
|
|
@@ -2444,6 +2541,13 @@ def print_orient_hook_note(root):
|
|
|
2444
2541
|
does): the note is check-layer behaviour, whoever owns the check."""
|
|
2445
2542
|
try:
|
|
2446
2543
|
state = orient_hook_state(root)
|
|
2544
|
+
codex = _codex_hook_config(root)
|
|
2545
|
+
if codex["policy"] != "enabled" or codex["disabled_entries"]:
|
|
2546
|
+
detail = codex["policy"] if codex["policy"] != "enabled" else "disabled definitions present"
|
|
2547
|
+
print(f"[note] Codex hook configuration: {detail}. Disabled or unverified "
|
|
2548
|
+
"definitions are excluded from wiring counts; trust and native delivery are not verified.")
|
|
2549
|
+
if state == "unwired":
|
|
2550
|
+
return
|
|
2447
2551
|
if state == "unwired":
|
|
2448
2552
|
print("[note] agent sessions start without automatic orientation on this "
|
|
2449
2553
|
"machine (no session-orientation hook found at project or user level). "
|
|
@@ -2481,10 +2585,64 @@ def cmd_check(root, strict=False, hybrid=False, extra_validate=None, extra_secti
|
|
|
2481
2585
|
failed = any(rc for _, rc in rcs)
|
|
2482
2586
|
print(f"\ncheck: {'NOT CLEAN' if failed else 'CLEAN'} "
|
|
2483
2587
|
f"({', '.join(f'{title} rc={rc}' for title, rc in rcs)})")
|
|
2484
|
-
|
|
2588
|
+
print_check_notes(root)
|
|
2485
2589
|
return 1 if failed else 0
|
|
2486
2590
|
|
|
2487
2591
|
|
|
2592
|
+
def _attr_pattern(path):
|
|
2593
|
+
"""A .gitattributes pattern matching exactly `path`. Order matters (probed):
|
|
2594
|
+
a backslash, glob characters and a leading `#` or `!` (comment, negation)
|
|
2595
|
+
are escaped first, then the result is C-quoted when it holds whitespace,
|
|
2596
|
+
`"` or a backslash."""
|
|
2597
|
+
p = re.sub(r"([\\\[*?])", r"\\\1", path)
|
|
2598
|
+
if p.startswith(("#", "!")):
|
|
2599
|
+
p = "\\" + p
|
|
2600
|
+
if re.search(r'[\s"\\]', p):
|
|
2601
|
+
p = '"' + p.replace("\\", "\\\\").replace('"', '\\"') + '"'
|
|
2602
|
+
return p
|
|
2603
|
+
|
|
2604
|
+
|
|
2605
|
+
def review_log_union_note(root):
|
|
2606
|
+
"""F-090: the note for a review log git would not merge with union, or None.
|
|
2607
|
+
|
|
2608
|
+
Git itself is asked (`check-attr`), so patterns and nested files count;
|
|
2609
|
+
personal and system attribute files do not, so the answer is the one a
|
|
2610
|
+
teammate's clone gets. Only `unspecified` is a gap: `union` or any other
|
|
2611
|
+
driver is a choice. Residual: `.git/info/attributes` is still read. Any
|
|
2612
|
+
failure -- no git, not a work tree, timeout -- is no note: `check` never
|
|
2613
|
+
breaks on it."""
|
|
2614
|
+
try:
|
|
2615
|
+
log = ai_path(root, "audit", "reviews", "REVIEW_LOG.md")
|
|
2616
|
+
if not log.is_file():
|
|
2617
|
+
return None
|
|
2618
|
+
prefix = _git_out(root, "rev-parse", "--show-prefix", timeout=3)
|
|
2619
|
+
if prefix is None:
|
|
2620
|
+
return None
|
|
2621
|
+
rel = log.resolve().relative_to(Path(root).resolve()).as_posix()
|
|
2622
|
+
out = _git_out(root, "-c", "core.attributesFile=", "check-attr", "-z", "merge",
|
|
2623
|
+
"--", rel, timeout=3, env={"GIT_ATTR_NOSYSTEM": "1"})
|
|
2624
|
+
if out is None:
|
|
2625
|
+
return None
|
|
2626
|
+
fields = out.split("\0")
|
|
2627
|
+
if len(fields) < 3 or fields[2] != "unspecified":
|
|
2628
|
+
return None
|
|
2629
|
+
path = prefix.rstrip("\r\n") + rel # a folder may begin with a space
|
|
2630
|
+
return (f"[note] {path} has no merge attribute: two branches that both add review "
|
|
2631
|
+
"rows conflict when merged. Fix: add this line to .gitattributes at the "
|
|
2632
|
+
f"repository root: {_attr_pattern(path)} merge=union")
|
|
2633
|
+
except Exception:
|
|
2634
|
+
return None
|
|
2635
|
+
|
|
2636
|
+
|
|
2637
|
+
def print_check_notes(root):
|
|
2638
|
+
"""Every check-layer note, informational and never an exit code. The one
|
|
2639
|
+
place an overlay that replaces `check` calls, so a new note cannot miss it."""
|
|
2640
|
+
print_orient_hook_note(root)
|
|
2641
|
+
note = review_log_union_note(root)
|
|
2642
|
+
if note:
|
|
2643
|
+
print(note)
|
|
2644
|
+
|
|
2645
|
+
|
|
2488
2646
|
# --------------------------------------------------------------------- gate
|
|
2489
2647
|
|
|
2490
2648
|
# --- UserPromptSubmit reminder hook (F-046) --------------------------------
|
|
@@ -2643,6 +2801,192 @@ _DECLARATION_RE = re.compile(
|
|
|
2643
2801
|
_GUIDE_NAME_RE = re.compile(r"GUIDE_[A-Za-z0-9_-]+\.md")
|
|
2644
2802
|
|
|
2645
2803
|
|
|
2804
|
+
def _hint_path(value, cwd):
|
|
2805
|
+
if not isinstance(value, str) or not value:
|
|
2806
|
+
return None
|
|
2807
|
+
p = Path(value)
|
|
2808
|
+
if not p.is_absolute():
|
|
2809
|
+
if not cwd or not Path(cwd).is_absolute():
|
|
2810
|
+
return None
|
|
2811
|
+
p = Path(cwd) / p
|
|
2812
|
+
return str(p.resolve())
|
|
2813
|
+
|
|
2814
|
+
|
|
2815
|
+
def hook_edits(payload):
|
|
2816
|
+
"""Parse the complete native apply_patch syntax without executing it.
|
|
2817
|
+
|
|
2818
|
+
Unknown or incomplete input yields no partial target set. Move checks both
|
|
2819
|
+
the old and new paths; file membership is evaluated by the existing gate.
|
|
2820
|
+
"""
|
|
2821
|
+
command = (payload.get("tool_input") or {}).get("command")
|
|
2822
|
+
if not isinstance(command, str) or len(command.encode("utf-8")) > VERDICT_LINE_MAX:
|
|
2823
|
+
return None
|
|
2824
|
+
lines = command.strip().splitlines()
|
|
2825
|
+
if not lines or lines[0] != "*** Begin Patch" or lines[-1] != "*** End Patch":
|
|
2826
|
+
return None
|
|
2827
|
+
edits, current, mode, changed = [], None, None, False
|
|
2828
|
+
for line in lines[1:-1]:
|
|
2829
|
+
match = re.fullmatch(r"\*\*\* (Add|Update|Delete) File: (.+)", line)
|
|
2830
|
+
if match:
|
|
2831
|
+
if current is not None and mode != "Delete" and not changed:
|
|
2832
|
+
return None
|
|
2833
|
+
mode, value = match.groups()
|
|
2834
|
+
target = _hint_path(value, payload.get("cwd"))
|
|
2835
|
+
if not target:
|
|
2836
|
+
return None
|
|
2837
|
+
current = {"path": target, "new_text": ""}
|
|
2838
|
+
edits.append(current)
|
|
2839
|
+
changed = False
|
|
2840
|
+
elif line.startswith("*** Move to: ") and current is not None and mode == "Update" and not changed:
|
|
2841
|
+
target = _hint_path(line[len("*** Move to: "):], payload.get("cwd"))
|
|
2842
|
+
if not target:
|
|
2843
|
+
return None
|
|
2844
|
+
current = {"path": target, "new_text": ""}
|
|
2845
|
+
edits.append(current)
|
|
2846
|
+
elif current is not None and mode != "Delete" and (
|
|
2847
|
+
line.startswith(("+", "-", " ", "@@")) or line == "*** End of File"):
|
|
2848
|
+
if mode == "Add" and not line.startswith("+"):
|
|
2849
|
+
return None
|
|
2850
|
+
if line.startswith(("+", "-")):
|
|
2851
|
+
changed = True
|
|
2852
|
+
if line.startswith("+"):
|
|
2853
|
+
current["new_text"] += line[1:] + "\n"
|
|
2854
|
+
else:
|
|
2855
|
+
return None
|
|
2856
|
+
if current is not None and mode != "Delete" and not changed:
|
|
2857
|
+
return None
|
|
2858
|
+
return edits or None
|
|
2859
|
+
|
|
2860
|
+
|
|
2861
|
+
def shell_read_paths(command, cwd, workdir=None):
|
|
2862
|
+
"""Literal Get-Content/cat reads only: no shell expansion or execution."""
|
|
2863
|
+
if not isinstance(command, str) or re.search(r"[$`\r\n;|&<>\x00]", command):
|
|
2864
|
+
return None
|
|
2865
|
+
token_re = re.compile(r"\s*(?:'([^']*)'|\"([^\"]*)\"|([^\s'\"]+))")
|
|
2866
|
+
tokens, pos = [], 0
|
|
2867
|
+
while pos < len(command.rstrip()):
|
|
2868
|
+
match = token_re.match(command, pos)
|
|
2869
|
+
if not match:
|
|
2870
|
+
return None
|
|
2871
|
+
token = next(x for x in match.groups() if x is not None)
|
|
2872
|
+
tokens.append(token)
|
|
2873
|
+
pos = match.end()
|
|
2874
|
+
if not tokens or tokens[0].lower() not in ("get-content", "cat"):
|
|
2875
|
+
return None
|
|
2876
|
+
paths, i = [], 1
|
|
2877
|
+
while i < len(tokens):
|
|
2878
|
+
token = tokens[i]
|
|
2879
|
+
if tokens[0].lower() == "get-content" and token.lower() in ("-literalpath", "-path", "-raw"):
|
|
2880
|
+
if token.lower() != "-raw" and i + 1 == len(tokens):
|
|
2881
|
+
return None
|
|
2882
|
+
elif tokens[0].lower() == "get-content" and token.lower() == "-totalcount":
|
|
2883
|
+
i += 1
|
|
2884
|
+
if i == len(tokens) or not tokens[i].isdigit():
|
|
2885
|
+
return None
|
|
2886
|
+
elif tokens[0] == "cat" and token == "--":
|
|
2887
|
+
pass
|
|
2888
|
+
elif token.startswith("-") or re.search(r"[*?\[\],]", token):
|
|
2889
|
+
return None
|
|
2890
|
+
else:
|
|
2891
|
+
base = _hint_path(workdir, cwd) if workdir else cwd
|
|
2892
|
+
resolved = _hint_path(token, base)
|
|
2893
|
+
if not resolved:
|
|
2894
|
+
return None
|
|
2895
|
+
paths.append(resolved)
|
|
2896
|
+
i += 1
|
|
2897
|
+
return paths or None
|
|
2898
|
+
|
|
2899
|
+
|
|
2900
|
+
def _codex_literal_calls(code):
|
|
2901
|
+
"""Recognize a small non-executable JS carrier grammar, otherwise nothing."""
|
|
2902
|
+
if not isinstance(code, str):
|
|
2903
|
+
return []
|
|
2904
|
+
calls, pos = [], 0
|
|
2905
|
+
pattern = re.compile(r"\s*(?:text\(\s*)?await\s+tools\.exec_command\((\{.*?\})\)\s*\)?\s*;?", re.DOTALL)
|
|
2906
|
+
field = re.compile(r'\s*(?:"(cmd|workdir)"|(cmd|workdir))\s*:\s*("(?:[^"\\]|\\.)*")\s*(,|$)')
|
|
2907
|
+
while pos < len(code.rstrip()):
|
|
2908
|
+
match = pattern.match(code, pos)
|
|
2909
|
+
if not match:
|
|
2910
|
+
return []
|
|
2911
|
+
obj, off, args = match[1][1:-1], 0, {}
|
|
2912
|
+
while off < len(obj.rstrip()):
|
|
2913
|
+
item = field.match(obj, off)
|
|
2914
|
+
if not item or (item[1] or item[2]) in args:
|
|
2915
|
+
return []
|
|
2916
|
+
try:
|
|
2917
|
+
args[item[1] or item[2]] = json.loads(item[3])
|
|
2918
|
+
except ValueError:
|
|
2919
|
+
return []
|
|
2920
|
+
off = item.end()
|
|
2921
|
+
if "cmd" not in args:
|
|
2922
|
+
return []
|
|
2923
|
+
calls.append(args)
|
|
2924
|
+
pos = match.end()
|
|
2925
|
+
return calls
|
|
2926
|
+
|
|
2927
|
+
|
|
2928
|
+
def transcript_events(path):
|
|
2929
|
+
"""Yield legacy assistant blocks, plus normalized recognized Codex blocks.
|
|
2930
|
+
|
|
2931
|
+
This is read-only and bounded by the existing transcript limits. Historical
|
|
2932
|
+
cwd is taken from host metadata, never guessed from the present process.
|
|
2933
|
+
"""
|
|
2934
|
+
cwd = None
|
|
2935
|
+
with Path(path).open("rb") as fh:
|
|
2936
|
+
for raw in fh:
|
|
2937
|
+
if len(raw) > VERDICT_LINE_MAX:
|
|
2938
|
+
continue
|
|
2939
|
+
try:
|
|
2940
|
+
entry = json.loads(raw.decode("utf-8", errors="replace"))
|
|
2941
|
+
except ValueError:
|
|
2942
|
+
continue
|
|
2943
|
+
if not isinstance(entry, dict):
|
|
2944
|
+
continue
|
|
2945
|
+
if entry.get("type") == "assistant":
|
|
2946
|
+
yield entry
|
|
2947
|
+
continue
|
|
2948
|
+
data = entry.get("payload")
|
|
2949
|
+
if not isinstance(data, dict):
|
|
2950
|
+
continue
|
|
2951
|
+
if entry.get("type") in ("session_meta", "turn_context"):
|
|
2952
|
+
if isinstance(data.get("cwd"), str):
|
|
2953
|
+
cwd = data["cwd"]
|
|
2954
|
+
continue
|
|
2955
|
+
if entry.get("type") != "response_item":
|
|
2956
|
+
continue
|
|
2957
|
+
blocks = []
|
|
2958
|
+
if data.get("type") == "message" and data.get("role") == "assistant":
|
|
2959
|
+
blocks = [{"type": "text", "text": x.get("text", "")}
|
|
2960
|
+
for x in (data.get("content") if isinstance(data.get("content"), list) else []) if isinstance(x, dict) and x.get("type") == "output_text"]
|
|
2961
|
+
elif data.get("type") in ("function_call", "custom_tool_call"):
|
|
2962
|
+
name = data.get("name")
|
|
2963
|
+
calls = []
|
|
2964
|
+
if name in ("exec_command", "Bash"):
|
|
2965
|
+
try:
|
|
2966
|
+
args = json.loads(data.get("arguments", "{}"))
|
|
2967
|
+
except (ValueError, TypeError):
|
|
2968
|
+
args = None
|
|
2969
|
+
if isinstance(args, dict):
|
|
2970
|
+
calls = [args]
|
|
2971
|
+
elif name == "exec":
|
|
2972
|
+
calls = _codex_literal_calls(data.get("input"))
|
|
2973
|
+
elif name == "apply_patch":
|
|
2974
|
+
command = data.get("input")
|
|
2975
|
+
if command is None:
|
|
2976
|
+
try:
|
|
2977
|
+
command = json.loads(data.get("arguments", "{}" )).get("command")
|
|
2978
|
+
except (ValueError, TypeError, AttributeError):
|
|
2979
|
+
pass
|
|
2980
|
+
for edit in hook_edits({"tool_input": {"command": command}, "cwd": cwd}) or []:
|
|
2981
|
+
blocks.append({"type": "tool_use", "name": "Write", "input": {"file_path": edit["path"]}})
|
|
2982
|
+
for args in calls:
|
|
2983
|
+
for target in shell_read_paths(args.get("cmd", args.get("command")), cwd, args.get("workdir")) or []:
|
|
2984
|
+
blocks.append({"type": "tool_use", "name": "Read", "input": {"file_path": target}})
|
|
2985
|
+
if blocks:
|
|
2986
|
+
yield {"type": "assistant", "isSidechain": bool(entry.get("agent_id") or data.get("agent_id")),
|
|
2987
|
+
"message": {"content": blocks}}
|
|
2988
|
+
|
|
2989
|
+
|
|
2646
2990
|
def transcript_facts(path):
|
|
2647
2991
|
"""What the session transcript shows about the verdict duty, or None when it
|
|
2648
2992
|
cannot be read within the bounds.
|
|
@@ -2657,14 +3001,7 @@ def transcript_facts(path):
|
|
|
2657
3001
|
p = Path(path)
|
|
2658
3002
|
if not p.is_file() or p.stat().st_size > VERDICT_MAX_BYTES:
|
|
2659
3003
|
return None
|
|
2660
|
-
|
|
2661
|
-
for raw in fh:
|
|
2662
|
-
if len(raw) > VERDICT_LINE_MAX or b'"assistant"' not in raw:
|
|
2663
|
-
continue
|
|
2664
|
-
try:
|
|
2665
|
-
entry = json.loads(raw.decode("utf-8", errors="replace"))
|
|
2666
|
-
except ValueError:
|
|
2667
|
-
continue
|
|
3004
|
+
for entry in transcript_events(p):
|
|
2668
3005
|
if not isinstance(entry, dict) or entry.get("type") != "assistant":
|
|
2669
3006
|
continue
|
|
2670
3007
|
content = (entry.get("message") or {}).get("content")
|
|
@@ -2698,6 +3035,13 @@ def transcript_facts(path):
|
|
|
2698
3035
|
def verdict_reason(payload, root=None, docs_name=None):
|
|
2699
3036
|
"""The refusal line for this edit event, or None when the edit may proceed.
|
|
2700
3037
|
Without a root, the project is the one holding the edited file (hook_project)."""
|
|
3038
|
+
if payload.get("tool_name") == "apply_patch" and not payload.get("agent_id"):
|
|
3039
|
+
for edit in hook_edits(payload) or []:
|
|
3040
|
+
reason = verdict_reason({**payload, "tool_name": "Edit", "tool_input": {
|
|
3041
|
+
"file_path": edit["path"], "new_string": edit["new_text"]}}, root, docs_name)
|
|
3042
|
+
if reason:
|
|
3043
|
+
return reason
|
|
3044
|
+
return None
|
|
2701
3045
|
if payload.get("tool_name") not in VERDICT_EDIT_TOOLS or payload.get("agent_id"):
|
|
2702
3046
|
return None
|
|
2703
3047
|
tool_input = payload.get("tool_input") or {}
|
|
@@ -3056,14 +3400,7 @@ def transcript_work(path):
|
|
|
3056
3400
|
p = Path(path)
|
|
3057
3401
|
if not p.is_file() or p.stat().st_size > VERDICT_MAX_BYTES:
|
|
3058
3402
|
return None
|
|
3059
|
-
|
|
3060
|
-
for raw in fh:
|
|
3061
|
-
if len(raw) > VERDICT_LINE_MAX or b'"assistant"' not in raw:
|
|
3062
|
-
continue
|
|
3063
|
-
try:
|
|
3064
|
-
entry = json.loads(raw.decode("utf-8", errors="replace"))
|
|
3065
|
-
except ValueError:
|
|
3066
|
-
continue
|
|
3403
|
+
for entry in transcript_events(p):
|
|
3067
3404
|
if not isinstance(entry, dict) or entry.get("type") != "assistant":
|
|
3068
3405
|
continue
|
|
3069
3406
|
content = (entry.get("message") or {}).get("content")
|
|
@@ -3118,6 +3455,17 @@ def constraints_hook_context(payload, root=None, docs_name=None):
|
|
|
3118
3455
|
a subagent, on a file of a project whose open L3 code unit binds it (or the
|
|
3119
3456
|
unit's own ANALYSIS, about to name a path a P row binds -- UC6), by a session
|
|
3120
3457
|
that worked on that unit and last declared L3."""
|
|
3458
|
+
if payload.get("tool_name") == "apply_patch" and not payload.get("agent_id"):
|
|
3459
|
+
lines = []
|
|
3460
|
+
for edit in hook_edits(payload) or []:
|
|
3461
|
+
context = constraints_hook_context({**payload, "tool_name": "Edit", "tool_input": {
|
|
3462
|
+
"file_path": edit["path"], "new_string": edit["new_text"]}}, root, docs_name)
|
|
3463
|
+
for line in (context or "").splitlines():
|
|
3464
|
+
if line not in lines:
|
|
3465
|
+
lines.append(line)
|
|
3466
|
+
if len(lines) > CONSTRAINTS_HOOK_LINES:
|
|
3467
|
+
lines = lines[:CONSTRAINTS_HOOK_LINES - 1] + [lines[-1]]
|
|
3468
|
+
return "\n".join(lines) or None
|
|
3121
3469
|
if payload.get("tool_name") not in VERDICT_EDIT_TOOLS or payload.get("agent_id"):
|
|
3122
3470
|
return None
|
|
3123
3471
|
tool_input = payload.get("tool_input") or {}
|
|
@@ -3808,6 +4156,10 @@ def cmd_orient(args):
|
|
|
3808
4156
|
for client, entries in sorted(orient_wiring(root).items()):
|
|
3809
4157
|
if len(entries) > 1:
|
|
3810
4158
|
places = ", ".join(sorted(set(entries.values())))
|
|
4159
|
+
if client == "codex":
|
|
4160
|
+
tail.append(f"[note] Codex has {len(entries)} configured orientation definitions "
|
|
4161
|
+
f"({places}); trust and runtime policy determine delivery. Keep one equivalent definition.")
|
|
4162
|
+
continue
|
|
3811
4163
|
tail.append(f"[note] session orientation is wired {len(entries)} times for one "
|
|
3812
4164
|
f"client ({places}): each session receives every copy. Keep one "
|
|
3813
4165
|
"entry and remove the others.")
|
|
@@ -602,7 +602,7 @@ Concurrent reviews: `init` writes a `.gitattributes` stanza giving this file
|
|
|
602
602
|
Rows are date-stamped and their order carries no meaning, so a union merge keeps
|
|
603
603
|
both sides instead of asking a human to choose. It is defence in depth: without
|
|
604
604
|
git, or without the stanza, the outcome is today's — one conflict you resolve by
|
|
605
|
-
hand, never a lost row.
|
|
605
|
+
hand, never a lost row. `check` names a missing stanza and the line to add (F-090).
|
|
606
606
|
|
|
607
607
|
|
|
608
608
|
## ai_docs/audit/HANDOFF_[topic].md — one open workstream, its own file
|