@denizokcu/haze 0.5.0 → 0.7.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 (162) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/README.md +101 -24
  3. package/dist/cli/chat/TaskBar.d.ts +9 -0
  4. package/dist/cli/chat/TaskBar.js +40 -0
  5. package/dist/cli/chat/chatMetrics.d.ts +11 -0
  6. package/dist/cli/chat/chatMetrics.js +50 -0
  7. package/dist/cli/chat/inputSuggestions.d.ts +16 -0
  8. package/dist/cli/chat/inputSuggestions.js +55 -0
  9. package/dist/cli/chat/messages.d.ts +9 -0
  10. package/dist/cli/chat/messages.js +76 -0
  11. package/dist/cli/chat/sessionRecorder.d.ts +12 -0
  12. package/dist/cli/chat/sessionRecorder.js +21 -0
  13. package/dist/cli/chat/startupInfo.d.ts +4 -0
  14. package/dist/cli/chat/startupInfo.js +53 -0
  15. package/dist/cli/chat/turnState.d.ts +5 -0
  16. package/dist/cli/chat/turnState.js +20 -0
  17. package/dist/cli/commands/chat.d.ts +0 -1
  18. package/dist/cli/commands/chat.js +519 -495
  19. package/dist/cli/commands/chatModes.d.ts +8 -0
  20. package/dist/cli/commands/chatModes.js +44 -0
  21. package/dist/cli/commands/commandHelp.d.ts +6 -0
  22. package/dist/cli/commands/commandHelp.js +25 -0
  23. package/dist/cli/commands/commands.d.ts +3 -2
  24. package/dist/cli/commands/commands.js +55 -320
  25. package/dist/cli/commands/formatters.d.ts +27 -0
  26. package/dist/cli/commands/formatters.js +149 -4
  27. package/dist/cli/commands/initCommand.d.ts +2 -0
  28. package/dist/cli/commands/initCommand.js +19 -0
  29. package/dist/cli/commands/logsCommand.d.ts +2 -0
  30. package/dist/cli/commands/logsCommand.js +63 -0
  31. package/dist/cli/commands/lspWizard.d.ts +14 -0
  32. package/dist/cli/commands/lspWizard.js +44 -0
  33. package/dist/cli/commands/mcpWizard.d.ts +15 -0
  34. package/dist/cli/commands/mcpWizard.js +69 -0
  35. package/dist/cli/commands/modelCommand.d.ts +2 -0
  36. package/dist/cli/commands/modelCommand.js +36 -0
  37. package/dist/cli/commands/providerWizard.d.ts +30 -0
  38. package/dist/cli/commands/providerWizard.js +114 -0
  39. package/dist/cli/commands/runCommand.d.ts +16 -0
  40. package/dist/cli/commands/runCommand.js +170 -0
  41. package/dist/cli/commands/settingsSummary.d.ts +3 -0
  42. package/dist/cli/commands/settingsSummary.js +40 -0
  43. package/dist/cli/commands/skillConfirmRemove.d.ts +11 -0
  44. package/dist/cli/commands/skillConfirmRemove.js +19 -0
  45. package/dist/cli/commands/skillCreation.d.ts +12 -0
  46. package/dist/cli/commands/skillCreation.js +14 -0
  47. package/dist/cli/commands/skillWizard.d.ts +15 -0
  48. package/dist/cli/commands/skillWizard.js +38 -0
  49. package/dist/cli/commands/streaming/assistantText.d.ts +17 -0
  50. package/dist/cli/commands/streaming/assistantText.js +115 -0
  51. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +55 -0
  52. package/dist/cli/commands/streaming/toolGroupRenderer.js +102 -0
  53. package/dist/cli/commands/streaming/toolResultState.d.ts +13 -0
  54. package/dist/cli/commands/streaming/toolResultState.js +25 -0
  55. package/dist/cli/commands/streaming/turnRuntime.d.ts +78 -0
  56. package/dist/cli/commands/streaming/turnRuntime.js +86 -0
  57. package/dist/cli/commands/streaming.d.ts +10 -29
  58. package/dist/cli/commands/streaming.js +249 -911
  59. package/dist/cli/commands/wizardActions.d.ts +40 -0
  60. package/dist/cli/commands/wizardActions.js +40 -0
  61. package/dist/cli/commands/wizardInput.d.ts +4 -0
  62. package/dist/cli/commands/wizardInput.js +19 -0
  63. package/dist/cli/commands/wizardPrompts.d.ts +22 -0
  64. package/dist/cli/commands/wizardPrompts.js +52 -0
  65. package/dist/cli/commands/wizardSuggestions.d.ts +23 -0
  66. package/dist/cli/commands/wizardSuggestions.js +139 -0
  67. package/dist/cli/index.js +62 -4
  68. package/dist/config/contextFiles.d.ts +8 -1
  69. package/dist/config/contextFiles.js +25 -12
  70. package/dist/config/lspSettings.d.ts +16 -0
  71. package/dist/config/lspSettings.js +95 -0
  72. package/dist/config/mcpSettings.d.ts +24 -0
  73. package/dist/config/mcpSettings.js +100 -0
  74. package/dist/config/providers.js +4 -4
  75. package/dist/config/settings.d.ts +34 -0
  76. package/dist/config/skillSettings.d.ts +15 -0
  77. package/dist/config/skillSettings.js +32 -0
  78. package/dist/config/updateCheck.d.ts +44 -0
  79. package/dist/config/updateCheck.js +83 -0
  80. package/dist/core/agent/budgets.d.ts +6 -0
  81. package/dist/core/agent/budgets.js +6 -0
  82. package/dist/core/agent/compaction.js +1 -1
  83. package/dist/core/agent/requestAssembly.d.ts +0 -7
  84. package/dist/core/agent/requestAssembly.js +27 -5
  85. package/dist/core/agent/toolOutputStore.js +5 -4
  86. package/dist/core/agent/toolResults.d.ts +31 -0
  87. package/dist/core/agent/toolResults.js +42 -0
  88. package/dist/core/agent/turnPolicy.d.ts +8 -0
  89. package/dist/core/agent/turnPolicy.js +23 -0
  90. package/dist/core/agent/workState.d.ts +18 -5
  91. package/dist/core/agent/workState.js +39 -20
  92. package/dist/core/bashOutput/reducers/content.d.ts +1 -0
  93. package/dist/core/bashOutput/reducers/content.js +1 -1
  94. package/dist/core/bashOutput/reducers/gh.d.ts +1 -0
  95. package/dist/core/bashOutput/reducers/gh.js +77 -0
  96. package/dist/core/bashOutput/registry.js +8 -0
  97. package/dist/core/goal/sessionGoal.d.ts +6 -30
  98. package/dist/core/goal/sessionGoal.js +3 -68
  99. package/dist/core/safety/bashClassifier.js +30 -0
  100. package/dist/core/safety/urlGuard.d.ts +1 -0
  101. package/dist/core/safety/urlGuard.js +6 -1
  102. package/dist/core/session/sessionSlimming.d.ts +5 -0
  103. package/dist/core/session/sessionSlimming.js +78 -0
  104. package/dist/core/session/sessionStore.d.ts +23 -3
  105. package/dist/core/session/sessionStore.js +30 -10
  106. package/dist/core/subagent/subagentRunner.d.ts +11 -1
  107. package/dist/core/subagent/subagentRunner.js +1 -0
  108. package/dist/llm/capabilities.d.ts +12 -0
  109. package/dist/llm/capabilities.js +10 -0
  110. package/dist/llm/client.d.ts +1 -0
  111. package/dist/llm/client.js +11 -2
  112. package/dist/llm/hazeTools.d.ts +31 -32
  113. package/dist/llm/hazeTools.js +40 -567
  114. package/dist/llm/lsp.d.ts +109 -0
  115. package/dist/llm/lsp.js +241 -0
  116. package/dist/llm/lspTools.d.ts +104 -0
  117. package/dist/llm/lspTools.js +115 -0
  118. package/dist/llm/mcp.d.ts +19 -0
  119. package/dist/llm/mcp.js +73 -0
  120. package/dist/llm/requestContext.d.ts +28 -0
  121. package/dist/llm/requestContext.js +41 -0
  122. package/dist/llm/systemPrompt.d.ts +5 -1
  123. package/dist/llm/systemPrompt.js +9 -3
  124. package/dist/llm/tools/bashTool.d.ts +5 -0
  125. package/dist/llm/tools/bashTool.js +81 -0
  126. package/dist/llm/tools/editMatch.d.ts +55 -0
  127. package/dist/llm/tools/editMatch.js +99 -0
  128. package/dist/llm/tools/failures.d.ts +36 -0
  129. package/dist/llm/tools/failures.js +38 -0
  130. package/dist/llm/tools/fetchTool.d.ts +65 -0
  131. package/dist/llm/tools/fetchTool.js +45 -0
  132. package/dist/llm/tools/fileToolShared.d.ts +10 -0
  133. package/dist/llm/tools/fileToolShared.js +43 -0
  134. package/dist/llm/tools/grepParse.d.ts +13 -0
  135. package/dist/llm/tools/grepParse.js +67 -0
  136. package/dist/llm/tools/outputCap.d.ts +53 -0
  137. package/dist/llm/tools/outputCap.js +67 -0
  138. package/dist/llm/tools/storedOutputTool.d.ts +10 -0
  139. package/dist/llm/tools/storedOutputTool.js +17 -0
  140. package/dist/llm/tools/taskTool.d.ts +28 -0
  141. package/dist/llm/tools/taskTool.js +41 -0
  142. package/dist/llm/tools/toolContext.d.ts +69 -0
  143. package/dist/llm/tools/toolContext.js +187 -0
  144. package/dist/llm/tools/workspaceFile.d.ts +33 -0
  145. package/dist/llm/tools/workspaceFile.js +27 -0
  146. package/dist/llm/webFetch.d.ts +13 -1
  147. package/dist/llm/webFetch.js +91 -7
  148. package/dist/skills/builder/SkillBuilder.d.ts +3 -0
  149. package/dist/skills/builder/SkillBuilder.js +24 -45
  150. package/dist/ui/components/TextInput.d.ts +1 -1
  151. package/dist/ui/components/TextInput.js +1 -99
  152. package/dist/ui/inputBuffer.d.ts +28 -0
  153. package/dist/ui/inputBuffer.js +99 -0
  154. package/dist/utils/collections.d.ts +6 -0
  155. package/dist/utils/collections.js +9 -0
  156. package/dist/utils/path.d.ts +2 -0
  157. package/dist/utils/path.js +40 -0
  158. package/dist/utils/version.d.ts +20 -0
  159. package/dist/utils/version.js +72 -0
  160. package/package.json +2 -2
  161. package/dist/cli/commands/skills.d.ts +0 -4
  162. package/dist/cli/commands/skills.js +0 -38
