@decantr/cli 1.4.0 → 1.5.2

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.
@@ -0,0 +1,155 @@
1
+ // src/commands/heal.ts
2
+ import { readFileSync as readFileSync2, existsSync as existsSync2 } from "fs";
3
+ import { join as join2 } from "path";
4
+ import { validateEssence, evaluateGuard } from "@decantr/essence-spec";
5
+
6
+ // src/telemetry.ts
7
+ import { readFileSync, writeFileSync, existsSync } from "fs";
8
+ import { join } from "path";
9
+ var TELEMETRY_ENDPOINT = "https://api.decantr.ai/v1/telemetry/guard";
10
+ var TELEMETRY_TIMEOUT_MS = 3e3;
11
+ var DNA_RULES = /* @__PURE__ */ new Set(["style", "recipe", "density", "accessibility", "theme-mode"]);
12
+ async function sendGuardMetrics(metrics) {
13
+ try {
14
+ const controller = new AbortController();
15
+ const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
16
+ await fetch(TELEMETRY_ENDPOINT, {
17
+ method: "POST",
18
+ headers: { "Content-Type": "application/json" },
19
+ body: JSON.stringify(metrics),
20
+ signal: controller.signal
21
+ });
22
+ clearTimeout(timer);
23
+ } catch {
24
+ }
25
+ }
26
+ function isOptedIn(projectRoot) {
27
+ const projectJsonPath = join(projectRoot, ".decantr", "project.json");
28
+ if (!existsSync(projectJsonPath)) return false;
29
+ try {
30
+ const data = JSON.parse(readFileSync(projectJsonPath, "utf-8"));
31
+ return data.telemetry === true;
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+ function optIn(projectRoot) {
37
+ const projectJsonPath = join(projectRoot, ".decantr", "project.json");
38
+ let data = {};
39
+ if (existsSync(projectJsonPath)) {
40
+ try {
41
+ data = JSON.parse(readFileSync(projectJsonPath, "utf-8"));
42
+ } catch {
43
+ }
44
+ }
45
+ data.telemetry = true;
46
+ writeFileSync(projectJsonPath, JSON.stringify(data, null, 2) + "\n", "utf-8");
47
+ }
48
+ function collectMetrics(essence, issues) {
49
+ const dna = essence.dna ?? {};
50
+ const blueprint = essence.blueprint ?? {};
51
+ const meta = essence.meta ?? {};
52
+ const guard = meta.guard ?? {};
53
+ const theme = dna.theme ?? {};
54
+ const sections = blueprint.sections ?? [];
55
+ const routes = blueprint.routes ?? {};
56
+ const byRule = {};
57
+ let dnaCount = 0;
58
+ let blueprintCount = 0;
59
+ for (const issue of issues) {
60
+ byRule[issue.rule] = (byRule[issue.rule] ?? 0) + 1;
61
+ if (DNA_RULES.has(issue.rule)) {
62
+ dnaCount++;
63
+ } else {
64
+ blueprintCount++;
65
+ }
66
+ }
67
+ return {
68
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
69
+ cli_version: "1.5.1",
70
+ essence_version: essence.version ?? "unknown",
71
+ guard_mode: guard.mode ?? "unknown",
72
+ violations: {
73
+ dna: dnaCount,
74
+ blueprint: blueprintCount,
75
+ by_rule: byRule
76
+ },
77
+ resolution_rate: 0,
78
+ sections_count: sections.length,
79
+ routes_count: Object.keys(routes).length,
80
+ theme: theme.style ?? "unknown"
81
+ };
82
+ }
83
+
84
+ // src/commands/heal.ts
85
+ var GREEN = "\x1B[32m";
86
+ var RED = "\x1B[31m";
87
+ var YELLOW = "\x1B[33m";
88
+ var CYAN = "\x1B[36m";
89
+ var RESET = "\x1B[0m";
90
+ var DIM = "\x1B[2m";
91
+ async function cmdHeal(projectRoot = process.cwd(), options = {}) {
92
+ const essencePath = join2(projectRoot, "decantr.essence.json");
93
+ if (!existsSync2(essencePath)) {
94
+ console.error("No decantr.essence.json found. Run `decantr init` first.");
95
+ process.exitCode = 1;
96
+ return;
97
+ }
98
+ const essence = JSON.parse(readFileSync2(essencePath, "utf-8"));
99
+ console.log("Scanning for issues...\n");
100
+ const issues = [];
101
+ const validation = validateEssence(essence);
102
+ if (!validation.valid) {
103
+ for (const err of validation.errors) {
104
+ issues.push({
105
+ type: "error",
106
+ rule: "schema",
107
+ message: err
108
+ });
109
+ }
110
+ }
111
+ try {
112
+ const violations = evaluateGuard(essence, { themeRegistry: /* @__PURE__ */ new Map(), patternRegistry: /* @__PURE__ */ new Map() });
113
+ for (const v of violations) {
114
+ issues.push({
115
+ type: v.severity === "error" ? "error" : "warning",
116
+ rule: v.rule,
117
+ message: v.message,
118
+ suggestion: v.suggestion
119
+ });
120
+ }
121
+ } catch {
122
+ }
123
+ if (issues.length === 0) {
124
+ console.log(`${GREEN}No issues found. Project is healthy.${RESET}`);
125
+ await maybeSendTelemetry(projectRoot, essence, issues, options);
126
+ return;
127
+ }
128
+ console.log(`Found ${issues.length} issue(s):
129
+ `);
130
+ for (const issue of issues) {
131
+ const icon = issue.type === "error" ? `${RED}x${RESET}` : `${YELLOW}!${RESET}`;
132
+ console.log(`${icon} [${issue.rule}] ${issue.message}`);
133
+ if (issue.suggestion) {
134
+ console.log(` ${DIM}Suggestion: ${issue.suggestion}${RESET}`);
135
+ }
136
+ }
137
+ console.log(`
138
+ ${YELLOW}Manual fixes required. Review the issues above.${RESET}`);
139
+ await maybeSendTelemetry(projectRoot, essence, issues, options);
140
+ }
141
+ async function maybeSendTelemetry(projectRoot, essence, issues, options) {
142
+ if (options.telemetry && !isOptedIn(projectRoot)) {
143
+ optIn(projectRoot);
144
+ console.log(`
145
+ ${CYAN}Telemetry enabled.${RESET} Anonymous guard metrics will be sent on future checks.`);
146
+ console.log(`${DIM}Set "telemetry": false in .decantr/project.json to opt out.${RESET}`);
147
+ }
148
+ if (isOptedIn(projectRoot)) {
149
+ const metrics = collectMetrics(essence, issues);
150
+ sendGuardMetrics(metrics);
151
+ }
152
+ }
153
+ export {
154
+ cmdHeal
155
+ };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import "./chunk-OTVIAUQG.js";
2
- import "./chunk-ZQ5FTYKG.js";
1
+ import "./chunk-66RIAQLH.js";
2
+ import "./chunk-6RJSFLT4.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  RegistryClient,
3
3
  refreshDerivedFiles
4
- } from "./chunk-ZQ5FTYKG.js";
4
+ } from "./chunk-6RJSFLT4.js";
5
5
 
