@moda-ai/cli 1.55.16 → 1.55.18

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 (31) hide show
  1. package/dist/{agent-a2xwfeeh.js → agent-cha3kg9d.js} +9 -9
  2. package/dist/{cli-86q35fpq.js → cli-0e8bfvn7.js} +8 -8
  3. package/dist/{cli-3gwbg0xp.js → cli-1exddmc0.js} +2 -2
  4. package/dist/{cli-b3cxcxgn.js → cli-3ezzeqcy.js} +669 -37
  5. package/dist/{cli-kf3d6y8c.js → cli-5hq827jt.js} +8 -2
  6. package/dist/{cli-xy6zn80e.js → cli-5q1gyvxn.js} +5 -5
  7. package/dist/{cli-7fc44hhq.js → cli-a1mv0ypm.js} +5 -5
  8. package/dist/{cli-zdeywyn9.js → cli-av3dqgj5.js} +4 -4
  9. package/dist/cli-bb7133m7.js +144 -0
  10. package/dist/{cli-2ars875d.js → cli-c8p69n55.js} +2 -2
  11. package/dist/{cli-atx672xv.js → cli-eazeanvt.js} +1 -1
  12. package/dist/{cli-53mvsfgn.js → cli-kg0kz05e.js} +3 -3
  13. package/dist/{cli-6ca1sz0a.js → cli-qmjnh4z9.js} +1 -1
  14. package/dist/cli.js +120 -49
  15. package/dist/{doctor-e2xrbpmp.js → doctor-kg0yq1wf.js} +9 -9
  16. package/dist/{fix-v8xka487.js → fix-q8er8egx.js} +7 -7
  17. package/dist/{harness-github-actions-301nak95.js → harness-github-actions-ver6cprq.js} +6 -6
  18. package/dist/{harness-28wbzncq.js → harness-v9s0k9s7.js} +6 -6
  19. package/dist/{index-ccdpy9ma.js → index-7zqa7t5c.js} +11 -11
  20. package/dist/{production-intelligence-0wqcvvxk.js → production-intelligence-k36jsvqx.js} +13 -13
  21. package/dist/{profile-commands-f5kysjrv.js → profile-commands-88sdwzbg.js} +3 -3
  22. package/dist/prompt-source-mcp.js +6 -6
  23. package/dist/{prompts-jg0stjfb.js → prompts-2r756vtd.js} +7 -7
  24. package/dist/{provision-25bw5rd7.js → provision-n3r7yway.js} +4 -4
  25. package/dist/{registry-39xzetsc.js → registry-5v63ga01.js} +4 -4
  26. package/dist/{skills-gjesa81c.js → skills-fed17et3.js} +6 -6
  27. package/dist/{sync-7ts9psky.js → sync-r4tncne4.js} +8 -8
  28. package/package.json +1 -1
  29. package/skills/integration/index.json +2 -2
  30. package/skills/moda-cli/SKILL.md +20 -8
  31. package/dist/cli-438g4nwh.js +0 -465
@@ -5,13 +5,13 @@ import {
5
5
  inspectCodeSelectors,
6
6
  inspectPythonSelectors,
7
7
  safePromptEvidencePath
8
- } from "./cli-7fc44hhq.js";
8
+ } from "./cli-a1mv0ypm.js";
9
9
  import"./cli-97fnztpy.js";
10
- import"./cli-kf3d6y8c.js";
11
- import"./cli-53mvsfgn.js";
12
- import"./cli-2ars875d.js";
13
- import"./cli-atx672xv.js";
14
- import"./cli-b3cxcxgn.js";
10
+ import"./cli-5hq827jt.js";
11
+ import"./cli-kg0kz05e.js";
12
+ import"./cli-c8p69n55.js";
13
+ import"./cli-eazeanvt.js";
14
+ import"./cli-3ezzeqcy.js";
15
15
  import {
16
16
  __commonJS,
17
17
  __toESM
@@ -11,17 +11,17 @@ import {
11
11
  runPromptSync,
12
12
  runPromptsCommand,
13
13
  writePromptSyncProgress
14
- } from "./cli-86q35fpq.js";
14
+ } from "./cli-0e8bfvn7.js";
15
15
  import {
16
16
  promptSourceHashPayload
17
17
  } from "./cli-mm48br00.js";
