-
Notifications
You must be signed in to change notification settings - Fork 26
feat: declare vouch-context engine contract #249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
claytonlin1110
wants to merge
2
commits into
vouchdev:test
Choose a base branch
from
claytonlin1110:feat/vouch-context-engine
base: test
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /** | ||
| * OpenClaw plugin entry for the vouch-context engine (#228). | ||
| * | ||
| * The host loads this module via openclaw.plugin.json → openclaw.extensions. | ||
| * Runtime assembly delegates to the Python engine through `vouch openclaw-rpc` | ||
| * so the cited synthesis path stays identical to unit tests and kb.context. | ||
| * | ||
| * Enable in openclaw.json: | ||
| * plugins.slots.contextEngine: "vouch-context" | ||
| */ | ||
|
|
||
| import { spawnSync } from 'node:child_process'; | ||
|
|
||
| export const ENGINE_ID = 'vouch-context'; | ||
| export const ENGINE_NAME = 'Vouch Context Engine'; | ||
|
|
||
| /** @typedef {import('node:child_process').SpawnSyncReturns<string>} SpawnResult */ | ||
|
|
||
| /** | ||
| * @param {string} method | ||
| * @param {Record<string, unknown>} params | ||
| * @returns {Record<string, unknown>} | ||
| */ | ||
| function callPythonEngine(method, params) { | ||
| const envelope = JSON.stringify({ | ||
| id: 'openclaw', | ||
| method, | ||
| params, | ||
| }); | ||
| /** @type {SpawnResult} */ | ||
| const proc = spawnSync('vouch', ['openclaw-rpc'], { | ||
| input: envelope, | ||
| encoding: 'utf8', | ||
| env: process.env, | ||
| maxBuffer: 16 * 1024 * 1024, | ||
| }); | ||
| if (proc.error) { | ||
| throw proc.error; | ||
| } | ||
| if (proc.status !== 0) { | ||
| const detail = (proc.stderr || proc.stdout || '').trim(); | ||
| throw new Error( | ||
| `vouch openclaw-rpc exited ${proc.status}${detail ? `: ${detail}` : ''}`, | ||
| ); | ||
| } | ||
| let parsed; | ||
| try { | ||
| parsed = JSON.parse(String(proc.stdout || '{}')); | ||
| } catch (err) { | ||
| throw new Error(`vouch openclaw-rpc returned invalid json: ${err}`); | ||
| } | ||
| if (!parsed.ok) { | ||
| const msg = parsed.error?.message || 'engine rpc failed'; | ||
| throw new Error(msg); | ||
| } | ||
| return parsed.result; | ||
| } | ||
|
|
||
| /** @type {{ id: string; name: string; description: string; register: (api: any) => void }} */ | ||
| const entry = { | ||
| id: 'vouch-context-engine', | ||
| name: 'Vouch Context Engine', | ||
| description: | ||
| 'Review-gated KB context: cited retrieval + salience reflex + hot memory on every assemble()', | ||
|
|
||
| register(api) { | ||
| api.registerContextEngine(ENGINE_ID, (ctx) => { | ||
| const workspaceDir = ctx.workspaceDir; | ||
| const kbPath = ctx.kbPath ?? ctx.kb_path; | ||
| const agent = ctx.agent; | ||
|
claytonlin1110 marked this conversation as resolved.
|
||
| const project = ctx.project; | ||
|
|
||
| const baseParams = () => ({ | ||
| workspaceDir, | ||
| kbPath, | ||
| agent, | ||
| project, | ||
| }); | ||
|
|
||
| return { | ||
| info: { | ||
| id: ENGINE_ID, | ||
| name: ENGINE_NAME, | ||
| version: '0.1.0', | ||
| ownsCompaction: false, | ||
| }, | ||
|
|
||
| async ingest({ sessionId, message, isHeartbeat }) { | ||
| return callPythonEngine('ingest', { | ||
| ...baseParams(), | ||
| sessionId, | ||
| message, | ||
| isHeartbeat, | ||
| }); | ||
| }, | ||
|
|
||
| async assemble(params) { | ||
| return callPythonEngine('assemble', { | ||
| ...baseParams(), | ||
| ...params, | ||
| }); | ||
| }, | ||
|
|
||
| async compact(params) { | ||
| return callPythonEngine('compact', { | ||
| ...baseParams(), | ||
| ...params, | ||
| }); | ||
| }, | ||
| }; | ||
| }); | ||
| }, | ||
| }; | ||
|
|
||
| export default entry; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """OpenClaw integration for vouch.""" | ||
|
|
||
| from .context_engine import ( | ||
| ENGINE_API_VERSION, | ||
| ENGINE_ID, | ||
| ENGINE_NAME, | ||
| VouchContextEngine, | ||
| create_vouch_context_engine, | ||
| describe_engine, | ||
| engine_info, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "ENGINE_API_VERSION", | ||
| "ENGINE_ID", | ||
| "ENGINE_NAME", | ||
| "VouchContextEngine", | ||
| "create_vouch_context_engine", | ||
| "describe_engine", | ||
| "engine_info", | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.