@mandujs/core 0.54.9 → 0.54.11

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 (63) hide show
  1. package/package.json +1 -1
  2. package/scripts/postinstall-lock.ts +153 -153
  3. package/src/a11y/run-audit.ts +15 -15
  4. package/src/agent/context.ts +535 -535
  5. package/src/agent/index.ts +6 -6
  6. package/src/agent/plan.ts +282 -282
  7. package/src/agent/repair.ts +171 -171
  8. package/src/agent/sync.ts +200 -200
  9. package/src/brain/doctor/analyzer.ts +7 -7
  10. package/src/bundler/__tests__/build-runner.ts +81 -62
  11. package/src/bundler/__tests__/cold-start.test.ts +60 -60
  12. package/src/bundler/__tests__/css.test.ts +20 -20
  13. package/src/bundler/analyzer.ts +15 -15
  14. package/src/bundler/build.test.ts +120 -88
  15. package/src/bundler/build.ts +511 -511
  16. package/src/bundler/css.ts +42 -42
  17. package/src/bundler/manifest-schema.ts +21 -21
  18. package/src/bundler/plugins/__tests__/block-generated-imports.test.ts +13 -13
  19. package/src/bundler/plugins/block-generated-imports.ts +13 -13
  20. package/src/bundler/types.ts +31 -31
  21. package/src/client/island.ts +79 -79
  22. package/src/config/validate.ts +1 -1
  23. package/src/deploy/inference/context.ts +82 -82
  24. package/src/devtools/client/components/panel/islands-panel.tsx +16 -16
  25. package/src/devtools/client/components/panel/panel-container.tsx +1 -1
  26. package/src/filling/context.ts +17 -17
  27. package/src/generator/generate.ts +30 -30
  28. package/src/generator/index.ts +3 -3
  29. package/src/generator/templates.test.ts +66 -65
  30. package/src/generator/templates.ts +210 -210
  31. package/src/guard/check.ts +9 -9
  32. package/src/guard/config-guard.ts +13 -13
  33. package/src/guard/fs-routes-policy.ts +51 -51
  34. package/src/guard/index.ts +11 -11
  35. package/src/index.ts +3 -3
  36. package/src/kitchen/api/file-api.ts +11 -11
  37. package/src/report/index.ts +1 -1
  38. package/src/resource/__tests__/generator.test.ts +6 -6
  39. package/src/resource/__tests__/schema.test.ts +14 -14
  40. package/src/resource/ddl/__tests__/emit.test.ts +165 -165
  41. package/src/resource/ddl/emit.ts +146 -146
  42. package/src/resource/generator-schema.ts +11 -11
  43. package/src/resource/generators/slot.ts +72 -72
  44. package/src/resource/schema.ts +21 -21
  45. package/src/router/client-entry.test.ts +192 -89
  46. package/src/router/client-entry.ts +516 -400
  47. package/src/router/fs-routes.ts +16 -16
  48. package/src/router/fs-scanner.ts +16 -27
  49. package/src/runtime/__tests__/devtools-adapter.test.ts +68 -68
  50. package/src/runtime/__tests__/observability-lifecycle.test.ts +103 -103
  51. package/src/runtime/__tests__/page-render-response.test.ts +103 -103
  52. package/src/runtime/__tests__/request-middleware.test.ts +70 -70
  53. package/src/runtime/devtools-adapter.ts +68 -68
  54. package/src/runtime/escape.ts +34 -34
  55. package/src/runtime/observability-lifecycle.ts +290 -290
  56. package/src/runtime/page-render-response.ts +106 -106
  57. package/src/runtime/request-middleware.ts +31 -31
  58. package/src/runtime/server.ts +243 -243
  59. package/src/runtime/ssr.ts +59 -59
  60. package/src/runtime/static-files.ts +289 -289
  61. package/src/runtime/streaming-ssr.ts +22 -22
  62. package/src/watcher/__tests__/watcher.test.ts +59 -59
  63. package/src/watcher/watcher.ts +61 -61
