@ottocode/sdk 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 (125) hide show
  1. package/README.md +338 -0
  2. package/package.json +128 -0
  3. package/src/agent/types.ts +19 -0
  4. package/src/auth/src/copilot-oauth.ts +190 -0
  5. package/src/auth/src/index.ts +100 -0
  6. package/src/auth/src/oauth.ts +234 -0
  7. package/src/auth/src/openai-oauth.ts +394 -0
  8. package/src/auth/src/wallet.ts +51 -0
  9. package/src/browser.ts +32 -0
  10. package/src/config/src/index.ts +110 -0
  11. package/src/config/src/manager.ts +181 -0
  12. package/src/config/src/paths.ts +98 -0
  13. package/src/core/src/errors.ts +102 -0
  14. package/src/core/src/index.ts +108 -0
  15. package/src/core/src/providers/resolver.ts +244 -0
  16. package/src/core/src/streaming/artifacts.ts +41 -0
  17. package/src/core/src/terminals/bun-pty.ts +13 -0
  18. package/src/core/src/terminals/circular-buffer.ts +30 -0
  19. package/src/core/src/terminals/ensure-bun-pty.ts +70 -0
  20. package/src/core/src/terminals/index.ts +8 -0
  21. package/src/core/src/terminals/manager.ts +158 -0
  22. package/src/core/src/terminals/rust-libs.ts +30 -0
  23. package/src/core/src/terminals/terminal.ts +132 -0
  24. package/src/core/src/tools/bin-manager.ts +250 -0
  25. package/src/core/src/tools/builtin/bash.ts +155 -0
  26. package/src/core/src/tools/builtin/bash.txt +7 -0
  27. package/src/core/src/tools/builtin/file-cache.ts +39 -0
  28. package/src/core/src/tools/builtin/finish.ts +12 -0
  29. package/src/core/src/tools/builtin/finish.txt +10 -0
  30. package/src/core/src/tools/builtin/fs/cd.ts +19 -0
  31. package/src/core/src/tools/builtin/fs/cd.txt +5 -0
  32. package/src/core/src/tools/builtin/fs/index.ts +20 -0
  33. package/src/core/src/tools/builtin/fs/ls.ts +72 -0
  34. package/src/core/src/tools/builtin/fs/ls.txt +8 -0
  35. package/src/core/src/tools/builtin/fs/pwd.ts +17 -0
  36. package/src/core/src/tools/builtin/fs/pwd.txt +5 -0
  37. package/src/core/src/tools/builtin/fs/read.ts +119 -0
  38. package/src/core/src/tools/builtin/fs/read.txt +8 -0
  39. package/src/core/src/tools/builtin/fs/tree.ts +149 -0
  40. package/src/core/src/tools/builtin/fs/tree.txt +11 -0
  41. package/src/core/src/tools/builtin/fs/util.ts +95 -0
  42. package/src/core/src/tools/builtin/fs/write.ts +106 -0
  43. package/src/core/src/tools/builtin/fs/write.txt +11 -0
  44. package/src/core/src/tools/builtin/git.commit.txt +6 -0
  45. package/src/core/src/tools/builtin/git.diff.txt +5 -0
  46. package/src/core/src/tools/builtin/git.status.txt +5 -0
  47. package/src/core/src/tools/builtin/git.ts +151 -0
  48. package/src/core/src/tools/builtin/glob.ts +128 -0
  49. package/src/core/src/tools/builtin/glob.txt +10 -0
  50. package/src/core/src/tools/builtin/grep.ts +136 -0
  51. package/src/core/src/tools/builtin/grep.txt +9 -0
  52. package/src/core/src/tools/builtin/ignore.ts +45 -0
  53. package/src/core/src/tools/builtin/patch/apply.ts +546 -0
  54. package/src/core/src/tools/builtin/patch/constants.ts +5 -0
  55. package/src/core/src/tools/builtin/patch/normalize.ts +31 -0
  56. package/src/core/src/tools/builtin/patch/parse-enveloped.ts +209 -0
  57. package/src/core/src/tools/builtin/patch/parse-unified.ts +231 -0
  58. package/src/core/src/tools/builtin/patch/parse.ts +28 -0
  59. package/src/core/src/tools/builtin/patch/text.ts +23 -0
  60. package/src/core/src/tools/builtin/patch/types.ts +82 -0
  61. package/src/core/src/tools/builtin/patch.ts +167 -0
  62. package/src/core/src/tools/builtin/patch.txt +207 -0
  63. package/src/core/src/tools/builtin/progress.ts +55 -0
  64. package/src/core/src/tools/builtin/progress.txt +7 -0
  65. package/src/core/src/tools/builtin/ripgrep.ts +125 -0
  66. package/src/core/src/tools/builtin/ripgrep.txt +7 -0
  67. package/src/core/src/tools/builtin/terminal.ts +300 -0
  68. package/src/core/src/tools/builtin/terminal.txt +93 -0
  69. package/src/core/src/tools/builtin/todos.ts +66 -0
  70. package/src/core/src/tools/builtin/todos.txt +7 -0
  71. package/src/core/src/tools/builtin/websearch.ts +250 -0
  72. package/src/core/src/tools/builtin/websearch.txt +12 -0
  73. package/src/core/src/tools/error.ts +67 -0
  74. package/src/core/src/tools/loader.ts +421 -0
  75. package/src/core/src/types/index.ts +11 -0
  76. package/src/core/src/types/types.ts +4 -0
  77. package/src/core/src/utils/ansi.ts +27 -0
  78. package/src/core/src/utils/debug.ts +40 -0
  79. package/src/core/src/utils/logger.ts +150 -0
  80. package/src/index.ts +313 -0
  81. package/src/prompts/src/agents/build.txt +89 -0
  82. package/src/prompts/src/agents/general.txt +15 -0
  83. package/src/prompts/src/agents/plan.txt +10 -0
  84. package/src/prompts/src/agents/research.txt +50 -0
  85. package/src/prompts/src/base.txt +24 -0
  86. package/src/prompts/src/debug.ts +104 -0
  87. package/src/prompts/src/index.ts +1 -0
  88. package/src/prompts/src/modes/oneshot.txt +9 -0
  89. package/src/prompts/src/providers/anthropic.txt +247 -0
  90. package/src/prompts/src/providers/anthropicSpoof.txt +1 -0
  91. package/src/prompts/src/providers/default.txt +466 -0
  92. package/src/prompts/src/providers/google.txt +230 -0
  93. package/src/prompts/src/providers/moonshot.txt +24 -0
  94. package/src/prompts/src/providers/openai.txt +414 -0
  95. package/src/prompts/src/providers.ts +143 -0
  96. package/src/providers/src/anthropic-caching.ts +202 -0
  97. package/src/providers/src/anthropic-oauth-client.ts +157 -0
  98. package/src/providers/src/authorization.ts +17 -0
  99. package/src/providers/src/catalog-manual.ts +135 -0
  100. package/src/providers/src/catalog-merged.ts +9 -0
  101. package/src/providers/src/catalog.ts +8329 -0
  102. package/src/providers/src/copilot-client.ts +39 -0
  103. package/src/providers/src/env.ts +31 -0
  104. package/src/providers/src/google-client.ts +16 -0
  105. package/src/providers/src/index.ts +75 -0
  106. package/src/providers/src/moonshot-client.ts +25 -0
  107. package/src/providers/src/oauth-models.ts +39 -0
  108. package/src/providers/src/openai-oauth-client.ts +108 -0
  109. package/src/providers/src/opencode-client.ts +64 -0
  110. package/src/providers/src/openrouter-client.ts +31 -0
  111. package/src/providers/src/pricing.ts +178 -0
  112. package/src/providers/src/setu-client.ts +643 -0
  113. package/src/providers/src/utils.ts +210 -0
  114. package/src/providers/src/validate.ts +39 -0
  115. package/src/providers/src/zai-client.ts +47 -0
  116. package/src/skills/index.ts +34 -0
  117. package/src/skills/loader.ts +152 -0
  118. package/src/skills/parser.ts +108 -0
  119. package/src/skills/tool.ts +87 -0
  120. package/src/skills/types.ts +41 -0
  121. package/src/skills/validator.ts +110 -0
  122. package/src/types/src/auth.ts +33 -0
  123. package/src/types/src/config.ts +36 -0
  124. package/src/types/src/index.ts +20 -0
  125. package/src/types/src/provider.ts +71 -0
