Skip to content

feat(harness-sdk): the kilo harness SDK - #5878

Open
iscekic wants to merge 1 commit into
mainfrom
feat/kilo-harness-sdk
Open

feat(harness-sdk): the kilo harness SDK#5878
iscekic wants to merge 1 commit into
mainfrom
feat/kilo-harness-sdk

Conversation

@iscekic

@iscekic iscekic commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

A new package, @kilocode/harness-sdk. It holds a conversation with a model,
keeps the model cache warm, stores the conversation, and summarises it when the
conversation outgrows the window.

One source runs on Node and on React Native. Nothing in src/core/ names a
platform: fetch, SQLite and the source of random bytes are all plugin points.

Read packages/harness-sdk/README.md first. It is what a consumer sees, and
it is the fastest way to judge whether the shape is right. AGENTS.md is the
second read: it holds why each decision was made and the measurement behind it.

Nothing on this branch imports the package, so it cannot change any behaviour
that runs today. #5895 is stacked on it and is the first consumer: the mobile
chat tab.

What it does

  • Holds a session. openSession gives a handle. ask streams the answer
    back as events: text, thinking, tool calls, tool results, and a done that
    carries the token counts and why the model stopped.
  • Speaks three gateway shapes. messages, responses and chat_completions,
    from one internal model. A model the catalog knows nothing about is assumed to
    speak all three, and the best one it actually speaks is used.
  • Keeps the prefix stable. The prompt is append-only and the cache
    breakpoints do not move, which is what makes the provider's cache hit.
  • Runs tools between rounds. Every call can outlive the request: the model is
    told a call is still running, carries on with what does not depend on it, and
    the answer drives a round of its own when it lands. Four parties decide how
    long it waits, in a fixed order.
  • Ships two tools. questionTool asks the person; subagentTool hands a
    task to a session of its own and returns one answer.
  • Stores and resumes. SQLite through a one-function driver, on node:sqlite
    or expo-sqlite. A session can be continued, or cloned onto another model —
    which is how a person switches model mid-conversation without losing it.
    The store plugins name no runtime type, so the package depends on neither.
  • Compacts itself. A session that fills the window summarises itself and
    keeps what it was told to keep.

How it is built

src/core/ holds the contracts and the pure domain. src/plugins/ holds every
implementation, including the package's own defaults. A CI check asserts the
direction: core/ never imports plugins/.

Eight plugin points, each a Context.Tag with a default this package owns:
ModelClient, ToolRegistry, PromptAssembler, ModelCatalog, SessionStore,
TokenSource, RetryPolicy, EntropySource. layerKilo is the wiring almost
every caller writes; each part underneath is still swappable.

Nine entry points, so a consumer bundles only what they run. The conformance
checks and the shipped fetch adapter each sit behind one of their own.

Libraries do the work: effect for control flow, streams and resources,
eventsource-parser for SSE, typia for validation, and the Anthropic and
OpenAI SDKs as types only, so a wrong field name in a request body does not
compile. One exception is written down with its reason: core/id.ts encodes a
ULID itself, because every ulid build either drags node:crypto into the core
or throws at import on a runtime with no global crypto.

typia runs at compile time through ttsc, so no schema object exists at run
time and validation costs 0.005 us per event.

What proves it

Unit tests 255 across 42 files
Live runs against the real gateway 20, pnpm test:e2e:all
Timing gates pnpm test:perf
Plugin conformance checkStore, checkAssembler, shipped for plugin authors
Package surface check:package imports the built bundle from all 9 entry points
Platform check:platform fails the build if it names a runtime
Migrations check:migrations catches the inlined SQL drifting from the schema

The live runs are not in CI and must not be: they cost money and need a token.
They exist because a change to the wire or to the session has to be answered by
the provider, not by a fake.

Two matrices are recorded in AGENTS.md rather than described:

  • Ten models, five turns each. Every one answered the last question from
    history. A model whose provider caches at all reads above 0.99 of its input
    from the cache.
  • Eleven models, both shipped tools. Every one called each tool and sent a
    payload the schema accepted. The subagent description was tuned against this
    table until it did — two models had read the old text as naming the only two
    uses, and answered that no tool of theirs could look a thing up.

Timing, measured rather than assumed: a 200 turn prompt assembles in under 20 us,
a whole request costs 48 us before the socket, and a streamed token costs 7 us
end to end against seconds of provider latency. AGENTS.md also records one
optimisation that was expected to be ten-fold and measured eleven percent, and
one memory measurement that was thrown away because it moved more than the thing
it was measuring.

Outside the package

  • .github/workflows/ci.yml — a harness-sdk job, path-filtered, running
    check:ci. The migration check is why it exists: nothing at run time notices
    when the inlined SQL stops matching the schema.
  • .gitignore — the package's dist/.
  • pnpm-lock.yaml — the new dependencies.
  • apps/web/AGENTS.md — ten lines next dev writes into the file itself and
    re-adds when removed. Unrelated to this package; committed because that is
    what the block asks for.

Not here

@iscekic iscekic self-assigned this Sep 4, 2026
@iscekic
iscekic marked this pull request as ready for review September 5, 2026 04:03
Comment thread packages/harness-sdk/src/core/ask.ts
Comment thread packages/harness-sdk/src/core/background.ts
Comment thread packages/harness-sdk/src/core/compact.ts
Comment thread packages/harness-sdk/src/plugins/gateway/wire/responses.ts
Comment thread packages/harness-sdk/src/plugins/store/driver.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/harness-sdk/src/plugins/gateway/wire/completions.ts
  • packages/harness-sdk/src/plugins/gateway/wire/replay.test.ts
