@standardagents/builder 0.12.6 → 0.12.8

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/dist/plugin.js CHANGED
@@ -3,7 +3,6 @@ import fs2__default from 'fs';
3
3
  import * as path8 from 'path';
4
4
  import path8__default from 'path';
5
5
  import { fileURLToPath } from 'url';
6
- import * as ts from 'typescript';
7
6
  import MagicString from 'magic-string';
8
7
  import { exec } from 'child_process';
9
8
  import { promisify } from 'util';
@@ -2002,7 +2001,13 @@ var MetadataService = class {
2002
2001
  return path8.join(this.metadataDir, `${agentName}.json`);
2003
2002
  }
2004
2003
  };
2005
- function extractToolUses(sourceCode) {
2004
+ var _ts;
2005
+ async function loadTypeScript() {
2006
+ if (!_ts) _ts = await import('typescript');
2007
+ return _ts;
2008
+ }
2009
+ async function extractToolUses(sourceCode) {
2010
+ const ts = await loadTypeScript();
2006
2011
  const sourceFile = ts.createSourceFile(
2007
2012
  "tool.ts",
2008
2013
  sourceCode,
@@ -2033,7 +2038,8 @@ function extractToolUses(sourceCode) {
2033
2038
  visit(sourceFile);
2034
2039
  return result;
2035
2040
  }
2036
- function extractPromptTools(sourceCode) {
2041
+ async function extractPromptTools(sourceCode) {
2042
+ const ts = await loadTypeScript();
2037
2043
  const sourceFile = ts.createSourceFile(
2038
2044
  "prompt.ts",
2039
2045
  sourceCode,
@@ -2069,7 +2075,8 @@ function extractPromptTools(sourceCode) {
2069
2075
  visit(sourceFile);
2070
2076
  return result;
2071
2077
  }
2072
- function extractPromptModel(sourceCode) {
2078
+ async function extractPromptModel(sourceCode) {
2079
+ const ts = await loadTypeScript();
2073
2080
  const sourceFile = ts.createSourceFile(
2074
2081
  "prompt.ts",
2075
2082
  sourceCode,
@@ -2091,7 +2098,8 @@ function extractPromptModel(sourceCode) {
2091
2098
  visit(sourceFile);
2092
2099
  return model;
2093
2100
  }
2094
- function extractPromptIncludes(sourceCode) {
2101
+ async function extractPromptIncludes(sourceCode) {
2102
+ const ts = await loadTypeScript();
2095
2103
  const sourceFile = ts.createSourceFile(
2096
2104
  "prompt.ts",
2097
2105
  sourceCode,
@@ -2143,7 +2151,8 @@ function extractPromptIncludes(sourceCode) {
2143
2151
  visit(sourceFile);
2144
2152
  return includes;
2145
2153
  }
2146
- function extractAgentPrompts(sourceCode) {
2154
+ async function extractAgentPrompts(sourceCode) {
2155
+ const ts = await loadTypeScript();
2147
2156
  const sourceFile = ts.createSourceFile(
2148
2157
  "agent.ts",
2149
2158
  sourceCode,
@@ -2178,7 +2187,8 @@ function extractAgentPrompts(sourceCode) {
2178
2187
  visit(sourceFile);
2179
2188
  return result;
2180
2189
  }
2181
- function extractAgentDescription(sourceCode) {
2190
+ async function extractAgentDescription(sourceCode) {
2191
+ const ts = await loadTypeScript();
2182
2192
  const sourceFile = ts.createSourceFile(
2183
2193
  "agent.ts",
2184
2194
  sourceCode,
@@ -2200,7 +2210,8 @@ function extractAgentDescription(sourceCode) {
2200
2210
  visit(sourceFile);
2201
2211
  return description;
2202
2212
  }
2203
- function extractDefinitionName(sourceCode) {
2213
+ async function extractDefinitionName(sourceCode) {
2214
+ const ts = await loadTypeScript();
2204
2215
  const sourceFile = ts.createSourceFile(
2205
2216
  "def.ts",
2206
2217
  sourceCode,
@@ -2222,7 +2233,8 @@ function extractDefinitionName(sourceCode) {
2222
2233
  visit(sourceFile);
2223
2234
  return name;
2224
2235
  }
2225
- function extractModelFallbacks(sourceCode) {
2236
+ async function extractModelFallbacks(sourceCode) {
2237
+ const ts = await loadTypeScript();
2226
2238
  const sourceFile = ts.createSourceFile(
2227
2239
  "model.ts",
2228
2240
  sourceCode,
@@ -2248,7 +2260,8 @@ function extractModelFallbacks(sourceCode) {
2248
2260
  visit(sourceFile);
2249
2261
  return fallbacks;
2250
2262
  }
2251
- function transformBundledJs(code) {
2263
+ async function transformBundledJs(code) {
2264
+ const ts = await loadTypeScript();
2252
2265
  const s = new MagicString(code);
2253
2266
  const sourceFile = ts.createSourceFile(
2254
2267
  "file.js",
@@ -2294,10 +2307,11 @@ function transformBundledJs(code) {
2294
2307
  }
2295
2308
  return s.toString().trim() + "\n";
2296
2309
  }
2297
- function injectAgentMetadata(tsCode, metadata) {
2310
+ async function injectAgentMetadata(tsCode, metadata) {
2298
2311
  if (!metadata.packageName && !metadata.version && !metadata.author && !metadata.license) {
2299
2312
  return tsCode;
2300
2313
  }
2314
+ const ts = await loadTypeScript();
2301
2315
  const s = new MagicString(tsCode);
2302
2316
  const sourceFile = ts.createSourceFile(
2303
2317
  "agent.ts",
@@ -2395,7 +2409,7 @@ var PackingService = class {
2395
2409
  warnings: [],
2396
2410
  errors: []
2397
2411
  };
2398
- const agentFilePath = this.findFile(path8.join(agentsDir, "agents"), agentName);
2412
+ const agentFilePath = await this.findFile(path8.join(agentsDir, "agents"), agentName);
2399
2413
  if (!agentFilePath) {
2400
2414
  analysis.errors.push(`Agent file not found: ${agentName}`);
2401
2415
  return analysis;
@@ -2407,7 +2421,7 @@ var PackingService = class {
2407
2421
  sharedWith: []
2408
2422
  });
2409
2423
  const agentSource = fs2.readFileSync(agentFilePath, "utf-8");
2410
- const agentPrompts = extractAgentPrompts(agentSource);
2424
+ const agentPrompts = await extractAgentPrompts(agentSource);
2411
2425
  if (agentPrompts.sideA) {
2412
2426
  analysis.primaryPrompt = agentPrompts.sideA;
2413
2427
  await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, /* @__PURE__ */ new Set(), `agent:${agentName}`);
@@ -2428,7 +2442,7 @@ var PackingService = class {
2428
2442
  * @param rootDir - Root directory of the project
2429
2443
  * @returns Object with generatedReadme and agentDescription
2430
2444
  */
2431
- generateReadmeForAnalysis(analysis, rootDir) {
2445
+ async generateReadmeForAnalysis(analysis, rootDir) {
2432
2446
  const agentsDir = path8.join(rootDir, "agents");
2433
2447
  const metadataService = new MetadataService(agentsDir);
2434
2448
  let agentDescription;
@@ -2436,7 +2450,7 @@ var PackingService = class {
2436
2450
  if (agentItem?.filePath) {
2437
2451
  try {
2438
2452
  const agentSource = fs2.readFileSync(agentItem.filePath, "utf-8");
2439
- agentDescription = extractAgentDescription(agentSource) || void 0;
2453
+ agentDescription = await extractAgentDescription(agentSource) || void 0;
2440
2454
  } catch {
2441
2455
  }
2442
2456
  }
@@ -2456,7 +2470,7 @@ var PackingService = class {
2456
2470
  * Recursively analyze a prompt and its dependencies.
2457
2471
  */
2458
2472
  async analyzePrompt(promptName, agentsDir, analysis, visited, parentKey) {
2459
- const promptFilePath = this.findFile(path8.join(agentsDir, "prompts"), promptName);
2473
+ const promptFilePath = await this.findFile(path8.join(agentsDir, "prompts"), promptName);
2460
2474
  if (!promptFilePath) {
2461
2475
  analysis.warnings.push(`Prompt file not found: ${promptName}`);
2462
2476
  return;
@@ -2476,15 +2490,15 @@ var PackingService = class {
2476
2490
  }
2477
2491
  visited.add(`prompt:${promptName}`);
2478
2492
  const promptSource = fs2.readFileSync(promptFilePath, "utf-8");
2479
- const modelName = extractPromptModel(promptSource);
2493
+ const modelName = await extractPromptModel(promptSource);
2480
2494
  if (modelName) {
2481
2495
  await this.analyzeModel(modelName, agentsDir, analysis, visited, thisKey);
2482
2496
  }
2483
- const { tools: toolNames } = extractPromptTools(promptSource);
2497
+ const { tools: toolNames } = await extractPromptTools(promptSource);
2484
2498
  for (const toolName of toolNames) {
2485
2499
  await this.analyzeTool(toolName, agentsDir, analysis, visited, "prompt-tools", thisKey);
2486
2500
  }
2487
- const includedPrompts = extractPromptIncludes(promptSource);
2501
+ const includedPrompts = await extractPromptIncludes(promptSource);
2488
2502
  for (const includedPrompt of includedPrompts) {
2489
2503
  const item = analysis.constituents.prompts.find((p) => p.name === includedPrompt);
2490
2504
  if (item) {
@@ -2501,17 +2515,17 @@ var PackingService = class {
2501
2515
  */
2502
2516
  async analyzeTool(toolName, agentsDir, analysis, visited, discoveredVia, parentKey) {
2503
2517
  const thisKey = `tool:${toolName}`;
2504
- const promptFilePath = this.findFile(path8.join(agentsDir, "prompts"), toolName);
2518
+ const promptFilePath = await this.findFile(path8.join(agentsDir, "prompts"), toolName);
2505
2519
  if (promptFilePath) {
2506
2520
  await this.analyzePrompt(toolName, agentsDir, analysis, visited, parentKey);
2507
2521
  return;
2508
2522
  }
2509
- const agentFilePath = this.findFile(path8.join(agentsDir, "agents"), toolName);
2523
+ const agentFilePath = await this.findFile(path8.join(agentsDir, "agents"), toolName);
2510
2524
  if (agentFilePath) {
2511
2525
  await this.analyzeNestedAgent(toolName, agentsDir, analysis, visited, parentKey);
2512
2526
  return;
2513
2527
  }
2514
- const toolFilePath = this.findFile(path8.join(agentsDir, "tools"), toolName);
2528
+ const toolFilePath = await this.findFile(path8.join(agentsDir, "tools"), toolName);
2515
2529
  if (!toolFilePath) {
2516
2530
  analysis.warnings.push(`Tool file not found: ${toolName}`);
2517
2531
  return;
@@ -2530,7 +2544,7 @@ var PackingService = class {
2530
2544
  }
2531
2545
  visited.add(`tool:${toolName}`);
2532
2546
  const toolSource = fs2.readFileSync(toolFilePath, "utf-8");
2533
- const { uses } = extractToolUses(toolSource);
2547
+ const { uses } = await extractToolUses(toolSource);
2534
2548
  for (const usedItem of uses) {
2535
2549
  await this.analyzeTool(usedItem, agentsDir, analysis, visited, "uses", thisKey);
2536
2550
  }
@@ -2539,7 +2553,7 @@ var PackingService = class {
2539
2553
  * Analyze a nested agent (used as a handoff target).
2540
2554
  */
2541
2555
  async analyzeNestedAgent(agentName, agentsDir, analysis, visited, parentKey) {
2542
- const agentFilePath = this.findFile(path8.join(agentsDir, "agents"), agentName);
2556
+ const agentFilePath = await this.findFile(path8.join(agentsDir, "agents"), agentName);
2543
2557
  if (!agentFilePath) {
2544
2558
  analysis.warnings.push(`Agent file not found: ${agentName}`);
2545
2559
  return;
@@ -2559,7 +2573,7 @@ var PackingService = class {
2559
2573
  }
2560
2574
  visited.add(`agent:${agentName}`);
2561
2575
  const agentSource = fs2.readFileSync(agentFilePath, "utf-8");
2562
- const agentPrompts = extractAgentPrompts(agentSource);
2576
+ const agentPrompts = await extractAgentPrompts(agentSource);
2563
2577
  if (agentPrompts.sideA) {
2564
2578
  await this.analyzePrompt(agentPrompts.sideA, agentsDir, analysis, visited, thisKey);
2565
2579
  }
@@ -2571,7 +2585,7 @@ var PackingService = class {
2571
2585
  * Analyze a model and its fallbacks.
2572
2586
  */
2573
2587
  async analyzeModel(modelName, agentsDir, analysis, visited, parentKey) {
2574
- const modelFilePath = this.findFile(path8.join(agentsDir, "models"), modelName);
2588
+ const modelFilePath = await this.findFile(path8.join(agentsDir, "models"), modelName);
2575
2589
  if (!modelFilePath) {
2576
2590
  analysis.warnings.push(`Model file not found: ${modelName}`);
2577
2591
  return;
@@ -2591,7 +2605,7 @@ var PackingService = class {
2591
2605
  }
2592
2606
  visited.add(`model:${modelName}`);
2593
2607
  const modelSource = fs2.readFileSync(modelFilePath, "utf-8");
2594
- const fallbacks = extractModelFallbacks(modelSource);
2608
+ const fallbacks = await extractModelFallbacks(modelSource);
2595
2609
  for (const fallbackName of fallbacks) {
2596
2610
  await this.analyzeModel(fallbackName, agentsDir, analysis, visited, thisKey);
2597
2611
  }
@@ -2640,34 +2654,34 @@ var PackingService = class {
2640
2654
  const result = { prompts: [], tools: [], models: [] };
2641
2655
  const agentsDir = path8.join(rootDir, "agents");
2642
2656
  const visited = /* @__PURE__ */ new Set();
2643
- const agentFilePath = this.findFile(path8.join(agentsDir, "agents"), agentName);
2657
+ const agentFilePath = await this.findFile(path8.join(agentsDir, "agents"), agentName);
2644
2658
  if (!agentFilePath) return result;
2645
2659
  const agentSource = fs2.readFileSync(agentFilePath, "utf-8");
2646
- const agentPrompts = extractAgentPrompts(agentSource);
2647
- const analyzePromptLight = (promptName) => {
2660
+ const agentPrompts = await extractAgentPrompts(agentSource);
2661
+ const analyzePromptLight = async (promptName) => {
2648
2662
  if (visited.has(promptName)) return;
2649
2663
  visited.add(promptName);
2650
2664
  result.prompts.push(promptName);
2651
- const promptFilePath = this.findFile(path8.join(agentsDir, "prompts"), promptName);
2665
+ const promptFilePath = await this.findFile(path8.join(agentsDir, "prompts"), promptName);
2652
2666
  if (!promptFilePath) return;
2653
2667
  const promptSource = fs2.readFileSync(promptFilePath, "utf-8");
2654
- const modelName = extractPromptModel(promptSource);
2668
+ const modelName = await extractPromptModel(promptSource);
2655
2669
  if (modelName && !result.models.includes(modelName)) {
2656
2670
  result.models.push(modelName);
2657
2671
  }
2658
- const { tools } = extractPromptTools(promptSource);
2672
+ const { tools } = await extractPromptTools(promptSource);
2659
2673
  for (const tool of tools) {
2660
2674
  if (!result.tools.includes(tool)) {
2661
2675
  result.tools.push(tool);
2662
2676
  }
2663
2677
  }
2664
- const includes = extractPromptIncludes(promptSource);
2678
+ const includes = await extractPromptIncludes(promptSource);
2665
2679
  for (const inc of includes) {
2666
- analyzePromptLight(inc);
2680
+ await analyzePromptLight(inc);
2667
2681
  }
2668
2682
  };
2669
- if (agentPrompts.sideA) analyzePromptLight(agentPrompts.sideA);
2670
- if (agentPrompts.sideB) analyzePromptLight(agentPrompts.sideB);
2683
+ if (agentPrompts.sideA) await analyzePromptLight(agentPrompts.sideA);
2684
+ if (agentPrompts.sideB) await analyzePromptLight(agentPrompts.sideB);
2671
2685
  return result;
2672
2686
  }
2673
2687
  /**
@@ -2812,7 +2826,7 @@ var PackingService = class {
2812
2826
  let agentDescription;
2813
2827
  if (agentItem?.filePath) {
2814
2828
  const agentSource = fs2.readFileSync(agentItem.filePath, "utf-8");
2815
- agentDescription = extractAgentDescription(agentSource) || void 0;
2829
+ agentDescription = await extractAgentDescription(agentSource) || void 0;
2816
2830
  }
2817
2831
  readmeContent = this.generateReadme(
2818
2832
  finalPackageName,
@@ -3412,7 +3426,7 @@ ${license || "See LICENSE file"}
3412
3426
  /**
3413
3427
  * Find a file by name in a directory.
3414
3428
  */
3415
- findFile(dir, name) {
3429
+ async findFile(dir, name) {
3416
3430
  if (!fs2.existsSync(dir)) {
3417
3431
  return null;
3418
3432
  }
@@ -3424,7 +3438,7 @@ ${license || "See LICENSE file"}
3424
3438
  for (const file of files) {
3425
3439
  const filePath = path8.join(dir, file);
3426
3440
  const source = fs2.readFileSync(filePath, "utf-8");
3427
- const extractedName = extractDefinitionName(source);
3441
+ const extractedName = await extractDefinitionName(source);
3428
3442
  if (extractedName === name) {
3429
3443
  return filePath;
3430
3444
  }
@@ -3434,7 +3448,7 @@ ${license || "See LICENSE file"}
3434
3448
  /**
3435
3449
  * List all agents in the workspace.
3436
3450
  */
3437
- listAgents(rootDir) {
3451
+ async listAgents(rootDir) {
3438
3452
  const agentsDir = path8.join(rootDir, "agents", "agents");
3439
3453
  if (!fs2.existsSync(agentsDir)) {
3440
3454
  return [];
@@ -3444,7 +3458,7 @@ ${license || "See LICENSE file"}
3444
3458
  for (const file of files) {
3445
3459
  const filePath = path8.join(agentsDir, file);
3446
3460
  const source = fs2.readFileSync(filePath, "utf-8");
3447
- const name = extractDefinitionName(source);
3461
+ const name = await extractDefinitionName(source);
3448
3462
  if (name) {
3449
3463
  agents.push(name);
3450
3464
  } else {
@@ -3708,7 +3722,7 @@ var UnpackingService = class {
3708
3722
  return analysis;
3709
3723
  }
3710
3724
  const indexContent = fs2.readFileSync(indexPath, "utf-8");
3711
- const registryItems = this.parseIndexExports(indexContent);
3725
+ const registryItems = await this.parseIndexExports(indexContent);
3712
3726
  const availableItems = /* @__PURE__ */ new Map();
3713
3727
  for (const item of registryItems) {
3714
3728
  availableItems.set(`${item.type}:${item.name}`, item);
@@ -3725,7 +3739,7 @@ var UnpackingService = class {
3725
3739
  continue;
3726
3740
  }
3727
3741
  const bundledCode = fs2.readFileSync(sourcePath, "utf-8");
3728
- const children = this.discoverRelationships(item.type, item.name, bundledCode, availableItems);
3742
+ const children = await this.discoverRelationships(item.type, item.name, bundledCode, availableItems);
3729
3743
  itemsWithRelations.push({
3730
3744
  name: item.name,
3731
3745
  type: item.type,
@@ -3766,10 +3780,10 @@ var UnpackingService = class {
3766
3780
  * Discover relationships from a bundled file.
3767
3781
  * Returns child items that this item references.
3768
3782
  */
3769
- discoverRelationships(type, name, bundledCode, availableItems) {
3783
+ async discoverRelationships(type, name, bundledCode, availableItems) {
3770
3784
  const children = [];
3771
3785
  if (type === "agent") {
3772
- const prompts = extractAgentPrompts(bundledCode);
3786
+ const prompts = await extractAgentPrompts(bundledCode);
3773
3787
  if (prompts.sideA && availableItems.has(`prompt:${prompts.sideA}`)) {
3774
3788
  children.push({ type: "prompt", name: prompts.sideA });
3775
3789
  }
@@ -3777,7 +3791,7 @@ var UnpackingService = class {
3777
3791
  children.push({ type: "prompt", name: prompts.sideB });
3778
3792
  }
3779
3793
  } else if (type === "prompt") {
3780
- const toolsResult = extractPromptTools(bundledCode);
3794
+ const toolsResult = await extractPromptTools(bundledCode);
3781
3795
  for (const toolName of toolsResult.tools) {
3782
3796
  if (availableItems.has(`tool:${toolName}`)) {
3783
3797
  children.push({ type: "tool", name: toolName });
@@ -3785,12 +3799,12 @@ var UnpackingService = class {
3785
3799
  children.push({ type: "agent", name: toolName });
3786
3800
  }
3787
3801
  }
3788
- const model = extractPromptModel(bundledCode);
3802
+ const model = await extractPromptModel(bundledCode);
3789
3803
  if (model && availableItems.has(`model:${model}`)) {
3790
3804
  children.push({ type: "model", name: model });
3791
3805
  }
3792
3806
  } else if (type === "tool") {
3793
- const usesResult = extractToolUses(bundledCode);
3807
+ const usesResult = await extractToolUses(bundledCode);
3794
3808
  for (const useName of usesResult.uses) {
3795
3809
  const colonIndex = useName.indexOf(":");
3796
3810
  if (colonIndex > 0) {
@@ -3868,9 +3882,9 @@ var UnpackingService = class {
3868
3882
  try {
3869
3883
  const sourcePath = path8.join(pkg.path, "dist", TYPE_TO_DIR[item.type], `${item.name}.js`);
3870
3884
  const bundledCode = fs2.readFileSync(sourcePath, "utf-8");
3871
- let tsCode = transformBundledJs(bundledCode);
3885
+ let tsCode = await transformBundledJs(bundledCode);
3872
3886
  if (item.type === "agent") {
3873
- tsCode = injectAgentMetadata(tsCode, agentMetadata);
3887
+ tsCode = await injectAgentMetadata(tsCode, agentMetadata);
3874
3888
  }
3875
3889
  const dir = path8.dirname(item.targetPath);
3876
3890
  if (!fs2.existsSync(dir)) {
@@ -3912,7 +3926,8 @@ var UnpackingService = class {
3912
3926
  * };
3913
3927
  * ```
3914
3928
  */
3915
- parseIndexExports(indexContent) {
3929
+ async parseIndexExports(indexContent) {
3930
+ const ts = await loadTypeScript();
3916
3931
  const sourceFile = ts.createSourceFile(
3917
3932
  "index.js",
3918
3933
  indexContent,