@@ -1,3 +1,6 @@
1
+ import http from 'node:http';
2
+ import https from 'node:https';
3
+ import { Readable } from 'node:stream';
1
4
  import { validateUrl } from '../core/safety/urlGuard.js';
2
5
  const DEFAULT_TIMEOUT_MS = 30_000;
3
6
  const DEFAULT_MAX_BYTES = 2_000_000;
@@ -121,6 +124,80 @@ async function readBodyCapped(response, maxBytes, abortController) {
121
124
  }
122
125
  return { text, bytes: Math.min(received, maxBytes), truncated };
123
126
  }
127
+ /**
128
+ * Perform an HTTP(S) request with the TCP connection pinned to `pinnedIp`.
129
+ *
130
+ * This closes the DNS-rebinding TOCTOU: `validateUrl` resolved the hostname and
131
+ * verified every address is public, but the global `fetch` would re-resolve the
132
+ * hostname at connect time — an attacker-controlled DNS server can return a
133
+ * public IP for the validation lookup and a private/internal IP for the connect
134
+ * lookup. By connecting directly to the already-validated IP (`hostname:
135
+ * pinnedIp`) while keeping the original `Host` header and TLS `servername`
136
+ * (`url.hostname`), the connection target is fixed to what we validated, with no
137
+ * second DNS lookup. TLS certificate verification still runs against the original
138
+ * hostname via `servername`, so pinning does not weaken identity checks.
139
+ *
140
+ * Literal-IP URLs carry no DNS-rebinding surface (`pinnedIp` is undefined), so
141
+ * they fall through to the global `fetch` — which also keeps the test mocks that
142
+ * stub `globalThis.fetch` working for that path.
143
+ */
144
+ /**
145
+ * Coerce a RequestInit headers value into a plain string record. Keeps the
146
+ * transport defensive against `Headers`/tuple/array inputs instead of blindly
147
+ * casting (the fetch tool only ever passes a plain object, but be safe).
148
+ */
149
+ function normalizeHeaders(input) {
150
+ if (!input)
151
+ return {};
152
+ if (Array.isArray(input)) {
153
+ const out = {};
154
+ for (const pair of input) {
155
+ if (Array.isArray(pair) && pair.length === 2)
156
+ out[String(pair[0])] = String(pair[1]);
157
+ }
158
+ return out;
159
+ }
160
+ if (input instanceof Headers) {
161
+ const out = {};
162
+ input.forEach((value, key) => {
163
+ out[key] = value;
164
+ });
165
+ return out;
166
+ }
167
+ return { ...input };
168
+ }
169
+ export async function pinnedFetch(url, pinnedIp, init) {
170
+ if (!pinnedIp)
171
+ return globalThis.fetch(url, init);
172
+ const isTls = url.protocol === 'https:';
173
+ const port = url.port ? Number(url.port) : (isTls ? 443 : 80);
174
+ const path = url.pathname + url.search;
175
+ const headers = normalizeHeaders(init.headers);
176
+ // Preserve the original host in the request line; node would otherwise send
177
+ // the pinned IP as the Host header.
178
+ headers.host = url.host;
179
+ const lib = isTls ? https : http;
180
+ return new Promise((resolve, reject) => {
181
+ const req = lib.request({
182
+ method: init.method ?? 'GET',
183
+ hostname: pinnedIp,
184
+ port,
185
+ path,
186
+ headers,
187
+ ...(isTls ? { servername: url.hostname, rejectUnauthorized: true } : {}),
188
+ signal: init.signal,
189
+ }, (res) => {
190
+ const body = Readable.toWeb(res);
191
+ resolve(new Response(body, {
192
+ status: res.statusCode ?? 200,
193
+ statusText: res.statusMessage ?? '',
194
+ headers: res.headers,
195
+ }));
196
+ });
197
+ req.on('error', reject);
198
+ req.end();
199
+ });
200
+ }
124
201
  /**
125
202
  * Fetch a public http(s) URL and return readable content.
126
203
  *
@@ -132,10 +209,16 @@ export async function fetchUrlContent(input, opts) {
132
209
  const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
133
210
  const maxBytes = opts?.maxBytes ?? DEFAULT_MAX_BYTES;
134
211
  const maxRedirects = opts?.maxRedirects ?? DEFAULT_MAX_REDIRECTS;
135
- const initial = await validateUrl(input);
212
+ const fetcher = opts?.fetcher ?? pinnedFetch;
213
+ const validateOpts = opts?.lookup ? { lookup: opts.lookup } : undefined;
214
+ const initial = await validateUrl(input, validateOpts);
136
215
  if (!initial.ok)
137
216
  throw new BlockedUrlError(initial);
138
217
  let currentUrl = initial.url;
218
+ // Pin the connection to the address we just validated — the validated IP
219
+ // flows from validateUrl straight into the transport, with no second DNS
220
+ // lookup in between (that gap was the rebinding window).
221
+ let currentPinnedIp = initial.resolvedAddresses?.[0];
139
222
  let response;
140
223
  const visited = [];
141
224
  for (let hop = 0; hop <= maxRedirects; hop++) {
@@ -150,7 +233,7 @@ export async function fetchUrlContent(input, opts) {
150
233
  }
151
234
  const combined = AbortSignal.any([timeoutSignal, abortController.signal]);
152
235
  try {
153
- response = await fetch(currentUrl, {
236
+ response = await fetcher(currentUrl, currentPinnedIp, {
154
237
  redirect: 'manual',
155
238
  signal: combined,
156
239
  headers: { accept: 'text/html,application/xhtml+xml,application/json,text/plain;q=0.5,*/*;q=0.1', 'user-agent': USER_AGENT },
