@xano/developer-mcp 1.0.75 → 2.0.0-beta.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 (127) hide show
  1. package/README.md +104 -37
  2. package/dist/cli_docs/index.d.ts +13 -37
  3. package/dist/cli_docs/index.js +28 -39
  4. package/dist/cli_docs/topics/integration.js +1 -1
  5. package/dist/cli_docs/topics/workspace.js +1 -1
  6. package/dist/index.js +58 -55
  7. package/dist/lib.d.ts +3 -1
  8. package/dist/lib.js +1 -1
  9. package/dist/meta_api_docs/format.js +1 -1
  10. package/dist/meta_api_docs/index.d.ts +14 -42
  11. package/dist/meta_api_docs/index.js +34 -46
  12. package/dist/tools/cli_docs.d.ts +2 -3
  13. package/dist/tools/cli_docs.js +3 -5
  14. package/dist/tools/define_tool.d.ts +47 -0
  15. package/dist/tools/define_tool.js +36 -0
  16. package/dist/tools/index.d.ts +88 -221
  17. package/dist/tools/index.js +80 -109
  18. package/dist/tools/mcp_version.d.ts +4 -25
  19. package/dist/tools/mcp_version.js +12 -19
  20. package/dist/tools/meta_api_docs.d.ts +2 -3
  21. package/dist/tools/meta_api_docs.js +3 -5
  22. package/dist/tools/validate_xanoscript.d.ts +18 -65
  23. package/dist/tools/validate_xanoscript.js +56 -54
  24. package/dist/tools/xanoscript_docs.d.ts +25 -74
  25. package/dist/tools/xanoscript_docs.js +86 -83
  26. package/dist/xanoscript_docs/README.md +5 -5
  27. package/dist/xanoscript_docs/apis.md +2 -2
  28. package/dist/xanoscript_docs/database.md +1 -1
  29. package/dist/xanoscript_docs/essentials.md +6 -6
  30. package/dist/xanoscript_docs/functions.md +3 -3
  31. package/dist/xanoscript_docs/integrations.md +5 -5
  32. package/dist/xanoscript_docs/middleware.md +1 -1
  33. package/dist/xanoscript_docs/performance.md +4 -4
  34. package/dist/xanoscript_docs/realtime.md +2 -2
  35. package/dist/xanoscript_docs/security.md +1 -1
  36. package/dist/xanoscript_docs/survival.md +1 -1
  37. package/dist/xanoscript_docs/syntax/string-filters.md +1 -1
  38. package/dist/xanoscript_docs/syntax.md +9 -9
  39. package/dist/xanoscript_docs/tools.md +2 -2
  40. package/dist/xanoscript_docs/types.md +2 -2
  41. package/dist/xanoscript_docs/unit-testing.md +1 -1
  42. package/dist/xanoscript_docs/workflow-tests.md +1 -1
  43. package/dist/xanoscript_docs/working.md +4 -4
  44. package/package.json +5 -4
  45. package/dist/api_docs/format.d.ts +0 -5
  46. package/dist/api_docs/format.js +0 -171
  47. package/dist/api_docs/index.d.ts +0 -52
  48. package/dist/api_docs/index.js +0 -111
  49. package/dist/api_docs/topics/agent.d.ts +0 -2
  50. package/dist/api_docs/topics/agent.js +0 -142
  51. package/dist/api_docs/topics/api.d.ts +0 -2
  52. package/dist/api_docs/topics/api.js +0 -176
  53. package/dist/api_docs/topics/apigroup.d.ts +0 -2
  54. package/dist/api_docs/topics/apigroup.js +0 -124
  55. package/dist/api_docs/topics/authentication.d.ts +0 -2
  56. package/dist/api_docs/topics/authentication.js +0 -61
  57. package/dist/api_docs/topics/branch.d.ts +0 -2
  58. package/dist/api_docs/topics/branch.js +0 -73
  59. package/dist/api_docs/topics/file.d.ts +0 -2
  60. package/dist/api_docs/topics/file.js +0 -70
  61. package/dist/api_docs/topics/function.d.ts +0 -2
  62. package/dist/api_docs/topics/function.js +0 -164
  63. package/dist/api_docs/topics/history.d.ts +0 -2
  64. package/dist/api_docs/topics/history.js +0 -149
  65. package/dist/api_docs/topics/mcp_server.d.ts +0 -2
  66. package/dist/api_docs/topics/mcp_server.js +0 -139
  67. package/dist/api_docs/topics/middleware.d.ts +0 -2
  68. package/dist/api_docs/topics/middleware.js +0 -156
  69. package/dist/api_docs/topics/realtime.d.ts +0 -2
  70. package/dist/api_docs/topics/realtime.js +0 -112
  71. package/dist/api_docs/topics/start.d.ts +0 -2
  72. package/dist/api_docs/topics/start.js +0 -107
  73. package/dist/api_docs/topics/table.d.ts +0 -2
  74. package/dist/api_docs/topics/table.js +0 -195
  75. package/dist/api_docs/topics/task.d.ts +0 -2
  76. package/dist/api_docs/topics/task.js +0 -165
  77. package/dist/api_docs/topics/tool.d.ts +0 -2
  78. package/dist/api_docs/topics/tool.js +0 -150
  79. package/dist/api_docs/topics/workflows.d.ts +0 -2
  80. package/dist/api_docs/topics/workflows.js +0 -131
  81. package/dist/api_docs/topics/workspace.d.ts +0 -2
  82. package/dist/api_docs/topics/workspace.js +0 -153
  83. package/dist/api_docs/types.d.ts +0 -79
  84. package/dist/api_docs/types.js +0 -4
  85. package/dist/cli_docs/topics/run.d.ts +0 -2
  86. package/dist/cli_docs/topics/run.js +0 -248
  87. package/dist/meta_api_docs/format.test.d.ts +0 -1
  88. package/dist/meta_api_docs/format.test.js +0 -272
  89. package/dist/meta_api_docs/index.test.d.ts +0 -1
  90. package/dist/meta_api_docs/index.test.js +0 -128
  91. package/dist/meta_api_docs/types.test.d.ts +0 -1
  92. package/dist/meta_api_docs/types.test.js +0 -132
  93. package/dist/templates/init-workspace.d.ts +0 -10
  94. package/dist/templates/init-workspace.js +0 -278
  95. package/dist/templates/xanoscript-index.d.ts +0 -11
  96. package/dist/templates/xanoscript-index.js +0 -72
  97. package/dist/tools/index.test.d.ts +0 -1
  98. package/dist/tools/index.test.js +0 -179
  99. package/dist/tools/xanoscript_docs.test.d.ts +0 -1
  100. package/dist/tools/xanoscript_docs.test.js +0 -197
  101. package/dist/xanoscript.test.d.ts +0 -1
  102. package/dist/xanoscript.test.js +0 -421
  103. package/dist/xanoscript_docs/cheatsheet.md +0 -287
  104. package/dist/xanoscript_docs/ephemeral.md +0 -330
  105. package/dist/xanoscript_docs/quickstart.md +0 -692
  106. package/dist/xanoscript_docs/run.md +0 -196
  107. package/dist/xanoscript_docs/schema.md +0 -300
  108. package/dist/xanoscript_docs_auto/README.md +0 -119
  109. package/dist/xanoscript_docs_auto/agents.md +0 -446
  110. package/dist/xanoscript_docs_auto/apis.md +0 -517
  111. package/dist/xanoscript_docs_auto/control-flow.md +0 -543
  112. package/dist/xanoscript_docs_auto/database.md +0 -551
  113. package/dist/xanoscript_docs_auto/debugging.md +0 -527
  114. package/dist/xanoscript_docs_auto/filters.md +0 -464
  115. package/dist/xanoscript_docs_auto/functions.md +0 -431
  116. package/dist/xanoscript_docs_auto/integrations.md +0 -657
  117. package/dist/xanoscript_docs_auto/mcp-servers.md +0 -408
  118. package/dist/xanoscript_docs_auto/operators.md +0 -368
  119. package/dist/xanoscript_docs_auto/syntax.md +0 -287
  120. package/dist/xanoscript_docs_auto/tables.md +0 -447
  121. package/dist/xanoscript_docs_auto/tasks.md +0 -479
  122. package/dist/xanoscript_docs_auto/testing.md +0 -574
  123. package/dist/xanoscript_docs_auto/tools.md +0 -485
  124. package/dist/xanoscript_docs_auto/triggers.md +0 -595
  125. package/dist/xanoscript_docs_auto/types.md +0 -323
  126. package/dist/xanoscript_docs_auto/variables.md +0 -462
  127. package/dist/xanoscript_docs_auto/version.json +0 -5
