@specverse/engines 5.1.0 → 6.0.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.
Files changed (92) hide show
  1. package/assets/prompts/core/standard/default/analyse.prompt.yaml +5 -5
  2. package/assets/prompts/core/standard/default/app-demo.prompt.yaml +21 -1
  3. package/assets/prompts/core/standard/default/behavior.prompt.yaml +157 -0
  4. package/assets/prompts/core/standard/default/create.prompt.yaml +3 -3
  5. package/assets/prompts/core/standard/default/materialise.prompt.yaml +804 -774
  6. package/assets/prompts/core/standard/default/realize.prompt.yaml +581 -544
  7. package/assets/prompts/core/standard/v9/analyse.prompt.yaml +5 -5
  8. package/assets/prompts/core/standard/v9/app-demo.prompt.yaml +233 -0
  9. package/assets/prompts/core/standard/v9/behavior.prompt.yaml +70 -39
  10. package/assets/prompts/core/standard/v9/create.prompt.yaml +3 -3
  11. package/assets/prompts/core/standard/v9/materialise.prompt.yaml +804 -774
  12. package/assets/prompts/core/standard/v9/realize.prompt.yaml +581 -544
  13. package/dist/ai/behavior-ai-service.d.ts +35 -28
  14. package/dist/ai/behavior-ai-service.d.ts.map +1 -1
  15. package/dist/ai/behavior-ai-service.js +95 -128
  16. package/dist/ai/behavior-ai-service.js.map +1 -1
  17. package/dist/ai/index.d.ts +26 -26
  18. package/dist/ai/index.d.ts.map +1 -1
  19. package/dist/ai/index.js +40 -29
  20. package/dist/ai/index.js.map +1 -1
  21. package/dist/ai/model-resolver.d.ts +13 -0
  22. package/dist/ai/model-resolver.d.ts.map +1 -0
  23. package/dist/ai/model-resolver.js +87 -0
  24. package/dist/ai/model-resolver.js.map +1 -0
  25. package/dist/ai/providers/claude-cli.d.ts +25 -0
  26. package/dist/ai/providers/claude-cli.d.ts.map +1 -0
  27. package/dist/ai/providers/claude-cli.js +185 -0
  28. package/dist/ai/providers/claude-cli.js.map +1 -0
  29. package/dist/ai/providers/index.d.ts +8 -5
  30. package/dist/ai/providers/index.d.ts.map +1 -1
  31. package/dist/ai/providers/index.js +7 -5
  32. package/dist/ai/providers/index.js.map +1 -1
  33. package/dist/ai/providers/stub.d.ts +15 -0
  34. package/dist/ai/providers/stub.d.ts.map +1 -0
  35. package/dist/ai/providers/stub.js +64 -0
  36. package/dist/ai/providers/stub.js.map +1 -0
  37. package/dist/ai/skill-detection.d.ts +5 -0
  38. package/dist/ai/skill-detection.d.ts.map +1 -0
  39. package/dist/ai/skill-detection.js +27 -0
  40. package/dist/ai/skill-detection.js.map +1 -0
  41. package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +184 -0
  42. package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +289 -15
  43. package/libs/instance-factories/cli/templates/commander/command-generator.ts +184 -0
  44. package/libs/instance-factories/tools/templates/mcp/mcp-server-generator.ts +322 -16
  45. package/package.json +8 -3
  46. package/assets/prompts/core/CHANGELOG.md +0 -158
  47. package/assets/prompts/core/MIGRATION-v6-to-v7.md +0 -379
  48. package/assets/prompts/core/base-terminal-prompt.md +0 -201
  49. package/assets/prompts/core/examples/example-usage.ts +0 -140
  50. package/assets/prompts/core/schemas/prompt.schema.json +0 -309
  51. package/assets/prompts/core/schemas/prompt.schema.yaml +0 -229
  52. package/assets/prompts/core/standard/archive/v1/analyse.prompt.yaml +0 -259
  53. package/assets/prompts/core/standard/archive/v1/create.prompt.yaml +0 -302
  54. package/assets/prompts/core/standard/archive/v1/materialise.prompt.yaml +0 -328
  55. package/assets/prompts/core/standard/archive/v1/realize.prompt.yaml +0 -606
  56. package/assets/prompts/core/standard/archive/v2/README.md +0 -110
  57. package/assets/prompts/core/standard/archive/v2/analyse.prompt.yaml +0 -151
  58. package/assets/prompts/core/standard/archive/v2/create.prompt.yaml +0 -151
  59. package/assets/prompts/core/standard/archive/v2/materialise.prompt.yaml +0 -132
  60. package/assets/prompts/core/standard/archive/v2/realize.prompt.yaml +0 -147
  61. package/assets/prompts/core/standard/archive/v3/README.md +0 -279
  62. package/assets/prompts/core/standard/archive/v3/analyse.prompt.yaml +0 -309
  63. package/assets/prompts/core/standard/archive/v3/create.prompt.yaml +0 -351
  64. package/assets/prompts/core/standard/archive/v3/materialise.prompt.yaml +0 -247
  65. package/assets/prompts/core/standard/archive/v3/realize.prompt.yaml +0 -344
  66. package/assets/prompts/core/standard/archive/v4/README.md +0 -79
  67. package/assets/prompts/core/standard/archive/v4/analyse.prompt.yaml +0 -204
  68. package/assets/prompts/core/standard/archive/v4/create.prompt.yaml +0 -185
  69. package/assets/prompts/core/standard/archive/v5/README.md +0 -224
  70. package/assets/prompts/core/standard/archive/v5/analyse.prompt.yaml +0 -209
  71. package/assets/prompts/core/standard/archive/v5/create.prompt.yaml +0 -225
  72. package/assets/prompts/core/standard/archive/v5/materialise.prompt.yaml +0 -242
  73. package/assets/prompts/core/standard/archive/v5/realize.prompt.yaml +0 -336
  74. package/assets/prompts/core/standard/archive/v6/README.md +0 -187
  75. package/assets/prompts/core/standard/archive/v6/analyse.prompt.yaml +0 -219
  76. package/assets/prompts/core/standard/archive/v6/create.prompt.yaml +0 -180
  77. package/assets/prompts/core/standard/archive/v6/materialise.prompt.yaml +0 -203
  78. package/assets/prompts/core/standard/archive/v6/realize.prompt.yaml +0 -215
  79. package/assets/prompts/core/standard/archive/v7/analyse.prompt.nick.yaml +0 -144
  80. package/assets/prompts/core/standard/archive/v7/analyse.prompt.old.yaml +0 -146
  81. package/assets/prompts/core/standard/archive/v7/analyse.prompt.yaml +0 -129
  82. package/assets/prompts/core/standard/archive/v7/create.prompt.yaml +0 -146
  83. package/assets/prompts/core/standard/archive/v7/materialise.prompt.yaml +0 -297
  84. package/assets/prompts/core/standard/archive/v7/realize.prompt.yaml +0 -294
  85. package/assets/prompts/core/standard/archive/v8/README.md +0 -400
  86. package/assets/prompts/core/standard/archive/v8/analyse.prompt.yaml +0 -185
  87. package/assets/prompts/core/standard/archive/v8/create.prompt.yaml +0 -203
  88. package/assets/prompts/core/standard/archive/v8/materialise.prompt.yaml +0 -297
  89. package/assets/prompts/core/standard/archive/v8/realize.prompt.yaml +0 -294
  90. package/assets/prompts/templates/api-orchestrator-template.yaml +0 -188
  91. package/assets/prompts/templates/claude-integration-template.md +0 -121
  92. package/assets/prompts/templates/terminal-prompt-template.md +0 -97
