@autonav/core 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/adapter/index.d.ts +3 -3
- package/dist/adapter/index.d.ts.map +1 -1
- package/dist/adapter/index.js +3 -3
- package/dist/adapter/index.js.map +1 -1
- package/dist/adapter/navigator-adapter.d.ts +196 -0
- package/dist/adapter/navigator-adapter.d.ts.map +1 -0
- package/dist/adapter/navigator-adapter.js +579 -0
- package/dist/adapter/navigator-adapter.js.map +1 -0
- package/dist/cli/autonav.d.ts +2 -6
- package/dist/cli/autonav.d.ts.map +1 -1
- package/dist/cli/autonav.js +32 -53
- package/dist/cli/autonav.js.map +1 -1
- package/dist/cli/nav-chat.d.ts +2 -1
- package/dist/cli/nav-chat.d.ts.map +1 -1
- package/dist/cli/nav-chat.js +32 -3
- package/dist/cli/nav-chat.js.map +1 -1
- package/dist/cli/nav-init.d.ts +2 -1
- package/dist/cli/nav-init.d.ts.map +1 -1
- package/dist/cli/nav-init.js +12 -4
- package/dist/cli/nav-init.js.map +1 -1
- package/dist/cli/nav-install.d.ts +2 -1
- package/dist/cli/nav-install.d.ts.map +1 -1
- package/dist/cli/nav-install.js +4 -2
- package/dist/cli/nav-install.js.map +1 -1
- package/dist/cli/nav-memento.d.ts +3 -2
- package/dist/cli/nav-memento.d.ts.map +1 -1
- package/dist/cli/nav-memento.js +12 -6
- package/dist/cli/nav-memento.js.map +1 -1
- package/dist/cli/nav-mend.d.ts +2 -1
- package/dist/cli/nav-mend.d.ts.map +1 -1
- package/dist/cli/nav-mend.js +4 -1
- package/dist/cli/nav-mend.js.map +1 -1
- package/dist/cli/nav-migrate.d.ts +2 -1
- package/dist/cli/nav-migrate.d.ts.map +1 -1
- package/dist/cli/nav-migrate.js +2 -6
- package/dist/cli/nav-migrate.js.map +1 -1
- package/dist/cli/nav-query.d.ts +2 -1
- package/dist/cli/nav-query.d.ts.map +1 -1
- package/dist/cli/nav-query.js +12 -6
- package/dist/cli/nav-query.js.map +1 -1
- package/dist/cli/nav-standup.d.ts +18 -0
- package/dist/cli/nav-standup.d.ts.map +1 -0
- package/dist/cli/nav-standup.js +151 -0
- package/dist/cli/nav-standup.js.map +1 -0
- package/dist/cli/nav-uninstall.d.ts +2 -1
- package/dist/cli/nav-uninstall.d.ts.map +1 -1
- package/dist/cli/nav-uninstall.js +4 -2
- package/dist/cli/nav-uninstall.js.map +1 -1
- package/dist/cli/nav-update.d.ts +2 -1
- package/dist/cli/nav-update.d.ts.map +1 -1
- package/dist/cli/nav-update.js +11 -6
- package/dist/cli/nav-update.js.map +1 -1
- package/dist/conversation/App.d.ts +9 -2
- package/dist/conversation/App.d.ts.map +1 -1
- package/dist/conversation/App.js +304 -111
- package/dist/conversation/App.js.map +1 -1
- package/dist/conversation/index.d.ts +5 -0
- package/dist/conversation/index.d.ts.map +1 -1
- package/dist/conversation/index.js +17 -2
- package/dist/conversation/index.js.map +1 -1
- package/dist/harness/chibi-harness.d.ts +36 -0
- package/dist/harness/chibi-harness.d.ts.map +1 -0
- package/dist/harness/chibi-harness.js +383 -0
- package/dist/harness/chibi-harness.js.map +1 -0
- package/dist/harness/chibi-plugins/get_plugin_config +64 -0
- package/dist/harness/chibi-plugins/query_navigator +114 -0
- package/dist/harness/chibi-plugins/submit_answer +38 -0
- package/dist/harness/chibi-plugins/update_plugin_config +91 -0
- package/dist/harness/claude-code-harness.d.ts +24 -0
- package/dist/harness/claude-code-harness.d.ts.map +1 -0
- package/dist/harness/claude-code-harness.js +242 -0
- package/dist/harness/claude-code-harness.js.map +1 -0
- package/dist/harness/ephemeral-home.d.ts +34 -0
- package/dist/harness/ephemeral-home.d.ts.map +1 -0
- package/dist/harness/ephemeral-home.js +56 -0
- package/dist/harness/ephemeral-home.js.map +1 -0
- package/dist/harness/factory.d.ts +47 -0
- package/dist/harness/factory.d.ts.map +1 -0
- package/dist/harness/factory.js +84 -0
- package/dist/harness/factory.js.map +1 -0
- package/dist/harness/helpers.d.ts +58 -0
- package/dist/harness/helpers.d.ts.map +1 -0
- package/dist/harness/helpers.js +78 -0
- package/dist/harness/helpers.js.map +1 -0
- package/dist/harness/index.d.ts +14 -0
- package/dist/harness/index.d.ts.map +1 -0
- package/dist/harness/index.js +13 -0
- package/dist/harness/index.js.map +1 -0
- package/dist/harness/opencode-harness.d.ts +79 -0
- package/dist/harness/opencode-harness.d.ts.map +1 -0
- package/dist/harness/opencode-harness.js +537 -0
- package/dist/harness/opencode-harness.js.map +1 -0
- package/dist/harness/opencode-tools/get_plugin_config.ts +72 -0
- package/dist/harness/opencode-tools/query_navigator.ts +126 -0
- package/dist/harness/opencode-tools/submit_answer.ts +40 -0
- package/dist/harness/opencode-tools/update_plugin_config.ts +105 -0
- package/dist/harness/sandbox.d.ts +59 -0
- package/dist/harness/sandbox.d.ts.map +1 -0
- package/dist/harness/sandbox.js +152 -0
- package/dist/harness/sandbox.js.map +1 -0
- package/dist/harness/tool-server.d.ts +50 -0
- package/dist/harness/tool-server.d.ts.map +1 -0
- package/dist/harness/tool-server.js +27 -0
- package/dist/harness/tool-server.js.map +1 -0
- package/dist/harness/types.d.ts +168 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +12 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/interview/App.d.ts +4 -2
- package/dist/interview/App.d.ts.map +1 -1
- package/dist/interview/App.js +36 -56
- package/dist/interview/App.js.map +1 -1
- package/dist/interview/index.d.ts +3 -0
- package/dist/interview/index.d.ts.map +1 -1
- package/dist/interview/index.js +1 -0
- package/dist/interview/index.js.map +1 -1
- package/dist/interview/prompts.d.ts +3 -1
- package/dist/interview/prompts.d.ts.map +1 -1
- package/dist/interview/prompts.js +5 -1
- package/dist/interview/prompts.js.map +1 -1
- package/dist/interview/ui/ChatBanner.d.ts +17 -0
- package/dist/interview/ui/ChatBanner.d.ts.map +1 -0
- package/dist/interview/ui/ChatBanner.js +30 -0
- package/dist/interview/ui/ChatBanner.js.map +1 -0
- package/dist/interview/ui/ChatInput.d.ts +36 -0
- package/dist/interview/ui/ChatInput.d.ts.map +1 -0
- package/dist/interview/ui/ChatInput.js +304 -0
- package/dist/interview/ui/ChatInput.js.map +1 -0
- package/dist/interview/ui/MarkdownText.d.ts +13 -0
- package/dist/interview/ui/MarkdownText.d.ts.map +1 -0
- package/dist/interview/ui/MarkdownText.js +107 -0
- package/dist/interview/ui/MarkdownText.js.map +1 -0
- package/dist/interview/ui/index.d.ts +3 -0
- package/dist/interview/ui/index.d.ts.map +1 -1
- package/dist/interview/ui/index.js +3 -0
- package/dist/interview/ui/index.js.map +1 -1
- package/dist/memento/implementer-agent.d.ts +31 -0
- package/dist/memento/implementer-agent.d.ts.map +1 -0
- package/dist/memento/implementer-agent.js +95 -0
- package/dist/memento/implementer-agent.js.map +1 -0
- package/dist/memento/index.d.ts +6 -5
- package/dist/memento/index.d.ts.map +1 -1
- package/dist/memento/index.js +7 -5
- package/dist/memento/index.js.map +1 -1
- package/dist/memento/loop.d.ts +6 -5
- package/dist/memento/loop.d.ts.map +1 -1
- package/dist/memento/loop.js +872 -180
- package/dist/memento/loop.js.map +1 -1
- package/dist/memento/matrix-animation.d.ts +26 -0
- package/dist/memento/matrix-animation.d.ts.map +1 -1
- package/dist/memento/matrix-animation.js +93 -18
- package/dist/memento/matrix-animation.js.map +1 -1
- package/dist/memento/nav-protocol.d.ts +2 -2
- package/dist/memento/nav-protocol.d.ts.map +1 -1
- package/dist/memento/nav-protocol.js +39 -43
- package/dist/memento/nav-protocol.js.map +1 -1
- package/dist/memento/prompts.d.ts +21 -8
- package/dist/memento/prompts.d.ts.map +1 -1
- package/dist/memento/prompts.js +79 -39
- package/dist/memento/prompts.js.map +1 -1
- package/dist/memento/rate-limit.d.ts +85 -0
- package/dist/memento/rate-limit.d.ts.map +1 -0
- package/dist/memento/rate-limit.js +221 -0
- package/dist/memento/rate-limit.js.map +1 -0
- package/dist/memento/types.d.ts +6 -6
- package/dist/memento/types.d.ts.map +1 -1
- package/dist/memento/types.js +3 -3
- package/dist/memento/worker-agent.d.ts +4 -1
- package/dist/memento/worker-agent.d.ts.map +1 -1
- package/dist/memento/worker-agent.js +38 -54
- package/dist/memento/worker-agent.js.map +1 -1
- package/dist/registry.d.ts +35 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +87 -0
- package/dist/registry.js.map +1 -0
- package/dist/repo-analyzer/index.d.ts +2 -1
- package/dist/repo-analyzer/index.d.ts.map +1 -1
- package/dist/repo-analyzer/index.js +6 -17
- package/dist/repo-analyzer/index.js.map +1 -1
- package/dist/skill-generator/index.d.ts +142 -0
- package/dist/skill-generator/index.d.ts.map +1 -0
- package/dist/skill-generator/index.js +510 -0
- package/dist/skill-generator/index.js.map +1 -0
- package/dist/standup/config.d.ts +19 -0
- package/dist/standup/config.d.ts.map +1 -0
- package/dist/standup/config.js +42 -0
- package/dist/standup/config.js.map +1 -0
- package/dist/standup/index.d.ts +24 -0
- package/dist/standup/index.d.ts.map +1 -0
- package/dist/standup/index.js +29 -0
- package/dist/standup/index.js.map +1 -0
- package/dist/standup/loop.d.ts +36 -0
- package/dist/standup/loop.d.ts.map +1 -0
- package/dist/standup/loop.js +508 -0
- package/dist/standup/loop.js.map +1 -0
- package/dist/standup/prompts.d.ts +62 -0
- package/dist/standup/prompts.d.ts.map +1 -0
- package/dist/standup/prompts.js +211 -0
- package/dist/standup/prompts.js.map +1 -0
- package/dist/standup/standup-protocol.d.ts +33 -0
- package/dist/standup/standup-protocol.d.ts.map +1 -0
- package/dist/standup/standup-protocol.js +189 -0
- package/dist/standup/standup-protocol.js.map +1 -0
- package/dist/standup/types.d.ts +185 -0
- package/dist/standup/types.d.ts.map +1 -0
- package/dist/standup/types.js +67 -0
- package/dist/standup/types.js.map +1 -0
- package/dist/templates/.gitignore.template +26 -0
- package/dist/templates/CLAUDE-pack.md.template +114 -0
- package/dist/templates/CLAUDE.md.template +153 -0
- package/dist/templates/README.md.template +174 -0
- package/dist/templates/config-pack.json.template +16 -0
- package/dist/templates/config.json.template +11 -0
- package/dist/templates/index.d.ts +22 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +32 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/plugins.json.template +33 -0
- package/dist/templates/system-configuration.md.template +70 -0
- package/dist/tools/cross-nav.d.ts +21 -0
- package/dist/tools/cross-nav.d.ts.map +1 -0
- package/dist/tools/cross-nav.js +93 -0
- package/dist/tools/cross-nav.js.map +1 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/related-navs-config.d.ts +15 -0
- package/dist/tools/related-navs-config.d.ts.map +1 -0
- package/dist/tools/related-navs-config.js +132 -0
- package/dist/tools/related-navs-config.js.map +1 -0
- package/dist/tools/related-navs.d.ts +23 -0
- package/dist/tools/related-navs.d.ts.map +1 -0
- package/dist/tools/related-navs.js +107 -0
- package/dist/tools/related-navs.js.map +1 -0
- package/dist/tools/response.d.ts +3 -2
- package/dist/tools/response.d.ts.map +1 -1
- package/dist/tools/response.js +7 -11
- package/dist/tools/response.js.map +1 -1
- package/dist/tools/self-config.d.ts +2 -1
- package/dist/tools/self-config.d.ts.map +1 -1
- package/dist/tools/self-config.js +5 -9
- package/dist/tools/self-config.js.map +1 -1
- package/package.json +4 -1
- package/dist/memento/state.d.ts +0 -56
- package/dist/memento/state.d.ts.map +0 -1
- package/dist/memento/state.js +0 -156
- package/dist/memento/state.js.map +0 -1
- package/dist/migrations/versions/v1.4.0-rfc2119-skills.d.ts +0 -18
- package/dist/migrations/versions/v1.4.0-rfc2119-skills.d.ts.map +0 -1
- package/dist/migrations/versions/v1.4.0-rfc2119-skills.js +0 -207
- package/dist/migrations/versions/v1.4.0-rfc2119-skills.js.map +0 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chibi Harness
|
|
3
|
+
*
|
|
4
|
+
* Adapts chibi-json into the universal Harness interface.
|
|
5
|
+
*
|
|
6
|
+
* chibi-json is stateless per invocation: each call reads ONE JSON object
|
|
7
|
+
* from stdin, executes the command, outputs JSONL to stdout, and exits.
|
|
8
|
+
* Multi-turn continuity comes from the named `context` — chibi persists
|
|
9
|
+
* conversation history on disk keyed by context name.
|
|
10
|
+
*
|
|
11
|
+
* Protocol (from `chibi-json --json-schema`):
|
|
12
|
+
* Input: { command: Command, context: string, project_root?: string, flags?: ExecutionFlags }
|
|
13
|
+
* Output: JSONL lines — transcript entries (entry_type: "message"|"tool_call"|"tool_result")
|
|
14
|
+
* and error objects (type: "error", message: string)
|
|
15
|
+
*
|
|
16
|
+
* Session lifecycle:
|
|
17
|
+
* 1. set_system_prompt (separate invocation, no output)
|
|
18
|
+
* 2. send_prompt (separate invocation, streams JSONL output)
|
|
19
|
+
* 3. For multi-turn: send_prompt again with same context name
|
|
20
|
+
*/
|
|
21
|
+
import type { Harness, HarnessSession, AgentConfig } from "./types.js";
|
|
22
|
+
import type { ToolDefinition } from "./tool-server.js";
|
|
23
|
+
/**
|
|
24
|
+
* Chibi Harness
|
|
25
|
+
*
|
|
26
|
+
* Creates sessions that delegate to chibi-json subprocess invocations.
|
|
27
|
+
* Each command is a separate process; context names provide multi-turn continuity.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ChibiHarness implements Harness {
|
|
30
|
+
readonly displayName = "chibi";
|
|
31
|
+
run(config: AgentConfig, prompt: string): HarnessSession;
|
|
32
|
+
createToolServer(name: string, tools: ToolDefinition[]): {
|
|
33
|
+
server: unknown;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=chibi-harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chibi-harness.d.ts","sourceRoot":"","sources":["../../src/harness/chibi-harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AASH,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAA6B,MAAM,YAAY,CAAC;AAClG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA+YvD;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,OAAO;IAC1C,QAAQ,CAAC,WAAW,WAAW;IAE/B,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc;IAIxD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE;CAY7E"}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chibi Harness
|
|
3
|
+
*
|
|
4
|
+
* Adapts chibi-json into the universal Harness interface.
|
|
5
|
+
*
|
|
6
|
+
* chibi-json is stateless per invocation: each call reads ONE JSON object
|
|
7
|
+
* from stdin, executes the command, outputs JSONL to stdout, and exits.
|
|
8
|
+
* Multi-turn continuity comes from the named `context` — chibi persists
|
|
9
|
+
* conversation history on disk keyed by context name.
|
|
10
|
+
*
|
|
11
|
+
* Protocol (from `chibi-json --json-schema`):
|
|
12
|
+
* Input: { command: Command, context: string, project_root?: string, flags?: ExecutionFlags }
|
|
13
|
+
* Output: JSONL lines — transcript entries (entry_type: "message"|"tool_call"|"tool_result")
|
|
14
|
+
* and error objects (type: "error", message: string)
|
|
15
|
+
*
|
|
16
|
+
* Session lifecycle:
|
|
17
|
+
* 1. set_system_prompt (separate invocation, no output)
|
|
18
|
+
* 2. send_prompt (separate invocation, streams JSONL output)
|
|
19
|
+
* 3. For multi-turn: send_prompt again with same context name
|
|
20
|
+
*/
|
|
21
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
22
|
+
import * as crypto from "node:crypto";
|
|
23
|
+
import * as fs from "node:fs";
|
|
24
|
+
import * as os from "node:os";
|
|
25
|
+
import * as path from "node:path";
|
|
26
|
+
import * as readline from "node:readline";
|
|
27
|
+
import { fileURLToPath } from "node:url";
|
|
28
|
+
import { createEphemeralHome } from "./ephemeral-home.js";
|
|
29
|
+
import { wrapCommand, isSandboxEnabled } from "./sandbox.js";
|
|
30
|
+
const CHIBI_TOOL_MARKER = "__chibi_tools__";
|
|
31
|
+
/**
|
|
32
|
+
* Build the chibi-json input object for a command.
|
|
33
|
+
*/
|
|
34
|
+
function buildInput(command, context, projectRoot, home) {
|
|
35
|
+
const input = { command, context };
|
|
36
|
+
if (projectRoot) {
|
|
37
|
+
input.project_root = projectRoot;
|
|
38
|
+
}
|
|
39
|
+
if (home) {
|
|
40
|
+
input.home = home;
|
|
41
|
+
}
|
|
42
|
+
return JSON.stringify(input);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Run a chibi-json command synchronously (for commands with no streaming output like set_system_prompt).
|
|
46
|
+
*/
|
|
47
|
+
function runSync(inputJson, opts) {
|
|
48
|
+
const { command, args } = wrapCommand("chibi-json", [], opts?.sandboxConfig);
|
|
49
|
+
execFileSync(command, args, {
|
|
50
|
+
input: inputJson,
|
|
51
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
52
|
+
timeout: 10_000,
|
|
53
|
+
env: opts?.env ? { ...process.env, ...opts.env } : undefined,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parse a chibi JSONL output line into AgentEvents.
|
|
58
|
+
*
|
|
59
|
+
* Chibi transcript entries have:
|
|
60
|
+
* - entry_type: "message" | "tool_call" | "tool_result"
|
|
61
|
+
* - from: sender name
|
|
62
|
+
* - to: context name
|
|
63
|
+
* - content: string (for messages) or structured data
|
|
64
|
+
*
|
|
65
|
+
* Error objects have:
|
|
66
|
+
* - type: "error"
|
|
67
|
+
* - message: string
|
|
68
|
+
*/
|
|
69
|
+
function parseChibiLine(line) {
|
|
70
|
+
const events = [];
|
|
71
|
+
try {
|
|
72
|
+
const data = JSON.parse(line);
|
|
73
|
+
// Error object
|
|
74
|
+
if (data.type === "error") {
|
|
75
|
+
events.push({
|
|
76
|
+
type: "error",
|
|
77
|
+
message: data.message || "Unknown chibi error",
|
|
78
|
+
});
|
|
79
|
+
return events;
|
|
80
|
+
}
|
|
81
|
+
// Transcript entries (from chibi's conversation log)
|
|
82
|
+
if (data.entry_type === "message") {
|
|
83
|
+
// Skip user messages (from="user"), only emit assistant responses
|
|
84
|
+
if (data.from !== "user" && data.content) {
|
|
85
|
+
events.push({ type: "text", text: data.content });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (data.entry_type === "tool_call") {
|
|
89
|
+
let input = {};
|
|
90
|
+
try {
|
|
91
|
+
input = typeof data.content === "string" ? JSON.parse(data.content) : (data.content || {});
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// content wasn't valid JSON — leave input empty
|
|
95
|
+
}
|
|
96
|
+
events.push({
|
|
97
|
+
type: "tool_use",
|
|
98
|
+
name: data.to || "unknown",
|
|
99
|
+
id: data.tool_call_id || data.id || "",
|
|
100
|
+
input,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else if (data.entry_type === "tool_result") {
|
|
104
|
+
events.push({
|
|
105
|
+
type: "tool_result",
|
|
106
|
+
toolUseId: data.tool_call_id || data.id || "",
|
|
107
|
+
content: typeof data.content === "string" ? data.content : JSON.stringify(data.content || ""),
|
|
108
|
+
isError: data.is_error === true,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Not valid JSON — ignore
|
|
114
|
+
}
|
|
115
|
+
return events;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Chibi harness session.
|
|
119
|
+
*
|
|
120
|
+
* Each prompt is a separate chibi-json invocation. The named context
|
|
121
|
+
* provides conversation continuity across invocations.
|
|
122
|
+
*/
|
|
123
|
+
class ChibiSession {
|
|
124
|
+
config;
|
|
125
|
+
contextName;
|
|
126
|
+
child = null;
|
|
127
|
+
closed = false;
|
|
128
|
+
registeredTools = new Map();
|
|
129
|
+
ephemeralHome = null;
|
|
130
|
+
sandboxConfig;
|
|
131
|
+
extraEnv = {};
|
|
132
|
+
sandboxDenials = [];
|
|
133
|
+
constructor(config, initialPrompt) {
|
|
134
|
+
this.config = { ...config };
|
|
135
|
+
this.contextName = `autonav-${crypto.randomUUID().slice(0, 8)}`;
|
|
136
|
+
// Create ephemeral home with all chibi plugins
|
|
137
|
+
this.ephemeralHome = createEphemeralHome({
|
|
138
|
+
harness: "chibi",
|
|
139
|
+
setup: (home) => {
|
|
140
|
+
// home_override IS the chibi_dir in AppState::load — files go at root level.
|
|
141
|
+
// Copy user config so chibi can authenticate with the LLM API.
|
|
142
|
+
const userConfig = path.join(os.homedir(), ".chibi", "config.toml");
|
|
143
|
+
if (fs.existsSync(userConfig)) {
|
|
144
|
+
fs.copyFileSync(userConfig, path.join(home, "config.toml"));
|
|
145
|
+
}
|
|
146
|
+
// Install all chibi plugins from the plugins directory
|
|
147
|
+
const pluginsDir = path.join(home, "plugins");
|
|
148
|
+
fs.mkdirSync(pluginsDir);
|
|
149
|
+
const srcDir = fileURLToPath(new URL("./chibi-plugins", import.meta.url));
|
|
150
|
+
if (fs.existsSync(srcDir)) {
|
|
151
|
+
for (const file of fs.readdirSync(srcDir)) {
|
|
152
|
+
const srcPath = path.join(srcDir, file);
|
|
153
|
+
if (fs.statSync(srcPath).isFile()) {
|
|
154
|
+
fs.copyFileSync(srcPath, path.join(pluginsDir, file));
|
|
155
|
+
fs.chmodSync(path.join(pluginsDir, file), 0o755);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
// Build extra env vars for plugin scripts
|
|
162
|
+
if (config.cwd) {
|
|
163
|
+
// Resolve plugins.json path relative to navigator directory
|
|
164
|
+
const pluginsPath = path.join(config.cwd, ".claude", "plugins.json");
|
|
165
|
+
if (fs.existsSync(pluginsPath)) {
|
|
166
|
+
this.extraEnv.AUTONAV_PLUGINS_PATH = pluginsPath;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// Cycle detection depth for cross-nav queries
|
|
170
|
+
const currentDepth = process.env.AUTONAV_QUERY_DEPTH || "0";
|
|
171
|
+
this.extraEnv.AUTONAV_QUERY_DEPTH = currentDepth;
|
|
172
|
+
// Build sandbox config from AgentConfig.sandbox + defaults
|
|
173
|
+
if (config.sandbox) {
|
|
174
|
+
this.sandboxConfig = { ...config.sandbox };
|
|
175
|
+
// Chibi makes its own API calls — never block network
|
|
176
|
+
this.sandboxConfig.blockNetwork = false;
|
|
177
|
+
// Merge paths: navigator dir (at least read), ephemeral home (always write)
|
|
178
|
+
const writeSet = new Set(this.sandboxConfig.writePaths || []);
|
|
179
|
+
if (this.ephemeralHome)
|
|
180
|
+
writeSet.add(this.ephemeralHome.homePath);
|
|
181
|
+
this.sandboxConfig.writePaths = [...writeSet];
|
|
182
|
+
// Only add cwd to readPaths if it's not already in writePaths (write implies read)
|
|
183
|
+
const readSet = new Set(this.sandboxConfig.readPaths || []);
|
|
184
|
+
if (config.cwd && !writeSet.has(config.cwd))
|
|
185
|
+
readSet.add(config.cwd);
|
|
186
|
+
this.sandboxConfig.readPaths = [...readSet];
|
|
187
|
+
// Debug: log sandbox status
|
|
188
|
+
if (process.env.AUTONAV_DEBUG === "1" && config.stderr) {
|
|
189
|
+
const active = isSandboxEnabled(this.sandboxConfig);
|
|
190
|
+
config.stderr(`[chibi] Sandbox: ${active ? "enabled (nono)" : "disabled"}\n`);
|
|
191
|
+
if (active) {
|
|
192
|
+
const { command, args } = wrapCommand("chibi-json", [], this.sandboxConfig);
|
|
193
|
+
config.stderr(`[chibi] Sandbox cmd: ${command} ${args.join(" ")}\n`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Extract chibi tool servers from mcpServers config
|
|
198
|
+
if (config.mcpServers) {
|
|
199
|
+
for (const serverObj of Object.values(config.mcpServers)) {
|
|
200
|
+
if (serverObj &&
|
|
201
|
+
typeof serverObj === "object" &&
|
|
202
|
+
CHIBI_TOOL_MARKER in serverObj) {
|
|
203
|
+
const chibiServer = serverObj;
|
|
204
|
+
for (const td of chibiServer.tools) {
|
|
205
|
+
this.registeredTools.set(td.name, td);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Set system prompt (separate synchronous invocation)
|
|
211
|
+
if (config.systemPrompt) {
|
|
212
|
+
const input = buildInput({ set_system_prompt: { prompt: config.systemPrompt } }, this.contextName, config.cwd, this.ephemeralHome.homePath);
|
|
213
|
+
try {
|
|
214
|
+
runSync(input, { env: this.extraEnv, sandboxConfig: this.sandboxConfig });
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
// Log but don't fail — system prompt is best-effort
|
|
218
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
219
|
+
if (config.stderr) {
|
|
220
|
+
config.stderr(`[chibi] Failed to set system prompt: ${msg}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Start the prompt invocation
|
|
225
|
+
this.child = this.spawnPrompt(initialPrompt);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Spawn a chibi-json process for a send_prompt command.
|
|
229
|
+
* Returns the child process whose stdout streams JSONL events.
|
|
230
|
+
*/
|
|
231
|
+
spawnPrompt(prompt) {
|
|
232
|
+
const inputJson = buildInput({ send_prompt: { prompt } }, this.contextName, this.config.cwd, this.ephemeralHome?.homePath);
|
|
233
|
+
const { command, args } = wrapCommand("chibi-json", [], this.sandboxConfig);
|
|
234
|
+
const child = spawn(command, args, {
|
|
235
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
236
|
+
env: { ...process.env, ...this.extraEnv },
|
|
237
|
+
});
|
|
238
|
+
// Write the single JSON input and close stdin
|
|
239
|
+
child.stdin?.write(inputJson);
|
|
240
|
+
child.stdin?.end();
|
|
241
|
+
// Handle stderr — always capture sandbox denials, forward rest to debug handler
|
|
242
|
+
if (child.stderr) {
|
|
243
|
+
const stderrHandler = this.config.stderr;
|
|
244
|
+
const sandboxActive = isSandboxEnabled(this.sandboxConfig);
|
|
245
|
+
child.stderr.on("data", (data) => {
|
|
246
|
+
const text = data.toString();
|
|
247
|
+
if (stderrHandler) {
|
|
248
|
+
stderrHandler(text);
|
|
249
|
+
}
|
|
250
|
+
// Surface sandbox denials as events even outside debug mode
|
|
251
|
+
if (sandboxActive && text.includes("nono:")) {
|
|
252
|
+
this.sandboxDenials.push(text.trim());
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return child;
|
|
257
|
+
}
|
|
258
|
+
async *[Symbol.asyncIterator]() {
|
|
259
|
+
if (!this.child || !this.child.stdout) {
|
|
260
|
+
throw new Error("Chibi process not started");
|
|
261
|
+
}
|
|
262
|
+
const rl = readline.createInterface({
|
|
263
|
+
input: this.child.stdout,
|
|
264
|
+
crlfDelay: Infinity,
|
|
265
|
+
});
|
|
266
|
+
let hasResult = false;
|
|
267
|
+
let lastText = "";
|
|
268
|
+
let hadError = false;
|
|
269
|
+
for await (const line of rl) {
|
|
270
|
+
if (!line.trim())
|
|
271
|
+
continue;
|
|
272
|
+
const events = parseChibiLine(line);
|
|
273
|
+
for (const event of events) {
|
|
274
|
+
if (event.type === "error") {
|
|
275
|
+
hadError = true;
|
|
276
|
+
}
|
|
277
|
+
if (event.type === "text") {
|
|
278
|
+
lastText = event.text;
|
|
279
|
+
}
|
|
280
|
+
// Intercept tool_use events for registered tools
|
|
281
|
+
// Note: chibi handles its own tool calls natively, but autonav-registered
|
|
282
|
+
// tools (submit_answer, self-config) need local interception.
|
|
283
|
+
// This won't work with stateless chibi-json — tool interception requires
|
|
284
|
+
// a long-running process. For now, yield the event and let the caller handle it.
|
|
285
|
+
yield event;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Surface sandbox denials so callers see what nono blocked
|
|
289
|
+
// These are informational — the process exit code determines success/failure
|
|
290
|
+
for (const denial of this.sandboxDenials) {
|
|
291
|
+
yield { type: "error", message: `[sandbox] ${denial}` };
|
|
292
|
+
}
|
|
293
|
+
this.sandboxDenials = [];
|
|
294
|
+
// Emit a synthetic result event based on process exit
|
|
295
|
+
if (!hasResult) {
|
|
296
|
+
const exitCode = await new Promise((resolve) => {
|
|
297
|
+
if (!this.child) {
|
|
298
|
+
resolve(null);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (this.child.exitCode !== null) {
|
|
302
|
+
resolve(this.child.exitCode);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
this.child.on("exit", (code) => resolve(code));
|
|
306
|
+
});
|
|
307
|
+
yield {
|
|
308
|
+
type: "result",
|
|
309
|
+
success: exitCode === 0 && !hadError,
|
|
310
|
+
text: lastText || (hadError ? "chibi-json returned an error" : ""),
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
send(prompt) {
|
|
315
|
+
if (this.closed) {
|
|
316
|
+
throw new Error("Session is closed");
|
|
317
|
+
}
|
|
318
|
+
// New invocation, same context name = multi-turn continuity
|
|
319
|
+
this.child = this.spawnPrompt(prompt);
|
|
320
|
+
const session = this;
|
|
321
|
+
return {
|
|
322
|
+
[Symbol.asyncIterator]() {
|
|
323
|
+
return session[Symbol.asyncIterator]();
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
updateConfig(config) {
|
|
328
|
+
Object.assign(this.config, config);
|
|
329
|
+
}
|
|
330
|
+
async close() {
|
|
331
|
+
this.closed = true;
|
|
332
|
+
if (this.child && this.child.exitCode === null) {
|
|
333
|
+
this.child.kill("SIGTERM");
|
|
334
|
+
await new Promise((resolve) => {
|
|
335
|
+
if (!this.child) {
|
|
336
|
+
resolve();
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
this.child.on("exit", () => resolve());
|
|
340
|
+
setTimeout(() => {
|
|
341
|
+
this.child?.kill("SIGKILL");
|
|
342
|
+
resolve();
|
|
343
|
+
}, 5000);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
// Clean up the context
|
|
347
|
+
try {
|
|
348
|
+
const destroyInput = buildInput({ destroy_context: { name: this.contextName } }, this.contextName, undefined, this.ephemeralHome?.homePath);
|
|
349
|
+
runSync(destroyInput, { env: this.extraEnv, sandboxConfig: this.sandboxConfig });
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
// Best-effort cleanup
|
|
353
|
+
}
|
|
354
|
+
// Clean up ephemeral home directory
|
|
355
|
+
this.ephemeralHome?.cleanup();
|
|
356
|
+
this.ephemeralHome = null;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Chibi Harness
|
|
361
|
+
*
|
|
362
|
+
* Creates sessions that delegate to chibi-json subprocess invocations.
|
|
363
|
+
* Each command is a separate process; context names provide multi-turn continuity.
|
|
364
|
+
*/
|
|
365
|
+
export class ChibiHarness {
|
|
366
|
+
displayName = "chibi";
|
|
367
|
+
run(config, prompt) {
|
|
368
|
+
return new ChibiSession(config, prompt);
|
|
369
|
+
}
|
|
370
|
+
createToolServer(name, tools) {
|
|
371
|
+
// Return a sentinel object that ChibiSession can detect and extract tools from.
|
|
372
|
+
// Note: Tool interception doesn't work with stateless chibi-json invocations.
|
|
373
|
+
// Tools registered here are yielded as events for the caller to handle.
|
|
374
|
+
return {
|
|
375
|
+
server: {
|
|
376
|
+
[CHIBI_TOOL_MARKER]: true,
|
|
377
|
+
name,
|
|
378
|
+
tools,
|
|
379
|
+
},
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
//# sourceMappingURL=chibi-harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chibi-harness.js","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B,CAAC,EAAE,IAAI;gBACzB,IAAI;gBACJ,KAAK;aACoB;SAC5B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# get_plugin_config chibi plugin
|
|
3
|
+
#
|
|
4
|
+
# Reads $AUTONAV_PLUGINS_PATH and returns plugin configuration.
|
|
5
|
+
|
|
6
|
+
set -euo pipefail
|
|
7
|
+
|
|
8
|
+
if [[ "${1:-}" == "--schema" ]]; then
|
|
9
|
+
printf '%s\n' '{' \
|
|
10
|
+
' "name": "get_plugin_config",' \
|
|
11
|
+
' "description": "Read your current plugin configuration. Use this to check what plugins are enabled, see notification settings, or verify your current schedule.",' \
|
|
12
|
+
' "parameters": {' \
|
|
13
|
+
' "type": "object",' \
|
|
14
|
+
' "properties": {' \
|
|
15
|
+
' "plugin": {' \
|
|
16
|
+
' "type": "string",' \
|
|
17
|
+
' "enum": ["slack", "signal", "github", "email", "all"],' \
|
|
18
|
+
' "description": "The plugin to read configuration for, or '\''all'\'' for everything"' \
|
|
19
|
+
' }' \
|
|
20
|
+
' },' \
|
|
21
|
+
' "required": ["plugin"]' \
|
|
22
|
+
' }' \
|
|
23
|
+
'}'
|
|
24
|
+
exit 0
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
# Read JSON args from stdin
|
|
28
|
+
input=$(cat)
|
|
29
|
+
plugin=$(echo "$input" | jq -r '.plugin // empty')
|
|
30
|
+
|
|
31
|
+
if [[ -z "$plugin" ]]; then
|
|
32
|
+
echo '{"success": false, "error": "Missing required field: plugin"}'
|
|
33
|
+
exit 0
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# Check env var
|
|
37
|
+
config_path="${AUTONAV_PLUGINS_PATH:-}"
|
|
38
|
+
if [[ -z "$config_path" ]]; then
|
|
39
|
+
echo '{"success": false, "error": "AUTONAV_PLUGINS_PATH not set. Plugin configuration unavailable."}'
|
|
40
|
+
exit 0
|
|
41
|
+
fi
|
|
42
|
+
|
|
43
|
+
if [[ ! -f "$config_path" ]]; then
|
|
44
|
+
echo '{"success": false, "error": "Plugin configuration file not found."}'
|
|
45
|
+
exit 0
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# Read and return config
|
|
49
|
+
config=$(cat "$config_path")
|
|
50
|
+
|
|
51
|
+
if [[ "$plugin" == "all" ]]; then
|
|
52
|
+
jq -n --argjson config "$config" \
|
|
53
|
+
'{"success": true, "plugin": "all", "config": $config}'
|
|
54
|
+
else
|
|
55
|
+
# Extract specific plugin section
|
|
56
|
+
section=$(echo "$config" | jq --arg p "$plugin" '.[$p] // null')
|
|
57
|
+
if [[ "$section" == "null" ]]; then
|
|
58
|
+
jq -n --arg p "$plugin" \
|
|
59
|
+
'{"success": true, "plugin": $p, "config": {"enabled": false, "config": {}}}'
|
|
60
|
+
else
|
|
61
|
+
jq -n --arg p "$plugin" --argjson section "$section" \
|
|
62
|
+
'{"success": true, "plugin": $p, "config": $section}'
|
|
63
|
+
fi
|
|
64
|
+
fi
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# query_navigator chibi plugin
|
|
3
|
+
#
|
|
4
|
+
# Queries another navigator by running chibi-json directly with the
|
|
5
|
+
# target's system prompt in a separate context. Chibi is naturally
|
|
6
|
+
# plural — one instance can be many navigators at once, each in its
|
|
7
|
+
# own context with no knowledge of the others.
|
|
8
|
+
#
|
|
9
|
+
# Flow: set_system_prompt → send_prompt → extract last assistant message → destroy_context
|
|
10
|
+
# Cycle detection via AUTONAV_QUERY_DEPTH env var (max 3).
|
|
11
|
+
|
|
12
|
+
set -euo pipefail
|
|
13
|
+
|
|
14
|
+
if [[ "${1:-}" == "--schema" ]]; then
|
|
15
|
+
printf '%s\n' '{' \
|
|
16
|
+
' "name": "query_navigator",' \
|
|
17
|
+
' "description": "Ask another navigator a question. Use this when you need information from a different navigator'\''s knowledge base. The target navigator will search its own knowledge and return an answer.",' \
|
|
18
|
+
' "parameters": {' \
|
|
19
|
+
' "type": "object",' \
|
|
20
|
+
' "properties": {' \
|
|
21
|
+
' "navigator": { "type": "string", "description": "Path to the target navigator directory (relative to cwd or absolute)" },' \
|
|
22
|
+
' "question": { "type": "string", "description": "The question to ask the target navigator" }' \
|
|
23
|
+
' },' \
|
|
24
|
+
' "required": ["navigator", "question"]' \
|
|
25
|
+
' }' \
|
|
26
|
+
'}'
|
|
27
|
+
exit 0
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
# Read JSON args from stdin
|
|
31
|
+
input=$(cat)
|
|
32
|
+
navigator=$(echo "$input" | jq -r '.navigator // empty')
|
|
33
|
+
question=$(echo "$input" | jq -r '.question // empty')
|
|
34
|
+
|
|
35
|
+
if [[ -z "$navigator" || -z "$question" ]]; then
|
|
36
|
+
echo '{"success": false, "error": "Missing required fields: navigator and question"}'
|
|
37
|
+
exit 0
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# Cycle detection
|
|
41
|
+
depth="${AUTONAV_QUERY_DEPTH:-0}"
|
|
42
|
+
if [[ "$depth" -ge 3 ]]; then
|
|
43
|
+
echo '{"success": false, "error": "Query depth limit reached (max 3). Cannot query another navigator from this depth."}'
|
|
44
|
+
exit 0
|
|
45
|
+
fi
|
|
46
|
+
export AUTONAV_QUERY_DEPTH=$(( depth + 1 ))
|
|
47
|
+
|
|
48
|
+
# Validate navigator directory
|
|
49
|
+
if [[ ! -d "$navigator" ]]; then
|
|
50
|
+
jq -n --arg p "$navigator" '{"success": false, "error": ("Navigator directory not found: " + $p)}'
|
|
51
|
+
exit 0
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
config_file="$navigator/config.json"
|
|
55
|
+
if [[ ! -f "$config_file" ]]; then
|
|
56
|
+
echo '{"success": false, "error": "Navigator config.json not found."}'
|
|
57
|
+
exit 0
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
nav_name=$(jq -r '.name // "unknown"' "$config_file")
|
|
61
|
+
instructions_path=$(jq -r '.instructionsPath // "CLAUDE.md"' "$config_file")
|
|
62
|
+
|
|
63
|
+
prompt_file="$navigator/$instructions_path"
|
|
64
|
+
if [[ ! -f "$prompt_file" ]]; then
|
|
65
|
+
jq -n --arg f "$instructions_path" '{"success": false, "error": ("Navigator instructions file not found: " + $f)}'
|
|
66
|
+
exit 0
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
system_prompt=$(cat "$prompt_file")
|
|
70
|
+
|
|
71
|
+
# Unique context for this sub-query (PID + random for collision avoidance)
|
|
72
|
+
ctx="autonav-xnav-$$-$(head -c 4 /dev/urandom | xxd -p)"
|
|
73
|
+
|
|
74
|
+
cleanup() {
|
|
75
|
+
# Destroy sub-query context (best-effort)
|
|
76
|
+
jq -n --arg ctx "$ctx" \
|
|
77
|
+
'{command: {destroy_context: {name: $ctx}}, context: $ctx}' \
|
|
78
|
+
| chibi-json 2>/dev/null || true
|
|
79
|
+
}
|
|
80
|
+
trap cleanup EXIT
|
|
81
|
+
|
|
82
|
+
# 1. Set system prompt on the sub-query context
|
|
83
|
+
jq -n \
|
|
84
|
+
--arg prompt "$system_prompt" \
|
|
85
|
+
--arg ctx "$ctx" \
|
|
86
|
+
--arg root "$navigator" \
|
|
87
|
+
'{command: {set_system_prompt: {prompt: $prompt}}, context: $ctx, project_root: $root}' \
|
|
88
|
+
| chibi-json 2>/dev/null || true
|
|
89
|
+
|
|
90
|
+
# 2. Send the question, capture JSONL output
|
|
91
|
+
response_jsonl=$(
|
|
92
|
+
jq -n \
|
|
93
|
+
--arg prompt "$question" \
|
|
94
|
+
--arg ctx "$ctx" \
|
|
95
|
+
--arg root "$navigator" \
|
|
96
|
+
'{command: {send_prompt: {prompt: $prompt}}, context: $ctx, project_root: $root}' \
|
|
97
|
+
| chibi-json 2>/dev/null
|
|
98
|
+
) || true
|
|
99
|
+
|
|
100
|
+
# 3. Extract the last assistant message from JSONL
|
|
101
|
+
response=""
|
|
102
|
+
if [[ -n "$response_jsonl" ]]; then
|
|
103
|
+
response=$(echo "$response_jsonl" \
|
|
104
|
+
| jq -rs '[.[] | select(.entry_type == "message" and .from != "user") | .content] | last // ""')
|
|
105
|
+
fi
|
|
106
|
+
|
|
107
|
+
# 4. Return structured result (cleanup runs via trap)
|
|
108
|
+
if [[ -n "$response" && "$response" != "null" && "$response" != '""' ]]; then
|
|
109
|
+
jq -n --arg nav "$nav_name" --arg resp "$response" \
|
|
110
|
+
'{"success": true, "navigator": $nav, "response": $resp}'
|
|
111
|
+
else
|
|
112
|
+
jq -n --arg nav "$nav_name" \
|
|
113
|
+
'{"success": false, "navigator": $nav, "error": "Navigator returned empty response."}'
|
|
114
|
+
fi
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# submit_answer chibi plugin
|
|
3
|
+
#
|
|
4
|
+
# Provides the submit_answer tool to chibi so the LLM can call it with
|
|
5
|
+
# structured args. The adapter captures the tool_call event from JSONL
|
|
6
|
+
# output — this script just needs to exist and declare the schema.
|
|
7
|
+
|
|
8
|
+
if [[ "$1" == "--schema" ]]; then
|
|
9
|
+
printf '%s\n' '{' \
|
|
10
|
+
' "name": "submit_answer",' \
|
|
11
|
+
' "description": "Submit your final answer. You MUST use this tool to provide your response with proper source citations.",' \
|
|
12
|
+
' "parameters": {' \
|
|
13
|
+
' "type": "object",' \
|
|
14
|
+
' "properties": {' \
|
|
15
|
+
' "answer": { "type": "string", "description": "Your complete answer grounded in the knowledge base." },' \
|
|
16
|
+
' "sources": {' \
|
|
17
|
+
' "type": "array",' \
|
|
18
|
+
' "items": {' \
|
|
19
|
+
' "type": "object",' \
|
|
20
|
+
' "properties": {' \
|
|
21
|
+
' "file": { "type": "string" },' \
|
|
22
|
+
' "section": { "type": "string" },' \
|
|
23
|
+
' "relevance": { "type": "string" }' \
|
|
24
|
+
' },' \
|
|
25
|
+
' "required": ["file", "section", "relevance"]' \
|
|
26
|
+
' }' \
|
|
27
|
+
' },' \
|
|
28
|
+
' "confidence": { "type": "number", "minimum": 0, "maximum": 1, "description": "Confidence score from 0.0 (no confidence) to 1.0 (fully confident). 0.9+ = high, 0.45-0.89 = medium, below 0.45 = low." },' \
|
|
29
|
+
' "confidenceReason": { "type": "string" },' \
|
|
30
|
+
' "outOfDomain": { "type": "boolean" }' \
|
|
31
|
+
' },' \
|
|
32
|
+
' "required": ["answer", "sources", "confidence", "confidenceReason", "outOfDomain"]' \
|
|
33
|
+
' }' \
|
|
34
|
+
'}'
|
|
35
|
+
exit 0
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
echo "Answer submitted successfully."
|