@@ -189,7 +272,7 @@ export async function fetchUrlContent(input, opts) {
189
272
  if (nextUrl.protocol !== 'http:' && nextUrl.protocol !== 'https:') {
190
273
  throw new BlockedUrlError({ ok: false, reasonCode: 'blocked_scheme', reason: `Redirect to non-http(s) scheme '${nextUrl.protocol}' is blocked.` });
191
274
  }
192
- const redirectValidation = await validateUrl(nextUrl.href);
275
+ const redirectValidation = await validateUrl(nextUrl.href, validateOpts);
193
276
  if (!redirectValidation.ok)
194
277
  throw new BlockedUrlError(redirectValidation);
195
278
  if (visited.includes(nextUrl.href)) {
@@ -197,16 +280,17 @@ export async function fetchUrlContent(input, opts) {
197
280
  }
198
281
  visited.push(currentUrl.href);
199
282
  currentUrl = nextUrl;
283
+ currentPinnedIp = redirectValidation.resolvedAddresses?.[0];
200
284
  continue;
201
285
  }
202
286
  break;
203
287
  }
204
288
  if (!response)
205
289
  throw new Error(`No response fetching ${input}`);
206
- // Belt-and-suspenders: re-validate the final URL after redirects.
207
- const finalValidation = await validateUrl(currentUrl.href);
208
- if (!finalValidation.ok)
209
- throw new BlockedUrlError(finalValidation);
290
+ // No post-fetch re-validation: every hop (including the final response) was
291
+ // validated and connection-pinned at fetch time. Re-resolving the final URL
292
+ // here would only reopen a rebinding race against a connection that already
293
+ // used a safe, pinned IP.
210
294
  const abortController = new AbortController();
