Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to the `indianopinion` npm package. The format follows

- `io.sh`: an invalid `--limit` (on `briefs`, `digest`, `topics list` and `breaking recent`) or a bad `prefs set --digest`/`--nudges` value now stops with exit 2 before any request. The validators ran inside a command substitution, so the usage error was printed and the command carried on and exited 0; `prefs set --digest maybe` even sent a malformed body. The CLI also checks `--limit` before the request on `digest`, `topics list` and `breaking recent` (#28).
- `io.sh` with jq prints an error from the API in the CLI's shape, `{"ok":false,"error":...,"message":...,"status":...}` plus `field`, `allowed`, `attempts_left`, `suggestion`, `options`, `scope` and `retry_after` when the API sends them, instead of the API's own body (WordPress's `{code, message, data}`). A body that is not JSON gives `http_<status>`, as in the CLI. Without jq the body is still passed through unchanged (#29).
- `brief --include coverage` returns the per-outlet framing as `coverage` (`[{outlet, framing, note}]`, the MCP `get_brief` shape) instead of under the REST name `stances`, in the CLI and in `io.sh`. With `--include`, `stances` is no longer in the output; without `--include` the REST payload is unchanged (#27).

## [0.2.2] - 2026-10-22

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Every command rejects a flag or extra word it does not take (exit 2), `--since`
ISO 8601 (exit 6), and `brief --include` takes only `brief`, `analysis`, `coverage` and `sources`
(exit 6).

`brief` without `--include` prints the REST payload as it is, where the per-outlet framing is the
`stances` array (`outlet`, `stance`, `note`). With `--include`, only the named parts are kept, and
`coverage` comes back as `coverage`: `[{outlet, framing, note}]`, the same as the MCP `get_brief` tool.

Output is JSON when stdout is not a terminal, or with `--json`; text on a terminal or with `--text`.
Errors go to stderr (a JSON object in JSON mode).

Expand Down
8 changes: 6 additions & 2 deletions bin/indianopinion.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function printText(cmd, data) {
w(`# ${data.title}`); w(`${data.section || ''} | ${data.published || ''} | ${data.corroboration} outlets`); w(data.url); w('');
if (data.brief) { w(data.brief); w(''); }
if (data.analysis) { w('Analysis: ' + data.analysis); w(''); }
for (const s of data.stances || []) w(`- ${s.outlet}: ${s.stance}${s.note ? ` (${s.note})` : ''}`);
for (const s of data.coverage || coverageOf(data.stances)) w(`- ${s.outlet}: ${s.framing}${s.note ? ` (${s.note})` : ''}`);
return;
case 'digest':
w(`Indian Opinion digest ${data.date}${data.lead ? `: ${data.lead}` : ''}`); w(data.web_url || '');
Expand Down Expand Up @@ -400,6 +400,7 @@ async function cmdBriefs(flags) {
}

const INCLUDE_FIELDS = ['brief', 'analysis', 'coverage', 'sources'];
const coverageOf = (stances) => (stances || []).map((s) => ({ outlet: s.outlet, framing: s.stance, note: s.note || null }));

async function cmdBrief(pos, flags) {
const v = pos[0];
Expand Down Expand Up @@ -433,7 +434,10 @@ async function cmdBrief(pos, flags) {
if (!inc.includes('analysis')) delete b.analysis;
if (!inc.includes('brief')) delete b.brief;
if (!inc.includes('sources')) delete b.sources;
if (!inc.includes('coverage')) delete b.stances;
// The REST payload calls the per-outlet framing "stances" ({outlet, stance, note}); --include
// names it "coverage", so return it under that name and in the MCP get_brief shape (#27).
if (inc.includes('coverage')) b.coverage = coverageOf(b.stances);
delete b.stances;
}
return b;
}
Expand Down
2 changes: 1 addition & 1 deletion io.sh
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ case "$cmd" in
if [ -n "$inc" ]; then
OUT=$(printf '%s' "$OUT" | jq -c --arg inc "$inc" '($inc | split(",")) as $i | if ($i | index("analysis")) then . else del(.analysis) end
| if ($i | index("brief")) then . else del(.brief) end | if ($i | index("sources")) then . else del(.sources) end
| if ($i | index("coverage")) then . else del(.stances) end')
| if ($i | index("coverage")) then .coverage = [(.stances // [])[] | {outlet, framing: .stance, note: (.note // null)}] else . end | del(.stances)')
fi
emit "$OUT" ;;
topics)
Expand Down
75 changes: 75 additions & 0 deletions test/brief-coverage.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// #27: brief --include coverage returns the per-outlet framing as "coverage", the name the
// README, the validation and the MCP get_brief tool use, instead of the REST name "stances".
// Node CLI and io.sh against the REST stub; no network.

import { test, before, after } from 'node:test';
import assert from 'node:assert/strict';
import { spawn, spawnSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { startStub, GOOD_TOKEN } from './stub-rest.mjs';

const HERE = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.join(HERE, '..');
const BIN = path.join(ROOT, 'bin', 'indianopinion.mjs');
const IOSH = path.join(ROOT, 'io.sh');
const HAVE_CURL = spawnSync('bash', ['-c', 'command -v curl']).status === 0;
const HAVE_JQ = spawnSync('bash', ['-c', 'command -v jq']).status === 0;
let stub; let home;

function run(args, { env = {}, bin = 'node' } = {}) {
const [cmd, argv] = bin === 'node' ? [process.execPath, [BIN, ...args]] : ['bash', [IOSH, ...args]];
return new Promise((resolve) => {
const child = spawn(cmd, argv, { env: { PATH: process.env.PATH, HOME: home, XDG_CONFIG_HOME: path.join(home, '.config'), IO_API: stub.api, IO_TOKEN: GOOD_TOKEN, ...env } });
let out = ''; let errs = '';
child.stdout.on('data', (d) => { out += d; });
child.stderr.on('data', (d) => { errs += d; });
child.stdin.end();
child.on('close', (code) => resolve({ code, out, err: errs }));
});
}

before(async () => { stub = await startStub(); home = fs.mkdtempSync(path.join(os.tmpdir(), 'io-coverage-')); });
after(async () => { await stub.close(); });

const bins = () => ['node', ...(HAVE_CURL && HAVE_JQ ? ['bash'] : [])];

const want = (b) => b.stances.map((s) => ({ outlet: s.outlet, framing: s.stance, note: s.note || null }));

test('#27: --include coverage returns coverage (outlet, framing, note) and nothing under stances', async () => {
const full = JSON.parse((await run(['brief', '99812'])).out);
assert.ok(Array.isArray(full.stances) && full.stances.length === 3, 'the stub brief has three stances');
for (const bin of bins()) {
let r = await run(['brief', '99812', '--include', 'coverage'], { bin });
assert.equal(r.code, 0, `${bin}: ${r.err}`);
let b = JSON.parse(r.out);
assert.deepEqual(b.coverage, want(full), `${bin} coverage`);
for (const k of ['stances', 'brief', 'analysis', 'sources']) assert.equal(b[k], undefined, `${bin} --include coverage still has ${k}`);
assert.equal(b.id, 99812);

r = await run(['brief', '99812', '--include', 'brief,coverage,sources'], { bin });
b = JSON.parse(r.out);
assert.ok(b.brief && b.sources && b.coverage, `${bin} brief,coverage,sources`);
assert.equal(b.stances, undefined);
assert.equal(b.analysis, undefined);

r = await run(['brief', '99812', '--include', 'brief'], { bin });
b = JSON.parse(r.out);
assert.equal(b.coverage, undefined, `${bin} --include brief has no coverage`);
assert.equal(b.stances, undefined, `${bin} --include brief has no stances`);

// Without --include, the REST payload is unchanged.
r = await run(['brief', '99812'], { bin });
assert.deepEqual(JSON.parse(r.out), full, `${bin} without --include`);
}
});

test('#27: the text view lists the coverage with or without --include', async () => {
for (const args of [['brief', '99812', '--text'], ['brief', '99812', '--text', '--include', 'coverage']]) {
const r = await run(args);
assert.equal(r.code, 0, r.err);
assert.match(r.out, /- thehindu\.com: neutral-report \(Straight account\)/, args.join(' '));
}
});
2 changes: 1 addition & 1 deletion test/fixes.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test('#7: brief --include rejects unknown fields (exit 6)', async () => {
assert.equal(r.code, 6);
r = await run(['brief', '99812', '--include', 'brief,coverage']);
assert.equal(r.code, 0, r.err);
assert.ok(r.json.brief && r.json.stances && !r.json.sources);
assert.ok(r.json.brief && r.json.coverage && !r.json.stances && !r.json.sources); // coverage by its name (#27)
});

test('following --cursor never skips a brief, even when the API overfills a page', async () => {
Expand Down
Loading