@ktkid/kmh-codex-cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +295 -2
- package/bin/README.md +25 -0
- package/bin/codex +36 -0
- package/bin/runtime-receipt.json +9 -0
- package/bin/version +1 -0
- package/cordis.patch.yml +7 -0
- package/lib/browser-types/src/account-status.d.ts +9 -0
- package/lib/browser-types/src/client/ComposerQuota.d.ts +10 -0
- package/lib/browser-types/src/client/DetailCard.d.ts +12 -0
- package/lib/browser-types/src/client/LiveBall.d.ts +19 -0
- package/lib/browser-types/src/client/QuotaCard.d.ts +20 -0
- package/lib/browser-types/src/client/QuotaDisplaySettings.d.ts +6 -0
- package/lib/browser-types/src/client/index.d.ts +18 -0
- package/lib/browser-types/src/client/locales.d.ts +54 -0
- package/lib/browser-types/src/client/quota-store.d.ts +56 -0
- package/lib/browser-types/src/live-state.d.ts +31 -0
- package/lib/browser-types/src/quota-protocol.d.ts +135 -0
- package/lib/browser-types/src/quota-rules.d.ts +18 -0
- package/lib/browser-types/src/tool-switches.d.ts +63 -0
- package/lib/client.js +21396 -0
- package/lib/src/account-status.d.ts +9 -0
- package/lib/src/account-status.js +1 -0
- package/lib/src/account.d.ts +35 -0
- package/lib/src/account.js +173 -0
- package/lib/src/adapter.d.ts +22 -0
- package/lib/src/adapter.js +221 -0
- package/lib/src/approval.d.ts +48 -0
- package/lib/src/approval.js +235 -0
- package/lib/src/capabilities.d.ts +40 -0
- package/lib/src/capabilities.js +85 -0
- package/lib/src/config.d.ts +69 -0
- package/lib/src/config.js +75 -0
- package/lib/src/connection.d.ts +65 -0
- package/lib/src/connection.js +178 -0
- package/lib/src/cursor.d.ts +54 -0
- package/lib/src/cursor.js +325 -0
- package/lib/src/image-delivery.d.ts +36 -0
- package/lib/src/image-delivery.js +65 -0
- package/lib/src/imagegen.d.ts +21 -0
- package/lib/src/imagegen.js +132 -0
- package/lib/src/index.d.ts +141 -0
- package/lib/src/index.js +534 -0
- package/lib/src/isolation.d.ts +61 -0
- package/lib/src/isolation.js +298 -0
- package/lib/src/live-state.d.ts +31 -0
- package/lib/src/live-state.js +14 -0
- package/lib/src/models.d.ts +24 -0
- package/lib/src/models.js +98 -0
- package/lib/src/native-items.d.ts +59 -0
- package/lib/src/native-items.js +122 -0
- package/lib/src/native-tools/catalog.d.ts +29 -0
- package/lib/src/native-tools/catalog.js +197 -0
- package/lib/src/probe.d.ts +17 -0
- package/lib/src/probe.js +54 -0
- package/lib/src/protocol.d.ts +508 -0
- package/lib/src/protocol.js +511 -0
- package/lib/src/quota-protocol.d.ts +135 -0
- package/lib/src/quota-protocol.js +97 -0
- package/lib/src/quota-rules.d.ts +18 -0
- package/lib/src/quota-rules.js +49 -0
- package/lib/src/quota.d.ts +32 -0
- package/lib/src/quota.js +227 -0
- package/lib/src/session-store.d.ts +592 -0
- package/lib/src/session-store.js +275 -0
- package/lib/src/status.d.ts +19 -0
- package/lib/src/status.js +69 -0
- package/lib/src/tool-policy.d.ts +47 -0
- package/lib/src/tool-policy.js +454 -0
- package/lib/src/tool-registry.d.ts +42 -0
- package/lib/src/tool-registry.js +70 -0
- package/lib/src/tool-selection.d.ts +88 -0
- package/lib/src/tool-selection.js +60 -0
- package/lib/src/tool-switches-service.d.ts +24 -0
- package/lib/src/tool-switches-service.js +129 -0
- package/lib/src/tool-switches.d.ts +63 -0
- package/lib/src/tool-switches.js +43 -0
- package/lib/src/turn.d.ts +200 -0
- package/lib/src/turn.js +1012 -0
- package/lib/src/web.d.ts +9 -0
- package/lib/src/web.js +143 -0
- package/package.json +171 -4
- package/vendor/codex/LICENSE +201 -0
- package/vendor/codex/NOTICE +4 -0
- package/vendor/codex/models.json +1613 -0
- package/vendor/native-tools/0.162.0-alpha.17.2.json +143 -0
- package/vendor/native-tools/0.163.0-alpha.10.2.json +128 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** 依据已验证的 CLI 版本解析原生工具;未知版本保留待核实状态。 */
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import { type CliToolRow } from "../tool-selection.ts";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import type { Config } from "../config.ts";
|
|
6
|
+
import type { NativeSelection } from "../capabilities.ts";
|
|
7
|
+
/** 当前版本的工具目录及独立诊断。 */
|
|
8
|
+
export interface NativeCatalog {
|
|
9
|
+
version: string;
|
|
10
|
+
rows: CliToolRow[];
|
|
11
|
+
overrides: string[];
|
|
12
|
+
diagnostic?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Codex config/read returns null for feature flags without a resolved boolean. */
|
|
15
|
+
export declare const configResponse: z.ZodObject<{
|
|
16
|
+
config: z.ZodObject<{
|
|
17
|
+
features: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodBoolean>>>;
|
|
18
|
+
}, z.core.$loose>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
/**
|
|
21
|
+
* 发现实际版本和 MCP 名称;可调整项只来自通过执行拒绝测试的版本。
|
|
22
|
+
* @param ctx 提供受管 subprocess 的插件上下文。
|
|
23
|
+
* @param config CLI 部署配置。
|
|
24
|
+
* @param legacy 原生技能及固定工具既有状态。
|
|
25
|
+
* @param signal 本次发现的取消信号。
|
|
26
|
+
* @param cwd 本次会话工作目录。
|
|
27
|
+
* @returns 完整已确认目录、诊断和进程配置覆盖。
|
|
28
|
+
*/
|
|
29
|
+
export declare function discoverNativeTools(ctx: Context, config: Config, legacy: NativeSelection, signal: AbortSignal, cwd: string): Promise<NativeCatalog>;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { ToolSourceId } from "../tool-selection.js";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { connectCodex } from "../connection.js";
|
|
7
|
+
const declaration = z
|
|
8
|
+
.object({
|
|
9
|
+
type: z.string(),
|
|
10
|
+
name: z.string().optional(),
|
|
11
|
+
description: z.string().optional(),
|
|
12
|
+
})
|
|
13
|
+
.passthrough();
|
|
14
|
+
const manifestSchema = z.object({
|
|
15
|
+
version: z.string(),
|
|
16
|
+
declarations: z.array(declaration),
|
|
17
|
+
});
|
|
18
|
+
/** Codex config/read returns null for feature flags without a resolved boolean. */
|
|
19
|
+
export const configResponse = z.object({
|
|
20
|
+
config: z
|
|
21
|
+
.object({
|
|
22
|
+
features: z.record(z.string(), z.boolean().nullable()).optional(),
|
|
23
|
+
})
|
|
24
|
+
.passthrough(),
|
|
25
|
+
});
|
|
26
|
+
const mcpResponse = z.object({
|
|
27
|
+
data: z.array(z.object({
|
|
28
|
+
name: z.string(),
|
|
29
|
+
tools: z.record(z.string(), z
|
|
30
|
+
.object({ name: z.string(), description: z.string().optional() })
|
|
31
|
+
.passthrough()),
|
|
32
|
+
})),
|
|
33
|
+
nextCursor: z.string().nullable().optional(),
|
|
34
|
+
});
|
|
35
|
+
const source = ToolSourceId("codex/native");
|
|
36
|
+
/** 通过受管子进程读取实际版本,完成或取消均等待进程退出。 */
|
|
37
|
+
async function versionOf(ctx, config, signal) {
|
|
38
|
+
signal.throwIfAborted();
|
|
39
|
+
const executable = await ctx.subprocess.resolveExecutable(config.command, config.env, signal);
|
|
40
|
+
signal.throwIfAborted();
|
|
41
|
+
const child = ctx.subprocess.spawn({
|
|
42
|
+
argv: [executable, "--version"],
|
|
43
|
+
cwd: config.cwd,
|
|
44
|
+
env: config.env,
|
|
45
|
+
graceMs: config.graceMs,
|
|
46
|
+
stdio: { stdin: "ignore", stdout: "pipe", stderr: "pipe" },
|
|
47
|
+
});
|
|
48
|
+
const stop = () => {
|
|
49
|
+
child.terminate();
|
|
50
|
+
};
|
|
51
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
52
|
+
if (signal.aborted)
|
|
53
|
+
stop();
|
|
54
|
+
try {
|
|
55
|
+
let text = "";
|
|
56
|
+
for await (const chunk of child.stdout ?? []) {
|
|
57
|
+
text += String(chunk);
|
|
58
|
+
if (text.length > 8192)
|
|
59
|
+
throw new Error("CODEX_VERSION_OUTPUT_TOO_LARGE");
|
|
60
|
+
}
|
|
61
|
+
await child.done;
|
|
62
|
+
signal.throwIfAborted();
|
|
63
|
+
const version = /^codex-cli ([^\s]+)$/m.exec(text)?.[1];
|
|
64
|
+
if (version === undefined)
|
|
65
|
+
throw new Error("CODEX_VERSION_UNKNOWN");
|
|
66
|
+
return version;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
signal.removeEventListener("abort", stop);
|
|
70
|
+
child.terminate();
|
|
71
|
+
await child.done.catch(() => undefined);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 发现实际版本和 MCP 名称;可调整项只来自通过执行拒绝测试的版本。
|
|
76
|
+
* @param ctx 提供受管 subprocess 的插件上下文。
|
|
77
|
+
* @param config CLI 部署配置。
|
|
78
|
+
* @param legacy 原生技能及固定工具既有状态。
|
|
79
|
+
* @param signal 本次发现的取消信号。
|
|
80
|
+
* @param cwd 本次会话工作目录。
|
|
81
|
+
* @returns 完整已确认目录、诊断和进程配置覆盖。
|
|
82
|
+
*/
|
|
83
|
+
export async function discoverNativeTools(ctx, config, legacy, signal, cwd) {
|
|
84
|
+
const version = await versionOf(ctx, config, signal);
|
|
85
|
+
let manifest;
|
|
86
|
+
try {
|
|
87
|
+
const path = join(dirname(fileURLToPath(import.meta.url)), "../../../vendor/native-tools", `${version}.json`);
|
|
88
|
+
manifest = manifestSchema.parse(JSON.parse(await readFile(path, "utf8")));
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return {
|
|
92
|
+
version,
|
|
93
|
+
rows: [],
|
|
94
|
+
overrides: [],
|
|
95
|
+
diagnostic: `CODEX_NATIVE_VERSION_UNVERIFIED: ${version}; ${error instanceof Error ? error.message : String(error)}`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const rows = manifest.declarations.map((item) => {
|
|
99
|
+
const name = item.name ?? item.type;
|
|
100
|
+
const control = name === "exec_command" || name === "write_stdin"
|
|
101
|
+
? { kind: "linked", group: "command-execution" }
|
|
102
|
+
: name === "apply_patch" ||
|
|
103
|
+
name === "view_image" ||
|
|
104
|
+
name === "web_search"
|
|
105
|
+
? { kind: "adjustable" }
|
|
106
|
+
: {
|
|
107
|
+
kind: "fixed",
|
|
108
|
+
enabled: legacy.webSearch,
|
|
109
|
+
reason: "Provider-side execution control is unverified; the existing choice is retained.",
|
|
110
|
+
};
|
|
111
|
+
const captured = z.json().parse(item);
|
|
112
|
+
return {
|
|
113
|
+
side: "native",
|
|
114
|
+
source,
|
|
115
|
+
name,
|
|
116
|
+
description: item.description ?? "",
|
|
117
|
+
declaration: captured,
|
|
118
|
+
control,
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
rows.push({
|
|
122
|
+
side: "native",
|
|
123
|
+
source,
|
|
124
|
+
name: "shell_command",
|
|
125
|
+
description: "Legacy command handler registered with unified exec.",
|
|
126
|
+
control: { kind: "linked", group: "command-execution" },
|
|
127
|
+
});
|
|
128
|
+
rows.push({
|
|
129
|
+
side: "native",
|
|
130
|
+
source,
|
|
131
|
+
name: "update_plan",
|
|
132
|
+
description: "Plan handler retained by Codex.",
|
|
133
|
+
control: {
|
|
134
|
+
kind: "fixed",
|
|
135
|
+
enabled: true,
|
|
136
|
+
reason: "Codex keeps the plan handler registered independently of its visible declaration.",
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
const connection = await connectCodex(ctx, {
|
|
140
|
+
command: config.command,
|
|
141
|
+
cwd,
|
|
142
|
+
configOverrides: [],
|
|
143
|
+
env: config.env,
|
|
144
|
+
graceMs: config.graceMs,
|
|
145
|
+
startupTimeoutMs: config.startupTimeoutMs,
|
|
146
|
+
}, signal);
|
|
147
|
+
try {
|
|
148
|
+
const effective = configResponse.parse(await connection.request("config/read", { cwd, includeLayers: false }, signal));
|
|
149
|
+
if (effective.config.features?.["unified_exec"] === false) {
|
|
150
|
+
return {
|
|
151
|
+
version,
|
|
152
|
+
rows: rows.map((row) => ({
|
|
153
|
+
...row,
|
|
154
|
+
control: {
|
|
155
|
+
kind: "unverified",
|
|
156
|
+
reason: "The effective unified_exec=false configuration needs its own compatibility fixture.",
|
|
157
|
+
},
|
|
158
|
+
})),
|
|
159
|
+
overrides: [],
|
|
160
|
+
diagnostic: "CODEX_NATIVE_CONFIG_UNVERIFIED: unified_exec=false",
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
let cursor;
|
|
164
|
+
const cursors = new Set();
|
|
165
|
+
do {
|
|
166
|
+
const response = mcpResponse.parse(await connection.request("mcpServerStatus/list", {
|
|
167
|
+
...(cursor === undefined ? {} : { cursor }),
|
|
168
|
+
detail: "toolsAndAuthOnly",
|
|
169
|
+
}, signal));
|
|
170
|
+
for (const server of response.data) {
|
|
171
|
+
for (const [name, tool] of Object.entries(server.tools)) {
|
|
172
|
+
rows.push({
|
|
173
|
+
side: "native",
|
|
174
|
+
source: ToolSourceId(`codex/mcp/${server.name}`),
|
|
175
|
+
sourceLabel: server.name,
|
|
176
|
+
name,
|
|
177
|
+
description: tool.description ?? "",
|
|
178
|
+
control: {
|
|
179
|
+
kind: "fixed",
|
|
180
|
+
enabled: true,
|
|
181
|
+
reason: "MCP per-tool execution control needs a verified fixture; the current server remains active.",
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
cursor = response.nextCursor ?? undefined;
|
|
187
|
+
if (cursor !== undefined && cursors.has(cursor))
|
|
188
|
+
throw new Error("CODEX_MCP_CURSOR_REPEATED");
|
|
189
|
+
if (cursor !== undefined)
|
|
190
|
+
cursors.add(cursor);
|
|
191
|
+
} while (cursor !== undefined);
|
|
192
|
+
return { version, rows, overrides: [] };
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
await connection.stop(config.cleanupTimeoutMs);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** 详情页测试连接:独立临时会话内对当前模型发短请求并回收。 */
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type { Config } from "./config.ts";
|
|
4
|
+
import type { NativeSelection } from "./capabilities.ts";
|
|
5
|
+
/** 测试连接结果。 */
|
|
6
|
+
export interface ProbeResult {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 用当前选择的模型执行短文本请求验证可用性。
|
|
12
|
+
* @param ctx - 宿主上下文。
|
|
13
|
+
* @param config - 插件配置。
|
|
14
|
+
* @param model - 详情页当前选择的模型。
|
|
15
|
+
* @param selection - 原生能力逐项选择(临时会话同样遵守隔离语义)。
|
|
16
|
+
*/
|
|
17
|
+
export declare function probeConnection(ctx: Context, config: Config, model: string, selection: NativeSelection): Promise<ProbeResult>;
|
package/lib/src/probe.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { connectCodex } from "./connection.js";
|
|
2
|
+
import { prepareIsolation } from "./isolation.js";
|
|
3
|
+
import { CodexTurn } from "./turn.js";
|
|
4
|
+
/**
|
|
5
|
+
* 用当前选择的模型执行短文本请求验证可用性。
|
|
6
|
+
* @param ctx - 宿主上下文。
|
|
7
|
+
* @param config - 插件配置。
|
|
8
|
+
* @param model - 详情页当前选择的模型。
|
|
9
|
+
* @param selection - 原生能力逐项选择(临时会话同样遵守隔离语义)。
|
|
10
|
+
*/
|
|
11
|
+
export async function probeConnection(ctx, config, model, selection) {
|
|
12
|
+
const signal = AbortSignal.timeout(config.probeTimeoutMs);
|
|
13
|
+
const plan = await prepareIsolation(ctx, config, {
|
|
14
|
+
cwd: config.cwd,
|
|
15
|
+
signal,
|
|
16
|
+
selection,
|
|
17
|
+
});
|
|
18
|
+
const connection = await connectCodex(ctx, {
|
|
19
|
+
command: config.command,
|
|
20
|
+
cwd: config.cwd,
|
|
21
|
+
configOverrides: plan.configOverrides,
|
|
22
|
+
env: config.env,
|
|
23
|
+
graceMs: config.graceMs,
|
|
24
|
+
startupTimeoutMs: config.startupTimeoutMs,
|
|
25
|
+
}, signal);
|
|
26
|
+
const turn = new CodexTurn(ctx, config, config.cwd);
|
|
27
|
+
try {
|
|
28
|
+
turn.adopt(connection);
|
|
29
|
+
await turn.start({
|
|
30
|
+
content: [{ type: "text", text: "ping" }],
|
|
31
|
+
model,
|
|
32
|
+
baseInstructions: "Reply with the single word: pong.",
|
|
33
|
+
tools: [],
|
|
34
|
+
}, undefined, signal);
|
|
35
|
+
for await (const _chunk of turn.pump(signal))
|
|
36
|
+
void _chunk;
|
|
37
|
+
return turn.terminalStatus === "completed"
|
|
38
|
+
? { ok: true }
|
|
39
|
+
: {
|
|
40
|
+
ok: false,
|
|
41
|
+
error: `CODEX_PROBE_STATUS_${turn.terminalStatus ?? "unknown"}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return {
|
|
46
|
+
ok: false,
|
|
47
|
+
error: error instanceof Error ? error.message : String(error),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
await turn.dispose();
|
|
52
|
+
await connection.stop(config.cleanupTimeoutMs);
|
|
53
|
+
}
|
|
54
|
+
}
|