@descix/cli 1.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 (94) hide show
  1. package/README.md +95 -0
  2. package/SERVICE_README_sdk.md +399 -0
  3. package/agent-assets/guides/README.md +61 -0
  4. package/agent-assets/guides/dynamic-site-pattern.md +125 -0
  5. package/agent-assets/guides/knowledge-only-pattern.md +93 -0
  6. package/agent-assets/guides/microservice-pattern.md +152 -0
  7. package/agent-assets/guides/static-site-pattern.md +111 -0
  8. package/agent-assets/instructions/app-asset-validation.md +477 -0
  9. package/agent-assets/instructions/onboarding-flow.md +408 -0
  10. package/agent-assets/instructions/standard-folder-structure.md +125 -0
  11. package/agent-assets/reference/app-creation.md +381 -0
  12. package/agent-assets/reference/architecture.md +406 -0
  13. package/agent-assets/reference/local-dev.md +138 -0
  14. package/agent-assets/reference/mcp-integration.md +424 -0
  15. package/agent-assets/reference/workspace-config.md +415 -0
  16. package/agent-assets/rules/descix_mcp.template.mdc +243 -0
  17. package/bin/descix.js +3930 -0
  18. package/bin/mcp-server.js +382 -0
  19. package/descix-cli-1.0.0.tgz +0 -0
  20. package/lib/agent-files.js +162 -0
  21. package/lib/api-client.js +458 -0
  22. package/lib/auth-guard.js +67 -0
  23. package/lib/commands/app-wizard.js +627 -0
  24. package/lib/commands/auth.js +407 -0
  25. package/lib/commands/buy.js +207 -0
  26. package/lib/commands/clone.js +91 -0
  27. package/lib/commands/config.js +155 -0
  28. package/lib/commands/doctor.js +277 -0
  29. package/lib/commands/folder.js +291 -0
  30. package/lib/commands/init.js +257 -0
  31. package/lib/commands/kb.js +654 -0
  32. package/lib/commands/mcp.js +273 -0
  33. package/lib/commands/serve.js +12 -0
  34. package/lib/commands/status.js +239 -0
  35. package/lib/commands/update.js +653 -0
  36. package/lib/core/Chunker.js +610 -0
  37. package/lib/core/Hydrator.js +801 -0
  38. package/lib/core/PathContext.js +335 -0
  39. package/lib/core/Syncer.js +310 -0
  40. package/lib/core/index.js +32 -0
  41. package/lib/global-config.js +86 -0
  42. package/lib/google-storage-adc.js +511 -0
  43. package/lib/wallet-file.js +232 -0
  44. package/lib/wizard/setup.js +502 -0
  45. package/lib/workspace-config.js +712 -0
  46. package/lib/workspace-utils.js +126 -0
  47. package/package.json +41 -0
  48. package/templates/agent-claude.md +226 -0
  49. package/templates/agent-cline.md +133 -0
  50. package/templates/agent-copilot.md +133 -0
  51. package/templates/agent-cursor.md +133 -0
  52. package/templates/descix_mcp.mdc +122 -0
  53. package/templates/drive/README.md +42 -0
  54. package/templates/drive/app/assets/app_description.md +13 -0
  55. package/templates/drive/app/assets/icon.png +0 -0
  56. package/templates/drive/app/assets/system_instructions.md +17 -0
  57. package/templates/drive/app/kb/General/README.md +25 -0
  58. package/templates/drive/community/Apps/.gitkeep +4 -0
  59. package/templates/drive/community/community_assets/community_description.md +15 -0
  60. package/templates/drive/community/community_assets/icon.png +0 -0
  61. package/templates/drive_templates/README.md +104 -0
  62. package/templates/drive_templates/agent_app_template/assets/app_description.txt +13 -0
  63. package/templates/drive_templates/agent_app_template/assets/system_instructions.txt +17 -0
  64. package/templates/drive_templates/agent_app_template/kb/General/README.md +25 -0
  65. package/templates/drive_templates/agent_app_template/microservice/.gitkeep +10 -0
  66. package/templates/drive_templates/agent_app_template/site/.gitkeep +4 -0
  67. package/templates/drive_templates/community_template/Apps/.gitkeep +4 -0
  68. package/templates/drive_templates/community_template/community_assets/community_description.txt +15 -0
  69. package/templates/scaffolds/README.md +62 -0
  70. package/templates/scaffolds/microservice/Dockerfile +19 -0
  71. package/templates/scaffolds/microservice/SERVICE_README_sdk.md +399 -0
  72. package/templates/scaffolds/microservice/app.js +50 -0
  73. package/templates/scaffolds/microservice/app.yaml +8 -0
  74. package/templates/scaffolds/microservice/defaults-config.json +5 -0
  75. package/templates/scaffolds/microservice/dev-overrides.json.example +5 -0
  76. package/templates/scaffolds/microservice/manifest.json +49 -0
  77. package/templates/scaffolds/microservice/package-lock.json +2645 -0
  78. package/templates/scaffolds/microservice/package.json +29 -0
  79. package/templates/scaffolds/microservice/scripts/register.js +55 -0
  80. package/templates/scaffolds/microservice/services/apiFront.js +75 -0
  81. package/templates/scaffolds/microservice/services/commandHandlers/sampleCommands.js +57 -0
  82. package/templates/scaffolds/microservice/services/mcpClient.js +78 -0
  83. package/templates/scaffolds/microservice/services/utils.js +247 -0
  84. package/templates/scaffolds/microservice/setup-schema.json +18 -0
  85. package/templates/scaffolds/microservice/templates/SERVICE_README_TEMPLATE.md +143 -0
  86. package/templates/scaffolds/site/DeSciXAppSDK.js +62 -0
  87. package/templates/scaffolds/site/README.md +51 -0
  88. package/templates/scaffolds/site/app.js +22 -0
  89. package/templates/scaffolds/site/index.html +42 -0
  90. package/templates/scaffolds/site/styles.css +123 -0
  91. package/test-hydration.js +150 -0
  92. package/vendor/mcp/transports/http-sse-transport.js +196 -0
  93. package/vendor/mcp/transports/index.js +15 -0
  94. package/vendor/mcp/transports/stdio-transport.js +118 -0
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Wallet File Manager
3
+ *
4
+ * Self-contained wallet file management for CLI/MCP.
5
+ * No service imports - pure file system operations.
6
+ */
7
+
8
+ import * as fs from 'fs/promises';
9
+ import * as path from 'path';
10
+ import os from 'os';
11
+
12
+ export class WalletFileManager {
13
+ /**
14
+ * Get default wallet file path
15
+ * Stores in user's home directory under .descix/wallet.json
16
+ */
17
+ static getDefaultWalletPath() {
18
+ const homeDir = os.homedir();
19
+ const descixDir = path.join(homeDir, '.descix');
20
+ return path.join(descixDir, 'wallet.json');
21
+ }
22
+
23
+ /**
24
+ * Get wallet file path from project root
25
+ * Checks for .descix/wallet.json in current working directory
26
+ */
27
+ static getProjectWalletPath(projectRoot = process.cwd()) {
28
+ return path.join(projectRoot, '.descix', 'wallet.json');
29
+ }
30
+
31
+ /**
32
+ * Load wallet file from path
33
+ * @param {string} walletPath - Path to wallet file
34
+ * @returns {Promise<Object|null>} Wallet data or null if not found
35
+ */
36
+ static async loadWalletFile(walletPath) {
37
+ try {
38
+ const data = await fs.readFile(walletPath, 'utf-8');
39
+ const walletData = JSON.parse(data);
40
+
41
+ if (this.validateWalletFile(walletData)) {
42
+ return walletData;
43
+ } else {
44
+ console.error('[WalletFile] Invalid wallet file structure');
45
+ return null;
46
+ }
47
+ } catch (error) {
48
+ if (error.code === 'ENOENT') {
49
+ return null; // File doesn't exist
50
+ }
51
+ console.error(`[WalletFile] Error loading wallet file: ${error.message}`);
52
+ return null;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Save wallet file to path
58
+ * @param {string} walletPath - Path to save wallet file
59
+ * @param {Object} walletData - Wallet data to save
60
+ * @returns {Promise<boolean>} Success status
61
+ */
62
+ static async saveWalletFile(walletPath, walletData) {
63
+ try {
64
+ // Validate before saving
65
+ if (!this.validateWalletFile(walletData)) {
66
+ throw new Error('Invalid wallet data structure');
67
+ }
68
+
69
+ // Ensure directory exists
70
+ const dir = path.dirname(walletPath);
71
+ await fs.mkdir(dir, { recursive: true });
72
+
73
+ // Write file with restricted permissions (600)
74
+ await fs.writeFile(walletPath, JSON.stringify(walletData, null, 2), { mode: 0o600 });
75
+
76
+ return true;
77
+ } catch (error) {
78
+ console.error(`[WalletFile] Error saving wallet file: ${error.message}`);
79
+ return false;
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Validate wallet file structure
85
+ * @param {Object} walletData - Wallet data to validate
86
+ * @returns {boolean} True if valid
87
+ */
88
+ static validateWalletFile(walletData) {
89
+ if (!walletData || typeof walletData !== 'object') {
90
+ return false;
91
+ }
92
+
93
+ // Required fields for authentication
94
+ // Note: tokenSymbol and communityId are optional (may be absent in multi-community mode)
95
+ const required = ['walletAddress', 'signature'];
96
+ for (const field of required) {
97
+ if (!walletData[field] || typeof walletData[field] !== 'string') {
98
+ return false;
99
+ }
100
+ }
101
+
102
+ // Validate wallet address format (basic check - should be hex string)
103
+ if (!/^0x[a-fA-F0-9]{40}$/.test(walletData.walletAddress)) {
104
+ return false;
105
+ }
106
+
107
+ return true;
108
+ }
109
+
110
+ /**
111
+ * Check if session is expired
112
+ * @param {Object} walletData - Wallet data with expiresAt field
113
+ * @returns {boolean} True if expired or no expiresAt
114
+ */
115
+ static isSessionExpired(walletData) {
116
+ if (!walletData || !walletData.expiresAt) {
117
+ return true; // No expiration date means expired
118
+ }
119
+
120
+ try {
121
+ const expiresAt = new Date(walletData.expiresAt);
122
+ const now = new Date();
123
+ return now >= expiresAt;
124
+ } catch (error) {
125
+ console.error('[WalletFile] Error parsing expiresAt:', error);
126
+ return true; // Invalid date means expired
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Check if wallet file has valid session token
132
+ * @param {Object} walletData - Wallet data
133
+ * @returns {boolean} True if has valid session
134
+ */
135
+ static hasValidSession(walletData) {
136
+ if (!walletData) {
137
+ return false;
138
+ }
139
+
140
+ // Check if session token exists
141
+ if (!walletData.sessionToken || !walletData.userId) {
142
+ return false;
143
+ }
144
+
145
+ // Check if session is expired
146
+ if (this.isSessionExpired(walletData)) {
147
+ return false;
148
+ }
149
+
150
+ return true;
151
+ }
152
+
153
+ /**
154
+ * Get wallet path for a workspace root
155
+ * Wallet is ALWAYS at {workspaceRoot}/.descix/wallet.json
156
+ *
157
+ * @param {string} workspaceRoot - Workspace root directory
158
+ * @returns {string} Path to wallet file
159
+ */
160
+ static getWalletPath(workspaceRoot) {
161
+ return path.join(workspaceRoot, '.descix', 'wallet.json');
162
+ }
163
+
164
+ /**
165
+ * Load wallet from workspace root
166
+ * This is the primary method - wallet is always at {workspaceRoot}/.descix/wallet.json
167
+ *
168
+ * @param {string} workspaceRoot - Workspace root directory
169
+ * @returns {Promise<Object|null>} Wallet data or null if not found
170
+ */
171
+ static async loadFromWorkspace(workspaceRoot) {
172
+ const walletPath = this.getWalletPath(workspaceRoot);
173
+ return await this.loadWalletFile(walletPath);
174
+ }
175
+
176
+ /**
177
+ * Save wallet to workspace root
178
+ *
179
+ * @param {string} workspaceRoot - Workspace root directory
180
+ * @param {Object} walletData - Wallet data to save
181
+ * @returns {Promise<boolean>} Success status
182
+ */
183
+ static async saveToWorkspace(workspaceRoot, walletData) {
184
+ const walletPath = this.getWalletPath(workspaceRoot);
185
+ return await this.saveWalletFile(walletPath, walletData);
186
+ }
187
+
188
+ /**
189
+ * @deprecated Use loadFromWorkspace() instead
190
+ * Find wallet file - now just checks workspace root and home directory
191
+ * @param {string} workspaceRoot - Workspace root directory (required)
192
+ * @returns {Promise<string|null>} Path to wallet file or null if not found
193
+ */
194
+ static async findWalletFile(workspaceRoot = null) {
195
+ // If workspace root provided, use it
196
+ if (workspaceRoot) {
197
+ const walletPath = this.getWalletPath(workspaceRoot);
198
+ try {
199
+ await fs.access(walletPath);
200
+ return walletPath;
201
+ } catch (error) {
202
+ // Not found in workspace
203
+ }
204
+ }
205
+
206
+ // Fallback to home directory (for initial setup before workspace exists)
207
+ const homePath = this.getDefaultWalletPath();
208
+ try {
209
+ await fs.access(homePath);
210
+ return homePath;
211
+ } catch (error) {
212
+ // Not found in home
213
+ }
214
+
215
+ return null;
216
+ }
217
+
218
+ /**
219
+ * Create wallet file from wallet data
220
+ * @param {Object} walletData - Wallet data { walletAddress, signature, tokenSymbol, communityId }
221
+ * @param {string} preferredPath - Preferred path (optional, will use default if not provided)
222
+ * @returns {Promise<string|null>} Path to saved wallet file or null on error
223
+ */
224
+ static async createWalletFile(walletData, preferredPath = null) {
225
+ const walletPath = preferredPath || this.getDefaultWalletPath();
226
+ const success = await this.saveWalletFile(walletPath, walletData);
227
+ return success ? walletPath : null;
228
+ }
229
+ }
230
+
231
+ export default WalletFileManager;
232
+