@dnai/dynamicllm 0.1.0 → 0.2.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 (58) hide show
  1. package/README.md +64 -0
  2. package/dist/bin/dynamicllm.js +7 -0
  3. package/dist/cli/formatters.d.ts +11 -0
  4. package/dist/cli/formatters.js +138 -0
  5. package/dist/cli/index.d.ts +1 -0
  6. package/dist/cli/index.js +345 -0
  7. package/dist/cli/init.d.ts +1 -0
  8. package/dist/{setup.js → cli/init.js} +22 -33
  9. package/dist/core/bootstrap.d.ts +14 -0
  10. package/dist/core/bootstrap.js +38 -0
  11. package/dist/core/constants.d.ts +4 -0
  12. package/dist/core/constants.js +71 -0
  13. package/dist/{lib → core}/fetcher.d.ts +6 -7
  14. package/dist/core/fetcher.js +247 -0
  15. package/dist/core/index.d.ts +9 -0
  16. package/dist/core/index.js +8 -0
  17. package/dist/{lib → core}/lint.js +0 -5
  18. package/dist/core/log.d.ts +13 -0
  19. package/dist/core/log.js +65 -0
  20. package/dist/core/report.d.ts +5 -0
  21. package/dist/{lib → core}/report.js +7 -14
  22. package/dist/{lib → core}/types.d.ts +43 -0
  23. package/dist/core/types.js +2 -0
  24. package/dist/{server.js → mcp/server.js} +48 -68
  25. package/framework/CONVENTIONS.md +40 -0
  26. package/framework/SYSTEM_PROMPT.md +203 -0
  27. package/framework/antidotes/constructive-optimism.md +37 -0
  28. package/framework/antidotes/liberated-agentism.md +37 -0
  29. package/framework/antidotes/objective-fallibilism.md +39 -0
  30. package/framework/antidotes/oxidative-creativism.md +41 -0
  31. package/framework/antidotes/polycentric-nodalism.md +38 -0
  32. package/framework/antidotes/vertical-authenticism.md +39 -0
  33. package/framework/lenses/logos.md +32 -0
  34. package/framework/lenses/mythos.md +32 -0
  35. package/framework/lenses/pathos.md +32 -0
  36. package/framework/qualities/beauty.md +29 -0
  37. package/framework/qualities/infinity.md +29 -0
  38. package/framework/qualities/love.md +29 -0
  39. package/framework/qualities/mystery.md +29 -0
  40. package/framework/qualities/play.md +29 -0
  41. package/framework/qualities/story.md +29 -0
  42. package/package.json +29 -5
  43. package/dist/cli.js +0 -20
  44. package/dist/lib/fetcher.js +0 -210
  45. package/dist/lib/report.d.ts +0 -19
  46. package/dist/lib/types.js +0 -1
  47. package/dist/setup.d.ts +0 -1
  48. /package/dist/{cli.d.ts → bin/dynamicllm.d.ts} +0 -0
  49. /package/dist/{lib → core}/cache.d.ts +0 -0
  50. /package/dist/{lib → core}/cache.js +0 -0
  51. /package/dist/{lib → core}/context.d.ts +0 -0
  52. /package/dist/{lib → core}/context.js +0 -0
  53. /package/dist/{lib → core}/lint.d.ts +0 -0
  54. /package/dist/{lib → core}/search.d.ts +0 -0
  55. /package/dist/{lib → core}/search.js +0 -0
  56. /package/dist/{index.d.ts → mcp/index.d.ts} +0 -0
  57. /package/dist/{index.js → mcp/index.js} +0 -0
  58. /package/dist/{server.d.ts → mcp/server.d.ts} +0 -0
