@yasaswy.nagavolu/agents 0.9.2 → 0.11.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/bin/cli.js +56 -1
- package/content/agents/idea-agent/council_fanout.py +40 -8
- package/content/global/CLAUDE.md +1 -0
- package/content/global/hooks/ai_attribution_guard.py +221 -0
- package/content/global/hooks/large_file_read_guard.py +6 -2
- package/content/hooks/conclusion-scribe/conclusion-scribe.env.example +2 -1
- package/content/hooks/conclusion-scribe/conclusion_scribe_hook.py +827 -180
- package/content/hooks/conclusion-scribe/test_conclusion_scribe_hook.py +632 -298
- package/content/manifest.json +222 -34
- package/content/manifest.schema.json +3 -3
- package/content/proxy/README.md +58 -0
- package/content/proxy/agent_dispatch_guard.py +6 -1
- package/content/proxy/agent_model_guard.py +6 -2
- package/content/proxy/artifact_mocker_gate.py +6 -2
- package/content/proxy/autostart_hook.py +7 -1
- package/content/proxy/code_is_law_lint_hook.py +6 -1
- package/content/proxy/code_is_law_prompt_nudge.py +171 -0
- package/content/proxy/execution_worker_review_gate.py +6 -2
- package/content/proxy/handover_ledger_hook.py +6 -2
- package/content/proxy/html_mocker_monitor_guard.py +6 -1
- package/content/proxy/html_mocker_prompt_nudge.py +6 -2
- package/content/proxy/html_mocker_subagent_guard.py +6 -1
- package/content/proxy/litellm/call_feed.ps1 +90 -0
- package/content/proxy/litellm/call_log.py +150 -0
- package/content/proxy/litellm/custom_callbacks.py +114 -0
- package/content/proxy/litellm/litellm_status.ps1 +104 -0
- package/content/proxy/litellm/litellm_watch.ps1 +108 -0
- package/content/proxy/litellm/smoke_test.py +182 -0
- package/content/proxy/litellm/start.ps1 +196 -18
- package/content/proxy/litellm/supervise_hidden.vbs +14 -0
- package/content/proxy/litellm/supervise_visible.vbs +25 -0
- package/content/proxy/managed_files_guard.py +6 -1
- package/content/proxy/publish_guard.py +6 -1
- package/content/proxy/reddit_intent_hook.py +6 -1
- package/content/proxy/triage_gate_hook.py +6 -2
- package/content/proxy/web_search_guard.py +6 -2
- package/content/skills/README.md +14 -0
- package/content/skills/code-is-law/SKILL.md +1 -1
- package/content/skills/launch-litellm/SKILL.md +53 -0
- package/content/skills/launch-litellm/launch_litellm.ps1 +177 -0
- package/content/skills/ship-the-code/SKILL.md +4 -4
- package/content/skills/ship-the-code/ship.py +164 -311
- package/content/skills/ship-the-code/tests/test_ship.py +222 -183
- package/content/skills/visual-check/compare.py +30 -4
- package/content/skills/web-search/search.py +25 -0
- package/lib/install.js +19 -4
- package/lib/menu.js +12 -0
- package/lib/tty-menu.js +8 -3
- package/lib/uninstall.js +4 -1
- package/lib/update.js +10 -4
- package/lib/version-banner.js +71 -0
- package/lib/wiring.js +168 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -13,6 +13,8 @@ const { uninstallBundle, UninstallError } = require('../lib/uninstall');
|
|
|
13
13
|
const { loadManifest, findBundle, ManifestError } = require('../lib/manifest');
|
|
14
14
|
const { loadLedger, bundleKeysInLedger, LedgerError } = require('../lib/ledger');
|
|
15
15
|
const { updateBundles, UpdateError } = require('../lib/update');
|
|
16
|
+
const { formatVersionBanner } = require('../lib/version-banner');
|
|
17
|
+
const { ledgerPath } = require('../lib/ledger');
|
|
16
18
|
const { WiringError } = require('../lib/wiring');
|
|
17
19
|
const {
|
|
18
20
|
basicMenuBundles,
|
|
@@ -341,6 +343,54 @@ function printFinalSummary({ installed, skipped, targetBase }) {
|
|
|
341
343
|
);
|
|
342
344
|
}
|
|
343
345
|
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* cliVersion recorded by the last install, or null if this machine has none.
|
|
349
|
+
*
|
|
350
|
+
* Reads the ledger file DIRECTLY rather than via loadLedger(), on purpose: this is a
|
|
351
|
+
* cosmetic banner, and loadLedger throws on a schema-major mismatch or a malformed
|
|
352
|
+
* file. A ledger problem must not be able to stop the installer from rendering its
|
|
353
|
+
* menu -- the install path itself will surface that error properly.
|
|
354
|
+
*/
|
|
355
|
+
function readInstalledCliVersion(targetDir) {
|
|
356
|
+
try {
|
|
357
|
+
const raw = readFileSync(ledgerPath(targetDir), 'utf8');
|
|
358
|
+
return JSON.parse(raw).cliVersion || null;
|
|
359
|
+
} catch {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Newest version on npm, or null. Best-effort with a short timeout: an offline or
|
|
366
|
+
* slow registry must never delay or block the menu, so every failure path resolves
|
|
367
|
+
* null rather than rejecting. Set AGENTS_NO_UPDATE_CHECK=1 to skip the request.
|
|
368
|
+
*/
|
|
369
|
+
function fetchLatestVersion(pkgName, { timeoutMs = 1500 } = {}) {
|
|
370
|
+
if (process.env.AGENTS_NO_UPDATE_CHECK) return Promise.resolve(null);
|
|
371
|
+
return new Promise((resolve) => {
|
|
372
|
+
let settled = false;
|
|
373
|
+
const done = (v) => { if (!settled) { settled = true; resolve(v); } };
|
|
374
|
+
try {
|
|
375
|
+
const https = require('node:https');
|
|
376
|
+
const url = `https://registry.npmjs.org/${pkgName.replace('/', '%2F')}/latest`;
|
|
377
|
+
const req = https.get(url, { timeout: timeoutMs }, (res) => {
|
|
378
|
+
if (res.statusCode !== 200) { res.resume(); return done(null); }
|
|
379
|
+
let body = '';
|
|
380
|
+
res.setEncoding('utf8');
|
|
381
|
+
res.on('data', (c) => { body += c; });
|
|
382
|
+
res.on('end', () => {
|
|
383
|
+
try { done(JSON.parse(body).version || null); } catch { done(null); }
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
req.on('timeout', () => { req.destroy(); done(null); });
|
|
387
|
+
req.on('error', () => done(null));
|
|
388
|
+
} catch {
|
|
389
|
+
done(null);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
344
394
|
async function runInteractiveMenu({ advanced, targetDir, targetConfig, noSecrets, profile }) {
|
|
345
395
|
const { manifest, manifestPath } = loadManifest(PACKAGE_ROOT);
|
|
346
396
|
const repoRoot = path.dirname(manifestPath);
|
|
@@ -353,7 +403,12 @@ async function runInteractiveMenu({ advanced, targetDir, targetConfig, noSecrets
|
|
|
353
403
|
const rows = candidateBundles.map((b) => describeBundleRow(b, manifest));
|
|
354
404
|
const details = new Map(candidateBundles.map((b) => [b.key, deriveBundleDetails(b, manifest, { repoRoot })]));
|
|
355
405
|
const header = `${pkg.name} v${pkg.version}`;
|
|
356
|
-
const
|
|
406
|
+
const subheader = formatVersionBanner({
|
|
407
|
+
running: pkg.version,
|
|
408
|
+
installed: readInstalledCliVersion(targetDir),
|
|
409
|
+
latest: await fetchLatestVersion(pkg.name),
|
|
410
|
+
});
|
|
411
|
+
const selectedKeys = await pickBundles(rows, { details, header, subheader });
|
|
357
412
|
if (selectedKeys === null) {
|
|
358
413
|
console.log('Cancelled — nothing installed.');
|
|
359
414
|
return 0;
|
|
@@ -23,6 +23,16 @@ GLM_MODEL = "litellm_glm"
|
|
|
23
23
|
COUNCIL_NAME = "idea"
|
|
24
24
|
LOG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "council.log")
|
|
25
25
|
|
|
26
|
+
# Router-style call log (project / session / subagent attribution), shared by every
|
|
27
|
+
# LiteLLM caller so one window shows all non-Claude traffic. Optional: if the proxy
|
|
28
|
+
# tree is missing this degrades to the local council.log only, never to a crash.
|
|
29
|
+
try:
|
|
30
|
+
import pathlib as _pathlib
|
|
31
|
+
sys.path.insert(0, str(_pathlib.Path(__file__).resolve().parents[2] / "proxy" / "litellm"))
|
|
32
|
+
from call_log import log_call as _log_call
|
|
33
|
+
except Exception:
|
|
34
|
+
_log_call = None
|
|
35
|
+
|
|
26
36
|
|
|
27
37
|
def _log_panel_call(model, duration, usage, error=None):
|
|
28
38
|
"""Best-effort structured log of one panel call. Never raises — a logging
|
|
@@ -44,6 +54,16 @@ def _log_panel_call(model, duration, usage, error=None):
|
|
|
44
54
|
fh.write(json.dumps(entry) + "\n")
|
|
45
55
|
except Exception:
|
|
46
56
|
pass
|
|
57
|
+
# Mirror into the shared router-style feed so the LiteLLM window shows this call
|
|
58
|
+
# with session/subagent attribution. Separate try: a failure here must not lose the
|
|
59
|
+
# council.log entry written above.
|
|
60
|
+
try:
|
|
61
|
+
if _log_call:
|
|
62
|
+
_log_call(f"{COUNCIL_NAME}-council", model,
|
|
63
|
+
status="error" if error else "ok",
|
|
64
|
+
duration=duration, usage=usage, error=error)
|
|
65
|
+
except Exception:
|
|
66
|
+
pass
|
|
47
67
|
|
|
48
68
|
PANEL_PROMPT_WITH_CONTEXT = """\
|
|
49
69
|
{context}
|
|
@@ -82,10 +102,15 @@ def call_litellm(prompt, key, model, max_tokens=2000):
|
|
|
82
102
|
try:
|
|
83
103
|
with urllib.request.urlopen(req, timeout=90) as r:
|
|
84
104
|
d = json.load(r)
|
|
85
|
-
|
|
105
|
+
choice = d["choices"][0]
|
|
106
|
+
msg = choice["message"]
|
|
86
107
|
# Reasoning models output CoT in 'reasoning_content'; final answer in 'content'
|
|
87
108
|
text = msg.get("content") or msg.get("reasoning_content") or msg.get("reasoning") or ""
|
|
88
|
-
|
|
109
|
+
truncated = choice.get("finish_reason") == "length"
|
|
110
|
+
_log_panel_call(model, time.monotonic() - start, d.get("usage"),
|
|
111
|
+
error="truncated: hit max_tokens" if truncated else None)
|
|
112
|
+
if truncated:
|
|
113
|
+
text += "\n\n[response truncated — hit max_tokens cap]"
|
|
89
114
|
return text.strip()
|
|
90
115
|
except urllib.error.HTTPError as e:
|
|
91
116
|
detail = e.read().decode()[:300]
|
|
@@ -113,6 +138,7 @@ def call_litellm_stream(prompt, key, model, max_tokens=2000):
|
|
|
113
138
|
})
|
|
114
139
|
start = time.monotonic()
|
|
115
140
|
parts = []
|
|
141
|
+
truncated = False
|
|
116
142
|
try:
|
|
117
143
|
with urllib.request.urlopen(req, timeout=90) as r:
|
|
118
144
|
for raw_line in r:
|
|
@@ -123,11 +149,17 @@ def call_litellm_stream(prompt, key, model, max_tokens=2000):
|
|
|
123
149
|
if payload == "[DONE]":
|
|
124
150
|
break
|
|
125
151
|
chunk = json.loads(payload)
|
|
126
|
-
|
|
152
|
+
choice = (chunk.get("choices") or [{}])[0]
|
|
153
|
+
if choice.get("finish_reason") == "length":
|
|
154
|
+
truncated = True
|
|
155
|
+
delta = choice.get("delta", {})
|
|
127
156
|
if delta.get("content"):
|
|
128
157
|
parts.append(delta["content"])
|
|
129
158
|
text = "".join(parts).strip()
|
|
130
|
-
_log_panel_call(model, time.monotonic() - start, None
|
|
159
|
+
_log_panel_call(model, time.monotonic() - start, None,
|
|
160
|
+
error="truncated: hit max_tokens" if truncated else None)
|
|
161
|
+
if truncated:
|
|
162
|
+
text += "\n\n[response truncated — hit max_tokens cap]"
|
|
131
163
|
return text
|
|
132
164
|
except urllib.error.HTTPError as e:
|
|
133
165
|
detail = e.read().decode()[:300]
|
|
@@ -153,10 +185,10 @@ def main():
|
|
|
153
185
|
sys.exit(1)
|
|
154
186
|
|
|
155
187
|
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as ex:
|
|
156
|
-
f_gemini = ex.submit(call_litellm, prompt, or_key, GEMINI_MODEL,
|
|
157
|
-
f_deepseek = ex.submit(call_litellm, prompt, or_key, DEEPSEEK_MODEL,
|
|
158
|
-
f_qwen = ex.submit(call_litellm_stream, prompt, or_key, QWEN_MODEL,
|
|
159
|
-
f_glm = ex.submit(call_litellm, prompt, or_key, GLM_MODEL,
|
|
188
|
+
f_gemini = ex.submit(call_litellm, prompt, or_key, GEMINI_MODEL, 4000)
|
|
189
|
+
f_deepseek = ex.submit(call_litellm, prompt, or_key, DEEPSEEK_MODEL, 6000)
|
|
190
|
+
f_qwen = ex.submit(call_litellm_stream, prompt, or_key, QWEN_MODEL, 4000)
|
|
191
|
+
f_glm = ex.submit(call_litellm, prompt, or_key, GLM_MODEL, 4000)
|
|
160
192
|
|
|
161
193
|
print(f"=== {GEMINI_MODEL} ===")
|
|
162
194
|
print(f_gemini.result())
|
package/content/global/CLAUDE.md
CHANGED
|
@@ -4,6 +4,7 @@ When making technical decisions, do not give much weight to development cost. In
|
|
|
4
4
|
When doing bug fixes, always start with reproducing the bug in an E2E setting as closely aligned with how an end user would experience it as possible. This makes sure you find the real problem so your fix will actually solve it.
|
|
5
5
|
If user has custom agent and other models in their custom agents respect them and launch with what was instructed. This takes higher priority.
|
|
6
6
|
Use git CLI for GitLab access, never glab — we use GitLab, not GitHub.
|
|
7
|
+
Always state all pending, open, or blocked items upfront and in full at the top of a response — never trail a reply with "one more thing pending" or drip-feed open items across later turns.
|
|
7
8
|
|
|
8
9
|
## Model Routing (HARD RULE)
|
|
9
10
|
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
ai_attribution_guard.py — PreToolUse(Bash) guard: DENY any command that would
|
|
4
|
+
write an AI-attribution trailer into a commit message, tag message, PR/MR
|
|
5
|
+
body, or issue note.
|
|
6
|
+
|
|
7
|
+
The user never wants these trailers, on this machine, ever. The normal path
|
|
8
|
+
is the harness setting `includeCoAuthoredBy: false` (in ~/.claude/settings.json,
|
|
9
|
+
not this repo). This hook is the codified backstop for everything that setting
|
|
10
|
+
can't reach: a subagent building its own message, a script that pastes a
|
|
11
|
+
template, or a future harness change. Code-is-law, same shape as
|
|
12
|
+
`web_search_guard.py` and `no_openrouter_guard.py` in proxy/ — a rule that
|
|
13
|
+
previously lived only in prose becomes a hook that enforces it.
|
|
14
|
+
|
|
15
|
+
WHAT IS DENIED (message text, wherever it appears — see _scan below):
|
|
16
|
+
- `noreply@anthropic.com` anywhere at all — never a legitimate address for
|
|
17
|
+
a human co-author, so no anchoring or context check is needed.
|
|
18
|
+
- A `https://claude.ai/code` URL, or a "Generated with Claude Code" /
|
|
19
|
+
robot-emoji generated-with marker — the two markers our own commit
|
|
20
|
+
template historically appended.
|
|
21
|
+
- A line beginning (ignoring leading whitespace/quote/comment characters)
|
|
22
|
+
with `Co-Authored-By:` whose VALUE names Claude/Anthropic/another AI
|
|
23
|
+
assistant. A human co-author trailer (`Co-Authored-By: Jane Doe
|
|
24
|
+
<jane@example.com>`) is legitimate and NOT denied — only the value is
|
|
25
|
+
checked against `_AI_MARKERS`.
|
|
26
|
+
- A line beginning the same way with `Claude-Session:` — always denied,
|
|
27
|
+
it's never a legitimate non-AI header.
|
|
28
|
+
|
|
29
|
+
These checks run against the raw command text split on real newlines, which
|
|
30
|
+
already covers heredoc bodies (`git commit -F - <<'EOF' ... EOF`) for free —
|
|
31
|
+
the heredoc content is literal text inside the command string, one line per
|
|
32
|
+
scan iteration, no special-casing needed. They ALSO run against the contents
|
|
33
|
+
of any file referenced by `git commit -F/--file/-t/--template <file>` or
|
|
34
|
+
`gh ... create --body-file <file>` (scoped to those subcommands specifically,
|
|
35
|
+
so an unrelated `grep -F` doesn't trigger a spurious file read) — if the file
|
|
36
|
+
exists it's read and scanned the same way; if not, that check is skipped.
|
|
37
|
+
|
|
38
|
+
WHAT IS NOT DENIED (the failure mode that matters — a previous guard in
|
|
39
|
+
proxy/ shipped exactly this bug and blocked routine work, see
|
|
40
|
+
html_mocker_monitor_guard.py's docstring): a command that merely MENTIONS
|
|
41
|
+
one of these strings mid-sentence — `git log --grep="Co-Authored-By"`,
|
|
42
|
+
`git commit -m "fix: stop emitting Co-Authored-By trailers"`, a grep, a docs
|
|
43
|
+
edit, an echo describing this very guard. Only the anchored trailer forms
|
|
44
|
+
(Co-Authored-By / Claude-Session) require line-start anchoring; the
|
|
45
|
+
noreply@anthropic.com / claude.ai/code / "Generated with Claude Code"
|
|
46
|
+
markers are treated as never having an innocent reason to appear literally
|
|
47
|
+
in a Bash command at all, so they're substring-matched anywhere.
|
|
48
|
+
|
|
49
|
+
Fails OPEN (prints nothing, exit 0; never wedges Claude Code) on: malformed
|
|
50
|
+
stdin, wrong hook/tool, missing tool_input.command, no trigger match, or any
|
|
51
|
+
unexpected exception. In the last-resort uncaught-exception case ONLY, the
|
|
52
|
+
failure reason is appended as one timestamped line to
|
|
53
|
+
~/.claude/logs/ai_attribution_guard.log — same pattern as the sibling guards.
|
|
54
|
+
|
|
55
|
+
Wiring (settings.json), matcher "Bash":
|
|
56
|
+
python ~/.claude/hooks/ai_attribution_guard.py
|
|
57
|
+
"""
|
|
58
|
+
from __future__ import annotations
|
|
59
|
+
|
|
60
|
+
# CLAUDE_HOOK_CHILD guard: hook-spawned child claude processes set this so
|
|
61
|
+
# this hook never re-fires recursively. Must run before any other I/O.
|
|
62
|
+
import os, sys
|
|
63
|
+
if os.environ.get("CLAUDE_HOOK_CHILD"):
|
|
64
|
+
sys.exit(0)
|
|
65
|
+
|
|
66
|
+
import json
|
|
67
|
+
import re
|
|
68
|
+
import shlex
|
|
69
|
+
import time
|
|
70
|
+
from pathlib import Path
|
|
71
|
+
|
|
72
|
+
LOG = Path.home() / ".claude" / "logs" / "ai_attribution_guard.log"
|
|
73
|
+
|
|
74
|
+
# Value markers that flag a Co-Authored-By trailer as AI (not human).
|
|
75
|
+
_AI_MARKERS = re.compile(
|
|
76
|
+
r"claude|anthropic|chatgpt|gpt[-\s]?\d|openai|copilot|gemini"
|
|
77
|
+
r"|\bai assistant\b|\bai agent\b|\blanguage model\b",
|
|
78
|
+
re.IGNORECASE,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Anchored (line-start, ignoring leading whitespace/quote/comment chars) trailers.
|
|
82
|
+
_LEADING = r'^[\s"\'`>#*\-]*'
|
|
83
|
+
_CO_AUTHORED_BY_RE = re.compile(_LEADING + r"co-authored-by\s*:(.*)$", re.IGNORECASE)
|
|
84
|
+
_CLAUDE_SESSION_RE = re.compile(_LEADING + r"claude-session\s*:", re.IGNORECASE)
|
|
85
|
+
|
|
86
|
+
# Substring-anywhere markers — never a legitimate thing for a Bash command to contain.
|
|
87
|
+
_NOREPLY_RE = re.compile(r"noreply@anthropic\.com", re.IGNORECASE)
|
|
88
|
+
_CLAUDE_URL_RE = re.compile(r"https?://claude\.ai/code", re.IGNORECASE)
|
|
89
|
+
_GENERATED_MARKER_RE = re.compile(r"generated\s+with\s+claude\s+code", re.IGNORECASE)
|
|
90
|
+
_ROBOT_GENERATED_RE = re.compile(r"\U0001F916.{0,60}generated\s+with", re.IGNORECASE | re.DOTALL)
|
|
91
|
+
|
|
92
|
+
REASON = (
|
|
93
|
+
"This command would write an AI-attribution trailer (Co-Authored-By naming "
|
|
94
|
+
"an AI, Claude-Session, a 'Generated with Claude Code' marker, a "
|
|
95
|
+
"claude.ai/code URL, or noreply@anthropic.com) into a commit/tag message, "
|
|
96
|
+
"PR/MR body, or issue note. The user never wants these on this machine. "
|
|
97
|
+
"Re-issue the same command with that line/marker removed."
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# git commit/tag file-message flags, and gh create's file-body flag. Scoped to
|
|
101
|
+
# these subcommands so an unrelated `grep -F` never triggers a stray file read.
|
|
102
|
+
_GIT_FILE_FLAGS = {"-F", "--file", "-t", "--template"}
|
|
103
|
+
_GH_FILE_FLAG = "--body-file"
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _log(reason: str) -> None:
|
|
107
|
+
"""Append one audit line (silent-fail). Only called on fail-open paths."""
|
|
108
|
+
try:
|
|
109
|
+
LOG.parent.mkdir(parents=True, exist_ok=True)
|
|
110
|
+
ts = time.strftime("%Y-%m-%dT%H:%M:%S")
|
|
111
|
+
with open(LOG, "a", encoding="utf-8") as f:
|
|
112
|
+
f.write(f"{ts}\tguard\tBash\tfail-open\t{reason[:200]}\n")
|
|
113
|
+
except Exception:
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _deny(reason: str) -> None:
|
|
118
|
+
print(json.dumps({
|
|
119
|
+
"hookSpecificOutput": {
|
|
120
|
+
"hookEventName": "PreToolUse",
|
|
121
|
+
"permissionDecision": "deny",
|
|
122
|
+
"permissionDecisionReason": reason,
|
|
123
|
+
}
|
|
124
|
+
}))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _scan(text: str) -> str | None:
|
|
128
|
+
"""Return a short reason string if `text` contains a denyable marker, else None."""
|
|
129
|
+
if _NOREPLY_RE.search(text):
|
|
130
|
+
return "contains noreply@anthropic.com"
|
|
131
|
+
if _CLAUDE_URL_RE.search(text):
|
|
132
|
+
return "contains a claude.ai/code URL"
|
|
133
|
+
if _GENERATED_MARKER_RE.search(text) or _ROBOT_GENERATED_RE.search(text):
|
|
134
|
+
return "contains a 'Generated with Claude Code' marker"
|
|
135
|
+
for line in text.split("\n"):
|
|
136
|
+
m = _CO_AUTHORED_BY_RE.match(line)
|
|
137
|
+
if m and _AI_MARKERS.search(m.group(1)):
|
|
138
|
+
return "contains a Co-Authored-By trailer naming an AI"
|
|
139
|
+
if _CLAUDE_SESSION_RE.match(line):
|
|
140
|
+
return "contains a Claude-Session trailer"
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _referenced_file_texts(command: str) -> list[str]:
|
|
145
|
+
"""Read contents of any git -F/-t/--file/--template or gh --body-file target."""
|
|
146
|
+
try:
|
|
147
|
+
tokens = shlex.split(command, posix=True)
|
|
148
|
+
except ValueError:
|
|
149
|
+
return []
|
|
150
|
+
|
|
151
|
+
lower = [t.lower() for t in tokens]
|
|
152
|
+
is_git_commit_or_tag = "git" in lower and ("commit" in lower or "tag" in lower)
|
|
153
|
+
is_gh_create = "gh" in lower and "create" in lower
|
|
154
|
+
if not is_git_commit_or_tag and not is_gh_create:
|
|
155
|
+
return []
|
|
156
|
+
|
|
157
|
+
refs: list[str] = []
|
|
158
|
+
for i, tok in enumerate(tokens[:-1]):
|
|
159
|
+
nxt = tokens[i + 1]
|
|
160
|
+
if is_git_commit_or_tag and tok in _GIT_FILE_FLAGS:
|
|
161
|
+
refs.append(nxt)
|
|
162
|
+
elif is_gh_create and tok == _GH_FILE_FLAG:
|
|
163
|
+
refs.append(nxt)
|
|
164
|
+
|
|
165
|
+
texts: list[str] = []
|
|
166
|
+
cwd = Path.cwd()
|
|
167
|
+
for ref in refs:
|
|
168
|
+
if ref == "-":
|
|
169
|
+
continue # stdin, not a file on disk to scan
|
|
170
|
+
p = Path(ref).expanduser()
|
|
171
|
+
if not p.is_absolute():
|
|
172
|
+
p = cwd / p
|
|
173
|
+
try:
|
|
174
|
+
if p.is_file():
|
|
175
|
+
texts.append(p.read_text(encoding="utf-8", errors="ignore"))
|
|
176
|
+
except Exception:
|
|
177
|
+
pass
|
|
178
|
+
return texts
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _safe_main() -> None:
|
|
182
|
+
try:
|
|
183
|
+
data = json.loads(sys.stdin.read() or "{}")
|
|
184
|
+
except Exception:
|
|
185
|
+
return
|
|
186
|
+
if not isinstance(data, dict):
|
|
187
|
+
return
|
|
188
|
+
if data.get("hook_event_name") != "PreToolUse":
|
|
189
|
+
return
|
|
190
|
+
if data.get("tool_name") != "Bash":
|
|
191
|
+
return
|
|
192
|
+
|
|
193
|
+
tool_input = data.get("tool_input") or {}
|
|
194
|
+
if not isinstance(tool_input, dict):
|
|
195
|
+
return
|
|
196
|
+
command = tool_input.get("command")
|
|
197
|
+
if not isinstance(command, str) or not command.strip():
|
|
198
|
+
return
|
|
199
|
+
|
|
200
|
+
reason = _scan(command)
|
|
201
|
+
if reason is None:
|
|
202
|
+
for text in _referenced_file_texts(command):
|
|
203
|
+
reason = _scan(text)
|
|
204
|
+
if reason:
|
|
205
|
+
break
|
|
206
|
+
|
|
207
|
+
if reason is None:
|
|
208
|
+
return # no trigger match -> allow
|
|
209
|
+
|
|
210
|
+
_deny(f"{REASON}\nDetected: {reason}.")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
if __name__ == "__main__":
|
|
214
|
+
try:
|
|
215
|
+
_safe_main()
|
|
216
|
+
except Exception as exc:
|
|
217
|
+
# Last-resort fail-open. Log if we somehow can, but never wedge.
|
|
218
|
+
try:
|
|
219
|
+
_log(f"uncaught exception: {exc!r}")
|
|
220
|
+
except Exception:
|
|
221
|
+
pass
|
|
@@ -14,9 +14,13 @@ Allow when ANY of:
|
|
|
14
14
|
Deny (exit 2 + stderr) when a whole-file read of a >THRESHOLD-line text file is attempted.
|
|
15
15
|
Tune THRESHOLD below, or remove the matcher from settings.json to disable.
|
|
16
16
|
"""
|
|
17
|
+
# CLAUDE_HOOK_CHILD guard: hook-spawned child claude processes set this so
|
|
18
|
+
# this hook never re-fires recursively. Must run before any other I/O.
|
|
19
|
+
import os, sys
|
|
20
|
+
if os.environ.get("CLAUDE_HOOK_CHILD"):
|
|
21
|
+
sys.exit(0)
|
|
22
|
+
|
|
17
23
|
import json
|
|
18
|
-
import os
|
|
19
|
-
import sys
|
|
20
24
|
|
|
21
25
|
THRESHOLD = 200
|
|
22
26
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# conclusion-scribe hook config — copy to ~/.claude/hooks/conclusion-scribe.env
|
|
2
2
|
# Machine/user-specific values live HERE, never in the hook code.
|
|
3
3
|
|
|
4
|
-
# Repos addressable as "<repo>#<iid>"
|
|
4
|
+
# Repos addressable as "<repo>#<iid>" when the hook extracts an issue
|
|
5
|
+
# reference from a conclusive message (URL-encoded paths).
|
|
5
6
|
# NOTE: repos under a scanned root (default C:\dev, override via the
|
|
6
7
|
# SCRIBE_HOOK_ROOTS env var) auto-discover from their gitlab.com git remote
|
|
7
8
|
# with zero config -- PROJECT_MAP below is only needed as an override, or as
|