6
6
  // src/commands/upgrade.ts
7
7
  import { readFileSync, writeFileSync, existsSync } from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decantr/cli",
3
- "version": "1.4.0",
3
+ "version": "1.5.2",
4
4
  "description": "Decantr CLI — search the registry, validate essence files, and access design intelligence from the terminal",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,13 +22,13 @@
22
22
  "publishConfig": {
23
23
  "access": "public"
24
24
  },
25
- "dependencies": {
26
- "@decantr/essence-spec": "1.0.0-beta.7",
27
- "@decantr/registry": "1.0.0-beta.7"
28
- },
29
25
  "scripts": {
30
26
  "build": "tsup",
31
27
  "test": "vitest run",
32
28
  "test:watch": "vitest"
29
+ },
30
+ "dependencies": {
31
+ "@decantr/essence-spec": "workspace:*",
32
+ "@decantr/registry": "workspace:*"
33
33
  }
34
- }
34
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Decantr AI
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,60 +0,0 @@
1
- // src/commands/heal.ts
2
- import { readFileSync, existsSync } from "fs";
3
- import { join } from "path";
4
- import { validateEssence, evaluateGuard } from "@decantr/essence-spec";
5
- var GREEN = "\x1B[32m";
6
- var RED = "\x1B[31m";
7
- var YELLOW = "\x1B[33m";
8
- var RESET = "\x1B[0m";
9
- var DIM = "\x1B[2m";
10
- async function cmdHeal(projectRoot = process.cwd()) {
11
- const essencePath = join(projectRoot, "decantr.essence.json");
12
- if (!existsSync(essencePath)) {
13
- console.error("No decantr.essence.json found. Run `decantr init` first.");
14
- process.exitCode = 1;
15
- return;
16
- }
17
- const essence = JSON.parse(readFileSync(essencePath, "utf-8"));
18
- console.log("Scanning for issues...\n");
19
- const issues = [];
20
- const validation = validateEssence(essence);
21
- if (!validation.valid) {
22
- for (const err of validation.errors) {
23
- issues.push({
24
- type: "error",
25
- rule: "schema",
26
- message: err
27
- });
28
- }
29
- }
30
- try {
31
- const violations = evaluateGuard(essence, { themeRegistry: /* @__PURE__ */ new Map(), patternRegistry: /* @__PURE__ */ new Map() });
32
- for (const v of violations) {
33
- issues.push({
34
- type: v.severity === "error" ? "error" : "warning",
35
- rule: v.rule,
36
- message: v.message,
37
- suggestion: v.suggestion
38
- });
39
- }
40
- } catch {
41
- }
42
- if (issues.length === 0) {
43
- console.log(`${GREEN}No issues found. Project is healthy.${RESET}`);
44
- return;
45
- }
46
- console.log(`Found ${issues.length} issue(s):
47
- `);
48
- for (const issue of issues) {
49
- const icon = issue.type === "error" ? `${RED}x${RESET}` : `${YELLOW}!${RESET}`;
50
- console.log(`${icon} [${issue.rule}] ${issue.message}`);
51
- if (issue.suggestion) {
52
- console.log(` ${DIM}Suggestion: ${issue.suggestion}${RESET}`);
53
- }
54
- }
55
- console.log(`
56
- ${YELLOW}Manual fixes required. Review the issues above.${RESET}`);
57
- }
58
- export {
59
- cmdHeal
60
- };