Files
ai-job-search/.agents/skills/jobnet-search/cli/src/commands/suggestions.ts
T
Mads LorentzenandClaude Fable 5 f3d4448cca fix: restore Danish CLI commands/ and tsconfig files dropped by old .gitignore (#53)
The pre-#21 .gitignore's unanchored 'commands/' rule silently excluded
.agents/skills/*/cli/src/commands/ (and the tsconfigs) from the initial
release, so every clone's four Danish portal CLIs failed on import with
'Cannot find module ./commands/search.js'. #21 fixed the rule but the
files were never restored - git history has no trace of them.

Restored from the maintainer's working copies, including the updated
jobindex helpers.ts (Jobindex moved search results from the JSON
endpoint, which now returns 204, into an embedded HTML Stash blob).

Verified: all four CLIs typecheck and return live results with their
documented flags. Surfaced while reviewing #52.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 17:39:47 +02:00

67 lines
1.7 KiB
TypeScript

import { defineCommand, option } from "@bunli/core"
import { z } from "zod"
import { apiFetch, writeError } from "../helpers.js"
export const suggestions = defineCommand({
name: "suggestions",
description: "Typeahead suggestions for job title / keyword search",
options: {
query: option(z.string().optional(), {
description: "Partial search string to complete",
}),
limit: option(z.coerce.number().optional(), {
description: "Cap number of suggestions returned",
}),
format: option(z.enum(["json", "table", "plain"]).default("json"), {
description: "Output format: json, table, plain",
}),
},
handler: async ({ flags, signal }) => {
if (signal.aborted) return
if (!flags.query) {
writeError("--query is required", "MISSING_REQUIRED")
process.exit(1)
}
const params: Record<string, string> = {
query: flags.query,
}
try {
const data = await apiFetch<string[]>("/FindJob/GetTypeaheadSuggestions", params)
if (signal.aborted) return
let results = data
if (flags.limit !== undefined) {
results = results.slice(0, flags.limit)
}
if (flags.format === "json") {
console.log(JSON.stringify(results, null, 2))
} else if (flags.format === "table") {
outputTable(results)
} else {
outputPlain(results)
}
} catch (err) {
writeError(err instanceof Error ? err.message : String(err), "API_ERROR")
process.exit(1)
}
},
})
function outputTable(data: string[]): void {
console.log("suggestion")
for (const s of data) {
console.log(s)
}
}
function outputPlain(data: string[]): void {
for (const s of data) {
console.log(s)
}
}