@kabmo-labs/kabmo 0.23.0 → 0.24.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/dist/client/index.html +1 -1
- package/dist/client/index.js +679 -679
- package/dist/client/static/js/{index-ph0q59rs.js → index-jcr5twtp.js} +769 -767
- package/dist/client/static/js/index-z3w7n85q.css +1 -0
- package/package.json +1 -1
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +23 -7
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +27 -11
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/index.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- package/src/client/data/settings/omp-schema.json +4 -4
- package/src/client/hooks/chat/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +17 -0
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -3
- package/src/client/hooks/chat/timeline/send.test-util.ts +1 -1
- package/src/client/hooks/chat/timeline/send.test.ts +1 -3
- package/src/client/hooks/chat/timeline/send.ts +8 -3
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +10 -3
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/tailwind.css +9 -1
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- package/src/server/lib/harness/acp/mapper.ts +6 -4
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-handshake.ts +9 -2
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session.test-util.ts +31 -2
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +20 -20
- package/src/server/lib/harness/acp/turn.ts +31 -7
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +13 -115
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/session/delete-flow.server.ts +15 -8
- package/src/server/lib/omp/session/delete.server.ts +12 -0
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/import-action.ts +18 -4
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update.ts +49 -7
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/harness/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +32 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +9 -0
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-plan.test.ts +51 -1
- package/src/shared/lib/harness/update-plan.ts +47 -7
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +25 -9
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +6 -3
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The launch table, and the extra indirection a launch line can need.
|
|
8
|
+
*
|
|
9
|
+
* Split from `launch.ts` so the table (data) and the probe (spawns one agent)
|
|
10
|
+
* stay under the file ceiling. `commandAvailable` reads this table; a probe
|
|
11
|
+
* reads it too, and both must agree about a bridge like `zcode`, whose command
|
|
12
|
+
* is `npx` but whose chat needs a separate runtime binary.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { existsSync } from 'node:fs';
|
|
16
|
+
import { homedir } from 'node:os';
|
|
17
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
18
|
+
|
|
19
|
+
/** One harness's launch configuration. */
|
|
20
|
+
export interface HarnessLaunch {
|
|
21
|
+
id: HarnessId;
|
|
22
|
+
command: string[];
|
|
23
|
+
/** Extra env the adapter needs (a wrapper path, a log dir, …). */
|
|
24
|
+
env?: Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* A binary the launch line SPAWNS but does not exec itself. The `zcode`
|
|
27
|
+
* bridge starts `zcode app-server --stdio`, so `npx` being present says
|
|
28
|
+
* nothing about whether a chat can run.
|
|
29
|
+
*/
|
|
30
|
+
requires?: HarnessRequirement;
|
|
31
|
+
/** Where the CLI installs from, for the settings page's install hint. */
|
|
32
|
+
install?: string;
|
|
33
|
+
/** What the agent looked like when measured on this machine. Display copy
|
|
34
|
+
* only — every panel reads the LIVE probe, never this. */
|
|
35
|
+
note: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** An indirection the launcher resolves on its own (the app-server case). */
|
|
39
|
+
export interface HarnessRequirement {
|
|
40
|
+
/** Binary name on PATH. */
|
|
41
|
+
binary: string;
|
|
42
|
+
/** Env var that overrides the lookup with a path or a name. */
|
|
43
|
+
env?: string;
|
|
44
|
+
/** App-bundle paths that also satisfy it. */
|
|
45
|
+
bundled?: readonly string[];
|
|
46
|
+
/** What a missing one is called in the card. */
|
|
47
|
+
label: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A configured path, a `~`-relative path, or a name on PATH. */
|
|
51
|
+
function resolvable(value: string): boolean {
|
|
52
|
+
const trimmed = value.trim();
|
|
53
|
+
if (!trimmed) return false;
|
|
54
|
+
if (trimmed.includes('/') || trimmed.includes('\\')) {
|
|
55
|
+
return existsSync(trimmed.replace(/^~(?=[/\\])/, homedir()));
|
|
56
|
+
}
|
|
57
|
+
return Boolean(Bun.which(trimmed));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Is the indirection this launch line needs actually present?
|
|
62
|
+
*
|
|
63
|
+
* An explicit `ZCODE_BIN` is authoritative (the bridge uses it verbatim), so a
|
|
64
|
+
* stale path DOES NOT fall back to PATH: claiming "available" would hide the
|
|
65
|
+
* broken setting behind a working install. With no override, PATH and the
|
|
66
|
+
* desktop bundle both count — those are the bridge's own resolution order.
|
|
67
|
+
*/
|
|
68
|
+
export function harnessRequirementMet(
|
|
69
|
+
requirement: HarnessRequirement | undefined,
|
|
70
|
+
env?: Record<string, string>,
|
|
71
|
+
): boolean {
|
|
72
|
+
if (!requirement) return true;
|
|
73
|
+
// A per-harness override wins, then the server's own environment: the spawn
|
|
74
|
+
// merges both, and `ZCODE_BIN` is commonly exported before Kabmo starts.
|
|
75
|
+
const explicit = requirement.env
|
|
76
|
+
? (env?.[requirement.env] ?? Bun.env[requirement.env] ?? '').trim()
|
|
77
|
+
: '';
|
|
78
|
+
if (explicit) return resolvable(explicit);
|
|
79
|
+
if (Bun.which(requirement.binary)) return true;
|
|
80
|
+
return (requirement.bundled ?? []).some(resolvable);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The launch table. A harness whose binary is missing reports the failure from
|
|
85
|
+
* `session/new`/spawn and the tab shows it with the install hint below.
|
|
86
|
+
*/
|
|
87
|
+
export const HARNESS_LAUNCH: Readonly<Partial<Record<HarnessId, HarnessLaunch>>> = {
|
|
88
|
+
'omp-acp': {
|
|
89
|
+
id: 'omp-acp',
|
|
90
|
+
command: ['omp', 'acp'],
|
|
91
|
+
install: 'curl -fsSL https://omp.sh/install | sh',
|
|
92
|
+
note: 'fastest handshake measured (0.08 s init, 0.22 s session/new); 221 models',
|
|
93
|
+
},
|
|
94
|
+
claude: {
|
|
95
|
+
id: 'claude',
|
|
96
|
+
command: ['npx', '-y', '@agentclientprotocol/claude-agent-acp@0.100.0'],
|
|
97
|
+
install: 'npm i -g @agentclientprotocol/claude-agent-acp',
|
|
98
|
+
note: 'mode 5 · model 5 · effort 6 · fast · ultracode; needs a Claude login',
|
|
99
|
+
},
|
|
100
|
+
codex: {
|
|
101
|
+
id: 'codex',
|
|
102
|
+
command: ['npx', '-y', '@agentclientprotocol/codex-acp@2.5.0'],
|
|
103
|
+
install: 'npm i -g @agentclientprotocol/codex-acp',
|
|
104
|
+
note: 'bridges `codex app-server`; set CODEX_PATH when the bundled binary cannot run',
|
|
105
|
+
},
|
|
106
|
+
opencode: {
|
|
107
|
+
id: 'opencode',
|
|
108
|
+
command: ['opencode', 'acp'],
|
|
109
|
+
install: 'curl -fsSL https://opencode.ai/install | bash',
|
|
110
|
+
note: 'plugin activation can gate session/new for ~80 s; Kabmo waits it out. Writes plugin logs to stdout',
|
|
111
|
+
},
|
|
112
|
+
dsh: {
|
|
113
|
+
id: 'dsh',
|
|
114
|
+
command: ['dsh', '--profile', 'acp'],
|
|
115
|
+
install: 'npm i -g @deepseek-ai/dsh',
|
|
116
|
+
note: 'no loadSession: history replays from Kabmo\u2019s own stored frames',
|
|
117
|
+
},
|
|
118
|
+
// `cmd` is the bin npm installs; the package also ships `cmdc` (Windows) and the
|
|
119
|
+
// long `command-code` / `commandcode` aliases. Measured: 0.77 s handshake, 43 ms
|
|
120
|
+
// session/new, 96 models · 4 thought levels, and list/resume/close advertised.
|
|
121
|
+
// Todos are off by default (`cmd mods enable todos -g`, then restart).
|
|
122
|
+
'command-code': {
|
|
123
|
+
id: 'command-code',
|
|
124
|
+
command: ['cmd', 'acp'],
|
|
125
|
+
install: 'npm i -g command-code',
|
|
126
|
+
note: 'needs `cmd login`; 96 models · 4 thought levels; todos off by default',
|
|
127
|
+
},
|
|
128
|
+
// Antigravity CLI (`agy`) replaced Gemini CLI, which Google deprecated. Its ACP
|
|
129
|
+
// server is `agy acp`, and it serves one project per process.
|
|
130
|
+
antigravity: {
|
|
131
|
+
id: 'antigravity',
|
|
132
|
+
command: ['agy', 'acp'],
|
|
133
|
+
install: 'download agy_cli_<os>_<arch>.tar.gz from github.com/google-antigravity/antigravity-cli/releases',
|
|
134
|
+
note: 'ACP since 1.5; sign in once (`agy acp --login`) or authenticate with a Gemini API key; runs under Docker on Linux',
|
|
135
|
+
},
|
|
136
|
+
minimax: {
|
|
137
|
+
id: 'minimax',
|
|
138
|
+
command: ['mcode', 'acp'],
|
|
139
|
+
install: 'npm i -g @minimax-ai/code',
|
|
140
|
+
note: 'needs `mcode login`; fork/resume/close/list all advertised',
|
|
141
|
+
},
|
|
142
|
+
pi: {
|
|
143
|
+
id: 'pi',
|
|
144
|
+
command: ['npx', '-y', 'pi-acp@0.0.34'],
|
|
145
|
+
install: 'npm i -g @earendil-works/pi-coding-agent pi-acp',
|
|
146
|
+
note: 'shells out to a `pi` binary on PATH; needs `pi auth` before a turn succeeds',
|
|
147
|
+
},
|
|
148
|
+
qwen: {
|
|
149
|
+
id: 'qwen',
|
|
150
|
+
command: ['qwen', '--acp'],
|
|
151
|
+
install: 'npm i -g @qwen-code/qwen-code',
|
|
152
|
+
note: 'list/resume; needs `qwen` auth',
|
|
153
|
+
},
|
|
154
|
+
kimi: {
|
|
155
|
+
id: 'kimi',
|
|
156
|
+
command: ['kimi', 'acp'],
|
|
157
|
+
install: 'curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash',
|
|
158
|
+
note: 'ACP needs an onboarded provider (config.toml) or a signed-in account',
|
|
159
|
+
},
|
|
160
|
+
cursor: {
|
|
161
|
+
id: 'cursor',
|
|
162
|
+
command: ['cursor-agent', 'acp'],
|
|
163
|
+
install: 'registry binary (cursor-agent)',
|
|
164
|
+
note: 'registry shape; no CLI probe run here',
|
|
165
|
+
},
|
|
166
|
+
// ZCode's ACP surface is a BRIDGE, not a subcommand: the vendor CLI ships no
|
|
167
|
+
// `acp` verb, and `zcode-acp-server` spawns `zcode app-server --stdio` and
|
|
168
|
+
// translates its events. The bridge resolves the CLI itself (`ZCODE_BIN` →
|
|
169
|
+
// `zcode` on PATH → the desktop app bundle), so the only requirement is a
|
|
170
|
+
// signed-in ZCode install; credentials stay in `~/.zcode`.
|
|
171
|
+
// Measured through Kabmo's own ACP client on 0.82.3: agentInfo
|
|
172
|
+
// `zcode-acp-server` 0.82.3, `session/new` in ~1 s, **1 model · 3 thought
|
|
173
|
+
// levels · 5 modes**, `list`/`resume`/`fork` advertised, steering supported.
|
|
174
|
+
zcode: {
|
|
175
|
+
id: 'zcode',
|
|
176
|
+
command: ['npx', '-y', 'zcode-acp-server@0.82.3'],
|
|
177
|
+
// The bridge spawns `zcode app-server --stdio`; without that binary the
|
|
178
|
+
// probe still answers (its model list comes from files) and every turn
|
|
179
|
+
// exits with "zcode not found". Check the thing a chat actually needs.
|
|
180
|
+
requires: {
|
|
181
|
+
binary: 'zcode',
|
|
182
|
+
env: 'ZCODE_BIN',
|
|
183
|
+
bundled: [
|
|
184
|
+
'/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs',
|
|
185
|
+
'~/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs',
|
|
186
|
+
'/opt/ZCode/resources/glm/zcode.cjs',
|
|
187
|
+
'/usr/share/zcode/resources/glm/zcode.cjs',
|
|
188
|
+
...(Bun.env.LOCALAPPDATA ? [`${Bun.env.LOCALAPPDATA}/Programs/ZCode/resources/glm/zcode.cjs`] : []),
|
|
189
|
+
],
|
|
190
|
+
label: 'a ZCode runtime (the desktop app, or `npm i -g zcode-app-cli`)',
|
|
191
|
+
},
|
|
192
|
+
install: 'npm i -g zcode-acp-server zcode-app-cli # the app-server runtime (or install the ZCode desktop app)',
|
|
193
|
+
note: 'bridges `zcode app-server --stdio`; measured 1 model · 3 thought levels · 5 modes, list/resume/fork + steering; needs a ZCode runtime — the desktop app, or `zcode-app-cli` on PATH (`ZCODE_BIN` for a custom install). Custom providers go in ~/.zcode/v2/provider_config.json; the bridge lists only selectable ones',
|
|
194
|
+
},
|
|
195
|
+
};
|
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { describe, expect, test } from 'bun:test';
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import os from 'node:os';
|
|
18
20
|
import { join } from 'node:path';
|
|
19
21
|
import { blockedProbe, capabilitiesFrom, configByCategory, probeHarness, selectValues, sessionLaunchCommand } from '@/server/lib/harness/launch';
|
|
22
|
+
import { harnessRequirementMet } from '@/server/lib/harness/launch-table';
|
|
20
23
|
import type { AcpInitializeResult, AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
21
24
|
|
|
22
25
|
const ompInit: AcpInitializeResult = {
|
|
@@ -181,3 +184,37 @@ describe('probeHarness launch override', () => {
|
|
|
181
184
|
expect(probe.harness).toBe('pi');
|
|
182
185
|
});
|
|
183
186
|
});
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A launch line can depend on a binary it does NOT exec.
|
|
190
|
+
*
|
|
191
|
+
* The zcode bridge starts `zcode app-server --stdio`; the probe still answers
|
|
192
|
+
* (its models come from files), so `npx` being present painted the tab ready
|
|
193
|
+
* while every turn exited with "zcode not found". These cases pin the
|
|
194
|
+
* resolution order the bridge itself uses.
|
|
195
|
+
*/
|
|
196
|
+
describe('harnessRequirementMet', () => {
|
|
197
|
+
const dir = fs.mkdtempSync(join(os.tmpdir(), 'kabmo-require-'));
|
|
198
|
+
const present = join(dir, 'zcode.cjs');
|
|
199
|
+
fs.writeFileSync(present, '');
|
|
200
|
+
|
|
201
|
+
test('no requirement means nothing to check', () => {
|
|
202
|
+
expect(harnessRequirementMet(undefined)).toBe(true);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('an explicit env path is authoritative, including when it is wrong', () => {
|
|
206
|
+
const requirement = { binary: 'definitely-not-zcode-xyz', env: 'ZCODE_BIN', label: 'runtime' };
|
|
207
|
+
expect(harnessRequirementMet(requirement, { ZCODE_BIN: present })).toBe(true);
|
|
208
|
+
// A stale override must NOT fall back to PATH: the bridge uses it verbatim.
|
|
209
|
+
expect(harnessRequirementMet(requirement, { ZCODE_BIN: join(dir, 'missing.cjs') })).toBe(false);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('a bundled app path counts when PATH has nothing', () => {
|
|
213
|
+
const requirement = { binary: 'definitely-not-zcode-xyz', bundled: [present], label: 'runtime' };
|
|
214
|
+
expect(harnessRequirementMet(requirement)).toBe(true);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('a binary that is neither on PATH nor bundled is missing', () => {
|
|
218
|
+
expect(harnessRequirementMet({ binary: 'definitely-not-zcode-xyz', label: 'runtime' })).toBe(false);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
@@ -16,127 +16,20 @@
|
|
|
16
16
|
* capability flags, then disposes. That is deliberately not done for all
|
|
17
17
|
* harnesses at once: seven agents cost ~6 s and seven processes, which is why
|
|
18
18
|
* the sidebar reads Kabmo's own index and this runs on an explicit action.
|
|
19
|
+
*
|
|
20
|
+
* The launch TABLE itself lives in `launch-table.ts` so this module is the probe
|
|
21
|
+
* and the session argv, both under the file ceiling.
|
|
19
22
|
*/
|
|
20
23
|
|
|
21
24
|
import { AcpProcess } from '@/server/lib/harness/acp/client';
|
|
25
|
+
import { newSessionAfterActivation } from '@/server/lib/harness/acp/activation';
|
|
22
26
|
import type { AcpConfigOption, AcpInitializeResult } from '@/server/lib/harness/acp/protocol';
|
|
23
27
|
import { acpOptionValues } from '@/server/lib/harness/acp/protocol';
|
|
24
28
|
import { UNPROBED_CAPABILITIES, type HarnessCapabilities, type HarnessProbe } from '@/server/lib/harness/capabilities';
|
|
29
|
+
import { HARNESS_LAUNCH, type HarnessLaunch } from '@/server/lib/harness/launch-table';
|
|
25
30
|
import { kabmoExtensionArgs } from '@/server/lib/omp/extensions/locator';
|
|
26
31
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
27
32
|
|
|
28
|
-
/** One harness's launch configuration. */
|
|
29
|
-
export interface HarnessLaunch {
|
|
30
|
-
id: HarnessId;
|
|
31
|
-
command: string[];
|
|
32
|
-
/** Extra env the adapter needs (a wrapper path, a log dir, …). */
|
|
33
|
-
env?: Record<string, string>;
|
|
34
|
-
/** Where the CLI installs from, for the settings page's install hint. */
|
|
35
|
-
install?: string;
|
|
36
|
-
/** What the agent looked like when measured on this machine. Display copy
|
|
37
|
-
* only — every panel reads the LIVE probe, never this. */
|
|
38
|
-
note: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The launch table. A harness whose binary is missing reports the failure from
|
|
43
|
-
* `session/new`/spawn and the tab shows it with the install hint below.
|
|
44
|
-
*/
|
|
45
|
-
export const HARNESS_LAUNCH: Readonly<Partial<Record<HarnessId, HarnessLaunch>>> = {
|
|
46
|
-
'omp-acp': {
|
|
47
|
-
id: 'omp-acp',
|
|
48
|
-
command: ['omp', 'acp'],
|
|
49
|
-
install: 'curl -fsSL https://omp.sh/install | sh',
|
|
50
|
-
note: 'fastest handshake measured (0.08 s init, 0.22 s session/new); 221 models',
|
|
51
|
-
},
|
|
52
|
-
claude: {
|
|
53
|
-
id: 'claude',
|
|
54
|
-
command: ['npx', '-y', '@agentclientprotocol/claude-agent-acp@0.100.0'],
|
|
55
|
-
install: 'npm i -g @agentclientprotocol/claude-agent-acp',
|
|
56
|
-
note: 'mode 5 · model 5 · effort 6 · fast · ultracode; needs a Claude login',
|
|
57
|
-
},
|
|
58
|
-
codex: {
|
|
59
|
-
id: 'codex',
|
|
60
|
-
command: ['npx', '-y', '@agentclientprotocol/codex-acp@2.5.0'],
|
|
61
|
-
install: 'npm i -g @agentclientprotocol/codex-acp',
|
|
62
|
-
note: 'bridges `codex app-server`; set CODEX_PATH when the bundled binary cannot run',
|
|
63
|
-
},
|
|
64
|
-
opencode: {
|
|
65
|
-
id: 'opencode',
|
|
66
|
-
command: ['opencode', 'acp'],
|
|
67
|
-
install: 'curl -fsSL https://opencode.ai/install | bash',
|
|
68
|
-
note: 'slowest start measured (2.3 s, plugin boot) and writes plugin logs to stdout',
|
|
69
|
-
},
|
|
70
|
-
dsh: {
|
|
71
|
-
id: 'dsh',
|
|
72
|
-
command: ['dsh', '--profile', 'acp'],
|
|
73
|
-
install: 'npm i -g @deepseek-ai/dsh',
|
|
74
|
-
note: 'no loadSession: history replays from Kabmo\u2019s own stored frames',
|
|
75
|
-
},
|
|
76
|
-
// `cmd` is the bin npm installs; the package also ships `cmdc` (Windows) and the
|
|
77
|
-
// long `command-code` / `commandcode` aliases. Measured: 0.77 s handshake, 43 ms
|
|
78
|
-
// session/new, 96 models · 4 thought levels, and list/resume/close advertised.
|
|
79
|
-
// Todos are off by default (`cmd mods enable todos -g`, then restart).
|
|
80
|
-
'command-code': {
|
|
81
|
-
id: 'command-code',
|
|
82
|
-
command: ['cmd', 'acp'],
|
|
83
|
-
install: 'npm i -g command-code',
|
|
84
|
-
note: 'needs `cmd login`; 96 models · 4 thought levels; todos off by default',
|
|
85
|
-
},
|
|
86
|
-
// Antigravity CLI (`agy`) replaced Gemini CLI, which Google deprecated. Its ACP
|
|
87
|
-
// server is `agy acp`, and it serves one project per process.
|
|
88
|
-
antigravity: {
|
|
89
|
-
id: 'antigravity',
|
|
90
|
-
command: ['agy', 'acp'],
|
|
91
|
-
install: 'download agy_cli_<os>_<arch>.tar.gz from github.com/google-antigravity/antigravity-cli/releases',
|
|
92
|
-
note: 'ACP since 1.5; sign in once (`agy acp --login`) or authenticate with a Gemini API key; runs under Docker on Linux',
|
|
93
|
-
},
|
|
94
|
-
minimax: {
|
|
95
|
-
id: 'minimax',
|
|
96
|
-
command: ['mcode', 'acp'],
|
|
97
|
-
install: 'npm i -g @minimax-ai/code',
|
|
98
|
-
note: 'needs `mcode login`; fork/resume/close/list all advertised',
|
|
99
|
-
},
|
|
100
|
-
pi: {
|
|
101
|
-
id: 'pi',
|
|
102
|
-
command: ['npx', '-y', 'pi-acp@0.0.34'],
|
|
103
|
-
install: 'npm i -g @earendil-works/pi-coding-agent pi-acp',
|
|
104
|
-
note: 'shells out to a `pi` binary on PATH; needs `pi auth` before a turn succeeds',
|
|
105
|
-
},
|
|
106
|
-
qwen: {
|
|
107
|
-
id: 'qwen',
|
|
108
|
-
command: ['qwen', '--acp'],
|
|
109
|
-
install: 'npm i -g @qwen-code/qwen-code',
|
|
110
|
-
note: 'list/resume; needs `qwen` auth',
|
|
111
|
-
},
|
|
112
|
-
kimi: {
|
|
113
|
-
id: 'kimi',
|
|
114
|
-
command: ['kimi', 'acp'],
|
|
115
|
-
install: 'curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash',
|
|
116
|
-
note: 'ACP needs an onboarded provider (config.toml) or a signed-in account',
|
|
117
|
-
},
|
|
118
|
-
cursor: {
|
|
119
|
-
id: 'cursor',
|
|
120
|
-
command: ['cursor-agent', 'acp'],
|
|
121
|
-
install: 'registry binary (cursor-agent)',
|
|
122
|
-
note: 'registry shape; no CLI probe run here',
|
|
123
|
-
},
|
|
124
|
-
// ZCode's ACP surface is a BRIDGE, not a subcommand: the vendor CLI ships no
|
|
125
|
-
// `acp` verb, and `zcode-acp-server` spawns `zcode app-server --stdio` and
|
|
126
|
-
// translates its events. The bridge resolves the CLI itself (`ZCODE_BIN` →
|
|
127
|
-
// `zcode` on PATH → the desktop app bundle), so the only requirement is a
|
|
128
|
-
// signed-in ZCode install; credentials stay in `~/.zcode`.
|
|
129
|
-
// Measured through Kabmo's own ACP client on 0.82.3: agentInfo
|
|
130
|
-
// `zcode-acp-server` 0.82.3, `session/new` in ~1 s, **1 model · 3 thought
|
|
131
|
-
// levels · 5 modes**, `list`/`resume`/`fork` advertised, steering supported.
|
|
132
|
-
zcode: {
|
|
133
|
-
id: 'zcode',
|
|
134
|
-
command: ['npx', '-y', 'zcode-acp-server@0.82.3'],
|
|
135
|
-
install: 'npm i -g zcode-acp-server',
|
|
136
|
-
note: 'bridges `zcode app-server --stdio`; measured 1 model · 3 thought levels · 5 modes, list/resume/fork + steering; needs ZCode credentials in ~/.zcode, `ZCODE_BIN` for a custom install',
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
|
|
140
33
|
/**
|
|
141
34
|
* The argv a SESSION spawns with, as opposed to the one a probe runs.
|
|
142
35
|
*
|
|
@@ -250,7 +143,7 @@ export async function probeHarness(
|
|
|
250
143
|
let agent: AcpInitializeResult['agentInfo'] | undefined;
|
|
251
144
|
|
|
252
145
|
try {
|
|
253
|
-
|
|
146
|
+
const agentProcess = new AcpProcess({
|
|
254
147
|
command: launch.command,
|
|
255
148
|
cwd,
|
|
256
149
|
...(launch.env ? { env: launch.env } : {}),
|
|
@@ -268,12 +161,17 @@ export async function probeHarness(
|
|
|
268
161
|
if (update.sessionUpdate === 'plan') observed.plan = true;
|
|
269
162
|
},
|
|
270
163
|
});
|
|
271
|
-
|
|
164
|
+
proc = agentProcess;
|
|
165
|
+
const init = await agentProcess.initialize();
|
|
272
166
|
// Kept for the failure path below: an agent that answers `initialize` and
|
|
273
167
|
// then refuses `session/new` ("Authentication required") still told us who
|
|
274
168
|
// it is, and the card can name it beside the refusal.
|
|
275
169
|
agent = init.agentInfo;
|
|
276
|
-
|
|
170
|
+
// opencode gates `session/new` on its own plugin activation; a probe that
|
|
171
|
+
// read the five-second refusal as final reported a booting agent as blocked.
|
|
172
|
+
const session = await newSessionAfterActivation(id, cwd, (dir, timeoutMs) =>
|
|
173
|
+
agentProcess.newSession(dir, timeoutMs),
|
|
174
|
+
);
|
|
277
175
|
const options = session.configOptions ?? [];
|
|
278
176
|
return {
|
|
279
177
|
harness: id,
|
|
@@ -74,6 +74,38 @@ function requireDialect(kind: ProviderRegistryKind, draft: ProviderDraft, target
|
|
|
74
74
|
return dialect;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The fields of an EXISTING entry that the import must not overwrite.
|
|
79
|
+
*
|
|
80
|
+
* A stored credential is the one that matters: an import brings an endpoint, and
|
|
81
|
+
* replacing a key the user set by hand is not what asking to copy a provider
|
|
82
|
+
* meant. `npm`/`type`/`wire_api` (the dialect) are kept too — they describe how
|
|
83
|
+
* that provider already works, and the source's dialect is a guess about a
|
|
84
|
+
* different agent.
|
|
85
|
+
*
|
|
86
|
+
* Lives here with the entry builders it mirrors, so the writer is read-modify-
|
|
87
|
+
* write and this module is "what does an entry look like".
|
|
88
|
+
*/
|
|
89
|
+
export function pickExisting(existing: Record<string, unknown>, incoming: Record<string, unknown>): Record<string, unknown> {
|
|
90
|
+
const keep: Record<string, unknown> = {};
|
|
91
|
+
const scalarKeys = ['npm', 'type', 'wire_api', 'api', 'name'];
|
|
92
|
+
for (const key of scalarKeys) {
|
|
93
|
+
if (existing[key] !== undefined && incoming[key] !== undefined) keep[key] = existing[key];
|
|
94
|
+
}
|
|
95
|
+
// Credentials, in each format's spelling: a top-level apiKey/api_key, or one
|
|
96
|
+
// nested inside opencode's `options`.
|
|
97
|
+
if (typeof existing.apiKey === 'string' && existing.apiKey) keep.apiKey = existing.apiKey;
|
|
98
|
+
if (typeof existing.api_key === 'string' && existing.api_key) keep.api_key = existing.api_key;
|
|
99
|
+
const existingOptions = asRecord(existing.options);
|
|
100
|
+
const incomingOptions = asRecord(incoming.options);
|
|
101
|
+
if (Object.keys(incomingOptions).length > 0) {
|
|
102
|
+
// `options` is merged key by key, so an endpoint arrives while a stored key
|
|
103
|
+
// and any hand-written option stay.
|
|
104
|
+
keep.options = { ...incomingOptions, ...existingOptions };
|
|
105
|
+
}
|
|
106
|
+
return keep;
|
|
107
|
+
}
|
|
108
|
+
|
|
77
109
|
/** kimi requires a context window per alias; 128k is the documented fallback. */
|
|
78
110
|
const DEFAULT_CONTEXT_WINDOW = 128_000;
|
|
79
111
|
|
|
@@ -30,6 +30,9 @@ export function serialise(kind: ProviderRegistryKind, doc: Record<string, unknow
|
|
|
30
30
|
case 'yaml-providers': return YAML.stringify(doc);
|
|
31
31
|
case 'toml-model-providers':
|
|
32
32
|
case 'toml-providers': return `${stringifyToml(doc)}\n`;
|
|
33
|
+
// The desktop's own writer emits two-space JSON with NO trailing newline;
|
|
34
|
+
// a non-canonical file is read fine but rewritten on the app's next save.
|
|
35
|
+
case 'zcode-provider-rules': return JSON.stringify(doc, null, 2);
|
|
33
36
|
default: return `${JSON.stringify(doc, null, 2)}\n`;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which harnesses read the same registry file.
|
|
8
|
+
*
|
|
9
|
+
* The bug this pins: a provider added on the `omp-acp` tab was written to the
|
|
10
|
+
* one `models.yml` both transports read, but only the clicked tab's probe was
|
|
11
|
+
* dropped — so the other picker kept serving the pre-write catalog until its
|
|
12
|
+
* TTL expired. The relation therefore has to be derived from the FILE the
|
|
13
|
+
* harness reads, not from a hand-written pair that a third transport would miss.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import { registryFilePath, harnessesSharingRegistry } from '@/server/lib/harness/provider-sources.server';
|
|
18
|
+
|
|
19
|
+
describe('harnesses that share a registry file', () => {
|
|
20
|
+
test('both omp transports read the same models.yml', () => {
|
|
21
|
+
const modelsYml = registryFilePath('omp-rpc');
|
|
22
|
+
expect(modelsYml).not.toBeNull();
|
|
23
|
+
// Measured on the real facts table: omp-acp reads the same file omp-rpc does.
|
|
24
|
+
expect(registryFilePath('omp-acp')).toBe(modelsYml);
|
|
25
|
+
expect(harnessesSharingRegistry(modelsYml!).sort()).toEqual(['omp-acp', 'omp-rpc']);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('a harness with its own file names only itself', () => {
|
|
29
|
+
const codex = registryFilePath('codex');
|
|
30
|
+
expect(codex).not.toBeNull();
|
|
31
|
+
expect(harnessesSharingRegistry(codex!)).toEqual(['codex']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('a path no harness reads invalidates nothing', () => {
|
|
35
|
+
// A caller that wrote some other file must not blank an unrelated picker.
|
|
36
|
+
expect(harnessesSharingRegistry(`${registryFilePath('omp-rpc')}.bak`)).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('harnesses without a registry never appear', () => {
|
|
40
|
+
// `minimax` has no file (`registry.file === null`); it must not match the
|
|
41
|
+
// home directory merely because both strings are empty.
|
|
42
|
+
expect(registryFilePath('minimax')).toBeNull();
|
|
43
|
+
expect(harnessesSharingRegistry('')).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -40,7 +40,9 @@ import { parse as parseToml } from 'smol-toml';
|
|
|
40
40
|
import { providerFacts, type ProviderRegistryKind } from '@/shared/lib/harness/provider-facts';
|
|
41
41
|
import { protocolOfSourceDialect, type CanonicalProtocol } from '@/shared/lib/harness/dialects';
|
|
42
42
|
import { isVendorProviderId } from '@/shared/lib/models/provider/vendors';
|
|
43
|
-
import type
|
|
43
|
+
import { HARNESS_IDS, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
44
|
+
import { canonicalize } from '@/server/lib/omp/core/paths';
|
|
45
|
+
import { readZcodeProviderKey, readZcodeProviders } from '@/server/lib/harness/provider-zcode.server';
|
|
44
46
|
|
|
45
47
|
/** One provider as a source registry holds it, minus its credential. */
|
|
46
48
|
export interface ImportableProvider {
|
|
@@ -84,6 +86,22 @@ export function registryFilePath(id: HarnessId): string | null {
|
|
|
84
86
|
return file ? join(homeDir(), file) : null;
|
|
85
87
|
}
|
|
86
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Every harness that reads the SAME registry file.
|
|
91
|
+
*
|
|
92
|
+
* `omp-rpc` and `omp-acp` are two transports over one `models.yml`, so a
|
|
93
|
+
* provider written through either must invalidate the other's cached model
|
|
94
|
+
* list. The comparison is the file itself, not a hand-written pair, so a future
|
|
95
|
+
* harness that shares a registry inherits the rule for free.
|
|
96
|
+
*/
|
|
97
|
+
export function harnessesSharingRegistry(path: string): HarnessId[] {
|
|
98
|
+
const key = canonicalize(path);
|
|
99
|
+
return HARNESS_IDS.filter((id) => {
|
|
100
|
+
const file = registryFilePath(id);
|
|
101
|
+
return file !== null && canonicalize(file) === key;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
87
105
|
/** A value at a dot-path (`options.baseURL`), or undefined. */
|
|
88
106
|
function atPointer(root: Record<string, unknown>, pointer: string): unknown {
|
|
89
107
|
let node: unknown = root;
|
|
@@ -115,7 +133,8 @@ function parseByKind(kind: ProviderRegistryKind, text: string): Record<string, u
|
|
|
115
133
|
case 'toml-providers': return asRecord(parseToml(text));
|
|
116
134
|
case 'json-provider':
|
|
117
135
|
case 'json-providers':
|
|
118
|
-
case 'json-model-providers':
|
|
136
|
+
case 'json-model-providers':
|
|
137
|
+
case 'zcode-provider-rules': return asRecord(JSON.parse(text));
|
|
119
138
|
default: return null;
|
|
120
139
|
}
|
|
121
140
|
} catch {
|
|
@@ -177,6 +196,10 @@ export async function readRegistryProviders(id: HarnessId): Promise<ImportablePr
|
|
|
177
196
|
const doc = parseByKind(kind, text);
|
|
178
197
|
if (!doc) return [];
|
|
179
198
|
|
|
199
|
+
// ZCode's registry is a rule GRAPH, not a providers map: one provider rule
|
|
200
|
+
// plus one rule per model. Its reader lives beside its writer.
|
|
201
|
+
if (kind === 'zcode-provider-rules') return readZcodeProviders(text, id);
|
|
202
|
+
|
|
180
203
|
// `modelProviders` is an ARRAY per protocol (qwen), so its rows are the models
|
|
181
204
|
// themselves and the provider id is the protocol key.
|
|
182
205
|
if (kind === 'json-model-providers') {
|
|
@@ -278,6 +301,7 @@ export async function readProviderKey(source: HarnessId, providerId: string): Pr
|
|
|
278
301
|
if (!text || !facts.registry.apiKeyField) return null;
|
|
279
302
|
const doc = parseByKind(facts.registry.kind, text);
|
|
280
303
|
if (!doc) return null;
|
|
304
|
+
if (facts.registry.kind === 'zcode-provider-rules') return readZcodeProviderKey(text, providerId);
|
|
281
305
|
const entry = asRecord(asRecord(atPointer(doc, facts.registry.pointer))[providerId]);
|
|
282
306
|
const value = atPointer(entry, facts.registry.apiKeyField);
|
|
283
307
|
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
@@ -39,8 +39,9 @@ import {
|
|
|
39
39
|
} from '@/shared/lib/harness/dialects';
|
|
40
40
|
import { isVendorProviderId } from '@/shared/lib/models/provider/vendors';
|
|
41
41
|
import { registryFilePath, readProviderKey, readRegistryProviders } from '@/server/lib/harness/provider-sources.server';
|
|
42
|
-
import { asRecord, modelRowsFor, providerEntryFor, type ProviderDraft } from '@/server/lib/harness/provider-entry';
|
|
42
|
+
import { asRecord, modelRowsFor, pickExisting, providerEntryFor, type ProviderDraft } from '@/server/lib/harness/provider-entry';
|
|
43
43
|
import { ProviderWriteError } from '@/server/lib/harness/provider-write-error';
|
|
44
|
+
import { writeZcodeProvider } from '@/server/lib/harness/provider-zcode.server';
|
|
44
45
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
45
46
|
|
|
46
47
|
/** What a successful write changed, so the card can report it rather than guess. */
|
|
@@ -164,17 +165,34 @@ export async function writeProvider(
|
|
|
164
165
|
if (!ID_PATTERN.test(id)) {
|
|
165
166
|
throw new ProviderWriteError(`"${id}" is not a provider id ${target} accepts (lowercase, digits, . _ : -)`);
|
|
166
167
|
}
|
|
167
|
-
|
|
168
|
+
const kind = facts.registry.kind;
|
|
169
|
+
// ZCode keys personal rules by the USER's id; its runtime ids are the
|
|
170
|
+
// `builtin:`/`account:` prefixes, and ids like `local` are its own documented
|
|
171
|
+
// example of a custom provider. The shared census is about the other agents,
|
|
172
|
+
// so it must not refuse a legitimate ZCode gateway.
|
|
173
|
+
if (kind !== 'zcode-provider-rules' && isVendorProviderId(id, facts.registry.bundledIds)) {
|
|
168
174
|
throw new ProviderWriteError(
|
|
169
175
|
`"${id}" is a provider ${target} ships itself, so writing it would override the vendor's entry instead of `
|
|
170
176
|
+ 'adding a gateway. Only providers you registered yourself can be imported.',
|
|
171
177
|
);
|
|
172
178
|
}
|
|
173
179
|
|
|
174
|
-
const kind = facts.registry.kind;
|
|
175
180
|
const plan = planFor(target, draft);
|
|
176
181
|
const planned: ProviderDraft = { ...draft, protocol: plan.protocol, baseUrl: plan.baseUrl };
|
|
177
182
|
const dialect = dialectFor(kind, plan.protocol) ?? '';
|
|
183
|
+
|
|
184
|
+
// ZCode's personal-provider file is a RULE GRAPH (one provider rule plus one
|
|
185
|
+
// model rule per id), not a providers map. Its writer owns that read-modify-
|
|
186
|
+
// write; this module still owns the format/protocol decisions above.
|
|
187
|
+
if (kind === 'zcode-provider-rules') {
|
|
188
|
+
if (id.startsWith('builtin:') || id.startsWith('account:')) {
|
|
189
|
+
throw new ProviderWriteError(
|
|
190
|
+
`"${id}" is a provider the ZCode runtime owns; a personal rule cannot replace a built-in or account plan.`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return writeZcodeProvider({ path, id, draft: planned, dialect });
|
|
194
|
+
}
|
|
195
|
+
|
|
178
196
|
const env = credentialEnvFor(kind, planned);
|
|
179
197
|
const notes: string[] = [];
|
|
180
198
|
|
|
@@ -272,35 +290,6 @@ export async function writeProvider(
|
|
|
272
290
|
});
|
|
273
291
|
}
|
|
274
292
|
|
|
275
|
-
/**
|
|
276
|
-
* The fields of an EXISTING entry that the import must not overwrite.
|
|
277
|
-
*
|
|
278
|
-
* A stored credential is the one that matters: an import brings an endpoint, and
|
|
279
|
-
* replacing a key the user set by hand is not what asking to copy a provider
|
|
280
|
-
* meant. `npm`/`type`/`wire_api` (the dialect) are kept too — they describe how
|
|
281
|
-
* that provider already works, and the source's dialect is a guess about a
|
|
282
|
-
* different agent.
|
|
283
|
-
*/
|
|
284
|
-
function pickExisting(existing: Record<string, unknown>, incoming: Record<string, unknown>): Record<string, unknown> {
|
|
285
|
-
const keep: Record<string, unknown> = {};
|
|
286
|
-
const scalarKeys = ['npm', 'type', 'wire_api', 'api', 'name'];
|
|
287
|
-
for (const key of scalarKeys) {
|
|
288
|
-
if (existing[key] !== undefined && incoming[key] !== undefined) keep[key] = existing[key];
|
|
289
|
-
}
|
|
290
|
-
// Credentials, in each format's spelling: a top-level apiKey/api_key, or one
|
|
291
|
-
// nested inside opencode's `options`.
|
|
292
|
-
if (typeof existing.apiKey === 'string' && existing.apiKey) keep.apiKey = existing.apiKey;
|
|
293
|
-
if (typeof existing.api_key === 'string' && existing.api_key) keep.api_key = existing.api_key;
|
|
294
|
-
const existingOptions = asRecord(existing.options);
|
|
295
|
-
const incomingOptions = asRecord(incoming.options);
|
|
296
|
-
if (Object.keys(incomingOptions).length > 0) {
|
|
297
|
-
// `options` is merged key by key, so an endpoint arrives while a stored key
|
|
298
|
-
// and any hand-written option stay.
|
|
299
|
-
keep.options = { ...incomingOptions, ...existingOptions };
|
|
300
|
-
}
|
|
301
|
-
return keep;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
293
|
/** The row the import list handed out, as the writer needs it. */
|
|
305
294
|
export interface ListedProvider {
|
|
306
295
|
id: string;
|