@directive-run/cli 0.2.0 → 0.5.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.
package/dist/index.cjs CHANGED
@@ -1,23 +1,4 @@
1
- 'use strict';
2
-
3
- var knowledge = require('@directive-run/knowledge');
4
- var fs = require('fs');
5
- var path = require('path');
6
- var pc = require('picocolors');
7
-
8
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
-
10
- var pc__default = /*#__PURE__*/_interopDefault(pc);
11
-
12
- // src/lib/knowledge.ts
13
-
14
- // src/templates/claude.ts
15
- function generateClaudeRules() {
16
- const corePatterns = knowledge.getKnowledge("core-patterns");
17
- const antiPatterns = knowledge.getKnowledge("anti-patterns");
18
- const naming = knowledge.getKnowledge("naming");
19
- const schemaTypes = knowledge.getKnowledge("schema-types");
20
- return `# Directive \u2014 Complete AI Coding Rules
1
+ 'use strict';var knowledge=require('@directive-run/knowledge'),fs=require('fs'),path=require('path'),d=require('picocolors');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var d__default=/*#__PURE__*/_interopDefault(d);function A(){let e=knowledge.getKnowledge("core-patterns"),r=knowledge.getKnowledge("anti-patterns"),t=knowledge.getKnowledge("naming"),s=knowledge.getKnowledge("schema-types");return `# Directive \u2014 Complete AI Coding Rules
21
2
 
22
3
  > Constraint-driven runtime for TypeScript. Declare requirements, let the runtime resolve them.
23
4
  > https://directive.run | \`npm install @directive-run/core\`
@@ -25,13 +6,13 @@ function generateClaudeRules() {
25
6
 
26
7
  ## Core Patterns
27
8
 
28
- ${corePatterns}
9
+ ${e}
29
10
 
30
11
  ---
31
12
 
32
13
  ## Anti-Patterns (All 36)
33
14
 
34
- ${antiPatterns}
15
+ ${r}
35
16
 
36
17
  ### AI Package Anti-Patterns (21-36)
37
18
 
@@ -58,13 +39,13 @@ ${antiPatterns}
58
39
 
59
40
  ## Naming Conventions
60
41
 
61
- ${naming}
42
+ ${t}
62
43
 
63
44
  ---
64
45
 
65
46
  ## Schema Type Builders
66
47
 
67
- ${schemaTypes}
48
+ ${s}
68
49
 
69
50
  ---
70
51
 
@@ -237,120 +218,7 @@ for await (const chunk of streamResult.stream) {
237
218
  \`\`\`
238
219
 
239
220
  Backpressure: \`"buffer"\` (default), \`"block"\`, \`"drop"\`
240
- `;
241
- }
242
-
243
- // src/templates/cursor.ts
244
- function generateCursorRules() {
245
- return `# Directive \u2014 AI Coding Rules
246
-
247
- > Constraint-driven runtime for TypeScript. \`npm install @directive-run/core\`
248
- > Full reference: https://directive.run/llms.txt
249
-
250
- ## Schema Shape (CRITICAL)
251
-
252
- \`\`\`typescript
253
- import { createModule, createSystem, t } from "@directive-run/core";
254
-
255
- const myModule = createModule("name", {
256
- schema: {
257
- facts: { count: t.number(), items: t.array<string>() },
258
- derivations: { total: "number" },
259
- events: { increment: "void", addItem: "string" },
260
- requirements: { FETCH_DATA: { url: "string" } },
261
- },
262
- init: (facts) => { facts.count = 0; facts.items = []; },
263
- derive: {
264
- total: (facts) => facts.items.length + facts.count,
265
- },
266
- events: {
267
- increment: (facts) => { facts.count += 1; },
268
- addItem: (facts, item) => { facts.items = [...facts.items, item]; },
269
- },
270
- constraints: {
271
- fetchWhenReady: {
272
- when: (facts) => facts.count > 0 && facts.items.length === 0,
273
- require: (facts) => ({ type: "FETCH_DATA", url: "/api/items" }),
274
- },
275
- },
276
- resolvers: {
277
- fetchData: {
278
- requirement: "FETCH_DATA",
279
- resolve: async (req, context) => {
280
- const data = await fetch(req.url).then(r => r.json());
281
- context.facts.items = data;
282
- },
283
- },
284
- },
285
- });
286
-
287
- const system = createSystem({ module: myModule });
288
- await system.settle();
289
- \`\`\`
290
-
291
- ## Top 10 Anti-Patterns
292
-
293
- | # | WRONG | CORRECT |
294
- |---|-------|---------|
295
- | 1 | \`facts.profile as ResourceState<Profile>\` | Remove cast \u2014 schema provides types |
296
- | 2 | \`{ phase: t.string() }\` flat schema | \`schema: { facts: { phase: t.string() } }\` |
297
- | 3 | \`facts.items\` in multi-module | \`facts.self.items\` |
298
- | 4 | \`t.map()\`, \`t.set()\`, \`t.promise()\` | Don't exist. Use \`t.object<Map<K,V>>()\` |
299
- | 5 | \`(req, ctx)\` in resolver | \`(req, context)\` \u2014 never abbreviate |
300
- | 6 | \`createModule("n", { phase: t.string() })\` | Must wrap: \`schema: { facts: { ... } }\` |
301
- | 7 | \`system.dispatch('login', {...})\` | \`system.events.login({...})\` |
302
- | 8 | \`facts.items.push(item)\` | \`facts.items = [...facts.items, item]\` |
303
- | 9 | \`useDirective(system)\` | \`useSelector(system, s => s.facts.count)\` |
304
- | 10 | \`facts['auth::status']\` | \`facts.auth.status\` dot notation |
305
-
306
- ## Naming
307
-
308
- - \`req\` = requirement (not request). Parameter: \`(req, context)\`
309
- - \`derive\` / derivations \u2014 never "computed" or "selectors"
310
- - Resolvers return \`void\` \u2014 mutate \`context.facts\` instead
311
- - Always use braces for returns: \`if (x) { return y; }\`
312
- - Multi-module: \`facts.self.fieldName\` for own module facts
313
- - Events: \`system.events.eventName(payload)\` \u2014 not \`system.dispatch()\`
314
- - Import from main: \`import { createModule } from '@directive-run/core'\`
315
-
316
- ## Schema Types That Exist
317
-
318
- \`t.string<T>()\`, \`t.number()\`, \`t.boolean()\`, \`t.array<T>()\`, \`t.object<T>()\`,
319
- \`t.enum("a","b")\`, \`t.literal(value)\`, \`t.nullable(inner)\`, \`t.optional(inner)\`, \`t.union(...)\`
320
-
321
- Chainable: \`.default()\`, \`.validate()\`, \`.transform()\`, \`.brand<>()\`, \`.refine()\`
322
-
323
- **DO NOT USE** (hallucinations): \`t.map()\`, \`t.set()\`, \`t.date()\`, \`t.tuple()\`, \`t.record()\`, \`t.promise()\`, \`t.any()\`
324
-
325
- ## Key Pattern: Constraint \u2192 Requirement \u2192 Resolver
326
-
327
- When the user wants "do X when Y": create THREE things:
328
- 1. **Constraint**: \`when: (facts) => Y_condition\` \u2192 \`require: { type: "DO_X" }\`
329
- 2. **Resolver**: handles "DO_X", calls API, sets \`context.facts\`
330
- 3. They are **decoupled**. Constraint declares need, resolver fulfills it.
331
- `;
332
- }
333
-
334
- // src/templates/copilot.ts
335
- function generateCopilotRules() {
336
- const base = generateCursorRules();
337
- const extraAntiPatterns = `
338
- ## Anti-Patterns 11-20
339
-
340
- | # | WRONG | CORRECT |
341
- |---|-------|---------|
342
- | 11 | \`module("name").schema({...}).build()\` | Prefer \`createModule("name", {...})\` object syntax |
343
- | 12 | Returning data from \`resolve\` | Resolvers return \`void\` \u2014 mutate \`context.facts\` |
344
- | 13 | Async logic in \`init\` | \`init\` is synchronous, facts assignment only |
345
- | 14 | \`await system.start()\` without settle | Add \`await system.settle()\` after start |
346
- | 15 | Missing \`crossModuleDeps\` | Declare \`crossModuleDeps: { auth: authSchema }\` |
347
- | 16 | \`require: "TYPE"\` string literal | \`require: { type: "TYPE" }\` object form |
348
- | 17 | Passthrough derivation \`(f) => f.count\` | Remove \u2014 read fact directly |
349
- | 18 | \`from '@directive-run/core/module'\` | \`from '@directive-run/core'\` (main export) |
350
- | 19 | \`async when()\` without \`deps\` | Add \`deps: ['factName']\` for async constraints |
351
- | 20 | No error boundary on resolver | Use try-catch or module error boundary config |
352
- `;
353
- const multiModule = `
221
+ `}function p(){return '# Directive \u2014 AI Coding Rules\n\n> Constraint-driven runtime for TypeScript. `npm install @directive-run/core`\n> Full reference: https://directive.run/llms.txt\n\n## Schema Shape (CRITICAL)\n\n```typescript\nimport { createModule, createSystem, t } from "@directive-run/core";\n\nconst myModule = createModule("name", {\n schema: {\n facts: { count: t.number(), items: t.array<string>() },\n derivations: { total: "number" },\n events: { increment: "void", addItem: "string" },\n requirements: { FETCH_DATA: { url: "string" } },\n },\n init: (facts) => { facts.count = 0; facts.items = []; },\n derive: {\n total: (facts) => facts.items.length + facts.count,\n },\n events: {\n increment: (facts) => { facts.count += 1; },\n addItem: (facts, item) => { facts.items = [...facts.items, item]; },\n },\n constraints: {\n fetchWhenReady: {\n when: (facts) => facts.count > 0 && facts.items.length === 0,\n require: (facts) => ({ type: "FETCH_DATA", url: "/api/items" }),\n },\n },\n resolvers: {\n fetchData: {\n requirement: "FETCH_DATA",\n resolve: async (req, context) => {\n const data = await fetch(req.url).then(r => r.json());\n context.facts.items = data;\n },\n },\n },\n});\n\nconst system = createSystem({ module: myModule });\nawait system.settle();\n```\n\n## Top 10 Anti-Patterns\n\n| # | WRONG | CORRECT |\n|---|-------|---------|\n| 1 | `facts.profile as ResourceState<Profile>` | Remove cast \u2014 schema provides types |\n| 2 | `{ phase: t.string() }` flat schema | `schema: { facts: { phase: t.string() } }` |\n| 3 | `facts.items` in multi-module | `facts.self.items` |\n| 4 | `t.map()`, `t.set()`, `t.promise()` | Don\'t exist. Use `t.object<Map<K,V>>()` |\n| 5 | `(req, ctx)` in resolver | `(req, context)` \u2014 never abbreviate |\n| 6 | `createModule("n", { phase: t.string() })` | Must wrap: `schema: { facts: { ... } }` |\n| 7 | `system.dispatch(\'login\', {...})` | `system.events.login({...})` |\n| 8 | `facts.items.push(item)` | `facts.items = [...facts.items, item]` |\n| 9 | `useDirective(system)` | `useSelector(system, s => s.facts.count)` |\n| 10 | `facts[\'auth::status\']` | `facts.auth.status` dot notation |\n\n## Naming\n\n- `req` = requirement (not request). Parameter: `(req, context)`\n- `derive` / derivations \u2014 never "computed" or "selectors"\n- Resolvers return `void` \u2014 mutate `context.facts` instead\n- Always use braces for returns: `if (x) { return y; }`\n- Multi-module: `facts.self.fieldName` for own module facts\n- Events: `system.events.eventName(payload)` \u2014 not `system.dispatch()`\n- Import from main: `import { createModule } from \'@directive-run/core\'`\n\n## Schema Types That Exist\n\n`t.string<T>()`, `t.number()`, `t.boolean()`, `t.array<T>()`, `t.object<T>()`,\n`t.enum("a","b")`, `t.literal(value)`, `t.nullable(inner)`, `t.optional(inner)`, `t.union(...)`\n\nChainable: `.default()`, `.validate()`, `.transform()`, `.brand<>()`, `.refine()`\n\n**DO NOT USE** (hallucinations): `t.map()`, `t.set()`, `t.date()`, `t.tuple()`, `t.record()`, `t.promise()`, `t.any()`\n\n## Key Pattern: Constraint \u2192 Requirement \u2192 Resolver\n\nWhen the user wants "do X when Y": create THREE things:\n1. **Constraint**: `when: (facts) => Y_condition` \u2192 `require: { type: "DO_X" }`\n2. **Resolver**: handles "DO_X", calls API, sets `context.facts`\n3. They are **decoupled**. Constraint declares need, resolver fulfills it.\n'}function u(){return p()+'\n## Anti-Patterns 11-20\n\n| # | WRONG | CORRECT |\n|---|-------|---------|\n| 11 | `module("name").schema({...}).build()` | Prefer `createModule("name", {...})` object syntax |\n| 12 | Returning data from `resolve` | Resolvers return `void` \u2014 mutate `context.facts` |\n| 13 | Async logic in `init` | `init` is synchronous, facts assignment only |\n| 14 | `await system.start()` without settle | Add `await system.settle()` after start |\n| 15 | Missing `crossModuleDeps` | Declare `crossModuleDeps: { auth: authSchema }` |\n| 16 | `require: "TYPE"` string literal | `require: { type: "TYPE" }` object form |\n| 17 | Passthrough derivation `(f) => f.count` | Remove \u2014 read fact directly |\n| 18 | `from \'@directive-run/core/module\'` | `from \'@directive-run/core\'` (main export) |\n| 19 | `async when()` without `deps` | Add `deps: [\'factName\']` for async constraints |\n| 20 | No error boundary on resolver | Use try-catch or module error boundary config |\n'+`
354
222
  ## Multi-Module
355
223
 
356
224
  \`\`\`typescript
@@ -362,8 +230,7 @@ const system = createSystem({
362
230
  // In constraints/resolvers: use facts.self.* for own module
363
231
  // Declare deps: crossModuleDeps: { auth: authSchema }
364
232
  \`\`\`
365
- `;
366
- const aiBasics = `
233
+ `+`
367
234
  ## AI Package Basics (\`@directive-run/ai\`)
368
235
 
369
236
  \`\`\`typescript
@@ -384,298 +251,20 @@ const result = await orchestrator.run(agent, "analyze this");
384
251
  - Subpath imports: \`from '@directive-run/ai/anthropic'\` not \`from '@directive-run/ai'\`
385
252
  - Token usage normalized: \`{ inputTokens, outputTokens }\` (not provider-specific)
386
253
  - \`facts.cache = [...facts.cache, item]\` not \`facts.cache.push(item)\`
387
- `;
388
- return base + extraAntiPatterns + multiModule + aiBasics;
389
- }
390
-
391
- // src/templates/cline.ts
392
- function generateClineRules() {
393
- return generateCopilotRules();
394
- }
395
-
396
- // src/templates/llms-txt.ts
397
- function generateLlmsTxt() {
398
- const knowledge$1 = knowledge.getAllKnowledge();
399
- const examples = knowledge.getAllExamples();
400
- const coreOrder = [
401
- "core-patterns",
402
- "anti-patterns",
403
- "naming",
404
- "multi-module",
405
- "constraints",
406
- "resolvers",
407
- "error-boundaries",
408
- "testing",
409
- "time-travel",
410
- "schema-types",
411
- "system-api",
412
- "react-adapter",
413
- "plugins"
414
- ];
415
- const aiOrder = [
416
- "ai-orchestrator",
417
- "ai-multi-agent",
418
- "ai-tasks",
419
- "ai-agents-streaming",
420
- "ai-guardrails-memory",
421
- "ai-adapters",
422
- "ai-budget-resilience",
423
- "ai-mcp-rag",
424
- "ai-communication",
425
- "ai-debug-observability",
426
- "ai-security",
427
- "ai-testing-evals"
428
- ];
429
- const exampleOrder = [
430
- "counter",
431
- "auth-flow",
432
- "shopping-cart",
433
- "error-boundaries",
434
- "ai-orchestrator",
435
- "fraud-analysis",
436
- "ai-checkpoint"
437
- ];
438
- const sections = [
439
- "# Directive \u2014 Complete AI Reference (llms.txt)",
440
- "",
441
- "> Constraint-driven runtime for TypeScript.",
442
- "> Declare requirements. Let the runtime resolve them.",
443
- "> https://directive.run",
444
- "",
445
- "## Core API (@directive-run/core)",
446
- ""
447
- ];
448
- for (const name of coreOrder) {
449
- const content = knowledge$1.get(name);
450
- if (content) {
451
- sections.push(content, "", "---", "");
452
- }
453
- }
454
- sections.push("## AI Package (@directive-run/ai)", "");
455
- for (const name of aiOrder) {
456
- const content = knowledge$1.get(name);
457
- if (content) {
458
- sections.push(content, "", "---", "");
459
- }
460
- }
461
- const apiSkeleton = knowledge$1.get("api-skeleton");
462
- if (apiSkeleton) {
463
- sections.push("## API Reference (Auto-Generated)", "", apiSkeleton, "");
464
- }
465
- sections.push("## Complete Examples", "");
466
- for (const name of exampleOrder) {
467
- const content = examples.get(name);
468
- if (content) {
469
- sections.push(
470
- `### ${name}`,
471
- "",
472
- "```typescript",
473
- content,
474
- "```",
475
- ""
476
- );
477
- }
478
- }
479
- return sections.join("\n");
480
- }
481
-
482
- // src/templates/windsurf.ts
483
- function generateWindsurfRules() {
484
- return generateCopilotRules();
485
- }
486
-
487
- // src/templates/index.ts
488
- var generators = {
489
- cursor: generateCursorRules,
490
- claude: generateClaudeRules,
491
- copilot: generateCopilotRules,
492
- windsurf: generateWindsurfRules,
493
- cline: generateClineRules
494
- };
495
- function getTemplate(toolId) {
496
- const generator = generators[toolId];
497
- if (!generator) {
498
- throw new Error(`No template for tool: ${toolId}`);
499
- }
500
- return generator();
501
- }
502
- var TOOL_SIGNALS = [
503
- {
504
- id: "cursor",
505
- name: "Cursor",
506
- signals: [".cursor", ".cursorrules"],
507
- outputPath: ".cursorrules"
508
- },
509
- {
510
- id: "claude",
511
- name: "Claude Code",
512
- signals: [".claude"],
513
- outputPath: ".claude/CLAUDE.md"
514
- },
515
- {
516
- id: "copilot",
517
- name: "GitHub Copilot",
518
- signals: [".github"],
519
- outputPath: ".github/copilot-instructions.md"
520
- },
521
- {
522
- id: "windsurf",
523
- name: "Windsurf",
524
- signals: [".windsurfrules"],
525
- outputPath: ".windsurfrules"
526
- },
527
- {
528
- id: "cline",
529
- name: "Cline",
530
- signals: [".clinerules"],
531
- outputPath: ".clinerules"
532
- }
533
- ];
534
- function detectTools(rootDir) {
535
- const detected = [];
536
- for (const tool of TOOL_SIGNALS) {
537
- const hasSignal = tool.signals.some(
538
- (signal) => fs.existsSync(path.join(rootDir, signal))
539
- );
540
- if (hasSignal) {
541
- detected.push({
542
- name: tool.name,
543
- id: tool.id,
544
- outputPath: path.join(rootDir, tool.outputPath)
545
- });
546
- }
547
- }
548
- return detected;
549
- }
550
- var MONOREPO_SIGNALS = [
551
- { file: "pnpm-workspace.yaml", tool: "pnpm" },
552
- { file: "turbo.json", tool: "turbo" }
553
- ];
554
- function detectMonorepo(startDir) {
555
- let dir = path.resolve(startDir);
556
- while (dir !== path.dirname(dir)) {
557
- for (const signal of MONOREPO_SIGNALS) {
558
- if (fs.existsSync(path.join(dir, signal.file))) {
559
- return { isMonorepo: true, rootDir: dir, tool: signal.tool };
560
- }
561
- }
562
- const pkgPath = path.join(dir, "package.json");
563
- if (fs.existsSync(pkgPath)) {
564
- try {
565
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
566
- if (pkg.workspaces) {
567
- const tool = fs.existsSync(path.join(dir, "yarn.lock")) ? "yarn" : "npm";
568
- return { isMonorepo: true, rootDir: dir, tool };
569
- }
570
- } catch {
571
- }
572
- }
573
- dir = path.dirname(dir);
574
- }
575
- return { isMonorepo: false, rootDir: startDir };
576
- }
577
-
578
- // src/lib/constants.ts
579
- var CLI_NAME = "directive";
580
- var PACKAGE_NAME = "@directive-run/cli";
581
- var SECTION_START = "<!-- directive:start -->";
582
- var SECTION_END = "<!-- directive:end -->";
583
-
584
- // src/lib/merge.ts
585
- function mergeSection(existingContent, newSection) {
586
- const startIdx = existingContent.indexOf(SECTION_START);
587
- const endIdx = existingContent.indexOf(SECTION_END);
588
- const wrapped = `${SECTION_START}
589
- ${newSection}
590
- ${SECTION_END}`;
591
- if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
592
- return existingContent.slice(0, startIdx) + wrapped + existingContent.slice(endIdx + SECTION_END.length);
593
- }
594
- const separator = existingContent.endsWith("\n") ? "\n" : "\n\n";
595
- return existingContent + separator + wrapped + "\n";
596
- }
597
- function hasDirectiveSection(content) {
598
- return content.includes(SECTION_START) && content.includes(SECTION_END);
599
- }
600
- async function loadSystem(filePath) {
601
- const resolved = path.resolve(filePath);
602
- if (!fs.existsSync(resolved)) {
603
- throw new Error(`File not found: ${resolved}`);
604
- }
605
- try {
606
- const mod = await import(resolved);
607
- if (mod.default && isSystem(mod.default)) {
608
- return mod.default;
609
- }
610
- if (mod.system && isSystem(mod.system)) {
611
- return mod.system;
612
- }
613
- for (const key of Object.keys(mod)) {
614
- if (isSystem(mod[key])) {
615
- return mod[key];
616
- }
617
- }
618
- throw new Error(
619
- `No Directive system found in ${pc__default.default.dim(filePath)}
254
+ `}function w(){return u()}function T(){let e=knowledge.getAllKnowledge(),r=knowledge.getAllExamples(),t=["core-patterns","anti-patterns","naming","multi-module","constraints","resolvers","error-boundaries","testing","time-travel","schema-types","system-api","react-adapter","plugins"],s=["ai-orchestrator","ai-multi-agent","ai-tasks","ai-agents-streaming","ai-guardrails-memory","ai-adapters","ai-budget-resilience","ai-mcp-rag","ai-communication","ai-debug-observability","ai-security","ai-testing-evals"],o=["counter","auth-flow","shopping-cart","error-boundaries","ai-orchestrator","fraud-analysis","ai-checkpoint"],n=["# Directive \u2014 Complete AI Reference (llms.txt)","","> Constraint-driven runtime for TypeScript.","> Declare requirements. Let the runtime resolve them.","> https://directive.run","","## Core API (@directive-run/core)",""];for(let i of t){let a=e.get(i);a&&n.push(a,"","---","");}n.push("## AI Package (@directive-run/ai)","");for(let i of s){let a=e.get(i);a&&n.push(a,"","---","");}let S=e.get("api-skeleton");S&&n.push("## API Reference (Auto-Generated)","",S,""),n.push("## Complete Examples","");for(let i of o){let a=r.get(i);a&&n.push(`### ${i}`,"","```typescript",a,"```","");}return n.join(`
255
+ `)}function x(){return u()}var E={cursor:p,claude:A,copilot:u,windsurf:x,cline:w};function D(e){let r=E[e];if(!r)throw new Error(`No template for tool: ${e}`);return r()}var P=[{id:"cursor",name:"Cursor",signals:[".cursor",".cursorrules"],outputPath:".cursorrules"},{id:"claude",name:"Claude Code",signals:[".claude"],outputPath:".claude/CLAUDE.md"},{id:"copilot",name:"GitHub Copilot",signals:[".github"],outputPath:".github/copilot-instructions.md"},{id:"windsurf",name:"Windsurf",signals:[".windsurfrules"],outputPath:".windsurfrules"},{id:"cline",name:"Cline",signals:[".clinerules"],outputPath:".clinerules"}];function N(e){let r=[];for(let t of P)t.signals.some(o=>fs.existsSync(path.join(e,o)))&&r.push({name:t.name,id:t.id,outputPath:path.join(e,t.outputPath)});return r}var _=[{file:"pnpm-workspace.yaml",tool:"pnpm"},{file:"turbo.json",tool:"turbo"}];function G(e){let r=path.resolve(e);for(;r!==path.dirname(r);){for(let s of _)if(fs.existsSync(path.join(r,s.file)))return {isMonorepo:true,rootDir:r,tool:s.tool};let t=path.join(r,"package.json");if(fs.existsSync(t))try{if(JSON.parse(fs.readFileSync(t,"utf-8")).workspaces){let o=fs.existsSync(path.join(r,"yarn.lock"))?"yarn":"npm";return {isMonorepo:!0,rootDir:r,tool:o}}}catch{}r=path.dirname(r);}return {isMonorepo:false,rootDir:e}}var L="directive";var K="@directive-run/cli",m="<!-- directive:start -->",l="<!-- directive:end -->";function $(e,r){let t=e.indexOf(m),s=e.indexOf(l),o=`${m}
256
+ ${r}
257
+ ${l}`;if(t!==-1&&s!==-1&&s>t)return e.slice(0,t)+o+e.slice(s+l.length);let n=e.endsWith(`
258
+ `)?`
259
+ `:`
260
+
261
+ `;return e+n+o+`
262
+ `}function F(e){return e.includes(m)&&e.includes(l)}async function U(e){let r=path.resolve(e);if(!fs.existsSync(r))throw new Error(`File not found: ${r}`);try{let t=await import(r);if(t.default&&v(t.default))return t.default;if(t.system&&v(t.system))return t.system;for(let s of Object.keys(t))if(v(t[s]))return t[s];throw new Error(`No Directive system found in ${d__default.default.dim(e)}
620
263
  Export a system as default or named "system":
621
264
 
622
- ${pc__default.default.cyan("export default")} createSystem({ module: myModule });
623
- ${pc__default.default.cyan("export const system")} = createSystem({ module: myModule });`
624
- );
625
- } catch (err) {
626
- if (err instanceof Error && err.message.includes("No Directive system")) {
627
- throw err;
628
- }
629
- throw new Error(
630
- `Failed to load ${pc__default.default.dim(filePath)}: ${err instanceof Error ? err.message : String(err)}
265
+ ${d__default.default.cyan("export default")} createSystem({ module: myModule });
266
+ ${d__default.default.cyan("export const system")} = createSystem({ module: myModule });`)}catch(t){throw t instanceof Error&&t.message.includes("No Directive system")?t:new Error(`Failed to load ${d__default.default.dim(e)}: ${t instanceof Error?t.message:String(t)}
631
267
 
632
268
  Make sure the file is valid TypeScript and tsx is installed:
633
- ${pc__default.default.cyan("npm install -D tsx")}`
634
- );
635
- }
636
- }
637
- function isSystem(obj) {
638
- if (typeof obj !== "object" || obj === null) {
639
- return false;
640
- }
641
- const sys = obj;
642
- return typeof sys.inspect === "function" && typeof sys.start === "function" && typeof sys.stop === "function" && "facts" in sys;
643
- }
644
-
645
- Object.defineProperty(exports, "getAllExamples", {
646
- enumerable: true,
647
- get: function () { return knowledge.getAllExamples; }
648
- });
649
- Object.defineProperty(exports, "getAllKnowledge", {
650
- enumerable: true,
651
- get: function () { return knowledge.getAllKnowledge; }
652
- });
653
- Object.defineProperty(exports, "getExample", {
654
- enumerable: true,
655
- get: function () { return knowledge.getExample; }
656
- });
657
- Object.defineProperty(exports, "getExampleFiles", {
658
- enumerable: true,
659
- get: function () { return knowledge.getExampleFiles; }
660
- });
661
- Object.defineProperty(exports, "getKnowledge", {
662
- enumerable: true,
663
- get: function () { return knowledge.getKnowledge; }
664
- });
665
- Object.defineProperty(exports, "getKnowledgeFiles", {
666
- enumerable: true,
667
- get: function () { return knowledge.getKnowledgeFiles; }
668
- });
669
- exports.CLI_NAME = CLI_NAME;
670
- exports.PACKAGE_NAME = PACKAGE_NAME;
671
- exports.SECTION_END = SECTION_END;
672
- exports.SECTION_START = SECTION_START;
673
- exports.detectMonorepo = detectMonorepo;
674
- exports.detectTools = detectTools;
675
- exports.generateLlmsTxt = generateLlmsTxt;
676
- exports.getTemplate = getTemplate;
677
- exports.hasDirectiveSection = hasDirectiveSection;
678
- exports.loadSystem = loadSystem;
679
- exports.mergeSection = mergeSection;
680
- //# sourceMappingURL=index.cjs.map
269
+ ${d__default.default.cyan("npm install -D tsx")}`)}}function v(e){if(typeof e!="object"||e===null)return false;let r=e;return typeof r.inspect=="function"&&typeof r.start=="function"&&typeof r.stop=="function"&&"facts"in r}Object.defineProperty(exports,"getAllExamples",{enumerable:true,get:function(){return knowledge.getAllExamples}});Object.defineProperty(exports,"getAllKnowledge",{enumerable:true,get:function(){return knowledge.getAllKnowledge}});Object.defineProperty(exports,"getExample",{enumerable:true,get:function(){return knowledge.getExample}});Object.defineProperty(exports,"getExampleFiles",{enumerable:true,get:function(){return knowledge.getExampleFiles}});Object.defineProperty(exports,"getKnowledge",{enumerable:true,get:function(){return knowledge.getKnowledge}});Object.defineProperty(exports,"getKnowledgeFiles",{enumerable:true,get:function(){return knowledge.getKnowledgeFiles}});exports.CLI_NAME=L;exports.PACKAGE_NAME=K;exports.SECTION_END=l;exports.SECTION_START=m;exports.detectMonorepo=G;exports.detectTools=N;exports.generateLlmsTxt=T;exports.getTemplate=D;exports.hasDirectiveSection=F;exports.loadSystem=U;exports.mergeSection=$;//# sourceMappingURL=index.cjs.map
681
270
  //# sourceMappingURL=index.cjs.map