KosmoKrator

data

Hacker News Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Hacker News KosmoKrator integration.

5 functions 5 read 0 write No credentials auth

Lua Namespace

Agents call this integration through app.integrations.hackernews.*. Use lua_read_doc("integrations.hackernews") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Hacker News — Lua API Reference

All Hacker News tools are available under app.integrations.hackernews.

get_item

Fetch a single Hacker News item (story, comment, job, poll, or poll option) by its numeric ID.

Parameters

NameTypeRequiredDescription
idintegeryesThe Hacker News item ID (e.g., 12345)

Response Fields

FieldTypeDescription
idintegerItem ID
typestringItem type: story, comment, job, poll, pollopt
titlestring|nullTitle (stories, jobs, polls)
urlstring|nullExternal URL (stories, jobs)
textstring|nullHTML body text (comments, text posts, poll options)
bystring|nullAuthor username
scoreinteger|nullScore / upvotes
timeinteger|nullUnix timestamp
time_isostring|nullISO 8601 formatted time
descendantsinteger|nullTotal comment count
kidsarrayDirect child item IDs (comments)
parentinteger|nullParent item ID (for comments)
deletedbooleanWhether the item was deleted

Example

local item = app.integrations.hackernews.get_item({ id = 12345 })

if item then
  print(item.title)
  print("by " .. item.by .. " | score: " .. (item.score or 0))
  print("Comments: " .. (item.descendants or 0))
  if item.url then
    print("Link: " .. item.url)
  end
end

get_user

Fetch a Hacker News user profile by username.

Parameters

NameTypeRequiredDescription
idstringyesThe Hacker News username (e.g., "pg", "dang")

Response Fields

FieldTypeDescription
idstringUsername
karmaintegerKarma score
aboutstring|nullProfile about text (HTML)
createdintegerUnix timestamp of account creation
created_isostringISO 8601 formatted creation time
submittedarrayList of submitted item IDs

Example

local user = app.integrations.hackernews.get_user({ id = "pg" })

if user then
  print(user.id .. " has " .. user.karma .. " karma")
  print("Account created: " .. user.created_iso)
end

list_top_stories

Fetch the current top stories from Hacker News, ranked by the HN algorithm (combination of score, recency, and flags).

Parameters

NameTypeRequiredDescription
limitintegernoMax stories to return (default: 30, max: 100)

Example

local result = app.integrations.hackernews.list_top_stories({ limit = 10 })

for _, story in ipairs(result.stories) do
  print(story.title)
  print("  by " .. (story.by or "unknown") .. " | score: " .. (story.score or 0) .. " | comments: " .. (story.descendants or 0))
  if story.url then
    print("  " .. story.url)
  end
end

list_new_stories

Fetch the newest stories from Hacker News. These are the most recently submitted stories, not yet ranked by the HN algorithm.

Parameters

NameTypeRequiredDescription
limitintegernoMax stories to return (default: 30, max: 100)

Example

local result = app.integrations.hackernews.list_new_stories({ limit = 15 })

for _, story in ipairs(result.stories) do
  print(story.title .. " (score: " .. (story.score or 0) .. ")")
end

list_best_stories

Fetch the highest-scoring stories from Hacker News, regardless of age.

Parameters

NameTypeRequiredDescription
limitintegernoMax stories to return (default: 30, max: 100)

Example

local result = app.integrations.hackernews.list_best_stories({ limit = 10 })

print("Top " .. result.limit .. " of " .. result.total_ids .. " best stories:")
for _, story in ipairs(result.stories) do
  print("  [" .. story.score .. "] " .. story.title)
end

Common Patterns

Get a story and its top comments

local story = app.integrations.hackernews.get_item({ id = 12345 })

if story and story.kids then
  for i, kid_id in ipairs(story.kids) do
    if i > 5 then break end
    local comment = app.integrations.hackernews.get_item({ id = kid_id })
    if comment then
      print(comment.by .. ": " .. (comment.text or ""))
    end
  end
end

Find stories about a topic

local result = app.integrations.hackernews.list_top_stories({ limit = 50 })
local topic = "rust"

for _, story in ipairs(result.stories) do
  if story.title and string.find(string.lower(story.title), topic) then
    print("[" .. (story.score or 0) .. "] " .. story.title)
    if story.url then print("  " .. story.url) end
  end
end
Raw agent markdown
# Hacker News — Lua API Reference

All Hacker News tools are available under `app.integrations.hackernews`.

## get_item

Fetch a single Hacker News item (story, comment, job, poll, or poll option) by its numeric ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | integer | yes | The Hacker News item ID (e.g., `12345`) |

### Response Fields

| Field | Type | Description |
|-------|------|-------------|
| `id` | integer | Item ID |
| `type` | string | Item type: `story`, `comment`, `job`, `poll`, `pollopt` |
| `title` | string\|null | Title (stories, jobs, polls) |
| `url` | string\|null | External URL (stories, jobs) |
| `text` | string\|null | HTML body text (comments, text posts, poll options) |
| `by` | string\|null | Author username |
| `score` | integer\|null | Score / upvotes |
| `time` | integer\|null | Unix timestamp |
| `time_iso` | string\|null | ISO 8601 formatted time |
| `descendants` | integer\|null | Total comment count |
| `kids` | array | Direct child item IDs (comments) |
| `parent` | integer\|null | Parent item ID (for comments) |
| `deleted` | boolean | Whether the item was deleted |

### Example

```lua
local item = app.integrations.hackernews.get_item({ id = 12345 })

if item then
  print(item.title)
  print("by " .. item.by .. " | score: " .. (item.score or 0))
  print("Comments: " .. (item.descendants or 0))
  if item.url then
    print("Link: " .. item.url)
  end
end
```

---

## get_user

Fetch a Hacker News user profile by username.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The Hacker News username (e.g., `"pg"`, `"dang"`) |

### Response Fields

| Field | Type | Description |
|-------|------|-------------|
| `id` | string | Username |
| `karma` | integer | Karma score |
| `about` | string\|null | Profile about text (HTML) |
| `created` | integer | Unix timestamp of account creation |
| `created_iso` | string | ISO 8601 formatted creation time |
| `submitted` | array | List of submitted item IDs |

### Example

```lua
local user = app.integrations.hackernews.get_user({ id = "pg" })

if user then
  print(user.id .. " has " .. user.karma .. " karma")
  print("Account created: " .. user.created_iso)
end
```

---

## list_top_stories

Fetch the current top stories from Hacker News, ranked by the HN algorithm (combination of score, recency, and flags).

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Max stories to return (default: 30, max: 100) |

### Example

```lua
local result = app.integrations.hackernews.list_top_stories({ limit = 10 })

for _, story in ipairs(result.stories) do
  print(story.title)
  print("  by " .. (story.by or "unknown") .. " | score: " .. (story.score or 0) .. " | comments: " .. (story.descendants or 0))
  if story.url then
    print("  " .. story.url)
  end
end
```

---

## list_new_stories

Fetch the newest stories from Hacker News. These are the most recently submitted stories, not yet ranked by the HN algorithm.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Max stories to return (default: 30, max: 100) |

### Example

```lua
local result = app.integrations.hackernews.list_new_stories({ limit = 15 })

for _, story in ipairs(result.stories) do
  print(story.title .. " (score: " .. (story.score or 0) .. ")")
end
```

---

## list_best_stories

Fetch the highest-scoring stories from Hacker News, regardless of age.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Max stories to return (default: 30, max: 100) |

### Example

```lua
local result = app.integrations.hackernews.list_best_stories({ limit = 10 })

print("Top " .. result.limit .. " of " .. result.total_ids .. " best stories:")
for _, story in ipairs(result.stories) do
  print("  [" .. story.score .. "] " .. story.title)
end
```

---

## Common Patterns

### Get a story and its top comments

```lua
local story = app.integrations.hackernews.get_item({ id = 12345 })

if story and story.kids then
  for i, kid_id in ipairs(story.kids) do
    if i > 5 then break end
    local comment = app.integrations.hackernews.get_item({ id = kid_id })
    if comment then
      print(comment.by .. ": " .. (comment.text or ""))
    end
  end
end
```

### Find stories about a topic

```lua
local result = app.integrations.hackernews.list_top_stories({ limit = 50 })
local topic = "rust"

for _, story in ipairs(result.stories) do
  if story.title and string.find(string.lower(story.title), topic) then
    print("[" .. (story.score or 0) .. "] " .. story.title)
    if story.url then print("  " .. story.url) end
  end
end
```

Metadata-Derived Lua Example

local result = app.integrations.hackernews.hackernews_get_item({
  id = 1
})
print(result)

Functions

hackernews_get_item

Fetch a Hacker News item (story, comment, job, poll, or poll option) by its numeric ID. Returns all available fields: title, URL, text, author (by), score, time, descendants, and kids (child comment IDs). Use this to look up any HN item when you know its ID.

Operation
Read read
Full name
hackernews.hackernews_get_item
ParameterTypeRequiredDescription
id integer yes The Hacker News item ID (e.g., 12345).

hackernews_get_user

Fetch a Hacker News user profile by username. Returns karma score, about text, account creation date, and lists of submitted item IDs (submissions) and comment IDs.

Operation
Read read
Full name
hackernews.hackernews_get_user
ParameterTypeRequiredDescription
id string yes The Hacker News username (e.g., "pg", "dang").

hackernews_list_top_stories

Fetch the current top stories from Hacker News. Returns up to N stories with full item data (title, URL, score, author, comment count). The "top" list is ranked by the HN algorithm (a combination of score, recency, and flags).

Operation
Read read
Full name
hackernews.hackernews_list_top_stories
ParameterTypeRequiredDescription
limit integer no Maximum number of stories to return (default: 30, max: 100).

hackernews_list_new_stories

Fetch the newest stories from Hacker News. Returns up to N stories with full item data (title, URL, score, author, comment count). These are the most recently submitted stories, not yet ranked by the HN algorithm.

Operation
Read read
Full name
hackernews.hackernews_list_new_stories
ParameterTypeRequiredDescription
limit integer no Maximum number of stories to return (default: 30, max: 100).

hackernews_list_best_stories

Fetch the highest-scoring (best) stories from Hacker News. Returns up to N stories with full item data (title, URL, score, author, comment count). These are the stories with the highest scores, regardless of age.

Operation
Read read
Full name
hackernews.hackernews_list_best_stories
ParameterTypeRequiredDescription
limit integer no Maximum number of stories to return (default: 30, max: 100).