runwork 0.6.1 → 0.8.2

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.
Files changed (80) hide show
  1. package/dist/__tests__/install-scripts.test.d.ts +1 -0
  2. package/dist/__tests__/install-scripts.test.js +247 -0
  3. package/dist/agents/__tests__/claude-code-plugin.test.d.ts +1 -0
  4. package/dist/agents/__tests__/claude-code-plugin.test.js +47 -0
  5. package/dist/agents/__tests__/claude-code-stats.test.js +143 -78
  6. package/dist/agents/__tests__/claude-desktop-plugin-tree.test.d.ts +1 -0
  7. package/dist/agents/__tests__/claude-desktop-plugin-tree.test.js +161 -0
  8. package/dist/agents/__tests__/claude-desktop-plugin.test.d.ts +1 -0
  9. package/dist/agents/__tests__/claude-desktop-plugin.test.js +117 -0
  10. package/dist/agents/__tests__/claude-desktop-rpm.test.d.ts +1 -0
  11. package/dist/agents/__tests__/claude-desktop-rpm.test.js +126 -0
  12. package/dist/agents/__tests__/codex-instructions.test.d.ts +1 -0
  13. package/dist/agents/__tests__/codex-instructions.test.js +57 -0
  14. package/dist/agents/__tests__/codex-stats.test.js +9 -0
  15. package/dist/agents/__tests__/graceful-degradation.test.js +3 -3
  16. package/dist/agents/__tests__/intro-skill.test.js +11 -2
  17. package/dist/agents/__tests__/skill-slug.test.d.ts +1 -0
  18. package/dist/agents/__tests__/skill-slug.test.js +77 -0
  19. package/dist/agents/claude-code.d.ts +3 -1
  20. package/dist/agents/claude-code.js +233 -58
  21. package/dist/agents/claude-desktop-plugin-tree.d.ts +44 -0
  22. package/dist/agents/claude-desktop-plugin-tree.js +92 -0
  23. package/dist/agents/claude-desktop.d.ts +20 -1
  24. package/dist/agents/claude-desktop.js +238 -61
  25. package/dist/agents/cline.d.ts +3 -1
  26. package/dist/agents/cline.js +44 -2
  27. package/dist/agents/codex.d.ts +3 -1
  28. package/dist/agents/codex.js +85 -14
  29. package/dist/agents/cursor.d.ts +12 -1
  30. package/dist/agents/cursor.js +98 -25
  31. package/dist/agents/gemini.d.ts +3 -1
  32. package/dist/agents/gemini.js +42 -4
  33. package/dist/agents/generic-adapter.d.ts +3 -1
  34. package/dist/agents/generic-adapter.js +59 -4
  35. package/dist/agents/intro-skill.js +77 -31
  36. package/dist/agents/types.d.ts +42 -2
  37. package/dist/agents/types.js +61 -6
  38. package/dist/agents/utils/instruction-hint.d.ts +10 -0
  39. package/dist/agents/utils/instruction-hint.js +46 -0
  40. package/dist/agents/utils/json-config.d.ts +6 -1
  41. package/dist/agents/utils/json-config.js +31 -4
  42. package/dist/agents/windsurf.d.ts +3 -1
  43. package/dist/agents/windsurf.js +37 -2
  44. package/dist/commands/__tests__/sync-telemetry.test.d.ts +1 -0
  45. package/dist/commands/__tests__/sync-telemetry.test.js +281 -0
  46. package/dist/commands/__tests__/upgrade.test.d.ts +1 -0
  47. package/dist/commands/__tests__/upgrade.test.js +174 -0
  48. package/dist/commands/build-plugin.d.ts +2 -0
  49. package/dist/commands/build-plugin.js +135 -0
  50. package/dist/commands/init.d.ts +8 -2
  51. package/dist/commands/init.js +19 -7
  52. package/dist/commands/sync-telemetry.d.ts +33 -0
  53. package/dist/commands/sync-telemetry.js +186 -0
  54. package/dist/commands/sync.d.ts +1 -0
  55. package/dist/commands/sync.js +84 -118
  56. package/dist/commands/uninstall.d.ts +2 -0
  57. package/dist/commands/uninstall.js +145 -0
  58. package/dist/commands/upgrade.d.ts +12 -0
  59. package/dist/commands/upgrade.js +67 -16
  60. package/dist/generated/bundled-types.js +36 -36
  61. package/dist/generated/version.d.ts +1 -1
  62. package/dist/generated/version.js +1 -1
  63. package/dist/health/__tests__/cli-distribution-checks.test.d.ts +1 -0
  64. package/dist/health/__tests__/cli-distribution-checks.test.js +199 -0
  65. package/dist/health/checks.d.ts +2 -0
  66. package/dist/health/checks.js +131 -18
  67. package/dist/health/runner.js +6 -2
  68. package/dist/index.js +4 -0
  69. package/dist/sync/executor.d.ts +2 -0
  70. package/dist/sync/executor.js +8 -4
  71. package/dist/types.d.ts +2 -0
  72. package/dist/ui/banner.js +15 -6
  73. package/dist/utils/__tests__/sqlite.test.js +84 -72
  74. package/dist/utils/sqlite-adapter.d.ts +48 -0
  75. package/dist/utils/sqlite-adapter.js +147 -0
  76. package/dist/utils/sqlite.d.ts +12 -5
  77. package/dist/utils/sqlite.js +12 -22
  78. package/dist/utils/zip.d.ts +6 -0
  79. package/dist/utils/zip.js +28 -3
  80. package/package.json +2 -4
