@andespindola/crow-skills 0.9.0 → 0.10.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/README.md +3 -3
- package/crow_skills/__init__.py +1 -1
- package/crow_skills/broadcast.py +987 -0
- package/crow_skills/cli.py +170 -0
- package/crow_skills/events.py +46 -4
- package/crow_skills/hook.py +256 -13
- package/crow_skills/integrations.py +277 -26
- package/crow_skills/resources.py +326 -102
- package/docs/cli.md +43 -17
- package/package.json +1 -1
- package/release.json +26 -16
- package/skills/crow-behaviour/SKILL.md +3 -1
- package/skills/crow-behaviour/references/broadcast.md +45 -0
- package/skills/crow-behaviour/references/orchestration.md +2 -0
- package/skills/crow-behaviour/references/progress-ledger.md +1 -1
- package/skills/crow-behaviour/references/resources.md +25 -5
- package/skills/crow-behaviour/scripts/crow_ledger.py +7 -1
|
@@ -56,9 +56,13 @@ OWNERS = {"claude-statusline": ("claude",), "claude-hooks": ("claude",), "claude
|
|
|
56
56
|
"devin-hooks": ("devin",), "tmux-status": ("claude", "codex", "gemini", "devin")}
|
|
57
57
|
HOOK_SCRIPT = "crow_hook.py"
|
|
58
58
|
RESOURCES_SCRIPT = "crow_resources.py"
|
|
59
|
+
BROADCAST_SCRIPT = "crow_broadcast.py"
|
|
59
60
|
COMMAND_HEADER = "Gerenciado por crow-skills (comando /crow). Não edite; use crow-skills integrations."
|
|
60
61
|
BEGIN = "# >>> crow-skills integrations (gerenciado; use crow-skills integrations uninstall) >>>"
|
|
61
62
|
END = "# <<< crow-skills integrations <<<"
|
|
63
|
+
# codex-hooks inside ~/.codex/config.toml, used when ~/.codex/hooks.json is a symlink (a dotfiles repo) or unsafe.
|
|
64
|
+
HOOKS_BEGIN = "# >>> crow-skills codex-hooks (gerenciado; use crow-skills integrations uninstall) >>>"
|
|
65
|
+
HOOKS_END = "# <<< crow-skills codex-hooks <<<"
|
|
62
66
|
CODEX_ITEMS = ["model-with-reasoning", "context-remaining", "current-dir", "task-progress", "used-tokens"]
|
|
63
67
|
SNIPPET_HEADER = "# Gerenciado por crow-skills (integração tmux). Não edite; use crow-skills integrations."
|
|
64
68
|
UNSUPPORTED = {
|
|
@@ -126,13 +130,21 @@ def resources_source():
|
|
|
126
130
|
return (Path(__file__).resolve().parent / "resources.py").read_bytes()
|
|
127
131
|
|
|
128
132
|
|
|
133
|
+
def broadcast_script_path(store):
|
|
134
|
+
return root(store) / BROADCAST_SCRIPT
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def broadcast_source():
|
|
138
|
+
return (Path(__file__).resolve().parent / "broadcast.py").read_bytes()
|
|
139
|
+
|
|
140
|
+
|
|
129
141
|
def remove_bytecode(store):
|
|
130
142
|
"""__pycache__ beside the copied scripts (written when the status line imports crow_hook):
|
|
131
143
|
removed with them, only when it holds nothing but their bytecode."""
|
|
132
144
|
cache = root(store) / "__pycache__"
|
|
133
145
|
if cache.is_symlink() or not cache.is_dir():
|
|
134
146
|
return
|
|
135
|
-
names = ("crow_progress.", "crow_hook.", "crow_resources.")
|
|
147
|
+
names = ("crow_progress.", "crow_hook.", "crow_resources.", "crow_broadcast.")
|
|
136
148
|
entries = list(cache.iterdir())
|
|
137
149
|
if all(e.is_file() and not e.is_symlink() and e.name.startswith(names) and e.suffix == ".pyc" for e in entries):
|
|
138
150
|
try:
|
|
@@ -146,7 +158,7 @@ def remove_bytecode(store):
|
|
|
146
158
|
def scripts(store):
|
|
147
159
|
"""(installed path, source bytes) of every script the hooks and status lines run."""
|
|
148
160
|
return ((script_path(store), script_source()), (hook_script_path(store), hook_source()),
|
|
149
|
-
(resources_script_path(store), resources_source()))
|
|
161
|
+
(resources_script_path(store), resources_source()), (broadcast_script_path(store), broadcast_source()))
|
|
150
162
|
|
|
151
163
|
|
|
152
164
|
def quoted_ok(*paths):
|
|
@@ -365,37 +377,57 @@ def codex_hooks_feature(home):
|
|
|
365
377
|
return " Habilite também [features] hooks = true em ~/.codex/config.toml (não alterado pelo crow-skills)."
|
|
366
378
|
|
|
367
379
|
|
|
368
|
-
def hook_command(store, home, python, host, event):
|
|
380
|
+
def hook_command(store, home, python, host, event, check=False):
|
|
369
381
|
return (shlex.quote(str(python)) + " -I -S " + shlex.quote(str(hook_script_path(store))) + " hook --host " + host +
|
|
370
|
-
" --event " + event + " --home " + shlex.quote(str(home)))
|
|
382
|
+
" --event " + event + (" --check" if check else "") + " --home " + shlex.quote(str(home)))
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
# crow-broadcast: Claude Code and Codex record tool events asynchronously (their output is
|
|
386
|
+
# ignored), so a second, synchronous and read-only PreToolUse entry, limited by matcher to the
|
|
387
|
+
# edit and shell tools, injects the conflict warning (or blocks, with broadcast.block_on_conflict).
|
|
388
|
+
CHECK_MATCHERS = {"claude": "Edit|Write|MultiEdit|NotebookEdit|Bash", "codex": "apply_patch|Bash"}
|
|
389
|
+
# Antigravity wraps tool events in {"matcher", "hooks"} groups; the other events are flat lists.
|
|
390
|
+
AGY_GROUPED = ("PreToolUse", "PostToolUse")
|
|
371
391
|
|
|
372
392
|
|
|
373
393
|
def hook_entries(store, home, python, host):
|
|
374
|
-
"""{event: [
|
|
394
|
+
"""{event: [item]} in the host's own schema: groups ({"hooks": [...], "matcher"?}) for the
|
|
395
|
+
"groups" layout, the agy block's own items (flat handlers or matcher groups) for agy."""
|
|
375
396
|
command = lambda event: hook_command(store, home, python, host, event) # noqa: E731
|
|
376
|
-
if host
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
397
|
+
if host in ("claude", "codex"):
|
|
398
|
+
events = CLAUDE_EVENTS if host == "claude" else CODEX_EVENTS
|
|
399
|
+
result = {e: [{"hooks": [dict({"type": "command", "command": command(e), "timeout": 5}, **({"async": True} if a else {}))]}]
|
|
400
|
+
for e, a in events}
|
|
401
|
+
result["PreToolUse"].append({"matcher": CHECK_MATCHERS[host], "hooks": [
|
|
402
|
+
{"type": "command", "command": hook_command(store, home, python, host, "PreToolUse", check=True), "timeout": 5}]})
|
|
403
|
+
return result
|
|
382
404
|
if host == "gemini":
|
|
383
|
-
return {e: [{"type": "command", "name": "crow-skills-" + e, "command": command(e), "timeout": 3000}]
|
|
405
|
+
return {e: [{"hooks": [{"type": "command", "name": "crow-skills-" + e, "command": command(e), "timeout": 3000}]}]
|
|
406
|
+
for e in GEMINI_EVENTS}
|
|
384
407
|
if host == "agy":
|
|
385
|
-
return {e: [{"type": "command", "command": command(e), "timeout": 3}]
|
|
386
|
-
|
|
408
|
+
return {e: ([{"matcher": "", "hooks": [{"type": "command", "command": command(e), "timeout": 3}]}] if e in AGY_GROUPED
|
|
409
|
+
else [{"type": "command", "command": command(e), "timeout": 3}]) for e in AGY_EVENTS}
|
|
410
|
+
return {e: [{"hooks": [{"type": "command", "command": command(e)}]}] for e in DEVIN_EVENTS}
|
|
387
411
|
|
|
388
412
|
|
|
389
413
|
def is_ours(entry, store):
|
|
390
414
|
return isinstance(entry, dict) and isinstance(entry.get("command"), str) and str(hook_script_path(store)) in entry["command"]
|
|
391
415
|
|
|
392
416
|
|
|
417
|
+
def ours_item(item, store):
|
|
418
|
+
"""An agy block item of ours: a handler, or a matcher group holding only our handlers."""
|
|
419
|
+
if is_ours(item, store):
|
|
420
|
+
return True
|
|
421
|
+
hooks = item.get("hooks") if isinstance(item, dict) else None
|
|
422
|
+
return isinstance(hooks, list) and bool(hooks) and all(is_ours(h, store) for h in hooks)
|
|
423
|
+
|
|
424
|
+
|
|
393
425
|
def strip_hooks(data, store, layout):
|
|
394
426
|
"""A copy of the settings without this CLI's hook entries (user entries keep their order)."""
|
|
395
427
|
result = deepcopy(data)
|
|
396
428
|
if layout == "agy":
|
|
397
429
|
block = result.get(AGY_KEY)
|
|
398
|
-
if isinstance(block, dict) and all(isinstance(v, list) and all(
|
|
430
|
+
if isinstance(block, dict) and all(isinstance(v, list) and all(ours_item(e, store) for e in v) for v in block.values()):
|
|
399
431
|
result.pop(AGY_KEY)
|
|
400
432
|
return result
|
|
401
433
|
hooks = result.get("hooks")
|
|
@@ -424,8 +456,9 @@ def strip_hooks(data, store, layout):
|
|
|
424
456
|
|
|
425
457
|
|
|
426
458
|
def refresh_in_place(data, entries, store, layout):
|
|
427
|
-
"""Replace our existing entries where they are (same events,
|
|
428
|
-
never moves the user's hooks or ours;
|
|
459
|
+
"""Replace our existing entries where they are (same events, same number of groups, each in a
|
|
460
|
+
group of its own with the same matcher), so a re-sync never moves the user's hooks or ours;
|
|
461
|
+
None when the layout does not match the desired one (the caller strips and appends)."""
|
|
429
462
|
result = deepcopy(data)
|
|
430
463
|
if layout == "agy":
|
|
431
464
|
if not isinstance(result.get(AGY_KEY), dict):
|
|
@@ -441,10 +474,14 @@ def refresh_in_place(data, entries, store, layout):
|
|
|
441
474
|
for hi, item in enumerate(group.get("hooks", []) if isinstance(group, dict) else []):
|
|
442
475
|
if is_ours(item, store):
|
|
443
476
|
found.setdefault(event, []).append((gi, hi))
|
|
444
|
-
if set(found) != set(entries) or any(len(v) !=
|
|
477
|
+
if set(found) != set(entries) or any(len(v) != len(entries[e]) for e, v in found.items()):
|
|
445
478
|
return None
|
|
446
|
-
for event,
|
|
447
|
-
|
|
479
|
+
for event, places in found.items():
|
|
480
|
+
for (gi, hi), wanted in zip(places, entries[event]):
|
|
481
|
+
group = hooks[event][gi]
|
|
482
|
+
if len(group.get("hooks", [])) != 1 or group.get("matcher") != wanted.get("matcher"):
|
|
483
|
+
return None
|
|
484
|
+
group["hooks"][hi] = wanted["hooks"][0]
|
|
448
485
|
return result
|
|
449
486
|
|
|
450
487
|
|
|
@@ -454,12 +491,30 @@ def add_hooks(data, entries, layout):
|
|
|
454
491
|
result[AGY_KEY] = entries
|
|
455
492
|
return result
|
|
456
493
|
hooks = result.setdefault("hooks", {})
|
|
457
|
-
for event,
|
|
458
|
-
hooks.setdefault(event, []).
|
|
494
|
+
for event, groups in entries.items():
|
|
495
|
+
hooks.setdefault(event, []).extend(deepcopy(groups)) # appended: the user's hooks keep their index (Codex trust)
|
|
459
496
|
return result
|
|
460
497
|
|
|
461
498
|
|
|
462
499
|
def hooks_sync(name, store, home, record, desired, python, dry):
|
|
500
|
+
if name == "codex-hooks":
|
|
501
|
+
unsafe = codex_hooks_json_unsafe(home)
|
|
502
|
+
if record and record.get("mode") != "toml" and unsafe:
|
|
503
|
+
# Installed into a regular hooks.json that has since become a symlink (moved into dotfiles):
|
|
504
|
+
# our entries live in the target now. Keep the record (and the script they call) until the
|
|
505
|
+
# user removes them; then the hooks move to config.toml on the next install.
|
|
506
|
+
left = codex_json_duplicates(home)
|
|
507
|
+
if left:
|
|
508
|
+
return record, "skip", ("~/.codex/hooks.json virou symlink (ou ficou inseguro) depois que o crow-skills gravou nele: "
|
|
509
|
+
+ str(left) + " entrada(s) do crow-skills com crow_hook.py continuam no arquivo de destino, "
|
|
510
|
+
"que o crow-skills não edita. Remova-as de lá" + (" e rode crow-skills integrations install de novo: os hooks "
|
|
511
|
+
"passam para ~/.codex/config.toml." if desired else "; o registro e o script que elas chamam ficam "
|
|
512
|
+
"até isso, para o Codex não chamar um script apagado."))
|
|
513
|
+
record = None
|
|
514
|
+
if not desired:
|
|
515
|
+
return None, "skip", "Entradas do crow-skills já ausentes de ~/.codex/hooks.json; controle encerrado."
|
|
516
|
+
if (record or {}).get("mode") == "toml" or (unsafe and (desired or not record)):
|
|
517
|
+
return codex_hooks_toml_sync(store, home, record, desired, python, dry, unsafe)
|
|
463
518
|
spec = HOOKS[name]
|
|
464
519
|
target = spec["file"](home)
|
|
465
520
|
if desired and not record and spec["requires"] is not None and not os.path.exists(spec["requires"](home)):
|
|
@@ -501,6 +556,192 @@ def hooks_sync(name, store, home, record, desired, python, dry):
|
|
|
501
556
|
return new_record, action, note
|
|
502
557
|
|
|
503
558
|
|
|
559
|
+
# --- codex-hooks in config.toml ------------------------------------------------------------------
|
|
560
|
+
# Codex 0.165 reads hooks from hooks.json and from config.toml (HooksToml: one array of matcher
|
|
561
|
+
# groups per event, each {matcher?, hooks: [{type = "command", command, timeout, async, ...}]};
|
|
562
|
+
# the same schema as hooks.json, read from the binary). When ~/.codex/hooks.json is a symlink
|
|
563
|
+
# (typically into a dotfiles repository) crow-skills never writes through it: the entries go to a
|
|
564
|
+
# marked block at the end of config.toml, verified by parsing and restored byte for byte.
|
|
565
|
+
|
|
566
|
+
def codex_hooks_json_unsafe(home):
|
|
567
|
+
"""Why ~/.codex/hooks.json cannot be edited safely ("symlink" or a reason), or None."""
|
|
568
|
+
path = home / ".codex" / "hooks.json"
|
|
569
|
+
if os.path.islink(path):
|
|
570
|
+
return "symlink"
|
|
571
|
+
try:
|
|
572
|
+
read_regular(protect(path, home))
|
|
573
|
+
except CrowError as exc:
|
|
574
|
+
return str(exc)
|
|
575
|
+
return None
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
def codex_json_duplicates(home):
|
|
579
|
+
"""crow_hook.py entries in ~/.codex/hooks.json when crow-skills does not manage that file
|
|
580
|
+
(read only, through the symlink): with the config.toml block they would run twice."""
|
|
581
|
+
path = home / ".codex" / "hooks.json"
|
|
582
|
+
try:
|
|
583
|
+
if not os.path.exists(path) or os.path.getsize(path) > 1024 * 1024:
|
|
584
|
+
return 0
|
|
585
|
+
with open(path, "r", encoding="utf-8") as handle:
|
|
586
|
+
data = json.load(handle)
|
|
587
|
+
except (OSError, ValueError):
|
|
588
|
+
return 0
|
|
589
|
+
count = 0
|
|
590
|
+
hooks = data.get("hooks") if isinstance(data, dict) else None
|
|
591
|
+
for groups in (hooks.values() if isinstance(hooks, dict) else ()):
|
|
592
|
+
for group in groups if isinstance(groups, list) else []:
|
|
593
|
+
items = group.get("hooks") if isinstance(group, dict) else None
|
|
594
|
+
for item in items if isinstance(items, list) else []:
|
|
595
|
+
if isinstance(item, dict) and HOOK_SCRIPT in str(item.get("command", "")):
|
|
596
|
+
count += 1
|
|
597
|
+
return count
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def toml_string(value):
|
|
601
|
+
return json.dumps(value, ensure_ascii=False) # a JSON string is a valid TOML basic string
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def codex_hooks_block(entries):
|
|
605
|
+
lines = [HOOKS_BEGIN]
|
|
606
|
+
for event, groups in entries.items():
|
|
607
|
+
for group in groups:
|
|
608
|
+
lines.append("[[hooks." + event + "]]")
|
|
609
|
+
if "matcher" in group:
|
|
610
|
+
lines.append("matcher = " + toml_string(group["matcher"]))
|
|
611
|
+
for item in group["hooks"]:
|
|
612
|
+
lines.append("[[hooks." + event + ".hooks]]")
|
|
613
|
+
for key, value in item.items():
|
|
614
|
+
lines.append(key + " = " + (("true" if value else "false") if isinstance(value, bool) else
|
|
615
|
+
str(value) if isinstance(value, int) else toml_string(value)))
|
|
616
|
+
return "\n".join(lines + [HOOKS_END]) + "\n"
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
def without_groups(parsed, groups):
|
|
620
|
+
"""parsed minus each of groups ({event: [group]}), each removed once by equality; None when
|
|
621
|
+
one of them is not there unchanged (edited, or keys appended to it)."""
|
|
622
|
+
result = deepcopy(parsed)
|
|
623
|
+
hooks = result.get("hooks")
|
|
624
|
+
for event, wanted in groups.items():
|
|
625
|
+
current = hooks.get(event) if isinstance(hooks, dict) else None
|
|
626
|
+
if not isinstance(current, list):
|
|
627
|
+
return None
|
|
628
|
+
for group in wanted:
|
|
629
|
+
if group not in current:
|
|
630
|
+
return None
|
|
631
|
+
del current[len(current) - 1 - current[::-1].index(group)] # the last equal one: ours come after the user's
|
|
632
|
+
if not current:
|
|
633
|
+
del hooks[event]
|
|
634
|
+
return result
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
def codex_hooks_toml_sync(store, home, record, desired, python, dry, unsafe):
|
|
638
|
+
label = "~/.codex/config.toml"
|
|
639
|
+
if tomllib is None:
|
|
640
|
+
return record, "skip", "Python 3.11+ (tomllib) é necessário para gravar os hooks do Codex em config.toml com verificação."
|
|
641
|
+
directory = home / ".codex"
|
|
642
|
+
if desired and not record and not directory.is_dir():
|
|
643
|
+
return None, "skip", "~/.codex/hooks.json: CLI não configurado neste perfil; nada alterado."
|
|
644
|
+
path = protect(directory / "config.toml", home)
|
|
645
|
+
old = read_regular(path)
|
|
646
|
+
try:
|
|
647
|
+
text = old.decode("utf-8") if old is not None else ""
|
|
648
|
+
except UnicodeDecodeError:
|
|
649
|
+
return record, "skip", "config.toml não é UTF-8; hooks do Codex não configurados."
|
|
650
|
+
span = marked(text, HOOKS_BEGIN, HOOKS_END)
|
|
651
|
+
stripped = text[:span[0]] + text[span[1]:] if span else text
|
|
652
|
+
try:
|
|
653
|
+
current = tomllib.loads(text)
|
|
654
|
+
base = tomllib.loads(stripped)
|
|
655
|
+
except tomllib.TOMLDecodeError:
|
|
656
|
+
return record, "skip", "config.toml não é TOML válido; hooks do Codex não configurados."
|
|
657
|
+
old_block = text[span[0]:span[1]] if span else None
|
|
658
|
+
if span and (not record or record.get("block_sha") != sha(old_block.encode("utf-8"))):
|
|
659
|
+
return (record if desired else None), "skip", ("Bloco codex-hooks do crow-skills em config.toml foi editado ou não tem registro; "
|
|
660
|
+
"nada alterado. Remova o bloco manualmente e rode crow-skills integrations install.")
|
|
661
|
+
if span:
|
|
662
|
+
old_groups = tomllib.loads(old_block).get("hooks", {})
|
|
663
|
+
expected_base = without_groups(current, old_groups)
|
|
664
|
+
if expected_base is not None and "hooks" in expected_base and not expected_base["hooks"] and "hooks" not in base:
|
|
665
|
+
expected_base.pop("hooks")
|
|
666
|
+
if expected_base != base:
|
|
667
|
+
return (record if desired else None), "skip", ("Chaves acrescentadas logo depois do bloco codex-hooks em config.toml mudariam de "
|
|
668
|
+
"tabela; nada alterado. Revise o arquivo manualmente.")
|
|
669
|
+
added_newline = (record or {}).get("added_newline", False)
|
|
670
|
+
if not desired:
|
|
671
|
+
if not record:
|
|
672
|
+
return None, "unchanged", None
|
|
673
|
+
if not span:
|
|
674
|
+
return None, "skip", "Bloco codex-hooks ausente de config.toml; controle encerrado."
|
|
675
|
+
result = stripped
|
|
676
|
+
if added_newline and span[1] == len(text) and result.endswith("\n"):
|
|
677
|
+
result = result[:-1]
|
|
678
|
+
if dry:
|
|
679
|
+
return None, "remove", None
|
|
680
|
+
backup(store, "codex-config", old)
|
|
681
|
+
if record.get("created_file") and not result.strip():
|
|
682
|
+
path.unlink()
|
|
683
|
+
else:
|
|
684
|
+
write(path, result.encode("utf-8"), old)
|
|
685
|
+
return None, "remove", None
|
|
686
|
+
if not quoted_ok(python, hook_script_path(store), home):
|
|
687
|
+
return record, "skip", "Caminho do Python, do estado ou do home contém aspas/variáveis; hooks não configurados."
|
|
688
|
+
entries = hook_entries(store, home, python, "codex")
|
|
689
|
+
block = codex_hooks_block(entries)
|
|
690
|
+
if span:
|
|
691
|
+
if old_block == block:
|
|
692
|
+
report_duplicates(home)
|
|
693
|
+
return record, "unchanged", None
|
|
694
|
+
result = text[:span[0]] + block + text[span[1]:]
|
|
695
|
+
else:
|
|
696
|
+
added_newline = bool(stripped) and not stripped.endswith("\n")
|
|
697
|
+
result = stripped + ("\n" if added_newline else "") + block
|
|
698
|
+
expected = deepcopy(base)
|
|
699
|
+
hooks = expected.setdefault("hooks", {})
|
|
700
|
+
try:
|
|
701
|
+
for event, groups in entries.items():
|
|
702
|
+
if not isinstance(hooks.setdefault(event, []), list):
|
|
703
|
+
raise ValueError(event)
|
|
704
|
+
hooks[event].extend(deepcopy(groups))
|
|
705
|
+
if tomllib.loads(result) != expected:
|
|
706
|
+
raise ValueError("diff")
|
|
707
|
+
except (tomllib.TOMLDecodeError, ValueError, AttributeError):
|
|
708
|
+
return record, "skip", ("A tabela [hooks] de config.toml tem um formato que o bloco do crow-skills não preservaria "
|
|
709
|
+
"(por exemplo, hooks definidos inline); nada alterado.")
|
|
710
|
+
action = "update" if record else "install"
|
|
711
|
+
new_record = {"path": str(path), "mode": "toml", "added_newline": added_newline, "installed_at": now(),
|
|
712
|
+
"block_sha": sha(block.encode("utf-8")),
|
|
713
|
+
"created_file": record.get("created_file", False) if record and record.get("mode") == "toml" else old is None}
|
|
714
|
+
note = ("~/.codex/hooks.json " + ("é symlink" if unsafe == "symlink" else "não pode ser editado com segurança") +
|
|
715
|
+
"; os hooks do crow-skills foram gravados em ~/.codex/config.toml (bloco marcado) e o hooks.json não foi tocado. "
|
|
716
|
+
"Codex só executa hook novo ou alterado depois de aprovado: abra o Codex, rode /hooks e aprove as entradas do "
|
|
717
|
+
"crow-skills.") + codex_hooks_feature(home)
|
|
718
|
+
report_duplicates(home)
|
|
719
|
+
if dry:
|
|
720
|
+
return new_record, action, note.strip()
|
|
721
|
+
new_record["backup"] = backup(store, "codex-config", old)
|
|
722
|
+
write(path, result.encode("utf-8"), old)
|
|
723
|
+
return new_record, action, note.strip()
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
# Findings that do not stop an integration but need the user (reported in "skipped").
|
|
727
|
+
_WARNINGS = []
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
def report_duplicates(home):
|
|
731
|
+
note = codex_duplicates_note(home)
|
|
732
|
+
if note:
|
|
733
|
+
_WARNINGS.append({"integration": "codex-hooks", "reason": note})
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
def codex_duplicates_note(home):
|
|
737
|
+
count = codex_json_duplicates(home)
|
|
738
|
+
if not count:
|
|
739
|
+
return None
|
|
740
|
+
return ("~/.codex/hooks.json (não gerenciado pelo crow-skills) já tem " + str(count) +
|
|
741
|
+
" entrada(s) com crow_hook.py, provavelmente adicionadas à mão; com o bloco em config.toml elas rodariam em dobro. "
|
|
742
|
+
"Remova-as do hooks.json (ou do arquivo para onde o symlink aponta); o crow-skills não edita esse arquivo.")
|
|
743
|
+
|
|
744
|
+
|
|
504
745
|
# --- /crow slash commands ------------------------------------------------------------------------
|
|
505
746
|
|
|
506
747
|
COMMANDS = {
|
|
@@ -578,9 +819,9 @@ def command_sync(name, store, home, record, desired, python, dry):
|
|
|
578
819
|
|
|
579
820
|
# --- codex ---------------------------------------------------------------------------------
|
|
580
821
|
|
|
581
|
-
def marked(text):
|
|
582
|
-
begins = [m.start() for m in re.finditer(r"(?m)^" + re.escape(
|
|
583
|
-
ends = [m.end() for m in re.finditer(r"(?m)^" + re.escape(
|
|
822
|
+
def marked(text, begin=BEGIN, end=END):
|
|
823
|
+
begins = [m.start() for m in re.finditer(r"(?m)^" + re.escape(begin) + r"\n", text)]
|
|
824
|
+
ends = [m.end() for m in re.finditer(r"(?m)^" + re.escape(end) + r"\n", text)]
|
|
584
825
|
if not begins and not ends:
|
|
585
826
|
return None
|
|
586
827
|
if len(begins) != 1 or len(ends) != 1 or ends[0] <= begins[0]:
|
|
@@ -852,6 +1093,7 @@ def sync(store, home, wanted, dry_run=False, python=None):
|
|
|
852
1093
|
after["files"][record["path"]] = {"backup": record.get("backup"), "created_file": record.get("created_file", False),
|
|
853
1094
|
"written_sha": record["written_sha"]}
|
|
854
1095
|
global _FILES, _LIVE
|
|
1096
|
+
del _WARNINGS[:]
|
|
855
1097
|
_FILES = {k: dict(v) for k, v in after["files"].items()}
|
|
856
1098
|
_LIVE = after["integrations"]
|
|
857
1099
|
with (nullcontext() if dry_run else store.lock()):
|
|
@@ -891,10 +1133,13 @@ def sync(store, home, wanted, dry_run=False, python=None):
|
|
|
891
1133
|
if after != state:
|
|
892
1134
|
atomic_json(state_path(store), after)
|
|
893
1135
|
if not after["integrations"]:
|
|
894
|
-
for script in (script_path(store), hook_script_path(store), resources_script_path(store)
|
|
1136
|
+
for script in (script_path(store), hook_script_path(store), resources_script_path(store),
|
|
1137
|
+
broadcast_script_path(store)):
|
|
895
1138
|
if script.exists():
|
|
896
1139
|
script.unlink()
|
|
897
1140
|
remove_bytecode(store)
|
|
1141
|
+
report["skipped"].extend(_WARNINGS)
|
|
1142
|
+
del _WARNINGS[:]
|
|
898
1143
|
for key in ("changes", "skipped"):
|
|
899
1144
|
report[key].sort(key=lambda c: NAMES.index(c["integration"]) if c["integration"] in NAMES else 99)
|
|
900
1145
|
report["dry_run"] = dry_run
|
|
@@ -911,6 +1156,12 @@ def status(store, home):
|
|
|
911
1156
|
row["path"] = record.get("path") or record.get("conf")
|
|
912
1157
|
if name == "tmux-status" and not record.get("block"):
|
|
913
1158
|
row["note"] = "tmux.conf é symlink; linha source-file adicionada manualmente pelo usuário."
|
|
1159
|
+
if name == "codex-hooks" and record.get("mode") == "toml":
|
|
1160
|
+
row["note"] = "Gravado em ~/.codex/config.toml (bloco marcado): ~/.codex/hooks.json é symlink ou inseguro e não é editado."
|
|
1161
|
+
duplicates = codex_duplicates_note(home)
|
|
1162
|
+
if duplicates:
|
|
1163
|
+
row["note"] += " " + duplicates
|
|
1164
|
+
row["duplicates"] = codex_json_duplicates(home)
|
|
914
1165
|
rows.append(row)
|
|
915
1166
|
for agent, reason in UNSUPPORTED.items():
|
|
916
1167
|
rows.append({"integration": UNSUPPORTED_ROW[agent], "agents": [agent], "status": "unsupported", "note": reason})
|