Previous Review Summaries (9 snapshots, latest commit 1b6d23f)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 1b6d23f)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/harness-sdk/src/plugins/gateway/wire/completions.ts 219 Empty content: "" is treated as a text delta and shadows reasoning on the same frame
Files Reviewed (14 files)
  • packages/harness-sdk/src/plugins/gateway/wire/completions.ts - 1 issue
  • packages/harness-sdk/src/plugins/gateway/wire/responses.ts
  • packages/harness-sdk/src/plugins/gateway/wire/messages.ts
  • packages/harness-sdk/src/plugins/gateway/index.ts
  • packages/harness-sdk/src/plugins/gateway/http.ts
  • packages/harness-sdk/src/core/ask.ts
  • packages/harness-sdk/src/core/background.ts
  • packages/harness-sdk/src/core/loop.ts
  • packages/harness-sdk/src/core/compact.ts
  • packages/harness-sdk/src/core/queue.ts
  • packages/harness-sdk/src/plugins/store/driver.ts
  • packages/harness-sdk/src/plugins/store/sqlite.ts
  • packages/harness-sdk/src/plugins/tools/subagent.ts
  • packages/harness-sdk/e2e/tools.ts

Fix these issues in Kilo Cloud

Previous review (commit b1600c9)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/harness-sdk/e2e/compact.ts
  • packages/harness-sdk/e2e/together.ts

Previous review (commit c5808bf)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • packages/harness-sdk/e2e/cancel.ts
  • packages/harness-sdk/e2e/conversation.ts
  • packages/harness-sdk/e2e/live.ts
  • packages/harness-sdk/e2e/shapes.ts
  • packages/harness-sdk/e2e/subagent.ts
  • packages/harness-sdk/e2e/tools.ts

Previous review (commit 7556919)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • packages/harness-sdk/e2e/image.ts

Previous review (commit 7dc528e)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/harness-sdk/e2e/tools.ts
  • packages/harness-sdk/e2e/queue.ts

Previous review (commit 7fe69c0)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/harness-sdk/e2e/tools.ts 325 First-attempt fail() makes the retry a no-op
Files Reviewed (4 files)
  • packages/harness-sdk/e2e/tools.ts - 1 issue
  • packages/harness-sdk/e2e/cancel.ts
  • packages/harness-sdk/e2e/image.ts
  • packages/harness-sdk/e2e/subagent.ts

Fix these issues in Kilo Cloud

Previous review (commit 4766987)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/harness-sdk/e2e/tools.ts 316 First-attempt fail() makes the retry a no-op
Files Reviewed (5 files)
  • packages/harness-sdk/e2e/tools.ts - 1 issue
  • packages/harness-sdk/e2e/cancel.ts
  • packages/harness-sdk/e2e/image.ts
  • packages/harness-sdk/e2e/subagent.ts
  • packages/harness-sdk/e2e/together.ts

Fix these issues in Kilo Cloud

Previous review (commit dfc1b09)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/harness-sdk/e2e/tools.ts 296 First-attempt fail() makes the retry a no-op
Files Reviewed (9 files)
  • packages/harness-sdk/e2e/tools.ts - 1 issue
  • packages/harness-sdk/AGENTS.md
  • packages/harness-sdk/e2e/cancel.ts
  • packages/harness-sdk/e2e/clone.ts
  • packages/harness-sdk/e2e/conversation.ts
  • packages/harness-sdk/e2e/image.ts
  • packages/harness-sdk/e2e/queue.ts
  • packages/harness-sdk/e2e/subagent.ts
  • packages/harness-sdk/e2e/together.ts

Fix these issues in Kilo Cloud

Previous review (commit 1f53424)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/harness-sdk/e2e/tools.ts 296 First-attempt fail() makes the retry a no-op
Files Reviewed (7 files)
  • packages/harness-sdk/e2e/tools.ts - 1 issue
  • packages/harness-sdk/AGENTS.md
  • packages/harness-sdk/e2e/cancel.ts
  • packages/harness-sdk/e2e/image.ts
  • packages/harness-sdk/e2e/queue.ts
  • packages/harness-sdk/e2e/subagent.ts
  • packages/harness-sdk/e2e/together.ts

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 142.3K · Output: 6.1K · Cached: 451.7K

Review guidance: REVIEW.md from base branch main

Comment thread packages/harness-sdk/e2e/tools.ts Outdated
@iscekic iscekic added human-ready The PR is ready for human review. and removed human-ready The PR is ready for human review. labels Sep 6, 2026
@iscekic
iscekic marked this pull request as draft September 10, 2026 00:54
iscekic added a commit that referenced this pull request Sep 10, 2026
@iscekic
iscekic force-pushed the feat/kilo-harness-sdk branch from 2e6d972 to 1b6d23f Compare September 10, 2026 01:38
@iscekic
iscekic marked this pull request as ready for review September 10, 2026 01:52
@iscekic
iscekic marked this pull request as draft September 10, 2026 02:16
@iscekic

iscekic commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

bot: Accepted. Pushed 4c7df0a (kwf kwf-fix-review-42c5).

What changed:

  • packages/harness-sdk/src/plugins/gateway/wire/completions.ts:219 — accepted. toDelta returned a text delta for content: "" before it reached the reasoning branch, so an empty placeholder shadowed the thinking on the same frame. Now only a non-empty string counts as a text delta. An empty-content frame yields its reasoning (reasoning or reasoning_content), or undefined when it carries nothing else. A replay unit test covers both reasoning fields and the bare empty frame.

@iscekic
iscekic force-pushed the feat/kilo-harness-sdk branch from 1b6d23f to 4c7df0a Compare September 10, 2026 02:48
@iscekic
iscekic marked this pull request as ready for review September 10, 2026 03:04
@iscekic iscekic added the human-ready The PR is ready for human review. label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-ready The PR is ready for human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant