@mainwp/control 1.0.0

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 (204) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +583 -0
  3. package/bin/_exit.js +12 -0
  4. package/bin/dev.js +7 -0
  5. package/bin/run.js +7 -0
  6. package/dist/chat/chat-engine.d.ts +213 -0
  7. package/dist/chat/chat-engine.d.ts.map +1 -0
  8. package/dist/chat/chat-engine.js +636 -0
  9. package/dist/chat/chat-engine.js.map +1 -0
  10. package/dist/chat/index.d.ts +10 -0
  11. package/dist/chat/index.d.ts.map +1 -0
  12. package/dist/chat/index.js +14 -0
  13. package/dist/chat/index.js.map +1 -0
  14. package/dist/chat/providers/anthropic.d.ts +52 -0
  15. package/dist/chat/providers/anthropic.d.ts.map +1 -0
  16. package/dist/chat/providers/anthropic.js +292 -0
  17. package/dist/chat/providers/anthropic.js.map +1 -0
  18. package/dist/chat/providers/gemini.d.ts +52 -0
  19. package/dist/chat/providers/gemini.d.ts.map +1 -0
  20. package/dist/chat/providers/gemini.js +284 -0
  21. package/dist/chat/providers/gemini.js.map +1 -0
  22. package/dist/chat/providers/index.d.ts +19 -0
  23. package/dist/chat/providers/index.d.ts.map +1 -0
  24. package/dist/chat/providers/index.js +23 -0
  25. package/dist/chat/providers/index.js.map +1 -0
  26. package/dist/chat/providers/local.d.ts +37 -0
  27. package/dist/chat/providers/local.d.ts.map +1 -0
  28. package/dist/chat/providers/local.js +130 -0
  29. package/dist/chat/providers/local.js.map +1 -0
  30. package/dist/chat/providers/openai-compatible.d.ts +155 -0
  31. package/dist/chat/providers/openai-compatible.d.ts.map +1 -0
  32. package/dist/chat/providers/openai-compatible.js +264 -0
  33. package/dist/chat/providers/openai-compatible.js.map +1 -0
  34. package/dist/chat/providers/openai.d.ts +24 -0
  35. package/dist/chat/providers/openai.d.ts.map +1 -0
  36. package/dist/chat/providers/openai.js +62 -0
  37. package/dist/chat/providers/openai.js.map +1 -0
  38. package/dist/chat/providers/openrouter.d.ts +26 -0
  39. package/dist/chat/providers/openrouter.d.ts.map +1 -0
  40. package/dist/chat/providers/openrouter.js +65 -0
  41. package/dist/chat/providers/openrouter.js.map +1 -0
  42. package/dist/chat/providers/provider-fetch.d.ts +15 -0
  43. package/dist/chat/providers/provider-fetch.d.ts.map +1 -0
  44. package/dist/chat/providers/provider-fetch.js +35 -0
  45. package/dist/chat/providers/provider-fetch.js.map +1 -0
  46. package/dist/chat/providers/provider.d.ts +214 -0
  47. package/dist/chat/providers/provider.d.ts.map +1 -0
  48. package/dist/chat/providers/provider.js +166 -0
  49. package/dist/chat/providers/provider.js.map +1 -0
  50. package/dist/chat/providers/sse-reader.d.ts +21 -0
  51. package/dist/chat/providers/sse-reader.d.ts.map +1 -0
  52. package/dist/chat/providers/sse-reader.js +48 -0
  53. package/dist/chat/providers/sse-reader.js.map +1 -0
  54. package/dist/chat/system-prompt.d.ts +33 -0
  55. package/dist/chat/system-prompt.d.ts.map +1 -0
  56. package/dist/chat/system-prompt.js +166 -0
  57. package/dist/chat/system-prompt.js.map +1 -0
  58. package/dist/chat/tool-envelope.d.ts +72 -0
  59. package/dist/chat/tool-envelope.d.ts.map +1 -0
  60. package/dist/chat/tool-envelope.js +263 -0
  61. package/dist/chat/tool-envelope.js.map +1 -0
  62. package/dist/commands/abilities/info.d.ts +21 -0
  63. package/dist/commands/abilities/info.d.ts.map +1 -0
  64. package/dist/commands/abilities/info.js +80 -0
  65. package/dist/commands/abilities/info.js.map +1 -0
  66. package/dist/commands/abilities/list.d.ts +19 -0
  67. package/dist/commands/abilities/list.d.ts.map +1 -0
  68. package/dist/commands/abilities/list.js +98 -0
  69. package/dist/commands/abilities/list.js.map +1 -0
  70. package/dist/commands/abilities/run.d.ts +75 -0
  71. package/dist/commands/abilities/run.d.ts.map +1 -0
  72. package/dist/commands/abilities/run.js +468 -0
  73. package/dist/commands/abilities/run.js.map +1 -0
  74. package/dist/commands/chat.d.ts +54 -0
  75. package/dist/commands/chat.d.ts.map +1 -0
  76. package/dist/commands/chat.js +384 -0
  77. package/dist/commands/chat.js.map +1 -0
  78. package/dist/commands/config/show.d.ts +54 -0
  79. package/dist/commands/config/show.d.ts.map +1 -0
  80. package/dist/commands/config/show.js +324 -0
  81. package/dist/commands/config/show.js.map +1 -0
  82. package/dist/commands/doctor.d.ts +77 -0
  83. package/dist/commands/doctor.d.ts.map +1 -0
  84. package/dist/commands/doctor.js +412 -0
  85. package/dist/commands/doctor.js.map +1 -0
  86. package/dist/commands/jobs/watch.d.ts +50 -0
  87. package/dist/commands/jobs/watch.d.ts.map +1 -0
  88. package/dist/commands/jobs/watch.js +269 -0
  89. package/dist/commands/jobs/watch.js.map +1 -0
  90. package/dist/commands/login.d.ts +25 -0
  91. package/dist/commands/login.d.ts.map +1 -0
  92. package/dist/commands/login.js +165 -0
  93. package/dist/commands/login.js.map +1 -0
  94. package/dist/commands/profile/delete.d.ts +22 -0
  95. package/dist/commands/profile/delete.d.ts.map +1 -0
  96. package/dist/commands/profile/delete.js +57 -0
  97. package/dist/commands/profile/delete.js.map +1 -0
  98. package/dist/commands/profile/list.d.ts +19 -0
  99. package/dist/commands/profile/list.d.ts.map +1 -0
  100. package/dist/commands/profile/list.js +53 -0
  101. package/dist/commands/profile/list.js.map +1 -0
  102. package/dist/commands/profile/use.d.ts +22 -0
  103. package/dist/commands/profile/use.d.ts.map +1 -0
  104. package/dist/commands/profile/use.js +46 -0
  105. package/dist/commands/profile/use.js.map +1 -0
  106. package/dist/config/fs-utils.d.ts +14 -0
  107. package/dist/config/fs-utils.d.ts.map +1 -0
  108. package/dist/config/fs-utils.js +31 -0
  109. package/dist/config/fs-utils.js.map +1 -0
  110. package/dist/config/keychain.d.ts +53 -0
  111. package/dist/config/keychain.d.ts.map +1 -0
  112. package/dist/config/keychain.js +175 -0
  113. package/dist/config/keychain.js.map +1 -0
  114. package/dist/config/profile-store.d.ts +85 -0
  115. package/dist/config/profile-store.d.ts.map +1 -0
  116. package/dist/config/profile-store.js +228 -0
  117. package/dist/config/profile-store.js.map +1 -0
  118. package/dist/config/settings.d.ts +71 -0
  119. package/dist/config/settings.d.ts.map +1 -0
  120. package/dist/config/settings.js +151 -0
  121. package/dist/config/settings.js.map +1 -0
  122. package/dist/core/abilities-executor.d.ts +126 -0
  123. package/dist/core/abilities-executor.d.ts.map +1 -0
  124. package/dist/core/abilities-executor.js +264 -0
  125. package/dist/core/abilities-executor.js.map +1 -0
  126. package/dist/core/batch-manager.d.ts +113 -0
  127. package/dist/core/batch-manager.d.ts.map +1 -0
  128. package/dist/core/batch-manager.js +244 -0
  129. package/dist/core/batch-manager.js.map +1 -0
  130. package/dist/core/http-client.d.ts +111 -0
  131. package/dist/core/http-client.d.ts.map +1 -0
  132. package/dist/core/http-client.js +329 -0
  133. package/dist/core/http-client.js.map +1 -0
  134. package/dist/core/safety-controller.d.ts +114 -0
  135. package/dist/core/safety-controller.d.ts.map +1 -0
  136. package/dist/core/safety-controller.js +229 -0
  137. package/dist/core/safety-controller.js.map +1 -0
  138. package/dist/hooks/command-not-found.d.ts +12 -0
  139. package/dist/hooks/command-not-found.d.ts.map +1 -0
  140. package/dist/hooks/command-not-found.js +58 -0
  141. package/dist/hooks/command-not-found.js.map +1 -0
  142. package/dist/index.d.ts +7 -0
  143. package/dist/index.d.ts.map +1 -0
  144. package/dist/index.js +7 -0
  145. package/dist/index.js.map +1 -0
  146. package/dist/lib/base-command.d.ts +123 -0
  147. package/dist/lib/base-command.d.ts.map +1 -0
  148. package/dist/lib/base-command.js +285 -0
  149. package/dist/lib/base-command.js.map +1 -0
  150. package/dist/output/formatter.d.ts +48 -0
  151. package/dist/output/formatter.d.ts.map +1 -0
  152. package/dist/output/formatter.js +138 -0
  153. package/dist/output/formatter.js.map +1 -0
  154. package/dist/output/json-envelope.d.ts +43 -0
  155. package/dist/output/json-envelope.d.ts.map +1 -0
  156. package/dist/output/json-envelope.js +73 -0
  157. package/dist/output/json-envelope.js.map +1 -0
  158. package/dist/utils/audit-logger.d.ts +97 -0
  159. package/dist/utils/audit-logger.d.ts.map +1 -0
  160. package/dist/utils/audit-logger.js +169 -0
  161. package/dist/utils/audit-logger.js.map +1 -0
  162. package/dist/utils/colors.d.ts +29 -0
  163. package/dist/utils/colors.d.ts.map +1 -0
  164. package/dist/utils/colors.js +36 -0
  165. package/dist/utils/colors.js.map +1 -0
  166. package/dist/utils/errors.d.ts +107 -0
  167. package/dist/utils/errors.d.ts.map +1 -0
  168. package/dist/utils/errors.js +149 -0
  169. package/dist/utils/errors.js.map +1 -0
  170. package/dist/utils/exit-codes.d.ts +21 -0
  171. package/dist/utils/exit-codes.d.ts.map +1 -0
  172. package/dist/utils/exit-codes.js +20 -0
  173. package/dist/utils/exit-codes.js.map +1 -0
  174. package/dist/utils/format.d.ts +64 -0
  175. package/dist/utils/format.d.ts.map +1 -0
  176. package/dist/utils/format.js +69 -0
  177. package/dist/utils/format.js.map +1 -0
  178. package/dist/utils/prompt.d.ts +34 -0
  179. package/dist/utils/prompt.d.ts.map +1 -0
  180. package/dist/utils/prompt.js +132 -0
  181. package/dist/utils/prompt.js.map +1 -0
  182. package/dist/utils/retry.d.ts +59 -0
  183. package/dist/utils/retry.d.ts.map +1 -0
  184. package/dist/utils/retry.js +96 -0
  185. package/dist/utils/retry.js.map +1 -0
  186. package/dist/utils/terminal-sanitizer.d.ts +60 -0
  187. package/dist/utils/terminal-sanitizer.d.ts.map +1 -0
  188. package/dist/utils/terminal-sanitizer.js +166 -0
  189. package/dist/utils/terminal-sanitizer.js.map +1 -0
  190. package/dist/validation/input-sanitizer.d.ts +76 -0
  191. package/dist/validation/input-sanitizer.d.ts.map +1 -0
  192. package/dist/validation/input-sanitizer.js +199 -0
  193. package/dist/validation/input-sanitizer.js.map +1 -0
  194. package/dist/validation/schema-validator.d.ts +75 -0
  195. package/dist/validation/schema-validator.d.ts.map +1 -0
  196. package/dist/validation/schema-validator.js +147 -0
  197. package/dist/validation/schema-validator.js.map +1 -0
  198. package/oclif.manifest.json +857 -0
  199. package/package.json +101 -0
  200. package/scripts/completions/README.md +221 -0
  201. package/scripts/completions/mainwpcontrol.bash +193 -0
  202. package/scripts/completions/mainwpcontrol.zsh +267 -0
  203. package/scripts/completions/profile-completer.sh +35 -0
  204. package/scripts/completions/regenerate.sh +78 -0
