@yasaswy.nagavolu/agents 0.15.0 → 0.16.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 +90 -1
- package/content/agents/idea-agent/council_fanout.py +35 -29
- package/content/agents/idea-agent/test_council_fanout.py +86 -0
- package/content/agents/lib/__init__.py +0 -0
- package/content/agents/lib/council_common.py +181 -0
- package/content/agents/lib/test_council_common.py +209 -0
- package/content/agents/plan-agent/plan_council_fanout.py +47 -21
- package/content/agents/plan-agent/test_plan_council_fanout.py +77 -0
- package/content/agents/review-agent/architecture_diagram_council_fanout.py +46 -27
- package/content/agents/review-agent/review_council_fanout.py +54 -28
- package/content/agents/review-agent/test_architecture_diagram_council_fanout.py +97 -0
- package/content/agents/review-agent/test_review_council_fanout.py +97 -0
- package/content/agents/review-agent/test_visual_diagnosis_review_agent.py +134 -0
- package/content/agents/review-agent/test_visual_review_council_fanout.py +92 -0
- package/content/agents/review-agent/visual_diagnosis.py +50 -7
- package/content/agents/review-agent/visual_review_council_fanout.py +56 -12
- package/content/agents/scribe-agent/scribe_runner.py +25 -1
- package/content/agents/visual-review-council/test_visual_diagnosis_vrc.py +130 -0
- package/content/agents/visual-review-council/visual_diagnosis.py +49 -5
- package/content/manifest.json +33 -2
- package/content/proxy/litellm/call_feed.ps1 +2 -1
- package/content/proxy/litellm/call_log.py +32 -3
- package/content/proxy/litellm/custom_callbacks.py +12 -1
- package/content/proxy/litellm/litellm_status.ps1 +13 -5
- package/content/proxy/litellm/litellm_watch.ps1 +2 -1
- package/content/proxy/litellm/start.ps1 +6 -4
- package/content/proxy/litellm/state_dir.ps1 +26 -0
- package/content/scripts/_vlm.py +30 -2
- package/content/skills/resume-session/SKILL.md +7 -3
- package/content/skills/visual-check/SKILL.md +1 -1
- package/content/skills/visual-check/compare.py +36 -4
- package/lib/doctor.js +219 -0
- package/lib/install.js +9 -1
- package/lib/update.js +18 -1
- package/lib/wiring.js +693 -547
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -31,6 +31,7 @@ const { supportsColor, createStyler, renderBar, formatBytes } = require('../lib/
|
|
|
31
31
|
const { collectBundleSecrets, collectComponentSecrets, isResolved, promptForMissingSecrets, maskValue, askChoice } = require('../lib/secretsPrompt');
|
|
32
32
|
const { envPath, readSecrets, removeSecret } = require('../lib/secretsStore');
|
|
33
33
|
const { runSelfProfilePostInstall } = require('../lib/selfProfile');
|
|
34
|
+
const { checkHealth, DoctorError } = require('../lib/doctor');
|
|
34
35
|
|
|
35
36
|
const PACKAGE_ROOT = path.join(__dirname, '..');
|
|
36
37
|
// One styler for the whole process: colors on only for a real TTY stdout
|
|
@@ -61,6 +62,7 @@ Usage:
|
|
|
61
62
|
agents-cli secrets Prompt for any missing secrets across all installed bundles
|
|
62
63
|
agents-cli secrets --bundle <key> Prompt for missing secrets for one bundle
|
|
63
64
|
agents-cli secrets --list Show which secrets are set/missing (names only — never values)
|
|
65
|
+
agents-cli doctor Report orphaned/missing/drifted files under the install target
|
|
64
66
|
agents-cli --help Show this help
|
|
65
67
|
|
|
66
68
|
Flags for install:
|
|
@@ -127,7 +129,22 @@ Hook items with wiring data are merged into <target>/settings.json's "hooks" sec
|
|
|
127
129
|
after install (idempotent; a one-time settings.json.bak-<timestamp> backup is taken
|
|
128
130
|
before the CLI's first-ever write there). A Python-backed hook is skipped (not an
|
|
129
131
|
error) when no python3/python is on PATH — re-run "install --bundle <key> --yes" once
|
|
130
|
-
Python is installed to wire it.
|
|
132
|
+
Python is installed to wire it. Duplicate hook registrations that predate this CLI
|
|
133
|
+
(or otherwise accumulate outside its per-block dedupe) are collapsed automatically on
|
|
134
|
+
every install/update — see "doctor" below to inspect settings.json wiring separately.
|
|
135
|
+
|
|
136
|
+
Flags for doctor:
|
|
137
|
+
--target-dir <path> Install target base, default ~/.claude (use for testing)
|
|
138
|
+
--json Print a machine-readable report instead of prose
|
|
139
|
+
|
|
140
|
+
doctor reports, without changing anything: orphans (files/directories sitting inside
|
|
141
|
+
a path this CLI manages that the ledger does not claim — e.g. a stale file left behind
|
|
142
|
+
by a renamed/retired item), missing (a ledger-tracked file no longer on disk), and
|
|
143
|
+
drifted (a ledger-tracked file whose on-disk hash no longer matches what was installed).
|
|
144
|
+
It never scans anywhere the manifest doesn't declare a file/directory item into, so the
|
|
145
|
+
rest of <target> (Claude Code's own state, caches, logs, your own files) is left alone.
|
|
146
|
+
Exit code is 0 when clean, 1 otherwise — safe to use as a CI/scripted gate. It never
|
|
147
|
+
deletes or modifies anything; deciding what to do about a finding is a separate step.
|
|
131
148
|
`);
|
|
132
149
|
}
|
|
133
150
|
|
|
@@ -951,6 +968,74 @@ async function runUpdate(argv) {
|
|
|
951
968
|
}
|
|
952
969
|
}
|
|
953
970
|
|
|
971
|
+
function parseDoctorArgs(argv) {
|
|
972
|
+
const args = { targetDir: null, json: false };
|
|
973
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
974
|
+
const arg = argv[i];
|
|
975
|
+
if (arg === '--target-dir') {
|
|
976
|
+
args.targetDir = argv[i + 1];
|
|
977
|
+
i += 1;
|
|
978
|
+
} else if (arg === '--json') {
|
|
979
|
+
args.json = true;
|
|
980
|
+
} else {
|
|
981
|
+
throw new DoctorError(`Unknown doctor flag: ${arg}`);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
return args;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
function describeOrphan(o) {
|
|
988
|
+
return o.type === 'dir' ? `${o.relTarget}/ (directory)` : o.relTarget;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function runDoctor(argv) {
|
|
992
|
+
let args;
|
|
993
|
+
try {
|
|
994
|
+
args = parseDoctorArgs(argv);
|
|
995
|
+
} catch (err) {
|
|
996
|
+
console.error(err.message);
|
|
997
|
+
return 1;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
try {
|
|
1001
|
+
const result = checkHealth({
|
|
1002
|
+
packageRoot: PACKAGE_ROOT,
|
|
1003
|
+
targetBase: args.targetDir,
|
|
1004
|
+
});
|
|
1005
|
+
|
|
1006
|
+
if (args.json) {
|
|
1007
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1008
|
+
return result.healthy ? 0 : 1;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
if (result.healthy) {
|
|
1012
|
+
console.log(`${result.targetBase}: healthy — no orphans, no missing files, no drift.`);
|
|
1013
|
+
return 0;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
console.log(`${result.targetBase}: issues found.`);
|
|
1017
|
+
if (result.orphans.length > 0) {
|
|
1018
|
+
console.log(`\nOrphans (not claimed by the ledger, ${result.orphans.length}):`);
|
|
1019
|
+
for (const o of result.orphans) console.log(` ${describeOrphan(o)}`);
|
|
1020
|
+
}
|
|
1021
|
+
if (result.missing.length > 0) {
|
|
1022
|
+
console.log(`\nMissing (ledger-tracked, not on disk, ${result.missing.length}):`);
|
|
1023
|
+
for (const m of result.missing) console.log(` ${m.relTarget} (bundle: ${m.bundle})`);
|
|
1024
|
+
}
|
|
1025
|
+
if (result.drifted.length > 0) {
|
|
1026
|
+
console.log(`\nDrifted (on-disk hash no longer matches the ledger, ${result.drifted.length}):`);
|
|
1027
|
+
for (const d of result.drifted) console.log(` ${d.relTarget} (bundle: ${d.bundle})`);
|
|
1028
|
+
}
|
|
1029
|
+
return 1;
|
|
1030
|
+
} catch (err) {
|
|
1031
|
+
if (err instanceof DoctorError || err instanceof ManifestError || err instanceof LedgerError) {
|
|
1032
|
+
console.error(err.message);
|
|
1033
|
+
return 1;
|
|
1034
|
+
}
|
|
1035
|
+
throw err;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
954
1039
|
async function main(argv) {
|
|
955
1040
|
const [command, ...rest] = argv;
|
|
956
1041
|
|
|
@@ -980,6 +1065,10 @@ async function main(argv) {
|
|
|
980
1065
|
return runUpdate(rest);
|
|
981
1066
|
}
|
|
982
1067
|
|
|
1068
|
+
if (command === 'doctor') {
|
|
1069
|
+
return runDoctor(rest);
|
|
1070
|
+
}
|
|
1071
|
+
|
|
983
1072
|
console.error(`Unknown command: ${command}`);
|
|
984
1073
|
printHelp();
|
|
985
1074
|
return 1;
|
|
@@ -7,13 +7,7 @@ Prints: labeled panel results to stdout.
|
|
|
7
7
|
|
|
8
8
|
Panels receive the raw goal and neutral context — never Claude's reframing.
|
|
9
9
|
"""
|
|
10
|
-
import sys, os, json, io, time, datetime, urllib.request, urllib.error, concurrent.futures
|
|
11
|
-
|
|
12
|
-
# Force utf-8 on stdout/stderr — Windows defaults to cp1252 which crashes on any non-ASCII model output
|
|
13
|
-
if hasattr(sys.stdout, 'buffer'):
|
|
14
|
-
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
|
15
|
-
if hasattr(sys.stderr, 'buffer'):
|
|
16
|
-
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
|
10
|
+
import sys, os, json, io, time, datetime, pathlib as _pathlib, urllib.request, urllib.error, concurrent.futures
|
|
17
11
|
|
|
18
12
|
GEMINI_MODEL = "litellm_gemini"
|
|
19
13
|
DEEPSEEK_MODEL = "litellm_deepseek"
|
|
@@ -27,12 +21,16 @@ LOG_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "counc
|
|
|
27
21
|
# LiteLLM caller so one window shows all non-Claude traffic. Optional: if the proxy
|
|
28
22
|
# tree is missing this degrades to the local council.log only, never to a crash.
|
|
29
23
|
try:
|
|
30
|
-
import pathlib as _pathlib
|
|
31
24
|
sys.path.insert(0, str(_pathlib.Path(__file__).resolve().parents[2] / "proxy" / "litellm"))
|
|
32
25
|
from call_log import log_call as _log_call
|
|
33
26
|
except Exception:
|
|
34
27
|
_log_call = None
|
|
35
28
|
|
|
29
|
+
# Shared preflight + failure-policy (fail-fast down-proxy detection, unmistakable
|
|
30
|
+
# panel-failure rendering, and the exit code contract) — see agents/lib/council_common.py.
|
|
31
|
+
sys.path.insert(0, str(_pathlib.Path(__file__).resolve().parents[1] / "lib"))
|
|
32
|
+
from council_common import PanelResult, preflight_proxy, render_and_exit # noqa: E402
|
|
33
|
+
|
|
36
34
|
|
|
37
35
|
def _log_panel_call(model, duration, usage, error=None):
|
|
38
36
|
"""Best-effort structured log of one panel call. Never raises — a logging
|
|
@@ -111,14 +109,15 @@ def call_litellm(prompt, key, model, max_tokens=2000):
|
|
|
111
109
|
error="truncated: hit max_tokens" if truncated else None)
|
|
112
110
|
if truncated:
|
|
113
111
|
text += "\n\n[response truncated — hit max_tokens cap]"
|
|
114
|
-
return text.strip()
|
|
112
|
+
return PanelResult.success(model, text.strip(), time.monotonic() - start)
|
|
115
113
|
except urllib.error.HTTPError as e:
|
|
116
114
|
detail = e.read().decode()[:300]
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
error = f"HTTP {e.code}: {detail}"
|
|
116
|
+
_log_panel_call(model, time.monotonic() - start, None, error=error)
|
|
117
|
+
return PanelResult.failure(model, error, time.monotonic() - start)
|
|
119
118
|
except Exception as e:
|
|
120
119
|
_log_panel_call(model, time.monotonic() - start, None, error=str(e))
|
|
121
|
-
return
|
|
120
|
+
return PanelResult.failure(model, e, time.monotonic() - start)
|
|
122
121
|
|
|
123
122
|
|
|
124
123
|
def call_litellm_stream(prompt, key, model, max_tokens=2000):
|
|
@@ -160,14 +159,15 @@ def call_litellm_stream(prompt, key, model, max_tokens=2000):
|
|
|
160
159
|
error="truncated: hit max_tokens" if truncated else None)
|
|
161
160
|
if truncated:
|
|
162
161
|
text += "\n\n[response truncated — hit max_tokens cap]"
|
|
163
|
-
return text
|
|
162
|
+
return PanelResult.success(model, text, time.monotonic() - start)
|
|
164
163
|
except urllib.error.HTTPError as e:
|
|
165
164
|
detail = e.read().decode()[:300]
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
error = f"HTTP {e.code}: {detail}"
|
|
166
|
+
_log_panel_call(model, time.monotonic() - start, None, error=error)
|
|
167
|
+
return PanelResult.failure(model, error, time.monotonic() - start)
|
|
168
168
|
except Exception as e:
|
|
169
169
|
_log_panel_call(model, time.monotonic() - start, None, error=str(e))
|
|
170
|
-
return
|
|
170
|
+
return PanelResult.failure(model, e, time.monotonic() - start)
|
|
171
171
|
|
|
172
172
|
|
|
173
173
|
def main():
|
|
@@ -181,8 +181,17 @@ def main():
|
|
|
181
181
|
|
|
182
182
|
or_key = os.environ.get("LITELLM_MASTER_KEY", "")
|
|
183
183
|
if not or_key:
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
render_and_exit([], key_missing=True,
|
|
185
|
+
usage_msg="Usage: council_fanout.py 'raw goal' ['context']")
|
|
186
|
+
|
|
187
|
+
# Fail fast: if the proxy itself is unreachable, every panel below will fail
|
|
188
|
+
# the same way after its own (60-90s) timeout. Detect that in ~1 request.
|
|
189
|
+
down_reason = preflight_proxy(or_key, caller="idea-council")
|
|
190
|
+
if down_reason:
|
|
191
|
+
render_and_exit([
|
|
192
|
+
PanelResult.failure(m, down_reason)
|
|
193
|
+
for m in (GEMINI_MODEL, DEEPSEEK_MODEL, QWEN_MODEL, GLM_MODEL)
|
|
194
|
+
])
|
|
186
195
|
|
|
187
196
|
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as ex:
|
|
188
197
|
f_gemini = ex.submit(call_litellm, prompt, or_key, GEMINI_MODEL, 4000)
|
|
@@ -190,18 +199,15 @@ def main():
|
|
|
190
199
|
f_qwen = ex.submit(call_litellm_stream, prompt, or_key, QWEN_MODEL, 4000)
|
|
191
200
|
f_glm = ex.submit(call_litellm, prompt, or_key, GLM_MODEL, 4000)
|
|
192
201
|
|
|
193
|
-
|
|
194
|
-
print(f_gemini.result())
|
|
195
|
-
|
|
196
|
-
print(f"\n=== {DEEPSEEK_MODEL} ===")
|
|
197
|
-
print(f_deepseek.result())
|
|
198
|
-
|
|
199
|
-
print(f"\n=== {QWEN_MODEL} ===")
|
|
200
|
-
print(f_qwen.result())
|
|
201
|
-
|
|
202
|
-
print(f"\n=== {GLM_MODEL} ===")
|
|
203
|
-
print(f_glm.result())
|
|
202
|
+
render_and_exit([f_gemini.result(), f_deepseek.result(), f_qwen.result(), f_glm.result()])
|
|
204
203
|
|
|
205
204
|
|
|
206
205
|
if __name__ == "__main__":
|
|
206
|
+
# Force utf-8 on stdout/stderr — Windows defaults to cp1252 which crashes on any
|
|
207
|
+
# non-ASCII model output. Done only under __main__ (not at import time) so tests
|
|
208
|
+
# can import this module without pytest's stdout/stderr capture being clobbered.
|
|
209
|
+
if hasattr(sys.stdout, 'buffer'):
|
|
210
|
+
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
|
211
|
+
if hasattr(sys.stderr, 'buffer'):
|
|
212
|
+
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')
|
|
207
213
|
main()
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Tests for council_fanout.py's use of the shared council_common exit-code
|
|
3
|
+
contract. Covers: proxy fully down, one panel erroring, all panels succeeding.
|
|
4
|
+
Assertions are on EXIT CODES, since the defect being fixed was silent exit 0.
|
|
5
|
+
"""
|
|
6
|
+
import sys
|
|
7
|
+
import urllib.error
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
13
|
+
import council_fanout as m # noqa: E402
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.fixture(autouse=True)
|
|
17
|
+
def _env(monkeypatch):
|
|
18
|
+
monkeypatch.setenv("LITELLM_MASTER_KEY", "fake-key")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _run_main(monkeypatch, argv):
|
|
22
|
+
monkeypatch.setattr(sys, "argv", argv)
|
|
23
|
+
with pytest.raises(SystemExit) as exc:
|
|
24
|
+
m.main()
|
|
25
|
+
return exc.value.code
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_missing_key_exits_one(monkeypatch, capsys):
|
|
29
|
+
monkeypatch.delenv("LITELLM_MASTER_KEY", raising=False)
|
|
30
|
+
code = _run_main(monkeypatch, ["council_fanout.py", "goal"])
|
|
31
|
+
assert code == 1
|
|
32
|
+
assert "LITELLM_MASTER_KEY" in capsys.readouterr().err
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_proxy_fully_down_exits_one_not_zero(monkeypatch, capsys):
|
|
36
|
+
"""The core defect: previously this scenario exited 0 with placeholder text."""
|
|
37
|
+
def fake_urlopen(*a, **k):
|
|
38
|
+
raise urllib.error.URLError("Connection refused")
|
|
39
|
+
monkeypatch.setattr(m.urllib.request, "urlopen", fake_urlopen)
|
|
40
|
+
|
|
41
|
+
code = _run_main(monkeypatch, ["council_fanout.py", "goal"])
|
|
42
|
+
assert code == 1
|
|
43
|
+
captured = capsys.readouterr()
|
|
44
|
+
assert "PANEL FAILED" in captured.out
|
|
45
|
+
assert "TOTAL FAILURE" in captured.err
|
|
46
|
+
assert "launch-litellm" in captured.err
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_one_panel_errors_others_succeed_exits_two(monkeypatch, capsys):
|
|
50
|
+
"""Preflight passes (simulate an up proxy), but one of the four panel calls
|
|
51
|
+
fails while the rest succeed — partial failure, not total, not silent."""
|
|
52
|
+
monkeypatch.setattr(m, "preflight_proxy", lambda key, timeout=5, caller=None: None)
|
|
53
|
+
|
|
54
|
+
def fake_call_litellm(prompt, key, model, max_tokens=2000):
|
|
55
|
+
if model == m.GLM_MODEL:
|
|
56
|
+
return m.PanelResult.failure(model, "HTTP 503: upstream error")
|
|
57
|
+
return m.PanelResult.success(model, f"analysis from {model}")
|
|
58
|
+
|
|
59
|
+
def fake_call_stream(prompt, key, model, max_tokens=2000):
|
|
60
|
+
return m.PanelResult.success(model, f"analysis from {model}")
|
|
61
|
+
|
|
62
|
+
monkeypatch.setattr(m, "call_litellm", fake_call_litellm)
|
|
63
|
+
monkeypatch.setattr(m, "call_litellm_stream", fake_call_stream)
|
|
64
|
+
|
|
65
|
+
code = _run_main(monkeypatch, ["council_fanout.py", "goal"])
|
|
66
|
+
assert code == 2
|
|
67
|
+
captured = capsys.readouterr()
|
|
68
|
+
assert f"=== {m.GLM_MODEL} — PANEL FAILED" in captured.out
|
|
69
|
+
assert "analysis from litellm_gemini" in captured.out
|
|
70
|
+
assert "PARTIAL FAILURE" in captured.err
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_all_panels_succeed_exits_zero(monkeypatch, capsys):
|
|
74
|
+
monkeypatch.setattr(m, "preflight_proxy", lambda key, timeout=5, caller=None: None)
|
|
75
|
+
|
|
76
|
+
def fake_call(prompt, key, model, max_tokens=2000):
|
|
77
|
+
return m.PanelResult.success(model, f"analysis from {model}")
|
|
78
|
+
|
|
79
|
+
monkeypatch.setattr(m, "call_litellm", fake_call)
|
|
80
|
+
monkeypatch.setattr(m, "call_litellm_stream", fake_call)
|
|
81
|
+
|
|
82
|
+
code = _run_main(monkeypatch, ["council_fanout.py", "goal"])
|
|
83
|
+
assert code == 0
|
|
84
|
+
captured = capsys.readouterr()
|
|
85
|
+
assert "PANEL FAILED" not in captured.out
|
|
86
|
+
assert captured.err == ""
|
|
File without changes
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
council_common.py — shared preflight + failure-policy for every council fan-out
|
|
4
|
+
script (idea, plan, review, visual-review, architecture-diagram, visual-diagnosis).
|
|
5
|
+
|
|
6
|
+
THE BUG THIS FIXES: every council script used to catch a failed panel call and
|
|
7
|
+
return the string "[<model> unavailable: <error>]" AS THAT PANEL'S ANSWER, print
|
|
8
|
+
it under a normal "=== model ===" heading, and exit 0. The synthesizing model had
|
|
9
|
+
no way to distinguish a placeholder from a genuine contribution, so a fully-down
|
|
10
|
+
council (e.g. LiteLLM proxy unreachable) silently collapsed to Claude talking to
|
|
11
|
+
itself while reporting success. This module is the ONE place that pattern is
|
|
12
|
+
fixed, so it doesn't need re-fixing per council.
|
|
13
|
+
|
|
14
|
+
Exit code contract — every council CLI built on this module must honor it:
|
|
15
|
+
0 — every panel returned a genuine answer.
|
|
16
|
+
1 — total failure: the proxy is unreachable, or every panel that was tried
|
|
17
|
+
failed. There is no genuine panel content to synthesize; callers must
|
|
18
|
+
treat this as "the council did not run", not as a degraded result.
|
|
19
|
+
2 — partial failure: at least one panel succeeded AND at least one failed.
|
|
20
|
+
The caller gets real content from the survivors, but must be told the
|
|
21
|
+
council is short-handed — a 4-panel council missing 1 is materially
|
|
22
|
+
different from one missing 3, and the exit code alone can't carry that,
|
|
23
|
+
so the printed banner always names which model(s) failed and the count.
|
|
24
|
+
|
|
25
|
+
Rationale for treating "any failure" as non-zero rather than only "all failed":
|
|
26
|
+
a council's entire value proposition is INDEPENDENT perspectives. Silently
|
|
27
|
+
downgrading a 4-panel council to 3 panels with no signal is the same class of
|
|
28
|
+
bug as downgrading it to 0 — the caller just doesn't find out. Making partial
|
|
29
|
+
failure exit 2 (not 0) forces every caller to at least look at the banner,
|
|
30
|
+
while keeping it distinct from total failure (1) so a caller that's fine with
|
|
31
|
+
"most of the council answered" can choose to proceed after inspecting it.
|
|
32
|
+
"""
|
|
33
|
+
import sys
|
|
34
|
+
import time
|
|
35
|
+
import urllib.request
|
|
36
|
+
import urllib.error
|
|
37
|
+
import pathlib as _pathlib
|
|
38
|
+
|
|
39
|
+
# Router-style call log (project / session / subagent attribution), shared by every
|
|
40
|
+
# LiteLLM caller so one window shows all non-Claude traffic. Optional: if the proxy
|
|
41
|
+
# tree is missing this degrades to no feed line, never to a crash. This is the ONE
|
|
42
|
+
# actual network call council_common itself makes (preflight_proxy, below) — every
|
|
43
|
+
# per-panel call still happens (and is separately logged) in each council's own
|
|
44
|
+
# call_litellm*/call_gemini_flash function, since that's where the model id, prompt,
|
|
45
|
+
# and per-council caller label already live.
|
|
46
|
+
try:
|
|
47
|
+
sys.path.insert(0, str(_pathlib.Path(__file__).resolve().parents[2] / "proxy" / "litellm"))
|
|
48
|
+
from call_log import log_call as _log_call
|
|
49
|
+
except Exception:
|
|
50
|
+
_log_call = None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _feed_call(caller, model, status, duration, error=None):
|
|
54
|
+
"""Best-effort feed line into the shared router-style call log. Never raises --
|
|
55
|
+
observability must not break the actual preflight check."""
|
|
56
|
+
try:
|
|
57
|
+
if _log_call:
|
|
58
|
+
_log_call(caller, model, status=status, duration=duration, error=error)
|
|
59
|
+
except Exception:
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
PROXY_URL = "http://127.0.0.1:4000/chat/completions"
|
|
64
|
+
|
|
65
|
+
LAUNCH_HINT = (
|
|
66
|
+
"LiteLLM proxy is unreachable at 127.0.0.1:4000. Run the global "
|
|
67
|
+
"'launch-litellm' skill to bring it up in a visible window, then retry."
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class PanelResult:
|
|
72
|
+
"""One panel's outcome. `ok=False` covers every failure mode (connection
|
|
73
|
+
refused, timeout, HTTP error) — NOT truncation, which is still genuine model
|
|
74
|
+
content. Callers must use `.render()` for display rather than printing
|
|
75
|
+
`.text`/`.error` directly, so a failure can never look like a real answer."""
|
|
76
|
+
|
|
77
|
+
__slots__ = ("model", "ok", "text", "error", "duration")
|
|
78
|
+
|
|
79
|
+
def __init__(self, model, ok, text="", error=None, duration=0.0):
|
|
80
|
+
self.model = model
|
|
81
|
+
self.ok = ok
|
|
82
|
+
self.text = text
|
|
83
|
+
self.error = error
|
|
84
|
+
self.duration = duration
|
|
85
|
+
|
|
86
|
+
@classmethod
|
|
87
|
+
def success(cls, model, text, duration=0.0):
|
|
88
|
+
return cls(model, True, text=text, duration=duration)
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def failure(cls, model, error, duration=0.0):
|
|
92
|
+
return cls(model, False, error=str(error), duration=duration)
|
|
93
|
+
|
|
94
|
+
def render(self):
|
|
95
|
+
"""Render this panel's block for stdout. A failure is rendered as an
|
|
96
|
+
unmissable banner instead of body text under the normal heading, so a
|
|
97
|
+
synthesizing model skimming the transcript cannot mistake it for a
|
|
98
|
+
genuine panel opinion."""
|
|
99
|
+
if self.ok:
|
|
100
|
+
return f"=== {self.model} ===\n{self.text}"
|
|
101
|
+
return (
|
|
102
|
+
f"=== {self.model} — PANEL FAILED (NOT A REAL ANSWER) ===\n"
|
|
103
|
+
f"*** THIS PANEL DID NOT RESPOND. DO NOT TREAT THIS AS A VIEWPOINT "
|
|
104
|
+
f"OR SYNTHESIZE IT AS IF IT WERE ONE. ***\n"
|
|
105
|
+
f"error: {self.error}"
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def preflight_proxy(key, timeout=5, caller="council-preflight"):
|
|
110
|
+
"""One cheap request before fanning out to every panel. Returns None if the
|
|
111
|
+
proxy process is reachable (even an HTTP error response means it's up and
|
|
112
|
+
answering), else a human-readable reason pointing at the actual remedy.
|
|
113
|
+
|
|
114
|
+
This exists so a fully-down proxy fails in ~1 request instead of being
|
|
115
|
+
discovered serially once per panel's (60-180s) timeout — the difference
|
|
116
|
+
between a ~1s failure and a multi-minute one for the exact same outcome.
|
|
117
|
+
|
|
118
|
+
This probe is fed into the shared call-log (`caller` labels which council ran
|
|
119
|
+
it) precisely BECAUSE it short-circuits everything after it: when the proxy
|
|
120
|
+
is down, none of the per-panel call_litellm*() functions ever run, so their
|
|
121
|
+
own call_log wiring never fires either. Without logging the preflight probe
|
|
122
|
+
itself, a fully-down council would leave literally zero trace in the feed —
|
|
123
|
+
the exact invisible-degrade shape this whole fix exists to close.
|
|
124
|
+
"""
|
|
125
|
+
req = urllib.request.Request(
|
|
126
|
+
PROXY_URL,
|
|
127
|
+
data=b'{"model":"__preflight__","messages":[{"role":"user","content":"ping"}],"max_tokens":1}',
|
|
128
|
+
headers={"Content-Type": "application/json", "Authorization": f"Bearer {key}"},
|
|
129
|
+
)
|
|
130
|
+
start = time.monotonic()
|
|
131
|
+
try:
|
|
132
|
+
urllib.request.urlopen(req, timeout=timeout)
|
|
133
|
+
_feed_call(caller, "__preflight__", "ok", time.monotonic() - start)
|
|
134
|
+
return None
|
|
135
|
+
except urllib.error.HTTPError:
|
|
136
|
+
# The proxy answered (even with an error status) — it's up. A model-not-
|
|
137
|
+
# found or auth error here is a different problem than "proxy is down".
|
|
138
|
+
_feed_call(caller, "__preflight__", "ok", time.monotonic() - start)
|
|
139
|
+
return None
|
|
140
|
+
except Exception as e:
|
|
141
|
+
_feed_call(caller, "__preflight__", "error", time.monotonic() - start, error=str(e))
|
|
142
|
+
return f"{LAUNCH_HINT} ({e})"
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def summarize(results):
|
|
146
|
+
"""Return (exit_code, banner_or_None) for a finished set of PanelResult, per
|
|
147
|
+
the module's exit code contract."""
|
|
148
|
+
n = len(results)
|
|
149
|
+
failed = [r for r in results if not r.ok]
|
|
150
|
+
if not failed:
|
|
151
|
+
return 0, None
|
|
152
|
+
names = ", ".join(r.model for r in failed)
|
|
153
|
+
if len(failed) == n:
|
|
154
|
+
return 1, (
|
|
155
|
+
f"COUNCIL TOTAL FAILURE: all {n} panel(s) failed ({names}). No genuine "
|
|
156
|
+
f"panel content was produced. Do not synthesize this as a real council "
|
|
157
|
+
f"result — there is nothing here but Claude's own reasoning.\n{LAUNCH_HINT}"
|
|
158
|
+
)
|
|
159
|
+
return 2, (
|
|
160
|
+
f"COUNCIL PARTIAL FAILURE: {len(failed)}/{n} panel(s) failed ({names}). "
|
|
161
|
+
f"{n - len(failed)}/{n} panel(s) below are genuine — treat any synthesis as "
|
|
162
|
+
f"representing only the surviving panels, not the full council."
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def render_and_exit(results, key_missing=False, usage_msg=None):
|
|
167
|
+
"""Print every panel's block (failures rendered unmistakably), print a
|
|
168
|
+
trailing failure banner to stderr if needed, and exit with the code the
|
|
169
|
+
module's contract specifies. Never returns."""
|
|
170
|
+
if key_missing:
|
|
171
|
+
print(f"[council] ERROR: set LITELLM_MASTER_KEY\n{usage_msg or ''}".rstrip(),
|
|
172
|
+
file=sys.stderr)
|
|
173
|
+
sys.exit(1)
|
|
174
|
+
|
|
175
|
+
for i, r in enumerate(results):
|
|
176
|
+
print(("\n" if i else "") + r.render())
|
|
177
|
+
|
|
178
|
+
code, banner = summarize(results)
|
|
179
|
+
if banner:
|
|
180
|
+
print(f"\n{banner}", file=sys.stderr)
|
|
181
|
+
sys.exit(code)
|