211
295
  const onAbort = () => abortController.abort();
212
296
  if (opts?.signal) {
@@ -26,6 +26,7 @@ declare function withSkillName(content: string, name: string): string;
26
26
  declare function normalizeSkillDescription(description: string): string;
27
27
  declare function withSkillDescription(content: string, description: string): string;
28
28
  declare function parseGeneratedSkill(text: string, description: string): GeneratedSkill;
29
+ declare function assertSafeGeneratedFile(filePath: string): string;
29
30
  export declare function createSkill(input: CreateSkillInput): Promise<{
30
31
  name: string;
31
32
  dir: string;
@@ -41,5 +42,7 @@ export declare const internals: {
41
42
  withSkillDescription: typeof withSkillDescription;
42
43
  normalizeSkillDescription: typeof normalizeSkillDescription;
43
44
  toSkillDirName: typeof toSkillDirName;
45
+ slug: typeof slug;
46
+ assertSafeGeneratedFile: typeof assertSafeGeneratedFile;
44
47
  };
45
48
  export {};
@@ -1,6 +1,7 @@
1
1
  import { generateObject } from 'ai';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'node:path';
4
+ import YAML from 'yaml';
4
5
  import { GLOBAL_SKILLS_DIR } from '../../config/paths.js';
5
6
  import { model } from '../../llm/client.js';
6
7
  import { loadSkill } from '../SkillLoader.js';
@@ -10,15 +11,13 @@ const STANDARD_SKILL_REQUIREMENTS = `
10
11
  # Operating rules
11
12
 
12
13
  - Optimize for autonomous completion for expert users: do not ask for command confirmations; stop only for concrete blockers or necessary product decisions.
13
- - Always ground the work in actual tool output or file contents before producing the final answer.
14
- - Define the exact commands, files, or project state that count as input for this workflow.
15
- - Inspect large inputs incrementally. Prefer summary/list commands first, then targeted per-file reads or per-file diffs for the files most relevant to the goal.
16
- - If a command output is truncated, do not stop. Run narrower commands or read specific files to gather enough evidence for a useful answer.
17
- - If the primary expected input is empty, check the natural fallback inputs before stopping. For example, when reviewing a branch diff, also inspect staged and unstaged working-tree changes.
18
- - Only report "nothing to do" when every explicitly relevant input source has been checked and is empty.
19
- - Only call something a blocker when a concrete tool failure, missing dependency/permission, or ambiguous user requirement prevents progress. Truncated output is not a blocker when narrower follow-up inspection is possible.
20
- - Do not stop after status/summary commands when the workflow requires analysis; inspect the actual content to analyze.
21
- - In the final response, cite the concrete files, commands, or evidence used. Exact line numbers are helpful but must not be required when the available evidence supports file/function-level feedback.
14
+ - Ground the work in actual tool output or file contents before producing the final answer.
15
+ - Inspect large inputs incrementally: summary/list commands first, then targeted reads or per-file diffs for what matters to the goal.
16
+ - Truncated output is not a blocker. Run narrower commands or read specific files to gather enough evidence.
17
+ - If the primary input is empty, check natural fallback inputs before stopping (e.g. for a branch diff, also inspect staged and unstaged changes).
18
+ - Only report "nothing to do" when every relevant input source has been checked and is empty.
19
+ - Only call something a blocker when a concrete tool failure, missing dependency/permission, or ambiguous user requirement prevents progress.
20
+ - Cite concrete files, commands, or evidence in the final response. Prefer file/function references; require exact lines only when available.
22
21
  `;
23
22
  const SKILL_CREATOR_SKILL = `---
24
23
  name: skill-creator
@@ -140,6 +139,14 @@ function withSkillDescription(content, description) {
140
139
  return content.replace(/^(---\n[\s\S]*?^description:\s*).*$/m, `$1${yamlString(normalized)}`);
141
140
  return content;
142
141
  }
142
+ /** Read the `description` field from generated SKILL.md frontmatter (single source of truth). */
143
+ function extractDescription(content) {
144
+ const match = /^---\r?\n([\s\S]*?)\r?\n---/m.exec(content);
145
+ if (!match)
146
+ return undefined;
147
+ const parsed = YAML.parse(match[1] ?? '');
148
+ return typeof parsed.description === 'string' && parsed.description.trim() ? parsed.description.trim() : undefined;
149
+ }
143
150
  function extractJson(text) {
144
151
  const fenced = /```(?:json)?\s*([\s\S]*?)\s*```/.exec(text);
145
152
  return fenced?.[1] ?? text;
@@ -155,38 +162,6 @@ function parseGeneratedSkill(text, description) {
155
162
  throw new Error('Generated skill did not include SKILL.md');
156
163
  return { name, intent, files };
157
164
  }
158
- async function descriptionFromSkillSummary(intent, finalName, files) {
159
- const skillMd = files.find(file => file.path === 'SKILL.md')?.content;
160
- if (!skillMd)
161
- return normalizeSkillDescription(`the user asks: ${intent}`);
162
- const activeModel = await model();
163
- if (!activeModel)
164
- return normalizeSkillDescription(`the user asks: ${intent}`);
165
- const result = await generateObject({
166
- model: activeModel,
167
- schema: z.object({ description: z.string().min(1).describe('Final Use when description that tells an LLM when to invoke this skill') }),
168
- schemaName: 'GeneratedHazeSkillDescription',
169
- schemaDescription: 'A final skill description chosen from the complete generated SKILL.md.',
170
- prompt: [
171
- 'Write the final Haze skill frontmatter description after reading the entire generated SKILL.md.',
172
- '',
173
- `Skill purpose (intent): ${intent}`,
174
- `Final skill name: ${finalName}`,
175
- '',
176
- 'Description rules:',
177
- '- Start with "Use when".',
178
- '- Optimize for LLM understandability: make it obvious when this skill should be invoked.',
179
- '- Summarize the actual workflow in the SKILL.md, not only the user wording.',
180
- '- Be specific about the trigger and desired outcome.',
181
- '- Keep it one sentence, concise but complete.',
182
- '- Avoid vague descriptions like "Use when the user asks for this workflow" unless no better signal exists.',
183
- '',
184
- 'Generated SKILL.md:',
185
- skillMd,
186
- ].join('\n'),
187
- });
188
- return normalizeSkillDescription(result.object.description || `the user asks: ${intent}`);
189
- }
190
165
  function assertSafeGeneratedFile(filePath) {
191
166
  if (path.isAbsolute(filePath))
192
167
  throw new Error(`Generated skill file must be relative: ${filePath}`);
@@ -200,7 +175,7 @@ function assertSafeGeneratedFile(filePath) {
200
175
  async function generateSkill(input) {
201
176
  const activeModel = await model();
202
177
  if (!activeModel)
203
- throw new Error('No model provider configured. Run /provider to choose or add a provider before using /create-skill.');
178
+ throw new Error('No model provider configured. Run /provider to choose or add a provider before creating a skill via /skills.');
204
179
  const role = input.role?.trim() || DEFAULT_SKILL_ROLE;
205
180
  const result = await generateObject({
206
181
  model: activeModel,
@@ -248,9 +223,13 @@ async function generateSkill(input) {
248
223
  });
249
224
  const generated = result.object;
250
225
  const intent = generated.intent?.trim() || input.description;
251
- // The user already named the skill — use it verbatim, do NOT run nameFromSkillSummary.
226
+ // The user already named the skill — use it verbatim. The single generation pass
227
+ // also writes the frontmatter description; normalize it rather than spending a
228
+ // second model call to re-derive it.
252
229
  const finalName = input.name;
253
- const finalDescription = await descriptionFromSkillSummary(intent, finalName, generated.files).catch(() => normalizeSkillDescription(`the user asks: ${intent}`));
230
+ const skillMd = generated.files.find(file => file.path === 'SKILL.md')?.content;
231
+ const rawDescription = skillMd ? extractDescription(skillMd) : undefined;
232
+ const finalDescription = normalizeSkillDescription(rawDescription ?? `the user asks: ${intent}`);
254
233
  const files = generated.files.map(file => file.path === 'SKILL.md' ? { ...file, content: withSkillDescription(file.content, finalDescription) } : file);
255
234
  return { name: finalName, intent, files };
256
235
  }
@@ -294,4 +273,4 @@ export async function createSkill(input) {
294
273
  }
295
274
  return { name: finalName, dir, file: skillFile };
296
275
  }
297
- export const internals = { SKILL_CREATOR_SKILL, STANDARD_SKILL_REQUIREMENTS, parseGeneratedSkill, fallbackSkill, withStandardRequirements, withSkillName, withSkillDescription, normalizeSkillDescription, toSkillDirName };
276
+ export const internals = { SKILL_CREATOR_SKILL, STANDARD_SKILL_REQUIREMENTS, parseGeneratedSkill, fallbackSkill, withStandardRequirements, withSkillName, withSkillDescription, normalizeSkillDescription, toSkillDirName, slug, assertSafeGeneratedFile };
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  export type TextInputSuggestion = {
3
3
  value: string;
4
4
  description?: string;
5
- kind?: 'command' | 'skill' | 'provider' | 'model';
5
+ kind?: 'command' | 'skill' | 'provider' | 'model' | 'lsp' | 'mcp';
6
6
  };
7
7
  export declare function TextInput({ placeholder, disabled, mask, historyItems, recordHistory, suggestions, suggestionMode, submitOnEmpty, width, onHistoryAdd, onCancel, onEscape, onToggleTasks, onSubmit }: {
8
8
  placeholder?: string;
@@ -2,106 +2,8 @@ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-run
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import { Box, Text, useInput } from 'ink';
4
4
  import { theme } from '../theme.js';
5
+ import { compactPasteBlocksForDisplay, cursorPosition, displayCursorForValueCursor, lineCount, normalizeLineEndings, updatePasteBlocksForReplacement, valueCursorForDisplayCursor, wrapDisplayValue, } from '../inputBuffer.js';
5
6
  const COMPACT_PASTE_MIN_LINES = 4;
6
- function normalizeLineEndings(text) {
7
- return text.replace(/\r\n|\r/g, '\n');
8
- }
9
- function lineCount(text) {
10
- return normalizeLineEndings(text).split('\n').length;
11
- }
12
- function pastePlaceholder(block) {
13
- return `[paste #${block.id} +${block.lineCount} lines]`;
14
- }
15
- function updatePasteBlocksForReplacement(blocks, start, end, insertedLength) {
16
- const delta = insertedLength - (end - start);
17
- return blocks.flatMap(block => {
18
- const replacesInsideBlock = start < block.end && end > block.start;
19
- const insertsInsideBlock = start === end && start > block.start && start < block.end;
20
- if (replacesInsideBlock || insertsInsideBlock)
21
- return [];
22
- if (block.start >= end)
23
- return [{ ...block, start: block.start + delta, end: block.end + delta }];
24
- return [block];
25
- });
26
- }
27
- function displayCursorForValueCursor(blocks, valueCursor) {
28
- let displayCursor = valueCursor;
29
- for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
30
- const placeholderLength = pastePlaceholder(block).length;
31
- const compactedLength = block.end - block.start - placeholderLength;
32
- if (valueCursor <= block.start)
33
- break;
34
- if (valueCursor < block.end)
35
- return block.start + placeholderLength;
36
- displayCursor -= compactedLength;
37
- }
38
- return displayCursor;
39
- }
40
- function compactPasteBlocksForDisplay(value, blocks) {
41
- if (blocks.length === 0)
42
- return value;
43
- let displayValue = '';
44
- let offset = 0;
45
- for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
46
- displayValue += value.slice(offset, block.start);
47
- displayValue += pastePlaceholder(block);
48
- offset = block.end;
49
- }
50
- displayValue += value.slice(offset);
51
- return displayValue;
52
- }
53
- function valueCursorForDisplayCursor(blocks, displayCursor) {
54
- let valueCursor = displayCursor;
55
- let displayOffset = 0;
56
- for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
57
- const placeholderLength = pastePlaceholder(block).length;
58
- const displayStart = block.start - displayOffset;
59
- const displayEnd = displayStart + placeholderLength;
60
- if (displayCursor <= displayStart)
61
- break;
62
- if (displayCursor <= displayEnd)
63
- return block.end;
64
- const compactedLength = block.end - block.start - placeholderLength;
65
- valueCursor += compactedLength;
66
- displayOffset += compactedLength;
67
- }
68
- return valueCursor;
69
- }
70
- function wrapDisplayValue(displayValue, width) {
71
- const wrapWidth = Math.max(1, width);
72
- const lines = [];
73
- let start = 0;
74
- let text = '';
75
- for (let index = 0; index < displayValue.length; index += 1) {
76
- const char = displayValue[index];
77
- if (char === '\n') {
78
- lines.push({ text, start, end: index });
79
- start = index + 1;
80
- text = '';
81
- continue;
82
- }
83
- if (text.length >= wrapWidth) {
84
- lines.push({ text, start, end: index });
85
- start = index;
86
- text = '';
87
- }
88
- text += char;
89
- }
90
- lines.push({ text, start, end: displayValue.length });
91
- return lines;
92
- }
93
- function cursorPosition(lines, displayCursor) {
94
- const foundIndex = lines.findIndex((line, index) => {
95
- const isLast = index === lines.length - 1;
96
- if (line.start === line.end)
97
- return displayCursor === line.start;
98
- const nextLineStartsAfterNewline = lines[index + 1]?.start === line.end + 1;
99
- return displayCursor >= line.start && (displayCursor < line.end || (nextLineStartsAfterNewline && displayCursor === line.end) || (isLast && displayCursor <= line.end));
100
- });
101
- const lineIndex = Math.max(0, foundIndex);
102
- const line = lines[lineIndex] ?? lines[0] ?? { start: 0, end: 0 };
103
- return { lineIndex, column: Math.max(0, Math.min(displayCursor - line.start, line.end - line.start)) };
104
- }
105
7
  export function TextInput({ placeholder, disabled, mask, historyItems = [], recordHistory = true, suggestions = [], suggestionMode = 'slash', submitOnEmpty = false, width = 80, onHistoryAdd, onCancel, onEscape, onToggleTasks, onSubmit }) {
106
8
  const [value, setValue] = useState('');
107
9
  const [cursor, setCursor] = useState(0);
@@ -0,0 +1,28 @@
1
+ export type PasteBlock = {
2
+ id: number;
3
+ start: number;
4
+ end: number;
5
+ lineCount: number;
6
+ };
7
+ export type WrappedLine = {
8
+ text: string;
9
+ start: number;
10
+ end: number;
11
+ };
12
+ export declare function normalizeLineEndings(text: string): string;
13
+ export declare function lineCount(text: string): number;
14
+ export declare function pastePlaceholder(block: PasteBlock): string;
15
+ export declare function updatePasteBlocksForReplacement(blocks: PasteBlock[], start: number, end: number, insertedLength: number): {
16
+ start: number;
17
+ end: number;
18
+ id: number;
19
+ lineCount: number;
20
+ }[];
21
+ export declare function displayCursorForValueCursor(blocks: PasteBlock[], valueCursor: number): number;
22
+ export declare function compactPasteBlocksForDisplay(value: string, blocks: PasteBlock[]): string;
23
+ export declare function valueCursorForDisplayCursor(blocks: PasteBlock[], displayCursor: number): number;
24
+ export declare function wrapDisplayValue(displayValue: string, width: number): WrappedLine[];
25
+ export declare function cursorPosition(lines: WrappedLine[], displayCursor: number): {
26
+ lineIndex: number;
27
+ column: number;
28
+ };
@@ -0,0 +1,99 @@
1
+ export function normalizeLineEndings(text) {
2
+ return text.replace(/\r\n|\r/g, '\n');
3
+ }
4
+ export function lineCount(text) {
5
+ return normalizeLineEndings(text).split('\n').length;
6
+ }
7
+ export function pastePlaceholder(block) {
8
+ return `[paste #${block.id} +${block.lineCount} lines]`;
9
+ }
10
+ export function updatePasteBlocksForReplacement(blocks, start, end, insertedLength) {
11
+ const delta = insertedLength - (end - start);
12
+ return blocks.flatMap(block => {
13
+ const replacesInsideBlock = start < block.end && end > block.start;
14
+ const insertsInsideBlock = start === end && start > block.start && start < block.end;
15
+ if (replacesInsideBlock || insertsInsideBlock)
16
+ return [];
17
+ if (block.start >= end)
18
+ return [{ ...block, start: block.start + delta, end: block.end + delta }];
19
+ return [block];
20
+ });
21
+ }
22
+ export function displayCursorForValueCursor(blocks, valueCursor) {
23
+ let displayCursor = valueCursor;
24
+ for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
25
+ const placeholderLength = pastePlaceholder(block).length;
26
+ const compactedLength = block.end - block.start - placeholderLength;
27
+ if (valueCursor <= block.start)
28
+ break;
29
+ if (valueCursor < block.end)
30
+ return block.start + placeholderLength;
31
+ displayCursor -= compactedLength;
32
+ }
33
+ return displayCursor;
34
+ }
35
+ export function compactPasteBlocksForDisplay(value, blocks) {
36
+ if (blocks.length === 0)
37
+ return value;
38
+ let displayValue = '';
39
+ let offset = 0;
40
+ for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
41
+ displayValue += value.slice(offset, block.start);
42
+ displayValue += pastePlaceholder(block);
43
+ offset = block.end;
44
+ }
45
+ displayValue += value.slice(offset);
46
+ return displayValue;
47
+ }
48
+ export function valueCursorForDisplayCursor(blocks, displayCursor) {
49
+ let valueCursor = displayCursor;
50
+ let displayOffset = 0;
51
+ for (const block of [...blocks].sort((a, b) => a.start - b.start)) {
52
+ const placeholderLength = pastePlaceholder(block).length;
53
+ const displayStart = block.start - displayOffset;
54
+ const displayEnd = displayStart + placeholderLength;
55
+ if (displayCursor <= displayStart)
56
+ break;
57
+ if (displayCursor <= displayEnd)
58
+ return block.end;
59
+ const compactedLength = block.end - block.start - placeholderLength;
60
+ valueCursor += compactedLength;
61
+ displayOffset += compactedLength;
62
+ }
63
+ return valueCursor;
64
+ }
65
+ export function wrapDisplayValue(displayValue, width) {
66
+ const wrapWidth = Math.max(1, width);
67
+ const lines = [];
68
+ let start = 0;
69
+ let text = '';
70
+ for (let index = 0; index < displayValue.length; index += 1) {
71
+ const char = displayValue[index];
72
+ if (char === '\n') {
73
+ lines.push({ text, start, end: index });
74
+ start = index + 1;
75
+ text = '';
76
+ continue;
77
+ }
78
+ if (text.length >= wrapWidth) {
79
+ lines.push({ text, start, end: index });
80
+ start = index;
81
+ text = '';
82
+ }
83
+ text += char;
84
+ }
85
+ lines.push({ text, start, end: displayValue.length });
86
+ return lines;
87
+ }
88
+ export function cursorPosition(lines, displayCursor) {
89
+ const foundIndex = lines.findIndex((line, index) => {
90
+ const isLast = index === lines.length - 1;
91
+ if (line.start === line.end)
92
+ return displayCursor === line.start;
93
+ const nextLineStartsAfterNewline = lines[index + 1]?.start === line.end + 1;
94
+ return displayCursor >= line.start && (displayCursor < line.end || (nextLineStartsAfterNewline && displayCursor === line.end) || (isLast && displayCursor <= line.end));
95
+ });
96
+ const lineIndex = Math.max(0, foundIndex);
97
+ const line = lines[lineIndex] ?? lines[0] ?? { start: 0, end: 0 };
98
+ return { lineIndex, column: Math.max(0, Math.min(displayCursor - line.start, line.end - line.start)) };
99
+ }
@@ -0,0 +1,6 @@
1
+ export type NamedItem = {
2
+ name: string;
3
+ };
4
+ export declare function findByName<T extends NamedItem>(items: readonly T[], name: string): T | undefined;
5
+ export declare function removeByName<T extends NamedItem>(items: readonly T[], name: string): T[];
6
+ export declare function upsertByName<T extends NamedItem>(items: readonly T[], item: T): T[];
@@ -0,0 +1,9 @@
1
+ export function findByName(items, name) {
2
+ return items.find(item => item.name === name);
3
+ }
4
+ export function removeByName(items, name) {
5
+ return items.filter(item => item.name !== name);
6
+ }
7
+ export function upsertByName(items, item) {
8
+ return [...removeByName(items, item.name), item];
9
+ }
@@ -1,3 +1,5 @@
1
1
  export declare function workspaceRoot(): string;
