opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: /knowledge to extract knowledge files

Open paralin opened this issue 2 weeks ago • 10 comments

Adds a command /knowledge which creates a sub-agent to take any new "knowledge" in the session and format it neatly into markdown docs in ./.opencode/knowledge/

This is particularly useful both for human-readable documentation for getting familiarized with a codebase, and for providing an extended version of AGENTS.md which does not pollute the context.

A follow-on commit adds a system to automatically load files from the knowledge directory according to topics mentioned in the conversation.

Try running /knowledge to create the sub-agent.

paralin avatar Dec 08 '25 18:12 paralin

It's so so hard to get this CI to pass. It complains about bun ./packages/sdk/js/script/build.ts - I run that, then it complains about formatting. So I run bun ./script/format.ts and then it complains about the SDK being out of date. I think because this thing is automatically making and pushing commits there are a lot of noise commits being made unnecessarily. There should just be a single .ts script in ./script/ that re-generates, formats, etc, to a state where the CI will pass right away. Am I missing something? cc @jerome-benoit

paralin avatar Dec 08 '25 19:12 paralin

  1. Fails after running bun run --conditions=browser ./src/index.ts generate and having a change:
    • https://github.com/sst/opencode/actions/runs/20039680842/job/57470274127?pr=5253#step:5:66
  2. I ran bun ./packages/sdk/js/script/build.ts to run the same commit that failed the workflow:
    • https://github.com/sst/opencode/actions/runs/20039777005/job/57470595171?pr=5253#step:5:67
  3. Now the SDK format step is failing again.
    • https://github.com/sst/opencode/actions/runs/20039843433/job/57470816779?pr=5253#step:5:74
    • bun ./packages/sdk/js/script/build.ts
    • On my machine this output is clean (no changes).

I cannot find a way to get this to pass.

paralin avatar Dec 08 '25 19:12 paralin

Hey @paralin, the format CI is set up to auto-push formatting fixes, but this doesn't work for PRs from forks (the GitHub token can't push to external repos).

You'll need to run bun run prettier --ignore-unknown --write . locally and push the formatted changes yourself.

edlsh avatar Dec 08 '25 19:12 edlsh

@edlsh Thanks, but I ran that command, amended, force pushed, and once again am caught in the same loop.

  1. prettier --ignore-unknown --write .
  2. git commit --amend
  3. git push -f

and now: https://github.com/sst/opencode/actions/runs/20040083944/job/57471612297?pr=5253#step:5:69

What now? Also, why is this done like this? Can't the pre-push hook also check the formatting (like it checks typecheck)?

paralin avatar Dec 08 '25 19:12 paralin

@paralin Don't worry too much about the format CI - it fails on fork PRs because it can't push back to external repos. Once a maintainer approves and merges to dev, the auto-formatting will run with proper permissions and fix it up.

edlsh avatar Dec 08 '25 19:12 edlsh

If you really wanted all green lights, then:

# 1. Generate SDK
bun ./packages/sdk/js/script/build.ts

# 2. Format everything (including generated SDK)
bun run prettier --ignore-unknown --write .

# 3. Commit and push
git add -A && git commit --amend && git push -f

The key is formatting after SDK generation so the generated files are also formatted.

edlsh avatar Dec 08 '25 19:12 edlsh

@edlsh I just ran the commands you gave me and unfortunately it's still not passing.

I would suggest a) making sure we have a bun format command that is deterministic (based on node_modules) and b) run this in the git commit hooks so it's always applied and c) just fail the PR check if the formatting was not applied properly. This way everyone can just format it on their end.

paralin avatar Dec 08 '25 19:12 paralin

commit adds a system to automatically load files from the knowledge directory according to topics mentioned in the conversation.

Try running /knowledge to create the sub-agent.

Sdk ci format and format ci always clash with each other, so you will never see both turn green. So chill, even if the ci fails they don’t bother much. It will still get merged

Raviguntakala avatar Dec 09 '25 02:12 Raviguntakala

@Raviguntakala okay I see, thanks.

paralin avatar Dec 09 '25 02:12 paralin

Working now and this PR is as minimal as possible to add the feature. I'm using it a lot in my projects.

In opencode.jsonc:

  "agent": {
    "knowledge-extractor": {
      // "model": "github-copilot/claude-opus-4-5",
      "model": "github-copilot/oswe-vscode-prime",
    },
  },

paralin avatar Dec 10 '25 20:12 paralin