@descix/cli 1.0.1 → 1.0.4
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/LICENSE.md +671 -0
- package/README.md +43 -4
- package/agent-assets/guides/README.md +2 -2
- package/agent-assets/guides/dynamic-site-pattern.md +29 -14
- package/agent-assets/guides/knowledge-only-pattern.md +5 -5
- package/agent-assets/guides/microservice-pattern.md +48 -4
- package/agent-assets/guides/static-site-pattern.md +8 -0
- package/agent-assets/instructions/app-asset-validation.md +5 -5
- package/agent-assets/instructions/onboarding-flow.md +4 -4
- package/agent-assets/instructions/standard-folder-structure.md +20 -11
- package/agent-assets/reference/app-creation.md +42 -20
- package/agent-assets/reference/architecture.md +24 -22
- package/agent-assets/reference/local-dev.md +230 -67
- package/agent-assets/reference/mcp-integration.md +21 -15
- package/agent-assets/reference/platform-api-consumer.md +244 -0
- package/agent-assets/reference/workspace-config.md +7 -7
- package/agent-assets/rules/descix_mcp.template.mdc +8 -8
- package/bin/descix.js +2559 -1435
- package/bin/kb-deny-lint.mjs +91 -0
- package/bin/mcp-server.js +175 -91
- package/lib/agent-files.js +37 -25
- package/lib/api-client.js +223 -56
- package/lib/auth-guard.js +13 -3
- package/lib/chat-session.js +187 -0
- package/lib/cli-version.js +59 -0
- package/lib/commands/airdrop.js +251 -0
- package/lib/commands/auth.js +254 -72
- package/lib/commands/briefer/errors.js +88 -0
- package/lib/commands/briefer/index.js +319 -0
- package/lib/commands/briefer/sources/canonical-sources.js +129 -0
- package/lib/commands/briefer/sources/entitlements.js +220 -0
- package/lib/commands/briefer/sources/environments.js +205 -0
- package/lib/commands/briefer/sources/identifiers.js +214 -0
- package/lib/commands/briefer/sources/microservice-deploy.js +267 -0
- package/lib/commands/briefer/sources/routing.js +275 -0
- package/lib/commands/briefer/sources/what-is-not.js +223 -0
- package/lib/commands/briefer/stitcher.js +134 -0
- package/lib/commands/briefer/util/source-reader.js +502 -0
- package/lib/commands/config.js +210 -90
- package/lib/commands/corpus.js +978 -0
- package/lib/commands/credits.js +122 -0
- package/lib/commands/health.js +627 -0
- package/lib/commands/kb-list-render.js +32 -0
- package/lib/commands/kb.js +190 -413
- package/lib/commands/mcp.js +5 -5
- package/lib/commands/microservice-restart.js +359 -0
- package/lib/commands/model-config.js +313 -0
- package/lib/commands/retired-kb-sync.js +134 -0
- package/lib/commands/serve.js +26 -1
- package/lib/commands/status.js +23 -51
- package/lib/commands/update.js +36 -107
- package/lib/core/Chunker.js +491 -17
- package/lib/core/CorpusDenyLint.js +326 -0
- package/lib/core/CorpusWalker.js +357 -0
- package/lib/core/Hydrator.js +75 -29
- package/lib/core/ManifestLoader.js +533 -0
- package/lib/core/SiteWalker.js +218 -0
- package/lib/core/Syncer.js +163 -11
- package/lib/diagnostic-log.js +41 -0
- package/lib/environment-report.js +100 -0
- package/lib/global-config.js +4 -1
- package/lib/oauth-client.js +164 -0
- package/lib/origin.js +143 -0
- package/lib/service-api-client.js +95 -0
- package/lib/wallet-environment.js +49 -0
- package/lib/wallet-file.js +16 -2
- package/lib/wizard/setup.js +10 -9
- package/lib/workspace-config.js +380 -235
- package/lib/workspace-identity.js +92 -0
- package/lib/workspace-utils.js +41 -61
- package/package.json +19 -6
- package/templates/agent-claude.md +157 -9
- package/templates/agent-cline.md +68 -8
- package/templates/agent-copilot.md +68 -8
- package/templates/agent-cursor.md +68 -8
- package/templates/alignment-schema.json +20 -0
- package/templates/cloud-brain-hook.sh +20 -0
- package/templates/drive/README.md +1 -1
- package/templates/drive_templates/README.md +2 -2
- package/templates/scaffolds/README.md +6 -10
- package/templates/scaffolds/microservice/SERVICE_README_sdk.md +104 -149
- package/templates/scaffolds/microservice/app.js +51 -10
- package/templates/scaffolds/microservice/app.yaml +2 -2
- package/templates/scaffolds/microservice/defaults-config-dev.json +4 -0
- package/templates/scaffolds/microservice/dev-overrides.example.json +5 -0
- package/templates/scaffolds/microservice/manifest.json +0 -1
- package/templates/scaffolds/microservice/package.json +3 -3
- package/templates/scaffolds/microservice/scripts/register.js +56 -41
- package/templates/scaffolds/microservice/services/mcpClient.js +55 -65
- package/templates/scaffolds/microservice/services/utils.js +20 -238
- package/templates/scaffolds/microservice/templates/SERVICE_README_TEMPLATE.md +24 -0
- package/lib/commands/app-wizard.js +0 -627
- package/lib/commands/folder.js +0 -291
- package/lib/core/PathContext.js +0 -335
- package/templates/scaffolds/microservice/dev-overrides.json.example +0 -5
- package/templates/scaffolds/site/DeSciXAppSDK.js +0 -62
- package/templates/scaffolds/site/README.md +0 -51
- package/templates/scaffolds/site/app.js +0 -22
- package/templates/scaffolds/site/index.html +0 -42
- package/templates/scaffolds/site/styles.css +0 -123
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credits Commands — platform-wide USD AI credits (WS-HEADLESS-MVP-A2, CEO-D-2026-07-01 D2).
|
|
3
|
+
*
|
|
4
|
+
* `descix credits balance | history | buy | grant | refund` over the backend commands
|
|
5
|
+
* get_credit_balance / get_credit_history / create_stripe_checkout_session
|
|
6
|
+
* (purchase_type:'ai_credits') / grant_credits / refund_credits.
|
|
7
|
+
*
|
|
8
|
+
* Credits are the metered AI-consumption balance (RAG chat / agents debit it per call).
|
|
9
|
+
* They are NOT community tokens — token purchases live under `descix buy`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import chalk from 'chalk';
|
|
13
|
+
import { DeSciXApiClient } from '../api-client.js';
|
|
14
|
+
import { requireAuth } from '../auth-guard.js';
|
|
15
|
+
|
|
16
|
+
function unwrap(response) {
|
|
17
|
+
return response?.message || response;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Show the caller's AI-credits balance. */
|
|
21
|
+
export async function showBalance() {
|
|
22
|
+
const apiClient = new DeSciXApiClient();
|
|
23
|
+
await requireAuth(apiClient);
|
|
24
|
+
const result = unwrap(await apiClient.invoke('get_credit_balance', {}));
|
|
25
|
+
console.log(chalk.bold('\nAI Credits Balance:'));
|
|
26
|
+
console.log(` Balance: ${chalk.green(`$${Number(result.usd_balance).toFixed(2)}`)}`);
|
|
27
|
+
console.log(` Lifetime purchased: $${Number(result.lifetime_purchased_usd).toFixed(2)}`);
|
|
28
|
+
console.log(` Lifetime granted: $${Number(result.lifetime_granted_usd).toFixed(2)}`);
|
|
29
|
+
console.log(` Lifetime used: $${Number(result.lifetime_debited_usd).toFixed(2)}`);
|
|
30
|
+
if (Number(result.usd_balance) <= 0) {
|
|
31
|
+
console.log(chalk.yellow(`\n Balance empty — metered AI calls will be rejected.`));
|
|
32
|
+
console.log(` Buy credits: ${chalk.cyan('descix credits buy --usd <amount>')}`);
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Show the caller's credit ledger history (newest first). */
|
|
38
|
+
export async function showHistory(options = {}) {
|
|
39
|
+
const apiClient = new DeSciXApiClient();
|
|
40
|
+
await requireAuth(apiClient);
|
|
41
|
+
const result = unwrap(await apiClient.invoke('get_credit_history', {
|
|
42
|
+
limit: options.limit ? parseInt(options.limit, 10) : undefined,
|
|
43
|
+
}));
|
|
44
|
+
const entries = result.entries || [];
|
|
45
|
+
console.log(chalk.bold(`\nCredit Ledger (${entries.length} entries, newest first):\n`));
|
|
46
|
+
if (entries.length === 0) {
|
|
47
|
+
console.log(chalk.dim(' (empty)'));
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
for (const e of entries) {
|
|
51
|
+
const sign = e.usd_delta >= 0 ? '+' : '';
|
|
52
|
+
const amountStr = `${sign}$${Number(e.usd_delta).toFixed(4)}`;
|
|
53
|
+
const amount = e.usd_delta >= 0 ? chalk.green(amountStr) : chalk.red(amountStr);
|
|
54
|
+
const ts = e.ts?._seconds ? new Date(e.ts._seconds * 1000).toISOString()
|
|
55
|
+
: (e.ts?.seconds ? new Date(e.ts.seconds * 1000).toISOString() : String(e.ts || ''));
|
|
56
|
+
let detail = '';
|
|
57
|
+
if (e.type === 'debit') {
|
|
58
|
+
detail = `${e.app_id || '?'} ${e.model_used || ''} in:${e.tokens_in ?? '?'} out:${e.tokens_out ?? '?'}`;
|
|
59
|
+
} else if (e.type === 'purchase') {
|
|
60
|
+
detail = `${e.source || ''} ${e.payment_ref || ''}`;
|
|
61
|
+
} else if (e.type === 'grant' || e.type === 'refund') {
|
|
62
|
+
detail = e.reason || '';
|
|
63
|
+
}
|
|
64
|
+
console.log(` ${ts} ${e.type.padEnd(12)} ${amount.padEnd(22)} bal $${Number(e.balance_after_usd).toFixed(4)} ${chalk.dim(detail)}`);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Start a Stripe checkout to buy AI credits. Prints the checkout URL. */
|
|
70
|
+
export async function buyCredits(options) {
|
|
71
|
+
const apiClient = new DeSciXApiClient();
|
|
72
|
+
await requireAuth(apiClient);
|
|
73
|
+
const usd = parseFloat(options.usd);
|
|
74
|
+
if (!Number.isFinite(usd) || usd <= 0) {
|
|
75
|
+
console.error(chalk.red('A positive --usd amount is required.'));
|
|
76
|
+
throw new Error('invalid --usd');
|
|
77
|
+
}
|
|
78
|
+
// success/cancel URLs: platform site (informational landing; settlement is webhook-driven).
|
|
79
|
+
// The landing page belongs to the SAME deployment the checkout session is created against.
|
|
80
|
+
// Hardcoding the production origin sent a DEV purchase's success/cancel links to prod.
|
|
81
|
+
const base = options.returnBase || apiClient.baseUrl;
|
|
82
|
+
const result = unwrap(await apiClient.invoke('create_stripe_checkout_session', {
|
|
83
|
+
amount_usd: usd,
|
|
84
|
+
purchase_type: 'ai_credits',
|
|
85
|
+
success_url: `${base}/?credits_purchase=success`,
|
|
86
|
+
cancel_url: `${base}/?credits_purchase=cancelled`,
|
|
87
|
+
}));
|
|
88
|
+
if (!result?.checkoutUrl) throw new Error('No checkout URL returned');
|
|
89
|
+
console.log(chalk.green('\n✓ Stripe checkout session created.'));
|
|
90
|
+
console.log(chalk.bold('\nComplete your purchase here:'));
|
|
91
|
+
console.log(` ${chalk.cyan(result.checkoutUrl)}`);
|
|
92
|
+
console.log(chalk.dim(`\n Session: ${result.sessionId}`));
|
|
93
|
+
console.log(chalk.dim(' Credits are added automatically once payment completes (webhook settlement).'));
|
|
94
|
+
console.log(` Check with: ${chalk.cyan('descix credits balance')}`);
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** ADMIN: grant credits to a user. (target_user_id — `user_id` is middleware-reserved.) */
|
|
99
|
+
export async function grantCredits(options) {
|
|
100
|
+
const apiClient = new DeSciXApiClient();
|
|
101
|
+
await requireAuth(apiClient);
|
|
102
|
+
const result = unwrap(await apiClient.invoke('grant_credits', {
|
|
103
|
+
target_user_id: options.user,
|
|
104
|
+
usd_amount: parseFloat(options.usd),
|
|
105
|
+
reason: options.reason,
|
|
106
|
+
}));
|
|
107
|
+
console.log(chalk.green(`\n✓ Granted $${Number(result.granted_usd).toFixed(2)} AI credits to ${result.target_user_id} (ledger ${result.entry_id}).`));
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** ADMIN: refund (remove) credits from a user. */
|
|
112
|
+
export async function refundCredits(options) {
|
|
113
|
+
const apiClient = new DeSciXApiClient();
|
|
114
|
+
await requireAuth(apiClient);
|
|
115
|
+
const result = unwrap(await apiClient.invoke('refund_credits', {
|
|
116
|
+
target_user_id: options.user,
|
|
117
|
+
usd_amount: parseFloat(options.usd),
|
|
118
|
+
reason: options.reason,
|
|
119
|
+
}));
|
|
120
|
+
console.log(chalk.green(`\n✓ Refunded $${Number(result.refunded_usd).toFixed(2)} AI credits from ${result.target_user_id} (ledger ${result.entry_id}).`));
|
|
121
|
+
return result;
|
|
122
|
+
}
|