@@ -1,19 +1,28 @@
1
1
  /**
2
- * Behavior AI Service — session-based Claude conversation for generating
3
- * TypeScript function bodies for unmatched behavior steps.
2
+ * Behavior AI Service — generates pure TypeScript function bodies for
3
+ * behavior steps that weren't matched by the realize engine's convention
4
+ * patterns.
4
5
  *
5
- * Architecture (mirrors specverse-app-demo/src/ai/ai-service.ts):
6
- * - First call: spawns Claude with --session-id <uuid> --system-prompt <prompt>
7
- * - Subsequent calls: --resume <uuid> for cached context (98% token savings)
8
- * - All steps for a controller share one session — Claude builds understanding
9
- * of the spec across calls, generating coherent code
10
- * - Loads system prompt from assets/prompts/core/standard/v9/behavior.prompt.yaml
6
+ * Architecture (post AI-SDK replatform, 2026-04):
7
+ * - Delegates to the Vercel AI SDK via the model resolver. Provider choice
8
+ * is driven by SPECVERSE_AI_PROVIDER (claude-cli | anthropic |
9
+ * openai-compatible | stub) with sensible defaults per environment.
10
+ * - Claude-CLI provider preserves the Max-subscription zero-cost path
11
+ * (spawn claude --print --session-id/--resume). API provider uses
12
+ * Anthropic prompt caching for equivalent savings.
13
+ * - When claude-cli is active AND the SpecVerse skill is installed,
14
+ * Claude Code auto-loads the skill — we skip the fullContext block
15
+ * (saves ~2K tokens per session init).
16
+ * - For providers that don't have skill auto-load (anthropic, openai-
17
+ * compatible), we include the fullContext block in the system prompt
18
+ * so the model has the same grounding.
11
19
  *
12
20
  * Used by ai-behaviors-generator at realize time.
13
21
  */