18
- import"./cli-7fc44hhq.js";
18
+ import"./cli-a1mv0ypm.js";
19
19
  import"./cli-97fnztpy.js";
20
- import"./cli-kf3d6y8c.js";
21
- import"./cli-53mvsfgn.js";
22
- import"./cli-2ars875d.js";
23
- import"./cli-atx672xv.js";
24
- import"./cli-b3cxcxgn.js";
20
+ import"./cli-5hq827jt.js";
21
+ import"./cli-kg0kz05e.js";
22
+ import"./cli-c8p69n55.js";
23
+ import"./cli-eazeanvt.js";
24
+ import"./cli-3ezzeqcy.js";
25
25
  import"./cli-0v6na3yp.js";
26
26
  export {
27
27
  writePromptSyncProgress,
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  selectTenantAndCreateKey
3
- } from "./cli-3gwbg0xp.js";
3
+ } from "./cli-1exddmc0.js";
4
4
  import {
5
5
  loadAuthSession
6
- } from "./cli-6ca1sz0a.js";
6
+ } from "./cli-qmjnh4z9.js";
7
7
  import {
8
8
  stringOption
9
- } from "./cli-kf3d6y8c.js";
9
+ } from "./cli-5hq827jt.js";
10
10
  import {
11
11
  CliAuthError,
12
12
  resolveIngestUrl,
13
13
  resolveModaBaseUrl
14
- } from "./cli-b3cxcxgn.js";
14
+ } from "./cli-3ezzeqcy.js";
15
15
  import"./cli-0v6na3yp.js";
16
16
 
17
17
  // src/provision.ts
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  assertFlags
3
- } from "./cli-53mvsfgn.js";
3
+ } from "./cli-kg0kz05e.js";
4
4
  import {
5
5
  callControlAPI
6
- } from "./cli-2ars875d.js";
7
- import"./cli-atx672xv.js";
6
+ } from "./cli-c8p69n55.js";
7
+ import"./cli-eazeanvt.js";
8
8
  import {
9
9
  CliInputError,
10
10
  explicitOutputMode,
11
11
  resolveApiKey
12
- } from "./cli-b3cxcxgn.js";
12
+ } from "./cli-3ezzeqcy.js";
13
13
  import"./cli-0v6na3yp.js";
14
14
 
15
15
  // src/registry.ts
@@ -3,12 +3,12 @@ import {
3
3
  pullSkills,
4
4
  runSkillSync,
5
5
  runSkillsCommand
6
- } from "./cli-zdeywyn9.js";
7
- import"./cli-kf3d6y8c.js";
8
- import"./cli-53mvsfgn.js";
9
- import"./cli-2ars875d.js";
10
- import"./cli-atx672xv.js";
11
- import"./cli-b3cxcxgn.js";
6
+ } from "./cli-av3dqgj5.js";
7
+ import"./cli-5hq827jt.js";
8
+ import"./cli-kg0kz05e.js";
9
+ import"./cli-c8p69n55.js";
10
+ import"./cli-eazeanvt.js";
11
+ import"./cli-3ezzeqcy.js";
12
12
  import"./cli-ssfq84k5.js";
13
13
  import"./cli-0v6na3yp.js";
14
14
  export {
@@ -1,21 +1,21 @@
1
1
  import {
2
2
  runPromptsCommand
3
- } from "./cli-86q35fpq.js";
3
+ } from "./cli-0e8bfvn7.js";
4
4
  import"./cli-mm48br00.js";
5
5
  import {
6
6
  runHarnessCommand
7
- } from "./cli-7fc44hhq.js";
7
+ } from "./cli-a1mv0ypm.js";
8
8
  import"./cli-97fnztpy.js";
