@event4u/agent-config 14.19.0 → 14.21.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.
Files changed (161) hide show
  1. package/.augment-plugin/marketplace.json +3 -3
  2. package/.augment-plugin/plugin.json +1 -1
  3. package/.claude-plugin/marketplace.json +1 -1
  4. package/CHANGELOG.md +351 -156
  5. package/README.md +1 -1
  6. package/agents/templates/.ai-council.yml.example +10 -0
  7. package/dist/agent-src/commands/agent-handoff.md +42 -41
  8. package/dist/agent-src/commands/analyze/inbox.md +1 -1
  9. package/dist/agent-src/commands/analyze/{reference-repo.md → repo.md} +247 -32
  10. package/dist/agent-src/commands/analyze/roadmap-repos.md +129 -0
  11. package/dist/agent-src/commands/analyze.md +12 -7
  12. package/dist/agent-src/commands/feature/plan.md +55 -16
  13. package/dist/agent-src/commands/feature/refactor.md +8 -3
  14. package/dist/agent-src/commands/humanize.md +48 -4
  15. package/dist/agent-src/contexts/execution/contract-decision-sheet.md +22 -1
  16. package/dist/agent-src/contexts/execution/host-capability-manifest.md +11 -2
  17. package/dist/agent-src/contexts/execution/roadmap-process-loop.md +35 -2
  18. package/dist/agent-src/contexts/execution/terminal-states.md +4 -1
  19. package/dist/agent-src/rules/evaluator-independence.md +4 -4
  20. package/dist/agent-src/rules/external-reference-deep-dive.md +2 -2
  21. package/dist/agent-src/rules/untrusted-input-defense.md +0 -2
  22. package/dist/agent-src/skills/competitive-positioning/SKILL.md +2 -2
  23. package/dist/agent-src/skills/evaluate-llm-feature/SKILL.md +1 -1
  24. package/dist/agent-src/skills/humanizer/references/anti-aiisms.md +27 -11
  25. package/dist/agent-src/skills/learning-to-rule-or-skill/SKILL.md +1 -1
  26. package/dist/agent-src/skills/markitdown/SKILL.md +2 -2
  27. package/dist/agent-src/skills/repomix-packer/SKILL.md +1 -1
  28. package/dist/agent-src/skills/skill-improvement-pipeline/SKILL.md +28 -6
  29. package/dist/agent-src/skills/technical-specification/SKILL.md +4 -0
  30. package/dist/agent-src/skills/test-driven-development/SKILL.md +1 -3
  31. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  32. package/dist/agent-src/templates/features.md +5 -0
  33. package/dist/agent-src/templates/roadmaps.md +29 -1
  34. package/dist/agent-src/templates/scripts/telemetry/mcp_lite.ts +213 -0
  35. package/dist/agent-src/templates/scripts/telemetry/report_renderer.ts +16 -0
  36. package/dist/agent-src/templates/scripts/telemetry_report.ts +22 -2
  37. package/dist/cli/mcp/dispatch.js +10 -0
  38. package/dist/cli/mcp/stdio.js +33 -2
  39. package/dist/cli/mcp/telemetry.js +227 -0
  40. package/dist/cli-delegate/{chunk-KPBWFOPZ.js → chunk-2FTMENJL.js} +194 -37
  41. package/dist/cli-delegate/{chunk-PMEKGDED.js → chunk-2TAQ2K4V.js} +166 -1
  42. package/dist/cli-delegate/{chunk-GZTMRYCN.js → chunk-643Z7FIC.js} +79 -12
  43. package/dist/cli-delegate/{chunk-CYH5SP6M.js → chunk-I6RHFQEG.js} +151 -16
  44. package/dist/cli-delegate/{chunk-IDHUQIXP.js → chunk-J3RFNKG4.js} +41 -5
  45. package/dist/cli-delegate/{chunk-7PRE6ZV2.js → chunk-YS6XTLEK.js} +199 -4
  46. package/dist/cli-delegate/chunk-ZVBOHSVF.js +1109 -0
  47. package/dist/cli-delegate/cmd_conformance.js +88 -110
  48. package/dist/cli-delegate/cmd_doctor.js +3 -3
  49. package/dist/cli-delegate/cmd_export.js +2 -2
  50. package/dist/cli-delegate/cmd_handoff.js +42 -12
  51. package/dist/cli-delegate/cmd_memory_get.js +1 -1
  52. package/dist/cli-delegate/cmd_prune.js +2 -2
  53. package/dist/cli-delegate/cmd_route_audit.js +1 -1
  54. package/dist/cli-delegate/cmd_session_recycle.js +59 -902
  55. package/dist/cli-delegate/cmd_settings_migrate.js +2 -2
  56. package/dist/cli-delegate/cmd_sync.js +2 -2
  57. package/dist/cli-delegate/cmd_uninstall.js +2 -2
  58. package/dist/cli-delegate/cmd_validate.js +2 -2
  59. package/dist/discovery/deprecation-report.md +1 -1
  60. package/dist/discovery/discovery-manifest.json +62 -31
  61. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  62. package/dist/discovery/discovery-manifest.summary.md +3 -3
  63. package/dist/discovery/dormancy-report.md +1 -1
  64. package/dist/discovery/orphan-report.md +1 -1
  65. package/dist/discovery/packs.json +7 -6
  66. package/dist/discovery/trust-report.md +2 -2
  67. package/dist/discovery/workspaces.json +6 -5
  68. package/dist/hooks/dispatch.js +3801 -2803
  69. package/dist/install/install.mjs +396 -168
  70. package/dist/mcp/registry-manifest.json +3 -3
  71. package/dist/mcp/server.json +2 -2
  72. package/dist/mcp/server.mjs +809 -180
  73. package/dist/scripts/ai_council/content_ceiling.js +63 -0
  74. package/dist/scripts/ai_council/seat_policy.js +106 -0
  75. package/dist/scripts/ai_council/transport_resolver.js +21 -0
  76. package/dist/scripts/mcp_server/telemetry.js +148 -0
  77. package/docs/guidelines/agent-infra/naming.md +1 -1
  78. package/docs/guidelines/agent-infra/security-lint-containment.md +46 -6
  79. package/docs/guidelines/agent-infra/self-improvement-pipeline.md +4 -4
  80. package/docs/guidelines/agent-infra/untrusted-input-spotlighting.md +1 -1
  81. package/docs/guidelines/redundancy-taxonomy.md +28 -0
  82. package/llms.txt +14 -14
  83. package/package.json +1 -1
  84. package/src/agent-src/templates/scripts/telemetry/mcp_lite.ts +213 -0
  85. package/src/agent-src/templates/scripts/telemetry/report_renderer.ts +16 -0
  86. package/src/agent-src/templates/scripts/telemetry_report.ts +22 -2
  87. package/src/config/assurance-capability-registry.json +9 -0
  88. package/src/config/gate-coverage.yml +55 -0
  89. package/src/config/gate-violation-baselines.json +18 -6
  90. package/src/config/release-gate-locality.yml +4 -3
  91. package/src/scripts/_cli/cmd_session_recycle.ts +51 -3
  92. package/src/scripts/_lib/audit_field_provenance.ts +44 -3
  93. package/src/scripts/_lib/blocked_by_marker.ts +189 -0
  94. package/src/scripts/_lib/host_capability.ts +76 -1
  95. package/src/scripts/_lib/install_reach_checks.ts +33 -1
  96. package/src/scripts/_lib/mcp_bridge.ts +222 -10
  97. package/src/scripts/_lib/mcp_consent_residual.ts +173 -0
  98. package/src/scripts/_lib/orchestration_record.ts +23 -1
  99. package/src/scripts/_lib/recycle_envelope_paths.ts +190 -0
  100. package/src/scripts/_lib/release_highlights.ts +19 -211
  101. package/src/scripts/_lib/release_material.ts +27 -77
  102. package/src/scripts/_lib/release_position.ts +96 -0
  103. package/src/scripts/_lib/review_skipped_record.ts +17 -1
  104. package/src/scripts/_lib/security_lint.ts +179 -7
  105. package/src/scripts/_lib/self_repair.ts +141 -6
  106. package/src/scripts/_lib/self_repair_store.ts +273 -7
  107. package/src/scripts/_lib/structured_ask.ts +117 -0
  108. package/src/scripts/_lib/subagent_capsule.ts +155 -3
  109. package/src/scripts/_lib/tty_prompt.ts +76 -0
  110. package/src/scripts/ai_council/api_transport.ts +163 -0
  111. package/src/scripts/ai_council/clients.ts +58 -63
  112. package/src/scripts/ai_council/config.ts +13 -0
  113. package/src/scripts/ai_council/content_ceiling.ts +79 -0
  114. package/src/scripts/ai_council/jury_aggregate.ts +178 -0
  115. package/src/scripts/ai_council/seat_policy.ts +137 -0
  116. package/src/scripts/ai_council/status_surface.ts +79 -0
  117. package/src/scripts/ai_council/transport_resolver.ts +59 -1
  118. package/src/scripts/ai_tells_rules.ts +446 -5
  119. package/src/scripts/ask_block_census.ts +499 -0
  120. package/src/scripts/bench_humanizer_eval.ts +264 -40
  121. package/src/scripts/bench_prose_tells_fp.ts +198 -0
  122. package/src/scripts/build_rule_trigger_matrix.ts +5 -0
  123. package/src/scripts/check_branch_work_committed.ts +234 -0
  124. package/src/scripts/check_mcp_doc_drift.ts +217 -0
  125. package/src/scripts/check_pack_size.ts +321 -3
  126. package/src/scripts/check_release_highlights.ts +0 -157
  127. package/src/scripts/council_cli.ts +18 -27
  128. package/src/scripts/detect_ai_tells.ts +142 -20
  129. package/src/scripts/handoff_context_hook.ts +54 -7
  130. package/src/scripts/harvest_reference_tokens.ts +698 -0
  131. package/src/scripts/hook_manifest.json +1 -1
  132. package/src/scripts/hook_manifest.yaml +31 -1
  133. package/src/scripts/hooks/concern_registry.ts +2 -0
  134. package/src/scripts/hooks/delegation_nudge_hook.ts +45 -1
  135. package/src/scripts/hooks/one_question_per_ask_hook.ts +191 -0
  136. package/src/scripts/hooks/session_eol_hook.ts +18 -7
  137. package/src/scripts/install-hooks.sh +52 -0
  138. package/src/scripts/install.ts +4 -4
  139. package/src/scripts/lint_agent_security.ts +316 -25
  140. package/src/scripts/lint_confusables.ts +42 -6
  141. package/src/scripts/lint_handoffs.ts +0 -132
  142. package/src/scripts/lint_hidden_unicode.ts +49 -7
  143. package/src/scripts/lint_instruction_smuggling.ts +42 -6
  144. package/src/scripts/lint_mcp_config_security.ts +42 -6
  145. package/src/scripts/lint_roadmap_blockers.ts +51 -1
  146. package/src/scripts/lint_roadmap_later_disposition.ts +217 -27
  147. package/src/scripts/lint_skill_frontmatter_safety.ts +43 -7
  148. package/src/scripts/mcp_server/resources.ts +41 -0
  149. package/src/scripts/mcp_server/telemetry.ts +19 -4
  150. package/src/scripts/migrate_command_suggestions.ts +1 -1
  151. package/src/scripts/orchestration_record.ts +12 -1
  152. package/src/scripts/probe_unblocked_ask.ts +135 -2
  153. package/src/scripts/release.ts +50 -95
  154. package/src/scripts/release_drill.ts +6 -10
  155. package/src/scripts/release_env.ts +1 -0
  156. package/src/scripts/release_publication.ts +40 -31
  157. package/src/scripts/self_repair_cli.ts +31 -1
  158. package/src/scripts/self_review_gate.ts +409 -15
  159. package/src/scripts/skill_scout.ts +69 -0
  160. package/dist/cli-delegate/chunk-2GNWGMAL.js +0 -172
  161. package/dist/cli-delegate/chunk-LPPWO5CE.js +0 -161
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Call telemetry for the stdio-lite MCP server (roadmap step 4.1).
3
+ *
4
+ * WHY THIS EXISTS. Before it, `grep -rn 'telemetry|collector|record'
5
+ * src/cli/mcp/*.ts` was empty: the two lite tools were invisible, so every
6
+ * statement about whether the lite surface is used at all was an assumption.
7
+ * One row per `tools/call` turns that into a reading — including a zero, which
8
+ * is a result.
9
+ *
10
+ * THREE CONSTRAINTS THE ROADMAP SET, AND HOW EACH IS MET.
11
+ *
12
+ * - **No second sink.** Rows go to the sink that already collects MCP
13
+ * `tools/call` records, `agents/runtime/mcp-telemetry/calls.jsonl`, through
14
+ * the same `record_call` the kernel server uses. Nothing new is created.
15
+ * - **No new consent gate.** The switch is the EXISTING
16
+ * `telemetry.artifact_engagement.enabled` key, default `false`. No key is
17
+ * introduced, so a consumer who has not opted into telemetry does not
18
+ * acquire a new thing to opt out of.
19
+ * - **One row per call, none when off.** `recordLiteCall` is the only writer
20
+ * and returns `null` without touching the filesystem when the gate is off.
21
+ *
22
+ * PRIVACY BY CONSTRUCTION. Two fields are caller-influenced and both are
23
+ * clamped at the boundary. `host` is resolved against a CLOSED vocabulary; an
24
+ * unrecognised client name becomes `other`, never the string the client sent.
25
+ * `tool_name` is caller-supplied on the wire — a client may call
26
+ * `tools/call` with ANY name — so a name outside a conservative identifier
27
+ * shape is recorded as `other_tool` rather than stored verbatim. Without that
28
+ * clamp the sink would accept a path or a secret as a tool name and this
29
+ * report would print it. The record therefore has no field capable of carrying
30
+ * free-form text, and there is no scrubbing pass that could fail because there
31
+ * is nothing to scrub. The client-install hash comes from the kernel collector
32
+ * unchanged.
33
+ *
34
+ * NEVER THROWS. Telemetry must not break the wire surface; every path here
35
+ * either records or returns `null`.
36
+ */
37
+ import * as fs from 'node:fs';
38
+ import * as path from 'node:path';
39
+ import { record_call } from '../../scripts/mcp_server/telemetry.js';
40
+ /** Transport label for this surface — distinguishes it from the kernel server. */
41
+ export const LITE_TRANSPORT = 'stdio-lite';
42
+ /** The settings key that gates every row. Deliberately an EXISTING key. */
43
+ export const LITE_TELEMETRY_SETTING = 'telemetry.artifact_engagement.enabled';
44
+ /**
45
+ * The closed host vocabulary.
46
+ *
47
+ * Membership is what makes the field non-identifying: a value is either one of
48
+ * these literals, `other`, or `unknown`. It is matched against the MCP
49
+ * `clientInfo.name` a client sends at `initialize`, lower-cased, with `_` and
50
+ * spaces folded to `-`; a name that merely CONTAINS one of these is resolved to
51
+ * it, because clients ship names like `claude-code-cli` and `Cursor (0.42)`.
52
+ */
53
+ export const KNOWN_HOSTS = [
54
+ 'claude-code',
55
+ 'claude-desktop',
56
+ 'cursor',
57
+ 'windsurf',
58
+ 'cline',
59
+ 'gemini-cli',
60
+ 'copilot',
61
+ 'augment',
62
+ 'aider',
63
+ 'codex',
64
+ 'roocode',
65
+ 'continue',
66
+ 'kilocode',
67
+ 'zed',
68
+ 'jetbrains',
69
+ 'kiro',
70
+ 'opencode',
71
+ 'trae',
72
+ 'warp',
73
+ ];
74
+ /** No `initialize` seen yet, or it carried no client name. */
75
+ export const HOST_UNKNOWN = 'unknown';
76
+ /** A client name that is not in the closed vocabulary. Never the raw string. */
77
+ export const HOST_OTHER = 'other';
78
+ /**
79
+ * Resolve a client-supplied name onto the closed vocabulary.
80
+ *
81
+ * Longest match first, so `claude-desktop` is not swallowed by a shorter
82
+ * sibling and `claude-code` wins over a bare `claude` substring.
83
+ */
84
+ export function normalizeHost(clientName) {
85
+ if (typeof clientName !== 'string')
86
+ return HOST_UNKNOWN;
87
+ const folded = clientName.trim().toLowerCase().replace(/[_\s]+/g, '-');
88
+ if (folded === '')
89
+ return HOST_UNKNOWN;
90
+ const byLength = [...KNOWN_HOSTS].sort((a, b) => b.length - a.length);
91
+ for (const known of byLength) {
92
+ if (folded === known || folded.includes(known))
93
+ return known;
94
+ }
95
+ return HOST_OTHER;
96
+ }
97
+ /**
98
+ * The shape a tool name must have to be stored verbatim.
99
+ *
100
+ * Conservative on purpose: MCP tool names are identifiers, so anything with a
101
+ * separator, whitespace, or unusual length is not a tool name that this surface
102
+ * could ever serve — it is caller-supplied text, and text is what must not
103
+ * reach the store.
104
+ */
105
+ const TOOL_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$/;
106
+ /** A caller-supplied name that is not identifier-shaped. Never the raw string. */
107
+ export const TOOL_OTHER = 'other_tool';
108
+ /**
109
+ * Clamp a wire tool name onto a storable one.
110
+ *
111
+ * A name this surface actually serves always passes; an unknown but
112
+ * identifier-shaped name passes too, because that is the latent-demand signal
113
+ * the store exists to carry. Everything else becomes `other_tool`.
114
+ */
115
+ export function normalizeToolName(name, isLiteTool) {
116
+ if (typeof name !== 'string' || name === '')
117
+ return '';
118
+ if (isLiteTool)
119
+ return name;
120
+ return TOOL_NAME_RE.test(name) ? name : TOOL_OTHER;
121
+ }
122
+ /** `str.strip()` on both ends, matching the sibling settings peeks in `src/cli`. */
123
+ function _strip(s) {
124
+ return s.replace(/^[ \t\r\f\v]+/, '').replace(/[ \t\r\f\v]+$/, '');
125
+ }
126
+ /**
127
+ * Read `telemetry.artifact_engagement.enabled` from a project settings file.
128
+ *
129
+ * A deliberately small nested-key peek over the YAML subset this package's own
130
+ * settings files are written in — the same shape `workspace_crypto.isEnabled`
131
+ * and `workspace_analytics` already use in `src/cli`, and for the same reason:
132
+ * the lite server must stay pure-Node with no YAML dependency.
133
+ *
134
+ * Every failure resolves to `false`. Missing file, unreadable file, missing
135
+ * section, missing key and an unparseable value are all indistinguishable and
136
+ * all mean OFF — the default-off doctrine the engagement collector states for
137
+ * itself.
138
+ */
139
+ export function liteTelemetryEnabled(settingsPath) {
140
+ const p = settingsPath ?? path.join(process.cwd(), '.agent-settings.yml');
141
+ let text;
142
+ try {
143
+ text = fs.readFileSync(p, 'utf-8');
144
+ }
145
+ catch {
146
+ return false;
147
+ }
148
+ // Track the two nesting levels the key needs: `telemetry:` at column 0,
149
+ // then `artifact_engagement:` beneath it, then `enabled:` beneath that.
150
+ let inTelemetry = false;
151
+ let inSection = false;
152
+ let sectionIndent = -1;
153
+ for (const raw of text.split(/\r\n|\r|\n/)) {
154
+ const line = raw.replace(/[ \t\r\f\v]+$/, '');
155
+ if (line === '' || _strip(line).startsWith('#'))
156
+ continue;
157
+ const indent = line.length - line.replace(/^ +/, '').length;
158
+ const body = _strip(line);
159
+ if (indent === 0) {
160
+ inTelemetry = body === 'telemetry:';
161
+ inSection = false;
162
+ sectionIndent = -1;
163
+ continue;
164
+ }
165
+ if (!inTelemetry)
166
+ continue;
167
+ if (!inSection) {
168
+ if (body === 'artifact_engagement:') {
169
+ inSection = true;
170
+ sectionIndent = indent;
171
+ }
172
+ continue;
173
+ }
174
+ // Left the section — a sibling key at or above its indent closes it.
175
+ if (indent <= sectionIndent) {
176
+ inSection = body === 'artifact_engagement:';
177
+ if (inSection)
178
+ sectionIndent = indent;
179
+ continue;
180
+ }
181
+ if (body.startsWith('enabled:')) {
182
+ const value = _strip(body.slice('enabled:'.length)).toLowerCase();
183
+ return value === 'true' || value === 'yes' || value === 'on';
184
+ }
185
+ }
186
+ return false;
187
+ }
188
+ /**
189
+ * Classify one lite `tools/call`.
190
+ *
191
+ * `implemented` — a lite tool ran. `stub` — the name is not on this surface, so
192
+ * the `not_implemented` envelope was returned, which is exactly the condition
193
+ * the kernel collector defines that outcome for. The lite server cannot
194
+ * distinguish "in the kernel catalogue but absent here" from "in no catalogue
195
+ * at all", so it never claims `latent_demand`: the kernel server owns that
196
+ * distinction, and guessing it here would put an unearned claim in the store.
197
+ */
198
+ export function classifyLiteOutcome(isLiteTool) {
199
+ return isLiteTool ? 'implemented' : 'stub';
200
+ }
201
+ /**
202
+ * Append exactly one row for one `tools/call`, or nothing.
203
+ *
204
+ * Returns the record written, or `null` when the gate is off or the write
205
+ * failed. Never throws.
206
+ */
207
+ export function recordLiteCall(options) {
208
+ const { toolName, isLiteTool, host, consumerRoot, settingsPath } = options;
209
+ const stored = normalizeToolName(toolName, isLiteTool);
210
+ if (stored === '')
211
+ return null;
212
+ try {
213
+ if (!liteTelemetryEnabled(settingsPath))
214
+ return null;
215
+ return record_call({
216
+ tool_name: stored,
217
+ outcome: classifyLiteOutcome(isLiteTool),
218
+ transport: LITE_TRANSPORT,
219
+ consumer_root: consumerRoot,
220
+ host,
221
+ });
222
+ }
223
+ catch {
224
+ return null;
225
+ }
226
+ }
227
+ //# sourceMappingURL=telemetry.js.map
@@ -81,7 +81,7 @@ __export(clients_exports, {
81
81
  record_cli_call: () => record_cli_call,
82
82
  reset_cli_call_counts: () => reset_cli_call_counts
83
83
  });