14
22
  export interface BehaviorAIServiceOptions {
15
- claudePath?: string;
23
+ /** Model override. Passed through to the resolver; interpretation is provider-specific. */
16
24
  model?: string;
25
+ /** Per-call timeout (ms). Default 120_000. Only honoured by the claude-cli provider. */
17
26
  timeout?: number;
18
27
  }
19
28
  export interface BehaviorGenerateContext {
@@ -28,36 +37,34 @@ export interface BehaviorGenerateContext {
28
37
  returnType?: string;
29
38
  }
30
39
  /**
31
- * Session-based AI service for generating behavior implementations.
40
+ * Service class kept for API compatibility with ai-behaviors-generator.
41
+ * Internally delegates to the AI SDK via the model resolver.
32
42
  */
33
43
  export declare class BehaviorAIService {
34
- private claudePath;
35
44
  private model;
45
+ private providerId;
46
+ private prompt;
47
+ private system;
36
48
  private timeout;
37
- private sessionId;
38
- private initialized;
39
- private currentProcess;
40
- private systemPrompt;
41
- private userTemplate;
49
+ /** Non-null after generateBehavior() succeeds once. */
50
+ get isAvailable(): boolean;
42
51
  constructor(options?: BehaviorAIServiceOptions);
43
- private detectClaudePath;
44
52
  /**
45
- * Check if Claude CLI is available.
53
+ * Build the system prompt. When the active provider can auto-load the
54
+ * SpecVerse skill (claude-cli + installed skill), we emit role +
55
+ * minimalContext only. Otherwise we include fullContext for grounding.
46
56
  */
47
- get isAvailable(): boolean;
57
+ private assembleSystemPrompt;
48
58
  /**
49
- * Start a new session for a controller. All step generations within the
50
- * controller will share this session, accumulating spec context.
59
+ * Start a new session for a controller. Session semantics are now owned
60
+ * by the provider for claude-cli that's the spawn-with-session-id
61
+ * mechanism; for anthropic API it's the prompt-cache marker. We just
62
+ * record a no-op for callers that expect a session id to log.
51
63
  */
52
64
  startSession(controllerName: string): string;
53
- /**
54
- * Generate a function body for a behavior step.
55
- * First call creates the session with system prompt; subsequent calls resume.
56
- */
65
+ /** Generate a function body for a behavior step. */
57
66
  generateBehavior(ctx: BehaviorGenerateContext): Promise<string | null>;
58
- /**
59
- * End the current session.
60
- */
67
+ /** End the current session — no-op now that session state lives in the provider. */
61
68
  endSession(): void;
62
69
  private buildUserPrompt;
63
70
  private extractCode;
@@ -1 +1 @@
1
- {"version":3,"file":"behavior-ai-service.d.ts","sourceRoot":"","sources":["../../src/ai/behavior-ai-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,MAAM,WAAW,wBAAwB;IACvC,UAAU,C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AK,CAAC,EAAE,MAAM,CAAC;IACf,wFAAwF;IACxF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAwCD;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,KAAK,CAAC;IACd,OAAO,CAAC,UAAU,CAAC;IACnB,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IAExB,uDAAuD;IACvD,IAAI,WAAW,IAAI,OAAO,CAEzB;gBAEW,OAAO,GAAE,wBAA6B;IAQlD;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAY5B;;;;;OAKG;IACH,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM;IAI5C,oDAAoD;IAC9C,gBAAgB,CAAC,GAAG,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA0B5E,oFAAoF;IACpF,UAAU,IAAI,IAAI;IAIlB,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,WAAW;CAQpB"}
@@ -1,184 +1,143 @@
1
1
  /**
2
- * Behavior AI Service — session-based Claude conversation for generating
3
- * TypeScript function bodies for unmatched behavior steps.
2
+ * Behavior AI Service — generates pure TypeScript function bodies for
3
+ * behavior steps that weren't matched by the realize engine's convention
4
+ * patterns.
4
5
  *
5
- * Architecture (mirrors specverse-app-demo/src/ai/ai-service.ts):
6
- * - First call: spawns Claude with --session-id <uuid> --system-prompt <prompt>
7
- * - Subsequent calls: --resume <uuid> for cached context (98% token savings)
8
- * - All steps for a controller share one session — Claude builds understanding
9
- * of the spec across calls, generating coherent code
10
- * - Loads system prompt from assets/prompts/core/standard/v9/behavior.prompt.yaml
6
+ * Architecture (post AI-SDK replatform, 2026-04):
7
+ * - Delegates to the Vercel AI SDK via the model resolver. Provider choice
8
+ * is driven by SPECVERSE_AI_PROVIDER (claude-cli | anthropic |
9
+ * openai-compatible | stub) with sensible defaults per environment.
10
+ * - Claude-CLI provider preserves the Max-subscription zero-cost path
11
+ * (spawn claude --print --session-id/--resume). API provider uses
12
+ * Anthropic prompt caching for equivalent savings.
13
+ * - When claude-cli is active AND the SpecVerse skill is installed,
14
+ * Claude Code auto-loads the skill — we skip the fullContext block
15
+ * (saves ~2K tokens per session init).
16
+ * - For providers that don't have skill auto-load (anthropic, openai-
17
+ * compatible), we include the fullContext block in the system prompt
18
+ * so the model has the same grounding.
11
19
  *
12
20
  * Used by ai-behaviors-generator at realize time.
13
21
  */
14
- import { spawn, execSync } from 'child_process';
15
- import { randomUUID } from 'crypto';
22
+ import { generateText } from 'ai';
23
+ import yaml from 'js-yaml';
16
24
  import { existsSync, readFileSync } from 'fs';
17
- import { join, dirname } from 'path';
25
+ import { dirname, join } from 'path';
18
26
  import { fileURLToPath } from 'url';
19
- import yaml from 'js-yaml';
20
- /**
21
- * Load behavior prompt from engines/assets/prompts/.
22
- */
27
+ import { resolveModel, resolveProviderId } from './model-resolver.js';
28
+ import { detectInstalledSkill } from './skill-detection.js';
29
+ /** Load the structured behavior prompt from engines/assets/prompts/. */
23
30
  function loadBehaviorPrompt() {
24
31
  try {
25
- // Find the engines package root by walking up from this file
26
32
  const __filename = fileURLToPath(import.meta.url);
27
33
  const __dirname = dirname(__filename);
28
- // dist/ai/behavior-ai-service.js or src/ai/behavior-ai-service.ts
29
- // Walk up to find assets/prompts
34
+ // Walk two or three levels up from dist/ai/ or src/ai/ to find assets/prompts
30
35
  const candidates = [
31
36
  join(__dirname, '..', '..', 'assets', 'prompts', 'core', 'standard', 'v9', 'behavior.prompt.yaml'),
32
37
  join(__dirname, '..', '..', '..', 'assets', 'prompts', 'core', 'standard', 'v9', 'behavior.prompt.yaml'),
33
38
  ];
34
39
  for (const path of candidates) {
35
40
  if (existsSync(path)) {
36
- const content = yaml.load(readFileSync(path, 'utf8'));
37
- const role = content?.system?.role || '';
38
- const context = content?.system?.context || '';
39
- const userTemplate = content?.user?.template || '';
41
+ const doc = yaml.load(readFileSync(path, 'utf8'));
40
42
  return {
41
- system: `${role}\n\n${context}`.trim(),
42
- userTemplate,
43
+ role: (doc?.system?.role ?? '').trim(),
44
+ minimalContext: (doc?.system?.minimalContext ?? '').trim(),
45
+ fullContext: (doc?.system?.fullContext ?? '').trim(),
46
+ userTemplate: (doc?.user?.template ?? '').trim(),
43
47
  };
44
48
  }
45
49
  }
46
50
  }
47
51
  catch {
48
- // Fall through to default
52
+ /* fall through to null — caller provides sensible defaults */
49
53
  }
50
54
  return null;
51
55
  }
52
- const DEFAULT_SYSTEM_PROMPT = `You are a SpecVerse behavior code generator.
53
- Generate TypeScript function bodies for behavior steps that don't match convention patterns.
54
- Use the global \`prisma\` client. Output only the function body, no fences, no explanation.`;
55
- const DEFAULT_USER_TEMPLATE = `Generate a TypeScript function body for: "{{step}}"
56
- Context: {{modelName}}.{{operationName}}, parameters: {{parameterNames}}
57
- Output ONLY the function body code.`;
56
+ const DEFAULT_ROLE = 'You are a SpecVerse behavior code generator. Produce pure TypeScript function bodies.';
57
+ const DEFAULT_MINIMAL_CONTEXT = 'Output ONLY the function body. No imports, no database access, no event publishing. Return a plain value. Throw Error("...") on failure.';
58
58
  /**
59
- * Session-based AI service for generating behavior implementations.
59
+ * Service class kept for API compatibility with ai-behaviors-generator.
60
+ * Internally delegates to the AI SDK via the model resolver.
60
61
  */
61
62
  export class BehaviorAIService {
62
- claudePath;
63
63
  model;
64
+ providerId;
65
+ prompt;
66
+ system;
64
67
  timeout;
65
- sessionId = null;
66
- initialized = false;
67
- currentProcess = null;
68
- systemPrompt;
69
- userTemplate;
70
- constructor(options = {}) {
71
- this.claudePath = options.claudePath || this.detectClaudePath();
72
- this.model = options.model || null;
73
- this.timeout = options.timeout || 60000;
74
- const prompt = loadBehaviorPrompt();
75
- this.systemPrompt = prompt?.system || DEFAULT_SYSTEM_PROMPT;
76
- this.userTemplate = prompt?.userTemplate || DEFAULT_USER_TEMPLATE;
68
+ /** Non-null after generateBehavior() succeeds once. */
69
+ get isAvailable() {
70
+ return this.providerId !== 'stub';
77
71
  }
78
- detectClaudePath() {
79
- const home = process.env.HOME || '';
80
- const candidates = [
81
- join(home, '.claude', 'local', 'claude'),
82
- 'claude',
83
- ];
84
- for (const candidate of candidates) {
85
- if (candidate === 'claude')
86
- return candidate;
87
- if (existsSync(candidate))
88
- return candidate;
89
- }
90
- return 'claude';
72
+ constructor(options = {}) {
73
+ this.model = resolveModel({ model: options.model });
74
+ this.providerId = resolveProviderId();
75
+ this.prompt = loadBehaviorPrompt();
76
+ this.timeout = options.timeout ?? 120_000;
77
+ this.system = this.assembleSystemPrompt();
91
78
  }
92
79
  /**
93
- * Check if Claude CLI is available.
80
+ * Build the system prompt. When the active provider can auto-load the
81
+ * SpecVerse skill (claude-cli + installed skill), we emit role +
82
+ * minimalContext only. Otherwise we include fullContext for grounding.
94
83
  */
95
- get isAvailable() {
96
- try {
97
- execSync(`${this.claudePath} --version`, { stdio: 'ignore', timeout: 5000 });
98
- return true;
99
- }
100
- catch {
101
- return false;
84
+ assembleSystemPrompt() {
85
+ const role = this.prompt?.role || DEFAULT_ROLE;
86
+ const minimal = this.prompt?.minimalContext || DEFAULT_MINIMAL_CONTEXT;
87
+ const full = this.prompt?.fullContext || '';
88
+ const skillAutoLoaded = this.providerId === 'claude-cli' && detectInstalledSkill().found;
89
+ if (skillAutoLoaded) {
90
+ return `${role}\n\n${minimal}`;
102
91
  }
92
+ return full ? `${role}\n\n${minimal}\n\n${full}` : `${role}\n\n${minimal}`;
103
93
  }
104
94
  /**
105
- * Start a new session for a controller. All step generations within the
106
- * controller will share this session, accumulating spec context.
95
+ * Start a new session for a controller. Session semantics are now owned
96
+ * by the provider for claude-cli that's the spawn-with-session-id
97
+ * mechanism; for anthropic API it's the prompt-cache marker. We just
98
+ * record a no-op for callers that expect a session id to log.
107
99
  */
108
100
  startSession(controllerName) {
109
- this.sessionId = randomUUID();
110
- this.initialized = false;
111
- return this.sessionId;
101
+ return `${controllerName}-${Date.now()}`;
112
102
  }
113
- /**
114
- * Generate a function body for a behavior step.
115
- * First call creates the session with system prompt; subsequent calls resume.
116
- */
103
+ /** Generate a function body for a behavior step. */
117
104
  async generateBehavior(ctx) {
118
- if (!this.sessionId) {
119
- this.startSession(ctx.modelName);
120
- }
121
105
  if (!this.isAvailable)
122
106
  return null;
123
107
  const userPrompt = this.buildUserPrompt(ctx);
124
- const args = ['--print'];
125
- if (!this.initialized) {
126
- args.push('--session-id', this.sessionId);
127
- args.push('--system-prompt', this.systemPrompt);
108
+ try {
109
+ const result = await generateText({
110
+ model: this.model,
111
+ system: this.system,
112
+ prompt: userPrompt,
113
+ abortSignal: AbortSignal.timeout(this.timeout),
114
+ // Anthropic prompt caching: mark the system message as cacheable
115
+ // so subsequent calls within a cache window get the 90% discount.
116
+ // Other providers ignore this.
117
+ providerOptions: {
118
+ anthropic: {
119
+ cacheControl: { type: 'ephemeral' },
120
+ },
121
+ },
122
+ });
123
+ return this.extractCode(result.text);
128
124
  }
129
- else {
130
- args.push('--resume', this.sessionId);
125
+ catch {
126
+ return null;
131
127
  }
132
- if (this.model)
133
- args.push('--model', this.model);
134
- args.push('-p', userPrompt);
135
- return new Promise((resolve) => {
136
- const proc = spawn(this.claudePath, args, {
137
- stdio: ['ignore', 'pipe', 'pipe'],
138
- env: { ...process.env },
139
- });
140
- this.currentProcess = proc;
141
- let output = '';
142
- const timer = setTimeout(() => {
143
- proc.kill();
144
- resolve(null);
145
- }, this.timeout);
146
- proc.stdout?.on('data', (data) => { output += data.toString(); });
147
- proc.on('close', (code) => {
148
- clearTimeout(timer);
149
- this.currentProcess = null;
150
- if (code !== 0) {
151
- resolve(null);
152
- return;
153
- }
154
- this.initialized = true;
155
- resolve(this.extractCode(output));
156
- });
157
- proc.on('error', () => {
158
- clearTimeout(timer);
159
- this.currentProcess = null;
160
- resolve(null);
161
- });
162
- });
163
128
  }
164
- /**
165
- * End the current session.
166
- */
129
+ /** End the current session — no-op now that session state lives in the provider. */
167
130
  endSession() {
168
- if (this.currentProcess) {
169
- this.currentProcess.kill();
170
- this.currentProcess = null;
171
- }
172
- this.sessionId = null;
173
- this.initialized = false;
131
+ /* nothing to do — provider manages its own lifecycle */
174
132
  }
175
133
  buildUserPrompt(ctx) {
134
+ const template = this.prompt?.userTemplate || DEFAULT_USER_TEMPLATE;
176
135
  const inputVars = ctx.parameterNames.length > 0 ? ctx.parameterNames.join(', ') : 'none';
177
136
  const inputSignature = ctx.parameterNames.length > 0
178
- ? `{ ${ctx.parameterNames.map(n => `${n}: any`).join('; ')} }`
137
+ ? `{ ${ctx.parameterNames.map((n) => `${n}: any`).join('; ')} }`
179
138
  : 'Record<string, never>';
180
139
  const returnType = ctx.returnType || 'any';
181
- return this.userTemplate
140
+ return template
182
141
  .replace(/\{\{step\}\}/g, ctx.step)
183
142
  .replace(/\{\{modelName\}\}/g, ctx.modelName)
184
143
  .replace(/\{\{operationName\}\}/g, ctx.operationName)
@@ -191,15 +150,23 @@ export class BehaviorAIService {
191
150
  }
192
151
  extractCode(output) {
193
152
  let code = output.trim();
194
- // Strip markdown fences
195
153
  const codeBlock = code.match(/```(?:typescript|ts|javascript|js)?\n([\s\S]*?)```/);
196
154
  if (codeBlock)
197
155
  code = codeBlock[1].trim();
198
- // Strip "function ... { ... }" wrapper if model included it
199
156
  const funcMatch = code.match(/^(?:export\s+)?(?:async\s+)?function\s+\w+\([^)]*\)[^{]*\{([\s\S]*)\}\s*$/);
200
157
  if (funcMatch)
201
158
  code = funcMatch[1].trim();
202
159
  return code || null;
203
160
  }
204
161
  }
162
+ const DEFAULT_USER_TEMPLATE = `Generate a PURE TypeScript function body for this SpecVerse behavior step.
163
+
164
+ Step: "{{step}}"
165
+
166
+ Function: async function {{functionName}}(input: {{inputSignature}}): Promise<{{returnType}}>
167
+
168
+ Available: {{inputVars}}
169
+ Available Prisma models (types only): {{availableModels}}
170
+
171
+ Output ONLY the function body (between { and }). No markdown fences.`;
205
172
  //# sourceMappingURL=behavior-ai-service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"behavior-ai-service.js","sourceRoot":"","sources":["../../src/ai/behavior-ai-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAgB,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,IAAI,MAAM,SAAS,CAAC;AAoB3B;;GAEG;AACH,SAAS,kBAAkB;IACzB,IAAI,CAAC;QACH,6DAA6D;QAC7D,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QAEtC,kEAAkE;QAClE,iCAAiC;QACjC,MAAM,UAAU,GAAG;YACjB,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,sBAAsB,CAAC;YAClG,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,E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,CAAC;IACnF,CAAC;IAEO,WAAW,CAAC,MAAc;QAChC,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACnF,IAAI,SAAS;YAAE,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;QAC1G,IAAI,SAAS;YAAE,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1C,OAAO,IAAI,IAAI,IAAI,CAAC;IACtB,CAAC;CACF;AAED,MAAM,qBAAqB,GAAG;;;;;;;;;qEASuC,CAAC"}
@@ -1,27 +1,37 @@
1
1
  /**
2
- * SpecVerse AI Module
3
- * Main export point for all AI functionality
2
+ * SpecVerse AI Module — public surface.
3
+ *
4
+ * Post AI-SDK replatform (2026-04, engines 6.0):
5
+ * - Provider abstraction is Vercel AI SDK (`ai` + `@ai-sdk/*`).
6
+ * - SpecVerse-specific: model-resolver picks claude-cli | anthropic |
7
+ * openai-compatible | stub based on SPECVERSE_AI_PROVIDER.
8
+ * - Behaviour generation at realize time delegates to generateText()
9
+ * through the resolved model; skill-aware system-prompt assembly.
10
+ *
11
+ * What was removed in 6.0:
12
+ * - LLMProvider, LLMProviderRegistry, ProviderFactory
13
+ * - OpenAIProvider, AnthropicProvider, InteractiveProvider
14
+ * - SpecVerseOrchestrator, InteractiveWorkflow (dead code, no consumers)
15
+ * - ConfigLoader / SpecVerseConfig (consumed only by the orchestrator)
16
+ * - config-loader.ts (no consumers)
17
+ * Consumers on those APIs should migrate to resolveModel() + generateText()
18
+ * from 'ai'. See docs/guides/SPECVERSE-AI.md.
4
19
  */
5
20
  export * from './commands/index.js';
6
21
  export * from './core/ecosystem-prompt-manager.js';
7
22
  export * from './types/index.js';
8
- export * from './config-loader.js';
9
23
  export { SessionManager } from './session/session-manager.js';
10
- export type { SessionInfo, JobRequest, JobStatus, CreateSessionOptions } from './session/types.js';
24
+ export type { SessionInfo, JobRequest, JobStatus, CreateSessionOptions, } from './session/types.js';
11
25
  export { BehaviorAIService } from './behavior-ai-service.js';
12
26
  export type { BehaviorAIServiceOptions, BehaviorGenerateContext } from './behavior-ai-service.js';
13
27
  export { regenerateBehavior } from './behavior-regenerate.js';
14
28
  export type { RegenerateBehaviorOptions, RegenerateBehaviorResult } from './behavior-regenerate.js';
15
- export { LLMProvider, LLMProviderRegistry } from './providers/llm-provider.js';
16
- export type { LLMMessage, LLMCompletionOptions, LLMCompletionResponse, LLMProviderConfig, LLMStreamChunk } from './providers/llm-provider.js';
17
- export { ProviderFactory } from './providers/provider-factory.js';
18
- export { OpenAIProvider } from './providers/openai-provider.js';
19
- export { AnthropicProvider } from './providers/anthropic-provider.js';
20
- export { InteractiveProvider } from './providers/interactive-provider.js';
21
- export { SpecVerseOrchestrator } from './orchestrator/specverse-orchestrator.js';
22
- export { InteractiveWorkflow } from './orchestrator/interactive-workflow.js';
23
- export { ConfigLoader, configLoader } from './config/index.js';
24
- export type { SpecVerseConfig } from './config/index.js';
29
+ export { resolveModel, resolveProviderId, describeActiveProvider } from './model-resolver.js';
30
+ export type { ProviderId, ResolveModelOptions } from './model-resolver.js';
31
+ export { claudeCli, isClaudeCliAvailable, detectClaudePath } from './providers/claude-cli.js';
32
+ export type { ClaudeCliOptions } from './providers/claude-cli.js';
33
+ export { stubModel } from './providers/stub.js';
34
+ export { detectInstalledSkill } from './skill-detection.js';
25
35
  import type { SpecVerseEngine, EngineInfo } from '@specverse/types';
26
36
  export interface AIEngine extends SpecVerseEngine {
27
37
  generatePrompt(spec: any, options?: any): Promise<string>;
@@ -31,17 +41,11 @@ export interface AIEngine extends SpecVerseEngine {
31
41
  generateBehavior(step: string, context: BehaviorGenContext): Promise<string | null>;
32
42
  }
33
43
  export interface BehaviorGenContext {
34
- /** The model name (e.g., "Order") */
35
44
  modelName: string;
36
- /** The operation/action name (e.g., "processOrder") */
37
45
  operationName: string;
38
- /** Function name to generate (e.g., "applyDiscountBasedOnLoyaltyTier") */
39
46
  functionName: string;
40
- /** Parameter names from the action (e.g., ['orderId', 'customerId']) */
41
47
  parameterNames: string[];
42
- /** Available models in the spec for context */
43
48
  availableModels?: string[];
44
- /** The full spec for context */
45
49
  spec?: any;
46
50
  }
47
51
  declare class SpecVerseAIEngine implements AIEngine {
@@ -51,18 +55,14 @@ declare class SpecVerseAIEngine implements AIEngine {
51
55
  private manager;
52
56
  initialize(config?: {
53
57
  catalogPath?: string;
54
- provider?: string;
55
58
  }): Promise<void>;
56
59
  getInfo(): EngineInfo;
57
60
  generatePrompt(spec: any, _options?: any): Promise<string>;
58
61
  suggest(spec: any, _context?: string): Promise<any[]>;
59
62
  /**
60
63
  * Generate a TypeScript function body for an unmatched behavior step.
61
- * Delegates to BehaviorAIService which holds a session-based conversation
62
- * with Claude (mirrors app-demo's runtime AI guard generation).
63
- *
64
- * For best results, callers should reuse the same BehaviorAIService instance
65
- * across multiple steps in a controller — the conversation accumulates context.
64
+ * Delegates to BehaviorAIService which resolves the active provider
65
+ * (claude-cli / anthropic / openai-compatible / stub) based on env.
66
66
  */
67
67
  generateBehavior(step: string, context: BehaviorGenContext): Promise<string | null>;
68
68
  template(operation: string, options?: any): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,oCAAoC,CAAC;AACnD,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAGnG,OAAO,EAAE,iBAAiB,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