Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): pin Learn dispatch and preserve skill bundles

xd-bobof944cca90fa0
diff --git a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py
index 18b81f74d1..aed0ad7ad5 100644
--- a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py
+++ b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py
@@ -6,6 +6,9 @@ import sys
from decimal import Decimal
from pathlib import Path
+# These helpers execute from Cindy's content-addressed built-in Skill bundle.
+# Keep the whole local import chain from mutating that immutable directory.
+sys.dont_write_bytecode = True
VENDOR_ROOT = Path(__file__).resolve().parent / "_vendor"
sys.path.insert(0, str(VENDOR_ROOT))
diff --git a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/generate_openai_yaml.py b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/generate_openai_yaml.py
index bc1cde829e..6c0e81697e 100644
--- a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/generate_openai_yaml.py
+++ b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/generate_openai_yaml.py
@@ -10,6 +10,9 @@ import argparse
import sys
from pathlib import Path
+# This script runs inside Cindy's content-addressed built-in Skill bundle.
+sys.dont_write_bytecode = True
+
from _frontmatter import FrontmatterError, parse_frontmatter, split_frontmatter
ACRONYMS = {
diff --git a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/init_skill.py b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/init_skill.py
index dde3fafdf0..fe8830fdaf 100644
--- a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/init_skill.py
+++ b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/init_skill.py
@@ -19,6 +19,9 @@ import shutil
import sys
from pathlib import Path
+# This script runs inside Cindy's content-addressed built-in Skill bundle.
+sys.dont_write_bytecode = True
+
from generate_openai_yaml import render_openai_yaml
MAX_SKILL_NAME_LENGTH = 64
diff --git a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/quick_validate.py b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/quick_validate.py
index c07c1ba236..23c476ccc3 100644
--- a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/quick_validate.py
+++ b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/quick_validate.py
@@ -7,6 +7,9 @@ import re
import sys
from pathlib import Path
+# This script runs inside Cindy's content-addressed built-in Skill bundle.
+sys.dont_write_bytecode = True
+
from _frontmatter import FrontmatterError, parse_frontmatter, split_frontmatter
MAX_SKILL_NAME_LENGTH = 64
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
index bdac7850bc..728f14cd97 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/makerSendTransaction.test.ts
@@ -5,6 +5,7 @@ import {
INHERITED_CAPABILITY_SELECTION,
appendAutoReviewUserIntent,
MAIN_OWNED_SEND_CONTEXT,
+ PINNED_SKILL_INVOCATION,
type AgentKind,
type SessionSendOptions,
type SessionSendResult,
@@ -253,6 +254,11 @@ describe('maker SEND transaction', () => {
'{"text":"/learn release flow","slashCommandRanges":[{"start":0,"end":6}]}',
'/learn release flow',
);
+ const sendOptions = vi.mocked(session.send).mock.calls[0]?.[1];
+ expect(sendOptions?.[PINNED_SKILL_INVOCATION]).toEqual({
+ name: 'learn',
+ path: grant.resolvedSkillPath,
+ });
expect(deps.createDbMessage).toHaveBeenCalledWith(
'session-1',
expect.objectContaining({
diff --git a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
index 8e191631ff..eb22df4bcf 100644
--- a/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
+++ b/apps/desktop/src/main/maker-ipc/makerSendTransaction.ts
@@ -5,6 +5,7 @@ import {
AUTO_REVIEW_USER_INTENT,
INHERITED_CAPABILITY_SELECTION,
MAIN_OWNED_SEND_CONTEXT,
+ PINNED_SKILL_INVOCATION,
LIBRARY_READ_ROOT,
type AgentKind,
type MainOwnedSendContext,
@@ -1436,6 +1437,14 @@ export function createMakerSendTransaction(deps: MakerSendTransactionDeps): Make
...(so[INHERITED_CAPABILITY_SELECTION] !== undefined
? { [INHERITED_CAPABILITY_SELECTION]: so[INHERITED_CAPABILITY_SELECTION] }
: {}),
+ ...(cindyLearnInvocation
+ ? {
+ [PINNED_SKILL_INVOCATION]: {
+ name: 'learn',
+ path: cindyLearnInvocation.resolvedSkillPath,
+ },
+ }
+ : {}),
...(restoredAutoReviewIntent !== undefined
? { [AUTO_REVIEW_USER_INTENT]: restoredAutoReviewIntent }
: {}),
diff --git a/packages/maker-core/src/agents/base-agent.ts b/packages/maker-core/src/agents/base-agent.ts
index c631da5ada..573b99ed6f 100644
--- a/packages/maker-core/src/agents/base-agent.ts
+++ b/packages/maker-core/src/agents/base-agent.ts
@@ -1914,6 +1914,17 @@ export const AUTO_REVIEW_USER_INTENT = Symbol('cindy.auto-review-user-intent');
/** Main-only selection from the original input for a retained-history continuation. */
export const INHERITED_CAPABILITY_SELECTION = Symbol('cindy.inherited-capability-selection');
+/**
+ * Main-attested Skill winner for this exact send. Symbol keys cannot cross the
+ * Renderer/device-link boundary, so only a Host dispatcher can pin a path.
+ */
+export const PINNED_SKILL_INVOCATION = Symbol('cindy.pinned-skill-invocation');
+
+export interface PinnedSkillInvocation {
+ readonly name: string;
+ readonly path: string;
+}
+
export interface MainOwnedSendContext {
readonly origin: TurnPermissionOrigin;
/** Main-authenticated user text before channel/persona/context decoration. */
@@ -1928,6 +1939,8 @@ export interface SendOptions {
readonly [AUTO_REVIEW_SOURCE_CONTENT]?: UserMessage['content'];
readonly [AUTO_REVIEW_USER_INTENT]?: AutoReviewUserIntent;
readonly [INHERITED_CAPABILITY_SELECTION]?: string;
+ /** Exact Skill selected by a Host authorization check for this send. */
+ readonly [PINNED_SKILL_INVOCATION]?: PinnedSkillInvocation;
/** Host-authenticated metadata; never accept an equivalent string-keyed wire field. */
readonly [MAIN_OWNED_SEND_CONTEXT]?: MainOwnedSendContext;
/**
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index 9622200180..9e02d93d7e 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -12,6 +12,7 @@ import {
AUTO_REVIEW_SOURCE_CONTENT,
INHERITED_CAPABILITY_SELECTION,
MAIN_OWNED_SEND_CONTEXT,
+ PINNED_SKILL_INVOCATION,
CodexResumePreparationBlockedError,
AgentNotAuthenticatedError,
type AgentDeps,
@@ -6660,6 +6661,57 @@ describe('CodexAgent MCP thread context hooks', () => {
await handle.close();
});
+ it.each(['/learn release flow', '/skill:learn release flow'])(
+ 'dispatches the exact Host-attested Skill path for %s without rescanning a new winner',
+ async (command) => {
+ const pinnedPath = '/cindy/system-skills/v10/learn/SKILL.md';
+ let skillsListCalls = 0;
+ const agent = new CodexAgent(createDeps());
+ const host = installFakeHost(agent, (method, params) => {
+ if (method === Method.SkillsList) {
+ skillsListCalls += 1;
+ const { cwds = ['/repo'] } = params as { cwds?: string[] };
+ return {
+ data: cwds.map((cwd) => ({
+ cwd,
+ skills: [{
+ name: 'learn',
+ description: 'Untrusted replacement',
+ path: '/repo/.agents/skills/learn/SKILL.md',
+ scope: 'repo',
+ enabled: true,
+ }],
+ errors: [],
+ })),
+ };
+ }
+ if (method === Method.TurnStart) return { turn: { id: 'turn-pinned-learn' } };
+ return undefined;
+ });
+ const handle = await agent.startSession({
+ sessionId: 'session-pinned-learn',
+ model: 'gpt-5.4',
+ workingDir: '/repo',
+ });
+
+ await handle.send(
+ { type: 'user', content: command },
+ { [PINNED_SKILL_INVOCATION]: { name: 'learn', path: pinnedPath } },
+ );
+
+ const turnStart = host.request.mock.calls.find(
+ ([method]) => method === Method.TurnStart,
+ )?.[1] as { input?: unknown[] };
+ expect(turnStart.input).toEqual([
+ { type: 'skill', name: 'learn', path: pinnedPath },
+ { type: 'text', text: 'release flow' },
+ ]);
+ expect(skillsListCalls).toBe(0);
+
+ await handle.close();
+ },
+ );
+
it.each(['system', 'admin'] as const)(
'keeps a palette-hidden %s Skill directly invocable',
async (scope) => {
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index f9a9b355a8..860d61be90 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -30,6 +30,7 @@ import { structuredPatch } from 'diff';
import {
BaseAgent,
INHERITED_CAPABILITY_SELECTION,
+ PINNED_SKILL_INVOCATION,
CodexResumePreparationBlockedError,
OneShotError,
AgentNotAuthenticatedError,
@@ -40,6 +41,7 @@ import {
type CodexExtraSpawnConfig,
type StartSessionOptions,
type OneShotOptions,
+ type PinnedSkillInvocation,
type RefreshLocalModelsOptions,
type SendOptions,
type TurnPermissionPolicy,
@@ -6155,16 +6157,46 @@ export class CodexAgent extends BaseAgent {
return undefined;
}
- const toTurnInput = async (content: UserMessage['content']): Promise<UserInput[]> => {
+ const toTurnInput = async (
+ content: UserMessage['content'],
+ pinnedSkill?: PinnedSkillInvocation,
+ ): Promise<UserInput[]> => {
if (reviewMode) {
+ if (pinnedSkill) {
+ throw new Error('A pinned Skill invocation is not allowed in review mode');
+ }
await assertReviewMessageContentPaths(content, opts.workingDir, reviewReadGrants);
// Review never resolves leading slash text as a user/project Skill. Its
// prompt and evidence must stay independent from task customizations.
return toAppServerInput(content, opts.workingDir);
}
- if (typeof content !== 'string') return toAppServerInput(content, opts.workingDir);
+ if (typeof content !== 'string') {
+ if (pinnedSkill) {
+ throw new Error('A pinned Skill invocation requires a text command');
+ }
+ return toAppServerInput(content, opts.workingDir);
+ }
const slash = parseLeadingSlashToken(content.trim());
+ if (pinnedSkill) {
+ const normalizedSlashName = slash?.name.toLowerCase();
+ const normalizedSkillName = pinnedSkill.name.toLowerCase();
+ if (
+ !slash
+ || (normalizedSlashName !== normalizedSkillName
+ && normalizedSlashName !== `skill:${normalizedSkillName}`)
+ ) {
+ throw new Error('The pinned Skill does not match the dispatched command');
+ }
+ const inputs: UserInput[] = [{
+ type: 'skill',
+ name: pinnedSkill.name,
+ path: pinnedSkill.path,
+ }];
+ const prompt = slash.rest.trim();
+ if (prompt) inputs.push({ type: 'text', text: prompt });
+ return inputs;
+ }
if (!slash) return toAppServerInput(content, opts.workingDir);
try {
@@ -12705,7 +12737,10 @@ export class CodexAgent extends BaseAgent {
}
let turnInput: TurnStartParams['input'];
try {
- turnInput = await toTurnInput(withLibraryNativeReadContext(message.content, mutableLibraryRoot, mutableExtraDirs));
+ turnInput = await toTurnInput(
+ withLibraryNativeReadContext(message.content, mutableLibraryRoot, mutableExtraDirs),
+ sendOpts?.[PINNED_SKILL_INVOCATION],
+ );
} catch (e) {
isTurnStartPending = false;
flushDeferredTerminalTurnCompletionsIfIdle();
diff --git a/scripts/__tests__/third-party-notices.test.mjs b/scripts/__tests__/third-party-notices.test.mjs
index f194deded5..6152acbc17 100644
--- a/scripts/__tests__/third-party-notices.test.mjs
+++ b/scripts/__tests__/third-party-notices.test.mjs
@@ -351,6 +351,26 @@ test("the bundled Skill validator accepts standard multiline YAML without extern
}
const skillDir = fs.mkdtempSync(path.join(os.tmpdir(), "cindy-skill-validator-"));
+ const bundledScriptsDir = path.join(
+ repoRoot,
+ "apps/desktop/resources/system-skills/cindy-skill-creator/scripts",
+ );
+ const bytecodeArtifacts = () => {
+ const artifacts = [];
+ const visit = directory => {
+ for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
+ const absolute = path.join(directory, entry.name);
+ if (entry.isDirectory()) {
+ if (entry.name === "__pycache__") artifacts.push(absolute);
+ visit(absolute);
+ } else if (entry.name.endsWith(".pyc")) {
+ artifacts.push(absolute);
+ }
+ }
+ };
+ visit(bundledScriptsDir);
+ return artifacts;
+ };
try {
const printableBoundaries = String.fromCodePoint(
0xa0,
@@ -386,6 +406,20 @@ metadata:
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
assert.match(result.stdout, /Skill is valid!/);
+ const generator = path.join(bundledScriptsDir, "generate_openai_yaml.py");
+ const generated = spawnSync(command, [...prefix, "-S", generator, skillDir], {
+ encoding: "utf8",
+ });
+ assert.equal(generated.status, 0, `${generated.stdout}\n${generated.stderr}`);
+
+ const initializer = path.join(bundledScriptsDir, "init_skill.py");
+ const initialized = spawnSync(
+ command,
+ [...prefix, "-S", initializer, "bytecode-regression", "--path", skillDir],
+ { encoding: "utf8" },
+ );
+ assert.equal(initialized.status, 0, `${initialized.stdout}\n${initialized.stderr}`);
+
fs.writeFileSync(
path.join(skillDir, "SKILL.md"),
"---\nname: on\ndescription: yes\n---\n# js-yaml scalar compatibility\n",
@@ -463,6 +497,11 @@ metadata:
});
assert.notEqual(rejected.status, 0);
assert.match(rejected.stdout, /special characters are not allowed/);
+ assert.deepEqual(
+ bytecodeArtifacts(),
+ [],
+ "bundled Python helpers must not mutate the content-addressed Skill with bytecode caches",
+ );
} finally {
fs.rmSync(skillDir, { recursive: true, force: true });
}