@@ -0,0 +1,166 @@
1
+ /**
2
+ * System Prompt for MainWP Control chat
3
+ *
4
+ * Embeds the runtime AI behavior contract from CHAT_PROMPT.md.
5
+ * This is executable configuration, not documentation.
6
+ *
7
+ * INVARIANT: AI is the primary interaction surface, NOT the execution authority.
8
+ */
9
+ /**
10
+ * Core system prompt content
11
+ * Derived from CHAT_PROMPT.md (authoritative document)
12
+ */
13
+ const CORE_PROMPT = `You are an AI assistant embedded in MainWP Control (\`mainwpcontrol\`), a command-line tool for MainWP Dashboard management.
14
+
15
+ ## Role
16
+
17
+ You are the **primary interaction surface**.
18
+ You are **NOT** an execution authority.
19
+
20
+ ## Absolute Prohibitions
21
+
22
+ You must NEVER:
23
+ - Execute actions directly
24
+ - Bypass validation or safety checks
25
+ - Invent abilities or parameters that don't exist
26
+ - Auto-confirm destructive operations
27
+ - Retry execution automatically without user knowledge
28
+
29
+ Only the MainWP Abilities API executes actions. You propose tool calls; the system executes them.
30
+
31
+ ## Tool Usage Contract
32
+
33
+ Each turn, you MUST output exactly ONE of:
34
+ - A tool call: \`{ "tool": "<tool_name>", "input": { ... } }\`
35
+ - An answer: \`{ "answer": "<human-readable response>" }\`
36
+
37
+ NEVER output both in the same turn.
38
+ NEVER output anything else.
39
+
40
+ ## Destructive Safety Rules
41
+
42
+ If an ability is marked destructive, you MUST follow this flow:
43
+ 1. First call with \`dry_run: true\` to preview changes
44
+ 2. Present the preview results to the user
45
+ 3. Ask for explicit user approval
46
+ 4. Only after approval, call with \`confirm: true\`
47
+
48
+ NEVER skip the preview step for destructive actions.
49
+ NEVER inject \`confirm: true\` without explicit user approval.
50
+
51
+ ## Error Handling
52
+
53
+ - Missing required inputs → Ask the user to provide them
54
+ - Invalid tool call → System will inform you; reformulate
55
+ - Repeated failures → Explain the situation and suggest next steps
56
+
57
+ Always fail safely and visibly.
58
+
59
+ ## Response Format
60
+
61
+ Your response MUST be valid JSON in one of these formats:
62
+
63
+ Tool call format:
64
+ \`\`\`json
65
+ {
66
+ "tool": "ability-name-v1",
67
+ "input": {
68
+ "param1": "value1"
69
+ }
70
+ }
71
+ \`\`\`
72
+
73
+ Answer format:
74
+ \`\`\`json
75
+ {
76
+ "answer": "Your response to the user"
77
+ }
78
+ \`\`\`
79
+
80
+ ## Key Principle
81
+
82
+ AI is the primary interaction surface, NOT the execution authority.
83
+ You interpret intent, explain consequences, and summarize results.
84
+ The system handles all actual execution through the Abilities API.`;
85
+ /**
86
+ * Format ability for inclusion in system prompt
87
+ */
88
+ function formatAbility(ability) {
89
+ const annotations = ability.meta?.annotations;
90
+ const tags = [];
91
+ if (annotations?.readonly)
92
+ tags.push('readonly');
93
+ if (annotations?.destructive)
94
+ tags.push('DESTRUCTIVE');
95
+ if (annotations?.idempotent)
96
+ tags.push('idempotent');
97
+ const tagStr = tags.length > 0 ? ` [${tags.join(', ')}]` : '';
98
+ return `- **${ability.name}**${tagStr}: ${ability.description}`;
99
+ }
100
+ /**
101
+ * Build abilities section for system prompt
102
+ */
103
+ function buildAbilitiesSection(abilities) {
104
+ if (abilities.length === 0) {
105
+ return '\n## Available Tools\n\nNo abilities available. Please check Dashboard connection.';
106
+ }
107
+ // Group by category
108
+ const byCategory = new Map();
109
+ for (const ability of abilities) {
110
+ const category = ability.category || 'Other';
111
+ const list = byCategory.get(category) ?? [];
112
+ list.push(ability);
113
+ byCategory.set(category, list);
114
+ }
115
+ const sections = ['\n## Available Tools\n'];
116
+ for (const [category, categoryAbilities] of byCategory.entries()) {
117
+ sections.push(`### ${category}\n`);
118
+ for (const ability of categoryAbilities) {
119
+ sections.push(formatAbility(ability));
120
+ }
121
+ sections.push('');
122
+ }
123
+ // Add destructive actions reminder
124
+ const destructive = abilities.filter((a) => a.meta?.annotations?.destructive);
125
+ if (destructive.length > 0) {
126
+ sections.push('\n## Destructive Actions Warning\n');
127
+ sections.push('The following abilities are DESTRUCTIVE and require the preview → approval flow:\n');
128
+ for (const ability of destructive) {
129
+ sections.push(`- ${ability.name}`);
130
+ }
131
+ sections.push('');
132
+ }
133
+ return sections.join('\n');
134
+ }
135
+ /**
136
+ * Build complete system prompt with abilities
137
+ */
138
+ function buildSystemPrompt(abilities) {
139
+ return CORE_PROMPT + buildAbilitiesSection(abilities);
140
+ }
141
+ /**
142
+ * Default system prompt configuration
143
+ */
144
+ export const defaultConfig = {
145
+ maxToolCalls: 3,
146
+ maxParseRetries: 2,
147
+ includeSchemas: false,
148
+ maxContextMessages: 20,
149
+ };
150
+ /**
151
+ * Build system prompt with configuration
152
+ */
153
+ export function buildConfiguredPrompt(abilities, config = {}) {
154
+ const mergedConfig = { ...defaultConfig, ...config };
155
+ let prompt = buildSystemPrompt(abilities);
156
+ // Add configuration constraints
157
+ prompt += `\n## Constraints\n`;
158
+ prompt += `- Maximum tool calls per turn: ${mergedConfig.maxToolCalls}\n`;
159
+ prompt += `- If you need more tool calls, explain and ask to continue\n`;
160
+ // Add context window constraints (omit if 0/unlimited to avoid misleading text)
161
+ if (mergedConfig.maxContextMessages !== undefined && mergedConfig.maxContextMessages > 0) {
162
+ prompt += `- Context window: ${mergedConfig.maxContextMessages} messages (older messages may be truncated)\n`;
163
+ }
164
+ return prompt;
165
+ }
166
+ //# sourceMappingURL=system-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/chat/system-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;GAGG;AACH,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mEAuE+C,CAAC;AAEpE;;GAEG;AACH,SAAS,aAAa,CAAC,O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AAG,MAAM,EAAE,CAAC;IAErD,IAAI,MAAM,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAE1C,gCAAgC;IAChC,MAAM,IAAI,oBAAoB,CAAC;IAC/B,MAAM,IAAI,kCAAkC,YAAY,CAAC,YAAY,IAAI,CAAC;IAC1E,MAAM,IAAI,8DAA8D,CAAC;IAEzE,gFAAgF;IAChF,IAAI,YAAY,CAAC,kBAAkB,KAAK,SAAS,IAAI,YAAY,CAAC,kBAAkB,GAAG,CAAC,EAAE,CAAC;QACzF,MAAM,IAAI,qBAAqB,YAAY,CAAC,kBAAkB,+CAA+C,CAAC;IAChH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Tool Envelope Parser for mainwpcontrol
3
+ *
4
+ * Parses and validates LLM tool call responses.
5
+ * Supports both native function calling (from provider) and JSON in content.
6
+ *
7
+ * Contract (from CHAT_PROMPT.md):
8
+ * - Tool call: { "tool": "<tool_name>", "input": { ... } }
9
+ * - Answer: { "answer": "<human-readable response>" }
10
+ */
11
+ import type { LLMResponse } from './providers/provider.js';
12
+ import type { Ability } from '../core/abilities-executor.js';
13
+ /**
14
+ * Parsed response types
15
+ */
16
+ export type ParsedResponse = {
17
+ type: 'tool';
18
+ tool: string;
19
+ input: Record<string, unknown>;
20
+ id?: string;
21
+ } | {
22
+ type: 'answer';
23
+ answer: string;
24
+ } | {
25
+ type: 'error';
26
+ error: string;
27
+ retryable: boolean;
28
+ };
29
+ /**
30
+ * Parse result with metadata
31
+ */
32
+ export interface ParseResult {
33
+ response: ParsedResponse;
34
+ /** Raw content from LLM */
35
+ rawContent: string;
36
+ /** Whether this came from native function calling */
37
+ nativeFunctionCall: boolean;
38
+ /** Parse attempt count */
39
+ attempts: number;
40
+ }
41
+ /**
42
+ * Tool envelope parser options
43
+ */
44
+ export interface ParserOptions {
45
+ /** Known abilities for validation */
46
+ abilities?: Ability[];
47
+ /** Whether to validate tool exists in abilities list */
48
+ validateToolExists?: boolean;
49
+ /** Whether to validate input against schema */
50
+ validateInput?: boolean;
51
+ }
52
+ /**
53
+ * Parse LLM response to extract tool call or answer
54
+ */
55
+ export declare function parseResponse(response: LLMResponse, options?: ParserOptions): ParseResult;
56
+ /**
57
+ * Format tool call for display
58
+ */
59
+ export declare function formatToolCall(tool: string, input: Record<string, unknown>): string;
60
+ /**
61
+ * Format parsed response for display
62
+ */
63
+ export declare function formatParsedResponse(result: ParseResult): string;
64
+ /**
65
+ * Check if response is retryable
66
+ */
67
+ export declare function isRetryable(result: ParseResult): boolean;
68
+ /**
69
+ * Build retry prompt for invalid JSON
70
+ */
71
+ export declare function buildRetryPrompt(result: ParseResult): string;
72
+ //# sourceMappingURL=tool-envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-envelope.d.ts","sourceRoot":"","sources":["../../src/chat/tool-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAY,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3E;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,cAAc,CAAC;IACzB,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,kBAAkB,EAAE,OAAO,CAAC;IAC5B,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC;IACtB,wDAAwD;IACxD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,+CAA+C;IAC/C,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAcD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,WAAW,EACrB,OAAO,GAAE,aAAkB,GAC1B,WAAW,CAWb;AAwND;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAGR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAWhE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAExD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAuB5D"}
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Tool Envelope Parser for mainwpcontrol
3
+ *
4
+ * Parses and validates LLM tool call responses.
5
+ * Supports both native function calling (from provider) and JSON in content.
6
+ *
7
+ * Contract (from CHAT_PROMPT.md):
8
+ * - Tool call: { "tool": "<tool_name>", "input": { ... } }
9
+ * - Answer: { "answer": "<human-readable response>" }
10
+ */
11
+ /**
12
+ * JSON extraction patterns
13
+ */
14
+ const JSON_PATTERNS = [
15
+ // Code block with json
16
+ /```json\s*\n?([\s\S]*?)\n?```/,
17
+ // Code block without language
18
+ /```\s*\n?([\s\S]*?)\n?```/,
19
+ // Raw JSON object
20
+ /(\{[\s\S]*\})/,
21
+ ];
22
+ /**
23
+ * Parse LLM response to extract tool call or answer
24
+ */
25
+ export function parseResponse(response, options = {}) {
26
+ // First, check for native function calling
27
+ if (response.toolCalls && response.toolCalls.length > 0) {
28
+ const firstToolCall = response.toolCalls[0];
29
+ if (firstToolCall) {
30
+ return parseNativeToolCall(firstToolCall, options);
31
+ }
32
+ }
33
+ // Otherwise, parse JSON from content
34
+ return parseContentJson(response.content, options);
35
+ }
36
+ /**
37
+ * Parse native tool call from provider
38
+ */
39
+ function parseNativeToolCall(toolCall, options) {
40
+ const validation = validateToolCall(toolCall.name, toolCall.arguments, options);
41
+ if (validation) {
42
+ return {
43
+ response: { type: 'error', error: validation, retryable: false },
44
+ rawContent: JSON.stringify(toolCall),
45
+ nativeFunctionCall: true,
46
+ attempts: 1,
47
+ };
48
+ }
49
+ return {
50
+ response: {
51
+ type: 'tool',
52
+ tool: toolCall.name,
53
+ input: toolCall.arguments,
54
+ id: toolCall.id,
55
+ },
56
+ rawContent: JSON.stringify(toolCall),
57
+ nativeFunctionCall: true,
58
+ attempts: 1,
59
+ };
60
+ }
61
+ /**
62
+ * Parse JSON from content string
63
+ */
64
+ function parseContentJson(content, options) {
65
+ const trimmed = content.trim();
66
+ // Try to extract JSON
67
+ let jsonStr = null;
68
+ let attempts = 0;
69
+ for (const pattern of JSON_PATTERNS) {
70
+ attempts++;
71
+ const match = trimmed.match(pattern);
72
+ if (match?.[1]) {
73
+ jsonStr = match[1].trim();
74
+ break;
75
+ }
76
+ }
77
+ // If no pattern matched, try the whole content
78
+ if (!jsonStr) {
79
+ jsonStr = trimmed;
80
+ attempts++;
81
+ }
82
+ // Parse JSON
83
+ let parsed;
84
+ try {
85
+ parsed = JSON.parse(jsonStr);
86
+ }
87
+ catch {
88
+ return {
89
+ response: {
90
+ type: 'error',
91
+ error: `Invalid JSON in response: ${jsonStr.slice(0, 100)}...`,
92
+ retryable: true,
93
+ },
94
+ rawContent: content,
95
+ nativeFunctionCall: false,
96
+ attempts,
97
+ };
98
+ }
99
+ // Validate structure
100
+ if (typeof parsed !== 'object' || parsed === null) {
101
+ return {
102
+ response: {
103
+ type: 'error',
104
+ error: 'Response must be a JSON object',
105
+ retryable: true,
106
+ },
107
+ rawContent: content,
108
+ nativeFunctionCall: false,
109
+ attempts,
110
+ };
111
+ }
112
+ const obj = parsed;
113
+ // Check for answer format
114
+ if ('answer' in obj && typeof obj['answer'] === 'string') {
115
+ return {
116
+ response: { type: 'answer', answer: obj['answer'] },
117
+ rawContent: content,
118
+ nativeFunctionCall: false,
119
+ attempts,
120
+ };
121
+ }
122
+ // Check for tool format
123
+ if ('tool' in obj && typeof obj['tool'] === 'string') {
124
+ const toolName = obj['tool'];
125
+ const input = typeof obj['input'] === 'object' && obj['input'] !== null
126
+ ? obj['input']
127
+ : {};
128
+ const validation = validateToolCall(toolName, input, options);
129
+ if (validation) {
130
+ return {
131
+ response: { type: 'error', error: validation, retryable: false },
132
+ rawContent: content,
133
+ nativeFunctionCall: false,
134
+ attempts,
135
+ };
136
+ }
137
+ return {
138
+ response: { type: 'tool', tool: toolName, input },
139
+ rawContent: content,
140
+ nativeFunctionCall: false,
141
+ attempts,
142
+ };
143
+ }
144
+ // Invalid format
145
+ return {
146
+ response: {
147
+ type: 'error',
148
+ error: 'Response must have either "tool" with "input" or "answer" property',
149
+ retryable: true,
150
+ },
151
+ rawContent: content,
152
+ nativeFunctionCall: false,
153
+ attempts,
154
+ };
155
+ }
156
+ /**
157
+ * Validate tool call against known abilities
158
+ */
159
+ function validateToolCall(toolName, input, options) {
160
+ // Validate tool exists if abilities provided
161
+ if (options.validateToolExists && options.abilities) {
162
+ const ability = findAbility(toolName, options.abilities);
163
+ if (!ability) {
164
+ const availableTools = options.abilities.map((a) => a.name).join(', ');
165
+ return `Unknown tool: "${toolName}". Available tools: ${availableTools}`;
166
+ }
167
+ // Validate required inputs if schema available
168
+ if (options.validateInput && ability.input_schema) {
169
+ const requiredError = validateRequiredInputs(input, ability.input_schema);
170
+ if (requiredError) {
171
+ return requiredError;
172
+ }
173
+ }
174
+ }
175
+ return null;
176
+ }
177
+ /**
178
+ * Find ability by name (supports short name and full name)
179
+ */
180
+ function findAbility(name, abilities) {
181
+ // Exact match
182
+ const exact = abilities.find((a) => a.name === name);
183
+ if (exact)
184
+ return exact;
185
+ // Short name match (e.g., "list-sites-v1" matches "mainwp/list-sites-v1")
186
+ const shortMatch = abilities.find((a) => {
187
+ const parts = a.name.split('/');
188
+ return parts[parts.length - 1] === name;
189
+ });
190
+ if (shortMatch)
191
+ return shortMatch;
192
+ // Prefix match (e.g., "mainwp/list-sites-v1" matches "list-sites-v1")
193
+ const prefixMatch = abilities.find((a) => a.name.endsWith(`/${name}`));
194
+ return prefixMatch;
195
+ }
196
+ /**
197
+ * Validate required inputs are present
198
+ */
199
+ function validateRequiredInputs(input, schema) {
200
+ const required = schema['required'];
201
+ if (!required || required.length === 0) {
202
+ return null;
203
+ }
204
+ const missing = required.filter((key) => !(key in input) || input[key] === undefined);
205
+ if (missing.length > 0) {
206
+ return `Missing required parameters: ${missing.join(', ')}`;
207
+ }
208
+ return null;
209
+ }
210
+ /**
211
+ * Format tool call for display
212
+ */
213
+ export function formatToolCall(tool, input) {
214
+ const inputStr = JSON.stringify(input, null, 2);
215
+ return `Tool: ${tool}\nInput: ${inputStr}`;
216
+ }
217
+ /**
218
+ * Format parsed response for display
219
+ */
220
+ export function formatParsedResponse(result) {
221
+ const { response } = result;
222
+ switch (response.type) {
223
+ case 'tool':
224
+ return formatToolCall(response.tool, response.input);
225
+ case 'answer':
226
+ return response.answer;
227
+ case 'error':
228
+ return `Error: ${response.error}`;
229
+ }
230
+ }
231
+ /**
232
+ * Check if response is retryable
233
+ */
234
+ export function isRetryable(result) {
235
+ return result.response.type === 'error' && result.response.retryable;
236
+ }
237
+ /**
238
+ * Build retry prompt for invalid JSON
239
+ */
240
+ export function buildRetryPrompt(result) {
241
+ if (result.response.type !== 'error') {
242
+ return '';
243
+ }
244
+ return `Your previous response was not valid JSON. Error: ${result.response.error}
245
+
246
+ Please respond with a valid JSON object in one of these formats:
247
+
248
+ Tool call:
249
+ \`\`\`json
250
+ {
251
+ "tool": "ability-name-v1",
252
+ "input": { "param1": "value1" }
253
+ }
254
+ \`\`\`
255
+
256
+ Or answer:
257
+ \`\`\`json
258
+ {
259
+ "answer": "Your response here"
260
+ }
261
+ \`\`\``;
262
+ }
263
+ //# sourceMappingURL=tool-envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-envelope.js","sourceRoot":"","sources":["../../src/chat/tool-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAsCH;;GAEG;AACH,MAAM,aAAa,GAAG;IACpB,uBAAuB;IACvB,+BAA+B;IAC/B,8BAA8B;IAC9B,2BAA2B;IAC3B,kBAAkB;IAClB,eAAe;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAqB,EACrB,UAAyB,EAAE;IAE3B,2CAA2C;IAC3C,IAAI,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxD,MAAM,aAAa,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,mBAAmB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,qCAAqC;IACrC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAC1B,QAAkB,EAClB,OAAsB;IAEtB,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAEhF,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;YACL,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE;YAChE,U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;;OAiB5E,CAAC;AACR,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Abilities info command for mainwpcontrol
3
+ *
4
+ * Shows detailed information about a specific ability.
5
+ */
6
+ import { BaseCommand } from '../../lib/base-command.js';
7
+ export default class AbilitiesInfo extends BaseCommand {
8
+ static description: string;
9
+ static examples: string[];
10
+ static flags: {
11
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ debug: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ };
16
+ static args: {
17
+ name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
18
+ };
19
+ run(): Promise<void>;
20
+ }
21
+ //# sourceMappingURL=info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../../src/commands/abilities/info.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,WAAW,EAAe,MAAM,2BAA2B,CAAC;AAIrE,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,WAAW;IACpD,MAAM,CAAC,WAAW,SAA+C;IAEjE,MAAM,CAAC,QAAQ,WAGb;IAEF,MAAM,CAAC,KAAK;;;;;MAEV;IAEF,MAAM,CAAC,IAAI;;MAKT;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAkE3B"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Abilities info command for mainwpcontrol
3
+ *
4
+ * Shows detailed information about a specific ability.
5
+ */
6
+ import { Args } from '@oclif/core';
7
+ import { BaseCommand, commonFlags } from '../../lib/base-command.js';
8
+ import { formatHeading, formatKeyValue } from '../../output/formatter.js';
9
+ import { InputError } from '../../utils/errors.js';
10
+ export default class AbilitiesInfo extends BaseCommand {
11
+ static description = 'Get detailed information about an ability';
12
+ static examples = [
13
+ '<%= config.bin %> abilities info list-sites-v1',
14
+ '<%= config.bin %> abilities info mainwp/delete-site-v1 --json',
15
+ ];
16
+ static flags = {
17
+ ...commonFlags,
18
+ };
19
+ static args = {
20
+ name: Args.string({
21
+ description: 'Ability name (e.g., list-sites-v1)',
22
+ required: true,
23
+ }),
24
+ };
25
+ async run() {
26
+ const { args, flags } = await this.parse(AbilitiesInfo);
27
+ await this.initCommon(flags);
28
+ const executor = await this.getExecutor();
29
+ const ability = await executor.getAbility(args.name);
30
+ if (!ability) {
31
+ throw new InputError(`Ability not found: ${args.name}. Run \`mainwpcontrol abilities list\` to see available abilities.`);
32
+ }
33
+ this.output({
34
+ name: ability.name,
35
+ label: ability.label,
36
+ description: ability.description,
37
+ category: ability.category,
38
+ annotations: ability.meta?.annotations ?? {},
39
+ inputSchema: ability.input_schema,
40
+ outputSchema: ability.output_schema,
41
+ }, () => {
42
+ const lines = [
43
+ formatHeading(ability.label || ability.name),
44
+ '',
45
+ ability.description,
46
+ '',
47
+ formatKeyValue('Name', ability.name),
48
+ formatKeyValue('Category', ability.category),
49
+ '',
50
+ formatHeading('Annotations'),
51
+ ];
52
+ const annotations = ability.meta?.annotations;
53
+ if (annotations) {
54
+ lines.push(formatKeyValue(' Readonly', annotations.readonly ? 'Yes' : 'No'));
55
+ lines.push(formatKeyValue(' Destructive', annotations.destructive ? 'Yes' : 'No'));
56
+ lines.push(formatKeyValue(' Idempotent', annotations.idempotent ? 'Yes' : 'No'));
57
+ if (annotations.instructions) {
58
+ lines.push('');
59
+ lines.push(formatHeading('Instructions'));
60
+ lines.push(annotations.instructions);
61
+ }
62
+ }
63
+ else {
64
+ lines.push(' (no annotations)');
65
+ }
66
+ if (ability.input_schema) {
67
+ lines.push('');
68
+ lines.push(formatHeading('Input Schema'));
69
+ lines.push(JSON.stringify(ability.input_schema, null, 2));
70
+ }
71
+ if (ability.output_schema) {
72
+ lines.push('');
73
+ lines.push(formatHeading('Output Schema'));
74
+ lines.push(JSON.stringify(ability.output_schema, null, 2));
75
+ }
76
+ return lines.join('\n');
77
+ });
78
+ }
79
+ }
80
+ //# sourceMappingURL=info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"info.js","sourceRoot":"","sources":["../../../src/commands/abilities/info.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,WAAW;IACpD,MAAM,CAAC,WAAW,GAAG,2CAA2C,CAAC;IAEjE,MAAM,CAAC,QAAQ,GAAG;QAChB,gDAAgD;QAChD,+DAA+D;KAChE,CAAC;IAEF,MAAM,CAAC,KAAK,GAAG;QACb,GAAG,WAAW;KACf,CAAC;IAEF,MAAM,CAAC,IAAI,GAAG;QACZ,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;YAChB,WAAW,EAAE,oCAAoC;YACjD,QAAQ,EAAE,IAAI;SACf,CAAC;KACH,CAAC;IAEF,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACxD,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAE7B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,UAAU,CAClB,sBAAsB,IAAI,CAAC,IAAI,oEAAoE,CACpG,CAAC;QACJ,CAAC;QA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,CAAC,CAAC;oBACf,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;oBAC1C,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;gBACvC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACnC,CAAC;YAED,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;gBACzB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACf,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC;gBAC1C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC5D,CAAC;YAED,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBAC1B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACf,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC;gBAC3C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC7D,CAAC;YAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC,CACF,CAAC;IACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Abilities list command for mainwpcontrol
3
+ *
4
+ * Lists all available abilities from the Dashboard.
5
+ */
6
+ import { BaseCommand } from '../../lib/base-command.js';
7
+ export default class AbilitiesList extends BaseCommand {
8
+ static description: string;
9
+ static examples: string[];
10
+ static flags: {
11
+ category: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ debug: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ };
17
+ run(): Promise<void>;
18
+ }
19
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/commands/abilities/list.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,WAAW,EAAe,MAAM,2BAA2B,CAAC;AAKrE,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,WAAW;IACpD,MAAM,CAAC,WAAW,SAA8B;IAEhD,MAAM,CAAC,QAAQ,WAIb;IAEF,MAAM,CAAC,KAAK;;;;;;MAMV;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA0F3B"}