vigiles 5.0.0 → 5.1.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 (38) hide show
  1. package/README.md +82 -116
  2. package/dist/adapters/claude-code/agent-runtime.d.ts +10 -0
  3. package/dist/adapters/claude-code/agent-runtime.js +15 -29
  4. package/dist/adapters/claude-code/dialect.js +18 -2
  5. package/dist/adapters/codex/eval.d.ts +94 -0
  6. package/dist/adapters/codex/eval.js +227 -0
  7. package/dist/cli.js +464 -8
  8. package/dist/codex.d.ts +1 -0
  9. package/dist/codex.js +3 -0
  10. package/dist/core/compile.js +8 -36
  11. package/dist/core/description-overlap.d.ts +27 -0
  12. package/dist/core/description-overlap.js +53 -0
  13. package/dist/core/dialect.d.ts +8 -0
  14. package/dist/core/frontmatter-read.d.ts +25 -0
  15. package/dist/core/frontmatter-read.js +138 -0
  16. package/dist/core/hook-events.d.ts +34 -0
  17. package/dist/core/hook-events.js +48 -0
  18. package/dist/core/mcp-config.d.ts +20 -0
  19. package/dist/core/mcp-config.js +40 -0
  20. package/dist/core/mcp-hook.d.ts +35 -0
  21. package/dist/core/mcp-hook.js +70 -0
  22. package/dist/core/mcp-tool.d.ts +50 -0
  23. package/dist/core/mcp-tool.js +61 -0
  24. package/dist/core/tool-contract.d.ts +68 -0
  25. package/dist/core/tool-contract.js +113 -0
  26. package/dist/core/types.d.ts +89 -0
  27. package/dist/core/validate.js +22 -0
  28. package/dist/eval.d.ts +69 -13
  29. package/dist/eval.js +106 -51
  30. package/dist/leaderboard.js +61 -3
  31. package/dist/plugin-loader.d.ts +1 -0
  32. package/dist/plugin-loader.js +71 -18
  33. package/dist/scan-behavioral.d.ts +73 -0
  34. package/dist/scan-behavioral.js +150 -0
  35. package/dist/scan.d.ts +126 -1
  36. package/dist/scan.js +559 -40
  37. package/package.json +27 -4
  38. package/skills/migrate-to-spec/SKILL.md +0 -2
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ /**
3
+ * Codex EVAL-tier transport — the runner + trace parser that
4
+ * `measureTriggerRate`/`runEval` dispatch to via the `ModelOutputParser` seam.
5
+ *
6
+ * SCHEMA: CONFIRMED against real `codex exec --json` (codex-cli 0.139.0, ChatGPT
7
+ * auth). The stream is the thread/item model:
8
+ *
9
+ * {"type":"thread.started","thread_id":"…"}
10
+ * {"type":"turn.started"}
11
+ * {"type":"item.started","item":{"id":"item_0","type":"command_execution",…}} // mid-flight
12
+ * {"type":"item.completed","item":{"id":"item_0","type":"command_execution","command":"…","aggregated_output":"…","exit_code":0}}
13
+ * {"type":"item.completed","item":{"id":"item_1","type":"agent_message","text":"…"}}
14
+ * {"type":"turn.completed","usage":{"input_tokens":…,"cached_input_tokens":…,"output_tokens":…}}
15
+ *
16
+ * So: assistant text = `item.completed` with `item.type:"agent_message"` →
17
+ * `item.text`; a tool call = `item.type:"command_execution"` → `item.command`;
18
+ * usage rides `turn.completed`. We count `item.completed` ONLY (an `item.started`
19
+ * carries the same `id` mid-flight — counting both double-counts).
20
+ *
21
+ * THE SKILL FINDING: Codex has NO discrete "skill selected" event (its CLI has no
22
+ * Skill-tool concept). When a skill triggers, the model READS the skill's
23
+ * `SKILL.md` via a `command_execution` (`sed/cat … skills/<name>/SKILL.md`) and
24
+ * usually says so in an `agent_message`. So "did skill X fire" on Codex is not a
25
+ * clean trace event like Claude's `Skill` tool_use — it's detected by the
26
+ * SKILL.md read (`codexSkillFired`). Best-effort by nature (a cached skill might
27
+ * not be re-read); pair with a behavioral/judged check for certainty.
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.codexEvalDriver = void 0;
31
+ exports.parseCodexEvalRun = parseCodexEvalRun;
32
+ exports.codexRunError = codexRunError;
33
+ exports.codexSkillFired = codexSkillFired;
34
+ exports.installCodexSkills = installCodexSkills;
35
+ exports.codexEvalAgentRunner = codexEvalAgentRunner;
36
+ exports.codexEvalRunner = codexEvalRunner;
37
+ const node_child_process_1 = require("node:child_process");
38
+ const node_fs_1 = require("node:fs");
39
+ const node_path_1 = require("node:path");
40
+ const str = (v) => (typeof v === "string" ? v : "");
41
+ const num = (v) => (typeof v === "number" ? v : 0);
42
+ /** Parse the JSONL stream, skipping blank / non-JSON / malformed lines. */
43
+ function parseLines(stdout) {
44
+ const out = [];
45
+ for (const line of stdout.split(/\r?\n/)) {
46
+ const s = line.trim();
47
+ if (!s.startsWith("{"))
48
+ continue;
49
+ try {
50
+ out.push(JSON.parse(s));
51
+ }
52
+ catch {
53
+ /* tolerate a partial / non-event line */
54
+ }
55
+ }
56
+ return out;
57
+ }
58
+ /** Is this completed item a tool/command call (vs an agent_message / error)? */
59
+ function isToolItem(itemType) {
60
+ return (itemType === "command_execution" || /function_call|tool/.test(itemType));
61
+ }
62
+ function buildCall(item, itemType) {
63
+ return {
64
+ // command_execution → the shell command; function-style → its name.
65
+ name: str(item.command) || str(item.name) || itemType,
66
+ input: item,
67
+ resultText: str(item.aggregated_output),
68
+ isError: num(item.exit_code) !== 0 && item.exit_code != null,
69
+ };
70
+ }
71
+ /** Map a `turn.completed` usage block to the common EvalUsage. */
72
+ function usageFrom(u) {
73
+ return {
74
+ costUsd: 0, // codex on the ChatGPT sub reports no per-run USD
75
+ durationMs: 0,
76
+ inputTokens: num(u.input_tokens),
77
+ outputTokens: num(u.output_tokens),
78
+ cacheCreationTokens: 0,
79
+ cacheReadTokens: num(u.cached_input_tokens),
80
+ };
81
+ }
82
+ const ZERO_USAGE = {
83
+ costUsd: 0,
84
+ durationMs: 0,
85
+ inputTokens: 0,
86
+ outputTokens: 0,
87
+ cacheCreationTokens: 0,
88
+ cacheReadTokens: 0,
89
+ };
90
+ /** Parse `codex exec --json` stdout into the common trace fields (confirmed schema). */
91
+ function parseCodexEvalRun(out) {
92
+ const texts = [];
93
+ const toolCalls = [];
94
+ let usage = ZERO_USAGE;
95
+ for (const e of parseLines(out.stdout)) {
96
+ if (e.type === "turn.completed" && e.usage)
97
+ usage = usageFrom(e.usage);
98
+ // Count COMPLETED items only — item.started carries the same id mid-flight.
99
+ if (e.type !== "item.completed" || !e.item)
100
+ continue;
101
+ const itemType = str(e.item.type);
102
+ if (itemType === "agent_message") {
103
+ const t = str(e.item.text);
104
+ if (t)
105
+ texts.push(t);
106
+ }
107
+ else if (isToolItem(itemType)) {
108
+ toolCalls.push(buildCall(e.item, itemType));
109
+ }
110
+ }
111
+ return {
112
+ // Fallback to trimmed stdout if no agent_message was seen (keeps output non-empty).
113
+ output: texts.join("\n") || out.stdout.trim(),
114
+ turns: texts.length,
115
+ toolCalls,
116
+ hooks: [],
117
+ subagents: [],
118
+ usage,
119
+ };
120
+ }
121
+ /**
122
+ * The error message if the run errored or was rate-limited (an `error` /
123
+ * `turn.failed` event), else null. CRITICAL for the eval tier: an errored turn
124
+ * must NOT be scored as a clean "skill didn't fire" miss — dogfooding hit a Codex
125
+ * usage limit ("You've hit your usage limit…") whose `error` event left an empty
126
+ * trace that `codexSkillFired` read as recall 0. A caller should skip/retry an
127
+ * errored run, not count it. (The Claude path has `isRateLimited` + backoff; this
128
+ * is the Codex equivalent detector.)
129
+ */
130
+ function codexRunError(out) {
131
+ for (const e of parseLines(out.stdout)) {
132
+ if (e.type === "error")
133
+ return str(e.message) || "codex error";
134
+ if (e.type === "turn.failed")
135
+ return str(e.error?.message) || "turn failed";
136
+ }
137
+ return null;
138
+ }
139
+ /**
140
+ * Did Codex activate skill `name` on this run? Detected by the SKILL.md read —
141
+ * Codex has no discrete skill-selection event, so when a skill triggers the model
142
+ * reads its `…/<name>/SKILL.md` via a `command_execution`. Best-effort (a cached
143
+ * skill might not be re-read); for the trigger-rate `fired` predicate over Codex.
144
+ */
145
+ function codexSkillFired(run, name) {
146
+ const needle = `${name}/SKILL.md`;
147
+ return run.toolCalls.some((c) => str(c.name).includes(needle));
148
+ }
149
+ /**
150
+ * Materialize a (Claude-shaped) plugin dir's skills into `<cwd>/.codex/skills/` —
151
+ * where Codex actually discovers them (validated live: codex reads
152
+ * `<cwd>/.codex/skills/<name>/SKILL.md`). This is the Codex analog of Claude's
153
+ * `--plugin-dir`: `measureTriggerRate` hands the runner a `pluginDir` (the
154
+ * stubbed/packaged skills), and the Codex runner installs them here before the
155
+ * turn. Pure fs — unit-testable without a binary.
156
+ */
157
+ function installCodexSkills(pluginDir, cwd) {
158
+ const skillsRoot = (0, node_path_1.join)(pluginDir, "skills");
159
+ if (!(0, node_fs_1.existsSync)(skillsRoot))
160
+ return 0;
161
+ let n = 0;
162
+ for (const name of (0, node_fs_1.readdirSync)(skillsRoot)) {
163
+ const src = (0, node_path_1.join)(skillsRoot, name, "SKILL.md");
164
+ if (!(0, node_fs_1.existsSync)(src))
165
+ continue;
166
+ const dest = (0, node_path_1.join)(cwd, ".codex", "skills", name, "SKILL.md");
167
+ (0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(dest), { recursive: true });
168
+ (0, node_fs_1.writeFileSync)(dest, (0, node_fs_1.readFileSync)(src, "utf-8"));
169
+ n += 1;
170
+ }
171
+ return n;
172
+ }
173
+ /* v8 ignore start -- real codex subprocess; validated against the binary, not the unit gate */
174
+ /**
175
+ * The Codex eval-tier `AgentRunner`: install the run's skills into `.codex/skills`
176
+ * (Codex's discovery path, vs Claude's `--plugin-dir`), then drive a real
177
+ * `codex exec --json` turn. The seam `measureTriggerRate(spec, { evalDriver:
178
+ * codexEvalDriver })` dispatches through.
179
+ */
180
+ function codexEvalAgentRunner(args) {
181
+ if (args.pluginDir)
182
+ installCodexSkills(args.pluginDir, args.cwd);
183
+ return Promise.resolve(codexEvalRunner({
184
+ task: args.task,
185
+ cwd: args.cwd,
186
+ timeoutMs: args.timeoutMs,
187
+ }));
188
+ }
189
+ /**
190
+ * The Codex eval driver — pass to `measureTriggerRate(spec, { evalDriver:
191
+ * codexEvalDriver })` to run a trigger-rate eval natively on `codex exec`. Pair
192
+ * the spec's `fired` with `codexSkillFired` (Codex has no Skill-tool event).
193
+ */
194
+ exports.codexEvalDriver = {
195
+ runner: codexEvalAgentRunner,
196
+ parse: parseCodexEvalRun,
197
+ runError: codexRunError,
198
+ };
199
+ /**
200
+ * Spawn real `codex exec --json` for the eval tier (real model, the user's codex
201
+ * auth — NOT the mock). CONFIRMED flags (codex 0.139.0): `--json` for the event
202
+ * stream, `--skip-git-repo-check` for a bare cwd, the approvals/sandbox bypass so
203
+ * the turn runs unattended, `-C <cwd>` for the working dir, prompt as the trailing
204
+ * positional, and stdin = /dev/null (`stdio: ["ignore",…]`) — codex otherwise
205
+ * blocks on "Reading additional input from stdin…". Needs ChatGPT/API auth +
206
+ * network egress to the model backend.
207
+ */
208
+ function codexEvalRunner(args) {
209
+ const r = (0, node_child_process_1.spawnSync)("codex", [
210
+ "exec",
211
+ "--json",
212
+ "--skip-git-repo-check",
213
+ "--dangerously-bypass-approvals-and-sandbox",
214
+ "-C",
215
+ args.cwd,
216
+ args.task,
217
+ ], {
218
+ cwd: args.cwd,
219
+ encoding: "utf-8",
220
+ timeout: args.timeoutMs,
221
+ stdio: ["ignore", "pipe", "pipe"],
222
+ maxBuffer: 64 * 1024 * 1024,
223
+ });
224
+ return { code: r.status ?? 1, stdout: r.stdout ?? "" };
225
+ }
226
+ /* v8 ignore stop */
227
+ //# sourceMappingURL=eval.js.map