@@ -1,210 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync, statSync, } from "node:fs";
2
- import { join, basename } from "node:path";
3
- import { createHash } from "node:crypto";
4
- import { FileCache } from "./cache.js";
5
- const DEFAULT_CDN_URL = "https://dynamicllm-cdn.eatlinguini.workers.dev";
6
- /** Parse YAML frontmatter from a markdown string */
7
- function parseFrontmatter(content) {
8
- const match = content.match(/^---\n([\s\S]*?)\n---/);
9
- if (!match)
10
- return {};
11
- const fm = {};
12
- for (const line of match[1].split("\n")) {
13
- const colon = line.indexOf(":");
14
- if (colon < 0)
15
- continue;
16
- const key = line.slice(0, colon).trim();
17
- let val = line.slice(colon + 1).trim();
18
- // Parse YAML arrays: [a, b, c]
19
- if (typeof val === "string" && val.startsWith("[") && val.endsWith("]")) {
20
- val = val
21
- .slice(1, -1)
22
- .split(",")
23
- .map((s) => s.trim())
24
- .filter(Boolean);
25
- }
26
- fm[key] = val;
27
- }
28
- return fm;
29
- }
30
- /** Scan a local directory of .md files and build index entries */
31
- function scanLocalDir(dir) {
32
- const nodes = [];
33
- const sources = [];
34
- const fileContents = new Map();
35
- if (!existsSync(dir))
36
- return { nodes, sources, fileContents };
37
- const files = readdirSync(dir).filter((f) => f.endsWith(".md"));
38
- for (const file of files) {
39
- const filePath = join(dir, file);
40
- const content = readFileSync(filePath, "utf-8");
41
- const slug = basename(file, ".md").toLowerCase().replace(/[_\s]+/g, "-");
42
- const fm = parseFrontmatter(content);
43
- const size = statSync(filePath).size;
44
- const hash = createHash("sha256").update(content).digest("hex").slice(0, 8);
45
- const type = fm.type;
46
- const name = fm.name ?? slug;
47
- const tags = fm.tags ?? [];
48
- const VALID_TYPES = new Set(["person", "idea", "antidote", "lens", "quality", "source", "synthesis"]);
49
- if (type && !VALID_TYPES.has(type)) {
50
- console.warn(`[dynamicllm] Skipping ${file}: invalid type "${type}"`);
51
- continue;
52
- }
53
- if (type === "source") {
54
- sources.push({
55
- slug,
56
- displayName: name,
57
- type: "source",
58
- author: fm.author ?? "",
59
- tags,
60
- hash,
61
- size,
62
- });
63
- fileContents.set(`sources/${slug}.md`, content);
64
- }
65
- else if (type) {
66
- const entry = {
67
- slug,
68
- displayName: name,
69
- type: type,
70
- tags,
71
- hash,
72
- size,
73
- };
74
- if (type === "antidote" && fm.mind_virus) {
75
- entry.mindVirus = fm.mind_virus;
76
- }
77
- if (fm.derived_from) {
78
- entry.derivedFrom = fm.derived_from;
79
- }
80
- nodes.push(entry);
81
- fileContents.set(`nodes/${slug}.md`, content);
82
- }
83
- }
84
- return { nodes, sources, fileContents };
85
- }
86
- export class NetworkFetcher {
87
- cdnUrl;
88
- cache;
89
- networkDir;
90
- localContents = new Map();
91
- mergedIndex = null;
92
- constructor(opts) {
93
- this.cdnUrl = opts?.cdnUrl ?? DEFAULT_CDN_URL;
94
- this.cache = new FileCache(opts?.cacheDir);
95
- this.networkDir = opts?.networkDir ?? null;
96
- }
97
- async fetchIndex() {
98
- if (this.mergedIndex)
99
- return this.mergedIndex;
100
- // 1. Fetch CDN index (framework files)
101
- const cdnIndex = await this.fetchCdnIndex();
102
- // 2. Scan local directory (custom nodes)
103
- if (this.networkDir) {
104
- const local = scanLocalDir(this.networkDir);
105
- this.localContents = local.fileContents;
106
- // Merge: local nodes/sources added to CDN index
107
- // Local entries override CDN entries with the same slug
108
- const cdnNodeSlugs = new Set(local.nodes.map((n) => n.slug));
109
- const cdnSourceSlugs = new Set(local.sources.map((s) => s.slug));
110
- const mergedNodes = [
111
- ...cdnIndex.nodes.filter((n) => !cdnNodeSlugs.has(n.slug)),
112
- ...local.nodes,
113
- ];
114
- const mergedSources = [
115
- ...cdnIndex.sources.filter((s) => !cdnSourceSlugs.has(s.slug)),
116
- ...local.sources,
117
- ];
118
- this.mergedIndex = {
119
- ...cdnIndex,
120
- nodes: mergedNodes,
121
- sources: mergedSources,
122
- };
123
- }
124
- else {
125
- this.mergedIndex = cdnIndex;
126
- }
127
- return this.mergedIndex;
128
- }
129
- /** Invalidate cached merged index (call after saving new files) */
130
- invalidateIndex() {
131
- this.mergedIndex = null;
132
- this.localContents.clear();
133
- }
134
- async fetchNode(slug) {
135
- const key = `nodes/${slug}.md`;
136
- const local = this.localContents.get(key);
137
- if (local)
138
- return local;
139
- return this.fetchFile(key);
140
- }
141
- async fetchSource(slug) {
142
- const key = `sources/${slug}.md`;
143
- const local = this.localContents.get(key);
144
- if (local)
145
- return local;
146
- return this.fetchFile(key);
147
- }
148
- async fetchMeta(slug) {
149
- return this.fetchFile(`meta/${slug}.md`);
150
- }
151
- async fetchCdnIndex() {
152
- const key = "index.json";
153
- const cached = this.cache.get(key);
154
- if (cached)
155
- return JSON.parse(cached);
156
- try {
157
- const content = await this.fetchRemote(key);
158
- const index = JSON.parse(content);
159
- const stale = this.cache.getStale(key);
160
- if (stale) {
161
- const oldIndex = JSON.parse(stale);
162
- if (oldIndex.schemaVersion < index.schemaVersion) {
163
- this.cache.clear();
164
- }
165
- }
166
- this.cache.set(key, content);
167
- return index;
168
- }
169
- catch {
170
- const stale = this.cache.getStale(key);
171
- if (stale) {
172
- console.warn("⚠ Cannot reach DynamicLLM network. Using stale cache.");
173
- return JSON.parse(stale);
174
- }
175
- throw new Error("Cannot reach DynamicLLM network. Run once with network access to populate cache.");
176
- }
177
- }
178
- async fetchFile(key) {
179
- const cached = this.cache.get(key);
180
- if (cached)
181
- return cached;
182
- try {
183
- const content = await this.fetchRemote(key);
184
- this.cache.set(key, content);
185
- return content;
186
- }
187
- catch {
188
- const stale = this.cache.getStale(key);
189
- if (stale) {
190
- console.warn(`⚠ Using stale cache for ${key}`);
191
- return stale;
192
- }
193
- throw new Error(`Cannot fetch ${key} from DynamicLLM network.`);
194
- }
195
- }
196
- async fetchRemote(key) {
197
- const url = `${this.cdnUrl}/${key}`;
198
- const controller = new AbortController();
199
- const timeout = setTimeout(() => controller.abort(), 10_000);
200
- try {
201
- const res = await fetch(url, { signal: controller.signal });
202
- if (!res.ok)
203
- throw new Error(`HTTP ${res.status} for ${key}`);
204
- return await res.text();
205
- }
206
- finally {
207
- clearTimeout(timeout);
208
- }
209
- }
210
- }
@@ -1,19 +0,0 @@
1
- export interface VirusAxisScore {
2
- axis: string;
3
- dynamicPole: string;
4
- staticPole: string;
5
- severity: "Clean" | "Warning" | "Infected";
6
- infectionPercent: number;
7
- evidence: string;
8
- }
9
- export interface ReportOptions {
10
- mode: "virus-scan" | "lens" | "quality";
11
- analysisText: string;
12
- contentLabel?: string;
13
- scores?: VirusAxisScore[];
14
- quality?: string;
15
- }
16
- export declare function generateReport(opts: ReportOptions): {
17
- filePath: string;
18
- content: string;
19
- };
package/dist/lib/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/setup.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function setup(): Promise<void>;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes