@tanstack/intent 0.0.34 → 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.
package/README.md CHANGED
@@ -104,7 +104,7 @@ npx @tanstack/intent@latest setup
104
104
  | Node.js + pnpm | Supported | Use `pnpm dlx @tanstack/intent@latest <command>` |
105
105
  | Node.js + Bun | Supported | Use `bunx @tanstack/intent@latest <command>` |
106
106
  | Deno | Best-effort | Requires `npm:` interop and `node_modules` support |
107
- | Yarn PnP | Unsupported | `@tanstack/intent` scans `node_modules` |
107
+ | Yarn PnP | Supported | Uses Yarn's PnP API when `node_modules` is absent |
108
108
 
109
109
  ## Monorepos
110
110
 
package/dist/cli.mjs CHANGED
@@ -1,10 +1,10 @@
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";
6
6
  import { t as resolveProjectContext } from "./project-context-alYMNoNa.mjs";
7
- import { a as scanIntentsOrFail, c as fail, i as resolveStaleTargets, l as isCliFailure, n as runInstallCommand, o as scanOptionsFromGlobalFlags, r as getMetaDir, s as printWarnings } from "./install-QjryhQtg.mjs";
7
+ import { a as scanIntentsOrFail, c as fail, i as resolveStaleTargets, l as isCliFailure, n as runInstallCommand, o as scanOptionsFromGlobalFlags, r as getMetaDir, s as printWarnings } from "./install-2_wkomiT.mjs";
8
8
  import { appendFileSync, existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
9
9
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
10
10
  import { fileURLToPath } from "node:url";
@@ -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/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as parseFrontmatter, n as findSkillFiles, o as resolveDepDir, r as getDeps } from "./utils-COlDcU72.mjs";
2
2
  import "./skill-paths-8k9K9y26.mjs";
3
- import { t as scanForIntents } from "./scanner-Dav1tzQK.mjs";
3
+ import { t as scanForIntents } from "./scanner-B1j-wDhj.mjs";
4
4
  import "./workspace-patterns-BN2A_60g.mjs";
5
5
  import { t as readIntentArtifacts } from "./artifact-coverage-wLNVX8yC.mjs";
6
6
  import { n as checkStaleness } from "./staleness-PdgakrCQ.mjs";
@@ -46,7 +46,7 @@ function getCheckSkillsWorkflowAdvisories(root) {
46
46
  return [`Intent workflow update available: run \`npx @tanstack/intent@latest setup\` to refresh ${relative(process.cwd(), workflowPath) || workflowPath}.`];
47
47
  }
48
48
  async function scanIntentsOrFail(options) {
49
- const { scanForIntents } = await import("./scanner-BAZxWeUk.mjs");
49
+ const { scanForIntents } = await import("./scanner-C2YjF4w_.mjs");
50
50
  try {
51
51
  return scanForIntents(void 0, options);
52
52
  } catch (err) {
@@ -3,7 +3,7 @@ import "./utils-COlDcU72.mjs";
3
3
  import "./skill-paths-8k9K9y26.mjs";
4
4
  import "./workspace-patterns-BN2A_60g.mjs";
5
5
  import "./project-context-alYMNoNa.mjs";
6
- import { t as INSTALL_PROMPT } from "./install-QjryhQtg.mjs";
6
+ import { t as INSTALL_PROMPT } from "./install-2_wkomiT.mjs";
7
7
  import { n as printSkillTree, r as printTable, t as computeSkillNameWidth } from "./display-CAof6doy.mjs";
8
8
  import { t as scanLibrary } from "./library-scanner-fexXlPXb.mjs";
9
9
 
@@ -352,7 +352,6 @@ function scanForIntents(root, options = {}) {
352
352
  const projectRoot = root ?? process.cwd();
353
353
  const scanScope = getScanScope(options);
354
354
  const packageManager = detectPackageManager(projectRoot);
355
- const pnpApi = scanScope === "global" ? null : loadPnpApi(projectRoot);
356
355
  const nodeModulesDir = join(projectRoot, "node_modules");
357
356
  const explicitGlobalNodeModules = process.env.INTENT_GLOBAL_NODE_MODULES?.trim() || null;
358
357
  const packages = [];
@@ -376,6 +375,12 @@ function scanForIntents(root, options = {}) {
376
375
  const packageIndexes = /* @__PURE__ */ new Map();
377
376
  const packageJsonCache = /* @__PURE__ */ new Map();
378
377
  const packageVariants = /* @__PURE__ */ new Map();
378
+ let pnpApi;
379
+ function getPnpApi() {
380
+ if (scanScope === "global") return null;
381
+ if (pnpApi === void 0) pnpApi = loadPnpApi(projectRoot);
382
+ return pnpApi;
383
+ }
379
384
  function rememberVariant(pkg) {
380
385
  let variants = packageVariants.get(pkg.name);
381
386
  if (!variants) {
@@ -427,9 +432,7 @@ function scanForIntents(root, options = {}) {
427
432
  tryRegister,
428
433
  warnings
429
434
  });
430
- function scanPnpPackages() {
431
- if (!pnpApi) return;
432
- const api = pnpApi;
435
+ function scanPnpPackages(api) {
433
436
  const visited = /* @__PURE__ */ new Set();
434
437
  const workspaceRoot = findWorkspaceRoot(projectRoot);
435
438
  const projectLocator = api.findPackageLocator?.(projectRoot.endsWith(sep) ? projectRoot : `${projectRoot}${sep}`);
@@ -449,9 +452,12 @@ function scanForIntents(root, options = {}) {
449
452
  for (const locator of roots) visit(locator);
450
453
  }
451
454
  function scanLocalPackages() {
452
- if (pnpApi && !nodeModules.local.exists) {
453
- scanPnpPackages();
454
- return;
455
+ if (!nodeModules.local.exists) {
456
+ const api = getPnpApi();
457
+ if (api) {
458
+ scanPnpPackages(api);
459
+ return;
460
+ }
455
461
  }
456
462
  assertLocalNodeModulesSupported(projectRoot);
457
463
  scanTarget(nodeModules.local);
@@ -1,6 +1,6 @@
1
1
  import "./utils-COlDcU72.mjs";
2
2
  import "./skill-paths-8k9K9y26.mjs";
3
- import { t as scanForIntents } from "./scanner-Dav1tzQK.mjs";
3
+ import { t as scanForIntents } from "./scanner-B1j-wDhj.mjs";
4
4
  import "./workspace-patterns-BN2A_60g.mjs";
5
5
 
6
6
  export { scanForIntents };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/intent",
3
- "version": "0.0.34",
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",