mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-17 03:39:33 +01:00
feat(agent-skill): turn the Codeman agent skill on by default
An absent `agentSkillEnabled` now means on, on the server (`getAgentSkillEnabled()` reads `!== false`, like `workspaceHooksEnabled`) and on the page (the App Settings switch loads `!== false`, so a Save of any other setting no longer writes the old default back). Only an explicit false turns it off. A partial settings PUT that omits the key leaves it as stored, since the route merges the request into the file. The switch's help text says it is on by default, that the copy stays out of git, and that turning it off removes no copy already written. The shared route-test mock now defaults to on too, so route tests see what a user sees. Tests: quick-start against a real server (absent key injects, a partial PUT keeps it on, an explicit false stays off through a later partial PUT), the real openAppSettings/saveAppSettings in JSDOM (absent shows on, explicit false shows off, a Save on a never-touched install sends true and passes the schema), and the plain create route at the mock's default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ba9d311cb7
commit
b3f0ba9e29
11 files changed
+297
-45
No files matched your search
+55
-30
@@ -353,49 +353,63 @@ describe('Agent skill injection (agentSkillEnabled)', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('does not inject by default, accepts the setting via PUT, then injects on quick-start', async () => {
|
||||
// 1. Default OFF: a claude quick-start creates the case without the skill.
|
||||
const offCase = 'test-skill-off-' + Date.now();
|
||||
createdCases.push(offCase);
|
||||
const offResponse = await fetch(`${baseUrl}/api/quick-start`, {
|
||||
// The tests below run in order against one server and one settings.json: absent key
|
||||
// (on), a partial PUT that omits it (still on), then an explicit false (off).
|
||||
const skillDirOf = (caseName: string) => join(CASES_DIR, caseName, '.claude', 'skills', 'codeman');
|
||||
|
||||
async function quickStart(prefix: string, mode?: string): Promise<string> {
|
||||
const caseName = `${prefix}-${Date.now()}`;
|
||||
createdCases.push(caseName);
|
||||
const response = await fetch(`${baseUrl}/api/quick-start`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ caseName: offCase }),
|
||||
body: JSON.stringify(mode ? { caseName, mode } : { caseName }),
|
||||
});
|
||||
const offData = await offResponse.json();
|
||||
expect(offData.success).toBe(true);
|
||||
expect(existsSync(join(CASES_DIR, offCase, '.claude', 'skills', 'codeman'))).toBe(false);
|
||||
expect((await response.json()).success).toBe(true);
|
||||
return caseName;
|
||||
}
|
||||
|
||||
// 2. The `.strict()` settings schema accepts the new synced key.
|
||||
const putResponse = await fetch(`${baseUrl}/api/settings`, {
|
||||
async function putSettings(body: Record<string, unknown>): Promise<void> {
|
||||
const response = await fetch(`${baseUrl}/api/settings`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ agentSkillEnabled: true }),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const putData = await putResponse.json();
|
||||
expect(putData.success).toBe(true);
|
||||
|
||||
// 3. The server's settings read is cached ~2s; outwait it so the create sees the toggle.
|
||||
expect((await response.json()).success).toBe(true);
|
||||
// The server's settings read is cached ~2s; outwait it so the next create sees the change.
|
||||
await new Promise((resolve) => setTimeout(resolve, 2100));
|
||||
}
|
||||
|
||||
// 4. Quick-start now injects the marker-carrying skill into the new case.
|
||||
const onCase = 'test-skill-on-' + Date.now();
|
||||
createdCases.push(onCase);
|
||||
const onResponse = await fetch(`${baseUrl}/api/quick-start`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ caseName: onCase }),
|
||||
});
|
||||
const onData = await onResponse.json();
|
||||
expect(onData.success).toBe(true);
|
||||
/** What settings.json holds, read back through GET /api/settings (enveloped or not). */
|
||||
async function storedSettings(): Promise<Record<string, unknown>> {
|
||||
const body = (await (await fetch(`${baseUrl}/api/settings`)).json()) as Record<string, unknown>;
|
||||
const settings = (body.success === true ? body.data : body) as Record<string, unknown>;
|
||||
// Not vacuous: every quick-start above records the case it used.
|
||||
expect(settings).toHaveProperty('lastUsedCase');
|
||||
return settings;
|
||||
}
|
||||
|
||||
it('injects by default: a settings.json without the key means on', async () => {
|
||||
const caseName = await quickStart('test-skill-default');
|
||||
// A quick-start writes lastUsedCase, never this key.
|
||||
expect(await storedSettings()).not.toHaveProperty('agentSkillEnabled');
|
||||
|
||||
const skillDir = join(CASES_DIR, onCase, '.claude', 'skills', 'codeman');
|
||||
const { readFileSync } = await import('node:fs');
|
||||
const skillMd = readFileSync(join(skillDir, 'SKILL.md'), 'utf-8');
|
||||
const skillMd = readFileSync(join(skillDirOf(caseName), 'SKILL.md'), 'utf-8');
|
||||
expect(skillMd.startsWith('---\nname: codeman')).toBe(true);
|
||||
expect(skillMd).toContain('<!-- codeman-managed-agent-skill');
|
||||
expect(existsSync(join(skillDir, 'reference', 'endpoints.md'))).toBe(true);
|
||||
expect(existsSync(join(skillDir, 'reference', 'recipes.md'))).toBe(true);
|
||||
expect(existsSync(join(skillDirOf(caseName), 'reference', 'endpoints.md'))).toBe(true);
|
||||
expect(existsSync(join(skillDirOf(caseName), 'reference', 'recipes.md'))).toBe(true);
|
||||
// The copy ignores itself in git, so the default leaves a repository's status clean.
|
||||
expect(readFileSync(join(skillDirOf(caseName), '.gitignore'), 'utf-8')).toBe('*\n');
|
||||
}, 30000);
|
||||
|
||||
it('a partial settings PUT that omits the key keeps it on', async () => {
|
||||
await putSettings({ autoNameSessions: false });
|
||||
expect(await storedSettings()).not.toHaveProperty('agentSkillEnabled');
|
||||
|
||||
const caseName = await quickStart('test-skill-partial');
|
||||
expect(existsSync(join(skillDirOf(caseName), 'SKILL.md'))).toBe(true);
|
||||
}, 30000);
|
||||
|
||||
it('does not inject for shell-mode quick-start even when enabled', async () => {
|
||||
@@ -410,4 +424,15 @@ describe('Agent skill injection (agentSkillEnabled)', () => {
|
||||
expect(data.success).toBe(true);
|
||||
expect(existsSync(join(CASES_DIR, shellCase, '.claude', 'skills', 'codeman'))).toBe(false);
|
||||
});
|
||||
|
||||
it('an explicit false turns it off, and a later partial PUT leaves it off', async () => {
|
||||
// The `.strict()` settings schema accepts the synced key.
|
||||
await putSettings({ agentSkillEnabled: false });
|
||||
await putSettings({ autoNameSessions: true });
|
||||
expect((await storedSettings()).agentSkillEnabled).toBe(false);
|
||||
|
||||
const caseName = await quickStart('test-skill-off');
|
||||
expect(existsSync(join(CASES_DIR, caseName))).toBe(true);
|
||||
expect(existsSync(skillDirOf(caseName))).toBe(false);
|
||||
}, 30000);
|
||||
});
|
||||
Reference in new issue
Block a user