@@ -1,171 +1,171 @@
1
- import fs from "fs/promises";
2
- import path from "path";
3
- import type {
4
- AgentDiagnostic,
5
- AgentRepairAction,
6
- AgentRepairReport,
7
- AgentVerifyReport,
8
- BuildAgentRepairOptions,
9
- } from "./types";
10
-
11
- const DEFAULT_VERIFY_INPUT = ".mandu/agent-verify.json";
12
-
13
- function resolveInside(rootDir: string, value: string): string {
14
- const root = path.resolve(rootDir);
15
- const resolved = path.resolve(root, value);
16
- if (resolved !== root && !resolved.startsWith(root + path.sep)) {
17
- throw new Error("repair input must stay inside the project root");
18
- }
19
- return resolved;
20
- }
21
-
22
- async function readVerifyReport(filePath: string): Promise<AgentVerifyReport | null> {
23
- try {
24
- const raw = await fs.readFile(filePath, "utf8");
25
- const parsed = JSON.parse(raw) as AgentVerifyReport;
26
- if (parsed?.framework !== "mandu" || !Array.isArray(parsed.diagnostics)) {
27
- return null;
28
- }
29
- return parsed;
30
- } catch {
31
- return null;
32
- }
33
- }
34
-
35
- function actionForDiagnostic(diagnostic: AgentDiagnostic): AgentRepairAction {
36
- const fix = diagnostic.suggestedFix;
37
- if (!fix) {
38
- return {
39
- diagnosticCode: diagnostic.code,
40
- kind: "manual",
41
- description: `Inspect ${diagnostic.code}: ${diagnostic.cause}`,
42
- safeToApply: false,
43
- applied: false,
44
- };
45
- }
46
-
47
- if (fix.type === "run_command" && fix.command) {
48
- return {
49
- diagnosticCode: diagnostic.code,
50
- kind: "run_command",
51
- description: fix.description,
52
- command: fix.command,
53
- safeToApply: false,
54
- applied: false,
55
- };
56
- }
57
-
58
- if ((fix.type === "create_file" || fix.type === "modify_file") && fix.path) {
59
- return {
60
- diagnosticCode: diagnostic.code,
61
- kind: "patch",
62
- description: fix.description,
63
- file: fix.path,
64
- // Current diagnostic shape does not carry patch content. Keep this
65
- // conservative until a typed patch payload exists.
66
- safeToApply: false,
67
- applied: false,
68
- };
69
- }
70
-
71
- return {
72
- diagnosticCode: diagnostic.code,
73
- kind: "manual",
74
- description: fix.description,
75
- safeToApply: false,
76
- applied: false,
77
- };
78
- }
79
-
80
- export function agentRepairReportPath(rootDir: string): string {
81
- return path.join(rootDir, ".mandu", "agent-repair.json");
82
- }
83
-
84
- export async function buildAgentRepairReport(
85
- rootDir: string = process.cwd(),
86
- options: BuildAgentRepairOptions = {},
87
- ): Promise<AgentRepairReport> {
88
- const root = path.resolve(rootDir);
89
- const sourceRel = options.from ?? DEFAULT_VERIFY_INPUT;
90
- const sourcePath = resolveInside(root, sourceRel);
91
- const warnings: string[] = [];
92
- const report = await readVerifyReport(sourcePath);
93
-
94
- if (!report) {
95
- return {
96
- schemaVersion: 1,
97
- framework: "mandu",
98
- generatedAt: new Date().toISOString(),
99
- ok: false,
100
- status: "input_missing",
101
- sourceReport: sourceRel,
102
- diagnostics: [
103
- {
104
- code: "MANDU_REPAIR_INPUT_MISSING",
105
- severity: "error",
106
- title: "Agent verify report missing",
107
- cause: `Could not read ${sourceRel}.`,
108
- suggestedFix: {
109
- type: "run_command",
110
- command: "mandu agent verify --changed --json --write",
111
- description: "Generate a fresh agent verify report first.",
112
- },
113
- docs: "docs/plans/20_agent_surface_consolidation_plan.md",
114
- repairable: true,
115
- source: "agent.repair",
116
- },
117
- ],
118
- actions: [
119
- {
120
- diagnosticCode: "MANDU_REPAIR_INPUT_MISSING",
121
- kind: "run_command",
122
- description: "Generate a fresh agent verify report first.",
123
- command: "mandu agent verify --changed --json --write",
124
- safeToApply: false,
125
- applied: false,
126
- },
127
- ],
128
- appliedActions: [],
129
- warnings: [],
130
- nextVerifyCommand: "mandu agent verify --changed --json --write",
131
- };
132
- }
133
-
134
- const diagnostics = report.diagnostics;
135
- const actions = diagnostics.map(actionForDiagnostic);
136
- const appliedActions: AgentRepairAction[] = [];
137
-
138
- if (options.apply) {
139
- const safePatchActions = actions.filter((action) => action.kind === "patch" && action.safeToApply);
140
- if (safePatchActions.length === 0) {
141
- warnings.push("No safe file patch candidates were available to apply.");
142
- }
143
- // Future extension: apply typed patch payloads here. Command execution is
144
- // intentionally never auto-applied by repair.
145
- }
146
-
147
- return {
148
- schemaVersion: 1,
149
- framework: "mandu",
150
- generatedAt: new Date().toISOString(),
151
- ok: true,
152
- status: diagnostics.length === 0 ? "nothing_to_repair" : "ready",
153
- sourceReport: sourceRel,
154
- diagnostics,
155
- actions,
156
- appliedActions,
157
- warnings,
158
- nextVerifyCommand: "mandu agent verify --changed --json --write",
159
- };
160
- }
161
-
162
- export async function writeAgentRepairReport(
163
- rootDir: string = process.cwd(),
164
- report?: AgentRepairReport,
165
- ): Promise<{ path: string; report: AgentRepairReport }> {
166
- const value = report ?? await buildAgentRepairReport(rootDir);
167
- const outPath = agentRepairReportPath(rootDir);
168
- await fs.mkdir(path.dirname(outPath), { recursive: true });
169
- await fs.writeFile(outPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
170
- return { path: outPath, report: value };
171
- }
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+ import type {
4
+ AgentDiagnostic,
5
+ AgentRepairAction,
6
+ AgentRepairReport,
7
+ AgentVerifyReport,
8
+ BuildAgentRepairOptions,
9
+ } from "./types";
10
+
11
+ const DEFAULT_VERIFY_INPUT = ".mandu/agent-verify.json";
12
+
13
+ function resolveInside(rootDir: string, value: string): string {
14
+ const root = path.resolve(rootDir);
15
+ const resolved = path.resolve(root, value);
16
+ if (resolved !== root && !resolved.startsWith(root + path.sep)) {
17
+ throw new Error("repair input must stay inside the project root");
18
+ }
19
+ return resolved;
20
+ }
21
+
22
+ async function readVerifyReport(filePath: string): Promise<AgentVerifyReport | null> {
23
+ try {
24
+ const raw = await fs.readFile(filePath, "utf8");
25
+ const parsed = JSON.parse(raw) as AgentVerifyReport;
26
+ if (parsed?.framework !== "mandu" || !Array.isArray(parsed.diagnostics)) {
27
+ return null;
28
+ }
29
+ return parsed;
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ function actionForDiagnostic(diagnostic: AgentDiagnostic): AgentRepairAction {
36
+ const fix = diagnostic.suggestedFix;
37
+ if (!fix) {
38
+ return {
39
+ diagnosticCode: diagnostic.code,
40
+ kind: "manual",
41
+ description: `Inspect ${diagnostic.code}: ${diagnostic.cause}`,
42
+ safeToApply: false,
43
+ applied: false,
44
+ };
45
+ }
46
+
47
+ if (fix.type === "run_command" && fix.command) {
48
+ return {
49
+ diagnosticCode: diagnostic.code,
50
+ kind: "run_command",
51
+ description: fix.description,
52
+ command: fix.command,
53
+ safeToApply: false,
54
+ applied: false,
55
+ };
56
+ }
57
+
58
+ if ((fix.type === "create_file" || fix.type === "modify_file") && fix.path) {
59
+ return {
60
+ diagnosticCode: diagnostic.code,
61
+ kind: "patch",
62
+ description: fix.description,
63
+ file: fix.path,
64
+ // Current diagnostic shape does not carry patch content. Keep this
65
+ // conservative until a typed patch payload exists.
66
+ safeToApply: false,
67
+ applied: false,
68
+ };
69
+ }
70
+
71
+ return {
72
+ diagnosticCode: diagnostic.code,
73
+ kind: "manual",
74
+ description: fix.description,
75
+ safeToApply: false,
76
+ applied: false,
77
+ };
78
+ }
79
+
80
+ export function agentRepairReportPath(rootDir: string): string {
81
+ return path.join(rootDir, ".mandu", "agent-repair.json");
82
+ }
83
+
84
+ export async function buildAgentRepairReport(
85
+ rootDir: string = process.cwd(),
86
+ options: BuildAgentRepairOptions = {},
87
+ ): Promise<AgentRepairReport> {
88
+ const root = path.resolve(rootDir);
89
+ const sourceRel = options.from ?? DEFAULT_VERIFY_INPUT;
90
+ const sourcePath = resolveInside(root, sourceRel);
91
+ const warnings: string[] = [];
92
+ const report = await readVerifyReport(sourcePath);
93
+
94
+ if (!report) {
95
+ return {
96
+ schemaVersion: 1,
97
+ framework: "mandu",
98
+ generatedAt: new Date().toISOString(),
99
+ ok: false,
100
+ status: "input_missing",
101
+ sourceReport: sourceRel,
102
+ diagnostics: [
103
+ {
104
+ code: "MANDU_REPAIR_INPUT_MISSING",
105
+ severity: "error",
106
+ title: "Agent verify report missing",
107
+ cause: `Could not read ${sourceRel}.`,
108
+ suggestedFix: {
109
+ type: "run_command",
110
+ command: "mandu agent verify --changed --json --write",
111
+ description: "Generate a fresh agent verify report first.",
112
+ },
113
+ docs: "docs/plans/20_agent_surface_consolidation_plan.md",
114
+ repairable: true,
115
+ source: "agent.repair",
116
+ },
117
+ ],
118
+ actions: [
119
+ {
120
+ diagnosticCode: "MANDU_REPAIR_INPUT_MISSING",
121
+ kind: "run_command",
122
+ description: "Generate a fresh agent verify report first.",
123
+ command: "mandu agent verify --changed --json --write",
124
+ safeToApply: false,
125
+ applied: false,
126
+ },
127
+ ],
128
+ appliedActions: [],
129
+ warnings: [],
130
+ nextVerifyCommand: "mandu agent verify --changed --json --write",
131
+ };
132
+ }
133
+
134
+ const diagnostics = report.diagnostics;
135
+ const actions = diagnostics.map(actionForDiagnostic);
136
+ const appliedActions: AgentRepairAction[] = [];
137
+
138
+ if (options.apply) {
139
+ const safePatchActions = actions.filter((action) => action.kind === "patch" && action.safeToApply);
140
+ if (safePatchActions.length === 0) {
141
+ warnings.push("No safe file patch candidates were available to apply.");
142
+ }
143
+ // Future extension: apply typed patch payloads here. Command execution is
144
+ // intentionally never auto-applied by repair.
145
+ }
146
+
147
+ return {
148
+ schemaVersion: 1,
149
+ framework: "mandu",
150
+ generatedAt: new Date().toISOString(),
151
+ ok: true,
152
+ status: diagnostics.length === 0 ? "nothing_to_repair" : "ready",
153
+ sourceReport: sourceRel,
154
+ diagnostics,
155
+ actions,
156
+ appliedActions,
157
+ warnings,
158
+ nextVerifyCommand: "mandu agent verify --changed --json --write",
159
+ };
160
+ }
161
+
162
+ export async function writeAgentRepairReport(
163
+ rootDir: string = process.cwd(),
164
+ report?: AgentRepairReport,
165
+ ): Promise<{ path: string; report: AgentRepairReport }> {
166
+ const value = report ?? await buildAgentRepairReport(rootDir);
167
+ const outPath = agentRepairReportPath(rootDir);
168
+ await fs.mkdir(path.dirname(outPath), { recursive: true });
169
+ await fs.writeFile(outPath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
170
+ return { path: outPath, report: value };
171
+ }