@octen.ai/cli 0.11.0 → 0.13.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 (44) hide show
  1. package/README.md +109 -2
  2. package/dist/api/constants.d.ts +61 -0
  3. package/dist/api/constants.js +22 -0
  4. package/dist/api/designSearch.d.ts +55 -0
  5. package/dist/api/designSearch.js +136 -0
  6. package/dist/api/placeSearch.d.ts +19 -0
  7. package/dist/api/placeSearch.js +54 -0
  8. package/dist/api/premierSearch.d.ts +19 -0
  9. package/dist/api/premierSearch.js +37 -0
  10. package/dist/api/verticalSearch.d.ts +41 -0
  11. package/dist/api/verticalSearch.js +112 -0
  12. package/dist/cli.js +15 -2
  13. package/dist/commands/designSearch.d.ts +2 -0
  14. package/dist/commands/designSearch.js +63 -0
  15. package/dist/commands/placeSearch.d.ts +2 -0
  16. package/dist/commands/placeSearch.js +36 -0
  17. package/dist/commands/premierSearch.d.ts +8 -0
  18. package/dist/commands/premierSearch.js +37 -0
  19. package/dist/commands/search.d.ts +1 -1
  20. package/dist/commands/search.js +5 -7
  21. package/dist/commands/verticalSearch.d.ts +4 -0
  22. package/dist/commands/verticalSearch.js +82 -0
  23. package/dist/output/pretty/businessSearch.d.ts +7 -0
  24. package/dist/output/pretty/businessSearch.js +159 -0
  25. package/dist/output/pretty/designSearch.d.ts +15 -0
  26. package/dist/output/pretty/designSearch.js +202 -0
  27. package/dist/output/pretty/envelope.d.ts +24 -0
  28. package/dist/output/pretty/envelope.js +21 -0
  29. package/dist/output/pretty/newsSearch.d.ts +10 -0
  30. package/dist/output/pretty/newsSearch.js +72 -0
  31. package/dist/output/pretty/placeSearch.d.ts +6 -0
  32. package/dist/output/pretty/placeSearch.js +87 -0
  33. package/dist/output/pretty/pulseSearch.d.ts +11 -0
  34. package/dist/output/pretty/pulseSearch.js +31 -0
  35. package/dist/output/pretty/search.d.ts +9 -3
  36. package/dist/output/pretty/search.js +26 -11
  37. package/dist/util/terminalText.d.ts +14 -0
  38. package/dist/util/terminalText.js +30 -0
  39. package/package.json +1 -1
  40. package/skills/manifest.json +1 -0
  41. package/skills/octen-design-search/SKILL.md +312 -0
  42. package/skills/octen-design-search/agents/openai.yaml +4 -0
  43. package/skills/octen-search/SKILL.md +53 -5
  44. package/skills/octen-web-search/SKILL.md +14 -2
