Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(codex): 斜杠技能在任务自己的 app-server 上解析 (makecindy#15809)
* fix(codex): 斜杠技能在任务自己的 app-server 上解析

远程工作区、独立 Codex 账号和受邀者任务的技能目录只存在于该任务自己的
app-server。原来解析 `/技能名` 时走全局工具主机:找不到这些技能时会把命令
当成普通文本发出,本机还会为此额外拉起一个 app-server。改为用当前任务的
主机列出技能。

Assisted-by: Cindy (https://cindy.app)
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(codex): 隔离本地 OAuth 会话的斜杠技能查询

Assisted-by: Cindy (https://cindy.app)
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

* fix(codex): 保留独立运行目录的斜杠技能查询

Assisted-by: Cindy (https://cindy.app)
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>

---------

Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
  • Loading branch information
dashhuang authored Dec 5, 2026
commit 528277ef13ad39055f34a74d8fe2b95146b62003
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ async function startHosted(fixture: Fixture) {
recordCodexThreadLocation,
};
const agent = new CodexAgent(deps);
// 斜杠技能解析走工具宿主的技能清单;测试里直接给出同一份清单。
Object.defineProperty(agent, 'listSkillsForCwd', {
value: async () => ({ skills: skillList(), errors: [] }),
});
agents.push(agent);

function skillList() {
Expand Down Expand Up @@ -371,7 +367,7 @@ async function startHosted(fixture: Fixture) {
};
const started = agent.startSession({
sessionId: 'hosted-session',
model: 'gpt-5.5',
model: fixture.guestProvider?.modelIds[0] ?? 'gpt-5.5',
...(fixture.guest ? { providerId: fixture.providerId ?? SHARED_PROVIDER.providerId } : {}),
workingDir,
permissionMode: fixture.permissionMode ?? 'acceptEdits',
Expand Down Expand Up @@ -1064,17 +1060,25 @@ describe('Codex device-hosted guest sessions', () => {
});

it.each([
['guest', true, 'private', false],
['guest', true, 'guest', true],
['same-account', false, 'private', true],
] as const)('resolves a leading slash Skill for a %s session only from allowed Skills (/%s)', async (_label, guest, name, resolved) => {
const fixture = await startHosted({ guest, guestHome: guest });
['guest', 'private', true, false, undefined],
['guest', 'guest', true, true, undefined],
['custom-provider guest', 'private', true, false, 'xai'],
['custom-provider guest', 'guest', true, true, 'xai'],
['same-account', 'private', false, true, undefined],
] as const)('resolves a leading slash Skill for a %s session only from allowed Skills (/%s)', async (_label, name, guest, resolved, providerId) => {
const fixture = await startHosted({
guest,
...(providerId ? { providerId, guestProvider: { ...SHARED_PROVIDER, providerId, modelIds: ['xai/grok-4.3'] } } : {}),
});
const handle = await fixture.started;
await handle.send({ type: 'user', content: `/${name} go` });
const turn = threadParams(fixture.request, Method.TurnStart);
const skillInputs = (turn.input as Array<{ type: string; path?: string }>).filter((item) => item.type === 'skill');
const expectedPath = name === 'guest' ? fixture.guestSkill : fixture.hostSkill;
expect(skillInputs.map((item) => item.path)).toEqual(resolved ? [expectedPath] : []);
if (guest) {
expect(fixture.getHost).not.toHaveBeenCalledWith(undefined, 'provider-oauth', expect.objectContaining({ hostPurpose: 'control-plane' }));
}
await handle.close();
});

Expand Down
69 changes: 69 additions & 0 deletions packages/maker-core/src/agents/codex/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9359,6 +9359,75 @@ describe('CodexAgent MCP thread context hooks', () => {
},
);

// 依据:远程 / 独立账号任务的技能目录只在该任务自己的 app-server 上;用全局工具主机解析
// 斜杠会找不到技能(原样发文本)或多起一个本机 app-server。
// 最小失败输入:远程或 account-b 任务发送 `/release ...`,旧实现第二个 transport 出现且输入为纯文本。tier: unit。
it.each(['remote', 'account'] as const)('resolves slash Skills on the active %s host without starting a utility server', async (kind) => {
const cwd = '/isolated/project';
const skillPath = '/isolated/skills/release/SKILL.md';
const agent = new CodexAgent(createDeps({}, {
isCodexAccountProvider: id => id === 'account-b',
getRemoteCodexTransport: () => {
const transport = new MockCodexTransport();
createdTransports.push(transport);
return transport;
},
}));
try {
const handle = await agent.startSession({ sessionId: `slash-${kind}`, model: 'gpt-5.4', workingDir: cwd,
...(kind === 'remote' ? { remoteHostId: 'remote-skills' } : { providerId: 'account-b' }) });
expect(createdTransports).toHaveLength(1);
const transport = createdTransports[0]!;
transport.setMockResponse(Method.SkillsList, { result: { data: [{ cwd, skills: [{
name: 'release', description: 'Release this project', path: skillPath, scope: 'user', enabled: true,
}], errors: [] }] } });
transport.setMockResponse(Method.TurnStart, { result: { turn: { id: 'slash-turn' } } });
await handle.send({ type: 'user', content: '/release Prepare release notes' });
const turn = transport.lines.map(line => JSON.parse(line)).find(item => item.method === Method.TurnStart);
expect(turn.params.input).toEqual([
{ type: 'skill', name: 'release', path: skillPath },
{ type: 'text', text: 'Prepare release notes' },
]);
expect(createdTransports).toHaveLength(1);
await handle.close();
} finally { await agent.dispose(); }
});

it('resolves local provider OAuth slash Skills without listing on the live task host', async () => {
const cwd = '/repo-xai';
const skillPath = '/skills/release/SKILL.md';
const agent = new CodexAgent(createDeps({}, {
prepareCodexExtraSpawnConfig: async (_providers, context) => ({
extraArgs: [],
extraEnv: {},
codexProxyActive: context.credentialMode === 'provider-oauth',
}),
}));
try {
const handle = await agent.startSession({
sessionId: 'slash-local-provider-oauth', providerId: 'xai', model: 'xai/grok-4.3', workingDir: cwd,
});
expect(createdTransports).toHaveLength(1);
const taskTransport = createdTransports[0]!;
MockCodexTransport.onCreate = (transport) => {
transport.setMockResponse(Method.SkillsList, { result: { data: [{ cwd, skills: [{
name: 'release', description: 'Release this project', path: skillPath, scope: 'user', enabled: true,
}], errors: [] }] } });
};

await handle.send({ type: 'user', content: '/release Prepare release notes' });

const taskRequests = taskTransport.lines.map(line => JSON.parse(line));
expect(taskRequests.some(request => request.method === Method.SkillsList)).toBe(false);
expect(taskRequests.find(request => request.method === Method.TurnStart)?.params.input).toEqual([
{ type: 'skill', name: 'release', path: skillPath },
{ type: 'text', text: 'Prepare release notes' },
]);
expect(createdTransports).toHaveLength(2);
await handle.close();
} finally { await agent.dispose(); }
});

it('lists remote skills through the target remote app-server host', async () => {
const remoteWorkingDir = '/srv/project';
MockCodexTransport.onCreate = (transport) => {
Expand Down
93 changes: 41 additions & 52 deletions packages/maker-core/src/agents/codex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6150,59 +6150,48 @@ assertRouteCurrent();
`Cindy Review requires Codex app-server 0.145.0 or newer for plugin and Skill isolation (current: ${initResp.userAgent ?? 'unknown'})`,
);
}
if (requiresCodexCapabilitySkillDiscovery(capabilityRoutingPolicy)) {
try {
// Local custom providers use a dedicated control-plane host so skills/list
// cannot reload a reused ChatGPT OAuth session host. Remote sessions must
// keep discovery on their daemon because its cwd and CODEX_HOME are remote.
// See: https://github.com/makecindy/cindy/issues/3467
const useLocalSkillDiscoveryHost =
!opts.remoteHostId && sessionCredentialMode === 'provider-oauth';
const skillDiscoveryHostKey = useLocalSkillDiscoveryHost
? codexLocalAuthHostIdentity(localControlPlaneHostKey('provider-oauth'), 'isolated')
: currentHostKey;
const skillDiscoveryHost = useLocalSkillDiscoveryHost
? await this.getHost(undefined, 'provider-oauth', {
keyOverride: skillDiscoveryHostKey,
localAuthPolicy: 'isolated',
hostPurpose: 'control-plane',
})
: host;
const skillDiscoveryHostGeneration = useLocalSkillDiscoveryHost
? (this.hostGenerations.get(skillDiscoveryHostKey) ?? 0)
: hostGeneration;
const assertCurrentSkillDiscoveryHost = (): void => {
assertCurrentHost('capability Skill discovery');
if (!useLocalSkillDiscoveryHost) return;
if (
this.hosts.get(skillDiscoveryHostKey) === skillDiscoveryHost
&& (this.hostGenerations.get(skillDiscoveryHostKey) ?? 0)
=== skillDiscoveryHostGeneration
) {
return;
}
log.warn('codex Skill discovery rejected after control-plane host replacement', {
hostKey: skillDiscoveryHostKey,
credentialMode: sessionCredentialMode,
});
throw new Error(
'Codex Skill discovery expired because its control-plane app-server was replaced',
);
};
assertCurrentSkillDiscoveryHost();
// Local custom providers without a scoped runtime home use a control-plane
// host so skills/list cannot reload a reused ChatGPT OAuth session host.
// A scoped home (including guests) or a remote daemon owns its own catalog.
// See: https://github.com/makecindy/cindy/issues/3467
const skillDiscoveryHostKey = !opts.remoteHostId && !sessionStorage && sessionCredentialMode === 'provider-oauth'
? codexLocalAuthHostIdentity(localControlPlaneHostKey('provider-oauth'), 'isolated')
: null;
const listSessionSkills = async (timeoutMs?: number, startupCatalog?: typeof refreshedSkills) => {
assertCurrentHost('Skill discovery');
if (skillDiscoveryHostKey === null) {
// Reuse the force-reloaded catalog just fetched on this same host and
// cwd right after prepareCodexSkills, avoiding a duplicate skills/list RPC.
// provider-oauth uses an isolated control-plane host (#3467) and always queries it.
const { skills, errors } =
!useLocalSkillDiscoveryHost && refreshedSkills
? refreshedSkills
: await this.listSkillsForHost(
skillDiscoveryHost,
opts.workingDir,
false,
CRITICAL_THREAD_RPC_TIMEOUT_MS,
);
assertCurrentSkillDiscoveryHost();
const catalog = startupCatalog ?? await this.listSkillsForHost(host, opts.workingDir, false, timeoutMs);
assertCurrentHost('Skill discovery');
return catalog;
}
const skillDiscoveryHost = await this.getHost(undefined, 'provider-oauth', {
keyOverride: skillDiscoveryHostKey,
localAuthPolicy: 'isolated',
hostPurpose: 'control-plane',
});
const skillDiscoveryHostGeneration = this.hostGenerations.get(skillDiscoveryHostKey) ?? 0;
const assertCurrentSkillDiscoveryHost = (): void => {
assertCurrentHost('Skill discovery');
if (
this.hosts.get(skillDiscoveryHostKey) === skillDiscoveryHost
&& (this.hostGenerations.get(skillDiscoveryHostKey) ?? 0) === skillDiscoveryHostGeneration
) return;
log.warn('codex Skill discovery rejected after control-plane host replacement', {
hostKey: skillDiscoveryHostKey,
credentialMode: sessionCredentialMode,
});
throw new Error('Codex Skill discovery expired because its control-plane app-server was replaced');
};
assertCurrentSkillDiscoveryHost();
const catalog = await this.listSkillsForHost(skillDiscoveryHost, opts.workingDir, false, timeoutMs);
assertCurrentSkillDiscoveryHost();
return catalog;
};
if (requiresCodexCapabilitySkillDiscovery(capabilityRoutingPolicy)) {
try {
const { skills, errors } = await listSessionSkills(CRITICAL_THREAD_RPC_TIMEOUT_MS, refreshedSkills);
capabilityRoutingConfig = {
...capabilityRoutingConfig,
...buildCodexCapabilitySkillConfigOverrides(capabilityRoutingPolicy, [
Expand Down Expand Up @@ -7746,7 +7735,7 @@ assertRouteCurrent();
if (!slash) return toAppServerInput(content, opts.workingDir);

try {
const { skills } = await this.listSkillsForCwd(opts.workingDir, false);
const { skills } = await listSessionSkills();
// 受邀者:斜杠只解析它自己带来的技能与 Codex 自带技能,不把本机用户的技能文件交给模型。
const skill = selectInvocableCodexSkill(
guestSkillAllowed ? skills.filter((candidate) => guestSkillAllowed(candidate.path, candidate.scope)) : skills,
Expand Down