9
9
  import {
10
10
  runSkillsCommand
11
- } from "./cli-zdeywyn9.js";
12
- import"./cli-kf3d6y8c.js";
13
- import"./cli-53mvsfgn.js";
14
- import"./cli-2ars875d.js";
15
- import"./cli-atx672xv.js";
11
+ } from "./cli-av3dqgj5.js";
12
+ import"./cli-5hq827jt.js";
13
+ import"./cli-kg0kz05e.js";
14
+ import"./cli-c8p69n55.js";
15
+ import"./cli-eazeanvt.js";
16
16
  import {
17
17
  CliInputError
18
- } from "./cli-b3cxcxgn.js";
18
+ } from "./cli-3ezzeqcy.js";
19
19
  import"./cli-ssfq84k5.js";
20
20
  import"./cli-0v6na3yp.js";
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moda-ai/cli",
3
- "version": "1.55.16",
3
+ "version": "1.55.18",
4
4
  "description": "CLI for Moda: production monitoring and evals for AI agents.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema_version": "moda.skill_index.v1",
3
- "bundled_at": "2026-10-15T06:39:15.616Z",
4
- "cli_version": "1.55.16",
3
+ "bundled_at": "2026-10-15T09:11:17.292Z",
4
+ "cli_version": "1.55.18",
5
5
  "skills": [
6
6
  {
7
7
  "id": "integration-cloudflare-think",
@@ -408,11 +408,16 @@ Treat an answer as degraded if **any** of these hold:
408
408
 
409
409
  ### Large outputs and unknown flags
410
410
 
411
- - **Byte limit.** In `--agent` mode, envelopes over 200 KB
412
- (`MODA_AGENT_MAX_OUTPUT_BYTES`) are bounded *without* cutting any text or
413
- breaking their shape: the complete output (the same JSON `--json` prints) is
414
- written to a local file, and whole trailing list items are dropped from
415
- `data`. `truncation.data.full_output_path` (also an `artifacts[]` entry of
411
+ - **Byte limit.** In `--agent` mode, envelopes over 24,000 bytes
412
+ (`MODA_AGENT_MAX_OUTPUT_BYTES`; kept under the 30,000-character tool output
413
+ limit) are bounded *without* cutting any text or breaking their shape: the
414
+ complete output (the same JSON `--json` prints) is written to a local file,
415
+ duplicate `content_blocks` are removed first, and then whole trailing list
416
+ items are dropped from `data`. When rows are dropped, the list's
417
+ `pagination` says what you got (`returned`, `limit`, `next_offset`; a
418
+ `next_cursor` that would skip rows becomes `null`) and `next_commands` has
419
+ the exact command for the rest (e.g. `moda frustrations --offset=3
420
+ --limit=7`). `truncation.data.full_output_path` (also an `artifacts[]` entry of
416
421
  kind `full_output`) is that file; read it in line ranges or with `jq`.
417
422
  These files are pruned after 24 hours (`MODA_AGENT_OUTPUT_RETENTION_HOURS`).
418
423
  `truncation.data` also says what was dropped (`dropped_items`,
@@ -737,11 +742,15 @@ Moda captured every LLM/tool call for a trace.
737
742
  ```bash
738
743
  moda frustrations # last 7 days
739
744
  moda frustrations --days-back=14 --limit=20
740
- moda frustrations --include-window --window=1 --limit=5
745
+ moda frustrations --include-window --window=1 --limit=5 # agent output omits windows unless asked
741
746
  moda emotions --family=frustration --user-id=<id> # one end user
742
747
  moda emotions --conversation-id=<id> # every family, one trace
743
748
  ```
744
749
 
750
+ In agent output, `frustrations` and `emotions` rows leave out the embedded
751
+ conversation window (most of each row) unless you pass `--include-window`;
752
+ each row keeps `anchor` and a `context_command` to read the turns around it.
753
+
745
754
  `--user-id` and `--conversation-id` work on `emotions` and `frustrations`, and
746
755
  scope *every* figure: summary, breakdown, list and total. `--limit` is 1–20 on
747
756
  both, and on `hallucinations` and `tool-failure-detail`. Page with `--offset`.
@@ -1086,7 +1095,8 @@ Problem, or before hand-editing prompt/skill files in a repo that talks to Moda.
1086
1095
  moda investigate # rank tool failures, frustrations,
1087
1096
  # and top Problems with evidence
1088
1097
  moda problems # cross-signal Problems by root cause
1089
- moda problem <problem_id> # the dossier: what, where, how often
1098
+ moda problem <problem_id> # compact dossier: what, where, how often
1099
+ moda problem <problem_id> --full # every dossier block (large)
1090
1100
  moda problem <problem_id> --evidence # attribution rationales and anchors
1091
1101
  moda problem <problem_id> --traces # affected traces with anchors
1092
1102
  moda tool-failure-detail <tool_name> # failing calls with surrounding turns
@@ -1443,4 +1453,6 @@ commands (`moda <command> --help` shows them). Boolean flags take `true`/`false`
1443
1453
  and also `1`/`0`, `yes`/`no`, `on`/`off`.
1444
1454
  `frustrations` and `tool-failure-detail` additionally accept
1445
1455
  `--include-window` (attach a `window` slice per row) and `--window=N` (1–5,
1446
- default `1`; half-width, so `--window=1` ⇒ 3 messages).
1456
+ default `1`; half-width, so `--window=1` ⇒ 3 messages). `emotions` accepts
1457
+ `--include-window` to keep each detection's `conversation_context` in agent
1458
+ output. `problem <id>` accepts `--full` for the whole dossier in agent output.
@@ -1,465 +0,0 @@
1
- import {
2
- CliInputError
3
- } from "./cli-b3cxcxgn.js";
4
-
5
- // src/batch-reads.ts
6
- import { readFile } from "node:fs/promises";
7
- var BATCH_MAX_TARGETS = 25;
8
- var BATCH_CONCURRENCY = 4;
9
- var ANCHOR_SUFFIX = /^(.+)@(\d+)$/;
10
- function parseBatchTarget(text, anchors, usage) {
11
- const raw = text.trim();
12
- if (raw.startsWith("{")) {
13
- let parsed;
14
- try {
15
- parsed = JSON.parse(raw);
16
- } catch {
17
- throw new CliInputError(`Could not parse the JSON target ${JSON.stringify(raw)}.`, usage, "bad_batch_target");
18
- }
19
- const record = parsed;
20
- const id = record?.id ?? record?.conversation_id ?? record?.trace_id;
21
- if (typeof id !== "string" || id.trim() === "") {
22
- throw new CliInputError(`JSON target ${JSON.stringify(raw)} has no "id" string.`, usage, "bad_batch_target");
23
- }
24
- const index = record.msg_index ?? record.message_index;
25
- if (index !== undefined && index !== null) {
26
- if (!anchors) {
27
- throw new CliInputError(`JSON target ${JSON.stringify(raw)} has a msg_index, which this command does not take.`, usage, "bad_batch_target");
28
- }
29
- if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) {
30
- throw new CliInputError(`JSON target ${JSON.stringify(raw)} has an invalid msg_index (want an integer >= 0).`, usage, "bad_batch_target");
31
- }
32
- return { raw, id, msgIndex: index };
33
- }
34
- return { raw, id };
35
- }
36
- if (anchors) {
37
- const match = ANCHOR_SUFFIX.exec(raw);
38
- if (match) {
39
- const msgIndex = Number(match[2]);
40
- if (!Number.isSafeInteger(msgIndex)) {
41
- throw new CliInputError(`Target ${JSON.stringify(raw)} has an @msg_index past ${Number.MAX_SAFE_INTEGER}. ` + 'If the id itself ends in @<digits>, pass it as {"id": "..."}.', usage, "bad_batch_target");
42
- }
43
- return { raw, id: match[1], msgIndex };
44
- }
45
- }
46
- return { raw, id: raw };
47
- }
48
- function parseTargetLines(text, anchors, usage) {
49
- return text.split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== "").map((line) => parseBatchTarget(line, anchors, usage));
50
- }
51
- async function readStdinText() {
52
- if (process.stdin.isTTY) {
53
- throw new CliInputError("--ids-from=- reads targets from stdin, but stdin is a terminal. Pipe ids in (one per line) or pass a file path.", undefined, "ids_from_tty");
54
- }
55
- const chunks = [];
56
- for await (const chunk of process.stdin)
57
- chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
58
- return Buffer.concat(chunks).toString("utf8");
59
- }
60
- async function readIdsFrom(source, usage) {
61
- if (source === "" || source === "true") {
62
- throw new CliInputError("--ids-from needs a value: - (stdin) or a file path.", usage, "missing_flag_value");
63
- }
64
- if (source === "-")
65
- return readStdinText();
66
- try {
67
- return await readFile(source, "utf8");
68
- } catch (error) {
69
- const code = error.code;
70
- throw new CliInputError(`Could not read --ids-from file ${JSON.stringify(source)}${typeof code === "string" ? ` (${code})` : ""}.`, usage, "ids_from_unreadable");
71
- }
72
- }
73
- async function collectBatchTargets(positionals, idsFrom, options) {
74
- const targets = positionals.map((value) => parseBatchTarget(value, options.anchors, options.usage));
75
- if (idsFrom !== undefined) {
76
- targets.push(...parseTargetLines(await readIdsFrom(idsFrom, options.usage), options.anchors, options.usage));
77
- }
78
- const seen = new Set;
79
- const unique = targets.filter((target) => {
80
- const key = `${target.id}\x00${target.msgIndex ?? ""}`;
81
- if (seen.has(key))
82
- return false;
83
- seen.add(key);
84
- return true;
85
- });
86
- if (unique.length === 0) {
87
- throw new CliInputError(`No targets: --ids-from gave no ids (one per line).`, options.usage, "missing_positional");
88
- }
89
- if (unique.length > BATCH_MAX_TARGETS) {
90
- throw new CliInputError(`Got ${unique.length} targets; 'moda ${options.command}' reads at most ${BATCH_MAX_TARGETS} per call, so nothing was read. ` + `Split the ids into calls of ${BATCH_MAX_TARGETS} or fewer.`, options.usage, "batch_too_large");
91
- }
92
- return unique;
93
- }
94
- async function mapWithConcurrency(items, limit, fn) {
95
- const results = new Array(items.length);
96
- let next = 0;
97
- let failure;
98
- const worker = async () => {
99
- while (!failure && next < items.length) {
100
- const index = next++;
101
- try {
102
- results[index] = await fn(items[index], index);
103
- } catch (error) {
104
- failure ??= { error };
105
- }
106
- }
107
- };
108
- await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, worker));
109
- if (failure)
110
- throw failure.error;
111
- return results;
112
- }
113
- function idNeedsJsonTarget(id) {
114
- return ANCHOR_SUFFIX.test(id);
115
- }
116
- function contextTarget(id) {
117
- const verbatim = id === id.trim() && !id.startsWith("{") && !idNeedsJsonTarget(id);
118
- return verbatim ? id : JSON.stringify({ id });
119
- }
120
-
121
- // src/transforms.ts
122
- function asRecord(value) {
123
- if (value && typeof value === "object" && !Array.isArray(value)) {
124
- return value;
125
- }
126
- return null;
127
- }
128
- function asString(value) {
129
- return typeof value === "string" ? value : null;
130
- }
131
- function asNumber(value) {
132
- return typeof value === "number" && Number.isFinite(value) ? value : null;
133
- }
134
- function frustrationAnchorIndex(row) {
135
- if (!row)
136
- return null;
137
- const userQuotes = Array.isArray(row.user_quotes) ? row.user_quotes : [];
138
- const firstQuote = asRecord(userQuotes[0]);
139
- const resolved = asNumber(firstQuote?.msg_index) ?? asNumber(row.anchor_msg_index);
140
- if (resolved !== null)
141
- return resolved;
142
- const keyTurns = Array.isArray(row.key_turns) ? row.key_turns : [];
143
- const firstTurn = keyTurns.find((t) => typeof t === "number");
144
- if (firstTurn !== undefined)
145
- return firstTurn;
146
- return asNumber(firstQuote?.turn);
147
- }
148
- function buildFrustrationAnchor(row) {
149
- const conversation_id = asString(row.conversation_id) ?? "";
150
- const userQuotes = Array.isArray(row.user_quotes) ? row.user_quotes : [];
151
- const firstQuote = asRecord(userQuotes[0]);
152
- const keyTurnsRaw = Array.isArray(row.key_turns) ? row.key_turns : [];
153
- const all_turns = keyTurnsRaw.filter((t) => typeof t === "number");
154
- const msg_index = frustrationAnchorIndex(row);
155
- let signal = null;
156
- let quote_preview = null;
157
- if (firstQuote) {
158
- signal = asString(firstQuote.signal);
159
- const quote = asString(firstQuote.quote);
160
- if (quote !== null) {
161
- let end = 0;
162
- let points = 0;
163
- for (const ch of quote) {
164
- if (points++ === 200)
165
- break;
166
- end += ch.length;
167
- }
168
- quote_preview = quote.slice(0, end);
169
- }
170
- }
171
- return {
172
- kind: "frustration",
173
- conversation_id,
174
- msg_index,
175
- signal,
176
- quote_preview,
177
- all_turns,
178
- no_anchor: msg_index === null
179
- };
180
- }
181
- function buildToolFailureAnchor(row, toolName) {
182
- const conversation_id = asString(row.conversation_id) ?? "";
183
- const msg_index = asNumber(row.msg_index);
184
- const tool_use_id = asString(row.tool_use_id);
185
- const error_subtype = asString(row.error_subtype);
186
- return {
187
- kind: "tool_failure",
188
- conversation_id,
189
- msg_index,
190
- tool_name: toolName,
191
- tool_use_id,
192
- error_subtype,
193
- no_anchor: msg_index === null
194
- };
195
- }
196
- function frustrationsFromEmotions(response) {
197
- if (!Array.isArray(response.detections) || Array.isArray(response.frustrations))
198
- return response;
199
- const summary = asRecord(response.summary) ?? {};
200
- const pagination = asRecord(response.pagination) ?? {};
201
- const byFamily = asRecord(summary.by_family) ?? {};
202
- const totalAnalyzed = asNumber(summary.conversations_analyzed) ?? 0;
203
- const byFamilyConversations = asRecord(summary.conversations_by_family);
204
- const frustrated = asNumber(byFamilyConversations?.frustration) ?? asNumber(byFamily.frustration) ?? 0;
205
- const frustrations = response.detections.map((item) => asRecord(item)).filter((row) => row !== null && (row.family === undefined || row.family === "frustration")).map(({ conversation_context, score, is_detected, ...row }) => ({
206
- ...row,
207
- is_frustrated: is_detected === true,
208
- frustration_score: score,
209
- target: row.elicitor === "bot" || row.elicitor === "external" ? row.elicitor : "ambiguous",
210
- conversation: conversation_context ?? null
211
- }));
212
- const atRisk = asNumber(pagination.at_risk) ?? Math.max(0, (asNumber(pagination.total) ?? 0) - frustrated);
213
- const signalBreakdown = {};
214
- for (const item of Array.isArray(response.signal_breakdown) ? response.signal_breakdown : []) {
215
- const row = asRecord(item);
216
- if (row?.family === "frustration" && typeof row.signal === "string") {
217
- signalBreakdown[row.signal] = asNumber(row.count) ?? 0;
218
- }
219
- }
220
- const { detections: _detections, ...rest } = response;
221
- return {
222
- ...rest,
223
- summary: {
224
- total_analyzed: totalAnalyzed,
225
- frustrated_count: frustrated,
226
- at_risk_count: atRisk,
227
- frustration_rate_pct: totalAnalyzed > 0 ? Math.round(frustrated / totalAnalyzed * 1000) / 10 : 0
228
- },
229
- signal_breakdown: signalBreakdown,
230
- frustrations,
231
- source: "emotion_detections"
232
- };
233
- }
234
- function withFrustrationAnchors(response) {
235
- if (!Array.isArray(response.frustrations))
236
- return response;
237
- const frustrations = response.frustrations.map((item) => {
238
- const row = asRecord(item);
239
- if (!row)
240
- return item;
241
- const anchor = buildFrustrationAnchor(row);
242
- return { ...row, anchor };
243
- });
244
- return { ...response, frustrations };
245
- }
246
- var TOOL_FAILURE_CONTEXT_RADIUS = 2;
247
- function shellWord(value) {
248
- return /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
249
- }
250
- function trimFailureWindow(value, radius, fallbackCenter) {
251
- const conv = asRecord(value);
252
- if (!conv)
253
- return value ?? null;
254
- const { coverage: _coverage, context, ...convRest } = conv;
255
- const ctx = asRecord(context);
256
- if (!ctx)
257
- return convRest;
258
- const center = asNumber(ctx.center_index) ?? fallbackCenter;
259
- const messages = (Array.isArray(ctx.messages) ? ctx.messages : []).map((message) => asRecord(message)).filter((message) => {
260
- const index = asNumber(message?.index);
261
- return message !== null && (center === null || index === null || Math.abs(index - center) <= radius);
262
- }).map(({ content_blocks, ...message }) => {
263
- const covered = typeof message.content === "string" && message.content.length > 0 || Array.isArray(message.tool_calls) && message.tool_calls.length > 0 || Array.isArray(message.tool_results) && message.tool_results.length > 0;
264
- return covered || content_blocks === undefined ? message : { ...message, content_blocks };
265
- });
266
- const indexes = messages.map((message) => asNumber(message.index)).filter((index) => index !== null);
267
- return {
268
- ...convRest,
269
- context: {
270
- ...ctx,
271
- ...indexes.length > 0 ? { from_index: Math.min(...indexes), to_index: Math.max(...indexes) } : {},
272
- messages
273
- }
274
- };
275
- }
276
- function trimToolFailureConversations(response, opts) {
277
- if (!Array.isArray(response.examples))
278
- return response;
279
- const examples = response.examples.map((item) => {
280
- const row = asRecord(item);
281
- if (!row)
282
- return item;
283
- const { conversation, window, ...rest } = row;
284
- const conversationId = asString(row.conversation_id);
285
- const msgIndex = asNumber(asRecord(row.anchor)?.msg_index) ?? asNumber(row.msg_index);
286
- return {
287
- ...rest,
288
- ...conversationId && msgIndex !== null ? { context_command: `moda context ${shellWord(contextTarget(conversationId))} --msg-index=${msgIndex} --window=${TOOL_FAILURE_CONTEXT_RADIUS}` } : {},
289
- ...opts.drop ? {} : { conversation: trimFailureWindow(conversation, TOOL_FAILURE_CONTEXT_RADIUS, msgIndex) },
290
- ..."window" in row ? { window: trimFailureWindow(window, opts.windowRadius ?? TOOL_FAILURE_CONTEXT_RADIUS, msgIndex) } : {}
291
- };
292
- });
293
- return { ...response, examples };
294
- }
295
- function withToolFailureAnchors(response) {
296
- if (!Array.isArray(response.examples))
297
- return response;
298
- const toolName = asString(response.tool_name) ?? "";
299
- const examples = response.examples.map((item) => {
300
- const row = asRecord(item);
301
- if (!row)
302
- return item;
303
- const anchor = buildToolFailureAnchor(row, toolName);
304
- return { ...row, anchor };
305
- });
306
- return { ...response, examples };
307
- }
308
- function embeddedWindowSize(conversation) {
309
- if (!conversation)
310
- return null;
311
- const ctx = asRecord(conversation.context);
312
- if (!ctx)
313
- return null;
314
- const center = asNumber(ctx.center_index);
315
- const from = asNumber(ctx.from_index);
316
- const to = asNumber(ctx.to_index);
317
- if (center === null || from === null || to === null)
318
- return null;
319
- return Math.min(center - from, to - center);
320
- }
321
-
322
- // src/intelligence-schema.ts
323
- var INTELLIGENCE_SCHEMA_VERSION = "moda.intelligence.v1";
324
- var provenanceSchema = { type: "string", enum: ["measured", "inferred"] };
325
- var mutabilitySchema = {
326
- type: "string",
327
- enum: ["read", "write", "sync", "unknown"]
328
- };
329
- var confidenceSchema = {
330
- type: "string",
331
- enum: ["high", "medium", "low", "unknown"]
332
- };
333
- var MODA_INTELLIGENCE_V1_JSON_SCHEMA = {
334
- $schema: "http://json-schema.org/draft-07/schema#",
335
- $id: "moda.intelligence.v1",
336
- title: "Moda Intelligence v1",
337
- type: "object",
338
- additionalProperties: false,
339
- required: [
340
- "schema_version",
341
- "generated_at",
342
- "command",
343
- "source",
344
- "degraded",
345
- "question",
346
- "summary",
347
- "answer_markdown",
348
- "answer_claims",
349
- "findings",
350
- "evidence_refs",
351
- "next_commands",
352
- "warnings"
353
- ],
354
- properties: {
355
- schema_version: { const: "moda.intelligence.v1" },
356
- generated_at: { type: "string", format: "date-time" },
357
- command: { type: "string" },
358
- source: { type: "string", enum: ["cloud", "local_fallback"] },
359
- degraded: { type: "boolean" },
360
- question: { type: "string" },
361
- summary: {
362
- type: "object",
363
- additionalProperties: false,
364
- required: ["text", "confidence"],
365
- properties: { text: { type: "string" }, confidence: confidenceSchema }
366
- },
367
- answer_markdown: { type: "string" },
368
- answer_claims: {
369
- type: "array",
370
- items: {
371
- type: "object",
372
- additionalProperties: false,
373
- required: ["text", "kind", "status", "evidence_ref_ids"],
374
- properties: {
375
- text: { type: "string" },
376
- value: { type: "number" },
377
- kind: { type: "string", enum: ["percentage", "count", "qualitative"] },
378
- status: {
379
- type: "string",
380
- enum: ["grounded", "ungrounded", "unverifiable"]
381
- },
382
- evidence_ref_ids: { type: "array", items: { type: "string" } },
383
- matched_path: { type: "string" }
384
- }
385
- }
386
- },
387
- findings: {
388
- type: "array",
389
- items: {
390
- type: "object",
391
- additionalProperties: false,
392
- required: ["id", "title", "evidence_ref_ids", "recommended_actions"],
393
- properties: {
394
- id: { type: "string" },
395
- title: { type: "string" },
396
- severity: {
397
- type: "string",
398
- enum: ["critical", "high", "medium", "low", "info"]
399
- },
400
- description: { type: "string" },
401
- evidence_ref_ids: { type: "array", items: { type: "string" } },
402
- recommended_actions: {
403
- type: "array",
404
- items: {
405
- type: "object",
406
- additionalProperties: false,
407
- required: ["id", "title", "mutability", "requires_approval"],
408
- properties: {
409
- id: { type: "string" },
410
- title: { type: "string" },
411
- rationale: { type: "string" },
412
- command: { type: "string" },
413
- mutability: mutabilitySchema,
414
- requires_approval: { type: "boolean" }
415
- }
416
- }
417
- }
418
- }
419
- }
420
- },
421
- evidence_refs: {
422
- type: "array",
423
- items: {
424
- type: "object",
425
- additionalProperties: false,
426
- required: ["id", "kind", "label", "grounding"],
427
- properties: {
428
- id: { type: "string" },
429
- kind: { type: "string" },
430
- label: { type: "string" },
431
- anchor: {
432
- type: "object",
433
- additionalProperties: false,
434
- properties: {
435
- conversation_id: { type: "string" },
436
- message_index: { type: "number" },
437
- run_id: { type: "string" },
438
- tool_name: { type: "string" }
439
- }
440
- },
441
- snippet: { type: "string" },
442
- grounding: provenanceSchema
443
- }
444
- }
445
- },
446
- next_commands: {
447
- type: "array",
448
- items: {
449
- type: "object",
450
- additionalProperties: false,
451
- required: ["command", "mutability", "requires_approval"],
452
- properties: {
453
- command: { type: "string" },
454
- purpose: { type: "string" },
455
- mutability: mutabilitySchema,
456
- requires_approval: { type: "boolean" }
457
- }
458
- }
459
- },
460
- warnings: { type: "array", items: { type: "string" } },
461
- meta: { type: "object" }
462
- }
463
- };
464
-
465
- export { BATCH_MAX_TARGETS, BATCH_CONCURRENCY, parseBatchTarget, collectBatchTargets, mapWithConcurrency, contextTarget, asRecord, asString, asNumber, frustrationAnchorIndex, frustrationsFromEmotions, withFrustrationAnchors, shellWord, trimToolFailureConversations, withToolFailureAnchors, embeddedWindowSize, INTELLIGENCE_SCHEMA_VERSION, MODA_INTELLIGENCE_V1_JSON_SCHEMA };