@@ -0,0 +1,202 @@
1
+ import pc from "picocolors";
2
+ import { quotePath } from "../../util/quotePath.js";
3
+ import { printable, printableLine } from "../../util/terminalText.js";
4
+ import { envelopeError, isRecord, unwrap } from "./envelope.js";
5
+ import { formatResultList } from "./search.js";
6
+ /** Where a description or a block of code is cut, as the other renderers cut a snippet. */
7
+ const MAX_TEXT = 300;
8
+ /** Where one line of design values is cut. */
9
+ const MAX_VALUE_LINE = 200;
10
+ /** The most images one call returns, so the most a group lookup can ask for. */
11
+ const MAX_COUNT = 100;
12
+ /**
13
+ * How deep a design value is walked. Real ones are three or four levels deep;
14
+ * the bound is there so one pathological value is cut short instead of
15
+ * exhausting the stack and taking the whole listing down.
16
+ */
17
+ const MAX_DEPTH = 12;
18
+ /**
19
+ * A string field, as one line that is safe to print. Everything this renderer
20
+ * prints from the response goes through here or through `printable`: the text
21
+ * is somebody else's page, and must not be able to drive the terminal.
22
+ */
23
+ const text = (v) => (typeof v === "string" ? printableLine(v).trim() : "");
24
+ const count = (v) => typeof v === "number" && Number.isFinite(v) ? v : undefined;
25
+ /**
26
+ * One line for a design value of any shape.
27
+ *
28
+ * The API says the fields vary by image, and they do: design tokens for a web
29
+ * page, plain lists for a slide, counts for an app screen. So this walks
30
+ * whatever it is given instead of naming fields. Three shapes are read down to
31
+ * the value a person wants — a `$value` token wrapper, a colour carrying a
32
+ * `hex`, a `{value, unit}` dimension — and anything else prints as `key value`
33
+ * pairs, so a shape never seen before still reaches the terminal.
34
+ */
35
+ function inline(v, depth = 0) {
36
+ if (v == null)
37
+ return { text: "", composite: false };
38
+ if (depth >= MAX_DEPTH && typeof v === "object")
39
+ return { text: "…", composite: false };
40
+ if (typeof v !== "object")
41
+ return { text: printableLine(String(v)), composite: false };
42
+ if (Array.isArray(v)) {
43
+ const parts = v.map((x) => inline(x, depth + 1).text).filter(Boolean);
44
+ return { text: parts.join(", "), composite: parts.length > 1 };
45
+ }
46
+ const o = v;
47
+ if ("$value" in o)
48
+ return inline(o.$value, depth + 1);
49
+ if (typeof o.hex === "string") {
50
+ const alpha = count(o.alpha);
51
+ const hex = text(o.hex);
52
+ return { text: alpha != null && alpha !== 1 ? `${hex} (alpha ${alpha})` : hex, composite: false };
53
+ }
54
+ if (typeof o.unit === "string" && typeof o.value === "number")
55
+ return { text: `${o.value}${text(o.unit)}`, composite: false };
56
+ const parts = Object.entries(o)
57
+ .map(([k, x]) => {
58
+ const r = inline(x, depth + 1);
59
+ return r.text ? `${printableLine(k)} ${r.composite ? `(${r.text})` : r.text}` : "";
60
+ })
61
+ .filter(Boolean);
62
+ return { text: parts.join(", "), composite: parts.length > 0 };
63
+ }
64
+ function cut(s, max, shortened) {
65
+ if (s.length <= max)
66
+ return s;
67
+ shortened.any = true;
68
+ // Not through the middle of a character that takes two code units: half of
69
+ // one prints as a replacement mark.
70
+ const end = /[\uD800-\uDBFF]/.test(s[max - 1]) ? max - 1 : max;
71
+ return `${s.slice(0, end)}…`;
72
+ }
73
+ /** An id that prints unchanged: printable ASCII. Anything else is left to --json. */
74
+ const PASTEABLE_ID = /^[\x20-\x7e]+$/;
75
+ function groupNoun(type) {
76
+ return type === "deck" ? "deck" : type === "web_page" ? "page" : "group";
77
+ }
78
+ function formatImage(im, i, ctx, shortened) {
79
+ const lines = [];
80
+ lines.push(`${i + 1}. ${pc.bold(text(im.title) || "(untitled)")}`);
81
+ const width = count(im.width);
82
+ const height = count(im.height);
83
+ const kind = [text(im.type), width != null && height != null ? `${width}x${height}` : ""].filter(Boolean).join(" · ");
84
+ if (kind)
85
+ lines.push(` ${pc.dim(kind)}`);
86
+ if (text(im.url))
87
+ lines.push(` ${pc.dim(text(im.url))}`);
88
+ if (text(im.source_page))
89
+ lines.push(` ${pc.dim(`Source: ${text(im.source_page)}`)}`);
90
+ const group = isRecord(im.group) ? im.group : undefined;
91
+ if (group) {
92
+ const name = [text(group.name), text(group.type) ? `(${text(group.type)})` : ""].filter(Boolean).join(" ");
93
+ const position = count(group.position);
94
+ const total = count(group.total);
95
+ const place = position != null && total != null ? `${position} of ${total}` : "";
96
+ const where = [name, place].filter(Boolean).join(" — ");
97
+ if (where)
98
+ lines.push(` ${where}`);
99
+ // The id is only useful as the argument that fetches the rest, so it is
100
+ // printed as that command. Skipped during a lookup: it is the command that
101
+ // was just run.
102
+ // Taken as sent, not through `text()`: the command is meant to be pasted,
103
+ // so the id in it has to be the id the API returned. One that cannot be
104
+ // shown unchanged — a control character, a tab, a line break — gets no
105
+ // command, rather than one that looks up a different id.
106
+ const id = typeof group.group_id === "string" ? group.group_id : "";
107
+ if (id && !ctx.group) {
108
+ const noun = groupNoun(group.type);
109
+ if (!PASTEABLE_ID.test(id)) {
110
+ lines.push(` ${pc.dim(`The ${noun}'s group_id is in the --json output.`)}`);
111
+ }
112
+ else {
113
+ const base = ctx.baseUrl ? ` --base-url ${quotePath(ctx.baseUrl)}` : "";
114
+ const command = `octen design-search --group ${quotePath(id)}`;
115
+ // One call returns at most MAX_COUNT, so for a larger group the
116
+ // command fetches a part and is labelled as one; and with no total the
117
+ // count is unknown, so it is neither given nor claimed.
118
+ const hint = total == null || total < 1
119
+ ? `More of the ${noun}: ${command} -n <count>${base} (returns 5 without -n)`
120
+ : total > MAX_COUNT
121
+ ? `First ${MAX_COUNT} of the ${noun}: ${command} -n ${MAX_COUNT}${base}`
122
+ : `Whole ${noun}: ${command} -n ${total}${base}`;
123
+ lines.push(` ${pc.dim(hint)}`);
124
+ }
125
+ }
126
+ const theme = isRecord(group.master) ? inline(group.master).text : "";
127
+ if (theme)
128
+ lines.push(` ${pc.dim(`Deck theme: ${cut(theme, MAX_VALUE_LINE, shortened)}`)}`);
129
+ }
130
+ if (text(im.description))
131
+ lines.push(` ${cut(text(im.description), MAX_TEXT, shortened)}`);
132
+ if (isRecord(im.design_facts)) {
133
+ const values = Object.entries(im.design_facts)
134
+ .map(([k, v]) => [k, inline(v).text])
135
+ .filter(([, v]) => v);
136
+ if (values.length) {
137
+ lines.push(` ${pc.bold("Design values")}`);
138
+ for (const [k, v] of values)
139
+ lines.push(` ${printableLine(k)}: ${cut(v, MAX_VALUE_LINE, shortened)}`);
140
+ }
141
+ }
142
+ const code = isRecord(im.snippet) && typeof im.snippet.code === "string" ? im.snippet.code : "";
143
+ if (code) {
144
+ const format = text(im.snippet.format);
145
+ lines.push(` ${pc.bold(`Code (${format ? `${format}, ` : ""}${code.length} chars)`)}`);
146
+ // Each line indented, so a line of the code cannot read as a field.
147
+ lines.push(...printable(cut(code, MAX_TEXT, shortened)).split("\n").map((l) => ` ${pc.dim(l)}`));
148
+ }
149
+ return lines.join("\n");
150
+ }
151
+ /**
152
+ * The API returns five images of a group unless told otherwise, and a lookup
153
+ * that shows part of a page reads as the whole of it. Says so when it applies.
154
+ */
155
+ function groupRemainder(images) {
156
+ const total = images.map((im) => count(im.group?.total)).find((t) => t != null);
157
+ if (total == null || images.length >= total)
158
+ return undefined;
159
+ const shown = `Showing ${images.length} of ${total} in this group`;
160
+ if (images.length >= MAX_COUNT)
161
+ return `${shown} — one call returns at most ${MAX_COUNT}.`;
162
+ return total > MAX_COUNT
163
+ ? `${shown} — add -n ${MAX_COUNT} for the first ${MAX_COUNT}, the most one call returns.`
164
+ : `${shown} — add -n ${total} for all of them.`;
165
+ }
166
+ /**
167
+ * Design references live under `data.images`; `data.results` holds the web
168
+ * results that come back alongside.
169
+ */
170
+ export function renderDesignSearch(data, ctx = {}) {
171
+ const body = unwrap(data);
172
+ // Entries that are not objects are skipped, so one of them cannot take the
173
+ // entries beside it down with it.
174
+ const images = Array.isArray(body?.images) ? body.images.filter(isRecord) : [];
175
+ const web = Array.isArray(body?.results) ? body.results.filter(isRecord) : [];
176
+ // An unknown group id is answered with an empty success, so "No results"
177
+ // would hide the likeliest cause: the id.
178
+ const noGroup = ctx.group && !images.length ? pc.dim(`No images in group ${printableLine(ctx.group)}.`) : undefined;
179
+ if (!images.length && !web.length) {
180
+ const err = envelopeError(data);
181
+ if (err)
182
+ return pc.red(`error: ${printableLine(err)}`);
183
+ return noGroup ?? pc.dim("No results.");
184
+ }
185
+ const shortened = { any: false };
186
+ const blocks = [];
187
+ if (images.length)
188
+ blocks.push(images.map((im, i) => formatImage(im, i, ctx, shortened)).join("\n\n"));
189
+ if (noGroup)
190
+ blocks.push(noGroup);
191
+ if (web.length) {
192
+ if (blocks.length)
193
+ blocks.push(pc.bold("Web results"));
194
+ blocks.push(formatResultList(web));
195
+ }
196
+ const remainder = ctx.group ? groupRemainder(images) : undefined;
197
+ if (remainder)
198
+ blocks.push(pc.dim(remainder));
199
+ if (shortened.any)
200
+ blocks.push(pc.dim("Shortened for the terminal — --json prints the values and the code in full."));
201
+ return blocks.join("\n\n");
202
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The Octen API wraps every payload in `{ code, msg, data, meta }`. Renderers
3
+ * want the inner body, but have to cope with being handed an already-unwrapped
4
+ * object (tests, piped JSON), so the unwrap is conditional.
5
+ *
6
+ * The seven renderers that predate this file each carry their own copy of the
7
+ * same few lines. New ones use this instead; folding the old ones in is a
8
+ * separate change, since each also has its own empty-state wording to preserve.
9
+ */
10
+ export interface Envelope {
11
+ code?: number;
12
+ msg?: string;
13
+ data?: unknown;
14
+ }
15
+ /** A JSON object — not null, not an array. */
16
+ export declare function isRecord(v: unknown): v is Record<string, any>;
17
+ /** The inner body, or the input itself when it is not an envelope. */
18
+ export declare function unwrap(data: unknown): any;
19
+ /**
20
+ * The API reports application errors inside a 200 envelope, so a renderer that
21
+ * only checked for an empty list would print "No results" for an auth failure.
22
+ * Returns the message to show, or undefined when the envelope is healthy.
23
+ */
24
+ export declare function envelopeError(data: unknown): string | undefined;
@@ -0,0 +1,21 @@
1
+ /** A JSON object — not null, not an array. */
2
+ export function isRecord(v) {
3
+ return v !== null && typeof v === "object" && !Array.isArray(v);
4
+ }
5
+ /** The inner body, or the input itself when it is not an envelope. */
6
+ export function unwrap(data) {
7
+ const inner = data?.data;
8
+ return data && typeof data === "object" && inner && typeof inner === "object" && !Array.isArray(inner)
9
+ ? inner
10
+ : data;
11
+ }
12
+ /**
13
+ * The API reports application errors inside a 200 envelope, so a renderer that
14
+ * only checked for an empty list would print "No results" for an auth failure.
15
+ * Returns the message to show, or undefined when the envelope is healthy.
16
+ */
17
+ export function envelopeError(data) {
18
+ const code = data?.code;
19
+ const msg = data?.msg;
20
+ return code != null && code !== 0 && msg ? String(msg) : undefined;
21
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * News results print the storylines first, then the ranked articles.
3
+ *
4
+ * The storylines are a clustering of the coverage, not a second retrieval, and
5
+ * they carry the summary that answers "what happened with X" without reading
6
+ * every article. One caveat the reader has to know: domain filters narrow the
7
+ * ranked articles only and never reach `subjects`, so a source-restricted
8
+ * question has to be answered from the articles below.
9
+ */
10
+ export declare function renderNewsSearch(data: any): string;
@@ -0,0 +1,72 @@
1
+ import pc from "picocolors";
2
+ import { formatResultList } from "./search.js";
3
+ import { envelopeError, unwrap } from "./envelope.js";
4
+ const MAX_SUMMARY = 400;
5
+ /**
6
+ * News results print the storylines first, then the ranked articles.
7
+ *
8
+ * The storylines are a clustering of the coverage, not a second retrieval, and
9
+ * they carry the summary that answers "what happened with X" without reading
10
+ * every article. One caveat the reader has to know: domain filters narrow the
11
+ * ranked articles only and never reach `subjects`, so a source-restricted
12
+ * question has to be answered from the articles below.
13
+ */
14
+ export function renderNewsSearch(data) {
15
+ const body = unwrap(data);
16
+ const subjects = body?.subjects ?? [];
17
+ const results = body?.results ?? [];
18
+ if (!subjects.length && !results.length) {
19
+ const err = envelopeError(data);
20
+ return err ? pc.red(`error: ${err}`) : pc.dim("No results.");
21
+ }
22
+ const blocks = [];
23
+ if (subjects.length)
24
+ blocks.push(subjects.map(formatSubject).join("\n\n"));
25
+ if (results.length) {
26
+ if (subjects.length)
27
+ blocks.push(pc.bold("Articles"));
28
+ blocks.push(formatResultList(results));
29
+ }
30
+ return blocks.join("\n\n");
31
+ }
32
+ function formatSubject(s, i) {
33
+ const lines = [];
34
+ lines.push(`${pc.bold(`Storyline ${i + 1}: ${s?.name ?? "(unnamed)"}`)}`);
35
+ const span = [s?.time_start, s?.time_latest].filter(Boolean).join(" → ");
36
+ if (span)
37
+ lines.push(` ${pc.dim(span)}`);
38
+ if (s?.summary) {
39
+ const raw = String(s.summary);
40
+ lines.push(` ${raw.length > MAX_SUMMARY ? raw.slice(0, MAX_SUMMARY) + "…" : raw}`);
41
+ }
42
+ // `top_news` is the lead article; `sub_news` are the supporting ones. They
43
+ // need not appear in `results` at all, so dropping them would lose coverage
44
+ // the caller already paid for.
45
+ const articles = [s?.top_news, ...(s?.sub_news ?? [])].filter(Boolean);
46
+ for (const a of articles) {
47
+ lines.push(` • ${a?.title ?? "(no title)"}`);
48
+ if (a?.url)
49
+ lines.push(` ${pc.dim(a.url)}`);
50
+ lines.push(...articleContent(a, " "));
51
+ }
52
+ return lines.join("\n");
53
+ }
54
+ /**
55
+ * Whatever content a storyline article carries, indented under it.
56
+ *
57
+ * These are not duplicates of the ranked results: a storyline's articles need
58
+ * not appear in `data.results` at all, so dropping their `summary`,
59
+ * `highlight` and `full_content` discards content the caller enabled and was
60
+ * billed for, with nowhere else to find it.
61
+ */
62
+ function articleContent(a, indent) {
63
+ const out = [];
64
+ for (const field of ["summary", "highlight", "full_content"]) {
65
+ const raw = a?.[field];
66
+ if (typeof raw !== "string" || !raw.trim())
67
+ continue;
68
+ const text = raw.length > MAX_SUMMARY ? raw.slice(0, MAX_SUMMARY) + "…" : raw;
69
+ out.push(...text.split("\n").map((l) => `${indent}${l}`));
70
+ }
71
+ return out;
72
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Place results live under `data.places`, not `data.results` — `results` is
3
+ * where the optional web pages go, and reading the wrong one is an easy way to
4
+ * conclude the endpoint returned nothing.
5
+ */
6
+ export declare function renderPlaceSearch(data: any): string;
@@ -0,0 +1,87 @@
1
+ import pc from "picocolors";
2
+ import { formatResultList } from "./search.js";
3
+ import { envelopeError, unwrap } from "./envelope.js";
4
+ /** `1.2 km` / `450 m` — metres are what the API returns, km is what reads past a point. */
5
+ function distance(m) {
6
+ if (typeof m !== "number" || !Number.isFinite(m))
7
+ return "";
8
+ return m >= 1000 ? `${(m / 1000).toFixed(1)} km` : `${Math.round(m)} m`;
9
+ }
10
+ /**
11
+ * Place results live under `data.places`, not `data.results` — `results` is
12
+ * where the optional web pages go, and reading the wrong one is an easy way to
13
+ * conclude the endpoint returned nothing.
14
+ */
15
+ export function renderPlaceSearch(data) {
16
+ const body = unwrap(data);
17
+ const places = body?.places ?? [];
18
+ const web = body?.results ?? [];
19
+ if (!places.length && !web.length) {
20
+ const err = envelopeError(data);
21
+ return err ? pc.red(`error: ${err}`) : pc.dim("No results.");
22
+ }
23
+ const blocks = [];
24
+ if (places.length)
25
+ blocks.push(places.map(formatPlace).join("\n\n"));
26
+ if (web.length) {
27
+ if (places.length)
28
+ blocks.push(pc.bold("Web results"));
29
+ blocks.push(formatResultList(web));
30
+ }
31
+ return blocks.join("\n\n");
32
+ }
33
+ function formatPlace(p, i) {
34
+ const lines = [];
35
+ lines.push(`${i + 1}. ${pc.bold(p?.name ?? "(unnamed)")}`);
36
+ const sub = [p?.category, distance(p?.distance)].filter(Boolean).join(" · ");
37
+ if (sub)
38
+ lines.push(` ${pc.dim(sub)}`);
39
+ if (p?.address)
40
+ lines.push(` ${p.address}`);
41
+ const rating = typeof p?.rating === "number"
42
+ ? `${p.rating}/5${typeof p.review_count === "number" ? ` (${p.review_count} reviews)` : ""}`
43
+ : "";
44
+ const status = [rating, p?.status].filter(Boolean).join(" · ");
45
+ if (status)
46
+ lines.push(` ${status}`);
47
+ if (p?.phone)
48
+ lines.push(` ${pc.dim(`Phone: ${p.phone}`)}`);
49
+ if (p?.website)
50
+ lines.push(` ${pc.dim(p.website)}`);
51
+ const hours = Array.isArray(p?.opening_hours) ? p.opening_hours.filter(Boolean) : [];
52
+ if (hours.length)
53
+ lines.push(...hours.map((h) => ` ${pc.dim(h)}`));
54
+ // `false` is printed, not dropped: "not wheelchair accessible" is a reason
55
+ // to pick a different place, and dropping it makes a definite no read the
56
+ // same as an unknown.
57
+ if (p?.attributes && typeof p.attributes === "object") {
58
+ const attrs = Object.entries(p.attributes)
59
+ .map(([k, v]) => (v === true ? k : v === false ? `no ${k}` : v == null ? "" : `${k}=${v}`))
60
+ .filter(Boolean)
61
+ .join(", ");
62
+ if (attrs)
63
+ lines.push(` ${pc.dim(attrs)}`);
64
+ }
65
+ if (typeof p?.latitude === "number" && typeof p?.longitude === "number") {
66
+ lines.push(` ${pc.dim(`${p.latitude}, ${p.longitude}`)}`);
67
+ }
68
+ // Only present when `--max-reviews` asked for them, so nothing is printed
69
+ // that was not requested — and nothing requested is dropped.
70
+ const reviews = Array.isArray(p?.reviews) ? p.reviews.filter(Boolean) : [];
71
+ if (reviews.length) {
72
+ lines.push(` ${pc.bold("Reviews")}`);
73
+ for (const r of reviews) {
74
+ const stamp = [
75
+ typeof r?.rating === "number" ? `${r.rating}/5` : "",
76
+ r?.time_published || "",
77
+ ].filter(Boolean).join(" · ");
78
+ if (stamp)
79
+ lines.push(` ${pc.dim(stamp)}`);
80
+ const text = typeof r?.text === "string" ? r.text.trim() : "";
81
+ // Each line indented, so a paragraph break cannot read as a new field.
82
+ if (text)
83
+ lines.push(...text.split("\n").map((l) => ` ${l}`));
84
+ }
85
+ }
86
+ return lines.join("\n");
87
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Give a lite-mode URL its scheme back.
3
+ *
4
+ * `lite` returns `github.com/docs`, not `https://github.com/docs`. A caller
5
+ * piping that into a browser or another tool gets something nothing can fetch,
6
+ * so the scheme goes on here rather than in a note the reader may not see.
7
+ * Anything already carrying one is left alone, which covers `standard` and any
8
+ * future mode.
9
+ */
10
+ export declare function withScheme(url: unknown): unknown;
11
+ export declare function renderPulseSearch(data: any): string;
@@ -0,0 +1,31 @@
1
+ import pc from "picocolors";
2
+ import { formatResultList } from "./search.js";
3
+ import { envelopeError, unwrap } from "./envelope.js";
4
+ /**
5
+ * Give a lite-mode URL its scheme back.
6
+ *
7
+ * `lite` returns `github.com/docs`, not `https://github.com/docs`. A caller
8
+ * piping that into a browser or another tool gets something nothing can fetch,
9
+ * so the scheme goes on here rather than in a note the reader may not see.
10
+ * Anything already carrying one is left alone, which covers `standard` and any
11
+ * future mode.
12
+ */
13
+ export function withScheme(url) {
14
+ if (typeof url !== "string" || url === "")
15
+ return url;
16
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(url))
17
+ return url;
18
+ // `//host/path` already has the slashes and wants only the scheme; adding
19
+ // the pair as well would produce `https:////host/path`.
20
+ return url.startsWith("//") ? `https:${url}` : `https://${url}`;
21
+ }
22
+ export function renderPulseSearch(data) {
23
+ const body = unwrap(data);
24
+ const raw = body?.results ?? [];
25
+ if (!raw.length) {
26
+ const err = envelopeError(data);
27
+ return err ? pc.red(`error: ${err}`) : pc.dim("No results.");
28
+ }
29
+ const results = raw.map((r) => (r && typeof r === "object" ? { ...r, url: withScheme(r.url) } : r));
30
+ return formatResultList(results);
31
+ }
@@ -1,4 +1,10 @@
1
- import type { SearchResult } from "../../api/search.js";
2
1
  export declare function renderSearch(data: any): string;
3
- /** Render a list of search results as numbered, titled blocks. */
4
- export declare function formatResultList(results: SearchResult[]): string;
2
+ /**
3
+ * Render a list of search results as numbered, titled blocks.
4
+ *
5
+ * Shared by every command that prints web results, so it takes whatever the
6
+ * response held: an entry that is not an object is skipped rather than taking
7
+ * the entries beside it down, a field of the wrong type is ignored, and the
8
+ * text — which is somebody else's page — is made safe for a terminal.
9
+ */
10
+ export declare function formatResultList(results: unknown): string;
@@ -1,4 +1,6 @@
1
1
  import pc from "picocolors";
2
+ import { printable, printableLine } from "../../util/terminalText.js";
3
+ import { isRecord } from "./envelope.js";
2
4
  const MAX_SNIPPET = 300;
3
5
  export function renderSearch(data) {
4
6
  // The Octen API wraps the payload in an envelope: { data: { results }, code, msg, ... }.
@@ -8,37 +10,50 @@ export function renderSearch(data) {
8
10
  const body = data && typeof data === "object" && inner && typeof inner === "object" && !Array.isArray(inner)
9
11
  ? inner
10
12
  : data;
11
- const res = body?.results ?? [];
13
+ // Entries that are not objects are dropped here, so a response made only of
14
+ // them reads as no results rather than as an empty listing.
15
+ const res = Array.isArray(body?.results) ? body.results.filter(isRecord) : [];
12
16
  if (!res.length) {
13
17
  // Surface app-level API errors (non-zero code) instead of a bland "No results."
14
18
  const code = data?.code;
15
19
  const msg = data?.msg;
16
20
  if (code != null && code !== 0 && msg) {
17
- return pc.red(`error: ${msg}`);
21
+ return pc.red(`error: ${printableLine(String(msg))}`);
18
22
  }
19
23
  return pc.dim("No results.");
20
24
  }
21
25
  return formatResultList(res);
22
26
  }
23
- /** Render a list of search results as numbered, titled blocks. */
27
+ const str = (v) => (typeof v === "string" ? v : "");
28
+ /**
29
+ * Render a list of search results as numbered, titled blocks.
30
+ *
31
+ * Shared by every command that prints web results, so it takes whatever the
32
+ * response held: an entry that is not an object is skipped rather than taking
33
+ * the entries beside it down, a field of the wrong type is ignored, and the
34
+ * text — which is somebody else's page — is made safe for a terminal.
35
+ */
24
36
  export function formatResultList(results) {
25
- return results
37
+ const list = Array.isArray(results) ? results.filter(isRecord) : [];
38
+ return list
26
39
  .map((r, i) => {
27
40
  const lines = [];
28
41
  // Numbered + bold title
29
- const title = r.title ?? "(no title)";
42
+ const title = printableLine(str(r.title)) || "(no title)";
30
43
  lines.push(`${i + 1}. ${pc.bold(title)}`);
31
44
  // Dim URL
32
- if (r.url)
33
- lines.push(` ${pc.dim(r.url)}`);
45
+ const url = printableLine(str(r.url));
46
+ if (url)
47
+ lines.push(` ${pc.dim(url)}`);
34
48
  // Dim publication time
35
- if (r.time_published)
36
- lines.push(` ${pc.dim(r.time_published)}`);
49
+ const published = printableLine(str(r.time_published));
50
+ if (published)
51
+ lines.push(` ${pc.dim(published)}`);
37
52
  // Snippet from highlight or full_content (truncated)
38
- const raw = r.highlight ?? r.full_content ?? "";
53
+ const raw = str(r.highlight) || str(r.full_content);
39
54
  if (raw) {
40
55
  const snippet = raw.length > MAX_SNIPPET ? raw.slice(0, MAX_SNIPPET) + "…" : raw;
41
- lines.push(` ${snippet}`);
56
+ lines.push(` ${printable(snippet)}`);
42
57
  }
43
58
  return lines.join("\n");
44
59
  })
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Make text from a response safe to write to a terminal.
3
+ *
4
+ * Titles, descriptions and code come from somebody else's page. Written as
5
+ * they are, an escape sequence in them drives the terminal — clears the
6
+ * screen, rewrites a line already printed, retitles the window — and a
7
+ * carriage return lets one line overwrite the one before it. These show the
8
+ * character instead of sending it. `--json` output is not touched: there the
9
+ * same characters are already escaped by JSON.
10
+ */
11
+ /** For text that may run over several lines, such as code. Tabs and line breaks are kept. */
12
+ export declare function printable(s: string): string;
13
+ /** For a value that belongs on one line, such as a title or a URL. */
14
+ export declare function printableLine(s: string): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Make text from a response safe to write to a terminal.
3
+ *
4
+ * Titles, descriptions and code come from somebody else's page. Written as
5
+ * they are, an escape sequence in them drives the terminal — clears the
6
+ * screen, rewrites a line already printed, retitles the window — and a
7
+ * carriage return lets one line overwrite the one before it. These show the
8
+ * character instead of sending it. `--json` output is not touched: there the
9
+ * same characters are already escaped by JSON.
10
+ */
11
+ // Every C0 control but tab and line feed, DEL, the C1 controls (a lone 0x9b is
12
+ // a whole CSI introducer on terminals that honour them), and the bidirectional
13
+ // overrides, which reorder what is displayed without changing what is there.
14
+ // eslint-disable-next-line no-control-regex
15
+ const UNSAFE = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F\u202A-\u202E\u2066-\u2069]/g;
16
+ function shown(c) {
17
+ const code = c.charCodeAt(0);
18
+ return code <= 0xff
19
+ ? `\\x${code.toString(16).padStart(2, "0")}`
20
+ : `\\u${code.toString(16).padStart(4, "0")}`;
21
+ }
22
+ /** For text that may run over several lines, such as code. Tabs and line breaks are kept. */
23
+ export function printable(s) {
24
+ // A carriage return is meant as a line break, so it becomes one.
25
+ return s.replace(/\r\n?/g, "\n").replace(UNSAFE, shown);
26
+ }
27
+ /** For a value that belongs on one line, such as a title or a URL. */
28
+ export function printableLine(s) {
29
+ return printable(s).replace(/[\t\n]+/g, " ");
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octen.ai/cli",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Command-line tool for Octen — web search, extract, chat, embeddings, and one-command MCP/Skills setup.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -2,6 +2,7 @@
2
2
  "source": "Octen-Team/octen-skills",
3
3
  "ref": "main",
4
4
  "skills": [
5
+ "octen-design-search",
5
6
  "octen-extract",
6
7
  "octen-image-search",
7
8
  "octen-place-search",