@knightcodeai/cli 0.17.4 → 0.18.1
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/CHANGELOG.md +1303 -0
- package/README.md +2 -2
- package/dist/bundle/chunks/anthropic-messages-A2IH2IY3.js +6 -0
- package/dist/bundle/chunks/anthropic.js +101 -0
- package/dist/bundle/chunks/azure-openai-responses-XZILQZOG.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +89 -0
- package/dist/bundle/chunks/chunk-253N4337.js +7 -0
- package/dist/bundle/chunks/chunk-2QIKI63P.js +108 -0
- package/dist/bundle/chunks/chunk-3LX7U45C.js +130 -0
- package/dist/bundle/chunks/chunk-4CRI7BMY.js +2 -0
- package/dist/bundle/chunks/chunk-57BPR4HF.js +2 -0
- package/dist/bundle/chunks/chunk-A5LJINMT.js +2 -0
- package/dist/bundle/chunks/chunk-AANBXVWQ.js +2 -0
- package/dist/bundle/chunks/chunk-AHB7JV5B.js +2 -0
- package/dist/bundle/chunks/chunk-B2FT7RH5.js +2 -0
- package/dist/bundle/chunks/chunk-BPNRVFVQ.js +2 -0
- package/dist/bundle/chunks/chunk-BRKUE2MD.js +2 -0
- package/dist/bundle/chunks/chunk-BXZL5C3N.js +58 -0
- package/dist/bundle/chunks/chunk-DGACKL4S.js +30 -0
- package/dist/bundle/chunks/chunk-DKOURXGU.js +2 -0
- package/dist/bundle/chunks/chunk-DVFCXHT4.js +2 -0
- package/dist/bundle/chunks/chunk-ETOMYYZC.js +2 -0
- package/dist/bundle/chunks/chunk-FA32X2UJ.js +7 -0
- package/dist/bundle/chunks/chunk-FHM6KUY3.js +44 -0
- package/dist/bundle/chunks/chunk-FO7CEQB3.js +11 -0
- package/dist/bundle/chunks/chunk-FXS5MU6B.js +2 -0
- package/dist/bundle/chunks/chunk-HHWP56PR.js +2 -0
- package/dist/bundle/chunks/chunk-HSL72VZI.js +2 -0
- package/dist/bundle/chunks/chunk-HUQB436V.js +2 -0
- package/dist/bundle/chunks/chunk-HWXGL4YB.js +2 -0
- package/dist/bundle/chunks/chunk-KQKUEQJA.js +6 -0
- package/dist/bundle/chunks/chunk-LROWZ6UF.js +1333 -0
- package/dist/bundle/chunks/chunk-MOALMQWH.js +9 -0
- package/dist/bundle/chunks/chunk-MXIWLMNT.js +8 -0
- package/dist/bundle/chunks/chunk-N6VDWLND.js +2 -0
- package/dist/bundle/chunks/chunk-NCIBB66G.js +2 -0
- package/dist/bundle/chunks/chunk-NDQ5OW6U.js +2 -0
- package/dist/bundle/chunks/chunk-O6JSP6YG.js +6 -0
- package/dist/bundle/chunks/chunk-OFST7FDG.js +2 -0
- package/dist/bundle/chunks/chunk-SPAUY3RD.js +12 -0
- package/dist/bundle/chunks/chunk-UZWP3NHW.js +2 -0
- package/dist/bundle/chunks/chunk-V5ANFNKF.js +11 -0
- package/dist/bundle/chunks/chunk-VJJ6J35N.js +20 -0
- package/dist/bundle/chunks/chunk-ZW7FVRHT.js +31 -0
- package/dist/bundle/chunks/cli-DFJTSQI6.js +51 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-6E2UM7IG.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +478 -0
- package/dist/bundle/chunks/dist-DKI7Q6GY.js +13 -0
- package/dist/bundle/chunks/easter-egg-3d-7O2AHLAQ.js +2 -0
- package/dist/bundle/chunks/execute-4CLOTQIS.js +499 -0
- package/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/bundle/chunks/google-generative-ai-CSWR3ORZ.js +2 -0
- package/dist/bundle/chunks/google-vertex-QIDRFOFB.js +2 -0
- package/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/bundle/chunks/jiti-loader-BXVX3Y2R.js +21 -0
- package/dist/bundle/chunks/jiti-static-loader-NNBCFAO5.js +2 -0
- package/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/bundle/chunks/knightcode-messages-3GNOTMSI.js +8 -0
- package/dist/bundle/chunks/lib-IHWMWJDR.js +9 -0
- package/dist/bundle/chunks/llama-cpp-classify-HRPRKOZA.js +22 -0
- package/dist/bundle/chunks/meta.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-46TK5OBA.js +5 -0
- package/dist/bundle/chunks/multipart-parser-VTTMF2EO.js +3 -0
- package/dist/bundle/chunks/node-7S3GFMOZ.js +16 -0
- package/dist/bundle/chunks/node-MAEICQNS.js +2 -0
- package/dist/bundle/chunks/openai-chatgpt.js +101 -0
- package/dist/bundle/chunks/openai-codex-responses-IT7VEKUU.js +10 -0
- package/dist/bundle/chunks/openai-codex.js +101 -0
- package/dist/bundle/chunks/openai-completions-LOKIW33V.js +7 -0
- package/dist/bundle/chunks/openai-decisions-4F3LWHMG.js +5 -0
- package/dist/bundle/chunks/openai-responses-OK36GJXP.js +3 -0
- package/dist/bundle/chunks/openrouter-images-ZI7LLZ4Y.js +2 -0
- package/dist/bundle/chunks/openrouter.js +101 -0
- package/dist/bundle/chunks/radius.js +101 -0
- package/dist/bundle/chunks/runtime-IN7ZPKFY.js +2 -0
- package/dist/bundle/chunks/src-ETRMT73D.js +4 -0
- package/dist/bundle/chunks/typesafe-system-one-J2CJBWEH.js +2 -0
- package/dist/bundle/chunks/virtual-modules-7VXI3TVN.js +2 -0
- package/dist/bundle/chunks/xai.js +2 -0
- package/dist/bundle/cli-runtime.js +3 -0
- package/dist/bundle/cli.js +16 -0
- package/dist/bundle/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/dist/bundle/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/dist/bundle/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
- package/dist/bundle/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
- package/dist/bundle/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
- package/dist/bundle/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
- package/dist/core/export-html/template.css +1015 -0
- package/dist/core/export-html/template.html +55 -0
- package/dist/core/export-html/template.js +1929 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked.min.js +78 -0
- package/dist/modes/interactive/theme/dark.json +74 -0
- package/dist/modes/interactive/theme/light.json +74 -0
- package/dist/modes/interactive/theme/system-theme.ts +579 -0
- package/dist/modes/interactive/theme/theme-controller.ts +253 -0
- package/dist/modes/interactive/theme/theme-schema.ts +145 -0
- package/dist/modes/interactive/theme/theme-tokens.ts +145 -0
- package/dist/modes/interactive/theme/theme.ts +1076 -0
- package/docs/app-server.md +479 -0
- package/docs/app-server.schema.json +8128 -0
- package/docs/cli-integration.md +106 -0
- package/docs/cli.md +393 -0
- package/docs/codemode.md +230 -0
- package/docs/compaction.md +463 -0
- package/docs/configuration.md +48 -0
- package/docs/containerization.md +143 -0
- package/docs/custom-provider.md +225 -0
- package/docs/desktop.md +73 -0
- package/docs/docs.json +236 -0
- package/docs/environment-variables.md +138 -0
- package/docs/extensions.md +420 -0
- package/docs/how-knightcode-works.md +49 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +39 -0
- package/docs/json.md +226 -0
- package/docs/keybindings.md +197 -0
- package/docs/llama-cpp.md +121 -0
- package/docs/mcp.md +272 -0
- package/docs/message-types.md +279 -0
- package/docs/models-configuration.md +187 -0
- package/docs/models.md +221 -0
- package/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/docs/packages.md +129 -0
- package/docs/plan-mode.md +121 -0
- package/docs/prompt-templates.md +59 -0
- package/docs/providers.md +282 -0
- package/docs/quickstart.md +128 -0
- package/docs/remote.md +87 -0
- package/docs/rpc-commands.md +860 -0
- package/docs/rpc-extension-ui.md +214 -0
- package/docs/rpc.md +193 -0
- package/docs/sdk.md +197 -0
- package/docs/security.md +99 -0
- package/docs/session-format.md +358 -0
- package/docs/sessions.md +135 -0
- package/docs/settings.md +220 -0
- package/docs/shell-aliases.md +93 -0
- package/docs/skills.md +93 -0
- package/docs/slash-commands.md +78 -0
- package/docs/terminal-setup.md +242 -0
- package/docs/termux.md +117 -0
- package/docs/themes.md +140 -0
- package/docs/tmux.md +55 -0
- package/docs/tui.md +195 -0
- package/docs/usage.md +167 -0
- package/docs/virtual-models.md +114 -0
- package/docs/windows.md +67 -0
- package/examples/README.md +36 -0
- package/examples/extensions/README.md +214 -0
- package/examples/extensions/auto-commit-on-exit.ts +55 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +151 -0
- package/examples/extensions/built-in-tool-renderer.ts +225 -0
- package/examples/extensions/claude-rules.ts +89 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +60 -0
- package/examples/extensions/custom-compaction.ts +118 -0
- package/examples/extensions/custom-footer.ts +66 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +617 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +399 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/debug-provider.ts +90 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_knightcode.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +75 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/entry-renderer.ts +41 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/gondolin/index.ts +531 -0
- package/examples/extensions/gondolin/package-lock.json +185 -0
- package/examples/extensions/gondolin/package.json +19 -0
- package/examples/extensions/handoff.ts +190 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform-streaming.ts +39 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/jev-router.ts +113 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +353 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +57 -0
- package/examples/extensions/overlay-qa-tests.ts +1450 -0
- package/examples/extensions/overlay-test.ts +153 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +66 -0
- package/examples/extensions/plan-mode/index.ts +387 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +436 -0
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +49 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +118 -0
- package/examples/extensions/question.ts +278 -0
- package/examples/extensions/questionnaire.ts +440 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +321 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +177 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +157 -0
- package/examples/extensions/subagent/index.ts +1010 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +199 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1004 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +294 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +121 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/rpc-client.ts +35 -0
- package/examples/rpc-extension-ui.ts +661 -0
- package/examples/sdk/01-minimal.ts +26 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +70 -0
- package/examples/sdk/04-skills.ts +55 -0
- package/examples/sdk/05-tools.ts +48 -0
- package/examples/sdk/06-extensions.ts +94 -0
- package/examples/sdk/07-context-files.ts +42 -0
- package/examples/sdk/08-prompt-templates.ts +51 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
- package/examples/sdk/10-settings.ts +53 -0
- package/examples/sdk/11-sessions.ts +52 -0
- package/examples/sdk/12-full-control.ts +74 -0
- package/examples/sdk/13-session-runtime.ts +67 -0
- package/examples/sdk/14-codemode-mcp.ts +61 -0
- package/examples/sdk/README.md +141 -0
- package/package.json +15 -15
- package/bin/knightcode +0 -62
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codemode, Tool Search, and MCP
|
|
3
|
+
*
|
|
4
|
+
* The CLI loads `codemode`, `tool_search`, and MCP as built-in extensions. SDK sessions add
|
|
5
|
+
* them to the resource loader's extension factories.
|
|
6
|
+
*
|
|
7
|
+
* `codemode` and `tool_search` are registered inactive. Enable them through the `defaultTools` setting
|
|
8
|
+
* (`tools` would also restrict the session to the named tools, which hides MCP tools), or let the
|
|
9
|
+
* MCP extension activate them: `codemode` for servers with `codemode` exposure, `tool_search` for
|
|
10
|
+
* servers with `deferred` exposure.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
createAgentSession,
|
|
15
|
+
createCodemodeExtension,
|
|
16
|
+
createMcpExtension,
|
|
17
|
+
createToolSearchExtension,
|
|
18
|
+
DefaultResourceLoader,
|
|
19
|
+
getAgentDir,
|
|
20
|
+
SessionManager,
|
|
21
|
+
SettingsManager,
|
|
22
|
+
} from "@knightcodeai/cli";
|
|
23
|
+
|
|
24
|
+
const cwd = process.cwd();
|
|
25
|
+
|
|
26
|
+
const resourceLoader = new DefaultResourceLoader({
|
|
27
|
+
cwd,
|
|
28
|
+
agentDir: getAgentDir(),
|
|
29
|
+
extensionFactories: [
|
|
30
|
+
createCodemodeExtension({ mode: "on" }),
|
|
31
|
+
createToolSearchExtension(),
|
|
32
|
+
// Reads mcp.json from the agent directory and the trusted project, like the CLI.
|
|
33
|
+
createMcpExtension(),
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
await resourceLoader.reload();
|
|
37
|
+
|
|
38
|
+
const settingsManager = SettingsManager.create(cwd);
|
|
39
|
+
// `+name` adds to the configured default tools instead of replacing them.
|
|
40
|
+
settingsManager.applyOverrides({ defaultTools: ["+codemode", "+tool_search"] });
|
|
41
|
+
|
|
42
|
+
const { session } = await createAgentSession({
|
|
43
|
+
resourceLoader,
|
|
44
|
+
settingsManager,
|
|
45
|
+
sessionManager: SessionManager.inMemory(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
// Emits session_start, which connects the MCP servers in the background.
|
|
50
|
+
await session.bindExtensions({});
|
|
51
|
+
console.log("Active tools:", session.getActiveToolNames().join(", "));
|
|
52
|
+
session.subscribe((event) => {
|
|
53
|
+
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
|
54
|
+
process.stdout.write(event.assistantMessageEvent.delta);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
await session.prompt("Use codemode to count the TypeScript files in src/ and list the three largest.");
|
|
58
|
+
console.log();
|
|
59
|
+
} finally {
|
|
60
|
+
session.dispose();
|
|
61
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# SDK Examples
|
|
2
|
+
|
|
3
|
+
Programmatic usage of @knightcodeai/cli via `createAgentSession()` and `createAgentSessionRuntime()`.
|
|
4
|
+
|
|
5
|
+
The runtime example shows how to build a recreate function that closes over process-global fixed inputs and recreates cwd-bound services and sessions as the active session cwd changes.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
| File | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
| `01-minimal.ts` | Simplest usage with all defaults |
|
|
12
|
+
| `02-custom-model.ts` | Select model and thinking level |
|
|
13
|
+
| `03-custom-prompt.ts` | Replace or modify system prompt |
|
|
14
|
+
| `04-skills.ts` | Discover, filter, or replace skills |
|
|
15
|
+
| `05-tools.ts` | Built-in tool allowlists |
|
|
16
|
+
| `06-extensions.ts` | Logging, blocking, result modification |
|
|
17
|
+
| `07-context-files.ts` | AGENTS.md context files |
|
|
18
|
+
| `08-prompt-templates.ts` | File-based prompt templates |
|
|
19
|
+
| `09-api-keys-and-oauth.ts` | API key resolution, OAuth config |
|
|
20
|
+
| `10-settings.ts` | Override compaction, retry, terminal settings |
|
|
21
|
+
| `11-sessions.ts` | In-memory, persistent, continue, list sessions |
|
|
22
|
+
| `12-full-control.ts` | Replace everything, no discovery |
|
|
23
|
+
| `13-session-runtime.ts` | Manage runtime-backed session replacement |
|
|
24
|
+
| `14-codemode-mcp.ts` | Add the `codemode`, `tool_search`, and MCP extensions |
|
|
25
|
+
|
|
26
|
+
## Running
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
cd packages/cli
|
|
30
|
+
bun examples/sdk/01-minimal.ts
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Reference
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { getModel } from "@knightcode/ai";
|
|
37
|
+
import {
|
|
38
|
+
createAgentSession,
|
|
39
|
+
DefaultResourceLoader,
|
|
40
|
+
ModelRuntime,
|
|
41
|
+
SessionManager,
|
|
42
|
+
SettingsManager,
|
|
43
|
+
} from "@knightcodeai/cli";
|
|
44
|
+
|
|
45
|
+
const modelRuntime = await ModelRuntime.create();
|
|
46
|
+
|
|
47
|
+
// Minimal
|
|
48
|
+
const { session } = await createAgentSession({ modelRuntime });
|
|
49
|
+
|
|
50
|
+
// Custom model
|
|
51
|
+
const model = getModel("anthropic", "claude-opus-4-5");
|
|
52
|
+
const { session } = await createAgentSession({ model, thinkingLevel: "high", modelRuntime });
|
|
53
|
+
|
|
54
|
+
// Modify prompt
|
|
55
|
+
const loader = new DefaultResourceLoader({
|
|
56
|
+
systemPromptOverride: (base) => `${base}\n\nBe concise.`,
|
|
57
|
+
});
|
|
58
|
+
await loader.reload();
|
|
59
|
+
const { session } = await createAgentSession({ resourceLoader: loader, modelRuntime });
|
|
60
|
+
|
|
61
|
+
// Read-only
|
|
62
|
+
const { session } = await createAgentSession({ tools: ["read", "grep", "find", "ls"], modelRuntime });
|
|
63
|
+
|
|
64
|
+
// In-memory
|
|
65
|
+
const { session } = await createAgentSession({
|
|
66
|
+
sessionManager: SessionManager.inMemory(),
|
|
67
|
+
modelRuntime,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Full control
|
|
71
|
+
const customRuntime = await ModelRuntime.create({
|
|
72
|
+
authPath: "/my/app/auth.json",
|
|
73
|
+
modelsPath: "/my/app/models.json",
|
|
74
|
+
});
|
|
75
|
+
await customRuntime.setRuntimeApiKey("anthropic", process.env.MY_KEY!);
|
|
76
|
+
|
|
77
|
+
const resourceLoader = new DefaultResourceLoader({
|
|
78
|
+
systemPromptOverride: () => "You are helpful.",
|
|
79
|
+
extensionFactories: [myExtension],
|
|
80
|
+
skillsOverride: () => ({ skills: [], diagnostics: [] }),
|
|
81
|
+
agentsFilesOverride: () => ({ agentsFiles: [] }),
|
|
82
|
+
promptsOverride: () => ({ prompts: [], diagnostics: [] }),
|
|
83
|
+
});
|
|
84
|
+
await resourceLoader.reload();
|
|
85
|
+
|
|
86
|
+
const { session } = await createAgentSession({
|
|
87
|
+
model,
|
|
88
|
+
modelRuntime: customRuntime,
|
|
89
|
+
resourceLoader,
|
|
90
|
+
tools: ["read", "bash", "my_tool"],
|
|
91
|
+
customTools: [myTool],
|
|
92
|
+
sessionManager: SessionManager.inMemory(),
|
|
93
|
+
settingsManager: SettingsManager.inMemory(),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Run prompts
|
|
97
|
+
session.subscribe((event) => {
|
|
98
|
+
if (event.type === "message_update" && event.assistantMessageEvent.type === "text_delta") {
|
|
99
|
+
process.stdout.write(event.assistantMessageEvent.delta);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
await session.prompt("Hello");
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Options
|
|
106
|
+
|
|
107
|
+
| Option | Default | Description |
|
|
108
|
+
|--------|---------|-------------|
|
|
109
|
+
| `modelRuntime` | Runtime using `agentDir/auth.json` and `models.json` | Canonical model and authentication runtime |
|
|
110
|
+
| `cwd` | `process.cwd()` | Working directory |
|
|
111
|
+
| `agentDir` | `~/.knightcode/agent` | Config directory |
|
|
112
|
+
| `model` | From settings/first available | Model to use |
|
|
113
|
+
| `thinkingLevel` | From settings/"off" | off, low, medium, high |
|
|
114
|
+
| `tools` | `["read", "bash", "edit", "write"]` built-ins | Allowlist tool names across built-in, extension, and custom tools |
|
|
115
|
+
| `customTools` | `[]` | Additional tool definitions |
|
|
116
|
+
| `resourceLoader` | DefaultResourceLoader | Resource loader for extensions, skills, prompts, themes, and context files |
|
|
117
|
+
| `sessionManager` | `SessionManager.create(cwd)` | Persistence |
|
|
118
|
+
| `settingsManager` | `SettingsManager.create(cwd, agentDir)` | Settings overrides |
|
|
119
|
+
|
|
120
|
+
## Events
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
session.subscribe((event) => {
|
|
124
|
+
switch (event.type) {
|
|
125
|
+
case "message_update":
|
|
126
|
+
if (event.assistantMessageEvent.type === "text_delta") {
|
|
127
|
+
process.stdout.write(event.assistantMessageEvent.delta);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case "tool_execution_start":
|
|
131
|
+
console.log(`Tool: ${event.toolName}`);
|
|
132
|
+
break;
|
|
133
|
+
case "tool_execution_end":
|
|
134
|
+
console.log(`Result: ${event.result}`);
|
|
135
|
+
break;
|
|
136
|
+
case "agent_settled":
|
|
137
|
+
console.log("Done");
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knightcodeai/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "KnightCode — a local, BYOK terminal coding agent powered by OpenRouter.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"configDir": ".knightcode"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"knightcode": "./
|
|
16
|
+
"knightcode": "./dist/bundle/cli.js"
|
|
17
17
|
},
|
|
18
18
|
"main": "./src/index.ts",
|
|
19
19
|
"types": "./src/index.ts",
|
|
@@ -24,35 +24,37 @@
|
|
|
24
24
|
"./*": "./src/*.ts"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"dist/",
|
|
28
|
+
"docs/",
|
|
29
|
+
"examples/",
|
|
30
|
+
"README.md",
|
|
31
|
+
"CHANGELOG.md"
|
|
29
32
|
],
|
|
30
33
|
"engines": {
|
|
31
|
-
"node": ">=22"
|
|
34
|
+
"node": ">=22.19.0"
|
|
32
35
|
},
|
|
33
36
|
"scripts": {
|
|
34
37
|
"dev": "bun --env-file=../../.env run --watch src/bun/cli.ts",
|
|
35
38
|
"start": "bun --env-file=../../.env run src/bun/cli.ts",
|
|
36
39
|
"check-types": "tsc --noEmit -p ../../tsconfig.json",
|
|
37
40
|
"test": "vitest --run",
|
|
38
|
-
"generate:schemas": "bun scripts/generate-schemas.ts"
|
|
41
|
+
"generate:schemas": "bun scripts/generate-schemas.ts",
|
|
42
|
+
"generate:references": "bun scripts/generate-references.ts"
|
|
39
43
|
},
|
|
40
|
-
"
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"@knightcodeai/cli-darwin-arm64": "0.17.4",
|
|
45
|
-
"@knightcodeai/cli-win32-x64": "0.17.4"
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@silvia-odwyer/photon-node": "0.3.4",
|
|
46
|
+
"jiti": "2.7.0",
|
|
47
|
+
"quickjs-wasi": "3.6.2"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
50
|
"@knightcode/agent": "workspace:*",
|
|
49
51
|
"@knightcode/ai": "workspace:*",
|
|
52
|
+
"@knightcode/app-server-protocol": "workspace:*",
|
|
50
53
|
"@knightcode/codemode": "workspace:*",
|
|
51
54
|
"@knightcode/mcp": "workspace:*",
|
|
52
55
|
"@knightcode/remote": "workspace:*",
|
|
53
56
|
"@knightcode/tools": "workspace:*",
|
|
54
57
|
"@knightcode/tui": "workspace:*",
|
|
55
|
-
"@silvia-odwyer/photon-node": "0.3.4",
|
|
56
58
|
"@types/cross-spawn": "6.0.6",
|
|
57
59
|
"@types/hosted-git-info": "3.0.5",
|
|
58
60
|
"@types/proper-lockfile": "4.1.4",
|
|
@@ -65,11 +67,9 @@
|
|
|
65
67
|
"highlight.js": "10.7.3",
|
|
66
68
|
"hosted-git-info": "9.0.3",
|
|
67
69
|
"ignore": "7.0.8",
|
|
68
|
-
"jiti": "2.7.0",
|
|
69
70
|
"marked": "18.0.11",
|
|
70
71
|
"minimatch": "10.2.6",
|
|
71
72
|
"proper-lockfile": "4.1.2",
|
|
72
|
-
"quickjs-wasi": "3.6.2",
|
|
73
73
|
"semver": "7.8.5",
|
|
74
74
|
"typebox": "1.3.27",
|
|
75
75
|
"undici": "8.10.2",
|
package/bin/knightcode
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Dependency-free launcher: resolves the platform-specific compiled binary
|
|
3
|
-
// (shipped as an optional dependency) and spawns it, forwarding args, stdio,
|
|
4
|
-
// signals, and the exit code. Uses only Node builtins.
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
6
|
-
import { createRequire } from "node:module";
|
|
7
|
-
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
9
|
-
|
|
10
|
-
const forwardedSignals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
11
|
-
|
|
12
|
-
function run(target) {
|
|
13
|
-
const child = spawn(target, process.argv.slice(2), {
|
|
14
|
-
stdio: "inherit",
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
child.on("error", (error) => {
|
|
18
|
-
console.error(error.message);
|
|
19
|
-
process.exit(1);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const forwarders = {};
|
|
23
|
-
for (const signal of forwardedSignals) {
|
|
24
|
-
forwarders[signal] = () => {
|
|
25
|
-
try {
|
|
26
|
-
child.kill(signal);
|
|
27
|
-
} catch {
|
|
28
|
-
// The child may have already exited.
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
process.on(signal, forwarders[signal]);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
child.on("exit", (code, signal) => {
|
|
35
|
-
for (const s of forwardedSignals) process.removeListener(s, forwarders[s]);
|
|
36
|
-
if (signal) {
|
|
37
|
-
process.kill(process.pid, signal);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
process.exit(typeof code === "number" ? code : 0);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const pkg = `@knightcodeai/cli-${process.platform}-${process.arch}`;
|
|
45
|
-
const binary = process.platform === "win32" ? "knightcode.exe" : "knightcode";
|
|
46
|
-
|
|
47
|
-
let target = process.env.KNIGHTCODE_BIN_PATH;
|
|
48
|
-
if (!target) {
|
|
49
|
-
try {
|
|
50
|
-
target = require.resolve(`${pkg}/bin/${binary}`);
|
|
51
|
-
} catch {
|
|
52
|
-
console.error(
|
|
53
|
-
`knightcode: no prebuilt binary for ${process.platform}-${process.arch}.\n` +
|
|
54
|
-
`Your package manager may have skipped the optional dependency "${pkg}".\n` +
|
|
55
|
-
`Reinstall the CLI with your package manager (npm, yarn, pnpm, or bun), ` +
|
|
56
|
-
`or set KNIGHTCODE_BIN_PATH to a local knightcode binary.`,
|
|
57
|
-
);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
run(target);
|