@inetafrica/open-claudia 2.15.0 → 3.0.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/.env.example +30 -4
- package/CHANGELOG.md +22 -0
- package/README.md +87 -66
- package/bin/agent.js +44 -18
- package/bin/cli.js +30 -28
- package/bin/dream.js +5 -11
- package/bin/loopback-client.js +29 -5
- package/bin/schedule.js +19 -5
- package/bin/tool.js +23 -5
- package/bot-agent.js +5 -2350
- package/bot.js +81 -3
- package/channels/telegram/adapter.js +65 -5
- package/channels/voice/adapter.js +1 -0
- package/channels/voice/manage.js +43 -5
- package/config-dir.js +3 -11
- package/core/actions.js +155 -40
- package/core/approvals.js +136 -29
- package/core/auth-flow.js +103 -19
- package/core/config-dir.js +19 -0
- package/core/config.js +115 -69
- package/core/doctor.js +111 -57
- package/core/dream.js +219 -62
- package/core/enforcer.js +0 -0
- package/core/entities.js +2 -1
- package/core/fsutil.js +21 -4
- package/core/handlers.js +542 -224
- package/core/ideas.js +2 -1
- package/core/jobs.js +589 -72
- package/core/lessons.js +3 -2
- package/core/loopback.js +42 -6
- package/core/memory-mutation-queue.js +241 -0
- package/core/migration-backup.js +1060 -0
- package/core/pack-review.js +295 -88
- package/core/packs.js +4 -3
- package/core/persona.js +2 -1
- package/core/process-tree.js +19 -2
- package/core/provider-migration.js +39 -0
- package/core/provider-status.js +80 -0
- package/core/providers/claude-events.js +121 -0
- package/core/providers/claude-hook.js +114 -0
- package/core/providers/claude.js +296 -0
- package/core/providers/codex-events.js +125 -0
- package/core/providers/codex-hook.js +280 -0
- package/core/providers/codex.js +286 -0
- package/core/providers/contract.js +153 -0
- package/core/providers/env.js +148 -0
- package/core/providers/events.js +171 -0
- package/core/providers/hook-command.js +22 -0
- package/core/providers/index.js +240 -0
- package/core/providers/utility-policy.js +269 -0
- package/core/recall/classic.js +2 -2
- package/core/recall/discoverer.js +71 -22
- package/core/recall/metrics.js +27 -1
- package/core/recall/tuning.js +4 -1
- package/core/recall/warm-walker.js +151 -108
- package/core/recall-filter.js +86 -61
- package/core/router.js +79 -7
- package/core/run-context.js +185 -0
- package/core/runner.js +1562 -1286
- package/core/scheduler.js +515 -210
- package/core/side-chat.js +346 -0
- package/core/single-instance.js +46 -0
- package/core/state.js +1084 -97
- package/core/subagent.js +72 -98
- package/core/system-prompt.js +462 -279
- package/core/tool-guard.js +73 -39
- package/core/tools.js +22 -5
- package/core/transcripts.js +30 -1
- package/core/usage-log.js +19 -4
- package/core/utility-agent.js +654 -0
- package/core/web-auth.js +29 -13
- package/docs/CHANNEL_DESIGN.md +181 -0
- package/docs/MULTI_CHANNEL_PLAN.md +254 -0
- package/docs/PROVIDER_MIGRATION.md +67 -0
- package/health.js +50 -39
- package/package.json +48 -4
- package/setup.js +198 -38
- package/soul.md +39 -0
- package/test-ability-extraction.js +5 -0
- package/test-approval-async.js +63 -4
- package/test-cursor-removal.js +337 -0
- package/test-enforcer.js +70 -27
- package/test-fixtures/current-provider-parity.json +132 -0
- package/test-fixtures/fake-agent-cli.js +509 -0
- package/test-fixtures/migrations/claude-only/jobs.json +3 -0
- package/test-fixtures/migrations/claude-only/sessions.json +5 -0
- package/test-fixtures/migrations/claude-only/state.json +5 -0
- package/test-fixtures/migrations/cursor-selected/crons.json +3 -0
- package/test-fixtures/migrations/cursor-selected/jobs.json +3 -0
- package/test-fixtures/migrations/cursor-selected/sessions.json +5 -0
- package/test-fixtures/migrations/cursor-selected/state.json +6 -0
- package/test-fixtures/migrations/dual-provider/jobs.json +3 -0
- package/test-fixtures/migrations/dual-provider/sessions.json +7 -0
- package/test-fixtures/migrations/dual-provider/state.json +10 -0
- package/test-fixtures/migrations/malformed-partial/jobs.json +1 -0
- package/test-fixtures/migrations/malformed-partial/sessions.json +1 -0
- package/test-fixtures/migrations/malformed-partial/sessions.json.bak +3 -0
- package/test-fixtures/migrations/malformed-partial/state.json +1 -0
- package/test-fixtures/migrations/malformed-partial/state.json.bak +5 -0
- package/test-fixtures/migrations/missing-project/jobs.json +3 -0
- package/test-fixtures/migrations/missing-project/sessions.json +3 -0
- package/test-fixtures/migrations/missing-project/state.json +4 -0
- package/test-fixtures/migrations/multi-user/jobs.json +4 -0
- package/test-fixtures/migrations/multi-user/sessions.json +4 -0
- package/test-fixtures/migrations/multi-user/state.json +6 -0
- package/test-fixtures/provider-event-samples.json +17 -0
- package/test-learning-e2e.js +5 -0
- package/test-memory-mutation-queue.js +191 -0
- package/test-provider-boot-matrix.js +399 -0
- package/test-provider-bootstrap.js +158 -0
- package/test-provider-capabilities.js +232 -0
- package/test-provider-claude.js +206 -0
- package/test-provider-codex.js +228 -0
- package/test-provider-compaction.js +371 -0
- package/test-provider-core-prompt.js +264 -0
- package/test-provider-coupling-audit.js +90 -0
- package/test-provider-dream.js +312 -0
- package/test-provider-enforcer.js +252 -0
- package/test-provider-env-isolation.js +150 -0
- package/test-provider-events.js +171 -0
- package/test-provider-fixture.js +332 -0
- package/test-provider-gateway.js +508 -0
- package/test-provider-language.js +89 -0
- package/test-provider-migration-backup.js +424 -0
- package/test-provider-pack-review.js +436 -0
- package/test-provider-parity-e2e.js +537 -0
- package/test-provider-prompt-parity.js +89 -0
- package/test-provider-recall.js +271 -0
- package/test-provider-registry.js +251 -0
- package/test-provider-resume-parity.js +41 -0
- package/test-provider-run-lifecycle.js +349 -0
- package/test-provider-runner.js +271 -0
- package/test-provider-scheduler.js +689 -0
- package/test-provider-session-commands.js +185 -0
- package/test-provider-session-history.js +205 -0
- package/test-provider-side-chat.js +337 -0
- package/test-provider-state-migration.js +316 -0
- package/test-provider-stream-decoder.js +69 -0
- package/test-provider-subagent.js +228 -0
- package/test-provider-tool-hooks.js +360 -0
- package/test-recall-discoverer.js +1 -0
- package/test-recall-engine.js +3 -3
- package/test-recall-evolution.js +18 -0
- package/test-runner-watchdog-static.js +16 -8
- package/test-single-runtime.js +35 -0
- package/test-telegram-poll-recovery.js +93 -0
- package/test-tool-guard.js +56 -0
- package/test-tools.js +19 -0
- package/test-unified-identity.js +3 -1
- package/test-usage-accounting.js +92 -20
- package/test-utility-provider-policy.js +486 -0
- package/web.js +130 -35
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const assert = require("assert");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
|
|
10
|
+
const configDir = fs.mkdtempSync(path.join(os.tmpdir(), "open-claudia-capabilities-"));
|
|
11
|
+
const workspace = path.join(configDir, "workspace");
|
|
12
|
+
fs.mkdirSync(path.join(workspace, "alpha"), { recursive: true });
|
|
13
|
+
process.env.OPEN_CLAUDIA_CONFIG_DIR = configDir;
|
|
14
|
+
process.env.WORKSPACE = workspace;
|
|
15
|
+
process.env.TELEGRAM_CHAT_ID = "fixture-chat";
|
|
16
|
+
process.env.CHANNELS = "";
|
|
17
|
+
process.env.OPEN_CLAUDIA_TEST = "1";
|
|
18
|
+
process.env.CLAUDE_PATH = process.execPath;
|
|
19
|
+
process.env.CODEX_PATH = process.execPath;
|
|
20
|
+
|
|
21
|
+
const stateApi = require("./core/state");
|
|
22
|
+
const handlers = require("./core/handlers");
|
|
23
|
+
const commands = require("./core/commands");
|
|
24
|
+
const providers = require("./core/providers");
|
|
25
|
+
const { handleAction } = require("./core/actions");
|
|
26
|
+
const { runInChat } = require("./core/context");
|
|
27
|
+
|
|
28
|
+
const state = stateApi.currentState();
|
|
29
|
+
state.currentSession = { name: "alpha", dir: path.join(workspace, "alpha") };
|
|
30
|
+
state.settings.backend = "claude";
|
|
31
|
+
|
|
32
|
+
function callbacks(rows) {
|
|
33
|
+
return rows.flat().map((button) => button.callback_data).filter(Boolean);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function pickerProbe() {
|
|
37
|
+
assert.strictEqual(typeof handlers.buildBackendPicker, "function");
|
|
38
|
+
assert.strictEqual(typeof handlers.buildModelPicker, "function");
|
|
39
|
+
const backend = handlers.buildBackendPicker({ state, registry: providers });
|
|
40
|
+
const expectedProviders = providers.listProviders().map((provider) => provider.id);
|
|
41
|
+
assert.deepStrictEqual(
|
|
42
|
+
callbacks(backend.rows).map((value) => value.slice("be:".length)),
|
|
43
|
+
expectedProviders,
|
|
44
|
+
"backend picker comes from registry order",
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const model = handlers.buildModelPicker({ state, registry: providers });
|
|
48
|
+
const modelCallbacks = callbacks(model.rows).filter((value) => value.startsWith("mb:"));
|
|
49
|
+
for (const provider of providers.listProviders()) {
|
|
50
|
+
const choices = provider.modelChoices();
|
|
51
|
+
for (const choice of choices) {
|
|
52
|
+
assert.ok(modelCallbacks.includes(`mb:${provider.id}:${choice}`), `${provider.id} model choice ${choice}`);
|
|
53
|
+
}
|
|
54
|
+
assert.ok(modelCallbacks.includes(`mb:${provider.id}:default`), `${provider.id} default model control`);
|
|
55
|
+
}
|
|
56
|
+
assert.ok(!fs.readFileSync(path.join(__dirname, "core", "handlers.js"), "utf8").includes("DEFAULT_CLAUDE_MODEL"));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function mutationProbe() {
|
|
60
|
+
assert.strictEqual(typeof handlers.applyProviderSetting, "function");
|
|
61
|
+
const claudeSettings = stateApi.getProviderSettings(state, "claude");
|
|
62
|
+
const codexSettings = stateApi.getProviderSettings(state, "codex");
|
|
63
|
+
claudeSettings.effort = "low";
|
|
64
|
+
claudeSettings.budget = 2;
|
|
65
|
+
codexSettings.effort = null;
|
|
66
|
+
codexSettings.budget = null;
|
|
67
|
+
codexSettings.worktree = false;
|
|
68
|
+
|
|
69
|
+
state.settings.backend = "codex";
|
|
70
|
+
let result = handlers.applyProviderSetting(state, "codex", "effort", "xhigh", { registry: providers });
|
|
71
|
+
assert.strictEqual(result.ok, true);
|
|
72
|
+
assert.strictEqual(codexSettings.effort, "xhigh");
|
|
73
|
+
assert.strictEqual(claudeSettings.effort, "low", "provider setting stays isolated");
|
|
74
|
+
|
|
75
|
+
const beforeBudget = structuredClone(state.providerSettings);
|
|
76
|
+
result = handlers.applyProviderSetting(state, "codex", "budget", 5, { registry: providers });
|
|
77
|
+
assert.strictEqual(result.ok, false);
|
|
78
|
+
assert.strictEqual(result.code, "UNSUPPORTED_PROVIDER_CAPABILITY");
|
|
79
|
+
assert.match(result.message, /no per-run monetary budget/i);
|
|
80
|
+
assert.deepStrictEqual(state.providerSettings, beforeBudget, "unsupported budget cannot mutate state");
|
|
81
|
+
|
|
82
|
+
const beforeWorktree = structuredClone(state.providerSettings);
|
|
83
|
+
result = handlers.applyProviderSetting(state, "codex", "worktree", true, { registry: providers });
|
|
84
|
+
assert.strictEqual(result.ok, false);
|
|
85
|
+
assert.match(result.message, /worktree/i);
|
|
86
|
+
assert.deepStrictEqual(state.providerSettings, beforeWorktree, "unsupported worktree cannot mutate state");
|
|
87
|
+
|
|
88
|
+
const beforeInvalidEffort = structuredClone(state.providerSettings);
|
|
89
|
+
result = handlers.applyProviderSetting(state, "codex", "effort", "maximum-ish", { registry: providers });
|
|
90
|
+
assert.strictEqual(result.ok, false);
|
|
91
|
+
assert.deepStrictEqual(state.providerSettings, beforeInvalidEffort, "invalid effort cannot mutate state");
|
|
92
|
+
|
|
93
|
+
state.settings.backend = "claude";
|
|
94
|
+
result = handlers.applyProviderSetting(state, "claude", "budget", 4, { registry: providers });
|
|
95
|
+
assert.strictEqual(result.ok, true);
|
|
96
|
+
assert.strictEqual(claudeSettings.budget, 4);
|
|
97
|
+
|
|
98
|
+
const stale = structuredClone(state.providerSettings);
|
|
99
|
+
result = handlers.applyProviderSetting(state, "codex", "effort", "high", { registry: providers, requireActive: true });
|
|
100
|
+
assert.strictEqual(result.code, "STALE_PROVIDER_CONTROL");
|
|
101
|
+
assert.deepStrictEqual(state.providerSettings, stale, "stale provider control cannot mutate inactive settings");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function inChat(fn, sent) {
|
|
105
|
+
return runInChat({
|
|
106
|
+
adapter: {
|
|
107
|
+
id: "fixture",
|
|
108
|
+
type: "fixture",
|
|
109
|
+
send: async (_channelId, text, options) => { sent.push({ text, options }); return true; },
|
|
110
|
+
},
|
|
111
|
+
channelId: "fixture-chat",
|
|
112
|
+
canonicalUserId: "telegram:fixture-chat",
|
|
113
|
+
userId: "fixture-chat",
|
|
114
|
+
}, fn);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function commandProbe() {
|
|
118
|
+
const names = new Set(commands.list().map((command) => command.name));
|
|
119
|
+
assert.ok(names.has("ask"), "/ask is registered");
|
|
120
|
+
const sent = [];
|
|
121
|
+
const dispatch = (text) => inChat(() => commands.dispatch(text, {
|
|
122
|
+
adapter: { id: "fixture", type: "fixture" },
|
|
123
|
+
channelId: "fixture-chat",
|
|
124
|
+
canonicalUserId: "telegram:fixture-chat",
|
|
125
|
+
userId: "fixture-chat",
|
|
126
|
+
}), sent);
|
|
127
|
+
|
|
128
|
+
state.settings.backend = "codex";
|
|
129
|
+
stateApi.getProviderSettings(state, "codex").effort = null;
|
|
130
|
+
await dispatch("/effort high");
|
|
131
|
+
assert.strictEqual(stateApi.getProviderSettings(state, "codex").effort, "high", "Codex native effort is accepted");
|
|
132
|
+
|
|
133
|
+
const beforeBudget = structuredClone(state.providerSettings);
|
|
134
|
+
await dispatch("/budget 5");
|
|
135
|
+
assert.deepStrictEqual(state.providerSettings, beforeBudget);
|
|
136
|
+
assert.match(sent.at(-1).text, /no per-run monetary budget/i);
|
|
137
|
+
|
|
138
|
+
const beforeWorktree = structuredClone(state.providerSettings);
|
|
139
|
+
await dispatch("/worktree");
|
|
140
|
+
assert.deepStrictEqual(state.providerSettings, beforeWorktree);
|
|
141
|
+
assert.match(sent.at(-1).text, /worktree/i);
|
|
142
|
+
|
|
143
|
+
await dispatch("/plan");
|
|
144
|
+
assert.strictEqual(stateApi.getProviderSettings(state, "codex").permissionMode, "plan");
|
|
145
|
+
await dispatch("/ask");
|
|
146
|
+
assert.strictEqual(stateApi.getProviderSettings(state, "codex").permissionMode, "ask");
|
|
147
|
+
|
|
148
|
+
await dispatch("/status");
|
|
149
|
+
assert.match(sent.at(-1).text, /Provider: OpenAI Codex/);
|
|
150
|
+
assert.match(sent.at(-1).text, /Capabilities:/);
|
|
151
|
+
assert.match(sent.at(-1).text, /budget unsupported/i);
|
|
152
|
+
|
|
153
|
+
await dispatch("/backend");
|
|
154
|
+
assert.deepStrictEqual(
|
|
155
|
+
callbacks(sent.at(-1).options.keyboard.inline_keyboard).map((value) => value.slice(3)),
|
|
156
|
+
providers.listProviders().map((provider) => provider.id),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
await dispatch("/model");
|
|
160
|
+
const modelControls = callbacks(sent.at(-1).options.keyboard.inline_keyboard);
|
|
161
|
+
assert.ok(modelControls.includes("mb:codex:gpt-5.6-sol"));
|
|
162
|
+
assert.ok(modelControls.includes("mb:codex:gpt-5.6-luna"));
|
|
163
|
+
assert.ok(!modelControls.includes("mb:codex:o4-mini"));
|
|
164
|
+
assert.ok(modelControls.includes("mb:claude:claude-sonnet-4-6"));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function callbackProbe() {
|
|
168
|
+
state.settings.backend = "codex";
|
|
169
|
+
stateApi.getProviderSettings(state, "codex").budget = null;
|
|
170
|
+
const before = structuredClone(state.providerSettings);
|
|
171
|
+
const sent = [];
|
|
172
|
+
await inChat(() => handleAction({
|
|
173
|
+
adapter: { id: "fixture", type: "fixture" },
|
|
174
|
+
channelId: "fixture-chat",
|
|
175
|
+
canonicalUserId: "telegram:fixture-chat",
|
|
176
|
+
userId: "fixture-chat",
|
|
177
|
+
action: { payload: "b:codex:5" },
|
|
178
|
+
}), sent);
|
|
179
|
+
assert.deepStrictEqual(state.providerSettings, before, "unsupported callback cannot mutate state");
|
|
180
|
+
assert.match(sent.at(-1).text, /no per-run monetary budget/i);
|
|
181
|
+
|
|
182
|
+
state.settings.backend = "claude";
|
|
183
|
+
const stale = structuredClone(state.providerSettings);
|
|
184
|
+
await inChat(() => handleAction({
|
|
185
|
+
adapter: { id: "fixture", type: "fixture" },
|
|
186
|
+
channelId: "fixture-chat",
|
|
187
|
+
canonicalUserId: "telegram:fixture-chat",
|
|
188
|
+
userId: "fixture-chat",
|
|
189
|
+
action: { payload: "e:codex:high" },
|
|
190
|
+
}), sent);
|
|
191
|
+
assert.deepStrictEqual(state.providerSettings, stale, "stale callback cannot mutate inactive provider");
|
|
192
|
+
assert.match(sent.at(-1).text, /stale/i);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function adapterReadOnlyProbe() {
|
|
196
|
+
const { createClaudeProvider } = require("./core/providers/claude");
|
|
197
|
+
const { createCodexProvider } = require("./core/providers/codex");
|
|
198
|
+
const common = {
|
|
199
|
+
resolveExecutable: () => process.execPath,
|
|
200
|
+
buildEnv: () => ({}),
|
|
201
|
+
getAuthStatus: () => ({ state: "authenticated", reason: null }),
|
|
202
|
+
hookTransport: false,
|
|
203
|
+
};
|
|
204
|
+
const context = {
|
|
205
|
+
coreInstructions: "policy",
|
|
206
|
+
dynamicContext: "context",
|
|
207
|
+
userPrompt: "question",
|
|
208
|
+
providerSettings: { permissionMode: "ask" },
|
|
209
|
+
fresh: true,
|
|
210
|
+
};
|
|
211
|
+
const claude = createClaudeProvider(common).buildMainInvocation(context);
|
|
212
|
+
assert.deepStrictEqual(claude.args.slice(claude.args.indexOf("--permission-mode"), claude.args.indexOf("--permission-mode") + 2), ["--permission-mode", "plan"]);
|
|
213
|
+
const codex = createCodexProvider({ ...common, defaultModel: "gpt-fixture" }).buildMainInvocation(context);
|
|
214
|
+
assert.deepStrictEqual(codex.args.slice(codex.args.indexOf("--sandbox"), codex.args.indexOf("--sandbox") + 2), ["--sandbox", "read-only"]);
|
|
215
|
+
assert.ok(!codex.args.includes("--dangerously-bypass-approvals-and-sandbox"));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function main() {
|
|
219
|
+
pickerProbe();
|
|
220
|
+
mutationProbe();
|
|
221
|
+
await commandProbe();
|
|
222
|
+
await callbackProbe();
|
|
223
|
+
await adapterReadOnlyProbe();
|
|
224
|
+
console.log("provider capabilities OK");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
main().catch((error) => {
|
|
228
|
+
console.error(error.stack || error.message);
|
|
229
|
+
process.exitCode = 1;
|
|
230
|
+
}).finally(() => {
|
|
231
|
+
fs.rmSync(configDir, { recursive: true, force: true });
|
|
232
|
+
});
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const assert = require("assert");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const { validateInvocation, validateProvider } = require("./core/providers/contract");
|
|
9
|
+
const { createClaudeProvider } = require("./core/providers/claude");
|
|
10
|
+
const { getProvider } = require("./core/providers");
|
|
11
|
+
|
|
12
|
+
function deepFreeze(value) {
|
|
13
|
+
if (!value || typeof value !== "object" || Object.isFrozen(value)) return value;
|
|
14
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
15
|
+
return Object.freeze(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const safeEnv = {
|
|
19
|
+
PATH: "/fixture/bin",
|
|
20
|
+
HOME: "/fixture/home",
|
|
21
|
+
CLAUDE_CODE_OAUTH_TOKEN: "fixture-present-not-a-real-token",
|
|
22
|
+
};
|
|
23
|
+
let authState = { state: "authenticated", reason: null, method: "fixture" };
|
|
24
|
+
const provider = createClaudeProvider({
|
|
25
|
+
hookTransport: false,
|
|
26
|
+
resolveExecutable: () => "/fixture/claude",
|
|
27
|
+
defaultModel: "claude-default-fixture",
|
|
28
|
+
buildEnv: () => ({ ...safeEnv }),
|
|
29
|
+
getAuthStatus: () => authState,
|
|
30
|
+
runCommand: (_binary, args) => {
|
|
31
|
+
if (args[0] === "--version") return { ok: true, output: "2.1.150 (Claude Code)", code: 0 };
|
|
32
|
+
if (args[0] === "--help") return {
|
|
33
|
+
ok: true,
|
|
34
|
+
output: "--append-system-prompt --output-format --resume --permission-mode --settings",
|
|
35
|
+
code: 0,
|
|
36
|
+
};
|
|
37
|
+
return { ok: false, output: "unexpected fixture command", code: 1 };
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
assert.strictEqual(validateProvider(provider), provider);
|
|
42
|
+
assert.strictEqual(provider.id, "claude");
|
|
43
|
+
assert.strictEqual(getProvider("claude").id, "claude", "built-in registry exposes the adapter without probing it at import");
|
|
44
|
+
assert.strictEqual(provider.label, "Claude Code");
|
|
45
|
+
assert.strictEqual(provider.isAvailable(), true);
|
|
46
|
+
assert.strictEqual(provider.executable(), "/fixture/claude");
|
|
47
|
+
assert.strictEqual(provider.defaultModel(), "claude-default-fixture");
|
|
48
|
+
assert.ok(provider.modelChoices().includes("claude-fable-5"));
|
|
49
|
+
assert.ok(provider.modelChoices().includes("claude-sonnet-4-6"));
|
|
50
|
+
assert.deepStrictEqual(provider.compatibilityStatus(), {
|
|
51
|
+
state: "compatible",
|
|
52
|
+
version: "2.1.150",
|
|
53
|
+
reason: null,
|
|
54
|
+
});
|
|
55
|
+
assert.strictEqual(provider.capabilities.resume.support, "native");
|
|
56
|
+
assert.strictEqual(provider.capabilities.readOnlyMode.support, "native");
|
|
57
|
+
assert.deepStrictEqual(provider.capabilities.effort.values, ["low", "medium", "high", "xhigh", "max"]);
|
|
58
|
+
assert.strictEqual(provider.capabilities.budget.support, "native");
|
|
59
|
+
assert.strictEqual(provider.capabilities.worktree.support, "native");
|
|
60
|
+
assert.strictEqual(provider.capabilities.maxTurns.support, "native");
|
|
61
|
+
assert.strictEqual(provider.capabilities.partialStreaming.support, "native");
|
|
62
|
+
assert.strictEqual(provider.capabilities.persistentUtilityStream.support, "native");
|
|
63
|
+
assert.strictEqual(provider.capabilities.preToolHook.support, "native");
|
|
64
|
+
assert.strictEqual(provider.capabilities.imageFlag.support, "unsupported");
|
|
65
|
+
|
|
66
|
+
const richContext = deepFreeze({
|
|
67
|
+
coreInstructions: "STABLE CORE",
|
|
68
|
+
dynamicContext: "DYNAMIC CONTEXT",
|
|
69
|
+
userPrompt: "USER SENTINEL",
|
|
70
|
+
fresh: true,
|
|
71
|
+
sessionId: "ignored-because-fresh",
|
|
72
|
+
providerSettings: {
|
|
73
|
+
model: "claude-sonnet-4-6",
|
|
74
|
+
effort: "high",
|
|
75
|
+
budget: 2.5,
|
|
76
|
+
permissionMode: "plan",
|
|
77
|
+
worktree: true,
|
|
78
|
+
},
|
|
79
|
+
maxTurns: 4,
|
|
80
|
+
transcriptDirectory: "/fixture/transcripts",
|
|
81
|
+
voiceStream: true,
|
|
82
|
+
toolHookSettings: "/fixture/deny-gate.json",
|
|
83
|
+
});
|
|
84
|
+
const before = JSON.stringify(richContext);
|
|
85
|
+
const richInvocation = validateInvocation(provider.buildMainInvocation(richContext));
|
|
86
|
+
assert.strictEqual(JSON.stringify(richContext), before, "frozen run context must not be mutated");
|
|
87
|
+
assert.strictEqual(richInvocation.binary, "/fixture/claude");
|
|
88
|
+
assert.deepStrictEqual(richInvocation.args, [
|
|
89
|
+
"-p",
|
|
90
|
+
"--verbose",
|
|
91
|
+
"--output-format", "stream-json",
|
|
92
|
+
"--append-system-prompt", "STABLE CORE",
|
|
93
|
+
"--settings", "/fixture/deny-gate.json",
|
|
94
|
+
"--add-dir", "/fixture/transcripts",
|
|
95
|
+
"--model", "claude-sonnet-4-6",
|
|
96
|
+
"--max-turns", "4",
|
|
97
|
+
"--effort", "high",
|
|
98
|
+
"--max-budget-usd", "2.5",
|
|
99
|
+
"--permission-mode", "plan",
|
|
100
|
+
"--worktree",
|
|
101
|
+
"--include-partial-messages",
|
|
102
|
+
"DYNAMIC CONTEXT\n\nUSER SENTINEL",
|
|
103
|
+
]);
|
|
104
|
+
assert.deepStrictEqual(richInvocation.env, safeEnv);
|
|
105
|
+
assert.strictEqual(richInvocation.stdin, null);
|
|
106
|
+
assert.ok(richInvocation.parserState.seenUsage instanceof Set);
|
|
107
|
+
|
|
108
|
+
function simpleContext(overrides = {}) {
|
|
109
|
+
return deepFreeze({
|
|
110
|
+
coreInstructions: "CORE",
|
|
111
|
+
dynamicContext: "",
|
|
112
|
+
userPrompt: "PROMPT",
|
|
113
|
+
providerSettings: {},
|
|
114
|
+
...overrides,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const fresh = provider.buildMainInvocation(simpleContext({ fresh: true, sessionId: "old" }));
|
|
119
|
+
assert.ok(!fresh.args.includes("--resume"));
|
|
120
|
+
assert.ok(!fresh.args.includes("--continue"));
|
|
121
|
+
assert.ok(fresh.args.includes("--dangerously-skip-permissions"), "direct mode preserves current behavior");
|
|
122
|
+
|
|
123
|
+
const resumed = provider.buildMainInvocation(simpleContext({ resumeSessionId: "resume-1" }));
|
|
124
|
+
assert.deepStrictEqual(resumed.args.slice(6, 10), ["--resume", "resume-1", "--model", "claude-default-fixture"]);
|
|
125
|
+
|
|
126
|
+
const implicitResume = provider.buildMainInvocation(simpleContext({ sessionId: "active-1" }));
|
|
127
|
+
assert.ok(implicitResume.args.indexOf("--resume") >= 0);
|
|
128
|
+
assert.strictEqual(implicitResume.args[implicitResume.args.indexOf("--resume") + 1], "active-1");
|
|
129
|
+
|
|
130
|
+
const continued = provider.buildMainInvocation(simpleContext({ continueSession: true, sessionId: "active-1" }));
|
|
131
|
+
assert.ok(continued.args.includes("--continue"));
|
|
132
|
+
assert.ok(!continued.args.includes("--resume"));
|
|
133
|
+
|
|
134
|
+
const readOnlyAsk = provider.buildMainInvocation(simpleContext({ providerSettings: { permissionMode: "ask" } }));
|
|
135
|
+
assert.deepStrictEqual(readOnlyAsk.args.slice(readOnlyAsk.args.indexOf("--permission-mode"), -1), ["--permission-mode", "plan"]);
|
|
136
|
+
|
|
137
|
+
assert.throws(
|
|
138
|
+
() => provider.buildMainInvocation(simpleContext({ resumeSessionId: "one", continueSession: true })),
|
|
139
|
+
(error) => error && error.code === "INVALID_PROVIDER_CONTEXT",
|
|
140
|
+
);
|
|
141
|
+
assert.throws(
|
|
142
|
+
() => provider.buildMainInvocation(simpleContext({ providerSettings: { effort: "extreme" } })),
|
|
143
|
+
(error) => error && error.code === "UNSUPPORTED_PROVIDER_SETTING",
|
|
144
|
+
);
|
|
145
|
+
assert.throws(
|
|
146
|
+
() => provider.buildMainInvocation(simpleContext({ providerSettings: { budget: -1 } })),
|
|
147
|
+
(error) => error && error.code === "INVALID_PROVIDER_CONTEXT",
|
|
148
|
+
);
|
|
149
|
+
assert.throws(
|
|
150
|
+
() => provider.buildMainInvocation(deepFreeze({ dynamicContext: "only", userPrompt: "raw" })),
|
|
151
|
+
(error) => error && error.code === "MISSING_CORE_INSTRUCTIONS",
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const utility = validateInvocation(provider.buildUtilityInvocation(deepFreeze({
|
|
155
|
+
coreInstructions: "UTILITY CORE",
|
|
156
|
+
userPrompt: "UTILITY PROMPT",
|
|
157
|
+
readOnly: true,
|
|
158
|
+
allowedTools: ["Read", "Glob"],
|
|
159
|
+
disallowedTools: ["Write"],
|
|
160
|
+
outputSchema: { type: "object", required: ["ok"] },
|
|
161
|
+
tier: "low",
|
|
162
|
+
maxTurns: 2,
|
|
163
|
+
toolHookSettings: "/fixture/utility-hook.json",
|
|
164
|
+
})));
|
|
165
|
+
assert.ok(utility.args.includes("--no-session-persistence"));
|
|
166
|
+
assert.deepStrictEqual(utility.args.slice(utility.args.indexOf("--allowedTools"), utility.args.indexOf("--allowedTools") + 2), ["--allowedTools", "Read,Glob"]);
|
|
167
|
+
assert.deepStrictEqual(utility.args.slice(utility.args.indexOf("--permission-mode"), utility.args.indexOf("--permission-mode") + 2), ["--permission-mode", "plan"]);
|
|
168
|
+
assert.strictEqual(utility.args[utility.args.indexOf("--model") + 1], "claude-haiku-4-5-20251001");
|
|
169
|
+
assert.strictEqual(utility.args[utility.args.indexOf("--json-schema") + 1], JSON.stringify({ type: "object", required: ["ok"] }));
|
|
170
|
+
assert.strictEqual(utility.stdin, "UTILITY PROMPT", "utility prompt uses protected stdin transport");
|
|
171
|
+
assert.ok(!utility.args.includes("UTILITY PROMPT"), "utility prompt is absent from argv");
|
|
172
|
+
|
|
173
|
+
const decoder = provider.createEventDecoder();
|
|
174
|
+
const raw = decoder.push(Buffer.from('{"type":"system","subtype":"init","session_id":"bound-session"}\n'));
|
|
175
|
+
assert.deepStrictEqual(provider.normalizeEvent(raw[0], richInvocation.parserState), [{ type: "session", sessionId: "bound-session" }]);
|
|
176
|
+
|
|
177
|
+
assert.strictEqual(provider.authStatus().state, "authenticated");
|
|
178
|
+
assert.strictEqual(provider.preflightAuth(), null);
|
|
179
|
+
authState = { state: "unauthenticated", reason: "login required" };
|
|
180
|
+
const authFailure = provider.preflightAuth();
|
|
181
|
+
assert.strictEqual(authFailure.code, "PROVIDER_UNAUTHENTICATED");
|
|
182
|
+
assert.match(authFailure.message, /Claude auth needs attention/);
|
|
183
|
+
assert.match(provider.authHelp(), /setup_token/);
|
|
184
|
+
|
|
185
|
+
const missing = createClaudeProvider({ hookTransport: false, resolveExecutable: () => null, getAuthStatus: () => ({ state: "not_checked", reason: "missing" }) });
|
|
186
|
+
assert.strictEqual(missing.isAvailable(), false);
|
|
187
|
+
assert.throws(
|
|
188
|
+
() => missing.buildMainInvocation(simpleContext()),
|
|
189
|
+
(error) => error && error.code === "NO_AVAILABLE_PROVIDER",
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const incompatible = createClaudeProvider({
|
|
193
|
+
hookTransport: false,
|
|
194
|
+
resolveExecutable: () => "/fixture/old-claude",
|
|
195
|
+
buildEnv: () => ({ PATH: "/fixture" }),
|
|
196
|
+
getAuthStatus: () => ({ state: "unknown", reason: "not checked" }),
|
|
197
|
+
runCommand: (_binary, args) => args[0] === "--version"
|
|
198
|
+
? { ok: true, output: "0.1.0", code: 0 }
|
|
199
|
+
: { ok: true, output: "--output-format", code: 0 },
|
|
200
|
+
});
|
|
201
|
+
assert.strictEqual(incompatible.compatibilityStatus().state, "incompatible");
|
|
202
|
+
|
|
203
|
+
const source = fs.readFileSync(path.join(__dirname, "core", "providers", "claude.js"), "utf8");
|
|
204
|
+
assert.ok(!source.includes('require("child_process")'), "provider adapter must return invocation data instead of spawning");
|
|
205
|
+
|
|
206
|
+
console.log("Claude provider OK");
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const assert = require("assert");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const { validateInvocation, validateProvider } = require("./core/providers/contract");
|
|
9
|
+
const { createCodexProvider } = require("./core/providers/codex");
|
|
10
|
+
const { getProvider } = require("./core/providers");
|
|
11
|
+
|
|
12
|
+
function deepFreeze(value) {
|
|
13
|
+
if (!value || typeof value !== "object" || Object.isFrozen(value)) return value;
|
|
14
|
+
for (const child of Object.values(value)) deepFreeze(child);
|
|
15
|
+
return Object.freeze(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const safeEnv = { PATH: "/fixture/bin", HOME: "/fixture/home", OPENAI_API_KEY: "fixture-not-a-real-key" };
|
|
19
|
+
let authState = { state: "authenticated", reason: null, method: "fixture" };
|
|
20
|
+
const provider = createCodexProvider({
|
|
21
|
+
hookTransport: false,
|
|
22
|
+
resolveExecutable: () => "/fixture/codex",
|
|
23
|
+
defaultModel: "gpt-5-codex",
|
|
24
|
+
buildEnv: () => ({ ...safeEnv }),
|
|
25
|
+
getAuthStatus: () => authState,
|
|
26
|
+
runCommand: (_binary, args) => {
|
|
27
|
+
if (args[0] === "--version") return { ok: true, output: "codex-cli 0.144.0", code: 0 };
|
|
28
|
+
if (args.join(" ") === "exec --help") return {
|
|
29
|
+
ok: true,
|
|
30
|
+
output: "--config --json --sandbox --image --model --skip-git-repo-check",
|
|
31
|
+
code: 0,
|
|
32
|
+
};
|
|
33
|
+
if (args.join(" ") === "exec resume --help") return {
|
|
34
|
+
ok: true,
|
|
35
|
+
output: "--config --json --image --model --skip-git-repo-check",
|
|
36
|
+
code: 0,
|
|
37
|
+
};
|
|
38
|
+
return { ok: false, output: "unexpected fixture command", code: 1 };
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
assert.strictEqual(validateProvider(provider), provider);
|
|
43
|
+
assert.strictEqual(provider.id, "codex");
|
|
44
|
+
assert.strictEqual(getProvider("codex").id, "codex", "built-in registry exposes Codex lazily");
|
|
45
|
+
assert.strictEqual(provider.label, "OpenAI Codex");
|
|
46
|
+
assert.strictEqual(provider.isAvailable(), true);
|
|
47
|
+
assert.strictEqual(provider.executable(), "/fixture/codex");
|
|
48
|
+
assert.strictEqual(provider.defaultModel(), "gpt-5-codex");
|
|
49
|
+
assert.deepStrictEqual(provider.modelChoices(), ["gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna"]);
|
|
50
|
+
assert.ok(!provider.modelChoices().includes("o4-mini"));
|
|
51
|
+
assert.deepStrictEqual(provider.compatibilityStatus(), {
|
|
52
|
+
state: "compatible",
|
|
53
|
+
version: "0.144.0",
|
|
54
|
+
reason: null,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
assert.strictEqual(provider.capabilities.resume.support, "native");
|
|
58
|
+
assert.strictEqual(provider.capabilities.readOnlyMode.support, "native");
|
|
59
|
+
assert.strictEqual(provider.capabilities.effort.support, "native");
|
|
60
|
+
assert.strictEqual(provider.capabilities.imageFlag.support, "native");
|
|
61
|
+
for (const key of ["budget", "worktree", "maxTurns"]) {
|
|
62
|
+
assert.strictEqual(provider.capabilities[key].support, "unsupported");
|
|
63
|
+
assert.ok(provider.capabilities[key].reason);
|
|
64
|
+
}
|
|
65
|
+
assert.strictEqual(provider.capabilities.partialStreaming.support, "unsupported");
|
|
66
|
+
assert.strictEqual(provider.capabilities.persistentUtilityStream.support, "unsupported");
|
|
67
|
+
assert.strictEqual(provider.capabilities.preToolHook.support, "native");
|
|
68
|
+
|
|
69
|
+
const freshContext = deepFreeze({
|
|
70
|
+
coreInstructions: "STABLE CORE",
|
|
71
|
+
dynamicContext: "DYNAMIC CONTEXT",
|
|
72
|
+
userPrompt: "USER SENTINEL",
|
|
73
|
+
fresh: true,
|
|
74
|
+
sessionId: "ignored-thread",
|
|
75
|
+
providerSettings: {
|
|
76
|
+
model: "gpt-5-codex",
|
|
77
|
+
effort: "high",
|
|
78
|
+
permissionMode: "plan",
|
|
79
|
+
budget: null,
|
|
80
|
+
worktree: false,
|
|
81
|
+
},
|
|
82
|
+
imagePaths: ["/fixture/one.png", "/fixture/two.png"],
|
|
83
|
+
});
|
|
84
|
+
const before = JSON.stringify(freshContext);
|
|
85
|
+
const fresh = validateInvocation(provider.buildMainInvocation(freshContext));
|
|
86
|
+
assert.strictEqual(JSON.stringify(freshContext), before, "frozen run context must not be mutated");
|
|
87
|
+
assert.deepStrictEqual(fresh.args, [
|
|
88
|
+
"exec",
|
|
89
|
+
"-c", `developer_instructions=${JSON.stringify("STABLE CORE")}`,
|
|
90
|
+
"-c", `model_reasoning_effort=${JSON.stringify("high")}`,
|
|
91
|
+
"--image", "/fixture/one.png", "/fixture/two.png",
|
|
92
|
+
"--json",
|
|
93
|
+
"--skip-git-repo-check",
|
|
94
|
+
"--sandbox", "read-only",
|
|
95
|
+
"--model", "gpt-5-codex",
|
|
96
|
+
"DYNAMIC CONTEXT\n\nUSER SENTINEL",
|
|
97
|
+
]);
|
|
98
|
+
assert.deepStrictEqual(fresh.env, safeEnv);
|
|
99
|
+
assert.strictEqual(fresh.stdin, null);
|
|
100
|
+
assert.ok(fresh.parserState.seenUsage instanceof Set);
|
|
101
|
+
assert.ok(!Object.prototype.hasOwnProperty.call(fresh.env, "CLAUDE_CODE_OAUTH_TOKEN"));
|
|
102
|
+
|
|
103
|
+
function simpleContext(overrides = {}) {
|
|
104
|
+
return deepFreeze({
|
|
105
|
+
coreInstructions: "CORE",
|
|
106
|
+
dynamicContext: "",
|
|
107
|
+
userPrompt: "PROMPT",
|
|
108
|
+
providerSettings: { budget: null, worktree: false },
|
|
109
|
+
...overrides,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const resumed = provider.buildMainInvocation(simpleContext({
|
|
114
|
+
resumeSessionId: "thread-1",
|
|
115
|
+
providerSettings: { effort: "medium", permissionMode: "plan", budget: null, worktree: false },
|
|
116
|
+
imagePaths: ["/fixture/resume.png"],
|
|
117
|
+
}));
|
|
118
|
+
assert.deepStrictEqual(resumed.args, [
|
|
119
|
+
"exec", "resume",
|
|
120
|
+
"-c", `developer_instructions=${JSON.stringify("CORE")}`,
|
|
121
|
+
"-c", `model_reasoning_effort=${JSON.stringify("medium")}`,
|
|
122
|
+
"-c", `sandbox_mode=${JSON.stringify("read-only")}`,
|
|
123
|
+
"--image", "/fixture/resume.png",
|
|
124
|
+
"--json",
|
|
125
|
+
"--skip-git-repo-check",
|
|
126
|
+
"--model", "gpt-5-codex",
|
|
127
|
+
"thread-1",
|
|
128
|
+
"PROMPT",
|
|
129
|
+
]);
|
|
130
|
+
assert.ok(!resumed.args.includes("--sandbox"));
|
|
131
|
+
assert.ok(resumed.args.indexOf("thread-1") > resumed.args.lastIndexOf("--model"));
|
|
132
|
+
|
|
133
|
+
const directResume = provider.buildMainInvocation(simpleContext({ sessionId: "thread-direct" }));
|
|
134
|
+
assert.ok(directResume.args.includes("--dangerously-bypass-approvals-and-sandbox"));
|
|
135
|
+
assert.ok(directResume.args.indexOf("--dangerously-bypass-approvals-and-sandbox") < directResume.args.indexOf("thread-direct"));
|
|
136
|
+
|
|
137
|
+
const continued = provider.buildMainInvocation(simpleContext({ continueSession: true, sessionId: "thread-continue" }));
|
|
138
|
+
assert.strictEqual(continued.args[1], "resume");
|
|
139
|
+
assert.ok(continued.args.includes("thread-continue"));
|
|
140
|
+
|
|
141
|
+
const freshIgnoringSession = provider.buildMainInvocation(simpleContext({ fresh: true, sessionId: "old-thread" }));
|
|
142
|
+
assert.strictEqual(freshIgnoringSession.args[1], "-c");
|
|
143
|
+
assert.ok(!freshIgnoringSession.args.includes("old-thread"));
|
|
144
|
+
|
|
145
|
+
assert.throws(
|
|
146
|
+
() => provider.buildMainInvocation(simpleContext({ continueSession: true })),
|
|
147
|
+
(error) => error && error.code === "INVALID_PROVIDER_CONTEXT",
|
|
148
|
+
);
|
|
149
|
+
for (const providerSettings of [
|
|
150
|
+
{ budget: 1, worktree: false },
|
|
151
|
+
{ budget: null, worktree: true },
|
|
152
|
+
]) {
|
|
153
|
+
assert.throws(
|
|
154
|
+
() => provider.buildMainInvocation(simpleContext({ providerSettings })),
|
|
155
|
+
(error) => error && error.code === "UNSUPPORTED_PROVIDER_SETTING",
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
assert.throws(
|
|
159
|
+
() => provider.buildMainInvocation(simpleContext({ maxTurns: 2 })),
|
|
160
|
+
(error) => error && error.code === "UNSUPPORTED_PROVIDER_SETTING",
|
|
161
|
+
);
|
|
162
|
+
assert.throws(
|
|
163
|
+
() => provider.buildMainInvocation(simpleContext({ voiceStream: true })),
|
|
164
|
+
(error) => error && error.code === "UNSUPPORTED_PROVIDER_CAPABILITY",
|
|
165
|
+
);
|
|
166
|
+
assert.throws(
|
|
167
|
+
() => provider.buildMainInvocation(simpleContext({ providerSettings: { effort: "max", budget: null, worktree: false } })),
|
|
168
|
+
(error) => error && error.code === "UNSUPPORTED_PROVIDER_SETTING",
|
|
169
|
+
);
|
|
170
|
+
assert.throws(
|
|
171
|
+
() => provider.buildMainInvocation(deepFreeze({ dynamicContext: "only", userPrompt: "raw" })),
|
|
172
|
+
(error) => error && error.code === "MISSING_CORE_INSTRUCTIONS",
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const utility = validateInvocation(provider.buildUtilityInvocation(deepFreeze({
|
|
176
|
+
coreInstructions: "UTILITY CORE",
|
|
177
|
+
userPrompt: "UTILITY PROMPT",
|
|
178
|
+
readOnly: true,
|
|
179
|
+
tier: "low",
|
|
180
|
+
outputSchemaPath: "/fixture/schema.json",
|
|
181
|
+
})));
|
|
182
|
+
assert.ok(utility.args.includes("--ephemeral"));
|
|
183
|
+
assert.strictEqual(utility.args[utility.args.indexOf("--model") + 1], "gpt-5.6-luna");
|
|
184
|
+
assert.strictEqual(utility.args[utility.args.indexOf("--output-schema") + 1], "/fixture/schema.json");
|
|
185
|
+
assert.deepStrictEqual(
|
|
186
|
+
utility.args.slice(utility.args.indexOf("--sandbox"), utility.args.indexOf("--sandbox") + 2),
|
|
187
|
+
["--sandbox", "read-only"],
|
|
188
|
+
);
|
|
189
|
+
assert.strictEqual(utility.args.at(-1), "-", "Codex utility invocation reads its protected prompt from stdin");
|
|
190
|
+
assert.strictEqual(utility.stdin, "UTILITY PROMPT");
|
|
191
|
+
assert.ok(!utility.args.includes("UTILITY PROMPT"));
|
|
192
|
+
|
|
193
|
+
const decoder = provider.createEventDecoder();
|
|
194
|
+
const raw = decoder.push(Buffer.from('{"type":"thread.started","thread_id":"bound-thread"}\n'));
|
|
195
|
+
assert.deepStrictEqual(provider.normalizeEvent(raw[0], fresh.parserState), [{ type: "session", sessionId: "bound-thread" }]);
|
|
196
|
+
|
|
197
|
+
assert.strictEqual(provider.authStatus().state, "authenticated");
|
|
198
|
+
assert.strictEqual(provider.preflightAuth(), null);
|
|
199
|
+
authState = { state: "unauthenticated", reason: "login required" };
|
|
200
|
+
const authFailure = provider.preflightAuth();
|
|
201
|
+
assert.strictEqual(authFailure.code, "PROVIDER_UNAUTHENTICATED");
|
|
202
|
+
assert.match(authFailure.message, /Codex authentication/i);
|
|
203
|
+
assert.match(provider.authHelp(), /codex_login/);
|
|
204
|
+
|
|
205
|
+
const missing = createCodexProvider({ hookTransport: false, resolveExecutable: () => null, getAuthStatus: () => ({ state: "not_checked", reason: "missing" }) });
|
|
206
|
+
assert.strictEqual(missing.isAvailable(), false);
|
|
207
|
+
assert.throws(
|
|
208
|
+
() => missing.buildMainInvocation(simpleContext()),
|
|
209
|
+
(error) => error && error.code === "NO_AVAILABLE_PROVIDER",
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const incompatible = createCodexProvider({
|
|
213
|
+
hookTransport: false,
|
|
214
|
+
resolveExecutable: () => "/fixture/old-codex",
|
|
215
|
+
buildEnv: () => ({ PATH: "/fixture" }),
|
|
216
|
+
getAuthStatus: () => ({ state: "unknown", reason: "not checked" }),
|
|
217
|
+
runCommand: (_binary, args) => {
|
|
218
|
+
if (args[0] === "--version") return { ok: true, output: "codex-cli 0.1.0", code: 0 };
|
|
219
|
+
if (args.join(" ") === "exec --help") return { ok: true, output: "--json", code: 0 };
|
|
220
|
+
return { ok: true, output: "--json", code: 0 };
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
assert.strictEqual(incompatible.compatibilityStatus().state, "incompatible");
|
|
224
|
+
|
|
225
|
+
const source = fs.readFileSync(path.join(__dirname, "core", "providers", "codex.js"), "utf8");
|
|
226
|
+
assert.ok(!source.includes('require("child_process")'), "provider adapter must return invocation data instead of spawning");
|
|
227
|
+
|
|
228
|
+
console.log("Codex provider OK");
|