@ottocode/server 0.1.173

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 (111) hide show
  1. package/package.json +42 -0
  2. package/src/events/bus.ts +43 -0
  3. package/src/events/types.ts +32 -0
  4. package/src/index.ts +281 -0
  5. package/src/openapi/helpers.ts +64 -0
  6. package/src/openapi/paths/ask.ts +70 -0
  7. package/src/openapi/paths/config.ts +218 -0
  8. package/src/openapi/paths/files.ts +72 -0
  9. package/src/openapi/paths/git.ts +457 -0
  10. package/src/openapi/paths/messages.ts +92 -0
  11. package/src/openapi/paths/sessions.ts +90 -0
  12. package/src/openapi/paths/setu.ts +154 -0
  13. package/src/openapi/paths/stream.ts +26 -0
  14. package/src/openapi/paths/terminals.ts +226 -0
  15. package/src/openapi/schemas.ts +345 -0
  16. package/src/openapi/spec.ts +49 -0
  17. package/src/presets.ts +85 -0
  18. package/src/routes/ask.ts +113 -0
  19. package/src/routes/auth.ts +592 -0
  20. package/src/routes/branch.ts +106 -0
  21. package/src/routes/config/agents.ts +44 -0
  22. package/src/routes/config/cwd.ts +21 -0
  23. package/src/routes/config/defaults.ts +45 -0
  24. package/src/routes/config/index.ts +16 -0
  25. package/src/routes/config/main.ts +73 -0
  26. package/src/routes/config/models.ts +139 -0
  27. package/src/routes/config/providers.ts +46 -0
  28. package/src/routes/config/utils.ts +120 -0
  29. package/src/routes/files.ts +218 -0
  30. package/src/routes/git/branch.ts +75 -0
  31. package/src/routes/git/commit.ts +209 -0
  32. package/src/routes/git/diff.ts +137 -0
  33. package/src/routes/git/index.ts +18 -0
  34. package/src/routes/git/push.ts +160 -0
  35. package/src/routes/git/schemas.ts +48 -0
  36. package/src/routes/git/staging.ts +208 -0
  37. package/src/routes/git/status.ts +83 -0
  38. package/src/routes/git/types.ts +31 -0
  39. package/src/routes/git/utils.ts +249 -0
  40. package/src/routes/openapi.ts +6 -0
  41. package/src/routes/research.ts +392 -0
  42. package/src/routes/root.ts +5 -0
  43. package/src/routes/session-approval.ts +63 -0
  44. package/src/routes/session-files.ts +387 -0
  45. package/src/routes/session-messages.ts +170 -0
  46. package/src/routes/session-stream.ts +61 -0
  47. package/src/routes/sessions.ts +814 -0
  48. package/src/routes/setu.ts +346 -0
  49. package/src/routes/terminals.ts +227 -0
  50. package/src/runtime/agent/registry.ts +351 -0
  51. package/src/runtime/agent/runner-reasoning.ts +108 -0
  52. package/src/runtime/agent/runner-setup.ts +257 -0
  53. package/src/runtime/agent/runner.ts +375 -0
  54. package/src/runtime/agent-registry.ts +6 -0
  55. package/src/runtime/ask/service.ts +369 -0
  56. package/src/runtime/context/environment.ts +202 -0
  57. package/src/runtime/debug/index.ts +117 -0
  58. package/src/runtime/debug/state.ts +140 -0
  59. package/src/runtime/errors/api-error.ts +192 -0
  60. package/src/runtime/errors/handling.ts +199 -0
  61. package/src/runtime/message/compaction-auto.ts +154 -0
  62. package/src/runtime/message/compaction-context.ts +101 -0
  63. package/src/runtime/message/compaction-detect.ts +26 -0
  64. package/src/runtime/message/compaction-limits.ts +37 -0
  65. package/src/runtime/message/compaction-mark.ts +111 -0
  66. package/src/runtime/message/compaction-prune.ts +75 -0
  67. package/src/runtime/message/compaction.ts +21 -0
  68. package/src/runtime/message/history-builder.ts +266 -0
  69. package/src/runtime/message/service.ts +468 -0
  70. package/src/runtime/message/tool-history-tracker.ts +204 -0
  71. package/src/runtime/prompt/builder.ts +167 -0
  72. package/src/runtime/provider/anthropic.ts +50 -0
  73. package/src/runtime/provider/copilot.ts +12 -0
  74. package/src/runtime/provider/google.ts +8 -0
  75. package/src/runtime/provider/index.ts +60 -0
  76. package/src/runtime/provider/moonshot.ts +8 -0
  77. package/src/runtime/provider/oauth-adapter.ts +237 -0
  78. package/src/runtime/provider/openai.ts +18 -0
  79. package/src/runtime/provider/opencode.ts +7 -0
  80. package/src/runtime/provider/openrouter.ts +7 -0
  81. package/src/runtime/provider/selection.ts +118 -0
  82. package/src/runtime/provider/setu.ts +126 -0
  83. package/src/runtime/provider/zai.ts +16 -0
  84. package/src/runtime/session/branch.ts +280 -0
  85. package/src/runtime/session/db-operations.ts +285 -0
  86. package/src/runtime/session/manager.ts +99 -0
  87. package/src/runtime/session/queue.ts +243 -0
  88. package/src/runtime/stream/abort-handler.ts +65 -0
  89. package/src/runtime/stream/error-handler.ts +371 -0
  90. package/src/runtime/stream/finish-handler.ts +101 -0
  91. package/src/runtime/stream/handlers.ts +5 -0
  92. package/src/runtime/stream/step-finish.ts +93 -0
  93. package/src/runtime/stream/types.ts +25 -0
  94. package/src/runtime/tools/approval.ts +180 -0
  95. package/src/runtime/tools/context.ts +83 -0
  96. package/src/runtime/tools/mapping.ts +154 -0
  97. package/src/runtime/tools/setup.ts +44 -0
  98. package/src/runtime/topup/manager.ts +110 -0
  99. package/src/runtime/utils/cwd.ts +69 -0
  100. package/src/runtime/utils/token.ts +35 -0
  101. package/src/tools/adapter.ts +634 -0
  102. package/src/tools/database/get-parent-session.ts +183 -0
  103. package/src/tools/database/get-session-context.ts +161 -0
  104. package/src/tools/database/index.ts +42 -0
  105. package/src/tools/database/present-session-links.ts +47 -0
  106. package/src/tools/database/query-messages.ts +160 -0
  107. package/src/tools/database/query-sessions.ts +126 -0
  108. package/src/tools/database/search-history.ts +135 -0
  109. package/src/types/sql-imports.d.ts +5 -0
  110. package/sst-env.d.ts +8 -0
  111. package/tsconfig.json +7 -0
