@gurulu/cli 0.4.1 → 0.4.3

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 (36) hide show
  1. package/dist/commands/attribution.d.ts +22 -0
  2. package/dist/commands/attribution.js +111 -0
  3. package/dist/commands/conversion-paths.d.ts +19 -0
  4. package/dist/commands/conversion-paths.js +55 -0
  5. package/dist/commands/errors.d.ts +27 -0
  6. package/dist/commands/errors.js +121 -0
  7. package/dist/commands/identity.d.ts +13 -0
  8. package/dist/commands/identity.js +85 -1
  9. package/dist/commands/init.js +1 -1
  10. package/dist/commands/install.d.ts +5 -0
  11. package/dist/commands/install.js +186 -9
  12. package/dist/commands/releases.d.ts +17 -0
  13. package/dist/commands/releases.js +54 -0
  14. package/dist/commands/replay.d.ts +18 -0
  15. package/dist/commands/replay.js +64 -0
  16. package/dist/commands/skad.d.ts +18 -0
  17. package/dist/commands/skad.js +53 -0
  18. package/dist/frameworks/detect.d.ts +1 -1
  19. package/dist/frameworks/detect.js +60 -0
  20. package/dist/index.js +162 -2
  21. package/package.json +1 -1
  22. package/scripts/gurulu-agentic-install.lib.cjs +32 -4
  23. package/scripts/gurulu-agentic-install.mjs +60 -5
  24. package/scripts/patches/auto-instrument/ast-helper.cjs +158 -10
  25. package/scripts/patches/auto-instrument/astro.cjs +12 -6
  26. package/scripts/patches/auto-instrument/express.cjs +23 -8
  27. package/scripts/patches/auto-instrument/fastify.cjs +7 -3
  28. package/scripts/patches/auto-instrument/hono.cjs +20 -9
  29. package/scripts/patches/auto-instrument/nestjs.cjs +7 -3
  30. package/scripts/patches/auto-instrument/nextjs-app-router.cjs +27 -9
  31. package/scripts/patches/auto-instrument/nextjs-pages.cjs +23 -10
  32. package/scripts/patches/auto-instrument/remix.cjs +7 -3
  33. package/scripts/patches/auto-instrument/sdk-helper-map.cjs +241 -0
  34. package/scripts/patches/auto-instrument/sveltekit.cjs +7 -3
  35. package/scripts/patches/auto-instrument/vue.cjs +7 -3
  36. package/scripts/patches/index.cjs +6 -0
@@ -35,7 +35,7 @@ function routeToCandidates(urlPath) {
35
35
  return out;
36
36
  }
37
37
 
38
- function astInstrumentFile(source, method, events) {
38
+ function astInstrumentFile(source, method, events, opts = {}) {
39
39
  const tree = ast.parseSource(source);
40
40
  const fns = ast.findExportedFunction(tree, method);
41
41
  if (fns.length === 0) return { ok: false, reason: `${method}-not-found` };
@@ -51,7 +51,9 @@ function astInstrumentFile(source, method, events) {
51
51
  }
52
52
  const stmts = events.map((e) => ast.buildTrackStatement(e.name, e.autoProperties));
53
53
  ast.injectTrackBeforeLastReturn(target.fn, target.body, stmts);
54
- ast.ensureGuruluImport(tree);
54
+ // Sprint D / D4 — alias-aware import.
55
+ const specifier = ast.resolveGuruluImportSpecifier(opts.repoRoot, opts.relPath);
56
+ ast.ensureGuruluImport(tree, specifier);
55
57
  const after = ast.generateSource(tree, source);
56
58
  return {
57
59
  ok: true,
@@ -103,9 +105,11 @@ function instrumentEvents(ctx, events) {
103
105
  for (const group of groups.values()) {
104
106
  const abs = path.join(ctx.repoRoot, group.relPath);
105
107
  const before = fs.readFileSync(abs, 'utf8');
108
+ // Sprint D / D4 — pass repoRoot + relPath to the import resolver.
109
+ const fileOpts = { repoRoot: (ctx && ctx.repoRoot) || null, relPath: group.relPath };
106
110
  let res;
107
111
  try {
108
- res = astInstrumentFile(before, group.method, group.events);
112
+ res = astInstrumentFile(before, group.method, group.events, fileOpts);
109
113
  } catch (err) {
110
114
  const msg = (err && err.message) || String(err);
111
115
  // eslint-disable-next-line no-console
@@ -70,7 +70,7 @@ function findEventHandler(tree) {
70
70
  return found;
71
71
  }
72
72
 
73
- function astInstrumentFile(source, events) {
73
+ function astInstrumentFile(source, events, opts = {}) {
74
74
  const tree = ast.parseSource(source);
75
75
  const target = findEventHandler(tree);
76
76
  if (!target) return { ok: false, reason: 'event-handler-not-found' };
@@ -85,7 +85,9 @@ function astInstrumentFile(source, events) {
85
85
  }
86
86
  const stmts = events.map((e) => ast.buildTrackStatement(e.name, e.autoProperties));
87
87
  ast.injectTrackBeforeLastReturn(target.fn, target.body, stmts);
88
- ast.ensureGuruluImport(tree);
88
+ // Sprint D / D4 — alias-aware import.
89
+ const specifier = ast.resolveGuruluImportSpecifier(opts.repoRoot, opts.relPath);
90
+ ast.ensureGuruluImport(tree, specifier);
89
91
  const after = ast.generateSource(tree, source);
90
92
  return {
91
93
  ok: true,
@@ -137,9 +139,11 @@ function instrumentEvents(ctx, events) {
137
139
  for (const group of groups.values()) {
138
140
  const abs = path.join(ctx.repoRoot, group.relPath);
139
141
  const before = fs.readFileSync(abs, 'utf8');
142
+ // Sprint D / D4 — pass repoRoot + relPath to the import resolver.
143
+ const fileOpts = { repoRoot: (ctx && ctx.repoRoot) || null, relPath: group.relPath };
140
144
  let res;
141
145
  try {
142
- res = astInstrumentFile(before, group.events);
146
+ res = astInstrumentFile(before, group.events, fileOpts);
143
147
  } catch (err) {
144
148
  const msg = (err && err.message) || String(err);
145
149
  // eslint-disable-next-line no-console
@@ -42,6 +42,12 @@ const PATCHERS = [
42
42
  ];
43
43
 
44
44
  const PATCHER_BY_NAME = {
45
+ // Sprint D / D3 — `nextjs` (bare) is the alias most agents emit. Resolve it
46
+ // to the App Router patcher (the modern default). The Pages Router can
47
+ // still be selected explicitly via `nextjs-pages`. Auto-detection (in the
48
+ // PATCHERS array above) handles the case where a project actually uses
49
+ // Pages Router and the agent passed `auto`.
50
+ nextjs: nextAppRouter,
45
51
  'nextjs-app': nextAppRouter,
46
52
  'nextjs-app-router': nextAppRouter,
47
53
  'nextjs-pages': nextPages,