@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.
- package/README.md +95 -0
- package/SERVICE_README_sdk.md +399 -0
- package/agent-assets/guides/README.md +61 -0
- package/agent-assets/guides/dynamic-site-pattern.md +125 -0
- package/agent-assets/guides/knowledge-only-pattern.md +93 -0
- package/agent-assets/guides/microservice-pattern.md +152 -0
- package/agent-assets/guides/static-site-pattern.md +111 -0
- package/agent-assets/instructions/app-asset-validation.md +477 -0
- package/agent-assets/instructions/onboarding-flow.md +408 -0
- package/agent-assets/instructions/standard-folder-structure.md +125 -0
- package/agent-assets/reference/app-creation.md +381 -0
- package/agent-assets/reference/architecture.md +406 -0
- package/agent-assets/reference/local-dev.md +138 -0
- package/agent-assets/reference/mcp-integration.md +424 -0
- package/agent-assets/reference/workspace-config.md +415 -0
- package/agent-assets/rules/descix_mcp.template.mdc +243 -0
- package/bin/descix.js +3930 -0
- package/bin/mcp-server.js +382 -0
- package/descix-cli-1.0.0.tgz +0 -0
- package/lib/agent-files.js +162 -0
- package/lib/api-client.js +458 -0
- package/lib/auth-guard.js +67 -0
- package/lib/commands/app-wizard.js +627 -0
- package/lib/commands/auth.js +407 -0
- package/lib/commands/buy.js +207 -0
- package/lib/commands/clone.js +91 -0
- package/lib/commands/config.js +155 -0
- package/lib/commands/doctor.js +277 -0
- package/lib/commands/folder.js +291 -0
- package/lib/commands/init.js +257 -0
- package/lib/commands/kb.js +654 -0
- package/lib/commands/mcp.js +273 -0
- package/lib/commands/serve.js +12 -0
- package/lib/commands/status.js +239 -0
- package/lib/commands/update.js +653 -0
- package/lib/core/Chunker.js +610 -0
- package/lib/core/Hydrator.js +801 -0
- package/lib/core/PathContext.js +335 -0
- package/lib/core/Syncer.js +310 -0
- package/lib/core/index.js +32 -0
- package/lib/global-config.js +86 -0
- package/lib/google-storage-adc.js +511 -0
- package/lib/wallet-file.js +232 -0
- package/lib/wizard/setup.js +502 -0
- package/lib/workspace-config.js +712 -0
- package/lib/workspace-utils.js +126 -0
- package/package.json +41 -0
- package/templates/agent-claude.md +226 -0
- package/templates/agent-cline.md +133 -0
- package/templates/agent-copilot.md +133 -0
- package/templates/agent-cursor.md +133 -0
- package/templates/descix_mcp.mdc +122 -0
- package/templates/drive/README.md +42 -0
- package/templates/drive/app/assets/app_description.md +13 -0
- package/templates/drive/app/assets/icon.png +0 -0
- package/templates/drive/app/assets/system_instructions.md +17 -0
- package/templates/drive/app/kb/General/README.md +25 -0
- package/templates/drive/community/Apps/.gitkeep +4 -0
- package/templates/drive/community/community_assets/community_description.md +15 -0
- package/templates/drive/community/community_assets/icon.png +0 -0
- package/templates/drive_templates/README.md +104 -0
- package/templates/drive_templates/agent_app_template/assets/app_description.txt +13 -0
- package/templates/drive_templates/agent_app_template/assets/system_instructions.txt +17 -0
- package/templates/drive_templates/agent_app_template/kb/General/README.md +25 -0
- package/templates/drive_templates/agent_app_template/microservice/.gitkeep +10 -0
- package/templates/drive_templates/agent_app_template/site/.gitkeep +4 -0
- package/templates/drive_templates/community_template/Apps/.gitkeep +4 -0
- package/templates/drive_templates/community_template/community_assets/community_description.txt +15 -0
- package/templates/scaffolds/README.md +62 -0
- package/templates/scaffolds/microservice/Dockerfile +19 -0
- package/templates/scaffolds/microservice/SERVICE_README_sdk.md +399 -0
- package/templates/scaffolds/microservice/app.js +50 -0
- package/templates/scaffolds/microservice/app.yaml +8 -0
- package/templates/scaffolds/microservice/defaults-config.json +5 -0
- package/templates/scaffolds/microservice/dev-overrides.json.example +5 -0
- package/templates/scaffolds/microservice/manifest.json +49 -0
- package/templates/scaffolds/microservice/package-lock.json +2645 -0
- package/templates/scaffolds/microservice/package.json +29 -0
- package/templates/scaffolds/microservice/scripts/register.js +55 -0
- package/templates/scaffolds/microservice/services/apiFront.js +75 -0
- package/templates/scaffolds/microservice/services/commandHandlers/sampleCommands.js +57 -0
- package/templates/scaffolds/microservice/services/mcpClient.js +78 -0
- package/templates/scaffolds/microservice/services/utils.js +247 -0
- package/templates/scaffolds/microservice/setup-schema.json +18 -0
- package/templates/scaffolds/microservice/templates/SERVICE_README_TEMPLATE.md +143 -0
- package/templates/scaffolds/site/DeSciXAppSDK.js +62 -0
- package/templates/scaffolds/site/README.md +51 -0
- package/templates/scaffolds/site/app.js +22 -0
- package/templates/scaffolds/site/index.html +42 -0
- package/templates/scaffolds/site/styles.css +123 -0
- package/test-hydration.js +150 -0
- package/vendor/mcp/transports/http-sse-transport.js +196 -0
- package/vendor/mcp/transports/index.js +15 -0
- package/vendor/mcp/transports/stdio-transport.js +118 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
# SDK Architecture Reference
|
|
2
|
+
|
|
3
|
+
**Status:** Implemented
|
|
4
|
+
**Version:** 2.0
|
|
5
|
+
**Last Updated:** January 2026
|
|
6
|
+
|
|
7
|
+
This document is the canonical reference for the DeSciX SDK architecture, covering the CLI-centric KB processing pipeline, Drive synchronization, and folder structure conventions.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 1. Architecture Overview
|
|
12
|
+
|
|
13
|
+
### Core Philosophy
|
|
14
|
+
|
|
15
|
+
1. **Drive as Backend:** Google Drive is the canonical source for raw assets (PDFs, documents, images).
|
|
16
|
+
2. **Git as Truth:** The local Git repository is the canonical source for *processed* text and code.
|
|
17
|
+
3. **Client-Side Mediation:** The CLI communicates directly with Drive via ADC (Application Default Credentials), removing server-side proxy overhead for file transfers.
|
|
18
|
+
4. **No Local Tools:** The CLI relies on Drive's internal conversion capabilities (OCR, Doc-to-Markdown) instead of bundling heavy local dependencies.
|
|
19
|
+
|
|
20
|
+
### Data Flow Summary
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
Drive (raw assets) → CLI (pull + convert) → Local Git (text + chunks) → Backend API → Pinecone
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 2. Core Components
|
|
29
|
+
|
|
30
|
+
All core SDK logic resides in `DeSciX_Core/descix-cli/lib/core/`.
|
|
31
|
+
|
|
32
|
+
### 2.1 Hydrator (`Hydrator.js`)
|
|
33
|
+
|
|
34
|
+
**Responsibilities:**
|
|
35
|
+
- Pull content from Drive to local filesystem
|
|
36
|
+
- Push staging files to Drive
|
|
37
|
+
- Convert files using Drive's native capabilities (PDF/Image → Google Doc → Markdown)
|
|
38
|
+
- Conflict detection and resolution during hydration
|
|
39
|
+
|
|
40
|
+
**Key Functions:**
|
|
41
|
+
|
|
42
|
+
| Function | Description |
|
|
43
|
+
|----------|-------------|
|
|
44
|
+
| `hydrateWorkspace(root, config, driveConfig, options)` | Full workspace setup with folder creation and Drive sync |
|
|
45
|
+
| `hydrateApp(config, options)` | Pull entire app from Drive |
|
|
46
|
+
| `hydrateKb(config, options)` | Pull and convert KB files from Drive |
|
|
47
|
+
| `pushStaging(config, options)` | Upload files from `kb/staging/` to Drive |
|
|
48
|
+
| `convertAndSave(driveFile, localDir)` | Convert and save a single file |
|
|
49
|
+
|
|
50
|
+
**Drive-Native Conversion Logic:**
|
|
51
|
+
1. PDF/DOCX/Images: Copy with `convert=true` → Creates temp Google Doc → Export as Markdown → Delete temp doc
|
|
52
|
+
2. Google Docs: Export directly as `text/markdown`
|
|
53
|
+
3. Google Sheets: Export as `text/csv`
|
|
54
|
+
4. Plain text files: Download as-is
|
|
55
|
+
|
|
56
|
+
### 2.2 Chunker (`Chunker.js`)
|
|
57
|
+
|
|
58
|
+
**Responsibilities:**
|
|
59
|
+
- Chunk documents for RAG embedding
|
|
60
|
+
- Support multiple chunking strategies (semantic, sliding window)
|
|
61
|
+
- Generate chunk records with metadata for Pinecone
|
|
62
|
+
|
|
63
|
+
**Key Functions:**
|
|
64
|
+
|
|
65
|
+
| Function | Description |
|
|
66
|
+
|----------|-------------|
|
|
67
|
+
| `categorizeFile(fileName, mimeType)` | Detect file type (code/docs/papers/generic) |
|
|
68
|
+
| `chunkFile(fileInfo, options)` | Chunk a file based on its type |
|
|
69
|
+
| `chunkDocument(content, metadata, rules)` | Markdown-aware section-based chunking |
|
|
70
|
+
| `processKb(config, options)` | Process entire KB directory into chunks |
|
|
71
|
+
| `loadChunks(config)` | Load all chunks from JSON files |
|
|
72
|
+
|
|
73
|
+
**Chunking Parameters (defaults):**
|
|
74
|
+
- `maxChunkSize`: 2000 characters
|
|
75
|
+
- `maxCodeFileSize`: 8000 characters
|
|
76
|
+
- `overlapSize`: 500 characters
|
|
77
|
+
|
|
78
|
+
**Chunking Strategies:**
|
|
79
|
+
- **Documents:** Split by Markdown headers (`#`, `##`, `###`) with overlap
|
|
80
|
+
- **Code:** Split by logical boundaries (functions, classes, contracts)
|
|
81
|
+
- **Generic:** Sliding window with overlap
|
|
82
|
+
|
|
83
|
+
### 2.3 Syncer (`Syncer.js`)
|
|
84
|
+
|
|
85
|
+
**Responsibilities:**
|
|
86
|
+
- Sync local chunks to Pinecone via backend API
|
|
87
|
+
- Compute delta between local and remote chunks
|
|
88
|
+
- Manage chunk lifecycle (upsert/delete)
|
|
89
|
+
|
|
90
|
+
**Key Functions:**
|
|
91
|
+
|
|
92
|
+
| Function | Description |
|
|
93
|
+
|----------|-------------|
|
|
94
|
+
| `syncKb(apiClient, config, options)` | Full sync workflow (delta + upsert + delete) |
|
|
95
|
+
| `computeChunkDelta(localChunks, remoteIds)` | Compare local vs remote chunks |
|
|
96
|
+
| `getRemoteChunkIds(apiClient, communityId, appId, kbId)` | Get existing chunk IDs from Pinecone |
|
|
97
|
+
| `upsertChunks(apiClient, ...)` | Push chunks to backend |
|
|
98
|
+
| `deleteStaleChunks(apiClient, ...)` | Remove deleted chunks |
|
|
99
|
+
| `getSyncStatus(apiClient, config)` | Check sync state |
|
|
100
|
+
|
|
101
|
+
**Security Note:** The CLI never communicates with Pinecone directly. All chunk operations go through the backend API, which validates metadata and manages Pinecone credentials.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 3. Folder Structure
|
|
106
|
+
|
|
107
|
+
### Local App Structure
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
[app]/
|
|
111
|
+
├── assets/ # App metadata (bidirectional sync)
|
|
112
|
+
│ ├── icon.png
|
|
113
|
+
│ ├── app_description.md
|
|
114
|
+
│ └── system_instructions.md
|
|
115
|
+
├── kb/
|
|
116
|
+
│ ├── staging/ # Local files to push to Drive
|
|
117
|
+
│ │ └── research.pdf
|
|
118
|
+
│ ├── General/ # Text-converted mirror of Drive
|
|
119
|
+
│ │ ├── research.md # Converted from PDF
|
|
120
|
+
│ │ └── notes.md # Converted from Google Doc
|
|
121
|
+
│ └── chunks/ # Processed JSON chunks (Git-tracked)
|
|
122
|
+
│ ├── research.chunks.json
|
|
123
|
+
│ └── notes.chunks.json
|
|
124
|
+
├── site/ # Static site files (push-only)
|
|
125
|
+
│ └── index.html
|
|
126
|
+
└── microservice/ # Service code (push-only)
|
|
127
|
+
└── src/index.js
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Folder Purposes
|
|
131
|
+
|
|
132
|
+
| Folder | Sync Direction | Purpose |
|
|
133
|
+
|--------|----------------|---------|
|
|
134
|
+
| `assets/` | Bidirectional | App metadata (icon, description, instructions) |
|
|
135
|
+
| `kb/staging/` | Local → Drive | Raw files waiting to be pushed |
|
|
136
|
+
| `kb/General/` | Drive → Local | Text-converted files from Drive |
|
|
137
|
+
| `kb/chunks/` | Local only | JSON chunk files for Pinecone sync |
|
|
138
|
+
| `site/` | Local → GCS | Static site deployment |
|
|
139
|
+
| `microservice/` | Local → GCS | Backend service deployment |
|
|
140
|
+
|
|
141
|
+
### Configuration Files
|
|
142
|
+
|
|
143
|
+
**`.descix/workspace.json`** - The **sole** configuration file for CLI operations:
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"version": "2.0",
|
|
148
|
+
"communities": {
|
|
149
|
+
"descix": {
|
|
150
|
+
"apps": {
|
|
151
|
+
"agent": {
|
|
152
|
+
"localPath": "descix/agent",
|
|
153
|
+
"kbId": "General",
|
|
154
|
+
"absolutePath": "/path/to/workspace/descix/agent",
|
|
155
|
+
"site": {
|
|
156
|
+
"port": 3000,
|
|
157
|
+
"devCommand": "npm run docs:dev"
|
|
158
|
+
},
|
|
159
|
+
"service": {
|
|
160
|
+
"port": 4001,
|
|
161
|
+
"devCommand": "npm run start"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"driveConfig": {
|
|
168
|
+
"base_folder_id": "1ABC...",
|
|
169
|
+
"base_folder_name": "DeSciX"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Note:** `.descix.app/context.json` files are no longer used. All app configuration is stored in `workspace.json`. The CLI auto-detects app context from the current working directory by matching against registered app paths.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## 4. CLI Commands
|
|
179
|
+
|
|
180
|
+
The DeSciX CLI provides two primary ways to manage content: **Context-Aware Updates** (for high-level sync) and **KB Processing Commands** (for low-level control).
|
|
181
|
+
|
|
182
|
+
### 4.1 Context-Aware Updates (`descix update`)
|
|
183
|
+
|
|
184
|
+
These commands auto-detect app context from `workspace.json` based on the current working directory.
|
|
185
|
+
|
|
186
|
+
| Command | Description |
|
|
187
|
+
|---------|-------------|
|
|
188
|
+
| `descix update` | Auto-detect what to update based on current folder |
|
|
189
|
+
| `descix update app` | Sync app assets (icon, description, instructions) to Drive |
|
|
190
|
+
| `descix update kb` | Full three-stage sync (Local → Drive → GCS → Pinecone) |
|
|
191
|
+
| `descix update site` | Deploy CodeSite to GCS |
|
|
192
|
+
| `descix update all` | Update all resources (App, KB, Site) in sequence |
|
|
193
|
+
|
|
194
|
+
### 4.2 KB Processing Commands (`descix kb`)
|
|
195
|
+
|
|
196
|
+
These commands provide granular control over the V2 local-first pipeline.
|
|
197
|
+
|
|
198
|
+
| Command | Description |
|
|
199
|
+
|---------|-------------|
|
|
200
|
+
| `descix kb pull` | Download from Drive, convert to text in `kb/General/` |
|
|
201
|
+
| `descix kb push` | Upload files from `kb/staging/` to Drive |
|
|
202
|
+
| `descix kb chunk` | Generate JSON chunks from `kb/General/` to `kb/chunks/` |
|
|
203
|
+
| `descix kb sync` | Push chunks to Pinecone via backend API |
|
|
204
|
+
| `descix kb build` | Convenience: pull → chunk → sync |
|
|
205
|
+
| `descix kb status` | Show sync status (local vs Pinecone) |
|
|
206
|
+
|
|
207
|
+
### Scaffold Commands
|
|
208
|
+
|
|
209
|
+
| Command | Description |
|
|
210
|
+
|---------|-------------|
|
|
211
|
+
| `descix site init` | Copy site template to current app's `site/` folder |
|
|
212
|
+
| `descix site upload` | Deploy site to GCS |
|
|
213
|
+
| `descix site servelocal [port]` | Register local dev server port |
|
|
214
|
+
| `descix microservice init` | Copy microservice template to current app's `microservice/` folder |
|
|
215
|
+
| `descix microservice register` | Register microservice with gateway |
|
|
216
|
+
| `descix microservice vectorize` | Vectorize README for discovery |
|
|
217
|
+
|
|
218
|
+
**Note:** Site and microservice commands are Git-based code operations. Drive templates contain content (assets, KB), while site/microservice commands handle code (HTML, JS, Dockerfile, etc.).
|
|
219
|
+
|
|
220
|
+
### Common Options
|
|
221
|
+
|
|
222
|
+
| Option | Description |
|
|
223
|
+
|--------|-------------|
|
|
224
|
+
| `-c, --community <id>` | Community ID (inferred if single) |
|
|
225
|
+
| `-a, --app <id>` | App ID (inferred if single) |
|
|
226
|
+
| `-k, --kb <id>` | KB name (default: General) |
|
|
227
|
+
| `-v, --verbose` | Show detailed output |
|
|
228
|
+
|
|
229
|
+
### Setup Command
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
descix setup [--dev]
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Flow:
|
|
236
|
+
1. Check prerequisites (gcloud CLI, ADC credentials)
|
|
237
|
+
2. Open browser for device login + workspace configuration
|
|
238
|
+
3. Hydrate local workspace from PWA selection
|
|
239
|
+
4. Create folder structure with new KB layout
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## 5. Backend API
|
|
244
|
+
|
|
245
|
+
### KB Endpoints
|
|
246
|
+
|
|
247
|
+
| Endpoint | Method | Description |
|
|
248
|
+
|----------|--------|-------------|
|
|
249
|
+
| `kb_sync_chunks` | POST | Upsert chunks to Pinecone |
|
|
250
|
+
| `kb_get_chunk_ids` | GET | Get existing chunk IDs for delta |
|
|
251
|
+
| `kb_delete_chunks` | DELETE | Remove stale chunks |
|
|
252
|
+
|
|
253
|
+
### `kb_sync_chunks` Request
|
|
254
|
+
|
|
255
|
+
```json
|
|
256
|
+
{
|
|
257
|
+
"community_id": "descix",
|
|
258
|
+
"app_id": "agent",
|
|
259
|
+
"kb_id": "General",
|
|
260
|
+
"chunks": [
|
|
261
|
+
{
|
|
262
|
+
"id": "descix_agent_General_research_0",
|
|
263
|
+
"text": "...",
|
|
264
|
+
"entity_type": "CHUNK",
|
|
265
|
+
"community_id": "descix",
|
|
266
|
+
"app_id": "agent",
|
|
267
|
+
"knowledgebase_name": "General",
|
|
268
|
+
"file_id": "research.md",
|
|
269
|
+
"chunk_id": "0"
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Pinecone Integration
|
|
276
|
+
|
|
277
|
+
The platform uses **Pinecone Integrated Embeddings**:
|
|
278
|
+
- Vectorization happens inside Pinecone, not in the backend
|
|
279
|
+
- The CLI/backend sends text + metadata only
|
|
280
|
+
- Pinecone's `llama-text-embed-v2` model handles embedding
|
|
281
|
+
- No local embedding libraries required
|
|
282
|
+
|
|
283
|
+
**Backend Flow:**
|
|
284
|
+
```
|
|
285
|
+
CLI → kb_sync_chunks API → pineconeService.upsertChunkRecords() → Pinecone (embeds + stores)
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## 6. Data Flows
|
|
291
|
+
|
|
292
|
+
### Push-Pull-Convert Cycle
|
|
293
|
+
|
|
294
|
+
```mermaid
|
|
295
|
+
flowchart LR
|
|
296
|
+
subgraph local [Local Filesystem]
|
|
297
|
+
staging[kb/staging/]
|
|
298
|
+
general[kb/General/]
|
|
299
|
+
chunks[kb/chunks/]
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
subgraph drive [Google Drive]
|
|
303
|
+
driveKb[kb/General/]
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
subgraph backend [Backend]
|
|
307
|
+
api[kb_sync_chunks]
|
|
308
|
+
pinecone[Pinecone]
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
staging -->|"kb push"| driveKb
|
|
312
|
+
driveKb -->|"kb pull (convert)"| general
|
|
313
|
+
general -->|"kb chunk"| chunks
|
|
314
|
+
chunks -->|"kb sync"| api
|
|
315
|
+
api --> pinecone
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Detailed Flow
|
|
319
|
+
|
|
320
|
+
1. **Stage:** User adds `paper.pdf` to `kb/staging/`
|
|
321
|
+
2. **Push:** `descix kb push` uploads to Drive `kb/General/`
|
|
322
|
+
3. **Pull:** `descix kb pull` downloads and converts:
|
|
323
|
+
- Sees `paper.pdf` in Drive
|
|
324
|
+
- Copies with `convert=true` → temp Google Doc
|
|
325
|
+
- Exports as Markdown → `kb/General/paper.md`
|
|
326
|
+
- Deletes temp doc
|
|
327
|
+
4. **Chunk:** `descix kb chunk` processes `paper.md`:
|
|
328
|
+
- Generates `kb/chunks/paper.chunks.json`
|
|
329
|
+
5. **Sync:** `descix kb sync` pushes to backend:
|
|
330
|
+
- Backend validates metadata
|
|
331
|
+
- Forwards to Pinecone
|
|
332
|
+
- Pinecone embeds and stores
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## 7. Authentication
|
|
337
|
+
|
|
338
|
+
### ADC (Application Default Credentials)
|
|
339
|
+
|
|
340
|
+
The CLI uses Google Cloud ADC for Drive access:
|
|
341
|
+
|
|
342
|
+
```bash
|
|
343
|
+
gcloud auth application-default login \
|
|
344
|
+
--scopes=https://www.googleapis.com/auth/drive.file,https://www.googleapis.com/auth/drive
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
**Verification:**
|
|
348
|
+
- `descix setup` checks ADC before proceeding
|
|
349
|
+
- `Hydrator` calls `verifyDriveAuth()` before operations
|
|
350
|
+
|
|
351
|
+
### Backend Authentication
|
|
352
|
+
|
|
353
|
+
CLI authenticates to backend via device login:
|
|
354
|
+
1. `descix login` opens browser
|
|
355
|
+
2. User authenticates via Powch
|
|
356
|
+
3. CLI receives session token
|
|
357
|
+
4. Token stored in `.descix/wallet.json`
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## 8. Migration Notes
|
|
362
|
+
|
|
363
|
+
### From `kb/src/` to `kb/staging/`
|
|
364
|
+
|
|
365
|
+
The v2 architecture renamed `kb/src/` to `kb/staging/` for clarity. The Hydrator includes automatic migration:
|
|
366
|
+
|
|
367
|
+
```javascript
|
|
368
|
+
// If old kb/src/ exists, rename to kb/staging/
|
|
369
|
+
const oldSrcDir = path.join(kbBaseDir, 'src');
|
|
370
|
+
if (await exists(oldSrcDir)) {
|
|
371
|
+
await rename(oldSrcDir, stagingDir);
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Git Mode vs Drive Mode
|
|
376
|
+
|
|
377
|
+
Apps operate in one of two modes, determined by how they are managed:
|
|
378
|
+
|
|
379
|
+
| Mode | Source of Truth | Versioning | User Type | Tool |
|
|
380
|
+
|------|-----------------|------------|-----------|------|
|
|
381
|
+
| **git** | Local Git repo | Git | Developers | CLI (`descix kb *`) |
|
|
382
|
+
| **drive** | Google Drive | GCS/Firestore | Non-developers | PWA only |
|
|
383
|
+
|
|
384
|
+
**Important:** The CLI only supports **git-mode** operations. Drive-mode apps are managed entirely through the PWA with server-side processing. There is no CLI flag to switch modes - if you're using the CLI, you're in git-mode.
|
|
385
|
+
|
|
386
|
+
Both modes start with content on Google Drive (users create documents there). The difference is:
|
|
387
|
+
- **Git mode**: Developer pulls content from Drive, then manages text/chunks locally with Git
|
|
388
|
+
- **Drive mode**: PWA triggers server-side pipeline (Drive → GCS → Pinecone) automatically
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## 9. File References
|
|
393
|
+
|
|
394
|
+
| Component | Path | Description |
|
|
395
|
+
|-----------|------|-------------|
|
|
396
|
+
| WorkspaceConfig | `DeSciX_Core/descix-cli/lib/workspace-config.js` | Sole configuration class |
|
|
397
|
+
| GlobalConfig | `DeSciX_Core/descix-cli/lib/global-config.js` | User-level settings (~/.descix) |
|
|
398
|
+
| Hydrator | `DeSciX_Core/descix-cli/lib/core/Hydrator.js` | Drive sync operations |
|
|
399
|
+
| Chunker | `DeSciX_Core/descix-cli/lib/core/Chunker.js` | KB chunking |
|
|
400
|
+
| Syncer | `DeSciX_Core/descix-cli/lib/core/Syncer.js` | Pinecone sync |
|
|
401
|
+
| KB Commands | `DeSciX_Core/descix-cli/lib/commands/kb.js` | Git-mode KB processing |
|
|
402
|
+
| Setup Command | `DeSciX_Core/descix-cli/lib/commands/setup.js` | Initial workspace setup |
|
|
403
|
+
| Drive ADC | `DeSciX_Core/descix-cli/lib/google-storage-adc.js` | Google Drive API wrapper |
|
|
404
|
+
| Backend KB API | `DeSciX_Cloud/services/commandHandlers/appCommands.js` | Server-side processing |
|
|
405
|
+
| Pinecone Service | `DeSciX_Cloud/services/pineconeService.js` | Vector database |
|
|
406
|
+
| Server Chunking | `DeSciX_Cloud/services/chunkingUtils.js` | Drive-mode chunking |
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Local Development Architecture: The "Local Mesh" Proxy
|
|
2
|
+
|
|
3
|
+
## 1. Overview
|
|
4
|
+
|
|
5
|
+
This document outlines the unified architecture for local development of DeSciX Apps (CodeSites and Microservices). The core design principle is to treat the local development environment as a **Local Load Balancer** that mirrors the production routing topology.
|
|
6
|
+
|
|
7
|
+
**Important**: This document applies to **git-mode** developers who use the CLI for app development. For **drive-mode** users (non-developers using the PWA), app management is handled entirely through the web interface with server-side processing.
|
|
8
|
+
|
|
9
|
+
This approach unifies three distinct scenarios:
|
|
10
|
+
1. **Platform Dev**: Developing the core platform (PWA + API) locally.
|
|
11
|
+
2. **End-User Dev**: Developing a single App against the production platform.
|
|
12
|
+
3. **Production**: Running live on `*.descix.net`.
|
|
13
|
+
|
|
14
|
+
## 1.1. Git Mode vs Drive Mode
|
|
15
|
+
|
|
16
|
+
| Aspect | Git Mode (CLI) | Drive Mode (PWA) |
|
|
17
|
+
|--------|---------------|-----------------|
|
|
18
|
+
| **User Type** | Developers | Non-technical users |
|
|
19
|
+
| **Content Source** | Local git repo (MD exports pulled from Drive via `kb pull`) | Google Drive |
|
|
20
|
+
| **Version Control** | Git | Drive/GCS/Firestore |
|
|
21
|
+
| **KB Processing** | `descix update kb` or `descix kb build` — local chunking → Pinecone directly | Server-side pipeline (Drive → GCS → Pinecone) — PWA users only |
|
|
22
|
+
| **Configuration** | `workspace.json` | N/A (PWA handles) |
|
|
23
|
+
| **Tools** | CLI, VSCode, Git | PWA only |
|
|
24
|
+
|
|
25
|
+
## 2. The Canonical Routing Model
|
|
26
|
+
|
|
27
|
+
Instead of exposing implementation details (like GCS bucket URLs or specific port numbers) to the client, the platform uses **Canonical Paths** for all resources.
|
|
28
|
+
|
|
29
|
+
### 2.1. Route Patterns
|
|
30
|
+
|
|
31
|
+
| Resource Type | Canonical Path | Production Target (LB) | Local Target (Gateway Proxy) |
|
|
32
|
+
| :--- | :--- | :--- | :--- |
|
|
33
|
+
| **Core API** | `/apifront`, `/api`, `/mcp` | Core API | `https://localhost:4000` |
|
|
34
|
+
| **Powch PWA** | `/powch` | Powch PWA | `https://localhost:5174` |
|
|
35
|
+
| **Microservice** | `/s/{community}/{appId}` | k8s-service | `http://localhost:{service.port}` |
|
|
36
|
+
| **CodeSite / App Site** | `/Community/{c}/Apps/{a}/site`, `/s/{appId}` | GCS / service | `http://localhost:{site.port}` |
|
|
37
|
+
| **PWA** | `/*` | PWA bucket | Served from gateway root (when run from DeSciX_PWA) |
|
|
38
|
+
|
|
39
|
+
## 3. The "Local Mesh" Proxy
|
|
40
|
+
|
|
41
|
+
The `descix serve` command spins up a **Local Gateway** on port `5173`. This gateway acts as the router, serving the PWA (when run from `DeSciX_PWA`) and proxying traffic based on the **Workspace Configuration**. Run `npm run dev:serve` from `DeSciX_PWA` or `npx descix serve` with PWA as cwd for Platform Dev.
|
|
42
|
+
|
|
43
|
+
### 3.1. Configuration: `.descix/workspace.json`
|
|
44
|
+
The `workspace.json` file is the **single source of truth** for local routing and app configuration. This is the only configuration methodology - `.descix.app/context.json` files are no longer used.
|
|
45
|
+
|
|
46
|
+
**Key Features:**
|
|
47
|
+
- Workspace root detection (searches upward for `.descix/`, `.cursor/`, or `.vscode/`)
|
|
48
|
+
- App context autodiscovery (CLI commands auto-detect community/app from cwd)
|
|
49
|
+
- Port registration for local dev servers
|
|
50
|
+
- Drive folder configuration for `kb pull/push`
|
|
51
|
+
- `apiUrl` derived automatically from `env.platform.microservice.port` in DEV mode
|
|
52
|
+
|
|
53
|
+
#### Platform Dev format (V2.1)
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"version": "2.1",
|
|
58
|
+
"workspaceRoot": "/path/to/workspace",
|
|
59
|
+
"serve-port": 5173,
|
|
60
|
+
"driveConfig": { "base_folder_id": "..." },
|
|
61
|
+
"env": {
|
|
62
|
+
"environment": "DEV",
|
|
63
|
+
"platform": {
|
|
64
|
+
"appId": "daita",
|
|
65
|
+
"localPath": "DeSciX_Cloud",
|
|
66
|
+
"site": { "port": 5174, "devCommand": "npm run dev:site" },
|
|
67
|
+
"microservice": { "port": 4000, "devCommand": "npm run dev:service" }
|
|
68
|
+
},
|
|
69
|
+
"products": [
|
|
70
|
+
{
|
|
71
|
+
"appId": "powch",
|
|
72
|
+
"localPath": "DeSciX_Powch",
|
|
73
|
+
"site": { "port": 5175, "devCommand": "npm run dev:site" },
|
|
74
|
+
"microservice": { "port": 3003, "devCommand": "npm run dev:service" }
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`env.platform.microservice.port` is the Core API port. CLI derives `apiUrl = https://localhost:{port}` automatically.
|
|
82
|
+
|
|
83
|
+
#### App Dev format (V2.0 — generated by `descix init`)
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"version": "2.0",
|
|
88
|
+
"communities": {
|
|
89
|
+
"descix": {
|
|
90
|
+
"apps": {
|
|
91
|
+
"myapp": {
|
|
92
|
+
"localPath": "myapp",
|
|
93
|
+
"kbId": "General",
|
|
94
|
+
"site": { "port": 3000, "devCommand": "npm run dev" },
|
|
95
|
+
"service": { "port": 4001, "devCommand": "npm run start" }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"driveConfig": { "base_folder_id": "..." }
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 3.2. Proxy Logic (createViteProxyConfig)
|
|
105
|
+
The gateway uses `createViteProxyConfig` from `@descix/app-sdk/dev` to generate Vite proxy rules from `workspace.json`:
|
|
106
|
+
|
|
107
|
+
- **`/apifront`, `/api`, `/mcp`** → `env.platform.microservice.port` (DEV) or `https://descix.net`
|
|
108
|
+
- **`/powch`** → `env.products.find(p => p.appId === 'powch').site.port`
|
|
109
|
+
- **`/s/{community}/{appId}`** → `localhost:{microservice.port}` for each product in `workspace.json`
|
|
110
|
+
- **`/Community/{c}/Apps/{a}/site`** → `localhost:{site.port}` for local app dev
|
|
111
|
+
- **`/Community`** → GCS fallback
|
|
112
|
+
- **`/.proxy/gcs_media`** → GCS media proxy
|
|
113
|
+
|
|
114
|
+
## 4. Scenarios
|
|
115
|
+
|
|
116
|
+
### Scenario 1: Platform Dev ("Dogfooding")
|
|
117
|
+
* **User**: Core Team.
|
|
118
|
+
* **Setup**: Full repo checkout. Run `npm run dev:serve` from `DeSciX_PWA` plus Core, Powch PWA, Powch service. `workspace.json` maps Powch and apps to local ports.
|
|
119
|
+
* **Result**: The gateway serves the PWA at `/` and routes `/apifront` to Core, `/powch` to Powch PWA, `/s/*` to microservices. Local app sites are proxied via `/Community/{c}/Apps/{a}/site`.
|
|
120
|
+
|
|
121
|
+
### Scenario 2: End-User Dev (Hybrid)
|
|
122
|
+
* **User**: App Developer.
|
|
123
|
+
* **Setup**: `descix init` creates a `workspace.json` mapping *only* their specific app.
|
|
124
|
+
* **Result**:
|
|
125
|
+
* `/apps/my-community/my-app` -> **Localhost** (User's Dev Server).
|
|
126
|
+
* `/apps/other-app` -> **Production** (Live GCS).
|
|
127
|
+
* `/api/core` -> **Production** (Live API).
|
|
128
|
+
* `/*` (PWA Shell) -> **Production** (Live PWA).
|
|
129
|
+
|
|
130
|
+
### Scenario 3: Production
|
|
131
|
+
* **User**: End User.
|
|
132
|
+
* **Setup**: No Local Proxy.
|
|
133
|
+
* **Result**: Traffic hits the Cloud Load Balancer, which applies the same routing rules to direct traffic to GCS buckets and Kubernetes services.
|
|
134
|
+
|
|
135
|
+
## 5. Client-Side Implications
|
|
136
|
+
|
|
137
|
+
* **"Dumb" Client**: The PWA Client (`AppData.js`) no longer needs complex logic to rewrite GCS URLs. It simply constructs the canonical path: `/apps/{community}/{app_id}/index.html`.
|
|
138
|
+
* **Embedded Mode**: For embedded scenarios (e.g., iframes), we may retain some legacy rewrite logic as a fallback, but the primary development flow relies on the Proxy.
|