2
2
  export declare function resolveWorkspacePath(inputPath: string): string;
3
3
  export declare function workspaceRelativePath(absolutePath: string): string;
4
+ export declare function assertRealPathInsideWorkspace(absolutePath: string, inputPath?: string): Promise<void>;
5
+ export declare function assertWritablePathInsideWorkspace(absolutePath: string, inputPath?: string): Promise<void>;
@@ -1,3 +1,4 @@
1
+ import fs from 'node:fs/promises';
1
2
  import path from 'node:path';
2
3
  export function workspaceRoot() {
3
4
  return process.cwd();
@@ -14,3 +15,42 @@ export function resolveWorkspacePath(inputPath) {
14
15
  export function workspaceRelativePath(absolutePath) {
15
16
  return path.relative(workspaceRoot(), absolutePath) || '.';
16
17
  }
18
+ function assertPathInsideRoot(root, candidate, inputPath) {
19
+ const relative = path.relative(root, candidate);
20
+ if (relative.startsWith('..') || path.isAbsolute(relative)) {
21
+ throw new Error(`Path is outside the workspace: ${inputPath}`);
22
+ }
23
+ }
24
+ export async function assertRealPathInsideWorkspace(absolutePath, inputPath = absolutePath) {
25
+ const [realRoot, realPath] = await Promise.all([
26
+ fs.realpath(workspaceRoot()),
27
+ fs.realpath(absolutePath),
28
+ ]);
29
+ assertPathInsideRoot(realRoot, realPath, inputPath);
30
+ }
31
+ async function nearestExistingPath(absolutePath) {
32
+ let current = absolutePath;
33
+ while (true) {
34
+ try {
35
+ await fs.access(current);
36
+ return current;
37
+ }
38
+ catch (error) {
39
+ const code = typeof error === 'object' && error != null && 'code' in error ? error.code : undefined;
40
+ if (code !== 'ENOENT')
41
+ throw error;
42
+ const parent = path.dirname(current);
43
+ if (parent === current)
44
+ throw error;
45
+ current = parent;
46
+ }
47
+ }
48
+ }
49
+ export async function assertWritablePathInsideWorkspace(absolutePath, inputPath = absolutePath) {
50
+ const [realRoot, existing] = await Promise.all([
51
+ fs.realpath(workspaceRoot()),
52
+ nearestExistingPath(absolutePath),
53
+ ]);
54
+ const realExisting = await fs.realpath(existing);
55
+ assertPathInsideRoot(realRoot, realExisting, inputPath);
56
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Minimal, dependency-free version comparison for the update check.
3
+ *
4
+ * Handles npm package versions like `0.6.0`, `1.2.3`, with optional leading
5
+ * `v` and optional pre-release suffix (`1.0.0-beta.1`). Numeric release
6
+ * segments are compared numerically; pre-release sorts *below* its release
7
+ * (so `1.0.0-beta.1` is older than `1.0.0`). Malformed input is treated as
8
+ * `0.0.0` so the check degrades to "no update" rather than throwing.
9
+ *
10
+ * Kept small on purpose: no `semver` dependency for a single comparison.
11
+ */
12
+ export interface ParsedVersion {
13
+ release: [number, number, number];
14
+ prerelease: string[];
15
+ }
16
+ export declare function parseVersion(input: string): ParsedVersion;
17
+ /** Returns -1 if `a` is older than `b`, 0 if equal, 1 if `a` is newer. */
18
+ export declare function compareVersions(a: string, b: string): number;
19
+ /** True when `latest` is strictly newer than `current`. */
20
+ export declare function isNewer(latest: string, current: string): boolean;