84
- import { spawnSync } from "node:child_process";
84
+ import { spawnSync as spawnSync2 } from "node:child_process";
85
85
  import * as fs3 from "node:fs";
86
86
  import * as os from "node:os";
87
87
  import * as path3 from "node:path";
@@ -205,6 +205,88 @@ function boundFor(member) {
205
205
  return AGENCY_BOUNDS.find((b) => b.member === member)?.bound ?? [];
206
206
  }
207
207
 
208
+ // src/scripts/ai_council/api_transport.ts
209
+ import { spawnSync } from "node:child_process";
210
+ var GEMINI_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
211
+ function curlJsonPost(url, extraHeaders, body) {
212
+ const args = ["-sS", "-X", "POST", url, "-H", "content-type: application/json"];
213
+ for (const h of extraHeaders) {
214
+ args.push("-H", h);
215
+ }
216
+ args.push("--connect-timeout", "30", "--max-time", "290");
217
+ args.push("-w", "\n%{http_code}", "--data-binary", "@-");
218
+ const r = spawnSync("curl", args, {
219
+ input: JSON.stringify(body),
220
+ encoding: "utf8",
221
+ maxBuffer: 64 * 1024 * 1024,
222
+ timeout: 3e5
223
+ });
224
+ if (r.error) {
225
+ throw new Error(`curl spawn failed: ${r.error.message}`);
226
+ }
227
+ if (r.status !== 0) {
228
+ throw new Error(
229
+ `curl exited ${r.status ?? "null"}: ${(r.stderr ?? "").toString().slice(0, 500)}`
230
+ );
231
+ }
232
+ const out = (r.stdout ?? "").toString();
233
+ const nl = out.lastIndexOf("\n");
234
+ const httpCode = (nl >= 0 ? out.slice(nl + 1) : out).trim();
235
+ const bodyText = nl >= 0 ? out.slice(0, nl) : out;
236
+ if (!/^2\d\d$/.test(httpCode)) {
237
+ throw new Error(`HTTP ${httpCode}: ${bodyText.slice(0, 500)}`);
238
+ }
239
+ return JSON.parse(bodyText);
240
+ }
241
+ function openAiCompatibleClient(baseUrl, apiKey, post = curlJsonPost) {
242
+ const url = `${baseUrl.replace(/\/+$/, "")}/chat/completions`;
243
+ return {
244
+ chat: {
245
+ completions: {
246
+ create: (kwargs) => post(url, [`authorization: Bearer ${apiKey}`], kwargs)
247
+ }
248
+ }
249
+ };
250
+ }
251
+ function geminiRestClient(apiKey, post = curlJsonPost, baseUrl = GEMINI_BASE_URL) {
252
+ return {
253
+ models: {
254
+ generate_content: (kwargs) => {
255
+ const model = String(kwargs["model"] ?? "");
256
+ const cfg = kwargs["config"] ?? {};
257
+ const url = `${baseUrl.replace(/\/+$/, "")}/models/${model}:generateContent`;
258
+ const raw = post(
259
+ url,
260
+ [`x-goog-api-key: ${apiKey}`],
261
+ {
262
+ contents: [{ role: "user", parts: [{ text: String(kwargs["contents"] ?? "") }] }],
263
+ generationConfig: { maxOutputTokens: cfg["max_output_tokens"] ?? null }
264
+ }
265
+ );
266
+ return normaliseGeminiRest(raw);
267
+ }
268
+ }
269
+ };
270
+ }
271
+ function normaliseGeminiRest(raw) {
272
+ const env = raw ?? {};
273
+ const candidates = Array.isArray(env["candidates"]) ? env["candidates"] : [];
274
+ const first = candidates[0] ?? {};
275
+ const content = first["content"] ?? {};
276
+ const parts = Array.isArray(content["parts"]) ? content["parts"] : [];
277
+ const text = parts.map((p) => String((p ?? {})["text"] ?? "")).join("");
278
+ const usage = env["usageMetadata"] ?? {};
279
+ const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : 0;
280
+ return {
281
+ text,
282
+ model_version: String(env["modelVersion"] ?? ""),
283
+ usage_metadata: {
284
+ prompt_token_count: num(usage["promptTokenCount"]),
285
+ candidates_token_count: num(usage["candidatesTokenCount"])
286
+ }
287
+ };
288
+ }
289
+
208
290
  // src/scripts/_lib/session_role.ts
