@tanstack/intent 0.0.35 → 0.0.36

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 (2) hide show
  1. package/dist/cli.mjs +205 -2
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import "./utils-COlDcU72.mjs";
2
+ import { s as toPosixPath } from "./utils-COlDcU72.mjs";
3
3
  import { n as findWorkspacePackages } from "./workspace-patterns-BN2A_60g.mjs";
4
4
  import { i as parseSkillUse } from "./skill-use-BzuuvLM7.mjs";
5
5
  import { r as resolveSkillUse } from "./resolver-Whd12ksO.mjs";
@@ -99,6 +99,205 @@ function isPathInsidePackageRoot(path, packageRoot) {
99
99
  const relativePath = relative(resolveFromCwd(packageRoot), resolveFromCwd(path));
100
100
  return relativePath === "" || !relativePath.startsWith("..") && !isAbsolute(relativePath);
101
101
  }
102
+ function splitDestinationSuffix(destination) {
103
+ const hashIndex = destination.indexOf("#");
104
+ const queryIndex = destination.indexOf("?");
105
+ const suffixIndex = hashIndex === -1 ? queryIndex : queryIndex === -1 ? hashIndex : Math.min(hashIndex, queryIndex);
106
+ if (suffixIndex === -1) return {
107
+ pathPart: destination,
108
+ suffix: ""
109
+ };
110
+ return {
111
+ pathPart: destination.slice(0, suffixIndex),
112
+ suffix: destination.slice(suffixIndex)
113
+ };
114
+ }
115
+ function isExternalOrAbsoluteDestination(destination) {
116
+ return destination === "" || destination.startsWith("#") || destination.startsWith("?") || destination.startsWith("//") || /^[A-Za-z][A-Za-z0-9+.-]*:/.test(destination) || isAbsolute(destination);
117
+ }
118
+ function findClosingBracket(line, start) {
119
+ let depth = 0;
120
+ for (let index = start; index < line.length; index++) {
121
+ const char = line[index];
122
+ if (char === "\\") {
123
+ index++;
124
+ continue;
125
+ }
126
+ if (char === "[") {
127
+ depth++;
128
+ continue;
129
+ }
130
+ if (char === "]") {
131
+ depth--;
132
+ if (depth === 0) return index;
133
+ }
134
+ }
135
+ return -1;
136
+ }
137
+ function findClosingParen(line, start) {
138
+ for (let index = start; index < line.length; index++) {
139
+ const char = line[index];
140
+ if (char === "\\") {
141
+ index++;
142
+ continue;
143
+ }
144
+ if (char === ")") return index;
145
+ }
146
+ return -1;
147
+ }
148
+ function readBareDestination(line, start) {
149
+ let depth = 0;
150
+ for (let index = start; index < line.length; index++) {
151
+ const char = line[index];
152
+ if (char === "\\") {
153
+ index++;
154
+ continue;
155
+ }
156
+ if (char === "(") {
157
+ depth++;
158
+ continue;
159
+ }
160
+ if (char === ")") {
161
+ if (depth === 0) return {
162
+ destinationEnd: index,
163
+ endParen: index
164
+ };
165
+ depth--;
166
+ continue;
167
+ }
168
+ if (/\s/.test(char) && depth === 0) {
169
+ const endParen = findClosingParen(line, index);
170
+ if (endParen === -1) return null;
171
+ return {
172
+ destinationEnd: index,
173
+ endParen
174
+ };
175
+ }
176
+ }
177
+ return null;
178
+ }
179
+ function readMarkdownDestination(line, start) {
180
+ let cursor = start;
181
+ while (cursor < line.length && /\s/.test(line[cursor])) cursor++;
182
+ if (line[cursor] === "<") {
183
+ const destinationStart = cursor + 1;
184
+ const destinationEnd = line.indexOf(">", destinationStart);
185
+ if (destinationEnd === -1) return null;
186
+ const endParen = findClosingParen(line, destinationEnd + 1);
187
+ if (endParen === -1) return null;
188
+ return {
189
+ destination: line.slice(destinationStart, destinationEnd),
190
+ destinationStart,
191
+ destinationEnd,
192
+ endParen
193
+ };
194
+ }
195
+ const read = readBareDestination(line, cursor);
196
+ if (!read) return null;
197
+ return {
198
+ destination: line.slice(cursor, read.destinationEnd),
199
+ destinationStart: cursor,
200
+ destinationEnd: read.destinationEnd,
201
+ endParen: read.endParen
202
+ };
203
+ }
204
+ function getCodeFenceMarker(line) {
205
+ const marker = line.match(/^\s*(`{3,}|~{3,})/)?.[1]?.[0];
206
+ return marker === "`" || marker === "~" ? marker : null;
207
+ }
208
+ function rewriteMarkdownDestination({ context, destination }) {
209
+ if (isExternalOrAbsoluteDestination(destination)) return destination;
210
+ const { pathPart, suffix } = splitDestinationSuffix(destination);
211
+ if (isExternalOrAbsoluteDestination(pathPart)) return destination;
212
+ const resolvedDestinationPath = resolve(context.skillDir, pathPart);
213
+ const relativeToPackageRoot = relative(context.resolvedPackageRoot, resolvedDestinationPath);
214
+ if (relativeToPackageRoot.startsWith("..") || isAbsolute(relativeToPackageRoot)) return destination;
215
+ const relativeToCwd = relative(context.cwd, resolvedDestinationPath);
216
+ return `${toPosixPath(relativeToCwd && !relativeToCwd.startsWith("..") && !isAbsolute(relativeToCwd) ? relativeToCwd : resolvedDestinationPath)}${suffix}`;
217
+ }
218
+ function rewriteMarkdownLineDestinations({ context, line }) {
219
+ if (!line.includes("[")) return line;
220
+ let output = "";
221
+ let cursor = 0;
222
+ while (cursor < line.length) {
223
+ const nextCodeStart = line.indexOf("`", cursor);
224
+ const nextLinkStart = line.indexOf("[", cursor);
225
+ if (nextLinkStart === -1) {
226
+ output += line.slice(cursor);
227
+ break;
228
+ }
229
+ if (nextCodeStart !== -1 && nextCodeStart < nextLinkStart) {
230
+ output += line.slice(cursor, nextCodeStart);
231
+ cursor = nextCodeStart;
232
+ const codeStart = cursor;
233
+ while (cursor < line.length && line[cursor] === "`") cursor++;
234
+ const marker = line.slice(codeStart, cursor);
235
+ const codeEnd = line.indexOf(marker, cursor);
236
+ if (codeEnd === -1) {
237
+ output += line.slice(codeStart);
238
+ break;
239
+ }
240
+ output += line.slice(codeStart, codeEnd + marker.length);
241
+ cursor = codeEnd + marker.length;
242
+ continue;
243
+ }
244
+ const linkStart = nextLinkStart > 0 && line[nextLinkStart - 1] === "!" ? nextLinkStart - 1 : nextLinkStart;
245
+ output += line.slice(cursor, linkStart);
246
+ const labelEnd = findClosingBracket(line, nextLinkStart);
247
+ if (labelEnd === -1) {
248
+ output += line.slice(linkStart);
249
+ break;
250
+ }
251
+ if (line[labelEnd + 1] !== "(") {
252
+ output += line.slice(linkStart, nextLinkStart + 1);
253
+ cursor = nextLinkStart + 1;
254
+ continue;
255
+ }
256
+ const destination = readMarkdownDestination(line, labelEnd + 2);
257
+ if (!destination) {
258
+ output += line.slice(linkStart, nextLinkStart + 1);
259
+ cursor = nextLinkStart + 1;
260
+ continue;
261
+ }
262
+ const rewritten = rewriteMarkdownDestination({
263
+ context,
264
+ destination: destination.destination
265
+ });
266
+ output += line.slice(linkStart, destination.destinationStart) + rewritten + line.slice(destination.destinationEnd, destination.endParen + 1);
267
+ cursor = destination.endParen + 1;
268
+ }
269
+ return output;
270
+ }
271
+ function rewriteLoadedSkillMarkdownDestinations({ content, packageRoot, skillFilePath }) {
272
+ const context = {
273
+ cwd: process.cwd(),
274
+ resolvedPackageRoot: resolveFromCwd(packageRoot),
275
+ skillDir: dirname(skillFilePath)
276
+ };
277
+ let inFence = null;
278
+ const parts = content.split(/(\r?\n)/);
279
+ let output = "";
280
+ for (let index = 0; index < parts.length; index += 2) {
281
+ const line = parts[index] ?? "";
282
+ const newline = parts[index + 1] ?? "";
283
+ const marker = getCodeFenceMarker(line);
284
+ if (inFence) {
285
+ output += line + newline;
286
+ if (marker === inFence) inFence = null;
287
+ continue;
288
+ }
289
+ if (marker) {
290
+ inFence = marker;
291
+ output += line + newline;
292
+ continue;
293
+ }
294
+ output += rewriteMarkdownLineDestinations({
295
+ context,
296
+ line
297
+ }) + newline;
298
+ }
299
+ return output;
300
+ }
102
301
  async function runLoadCommand(use, options, scanIntentsOrFail$1) {
103
302
  if (!use) fail("Missing skill use. Expected: intent load <package>#<skill>");
104
303
  if (options.json && options.path) fail("Use either --json or --path, not both.");
@@ -112,7 +311,11 @@ async function runLoadCommand(use, options, scanIntentsOrFail$1) {
112
311
  for (const warning of resolved.warnings) console.error(`Warning: ${warning}`);
113
312
  return;
114
313
  }
115
- const content = readFileSync(resolvedPath, "utf8");
314
+ const content = rewriteLoadedSkillMarkdownDestinations({
315
+ content: readFileSync(resolvedPath, "utf8"),
316
+ packageRoot: resolved.packageRoot,
317
+ skillFilePath: resolvedPath
318
+ });
116
319
  if (options.json) {
117
320
  console.log(JSON.stringify({
118
321
  package: resolved.packageName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/intent",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "Ship compositional knowledge for AI coding agents alongside your npm packages",
5
5
  "license": "MIT",
6
6
  "type": "module",