@@ -0,0 +1,41 @@
1
+ export type SkillScope = 'cwd' | 'parent' | 'repo' | 'user' | 'system';
2
+
3
+ export interface SkillMetadata {
4
+ name: string;
5
+ description: string;
6
+ license?: string;
7
+ compatibility?: string;
8
+ metadata?: Record<string, string>;
9
+ allowedTools?: string[];
10
+ }
11
+
12
+ export interface SkillDefinition {
13
+ metadata: SkillMetadata;
14
+ content: string;
15
+ path: string;
16
+ scope: SkillScope;
17
+ }
18
+
19
+ export interface DiscoveredSkill {
20
+ name: string;
21
+ description: string;
22
+ path: string;
23
+ scope: SkillScope;
24
+ }
25
+
26
+ export interface SkillLoadResult {
27
+ ok: true;
28
+ name: string;
29
+ description: string;
30
+ content: string;
31
+ path: string;
32
+ scope: SkillScope;
33
+ allowedTools?: string[];
34
+ }
35
+
36
+ export interface SkillErrorResult {
37
+ ok: false;
38
+ error: string;
39
+ }
40
+
41
+ export type SkillResult = SkillLoadResult | SkillErrorResult;
@@ -0,0 +1,110 @@
1
+ import type { SkillMetadata } from './types.ts';
2
+
3
+ const NAME_REGEX = /^[a-z0-9]+(-[a-z0-9]+)*$/;
4
+ const MAX_NAME_LENGTH = 64;
5
+ const MAX_DESCRIPTION_LENGTH = 1024;
6
+ const MAX_COMPATIBILITY_LENGTH = 500;
7
+
8
+ export class SkillValidationError extends Error {
9
+ constructor(
10
+ message: string,
11
+ public path: string,
12
+ ) {
13
+ super(message);
14
+ this.name = 'SkillValidationError';
15
+ }
16
+ }
17
+
18
+ export function validateMetadata(
19
+ meta: unknown,
20
+ path: string,
21
+ ): asserts meta is SkillMetadata {
22
+ if (!meta || typeof meta !== 'object') {
23
+ throw new SkillValidationError(`Invalid frontmatter in ${path}`, path);
24
+ }
25
+
26
+ const m = meta as Record<string, unknown>;
27
+
28
+ if (typeof m.name !== 'string' || !m.name) {
29
+ throw new SkillValidationError(
30
+ `Missing required 'name' field in ${path}`,
31
+ path,
32
+ );
33
+ }
34
+ if (m.name.length > MAX_NAME_LENGTH) {
35
+ throw new SkillValidationError(
36
+ `Skill name exceeds ${MAX_NAME_LENGTH} chars in ${path}`,
37
+ path,
38
+ );
39
+ }
40
+ if (!NAME_REGEX.test(m.name)) {
41
+ throw new SkillValidationError(
42
+ `Invalid skill name '${m.name}' - must be lowercase alphanumeric with hyphens, no start/end hyphens, no consecutive hyphens`,
43
+ path,
44
+ );
45
+ }
46
+
47
+ if (typeof m.description !== 'string' || !m.description) {
48
+ throw new SkillValidationError(
49
+ `Missing required 'description' field in ${path}`,
50
+ path,
51
+ );
52
+ }
53
+ if (m.description.length > MAX_DESCRIPTION_LENGTH) {
54
+ throw new SkillValidationError(
55
+ `Description exceeds ${MAX_DESCRIPTION_LENGTH} chars in ${path}`,
56
+ path,
57
+ );
58
+ }
59
+
60
+ if (
61
+ m.compatibility &&
62
+ typeof m.compatibility === 'string' &&
63
+ m.compatibility.length > MAX_COMPATIBILITY_LENGTH
64
+ ) {
65
+ throw new SkillValidationError(
66
+ `Compatibility exceeds ${MAX_COMPATIBILITY_LENGTH} chars in ${path}`,
67
+ path,
68
+ );
69
+ }
70
+
71
+ if (m.metadata !== undefined) {
72
+ if (typeof m.metadata !== 'object' || m.metadata === null) {
73
+ throw new SkillValidationError(
74
+ `metadata must be an object in ${path}`,
75
+ path,
76
+ );
77
+ }
78
+ for (const [key, value] of Object.entries(
79
+ m.metadata as Record<string, unknown>,
80
+ )) {
81
+ if (typeof value !== 'string') {
82
+ throw new SkillValidationError(
83
+ `metadata.${key} must be a string in ${path}`,
84
+ path,
85
+ );
86
+ }
87
+ }
88
+ }
89
+
90
+ if (m['allowed-tools'] !== undefined && m.allowedTools === undefined) {
91
+ m.allowedTools = m['allowed-tools'];
92
+ }
93
+
94
+ if (m.allowedTools !== undefined) {
95
+ if (typeof m.allowedTools === 'string') {
96
+ m.allowedTools = m.allowedTools.split(/\s+/).filter(Boolean);
97
+ }
98
+ if (!Array.isArray(m.allowedTools)) {
99
+ throw new SkillValidationError(
100
+ `allowed-tools must be a string or array in ${path}`,
101
+ path,
102
+ );
103
+ }
104
+ }
105
+ }
106
+
107
+ export function validateSkillName(name: string): boolean {
108
+ if (!name || name.length > MAX_NAME_LENGTH) return false;
109
+ return NAME_REGEX.test(name);
110
+ }
@@ -0,0 +1,33 @@
1
+ import type { ProviderId } from './provider';
2
+
3
+ /**
4
+ * API key authentication
5
+ */
6
+ export type ApiAuth = { type: 'api'; key: string };
7
+
8
+ /**
9
+ * Wallet/private-key authentication
10
+ */
11
+ export type WalletAuth = { type: 'wallet'; secret: string };
12
+
13
+ /**
14
+ * OAuth authentication tokens
15
+ */
16
+ export type OAuth = {
17
+ type: 'oauth';
18
+ access: string;
19
+ refresh: string;
20
+ expires: number;
21
+ accountId?: string;
22
+ idToken?: string;
23
+ };
24
+
25
+ /**
26
+ * Union of all auth types
27
+ */
28
+ export type AuthInfo = ApiAuth | OAuth | WalletAuth;
29
+
30
+ /**
31
+ * Collection of auth credentials per provider
32
+ */
33
+ export type AuthFile = Partial<Record<ProviderId, AuthInfo>>;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Configuration scope - where settings are stored
3
+ */
4
+ export type Scope = 'global' | 'local';
5
+
6
+ /**
7
+ * Default settings for the CLI
8
+ */
9
+ export type ToolApprovalMode = 'auto' | 'dangerous' | 'all';
10
+
11
+ export type DefaultConfig = {
12
+ agent: string;
13
+ provider: ProviderId;
14
+ model: string;
15
+ toolApproval?: ToolApprovalMode;
16
+ };
17
+
18
+ /**
19
+ * Path configuration
20
+ */
21
+ export type PathConfig = {
22
+ dataDir: string;
23
+ dbPath: string;
24
+ projectConfigPath: string | null;
25
+ globalConfigPath: string | null;
26
+ };
27
+
28
+ /**
29
+ * Complete otto configuration object
30
+ */
31
+ export type OttoConfig = {
32
+ projectRoot: string;
33
+ defaults: DefaultConfig;
34
+ paths: PathConfig;
35
+ onboardingComplete?: boolean;
36
+ };
@@ -0,0 +1,20 @@
1
+ // Provider types
2
+ export type {
3
+ ProviderId,
4
+ ProviderFamily,
5
+ ModelInfo,
6
+ ModelProviderBinding,
7
+ ProviderCatalogEntry,
8
+ } from './provider';
9
+
10
+ // Auth types
11
+ export type { ApiAuth, OAuth, AuthInfo, AuthFile } from './auth';
12
+
13
+ // Config types
14
+ export type {
15
+ Scope,
16
+ DefaultConfig,
17
+ PathConfig,
18
+ OttoConfig,
19
+ ToolApprovalMode,
20
+ } from './config';
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Provider identifiers for supported AI providers
3
+ */
4
+ export type ProviderId =
5
+ | 'openai'
6
+ | 'anthropic'
7
+ | 'google'
8
+ | 'openrouter'
9
+ | 'opencode'
10
+ | 'copilot'
11
+ | 'setu'
12
+ | 'zai'
13
+ | 'zai-coding'
14
+ | 'moonshot';
15
+
16
+ /**
17
+ * Provider family for prompt selection
18
+ */
19
+ export type ProviderFamily =
20
+ | 'openai'
21
+ | 'anthropic'
22
+ | 'google'
23
+ | 'moonshot'
24
+ | 'openai-compatible';
25
+
26
+ export type ModelProviderBinding = {
27
+ id?: string;
28
+ npm?: string;
29
+ api?: string;
30
+ baseURL?: string;
31
+ /**
32
+ * The provider family for prompt selection.
33
+ * Used to determine which base prompt to use for this model.
34
+ */
35
+ family?: ProviderFamily;
36
+ };
37
+
38
+ /**
39
+ * Information about a specific model
40
+ */
41
+ export type ModelInfo = {
42
+ id: string;
43
+ label?: string;
44
+ modalities?: { input?: string[]; output?: string[] };
45
+ toolCall?: boolean;
46
+ reasoningText?: boolean;
47
+ attachment?: boolean;
48
+ temperature?: boolean | number;
49
+ knowledge?: string;
50
+ releaseDate?: string;
51
+ lastUpdated?: string;
52
+ openWeights?: boolean;
53
+ cost?: {
54
+ input?: number;
55
+ output?: number;
56
+ cacheRead?: number;
57
+ cacheWrite?: number;
58
+ };
59
+ limit?: { context?: number; output?: number };
60
+ provider?: ModelProviderBinding;
61
+ };
62
+
63
+ export type ProviderCatalogEntry = {
64
+ id: ProviderId;
65
+ label?: string;
66
+ env?: string[];
67
+ npm?: string;
68
+ api?: string;
69
+ doc?: string;
70
+ models: ModelInfo[];
71
+ };