ai-native-core 0.2.4 → 0.2.6

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/bin/ai-native.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-native-core",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "让任何项目拥有 AI Native 开发能力的运行时框架",
5
5
  "keywords": [
6
6
  "ai-native",
@@ -3,6 +3,12 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const readline = require('readline');
6
+ const { execSync } = require('child_process');
7
+
8
+ function getProjectRoot() {
9
+ try { return execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim(); }
10
+ catch { return process.cwd(); }
11
+ }
6
12
 
7
13
  const VALID_STACKS = ['react-spa', 'nextjs', 'vue', 'backend-go', 'backend-python', 'backend-java'];
8
14
 
@@ -19,7 +25,8 @@ function run(args) {
19
25
  process.exit(1);
20
26
  }
21
27
  }
22
- doInit(stacks, isForce);
28
+ const answers = inferFromStacks(stacks);
29
+ doInit(stacks, isForce, answers);
23
30
  } else {
24
31
  interactiveInit(isForce);
25
32
  }
@@ -76,7 +83,7 @@ function interactiveInit(isForce) {
76
83
  }
77
84
 
78
85
  function doInit(stacks, isForce, answers = {}) {
79
- const root = process.cwd();
86
+ const root = getProjectRoot();
80
87
  const dirs = ['.ai-native/memory', '.ai-native/hooks', '.ai-native/reports', 'docs/.ai-native/memory', 'docs/decisions'];
81
88
 
82
89
  console.log(`\n[ai-native] Initializing...\n`);
@@ -122,4 +129,33 @@ function doInit(stacks, isForce, answers = {}) {
122
129
  console.log(' 3. ai-native accept');
123
130
  }
124
131
 
132
+ function inferFromStacks(stacks) {
133
+ const answers = { pm: 'pnpm' };
134
+ const frontendStacks = ['react-spa', 'nextjs', 'vue'];
135
+ const backendStacks = ['backend-java', 'backend-go', 'backend-python'];
136
+ const hasFrontend = stacks.some(s => frontendStacks.includes(s));
137
+ const hasBackend = stacks.some(s => backendStacks.includes(s));
138
+
139
+ if (hasFrontend && hasBackend) answers.type = 'fullstack';
140
+ else if (hasBackend) answers.type = 'backend';
141
+ else answers.type = 'frontend';
142
+
143
+ if (hasBackend) {
144
+ const lang = stacks.find(s => s.startsWith('backend-')).replace('backend-', '');
145
+ answers.test = { java: 'junit', go: 'go-test', python: 'pytest' }[lang] || 'junit';
146
+ } else {
147
+ answers.test = 'vitest';
148
+ }
149
+
150
+ if (hasFrontend) {
151
+ answers.css = 'tailwind-v4';
152
+ answers.ui = 'shadcn';
153
+ answers.ts = 'yes';
154
+ } else {
155
+ answers.ts = 'no';
156
+ }
157
+
158
+ return answers;
159
+ }
160
+
125
161
  module.exports = { run };