209
291
  var SESSION_ROLE_ENV = "AGENT_CONFIG_SESSION_ROLE";
210
292
  var KNOWN_ROLES = /* @__PURE__ */ new Set(["orchestrator", "worker", "reviewer"]);
@@ -899,34 +981,6 @@ var ExternalAIClient = class {
899
981
  return this.ask(system_prompt, user_prompt, max_tokens);
900
982
  }
901
983
  };
902
- function _curlJsonPost(url, extraHeaders, body) {
903
- const args = ["-sS", "-X", "POST", url, "-H", "content-type: application/json"];
904
- for (const h of extraHeaders) {
905
- args.push("-H", h);
906
- }
907
- args.push("--connect-timeout", "30", "--max-time", "290");
908
- args.push("-w", "\n%{http_code}", "--data-binary", "@-");
909
- const r = spawnSync("curl", args, {
910
- input: JSON.stringify(body),
911
- encoding: "utf8",
912
- maxBuffer: 64 * 1024 * 1024,
913
- timeout: 3e5
914
- });
915
- if (r.error) {
916
- throw new Error(`curl spawn failed: ${r.error.message}`);
917
- }
918
- if (r.status !== 0) {
919
- throw new Error(`curl exited ${r.status ?? "null"}: ${(r.stderr ?? "").toString().slice(0, 500)}`);
920
- }
921
- const out = (r.stdout ?? "").toString();
922
- const nl = out.lastIndexOf("\n");
923
- const httpCode = (nl >= 0 ? out.slice(nl + 1) : out).trim();
924
- const bodyText = nl >= 0 ? out.slice(0, nl) : out;
925
- if (!/^2\d\d$/.test(httpCode)) {
926
- throw new Error(`HTTP ${httpCode}: ${bodyText.slice(0, 500)}`);
927
- }
928
- return JSON.parse(bodyText);
929
- }
930
984
  var AnthropicClient = class extends ExternalAIClient {
931
985
  name = "anthropic";
932
986
  billable = true;
@@ -957,7 +1011,7 @@ var AnthropicClient = class extends ExternalAIClient {
957
1011
  }
958
1012
  this._client = {
959
1013
  messages: {
960
- create: (kwargs) => _curlJsonPost(
1014
+ create: (kwargs) => curlJsonPost(
961
1015
  "https://api.anthropic.com/v1/messages",
962
1016
  [`x-api-key: ${api_key}`, "anthropic-version: 2023-06-01"],
963
1017
  kwargs
@@ -1081,7 +1135,7 @@ var OpenAIClient = class extends ExternalAIClient {
1081
1135
  this._client = {
1082
1136
  chat: {
1083
1137
  completions: {
1084
- create: (kwargs) => _curlJsonPost(
1138
+ create: (kwargs) => curlJsonPost(
1085
1139
  "https://api.openai.com/v1/chat/completions",
1086
1140
  [`authorization: Bearer ${api_key}`],
1087
1141
  kwargs
@@ -1164,7 +1218,7 @@ var GeminiClient = class extends ExternalAIClient {
1164
1218
  "GeminiClient requires explicit api_key or injected client. Use `api_key_ref: env:GEMINI_API_KEY` in ~/.event4u/agent-config/settings/.ai-council.yml."
1165
1219
  );
1166
1220
  }
1167
- throw new Error("google-genai package not installed. `pip install google-genai`.");
1221
+ this._client = geminiRestClient(api_key, opts.transport ?? curlJsonPost);
1168
1222
  }
1169
1223
  ask(system_prompt, user_prompt, max_tokens = DEFAULT_MAX_TOKENS) {
1170
1224
  const t0 = _nowMs();
@@ -1226,7 +1280,11 @@ var _OpenAICompatibleClient = class extends ExternalAIClient {
1226
1280
  `${this.constructor.name} requires explicit api_key or injected client.`
1227
1281
  );
1228
1282
  }
1229
- throw new Error("openai package not installed. `pip install openai`.");
1283
+ this._client = openAiCompatibleClient(
1284
+ opts.base_url,
1285
+ api_key,
1286
+ opts.transport ?? curlJsonPost
1287
+ );
1230
1288
  }
1231
1289
  ask(system_prompt, user_prompt, max_tokens = DEFAULT_MAX_TOKENS) {
1232
1290
  const t0 = _nowMs();
@@ -1279,7 +1337,13 @@ var XAIClient = class extends _OpenAICompatibleClient {
1279
1337
  name = "xai";
1280
1338
  base_url = XAI_BASE_URL;
1281
1339
  constructor(opts = {}) {
1282
- super({ model: opts.model ?? DEFAULT_XAI_MODEL, client: opts.client, api_key: opts.api_key });
1340
+ super({
1341
+ model: opts.model ?? DEFAULT_XAI_MODEL,
1342
+ client: opts.client,
1343
+ api_key: opts.api_key,
1344
+ transport: opts.transport,
1345
+ base_url: XAI_BASE_URL
1346
+ });
1283
1347
  }
1284
1348
  };
1285
1349
  var PerplexityClient = class extends _OpenAICompatibleClient {
@@ -1289,7 +1353,9 @@ var PerplexityClient = class extends _OpenAICompatibleClient {
1289
1353
  super({
1290
1354
  model: opts.model ?? DEFAULT_PERPLEXITY_MODEL,
1291
1355
  client: opts.client,
1292
- api_key: opts.api_key
1356
+ api_key: opts.api_key,
1357
+ transport: opts.transport,
1358
+ base_url: PERPLEXITY_BASE_URL
1293
1359
  });
1294
1360
  }
1295
1361
  };
@@ -1546,7 +1612,7 @@ var CliClient = class extends ExternalAIClient {
1546
1612
  if (stdinPayload !== null) {
1547
1613
  spawnOpts.input = stdinPayload;
1548
1614
  }
1549
- const r = spawnSync(argv0, cmd.slice(1), spawnOpts);
1615
+ const r = spawnSync2(argv0, cmd.slice(1), spawnOpts);
1550
1616
  if (r.error) {
1551
1617
  const err = r.error;
1552
1618
  if (r.signal === "SIGTERM" || err.code === "ETIMEDOUT") {
@@ -2636,6 +2702,89 @@ import * as fs4 from "node:fs";
2636
2702
  import * as os2 from "node:os";
2637
2703
  import * as path4 from "node:path";
2638
2704
 
2705
+ // src/scripts/ai_council/content_ceiling.ts
2706
+ var CONTENT_CLASSES = ["public-artifact", "project-content"];
2707
+ var DEFAULT_CONTENT_CLASS = "project-content";
2708
+ var DEFAULT_SEAT_CEILING = "project-content";
2709
+ var _SET = new Set(CONTENT_CLASSES);
2710
+ function classifyContentClass(raw, fallback = DEFAULT_CONTENT_CLASS) {
2711
+ if (typeof raw === "string" && _SET.has(raw)) {
2712
+ return raw;
2713
+ }
2714
+ return fallback;
2715
+ }
2716
+ function admitsContent(seatCeiling, contentClass) {
2717
+ if (seatCeiling === "public-artifact" && contentClass === "project-content") {
2718
+ return {
2719
+ admitted: false,
2720
+ reason: "seat ceiling is 'public-artifact'; the payload is classified 'project-content' (consumer-supplied)"
2721
+ };
2722
+ }
2723
+ return { admitted: true, reason: null };
2724
+ }
2725
+
2726
+ // src/scripts/ai_council/seat_policy.ts
2727
+ var POLICY_EXCLUSIONS = [
2728
+ /** The provider's terms forbid this use of the route. */
2729
+ "policy_terms",
2730
+ /** A privacy constraint forbids sending to this route. */
2731
+ "policy_privacy",
2732
+ /** The route's cost property is asserted rather than proven. */
2733
+ "policy_unproven_cost",
2734
+ /** The route serves a model other than the one requested. */
2735
+ "policy_model_mismatch",
2736
+ /** 2.2 — the payload's content class exceeds the seat's ceiling. */
2737
+ "policy_content_ceiling",
2738
+ /** The config named an exclusion this build does not understand. */
2739
+ "policy_unknown"
2740
+ ];
2741
+ var _SET2 = new Set(POLICY_EXCLUSIONS);
2742
+ function isPolicyExclusion(v) {
2743
+ return typeof v === "string" && _SET2.has(v);
2744
+ }
2745
+ function classifyPolicyExclusion(raw) {
2746
+ if (raw === void 0 || raw === null) {
2747
+ return null;
2748
+ }
2749
+ return isPolicyExclusion(raw) ? raw : "policy_unknown";
2750
+ }
2751
+ function policyExclusionReason(p, provider) {
2752
+ const who = provider === void 0 ? "this seat" : provider;
2753
+ switch (p) {
2754
+ case "policy_terms":
2755
+ return `${who} is excluded by policy: the route's terms forbid this use`;
2756
+ case "policy_privacy":
2757
+ return `${who} is excluded by policy: a privacy constraint forbids this route`;
2758
+ case "policy_unproven_cost":
2759
+ return `${who} is excluded by policy: the route's cost property is asserted, not proven`;
2760
+ case "policy_model_mismatch":
2761
+ return `${who} is excluded by policy: the route serves a model other than the one requested`;
2762
+ case "policy_content_ceiling":
2763
+ return `${who} is excluded by policy: the payload exceeds the seat's content ceiling`;
2764
+ case "policy_unknown":
2765
+ return `${who} is excluded by policy: an exclusion this build does not understand (failing closed)`;
2766
+ }
2767
+ }
2768
+ function parseSeatFields(name, raw) {
2769
+ const dr = raw["disabled_reason"];
2770
+ let disabled_reason = null;
2771
+ if (dr !== void 0 && dr !== null) {
2772
+ if (typeof dr !== "string" || dr.trim() === "") {
2773
+ return {
2774
+ error: `members.${name}.disabled_reason must be a non-empty string when set (got ${JSON.stringify(dr)}).`
2775
+ };
2776
+ }
2777
+ disabled_reason = dr.trim();
2778
+ }
2779
+ return {
2780
+ fields: {
2781
+ disabled_reason,
2782
+ policy_exclusion: classifyPolicyExclusion(raw["policy_exclusion"]),
2783
+ content_ceiling: classifyContentClass(raw["content_ceiling"], DEFAULT_SEAT_CEILING)
2784
+ }
2785
+ };
2786
+ }
2787
+
2639
2788
  // src/scripts/ai_council/fallback_config.ts
2640
2789
  var SECOND_MODEL_PROVIDERS = /* @__PURE__ */ new Set([
2641
2790
  "anthropic",
@@ -3830,6 +3979,10 @@ function _build_member(name, cfg, default_mode = "auto", ignored = []) {
3830
3979
  }
3831
3980
  verified_at = coerced;
3832
3981
  }
3982
+ const seat = parseSeatFields(name, cfg);
3983
+ if ("error" in seat) {
3984
+ throw new CouncilConfigError(seat.error);
3985
+ }
3833
3986
  const prompt_cache_raw = _get(cfg, "prompt_cache", null);
3834
3987
  let prompt_cache_ttl = "5m";
3835
3988
  if (prompt_cache_raw !== null && prompt_cache_raw !== void 0 && !_isBool(prompt_cache_raw)) {
@@ -3857,7 +4010,8 @@ function _build_member(name, cfg, default_mode = "auto", ignored = []) {
3857
4010
  participate_low_impact: participate_raw,
3858
4011
  tier,
3859
4012
  prompt_cache_ttl,
3860
- verified_at
4013
+ verified_at,
4014
+ ...seat.fields
3861
4015
  };
3862
4016
  }
3863
4017
  var DEFAULT_CLI_CALLS_PER_DAY2 = DEFAULT_CLI_CALLS_PER_DAY;
@@ -4210,6 +4364,9 @@ export {
4210
4364
  hardenedSpawnEnv,
4211
4365
  load_cli_call_counts,
4212
4366
  clients_exports,
4367
+ DEFAULT_SEAT_CEILING,
4368
+ admitsContent,
4369
+ policyExclusionReason,
4213
4370
  _RAW_KEY_PREFIXES,
4214
4371
  config_exports
4215
4372
  };