@@ -0,0 +1,161 @@
1
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { tmpdir } from 'os';
5
+ import { writePluginMcpConfig, writePluginMetadata, writePluginSkills, writePluginTeamInstructions, writePluginTree, } from '../claude-desktop-plugin-tree.js';
6
+ describe('claude-desktop plugin-tree helpers', () => {
7
+ let workDir;
8
+ beforeEach(() => {
9
+ workDir = mkdtempSync(join(tmpdir(), 'runwork-plugin-tree-'));
10
+ });
11
+ afterEach(() => {
12
+ rmSync(workDir, { recursive: true, force: true });
13
+ });
14
+ describe('writePluginMetadata', () => {
15
+ it('writes .claude-plugin/plugin.json with the expected shape', () => {
16
+ writePluginMetadata(workDir, {
17
+ pluginName: 'runwork',
18
+ pluginVersion: '1.0.0',
19
+ description: 'Skills and tools from your Runwork workspace',
20
+ authorName: 'Runwork',
21
+ });
22
+ const raw = readFileSync(join(workDir, '.claude-plugin', 'plugin.json'), 'utf-8');
23
+ const parsed = JSON.parse(raw);
24
+ expect(parsed).toEqual({
25
+ name: 'runwork',
26
+ version: '1.0.0',
27
+ description: 'Skills and tools from your Runwork workspace',
28
+ author: { name: 'Runwork' },
29
+ });
30
+ });
31
+ });
32
+ describe('writePluginMcpConfig', () => {
33
+ it('wraps entries under mcpServers and embeds the bearer token in the URL', () => {
34
+ const servers = [
35
+ {
36
+ name: 'Runwork',
37
+ url: 'https://runwork.ai/api/workspaces/abc/mcp',
38
+ transport: 'streamable-http',
39
+ headers: { Authorization: 'Bearer rk_test_token' },
40
+ description: 'Workspace tools',
41
+ },
42
+ ];
43
+ writePluginMcpConfig(workDir, servers);
44
+ const raw = readFileSync(join(workDir, '.mcp.json'), 'utf-8');
45
+ const parsed = JSON.parse(raw);
46
+ expect(Object.keys(parsed.mcpServers)).toEqual(['Runwork']);
47
+ const entry = parsed.mcpServers['Runwork'];
48
+ expect(entry.type).toBe('http');
49
+ expect(entry.url).toBe('https://runwork.ai/api/workspaces/abc/mcp?token=rk_test_token');
50
+ expect(entry.description).toBe('Workspace tools');
51
+ });
52
+ it('leaves the URL untouched when no Authorization header is present', () => {
53
+ const servers = [
54
+ {
55
+ name: 'Public Server',
56
+ url: 'https://example.com/mcp',
57
+ transport: 'streamable-http',
58
+ },
59
+ ];
60
+ writePluginMcpConfig(workDir, servers);
61
+ const parsed = JSON.parse(readFileSync(join(workDir, '.mcp.json'), 'utf-8'));
62
+ expect(parsed.mcpServers['Public Server'].url).toBe('https://example.com/mcp');
63
+ expect(parsed.mcpServers['Public Server']).not.toHaveProperty('description');
64
+ });
65
+ });
66
+ describe('writePluginSkills', () => {
67
+ it('writes one SKILL.md per skill in kebab-cased directories', () => {
68
+ const skills = [
69
+ {
70
+ name: 'Write Cold Email',
71
+ filename: 'write-cold-email',
72
+ content: 'Draft a cold email.',
73
+ description: 'Write Cold Email - Runwork workspace skill',
74
+ },
75
+ {
76
+ name: 'Blog Writing Specialist',
77
+ filename: 'blog-writing-specialist',
78
+ content: '---\nname: blog-writing-specialist\ndescription: existing\n---\n\nBody',
79
+ description: 'Blog skill',
80
+ },
81
+ ];
82
+ writePluginSkills(workDir, skills);
83
+ expect(existsSync(join(workDir, 'skills', 'write-cold-email', 'SKILL.md'))).toBe(true);
84
+ expect(existsSync(join(workDir, 'skills', 'blog-writing-specialist', 'SKILL.md'))).toBe(true);
85
+ const coldEmail = readFileSync(join(workDir, 'skills', 'write-cold-email', 'SKILL.md'), 'utf-8');
86
+ expect(coldEmail).toContain('name: write-cold-email');
87
+ expect(coldEmail).toContain('Draft a cold email.');
88
+ });
89
+ it('removes legacy directories named with spaces from prior sync runs', () => {
90
+ const legacyDir = join(workDir, 'skills', 'Write Cold Email');
91
+ writePluginSkills(workDir, [
92
+ {
93
+ name: 'Write Cold Email',
94
+ filename: 'write-cold-email',
95
+ content: 'original',
96
+ description: 'original',
97
+ },
98
+ ]);
99
+ // First write creates kebab dir only — nothing to clean up yet.
100
+ expect(existsSync(legacyDir)).toBe(false);
101
+ // Simulate a legacy dir left behind from an earlier sync then re-run.
102
+ const { mkdirSync, writeFileSync } = require('fs');
103
+ mkdirSync(legacyDir, { recursive: true });
104
+ writeFileSync(join(legacyDir, 'SKILL.md'), 'stale');
105
+ writePluginSkills(workDir, [
106
+ {
107
+ name: 'Write Cold Email',
108
+ filename: 'write-cold-email',
109
+ content: 'refreshed',
110
+ description: 'refreshed',
111
+ },
112
+ ]);
113
+ expect(existsSync(legacyDir)).toBe(false);
114
+ expect(existsSync(join(workDir, 'skills', 'write-cold-email', 'SKILL.md'))).toBe(true);
115
+ });
116
+ });
117
+ describe('writePluginTeamInstructions', () => {
118
+ it('writes a runwork-team-instructions SKILL.md with YAML frontmatter', () => {
119
+ writePluginTeamInstructions(workDir, 'Always reply in British English.\n- Second rule.');
120
+ const skillPath = join(workDir, 'skills', 'runwork-team-instructions', 'SKILL.md');
121
+ expect(existsSync(skillPath)).toBe(true);
122
+ const content = readFileSync(skillPath, 'utf-8');
123
+ expect(content.startsWith('---\n')).toBe(true);
124
+ expect(content).toContain('name: runwork-team-instructions');
125
+ expect(content).toContain('description: Team instructions');
126
+ expect(content).toContain('Always reply in British English.');
127
+ expect(content).toContain('- Second rule.');
128
+ });
129
+ });
130
+ describe('writePluginTree', () => {
131
+ it('writes metadata, mcp config, and skills in one call', () => {
132
+ writePluginTree(workDir, {
133
+ pluginName: 'runwork',
134
+ pluginVersion: '1.0.0',
135
+ description: 'Skills and tools from your Runwork workspace',
136
+ authorName: 'Runwork',
137
+ skills: [
138
+ {
139
+ name: 'Runwork',
140
+ filename: 'runwork',
141
+ content: 'Intro skill',
142
+ description: 'Runwork intro',
143
+ },
144
+ ],
145
+ mcpServers: [
146
+ {
147
+ name: 'Runwork',
148
+ url: 'https://runwork.ai/api/workspaces/abc/mcp',
149
+ transport: 'streamable-http',
150
+ headers: { Authorization: 'Bearer rk_test' },
151
+ },
152
+ ],
153
+ });
154
+ expect(existsSync(join(workDir, '.claude-plugin', 'plugin.json'))).toBe(true);
155
+ expect(existsSync(join(workDir, '.mcp.json'))).toBe(true);
156
+ expect(existsSync(join(workDir, 'skills', 'runwork', 'SKILL.md'))).toBe(true);
157
+ const mcpJson = JSON.parse(readFileSync(join(workDir, '.mcp.json'), 'utf-8'));
158
+ expect(mcpJson.mcpServers['Runwork'].url).toContain('token=rk_test');
159
+ });
160
+ });
161
+ });
@@ -0,0 +1,117 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { tmpdir } from 'os';
5
+ let mockHomeDir = '/tmp/runwork-cli-tests';
6
+ vi.mock('os', async () => {
7
+ const actual = await vi.importActual('os');
8
+ return {
9
+ ...actual,
10
+ homedir: vi.fn(() => mockHomeDir),
11
+ platform: vi.fn(() => 'darwin'),
12
+ };
13
+ });
14
+ import { ClaudeDesktopAdapter } from '../claude-desktop.js';
15
+ const ACCOUNT_ID = 'account-id';
16
+ const ORG_ID = 'org-id';
17
+ function getClaudeRoot(homeDir) {
18
+ return join(homeDir, 'Library', 'Application Support', 'Claude');
19
+ }
20
+ function getCoworkOrgDir(homeDir) {
21
+ return join(getClaudeRoot(homeDir), 'local-agent-mode-sessions', ACCOUNT_ID, ORG_ID);
22
+ }
23
+ function getCoworkPluginsDir(homeDir) {
24
+ return join(getCoworkOrgDir(homeDir), 'cowork_plugins');
25
+ }
26
+ describe('ClaudeDesktopAdapter plugin registration', () => {
27
+ let tempHomeDir;
28
+ beforeEach(() => {
29
+ tempHomeDir = mkdtempSync(join(tmpdir(), 'runwork-cli-claude-desktop-'));
30
+ mockHomeDir = tempHomeDir;
31
+ const pluginsDir = getCoworkPluginsDir(tempHomeDir);
32
+ mkdirSync(pluginsDir, { recursive: true });
33
+ writeFileSync(join(pluginsDir, 'installed_plugins.json'), JSON.stringify({
34
+ version: 2,
35
+ plugins: {},
36
+ }));
37
+ writeFileSync(join(pluginsDir, 'known_marketplaces.json'), JSON.stringify({}));
38
+ });
39
+ afterEach(() => {
40
+ rmSync(tempHomeDir, { recursive: true, force: true });
41
+ });
42
+ it('re-enables the Runwork cowork plugin during sync', async () => {
43
+ const adapter = new ClaudeDesktopAdapter();
44
+ const coworkSettingsPath = join(getCoworkOrgDir(tempHomeDir), 'cowork_settings.json');
45
+ writeFileSync(coworkSettingsPath, JSON.stringify({
46
+ enabledPlugins: {
47
+ 'cowork-plugin-management@knowledge-work-plugins': true,
48
+ 'runwork@runwork': false,
49
+ },
50
+ }));
51
+ await adapter.writeSkills([{
52
+ name: 'Runwork',
53
+ filename: 'runwork',
54
+ content: '# Runwork',
55
+ description: 'Runwork intro skill',
56
+ }], 'user');
57
+ const settings = JSON.parse(readFileSync(coworkSettingsPath, 'utf-8'));
58
+ expect(settings.enabledPlugins?.['cowork-plugin-management@knowledge-work-plugins']).toBe(true);
59
+ expect(settings.enabledPlugins?.['runwork@runwork']).toBe(true);
60
+ });
61
+ it('writes cowork plugin mcp config using the mcpServers wrapper', async () => {
62
+ const adapter = new ClaudeDesktopAdapter();
63
+ const server = {
64
+ name: 'Runwork',
65
+ url: 'https://runwork.ai/api/workspaces/test/mcp',
66
+ transport: 'streamable-http',
67
+ headers: {
68
+ Authorization: 'Bearer test-token',
69
+ },
70
+ description: 'Runwork workspace tools',
71
+ };
72
+ await adapter.writeMcpServers([server], 'user');
73
+ const cacheMcpPath = join(getCoworkPluginsDir(tempHomeDir), 'cache', 'runwork', 'runwork', '1.0.0', '.mcp.json');
74
+ const marketplaceMcpPath = join(getCoworkPluginsDir(tempHomeDir), 'marketplaces', 'runwork', 'plugins', 'runwork', '.mcp.json');
75
+ const cacheConfig = JSON.parse(readFileSync(cacheMcpPath, 'utf-8'));
76
+ const marketplaceConfig = JSON.parse(readFileSync(marketplaceMcpPath, 'utf-8'));
77
+ expect(cacheConfig.mcpServers?.['Runwork']?.url).toBe('https://runwork.ai/api/workspaces/test/mcp?token=test-token');
78
+ expect(marketplaceConfig).toEqual(cacheConfig);
79
+ });
80
+ it('removes the cowork enable flag during cleanup', async () => {
81
+ const adapter = new ClaudeDesktopAdapter();
82
+ const pluginsDir = getCoworkPluginsDir(tempHomeDir);
83
+ const coworkSettingsPath = join(getCoworkOrgDir(tempHomeDir), 'cowork_settings.json');
84
+ const cacheDir = join(pluginsDir, 'cache', 'runwork', 'runwork', '1.0.0');
85
+ const marketplaceDir = join(pluginsDir, 'marketplaces', 'runwork');
86
+ mkdirSync(cacheDir, { recursive: true });
87
+ mkdirSync(marketplaceDir, { recursive: true });
88
+ writeFileSync(join(pluginsDir, 'installed_plugins.json'), JSON.stringify({
89
+ version: 2,
90
+ plugins: {
91
+ 'runwork@runwork': [{
92
+ scope: 'user',
93
+ installPath: cacheDir,
94
+ version: '1.0.0',
95
+ }],
96
+ },
97
+ }));
98
+ writeFileSync(join(pluginsDir, 'known_marketplaces.json'), JSON.stringify({
99
+ runwork: {
100
+ source: { source: 'directory', path: marketplaceDir },
101
+ installLocation: marketplaceDir,
102
+ },
103
+ }));
104
+ writeFileSync(coworkSettingsPath, JSON.stringify({
105
+ enabledPlugins: {
106
+ 'runwork@runwork': true,
107
+ 'cowork-plugin-management@knowledge-work-plugins': true,
108
+ },
109
+ }));
110
+ await adapter.cleanup('user');
111
+ const settings = JSON.parse(readFileSync(coworkSettingsPath, 'utf-8'));
112
+ expect(settings.enabledPlugins?.['runwork@runwork']).toBeUndefined();
113
+ expect(settings.enabledPlugins?.['cowork-plugin-management@knowledge-work-plugins']).toBe(true);
114
+ expect(existsSync(cacheDir)).toBe(false);
115
+ expect(existsSync(marketplaceDir)).toBe(false);
116
+ });
117
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,126 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { tmpdir } from 'os';
5
+ let mockHomeDir = '/tmp/runwork-cli-rpm-tests';
6
+ vi.mock('os', async () => {
7
+ const actual = await vi.importActual('os');
8
+ return {
9
+ ...actual,
10
+ homedir: vi.fn(() => mockHomeDir),
11
+ platform: vi.fn(() => 'darwin'),
12
+ };
13
+ });
14
+ import { ClaudeDesktopAdapter, findRpmPluginByName } from '../claude-desktop.js';
15
+ const SESSION_ID = 'test-session';
16
+ const ORG_ID = 'test-org';
17
+ function getOrgDir(homeDir) {
18
+ return join(homeDir, 'Library', 'Application Support', 'Claude', 'local-agent-mode-sessions', SESSION_ID, ORG_ID);
19
+ }
20
+ describe('findRpmPluginByName', () => {
21
+ let tempHomeDir;
22
+ beforeEach(() => {
23
+ tempHomeDir = mkdtempSync(join(tmpdir(), 'runwork-rpm-'));
24
+ mockHomeDir = tempHomeDir;
25
+ mkdirSync(getOrgDir(tempHomeDir), { recursive: true });
26
+ });
27
+ afterEach(() => {
28
+ rmSync(tempHomeDir, { recursive: true, force: true });
29
+ });
30
+ it('returns null when there is no rpm/ directory', () => {
31
+ expect(findRpmPluginByName('runwork')).toBeNull();
32
+ });
33
+ it('returns null when rpm/manifest.json is missing', () => {
34
+ mkdirSync(join(getOrgDir(tempHomeDir), 'rpm'), { recursive: true });
35
+ expect(findRpmPluginByName('runwork')).toBeNull();
36
+ });
37
+ it('returns null when the manifest does not list the plugin', () => {
38
+ const rpmDir = join(getOrgDir(tempHomeDir), 'rpm');
39
+ mkdirSync(rpmDir, { recursive: true });
40
+ writeFileSync(join(rpmDir, 'manifest.json'), JSON.stringify({
41
+ lastUpdated: Date.now(),
42
+ plugins: [
43
+ { id: 'plugin_other', name: 'other-plugin', marketplaceName: 'My Uploads' },
44
+ ],
45
+ }));
46
+ expect(findRpmPluginByName('runwork')).toBeNull();
47
+ });
48
+ it('returns the plugin path and org dir when the plugin is listed', () => {
49
+ const rpmDir = join(getOrgDir(tempHomeDir), 'rpm');
50
+ mkdirSync(rpmDir, { recursive: true });
51
+ writeFileSync(join(rpmDir, 'manifest.json'), JSON.stringify({
52
+ lastUpdated: Date.now(),
53
+ plugins: [
54
+ { id: 'plugin_other', name: 'other-plugin' },
55
+ { id: 'plugin_01ABC', name: 'runwork', marketplaceName: 'My Uploads' },
56
+ ],
57
+ }));
58
+ // The plugin directory itself doesn't need to exist for the lookup —
59
+ // we just read the manifest to learn where it lives.
60
+ const location = findRpmPluginByName('runwork');
61
+ expect(location).not.toBeNull();
62
+ expect(location?.pluginPath).toBe(join(rpmDir, 'plugin_01ABC'));
63
+ expect(location?.orgDir).toBe(getOrgDir(tempHomeDir));
64
+ });
65
+ it('handles malformed manifest.json gracefully', () => {
66
+ const rpmDir = join(getOrgDir(tempHomeDir), 'rpm');
67
+ mkdirSync(rpmDir, { recursive: true });
68
+ writeFileSync(join(rpmDir, 'manifest.json'), 'not-json');
69
+ expect(findRpmPluginByName('runwork')).toBeNull();
70
+ });
71
+ it('skips entries that are missing an id field', () => {
72
+ const rpmDir = join(getOrgDir(tempHomeDir), 'rpm');
73
+ mkdirSync(rpmDir, { recursive: true });
74
+ writeFileSync(join(rpmDir, 'manifest.json'), JSON.stringify({ plugins: [{ name: 'runwork' }] }));
75
+ expect(findRpmPluginByName('runwork')).toBeNull();
76
+ });
77
+ });
78
+ describe('ClaudeDesktopAdapter.cleanup with rpm plugin', () => {
79
+ let tempHomeDir;
80
+ beforeEach(() => {
81
+ tempHomeDir = mkdtempSync(join(tmpdir(), 'runwork-rpm-cleanup-'));
82
+ mockHomeDir = tempHomeDir;
83
+ mkdirSync(getOrgDir(tempHomeDir), { recursive: true });
84
+ });
85
+ afterEach(() => {
86
+ rmSync(tempHomeDir, { recursive: true, force: true });
87
+ });
88
+ it('removes rpm plugin directory and manifest entry, leaving other plugins intact', async () => {
89
+ const rpmDir = join(getOrgDir(tempHomeDir), 'rpm');
90
+ const runworkPluginDir = join(rpmDir, 'plugin_runwork_id');
91
+ const otherPluginDir = join(rpmDir, 'plugin_other_id');
92
+ mkdirSync(join(runworkPluginDir, 'skills', 'intro'), { recursive: true });
93
+ writeFileSync(join(runworkPluginDir, 'skills', 'intro', 'SKILL.md'), 'stale');
94
+ mkdirSync(otherPluginDir, { recursive: true });
95
+ writeFileSync(join(rpmDir, 'manifest.json'), JSON.stringify({
96
+ lastUpdated: 1,
97
+ plugins: [
98
+ { id: 'plugin_runwork_id', name: 'runwork', marketplaceName: 'My Uploads' },
99
+ { id: 'plugin_other_id', name: 'other-plugin', marketplaceName: 'knowledge-work-plugins' },
100
+ ],
101
+ }));
102
+ const adapter = new ClaudeDesktopAdapter();
103
+ await adapter.cleanup('user');
104
+ expect(existsSync(runworkPluginDir)).toBe(false);
105
+ expect(existsSync(otherPluginDir)).toBe(true);
106
+ const manifest = JSON.parse(readFileSync(join(rpmDir, 'manifest.json'), 'utf-8'));
107
+ expect(manifest.plugins).toEqual([
108
+ { id: 'plugin_other_id', name: 'other-plugin', marketplaceName: 'knowledge-work-plugins' },
109
+ ]);
110
+ expect(typeof manifest.lastUpdated).toBe('number');
111
+ expect(manifest.lastUpdated).toBeGreaterThan(1);
112
+ });
113
+ it('is a no-op when no rpm plugin is registered', async () => {
114
+ const rpmDir = join(getOrgDir(tempHomeDir), 'rpm');
115
+ mkdirSync(rpmDir, { recursive: true });
116
+ writeFileSync(join(rpmDir, 'manifest.json'), JSON.stringify({
117
+ lastUpdated: 1,
118
+ plugins: [{ id: 'plugin_other_id', name: 'other-plugin' }],
119
+ }));
120
+ const adapter = new ClaudeDesktopAdapter();
121
+ await adapter.cleanup('user');
122
+ const manifest = JSON.parse(readFileSync(join(rpmDir, 'manifest.json'), 'utf-8'));
123
+ expect(manifest.plugins).toHaveLength(1);
124
+ expect(manifest.plugins[0].name).toBe('other-plugin');
125
+ });
126
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'fs';
3
+ import { join } from 'path';
4
+ import { tmpdir } from 'os';
5
+ let mockHomeDir = '/tmp/runwork-cli-codex-instructions-tests';
6
+ vi.mock('os', async () => {
7
+ const actual = await vi.importActual('os');
8
+ return {
9
+ ...actual,
10
+ homedir: vi.fn(() => mockHomeDir),
11
+ platform: vi.fn(() => 'darwin'),
12
+ };
13
+ });
14
+ import { CodexAdapter } from '../codex.js';
15
+ describe('CodexAdapter user-scope instruction file', () => {
16
+ let tempHomeDir;
17
+ beforeEach(() => {
18
+ tempHomeDir = mkdtempSync(join(tmpdir(), 'runwork-codex-instr-'));
19
+ mockHomeDir = tempHomeDir;
20
+ });
21
+ afterEach(() => {
22
+ rmSync(tempHomeDir, { recursive: true, force: true });
23
+ });
24
+ it('writeInstructionHint writes to ~/.codex/AGENTS.md', async () => {
25
+ const adapter = new CodexAdapter();
26
+ await adapter.writeInstructionHint('<!-- runwork:start -->\nhello\n<!-- runwork:end -->', 'user');
27
+ const agentsPath = join(tempHomeDir, '.codex', 'AGENTS.md');
28
+ expect(existsSync(agentsPath)).toBe(true);
29
+ expect(readFileSync(agentsPath, 'utf-8')).toContain('hello');
30
+ // Legacy location must not be touched.
31
+ expect(existsSync(join(tempHomeDir, '.codex', 'instructions.md'))).toBe(false);
32
+ });
33
+ it('writeTeamInstructions writes to ~/.codex/AGENTS.md', async () => {
34
+ const adapter = new CodexAdapter();
35
+ await adapter.writeTeamInstructions('team rule', 'user');
36
+ const agentsPath = join(tempHomeDir, '.codex', 'AGENTS.md');
37
+ expect(existsSync(agentsPath)).toBe(true);
38
+ const contents = readFileSync(agentsPath, 'utf-8');
39
+ expect(contents).toContain('<!-- runwork-team:start -->');
40
+ expect(contents).toContain('team rule');
41
+ expect(contents).toContain('<!-- runwork-team:end -->');
42
+ expect(existsSync(join(tempHomeDir, '.codex', 'instructions.md'))).toBe(false);
43
+ });
44
+ it('cleanup removes both hint and team markers from ~/.codex/AGENTS.md', async () => {
45
+ const adapter = new CodexAdapter();
46
+ await adapter.writeInstructionHint('<!-- runwork:start -->\nhint body\n<!-- runwork:end -->', 'user');
47
+ await adapter.writeTeamInstructions('team body', 'user');
48
+ const agentsPath = join(tempHomeDir, '.codex', 'AGENTS.md');
49
+ expect(readFileSync(agentsPath, 'utf-8')).toContain('hint body');
50
+ await adapter.cleanup('user');
51
+ const after = readFileSync(agentsPath, 'utf-8');
52
+ expect(after).not.toContain('runwork:start');
53
+ expect(after).not.toContain('runwork-team:start');
54
+ expect(after).not.toContain('hint body');
55
+ expect(after).not.toContain('team body');
56
+ });
57
+ });
@@ -72,6 +72,15 @@ describe('CodexAdapter (codex).readUsageStats', () => {
72
72
  expect(result).not.toBeNull();
73
73
  expect(result.sessionCount).toBe(3);
74
74
  expect(result.hasNewActivity).toBe(true);
75
+ // Filtering must use updated_at (not created_at): long-lived threads can
76
+ // accumulate post-sync activity without ever being newly created.
77
+ const calls = querySqlite.mock.calls;
78
+ const countSql = calls.find(c => c[1].includes('count(*)'))?.[1];
79
+ expect(countSql).toContain('WHERE updated_at >');
80
+ expect(countSql).not.toContain('created_at >');
81
+ const tokensSql = calls.find(c => c[1].includes('sum(tokens_used)'))?.[1];
82
+ expect(tokensSql).toContain('WHERE updated_at >');
83
+ expect(tokensSql).not.toContain('created_at >');
75
84
  // Verify querySqlite was called with the DB path
76
85
  expect(querySqlite).toHaveBeenCalledWith(DB_PATH, expect.stringContaining('count(*)'));
77
86
  });
@@ -16,14 +16,14 @@ vi.mock('child_process', () => ({
16
16
  }));
17
17
  vi.mock('../../utils/sqlite.js', () => ({
18
18
  querySqlite: vi.fn(() => ''),
19
+ openWritableSqlite: vi.fn(() => null),
20
+ sqliteAvailable: vi.fn(() => false),
21
+ sqliteFlavor: vi.fn(() => null),
19
22
  }));
20
23
  vi.mock('smol-toml', () => ({
21
24
  parse: vi.fn(() => ({})),
22
25
  stringify: vi.fn(() => ''),
23
26
  }));
24
- vi.mock('better-sqlite3', () => ({
25
- default: vi.fn(() => { throw new Error('not available'); }),
26
- }));
27
27
  import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
28
28
  import { homedir } from 'os';
29
29
  import { execFileSync } from 'child_process';
@@ -70,11 +70,11 @@ describe('generateIntroSkill', () => {
70
70
  const skill = generateIntroSkill(makeContext({
71
71
  mcpServerCount: 2,
72
72
  skillCount: 2,
73
- mcpServerNames: ['Workspace Tools', 'aTars MCP'],
73
+ mcpServerNames: ['Runwork', 'aTars MCP'],
74
74
  skillNames: ['Developer Tools', 'Writing Plans'],
75
75
  }));
76
76
  expect(skill.content).toContain('MCP Servers (2)');
77
- expect(skill.content).toContain('Workspace Tools');
77
+ expect(skill.content).toContain('Runwork');
78
78
  expect(skill.content).toContain('Skills (2)');
79
79
  expect(skill.content).toContain('Developer Tools');
80
80
  });
@@ -84,6 +84,15 @@ describe('generateIntroSkill', () => {
84
84
  expect(skill.content).toContain('runwork dev');
85
85
  expect(skill.content).toContain('runwork doctor');
86
86
  });
87
+ it('uses canonical install commands and does not reference the old @runworkai/cli package', () => {
88
+ const skill = generateIntroSkill(makeContext());
89
+ expect(skill.content).toContain('curl -fsSL https://runwork.ai/install.sh | sh');
90
+ expect(skill.content).toContain('brew install runwork-ai/tap/runwork');
91
+ expect(skill.content).toContain('npx runwork@latest');
92
+ expect(skill.content).toContain('bunx runwork@latest');
93
+ expect(skill.content).not.toContain('@runworkai/cli');
94
+ expect(skill.content).not.toContain('npm install -g runwork');
95
+ });
87
96
  it('includes references section', () => {
88
97
  const skill = generateIntroSkill(makeContext());
89
98
  expect(skill.content).toContain('https://www.runwork.ai');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { toSlug, buildSkillMd } from '../types.js';
3
+ describe('toSlug', () => {
4
+ it('converts spaces to hyphens', () => {
5
+ expect(toSlug('Write Cold Email')).toBe('write-cold-email');
6
+ });
7
+ it('lowercases', () => {
8
+ expect(toSlug('Developer Tools')).toBe('developer-tools');
9
+ });
10
+ it('collapses multiple non-alphanumeric chars', () => {
11
+ expect(toSlug('Link generate - quote payment')).toBe('link-generate-quote-payment');
12
+ });
13
+ it('strips leading and trailing hyphens', () => {
14
+ expect(toSlug('--test--')).toBe('test');
15
+ expect(toSlug(' hello ')).toBe('hello');
16
+ });
17
+ it('preserves already-slugified names', () => {
18
+ expect(toSlug('my-skill')).toBe('my-skill');
19
+ expect(toSlug('runwork')).toBe('runwork');
20
+ });
21
+ it('handles special characters', () => {
22
+ expect(toSlug('Y Combinator slide maker')).toBe('y-combinator-slide-maker');
23
+ expect(toSlug("my test skill 1")).toBe('my-test-skill-1');
24
+ });
25
+ });
26
+ describe('buildSkillMd', () => {
27
+ function makeSkill(overrides = {}) {
28
+ return {
29
+ name: 'Write Cold Email',
30
+ filename: 'write-cold-email',
31
+ content: 'Some skill content',
32
+ description: 'A skill for writing emails',
33
+ ...overrides,
34
+ };
35
+ }
36
+ it('generates frontmatter with slugified name when no frontmatter exists', () => {
37
+ const result = buildSkillMd(makeSkill());
38
+ expect(result).toContain('name: write-cold-email');
39
+ expect(result).not.toContain('name: Write Cold Email');
40
+ expect(result).toContain('description: A skill for writing emails');
41
+ expect(result).toContain('Some skill content');
42
+ });
43
+ it('normalizes name in existing frontmatter', () => {
44
+ const result = buildSkillMd(makeSkill({
45
+ content: '---\nname: Write Cold Email\ndescription: existing desc\n---\n\nBody',
46
+ }));
47
+ expect(result).toContain('name: write-cold-email');
48
+ expect(result).not.toContain('name: Write Cold Email');
49
+ expect(result).toContain('description: existing desc');
50
+ });
51
+ it('normalizes quoted name in existing frontmatter', () => {
52
+ const result = buildSkillMd(makeSkill({
53
+ content: '---\nname: "Developer Tools"\ndescription: dev tools\n---\n\nBody',
54
+ name: 'Developer Tools',
55
+ filename: 'developer-tools',
56
+ }));
57
+ expect(result).toContain('name: developer-tools');
58
+ expect(result).not.toContain('Developer Tools');
59
+ });
60
+ it('preserves already-slugified name in existing frontmatter', () => {
61
+ const result = buildSkillMd(makeSkill({
62
+ content: '---\nname: write-cold-email\ndescription: desc\n---\n\nBody',
63
+ }));
64
+ expect(result).toContain('name: write-cold-email');
65
+ });
66
+ it('injects description when frontmatter exists without one', () => {
67
+ const result = buildSkillMd(makeSkill({
68
+ content: '---\nsome-key: value\n---\n\nBody',
69
+ }));
70
+ expect(result).toContain('name: write-cold-email');
71
+ expect(result).toContain('description: A skill for writing emails');
72
+ });
73
+ it('uses default description when none provided', () => {
74
+ const result = buildSkillMd(makeSkill({ description: '' }));
75
+ expect(result).toContain('description: Write Cold Email skill');
76
+ });
77
+ });
@@ -1,7 +1,8 @@
1
- import type { AgentAdapter, AgentConfigOverride, AgentUsageStats, McpServerEntry, SkillFile, SkillUsageEntry } from './types.js';
1
+ import type { AgentAdapter, AgentConfigOverride, AgentUsageStats, CleanupManifest, McpServerEntry, SkillFile, SkillUsageEntry } from './types.js';
2
2
  export declare class ClaudeCodeAdapter implements AgentAdapter {
3
3
  name: string;
4
4
  slug: string;
5
+ mcpProvidesSkills: boolean;
5
6
  detect(): Promise<boolean>;
6
7
  supportsMcpScope(_scope: 'project' | 'user'): boolean;
7
8
  supportsSkills(): boolean;
@@ -12,6 +13,7 @@ export declare class ClaudeCodeAdapter implements AgentAdapter {
12
13
  writeAgentConfig(config: AgentConfigOverride, scope: 'project' | 'user'): Promise<void>;
13
14
  /** Remove the managed marker and all entries after it from a permissions array */
14
15
  private removeAfterMarker;
16
+ cleanup(scope: 'project' | 'user', manifest?: CleanupManifest): Promise<void>;
15
17
  readUsageStats(lastSyncAt: string | null): Promise<AgentUsageStats | null>;
16
18
  readSkillUsage(lastSyncAt: string | null): Promise<SkillUsageEntry[] | null>;
17
19
  readVersion(): Promise<string | null>;