@@ -0,0 +1,44 @@
1
+ import type { Hono } from 'hono';
2
+ import { loadConfig } from '@ottocode/sdk';
3
+ import type { EmbeddedAppConfig } from '../../index.ts';
4
+ import { logger } from '@ottocode/sdk';
5
+ import { serializeError } from '../../runtime/errors/api-error.ts';
6
+ import { discoverAllAgents, getDefault } from './utils.ts';
7
+
8
+ export function registerAgentsRoute(app: Hono) {
9
+ app.get('/v1/config/agents', async (c) => {
10
+ try {
11
+ const embeddedConfig = c.get('embeddedConfig') as
12
+ | EmbeddedAppConfig
13
+ | undefined;
14
+
15
+ if (embeddedConfig) {
16
+ const agents = embeddedConfig.agents
17
+ ? Object.keys(embeddedConfig.agents)
18
+ : ['general', 'build', 'plan'];
19
+ return c.json({
20
+ agents,
21
+ default: getDefault(
22
+ embeddedConfig.agent,
23
+ embeddedConfig.defaults?.agent,
24
+ 'general',
25
+ ),
26
+ });
27
+ }
28
+
29
+ const projectRoot = c.req.query('project') || process.cwd();
30
+ const cfg = await loadConfig(projectRoot);
31
+
32
+ const allAgents = await discoverAllAgents(cfg.projectRoot);
33
+
34
+ return c.json({
35
+ agents: allAgents,
36
+ default: cfg.defaults.agent,
37
+ });
38
+ } catch (error) {
39
+ logger.error('Failed to get agents', error);
40
+ const errorResponse = serializeError(error);
41
+ return c.json(errorResponse, errorResponse.error.status || 500);
42
+ }
43
+ });
44
+ }
@@ -0,0 +1,21 @@
1
+ import type { Hono } from 'hono';
2
+ import { basename } from 'node:path';
3
+ import { logger } from '@ottocode/sdk';
4
+ import { serializeError } from '../../runtime/errors/api-error.ts';
5
+
6
+ export function registerCwdRoute(app: Hono) {
7
+ app.get('/v1/config/cwd', (c) => {
8
+ try {
9
+ const cwd = process.cwd();
10
+ const dirName = basename(cwd);
11
+ return c.json({
12
+ cwd,
13
+ dirName,
14
+ });
15
+ } catch (error) {
16
+ logger.error('Failed to get current working directory', error);
17
+ const errorResponse = serializeError(error);
18
+ return c.json(errorResponse, errorResponse.error.status || 500);
19
+ }
20
+ });
21
+ }
@@ -0,0 +1,45 @@
1
+ import type { Hono } from 'hono';
2
+ import { setConfig, loadConfig } from '@ottocode/sdk';
3
+ import { logger } from '@ottocode/sdk';
4
+ import { serializeError } from '../../runtime/errors/api-error.ts';
5
+
6
+ export function registerDefaultsRoute(app: Hono) {
7
+ app.patch('/v1/config/defaults', async (c) => {
8
+ try {
9
+ const projectRoot = c.req.query('project') || process.cwd();
10
+ const body = await c.req.json<{
11
+ agent?: string;
12
+ provider?: string;
13
+ model?: string;
14
+ toolApproval?: 'auto' | 'dangerous' | 'all';
15
+ scope?: 'global' | 'local';
16
+ }>();
17
+
18
+ const scope = body.scope || 'global';
19
+ const updates: Partial<{
20
+ agent: string;
21
+ provider: string;
22
+ model: string;
23
+ toolApproval: 'auto' | 'dangerous' | 'all';
24
+ }> = {};
25
+
26
+ if (body.agent) updates.agent = body.agent;
27
+ if (body.provider) updates.provider = body.provider;
28
+ if (body.model) updates.model = body.model;
29
+ if (body.toolApproval) updates.toolApproval = body.toolApproval;
30
+
31
+ await setConfig(scope, updates, projectRoot);
32
+
33
+ const cfg = await loadConfig(projectRoot);
34
+
35
+ return c.json({
36
+ success: true,
37
+ defaults: cfg.defaults,
38
+ });
39
+ } catch (error) {
40
+ logger.error('Failed to update defaults', error);
41
+ const errorResponse = serializeError(error);
42
+ return c.json(errorResponse, errorResponse.error.status || 500);
43
+ }
44
+ });
45
+ }
@@ -0,0 +1,16 @@
1
+ import type { Hono } from 'hono';
2
+ import { registerCwdRoute } from './cwd.ts';
3
+ import { registerMainConfigRoute } from './main.ts';
4
+ import { registerAgentsRoute } from './agents.ts';
5
+ import { registerProvidersRoute } from './providers.ts';
6
+ import { registerModelsRoutes } from './models.ts';
7
+ import { registerDefaultsRoute } from './defaults.ts';
8
+
9
+ export function registerConfigRoutes(app: Hono) {
10
+ registerCwdRoute(app);
11
+ registerMainConfigRoute(app);
12
+ registerAgentsRoute(app);
13
+ registerProvidersRoute(app);
14
+ registerModelsRoutes(app);
15
+ registerDefaultsRoute(app);
16
+ }
@@ -0,0 +1,73 @@
1
+ import type { Hono } from 'hono';
2
+ import { loadConfig } from '@ottocode/sdk';
3
+ import type { EmbeddedAppConfig } from '../../index.ts';
4
+ import { logger } from '@ottocode/sdk';
5
+ import { serializeError } from '../../runtime/errors/api-error.ts';
6
+ import {
7
+ discoverAllAgents,
8
+ getAuthorizedProviders,
9
+ getDefault,
10
+ } from './utils.ts';
11
+
12
+ export function registerMainConfigRoute(app: Hono) {
13
+ app.get('/v1/config', async (c) => {
14
+ try {
15
+ const projectRoot = c.req.query('project') || process.cwd();
16
+ const embeddedConfig = c.get('embeddedConfig') as
17
+ | EmbeddedAppConfig
18
+ | undefined;
19
+
20
+ const cfg = await loadConfig(projectRoot);
21
+
22
+ let allAgents: string[];
23
+
24
+ if (embeddedConfig?.agents) {
25
+ const embeddedAgents = Object.keys(embeddedConfig.agents);
26
+ const fileAgents = await discoverAllAgents(cfg.projectRoot);
27
+ allAgents = Array.from(
28
+ new Set([...embeddedAgents, ...fileAgents]),
29
+ ).sort();
30
+ } else {
31
+ allAgents = await discoverAllAgents(cfg.projectRoot);
32
+ }
33
+
34
+ const authorizedProviders = await getAuthorizedProviders(
35
+ embeddedConfig,
36
+ cfg,
37
+ );
38
+
39
+ const defaults = {
40
+ agent: getDefault(
41
+ embeddedConfig?.agent,
42
+ embeddedConfig?.defaults?.agent,
43
+ cfg.defaults.agent,
44
+ ),
45
+ provider: getDefault(
46
+ embeddedConfig?.provider,
47
+ embeddedConfig?.defaults?.provider,
48
+ cfg.defaults.provider,
49
+ ),
50
+ model: getDefault(
51
+ embeddedConfig?.model,
52
+ embeddedConfig?.defaults?.model,
53
+ cfg.defaults.model,
54
+ ),
55
+ toolApproval: getDefault(
56
+ undefined,
57
+ embeddedConfig?.defaults?.toolApproval,
58
+ cfg.defaults.toolApproval,
59
+ ) as 'auto' | 'dangerous' | 'all',
60
+ };
61
+
62
+ return c.json({
63
+ agents: allAgents,
64
+ providers: authorizedProviders,
65
+ defaults,
66
+ });
67
+ } catch (error) {
68
+ logger.error('Failed to load config', error);
69
+ const errorResponse = serializeError(error);
70
+ return c.json(errorResponse, errorResponse.error.status || 500);
71
+ }
72
+ });
73
+ }
@@ -0,0 +1,139 @@
1
+ import type { Hono } from 'hono';
2
+ import {
3
+ loadConfig,
4
+ catalog,
5
+ type ProviderId,
6
+ filterModelsForAuthType,
7
+ } from '@ottocode/sdk';
8
+ import type { EmbeddedAppConfig } from '../../index.ts';
9
+ import { logger } from '@ottocode/sdk';
10
+ import { serializeError } from '../../runtime/errors/api-error.ts';
11
+ import {
12
+ isProviderAuthorizedHybrid,
13
+ getAuthorizedProviders,
14
+ getDefault,
15
+ getAuthTypeForProvider,
16
+ } from './utils.ts';
17
+
18
+ export function registerModelsRoutes(app: Hono) {
19
+ app.get('/v1/config/providers/:provider/models', async (c) => {
20
+ try {
21
+ const embeddedConfig = c.get('embeddedConfig') as
22
+ | EmbeddedAppConfig
23
+ | undefined;
24
+ const provider = c.req.param('provider') as ProviderId;
25
+
26
+ const projectRoot = c.req.query('project') || process.cwd();
27
+ const cfg = await loadConfig(projectRoot);
28
+
29
+ const authorized = await isProviderAuthorizedHybrid(
30
+ embeddedConfig,
31
+ cfg,
32
+ provider,
33
+ );
34
+
35
+ if (!authorized) {
36
+ logger.warn('Provider not authorized', { provider });
37
+ return c.json({ error: 'Provider not authorized' }, 403);
38
+ }
39
+
40
+ const providerCatalog = catalog[provider];
41
+ if (!providerCatalog) {
42
+ logger.warn('Provider not found in catalog', { provider });
43
+ return c.json({ error: 'Provider not found' }, 404);
44
+ }
45
+
46
+ const authType = await getAuthTypeForProvider(
47
+ embeddedConfig,
48
+ provider,
49
+ projectRoot,
50
+ );
51
+ const filteredModels = filterModelsForAuthType(
52
+ provider,
53
+ providerCatalog.models,
54
+ authType,
55
+ );
56
+
57
+ return c.json({
58
+ models: filteredModels.map((m) => ({
59
+ id: m.id,
60
+ label: m.label || m.id,
61
+ toolCall: m.toolCall,
62
+ reasoningText: m.reasoningText,
63
+ vision: m.modalities?.input?.includes('image') ?? false,
64
+ })),
65
+ default: getDefault(
66
+ embeddedConfig?.model,
67
+ embeddedConfig?.defaults?.model,
68
+ cfg.defaults.model,
69
+ ),
70
+ });
71
+ } catch (error) {
72
+ logger.error('Failed to get provider models', error);
73
+ const errorResponse = serializeError(error);
74
+ return c.json(errorResponse, errorResponse.error.status || 500);
75
+ }
76
+ });
77
+
78
+ app.get('/v1/config/models', async (c) => {
79
+ try {
80
+ const embeddedConfig = c.get('embeddedConfig') as
81
+ | EmbeddedAppConfig
82
+ | undefined;
83
+
84
+ const projectRoot = c.req.query('project') || process.cwd();
85
+ const cfg = await loadConfig(projectRoot);
86
+
87
+ const authorizedProviders = await getAuthorizedProviders(
88
+ embeddedConfig,
89
+ cfg,
90
+ );
91
+
92
+ const modelsMap: Record<
93
+ string,
94
+ {
95
+ label: string;
96
+ models: Array<{
97
+ id: string;
98
+ label: string;
99
+ toolCall?: boolean;
100
+ reasoningText?: boolean;
101
+ }>;
102
+ }
103
+ > = {};
104
+
105
+ for (const provider of authorizedProviders) {
106
+ const providerCatalog = catalog[provider];
107
+ if (providerCatalog) {
108
+ const authType = await getAuthTypeForProvider(
109
+ embeddedConfig,
110
+ provider,
111
+ projectRoot,
112
+ );
113
+ const filteredModels = filterModelsForAuthType(
114
+ provider,
115
+ providerCatalog.models,
116
+ authType,
117
+ );
118
+ modelsMap[provider] = {
119
+ label: providerCatalog.label || provider,
120
+ authType,
121
+ models: filteredModels.map((m) => ({
122
+ id: m.id,
123
+ label: m.label || m.id,
124
+ toolCall: m.toolCall,
125
+ reasoningText: m.reasoningText,
126
+ vision: m.modalities?.input?.includes('image') ?? false,
127
+ })),
128
+ };
129
+ }
130
+ }
131
+
132
+ return c.json(modelsMap);
133
+ } catch (error) {
134
+ logger.error('Failed to get all models', error);
135
+ const errorResponse = serializeError(error);
136
+ return c.json(errorResponse, errorResponse.error.status || 500);
137
+ }
138
+ });
139
+ }
@@ -0,0 +1,46 @@
1
+ import type { Hono } from 'hono';
2
+ import { loadConfig } from '@ottocode/sdk';
3
+ import type { ProviderId } from '@ottocode/sdk';
4
+ import type { EmbeddedAppConfig } from '../../index.ts';
5
+ import { logger } from '@ottocode/sdk';
6
+ import { serializeError } from '../../runtime/errors/api-error.ts';
7
+ import { getAuthorizedProviders, getDefault } from './utils.ts';
8
+
9
+ export function registerProvidersRoute(app: Hono) {
10
+ app.get('/v1/config/providers', async (c) => {
11
+ try {
12
+ const embeddedConfig = c.get('embeddedConfig') as
13
+ | EmbeddedAppConfig
14
+ | undefined;
15
+
16
+ if (embeddedConfig) {
17
+ const providers = embeddedConfig.auth
18
+ ? (Object.keys(embeddedConfig.auth) as ProviderId[])
19
+ : [embeddedConfig.provider];
20
+
21
+ return c.json({
22
+ providers,
23
+ default: getDefault(
24
+ embeddedConfig.provider,
25
+ embeddedConfig.defaults?.provider,
26
+ undefined,
27
+ ),
28
+ });
29
+ }
30
+
31
+ const projectRoot = c.req.query('project') || process.cwd();
32
+ const cfg = await loadConfig(projectRoot);
33
+
34
+ const authorizedProviders = await getAuthorizedProviders(undefined, cfg);
35
+
36
+ return c.json({
37
+ providers: authorizedProviders,
38
+ default: cfg.defaults.provider,
39
+ });
40
+ } catch (error) {
41
+ logger.error('Failed to get providers', error);
42
+ const errorResponse = serializeError(error);
43
+ return c.json(errorResponse, errorResponse.error.status || 500);
44
+ }
45
+ });
46
+ }
@@ -0,0 +1,120 @@
1
+ import {
2
+ catalog,
3
+ type ProviderId,
4
+ isProviderAuthorized,
5
+ getGlobalAgentsDir,
6
+ getAuth,
7
+ } from '@ottocode/sdk';
8
+ import { readdir } from 'node:fs/promises';
9
+ import { join } from 'node:path';
10
+ import type { EmbeddedAppConfig } from '../../index.ts';
11
+ import type { OttoConfig } from '@ottocode/sdk';
12
+ import { logger } from '@ottocode/sdk';
13
+ import { loadAgentsConfig } from '../../runtime/agent/registry.ts';
14
+
15
+ export async function isProviderAuthorizedHybrid(
16
+ embeddedConfig: EmbeddedAppConfig | undefined,
17
+ fileConfig: OttoConfig,
18
+ provider: ProviderId,
19
+ ): Promise<boolean> {
20
+ const hasEmbeddedAuth =
21
+ embeddedConfig?.provider === provider ||
22
+ (embeddedConfig?.auth && provider in embeddedConfig.auth);
23
+
24
+ if (hasEmbeddedAuth) {
25
+ return true;
26
+ }
27
+
28
+ return await isProviderAuthorized(fileConfig, provider);
29
+ }
30
+
31
+ export async function getAuthorizedProviders(
32
+ embeddedConfig: EmbeddedAppConfig | undefined,
33
+ fileConfig: OttoConfig,
34
+ ): Promise<ProviderId[]> {
35
+ const allProviders = Object.keys(catalog) as ProviderId[];
36
+ const authorizedProviders: ProviderId[] = [];
37
+
38
+ for (const provider of allProviders) {
39
+ const authorized = await isProviderAuthorizedHybrid(
40
+ embeddedConfig,
41
+ fileConfig,
42
+ provider,
43
+ );
44
+ if (authorized) {
45
+ authorizedProviders.push(provider);
46
+ }
47
+ }
48
+
49
+ return authorizedProviders;
50
+ }
51
+
52
+ export function getDefault<T>(
53
+ embeddedValue: T | undefined,
54
+ embeddedDefaultValue: T | undefined,
55
+ fileValue: T,
56
+ ): T {
57
+ return embeddedValue ?? embeddedDefaultValue ?? fileValue;
58
+ }
59
+
60
+ export async function getAuthTypeForProvider(
61
+ embeddedConfig: EmbeddedAppConfig | undefined,
62
+ provider: ProviderId,
63
+ projectRoot: string,
64
+ ): Promise<'api' | 'oauth' | 'wallet' | undefined> {
65
+ if (embeddedConfig?.auth?.[provider]) {
66
+ return embeddedConfig.auth[provider].type as 'api' | 'oauth' | 'wallet';
67
+ }
68
+ const auth = await getAuth(provider, projectRoot);
69
+ return auth?.type as 'api' | 'oauth' | 'wallet' | undefined;
70
+ }
71
+
72
+ export async function discoverAllAgents(
73
+ projectRoot: string,
74
+ ): Promise<string[]> {
75
+ const builtInAgents = ['general', 'build', 'plan'];
76
+ const agentSet = new Set<string>(builtInAgents);
77
+
78
+ try {
79
+ const agentsJson = await loadAgentsConfig(projectRoot);
80
+ for (const agentName of Object.keys(agentsJson)) {
81
+ if (agentName.trim()) {
82
+ agentSet.add(agentName);
83
+ }
84
+ }
85
+ } catch (err) {
86
+ logger.debug('Failed to load agents.json', err);
87
+ }
88
+
89
+ try {
90
+ const localAgentsPath = join(projectRoot, '.otto', 'agents');
91
+ const localFiles = await readdir(localAgentsPath).catch(() => []);
92
+ for (const file of localFiles) {
93
+ if (file.endsWith('.txt') || file.endsWith('.md')) {
94
+ const agentName = file.replace(/\.(txt|md)$/, '');
95
+ if (agentName.trim()) {
96
+ agentSet.add(agentName);
97
+ }
98
+ }
99
+ }
100
+ } catch (err) {
101
+ logger.debug('Failed to read local agents directory', err);
102
+ }
103
+
104
+ try {
105
+ const globalAgentsPath = getGlobalAgentsDir();
106
+ const globalFiles = await readdir(globalAgentsPath).catch(() => []);
107
+ for (const file of globalFiles) {
108
+ if (file.endsWith('.txt') || file.endsWith('.md')) {
109
+ const agentName = file.replace(/\.(txt|md)$/, '');
110
+ if (agentName.trim()) {
111
+ agentSet.add(agentName);
112
+ }
113
+ }
114
+ }
115
+ } catch (err) {
116
+ logger.debug('Failed to read global agents directory', err);
117
+ }
118
+
119
+ return Array.from(agentSet).sort();
120
+ }