@@ -1,197 +0,0 @@
1
- import { describe, it, expect, afterEach } from "vitest";
2
- import { join, dirname } from "path";
3
- import { fileURLToPath } from "url";
4
- import { getXanoscriptDocsPath, setXanoscriptDocsPath, xanoscriptDocs, xanoscriptDocsTool, } from "./xanoscript_docs.js";
5
- import { toMcpResponse } from "./types.js";
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = dirname(__filename);
8
- const DOCS_PATH = join(__dirname, "..", "xanoscript_docs");
9
- afterEach(() => {
10
- // Reset to default so tests don't interfere with each other
11
- setXanoscriptDocsPath(DOCS_PATH);
12
- });
13
- describe("getXanoscriptDocsPath", () => {
14
- it("should return a string path", () => {
15
- const path = getXanoscriptDocsPath();
16
- expect(typeof path).toBe("string");
17
- expect(path.length).toBeGreaterThan(0);
18
- });
19
- it("should return a path ending with xanoscript_docs", () => {
20
- const path = getXanoscriptDocsPath();
21
- expect(path).toMatch(/xanoscript_docs$/);
22
- });
23
- it("should return a consistent path on repeated calls", () => {
24
- const path1 = getXanoscriptDocsPath();
25
- const path2 = getXanoscriptDocsPath();
26
- expect(path1).toBe(path2);
27
- });
28
- });
29
- describe("setXanoscriptDocsPath", () => {
30
- it("should override the docs path", () => {
31
- const customPath = "/custom/docs/path";
32
- setXanoscriptDocsPath(customPath);
33
- expect(getXanoscriptDocsPath()).toBe(customPath);
34
- });
35
- it("should be used by xanoscriptDocs when set", () => {
36
- setXanoscriptDocsPath(DOCS_PATH);
37
- const result = xanoscriptDocs();
38
- expect(result.documentation).toContain("Documentation version:");
39
- });
40
- });
41
- describe("xanoscriptDocs", () => {
42
- it("should return README when called with no args", () => {
43
- const result = xanoscriptDocs();
44
- expect(result).toHaveProperty("documentation");
45
- expect(typeof result.documentation).toBe("string");
46
- expect(result.documentation).toContain("Documentation version:");
47
- });
48
- it("should return specific topic documentation", () => {
49
- const result = xanoscriptDocs({ topic: "syntax" });
50
- expect(result.documentation).toContain("Documentation version:");
51
- });
52
- it("should return context-aware docs for file_path", () => {
53
- const result = xanoscriptDocs({ file_path: "api/users/create.xs" });
54
- expect(result.documentation).toContain("XanoScript Documentation for:");
55
- expect(result.documentation).toContain("Matched topics:");
56
- });
57
- it("should support quick_reference mode", () => {
58
- const full = xanoscriptDocs({ topic: "syntax", mode: "full" });
59
- const quick = xanoscriptDocs({ topic: "syntax", mode: "quick_reference" });
60
- expect(quick.documentation.length).toBeLessThanOrEqual(full.documentation.length);
61
- });
62
- it("should throw for unknown topic", () => {
63
- expect(() => xanoscriptDocs({ topic: "nonexistent" })).toThrow('Unknown topic "nonexistent"');
64
- });
65
- it("should throw for invalid docs path", () => {
66
- setXanoscriptDocsPath("/nonexistent/path");
67
- expect(() => xanoscriptDocs({ topic: "syntax" })).toThrow();
68
- });
69
- });
70
- describe("xanoscriptDocsTool", () => {
71
- it("should return success with data for valid call", () => {
72
- const result = xanoscriptDocsTool();
73
- expect(result.success).toBe(true);
74
- expect(result.data).toBeDefined();
75
- expect(typeof result.data).toBe("string");
76
- expect(result.error).toBeUndefined();
77
- });
78
- it("should return success with topic docs", () => {
79
- const result = xanoscriptDocsTool({ topic: "syntax" });
80
- expect(result.success).toBe(true);
81
- expect(result.data).toContain("Documentation version:");
82
- });
83
- it("should return error for unknown topic", () => {
84
- const result = xanoscriptDocsTool({ topic: "nonexistent" });
85
- expect(result.success).toBe(false);
86
- expect(result.error).toBeDefined();
87
- expect(result.error).toContain("Unknown topic");
88
- });
89
- it("should return error for invalid docs path", () => {
90
- setXanoscriptDocsPath("/nonexistent/path");
91
- const result = xanoscriptDocsTool({ topic: "syntax" });
92
- expect(result.success).toBe(false);
93
- expect(result.error).toBeDefined();
94
- expect(result.error).toContain("Error retrieving XanoScript documentation");
95
- });
96
- it("should return multi-content array for file_path mode", () => {
97
- const result = xanoscriptDocsTool({ file_path: "api/users/create.xs" });
98
- expect(result.success).toBe(true);
99
- expect(Array.isArray(result.data)).toBe(true);
100
- const data = result.data;
101
- // First element is the header
102
- expect(data[0]).toContain("XanoScript Documentation for: api/users/create.xs");
103
- expect(data[0]).toContain("Matched topics:");
104
- expect(data[0]).toContain("Version:");
105
- // Remaining elements are per-topic content
106
- expect(data.length).toBeGreaterThan(1);
107
- });
108
- it("should return single string for topic mode", () => {
109
- const result = xanoscriptDocsTool({ topic: "syntax" });
110
- expect(result.success).toBe(true);
111
- expect(typeof result.data).toBe("string");
112
- expect(Array.isArray(result.data)).toBe(false);
113
- });
114
- it("should return single string for no-args mode", () => {
115
- const result = xanoscriptDocsTool();
116
- expect(result.success).toBe(true);
117
- expect(typeof result.data).toBe("string");
118
- expect(Array.isArray(result.data)).toBe(false);
119
- });
120
- it("should produce multiple MCP content blocks for file_path via toMcpResponse", () => {
121
- const result = xanoscriptDocsTool({ file_path: "api/users/create.xs" });
122
- const mcpResponse = toMcpResponse(result);
123
- expect(mcpResponse.isError).toBeUndefined();
124
- // Should have multiple content blocks (header + N topics)
125
- expect(mcpResponse.content.length).toBeGreaterThan(1);
126
- // All blocks should be text type
127
- for (const block of mcpResponse.content) {
128
- expect(block.type).toBe("text");
129
- expect(typeof block.text).toBe("string");
130
- }
131
- });
132
- it("should produce single MCP content block for topic mode via toMcpResponse", () => {
133
- const result = xanoscriptDocsTool({ topic: "syntax" });
134
- const mcpResponse = toMcpResponse(result);
135
- expect(mcpResponse.content).toHaveLength(1);
136
- expect(mcpResponse.content[0].type).toBe("text");
137
- });
138
- it("should include structuredContent for file_path mode", () => {
139
- const result = xanoscriptDocsTool({ file_path: "api/users/create.xs" });
140
- expect(result.success).toBe(true);
141
- expect(result.structuredContent).toBeDefined();
142
- expect(result.structuredContent).toHaveProperty("file_path", "api/users/create.xs");
143
- expect(result.structuredContent).toHaveProperty("mode", "quick_reference");
144
- expect(result.structuredContent).toHaveProperty("version");
145
- expect(result.structuredContent).toHaveProperty("topics");
146
- expect(Array.isArray(result.structuredContent.topics)).toBe(true);
147
- });
148
- it("should include structuredContent for topic mode", () => {
149
- const result = xanoscriptDocsTool({ topic: "syntax" });
150
- expect(result.success).toBe(true);
151
- expect(result.structuredContent).toBeDefined();
152
- expect(result.structuredContent).toHaveProperty("documentation");
153
- });
154
- it("should include structuredContent in MCP response", () => {
155
- const result = xanoscriptDocsTool({ file_path: "api/users/create.xs" });
156
- const mcpResponse = toMcpResponse(result);
157
- expect(mcpResponse.structuredContent).toBeDefined();
158
- expect(mcpResponse.structuredContent).toHaveProperty("file_path");
159
- expect(mcpResponse.structuredContent).toHaveProperty("topics");
160
- });
161
- });
162
- describe("xanoscriptDocs structured output", () => {
163
- it("should include topics array for file_path mode", () => {
164
- const result = xanoscriptDocs({ file_path: "api/users/create.xs" });
165
- expect(result.topics).toBeDefined();
166
- expect(Array.isArray(result.topics)).toBe(true);
167
- expect(result.topics.length).toBeGreaterThan(0);
168
- });
169
- it("should have topic and content fields in each TopicDoc", () => {
170
- const result = xanoscriptDocs({ file_path: "api/users/create.xs" });
171
- for (const doc of result.topics) {
172
- expect(doc).toHaveProperty("topic");
173
- expect(doc).toHaveProperty("content");
174
- expect(typeof doc.topic).toBe("string");
175
- expect(typeof doc.content).toBe("string");
176
- expect(doc.content.length).toBeGreaterThan(0);
177
- }
178
- });
179
- it("should not include topics array for topic mode", () => {
180
- const result = xanoscriptDocs({ topic: "syntax" });
181
- expect(result.topics).toBeUndefined();
182
- });
183
- it("should not include topics array for no-args mode", () => {
184
- const result = xanoscriptDocs();
185
- expect(result.topics).toBeUndefined();
186
- });
187
- it("should respect exclude_topics in structured output", () => {
188
- const result = xanoscriptDocs({
189
- file_path: "api/users/create.xs",
190
- exclude_topics: ["syntax", "essentials"],
191
- });
192
- expect(result.topics).toBeDefined();
193
- const topicNames = result.topics.map((d) => d.topic);
194
- expect(topicNames).not.toContain("syntax");
195
- expect(topicNames).not.toContain("essentials");
196
- });
197
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,421 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { join, dirname } from "path";
3
- import { fileURLToPath } from "url";
4
- import { XANOSCRIPT_DOCS_V2, getDocsForFilePath, extractQuickReference, getXanoscriptDocsVersion, readXanoscriptDocsV2, readXanoscriptDocsStructured, getTopicNames, getTopicDescriptions, } from "./xanoscript.js";
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
- const DOCS_PATH = join(__dirname, "xanoscript_docs");
8
- describe("xanoscript module", () => {
9
- describe("XANOSCRIPT_DOCS_V2", () => {
10
- it("should have all expected topics", () => {
11
- const expectedTopics = [
12
- "survival",
13
- "working",
14
- "readme",
15
- "essentials",
16
- "syntax",
17
- "syntax/string-filters",
18
- "syntax/array-filters",
19
- "syntax/functions",
20
- "types",
21
- "tables",
22
- "functions",
23
- "apis",
24
- "tasks",
25
- "triggers",
26
- "database",
27
- "agents",
28
- "tools",
29
- "mcp-servers",
30
- "unit-testing",
31
- "workflow-tests",
32
- "integrations",
33
- "integrations/cloud-storage",
34
- "integrations/search",
35
- "integrations/redis",
36
- "integrations/external-apis",
37
- "integrations/utilities",
38
- "frontend",
39
- "addons",
40
- "debugging",
41
- "performance",
42
- "realtime",
43
- "security",
44
- "streaming",
45
- "middleware",
46
- "branch",
47
- "workspace",
48
- ];
49
- expect(Object.keys(XANOSCRIPT_DOCS_V2)).toEqual(expectedTopics);
50
- });
51
- it("should have valid DocConfig structure for each topic", () => {
52
- for (const [key, config] of Object.entries(XANOSCRIPT_DOCS_V2)) {
53
- expect(config).toHaveProperty("file");
54
- expect(config).toHaveProperty("applyTo");
55
- expect(config).toHaveProperty("description");
56
- expect(typeof config.file).toBe("string");
57
- expect(Array.isArray(config.applyTo)).toBe(true);
58
- expect(typeof config.description).toBe("string");
59
- expect(config.file).toMatch(/\.md$/);
60
- }
61
- });
62
- });
63
- describe("getDocsForFilePath", () => {
64
- it("should always include syntax for .xs files", () => {
65
- const result = getDocsForFilePath("test.xs");
66
- expect(result).toContain("syntax");
67
- });
68
- it("should match api files", () => {
69
- const result = getDocsForFilePath("api/users/create.xs");
70
- expect(result).toContain("syntax");
71
- expect(result).toContain("apis");
72
- expect(result).toContain("types");
73
- expect(result).toContain("database");
74
- expect(result).toContain("unit-testing");
75
- // Niche topics should NOT be auto-included for apis
76
- expect(result).not.toContain("addons");
77
- expect(result).not.toContain("integrations");
78
- expect(result).not.toContain("schema");
79
- expect(result).not.toContain("streaming");
80
- });
81
- it("should match function files", () => {
82
- const result = getDocsForFilePath("function/format.xs");
83
- expect(result).toContain("syntax");
84
- expect(result).toContain("functions");
85
- expect(result).toContain("types");
86
- expect(result).toContain("database");
87
- // Niche topics should NOT be auto-included for functions
88
- expect(result).not.toContain("addons");
89
- expect(result).not.toContain("integrations");
90
- expect(result).not.toContain("realtime");
91
- expect(result).not.toContain("schema");
92
- expect(result).not.toContain("streaming");
93
- });
94
- it("should match table files", () => {
95
- const result = getDocsForFilePath("table/users.xs");
96
- expect(result).toContain("syntax");
97
- expect(result).toContain("tables");
98
- });
99
- it("should match task files", () => {
100
- const result = getDocsForFilePath("task/cleanup.xs");
101
- expect(result).toContain("syntax");
102
- expect(result).toContain("tasks");
103
- expect(result).toContain("database");
104
- // integrations is now topic-only (not auto-included)
105
- expect(result).not.toContain("integrations");
106
- });
107
- it("should match trigger files", () => {
108
- const result = getDocsForFilePath("table/trigger/on_create.xs");
109
- expect(result).toContain("syntax");
110
- expect(result).toContain("triggers");
111
- });
112
- it("should match ai/agent files", () => {
113
- const result = getDocsForFilePath("ai/agent/support_bot.xs");
114
- expect(result).toContain("syntax");
115
- expect(result).toContain("agents");
116
- expect(result).toContain("types");
117
- });
118
- it("should match ai/tool files", () => {
119
- const result = getDocsForFilePath("ai/tool/search_docs.xs");
120
- expect(result).toContain("syntax");
121
- expect(result).toContain("tools");
122
- expect(result).toContain("types");
123
- expect(result).toContain("database");
124
- });
125
- it("should match ai/mcp_server files", () => {
126
- const result = getDocsForFilePath("ai/mcp_server/my_server.xs");
127
- expect(result).toContain("syntax");
128
- expect(result).toContain("mcp-servers");
129
- });
130
- it("should match middleware files", () => {
131
- const result = getDocsForFilePath("middleware/auth_check.xs");
132
- expect(result).toContain("syntax");
133
- expect(result).toContain("middleware");
134
- });
135
- it("should match branch.xs", () => {
136
- const result = getDocsForFilePath("branch.xs");
137
- expect(result).toContain("syntax");
138
- expect(result).toContain("branch");
139
- });
140
- it("should match workspace.xs", () => {
141
- const result = getDocsForFilePath("workspace/workspace.xs");
142
- expect(result).toContain("syntax");
143
- expect(result).toContain("workspace");
144
- });
145
- it("should match static frontend files", () => {
146
- const result = getDocsForFilePath("static/index.html");
147
- expect(result).toContain("frontend");
148
- });
149
- it("should match run files", () => {
150
- const result = getDocsForFilePath("run/job/main.xs");
151
- expect(result).toContain("syntax");
152
- });
153
- it("should not include readme automatically", () => {
154
- const result = getDocsForFilePath("api/test.xs");
155
- expect(result).not.toContain("readme");
156
- });
157
- it("should include syntax and essentials for .xs files", () => {
158
- const result = getDocsForFilePath("some/random/file.xs");
159
- expect(result).toContain("syntax");
160
- expect(result).toContain("essentials");
161
- });
162
- });
163
- describe("extractQuickReference", () => {
164
- it("should extract Quick Reference section when present", () => {
165
- const content = `# Title
166
-
167
- Some intro text.
168
-
169
- ## Quick Reference
170
-
171
- Quick reference content here.
172
-
173
- More quick reference.
174
-
175
- ## Next Section
176
-
177
- Other content.
178
- `;
179
- const result = extractQuickReference(content, "test");
180
- expect(result).toContain("# test");
181
- expect(result).toContain("## Quick Reference");
182
- expect(result).toContain("Quick reference content here.");
183
- expect(result).not.toContain("## Next Section");
184
- expect(result).not.toContain("Other content.");
185
- });
186
- it("should return fallback when no Quick Reference section", () => {
187
- const content = `# Title
188
-
189
- Some intro text.
190
-
191
- ## First Section
192
-
193
- Section content.
194
-
195
- ## Second Section
196
-
197
- More content.
198
- `;
199
- const result = extractQuickReference(content, "test");
200
- expect(result).toContain("# Title");
201
- expect(result).toContain("Some intro text.");
202
- expect(result).not.toContain("## First Section");
203
- });
204
- it("should return up to 50 lines if no sections found", () => {
205
- const lines = Array(100).fill("Line content").join("\n");
206
- const result = extractQuickReference(lines, "test");
207
- const resultLines = result.split("\n");
208
- expect(resultLines.length).toBeLessThanOrEqual(50);
209
- });
210
- it("should include Quick Reference to end if no following section", () => {
211
- const content = `# Title
212
-
213
- ## Quick Reference
214
-
215
- Quick reference content.
216
- More content.
217
- Even more content.
218
- `;
219
- const result = extractQuickReference(content, "test");
220
- expect(result).toContain("Quick reference content.");
221
- expect(result).toContain("More content.");
222
- expect(result).toContain("Even more content.");
223
- });
224
- });
225
- describe("getXanoscriptDocsVersion", () => {
226
- it("should return version from valid docs path", () => {
227
- const version = getXanoscriptDocsVersion(DOCS_PATH);
228
- expect(typeof version).toBe("string");
229
- // Version should be a semver-like string or "unknown"
230
- expect(version).toMatch(/^(\d+\.\d+\.\d+|unknown)$/);
231
- });
232
- it("should return unknown for invalid path", () => {
233
- const version = getXanoscriptDocsVersion("/nonexistent/path");
234
- expect(version).toBe("unknown");
235
- });
236
- });
237
- describe("readXanoscriptDocsV2", () => {
238
- it("should return README when no args provided", () => {
239
- const result = readXanoscriptDocsV2(DOCS_PATH);
240
- expect(result).toContain("Documentation version:");
241
- });
242
- it("should return README when empty args provided", () => {
243
- const result = readXanoscriptDocsV2(DOCS_PATH, {});
244
- expect(result).toContain("Documentation version:");
245
- });
246
- it("should return specific topic documentation", () => {
247
- const result = readXanoscriptDocsV2(DOCS_PATH, { topic: "syntax" });
248
- expect(result).toContain("Documentation version:");
249
- });
250
- it("should throw for unknown topic", () => {
251
- expect(() => readXanoscriptDocsV2(DOCS_PATH, { topic: "nonexistent" })).toThrow('Unknown topic "nonexistent"');
252
- });
253
- it("should return context-aware docs for file_path", () => {
254
- const result = readXanoscriptDocsV2(DOCS_PATH, {
255
- file_path: "api/users/create.xs",
256
- });
257
- expect(result).toContain("XanoScript Documentation for: api/users/create.xs");
258
- expect(result).toContain("Matched topics:");
259
- expect(result).toContain("Version:");
260
- });
261
- it("should support quick_reference mode for topic", () => {
262
- const fullResult = readXanoscriptDocsV2(DOCS_PATH, {
263
- topic: "syntax",
264
- mode: "full",
265
- });
266
- const quickResult = readXanoscriptDocsV2(DOCS_PATH, {
267
- topic: "syntax",
268
- mode: "quick_reference",
269
- });
270
- // Quick reference should be shorter
271
- expect(quickResult.length).toBeLessThanOrEqual(fullResult.length);
272
- });
273
- it("should support quick_reference mode for file_path", () => {
274
- const fullResult = readXanoscriptDocsV2(DOCS_PATH, {
275
- file_path: "api/test.xs",
276
- mode: "full",
277
- });
278
- const quickResult = readXanoscriptDocsV2(DOCS_PATH, {
279
- file_path: "api/test.xs",
280
- mode: "quick_reference",
281
- });
282
- expect(quickResult).toContain("Mode: quick_reference");
283
- });
284
- it("should default to quick_reference mode for file_path", () => {
285
- const result = readXanoscriptDocsV2(DOCS_PATH, {
286
- file_path: "api/test.xs",
287
- });
288
- expect(result).toContain("Mode: quick_reference");
289
- });
290
- it("should default to full mode for topic", () => {
291
- const result = readXanoscriptDocsV2(DOCS_PATH, { topic: "syntax" });
292
- // Full mode returns the complete doc content, not quick_reference
293
- expect(result).not.toContain("Mode: quick_reference");
294
- });
295
- it("should support exclude_topics with file_path", () => {
296
- const result = readXanoscriptDocsV2(DOCS_PATH, {
297
- file_path: "api/users/create.xs",
298
- exclude_topics: ["syntax", "essentials"],
299
- });
300
- expect(result).toContain("Matched topics:");
301
- expect(result).not.toContain("Matched topics: syntax");
302
- // Verify excluded topics are not in the matched list
303
- const matchLine = result.split("\n").find((l) => l.startsWith("Matched topics:"));
304
- expect(matchLine).not.toContain("syntax");
305
- expect(matchLine).not.toContain("essentials");
306
- });
307
- it("should throw when all topics are excluded via exclude_topics", () => {
308
- expect(() => readXanoscriptDocsV2(DOCS_PATH, {
309
- file_path: "branch.xs",
310
- exclude_topics: ["syntax", "essentials", "debugging", "branch", "survival", "working"],
311
- })).toThrow("No documentation found");
312
- });
313
- it("should throw for invalid docs path", () => {
314
- expect(() => readXanoscriptDocsV2("/nonexistent/path", { topic: "syntax" })).toThrow();
315
- });
316
- it("should return compact index with mode: index", () => {
317
- const result = readXanoscriptDocsV2(DOCS_PATH, { mode: "index" });
318
- expect(result).toContain("# XanoScript Documentation Index");
319
- expect(result).toContain("Version:");
320
- expect(result).toContain("Topics:");
321
- expect(result).toContain("| Topic | Description | Size | Est. Tokens |");
322
- // Should contain some known topics
323
- expect(result).toContain("| syntax |");
324
- expect(result).toContain("| essentials |");
325
- expect(result).toContain("| database |");
326
- // Should contain KB size indicators
327
- expect(result).toContain("KB |");
328
- });
329
- it("should return index mode without requiring topic or file_path", () => {
330
- const result = readXanoscriptDocsV2(DOCS_PATH, { mode: "index" });
331
- // Index mode ignores topic/file_path — just returns the listing
332
- expect(result).toContain("# XanoScript Documentation Index");
333
- });
334
- it("should return index that is significantly smaller than full docs", () => {
335
- const index = readXanoscriptDocsV2(DOCS_PATH, { mode: "index" });
336
- const full = readXanoscriptDocsV2(DOCS_PATH, { topic: "syntax", mode: "full" });
337
- // Index should be compact — smaller than even a single full topic
338
- expect(index.length).toBeLessThan(full.length);
339
- });
340
- });
341
- describe("getTopicNames", () => {
342
- it("should return all topic names", () => {
343
- const names = getTopicNames();
344
- expect(names).toEqual(Object.keys(XANOSCRIPT_DOCS_V2));
345
- });
346
- it("should return an array of strings", () => {
347
- const names = getTopicNames();
348
- expect(Array.isArray(names)).toBe(true);
349
- names.forEach((name) => {
350
- expect(typeof name).toBe("string");
351
- });
352
- });
353
- });
354
- describe("getTopicDescriptions", () => {
355
- it("should return formatted descriptions string", () => {
356
- const descriptions = getTopicDescriptions();
357
- expect(typeof descriptions).toBe("string");
358
- });
359
- it("should include all topics", () => {
360
- const descriptions = getTopicDescriptions();
361
- for (const key of Object.keys(XANOSCRIPT_DOCS_V2)) {
362
- expect(descriptions).toContain(key);
363
- }
364
- });
365
- it("should include topic descriptions", () => {
366
- const descriptions = getTopicDescriptions();
367
- expect(descriptions).toContain("XanoScript overview");
368
- expect(descriptions).toContain("Expressions, operators");
369
- });
370
- });
371
- describe("readXanoscriptDocsStructured", () => {
372
- it("should return array of TopicDoc objects", () => {
373
- const result = readXanoscriptDocsStructured(DOCS_PATH, {
374
- file_path: "api/users/create.xs",
375
- });
376
- expect(Array.isArray(result)).toBe(true);
377
- expect(result.length).toBeGreaterThan(0);
378
- for (const doc of result) {
379
- expect(doc).toHaveProperty("topic");
380
- expect(doc).toHaveProperty("content");
381
- expect(typeof doc.topic).toBe("string");
382
- expect(typeof doc.content).toBe("string");
383
- }
384
- });
385
- it("should match the same topics as getDocsForFilePath", () => {
386
- const filePath = "api/users/create.xs";
387
- const expected = getDocsForFilePath(filePath);
388
- const result = readXanoscriptDocsStructured(DOCS_PATH, { file_path: filePath });
389
- const resultTopics = result.map((d) => d.topic);
390
- expect(resultTopics).toEqual(expected);
391
- });
392
- it("should respect exclude_topics", () => {
393
- const result = readXanoscriptDocsStructured(DOCS_PATH, {
394
- file_path: "api/users/create.xs",
395
- exclude_topics: ["syntax", "essentials"],
396
- });
397
- const topics = result.map((d) => d.topic);
398
- expect(topics).not.toContain("syntax");
399
- expect(topics).not.toContain("essentials");
400
- });
401
- it("should throw when all topics are excluded", () => {
402
- expect(() => readXanoscriptDocsStructured(DOCS_PATH, {
403
- file_path: "branch.xs",
404
- exclude_topics: ["syntax", "essentials", "debugging", "branch", "survival", "working"],
405
- })).toThrow("No documentation found");
406
- });
407
- it("should use quick_reference mode by default", () => {
408
- const quickResult = readXanoscriptDocsStructured(DOCS_PATH, {
409
- file_path: "table/users.xs",
410
- });
411
- const fullResult = readXanoscriptDocsStructured(DOCS_PATH, {
412
- file_path: "table/users.xs",
413
- mode: "full",
414
- });
415
- // Quick reference content should be shorter than full
416
- const quickTotal = quickResult.reduce((sum, d) => sum + d.content.length, 0);
417
- const fullTotal = fullResult.reduce((sum, d) => sum + d.content.length, 0);
418
- expect(quickTotal).toBeLessThanOrEqual(fullTotal);
419
- });
420
- });
421
- });