dna-sdk 0.1.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 (240) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +58 -0
  3. package/dist/adapters/embedding/onnx.d.ts +32 -0
  4. package/dist/adapters/embedding/onnx.js +51 -0
  5. package/dist/adapters/filesystem/cache.d.ts +16 -0
  6. package/dist/adapters/filesystem/cache.js +113 -0
  7. package/dist/adapters/filesystem/index.d.ts +2 -0
  8. package/dist/adapters/filesystem/index.js +2 -0
  9. package/dist/adapters/filesystem/source.d.ts +82 -0
  10. package/dist/adapters/filesystem/source.js +357 -0
  11. package/dist/adapters/postgres/index.d.ts +2 -0
  12. package/dist/adapters/postgres/index.js +2 -0
  13. package/dist/adapters/postgres/migrations.d.ts +14 -0
  14. package/dist/adapters/postgres/migrations.js +88 -0
  15. package/dist/adapters/postgres/source.d.ts +172 -0
  16. package/dist/adapters/postgres/source.js +569 -0
  17. package/dist/adapters/resolvers/github.d.ts +12 -0
  18. package/dist/adapters/resolvers/github.js +47 -0
  19. package/dist/adapters/resolvers/http.d.ts +22 -0
  20. package/dist/adapters/resolvers/http.js +145 -0
  21. package/dist/adapters/resolvers/index.d.ts +3 -0
  22. package/dist/adapters/resolvers/index.js +3 -0
  23. package/dist/adapters/resolvers/local.d.ts +24 -0
  24. package/dist/adapters/resolvers/local.js +132 -0
  25. package/dist/adapters/search/driver.d.ts +45 -0
  26. package/dist/adapters/search/driver.js +138 -0
  27. package/dist/adapters/search/migrations.d.ts +26 -0
  28. package/dist/adapters/search/migrations.js +58 -0
  29. package/dist/adapters/search/rrf.d.ts +23 -0
  30. package/dist/adapters/search/rrf.js +42 -0
  31. package/dist/adapters/search/sqlite-vec.d.ts +66 -0
  32. package/dist/adapters/search/sqlite-vec.js +294 -0
  33. package/dist/bootstrap.d.ts +45 -0
  34. package/dist/bootstrap.js +134 -0
  35. package/dist/extensions/agentskills/DOCS.md +18 -0
  36. package/dist/extensions/agentskills.d.ts +28 -0
  37. package/dist/extensions/agentskills.js +252 -0
  38. package/dist/extensions/agentsmd/DOCS.md +18 -0
  39. package/dist/extensions/agentsmd.d.ts +22 -0
  40. package/dist/extensions/agentsmd.js +170 -0
  41. package/dist/extensions/audit/kinds/audit-log.kind.yaml +148 -0
  42. package/dist/extensions/audit.d.ts +25 -0
  43. package/dist/extensions/audit.js +62 -0
  44. package/dist/extensions/automation/kinds/automation.kind.yaml +296 -0
  45. package/dist/extensions/automation/query.d.ts +49 -0
  46. package/dist/extensions/automation/query.js +77 -0
  47. package/dist/extensions/automation/write-guards.d.ts +59 -0
  48. package/dist/extensions/automation/write-guards.js +153 -0
  49. package/dist/extensions/automation.d.ts +41 -0
  50. package/dist/extensions/automation.js +54 -0
  51. package/dist/extensions/collab.d.ts +16 -0
  52. package/dist/extensions/collab.js +79 -0
  53. package/dist/extensions/doc/kinds/doc.kind.yaml +118 -0
  54. package/dist/extensions/doc.d.ts +25 -0
  55. package/dist/extensions/doc.js +10 -0
  56. package/dist/extensions/eval/kinds/eval-baseline.kind.yaml +65 -0
  57. package/dist/extensions/eval/kinds/eval-case.kind.yaml +140 -0
  58. package/dist/extensions/eval/kinds/eval-run.kind.yaml +134 -0
  59. package/dist/extensions/eval/kinds/eval-suite.kind.yaml +87 -0
  60. package/dist/extensions/eval.d.ts +24 -0
  61. package/dist/extensions/eval.js +31 -0
  62. package/dist/extensions/evidence/kinds/evidence.kind.yaml +92 -0
  63. package/dist/extensions/evidence.d.ts +17 -0
  64. package/dist/extensions/evidence.js +94 -0
  65. package/dist/extensions/federation.d.ts +22 -0
  66. package/dist/extensions/federation.js +173 -0
  67. package/dist/extensions/guardrails/DOCS.md +20 -0
  68. package/dist/extensions/guardrails.d.ts +31 -0
  69. package/dist/extensions/guardrails.js +228 -0
  70. package/dist/extensions/helix/DOCS-Actor.md +20 -0
  71. package/dist/extensions/helix/DOCS-Agent.md +20 -0
  72. package/dist/extensions/helix/DOCS-UseCase.md +20 -0
  73. package/dist/extensions/helix/layers.d.ts +12 -0
  74. package/dist/extensions/helix/layers.js +18 -0
  75. package/dist/extensions/helix/write-guards.d.ts +70 -0
  76. package/dist/extensions/helix/write-guards.js +172 -0
  77. package/dist/extensions/helix.d.ts +29 -0
  78. package/dist/extensions/helix.js +963 -0
  79. package/dist/extensions/helix_extras.d.ts +124 -0
  80. package/dist/extensions/helix_extras.js +328 -0
  81. package/dist/extensions/hooks.d.ts +31 -0
  82. package/dist/extensions/hooks.js +247 -0
  83. package/dist/extensions/kinddef/DOCS.md +24 -0
  84. package/dist/extensions/kinddef.d.ts +40 -0
  85. package/dist/extensions/kinddef.js +171 -0
  86. package/dist/extensions/lesson.d.ts +6 -0
  87. package/dist/extensions/lesson.js +194 -0
  88. package/dist/extensions/modelreg/kinds/model-profile.kind.yaml +155 -0
  89. package/dist/extensions/modelreg.d.ts +30 -0
  90. package/dist/extensions/modelreg.js +38 -0
  91. package/dist/extensions/recognizer.d.ts +34 -0
  92. package/dist/extensions/recognizer.js +272 -0
  93. package/dist/extensions/research.d.ts +32 -0
  94. package/dist/extensions/research.js +292 -0
  95. package/dist/extensions/safety.d.ts +33 -0
  96. package/dist/extensions/safety.js +230 -0
  97. package/dist/extensions/sdlc/kinds/adr.kind.yaml +136 -0
  98. package/dist/extensions/sdlc/kinds/archive-proposal.kind.yaml +107 -0
  99. package/dist/extensions/sdlc/kinds/changelog.kind.yaml +108 -0
  100. package/dist/extensions/sdlc/kinds/cognitive-policy.kind.yaml +470 -0
  101. package/dist/extensions/sdlc/kinds/forecast.kind.yaml +125 -0
  102. package/dist/extensions/sdlc/kinds/insight.kind.yaml +87 -0
  103. package/dist/extensions/sdlc/kinds/kaizen.kind.yaml +106 -0
  104. package/dist/extensions/sdlc/kinds/lesson-learned.kind.yaml +270 -0
  105. package/dist/extensions/sdlc/kinds/narrative.kind.yaml +189 -0
  106. package/dist/extensions/sdlc/kinds/pattern-insight.kind.yaml +204 -0
  107. package/dist/extensions/sdlc/kinds/postmortem.kind.yaml +168 -0
  108. package/dist/extensions/sdlc/kinds/pre-mortem.kind.yaml +145 -0
  109. package/dist/extensions/sdlc/kinds/prompt-template.kind.yaml +109 -0
  110. package/dist/extensions/sdlc/kinds/retrospective.kind.yaml +186 -0
  111. package/dist/extensions/sdlc/kinds/risk-register.kind.yaml +178 -0
  112. package/dist/extensions/sdlc/kinds/saved-view.kind.yaml +127 -0
  113. package/dist/extensions/sdlc/kinds/status-report.kind.yaml +129 -0
  114. package/dist/extensions/sdlc/kinds/synthesis-run.kind.yaml +279 -0
  115. package/dist/extensions/sdlc/kinds/synthesizer-state.kind.yaml +196 -0
  116. package/dist/extensions/sdlc/kinds/workflow-event.kind.yaml +195 -0
  117. package/dist/extensions/sdlc.d.ts +32 -0
  118. package/dist/extensions/sdlc.js +1318 -0
  119. package/dist/extensions/soulspec/DOCS.md +19 -0
  120. package/dist/extensions/soulspec.d.ts +22 -0
  121. package/dist/extensions/soulspec.js +287 -0
  122. package/dist/extensions/tenant.d.ts +6 -0
  123. package/dist/extensions/tenant.js +291 -0
  124. package/dist/extensions/testkit.d.ts +24 -0
  125. package/dist/extensions/testkit.js +211 -0
  126. package/dist/index.d.ts +80 -0
  127. package/dist/index.js +102 -0
  128. package/dist/kernel/_text.d.ts +28 -0
  129. package/dist/kernel/_text.js +42 -0
  130. package/dist/kernel/bundle-handle.d.ts +83 -0
  131. package/dist/kernel/bundle-handle.js +184 -0
  132. package/dist/kernel/capabilities.d.ts +157 -0
  133. package/dist/kernel/capabilities.js +109 -0
  134. package/dist/kernel/collaborator-ports.d.ts +91 -0
  135. package/dist/kernel/collaborator-ports.js +1 -0
  136. package/dist/kernel/composition-resolver.d.ts +215 -0
  137. package/dist/kernel/composition-resolver.js +558 -0
  138. package/dist/kernel/composition.d.ts +10 -0
  139. package/dist/kernel/composition.js +1 -0
  140. package/dist/kernel/descriptor-loader.d.ts +13 -0
  141. package/dist/kernel/descriptor-loader.js +48 -0
  142. package/dist/kernel/document.d.ts +43 -0
  143. package/dist/kernel/document.js +71 -0
  144. package/dist/kernel/embedding.d.ts +28 -0
  145. package/dist/kernel/embedding.js +78 -0
  146. package/dist/kernel/errors.d.ts +62 -0
  147. package/dist/kernel/errors.js +82 -0
  148. package/dist/kernel/events.d.ts +6 -0
  149. package/dist/kernel/events.js +21 -0
  150. package/dist/kernel/evidence-capture.d.ts +69 -0
  151. package/dist/kernel/evidence-capture.js +138 -0
  152. package/dist/kernel/fs.d.ts +20 -0
  153. package/dist/kernel/fs.js +128 -0
  154. package/dist/kernel/generic-rw.d.ts +33 -0
  155. package/dist/kernel/generic-rw.js +235 -0
  156. package/dist/kernel/hooks.d.ts +172 -0
  157. package/dist/kernel/hooks.js +256 -0
  158. package/dist/kernel/index.d.ts +624 -0
  159. package/dist/kernel/index.js +1638 -0
  160. package/dist/kernel/instance.d.ts +211 -0
  161. package/dist/kernel/instance.js +487 -0
  162. package/dist/kernel/kind-registry.d.ts +183 -0
  163. package/dist/kernel/kind-registry.js +710 -0
  164. package/dist/kernel/kind_base.d.ts +106 -0
  165. package/dist/kernel/kind_base.js +244 -0
  166. package/dist/kernel/layer-resolver.d.ts +48 -0
  167. package/dist/kernel/layer-resolver.js +284 -0
  168. package/dist/kernel/lock-manager.d.ts +21 -0
  169. package/dist/kernel/lock-manager.js +43 -0
  170. package/dist/kernel/lock.d.ts +38 -0
  171. package/dist/kernel/lock.js +115 -0
  172. package/dist/kernel/meta.d.ts +135 -0
  173. package/dist/kernel/meta.js +817 -0
  174. package/dist/kernel/models.d.ts +3089 -0
  175. package/dist/kernel/models.js +764 -0
  176. package/dist/kernel/navigator.d.ts +36 -0
  177. package/dist/kernel/navigator.js +132 -0
  178. package/dist/kernel/port-surface.d.ts +33 -0
  179. package/dist/kernel/port-surface.js +180 -0
  180. package/dist/kernel/preview.d.ts +60 -0
  181. package/dist/kernel/preview.js +54 -0
  182. package/dist/kernel/prompt-budget.d.ts +39 -0
  183. package/dist/kernel/prompt-budget.js +43 -0
  184. package/dist/kernel/prompt-builder.d.ts +25 -0
  185. package/dist/kernel/prompt-builder.js +237 -0
  186. package/dist/kernel/protocols.d.ts +751 -0
  187. package/dist/kernel/protocols.js +493 -0
  188. package/dist/kernel/reports.d.ts +26 -0
  189. package/dist/kernel/reports.js +215 -0
  190. package/dist/kernel/resolver.d.ts +146 -0
  191. package/dist/kernel/resolver.js +232 -0
  192. package/dist/kernel/resource.d.ts +57 -0
  193. package/dist/kernel/resource.js +97 -0
  194. package/dist/kernel/runtime.d.ts +16 -0
  195. package/dist/kernel/runtime.js +18 -0
  196. package/dist/kernel/safety-scanner.d.ts +38 -0
  197. package/dist/kernel/safety-scanner.js +228 -0
  198. package/dist/kernel/serialize-to-files.d.ts +29 -0
  199. package/dist/kernel/serialize-to-files.js +23 -0
  200. package/dist/kernel/spec-access.d.ts +23 -0
  201. package/dist/kernel/spec-access.js +40 -0
  202. package/dist/kernel/studio_ui.d.ts +88 -0
  203. package/dist/kernel/studio_ui.js +135 -0
  204. package/dist/kernel/templates.d.ts +77 -0
  205. package/dist/kernel/templates.js +116 -0
  206. package/dist/kernel/tool-registry.d.ts +52 -0
  207. package/dist/kernel/tool-registry.js +89 -0
  208. package/dist/kernel/write-pipeline.d.ts +65 -0
  209. package/dist/kernel/write-pipeline.js +271 -0
  210. package/dist/kernel/writer-helpers.d.ts +24 -0
  211. package/dist/kernel/writer-helpers.js +42 -0
  212. package/dist/memory/decay.d.ts +31 -0
  213. package/dist/memory/decay.js +97 -0
  214. package/dist/memory/ecphory.d.ts +25 -0
  215. package/dist/memory/ecphory.js +178 -0
  216. package/dist/memory/encodingContext.d.ts +21 -0
  217. package/dist/memory/encodingContext.js +62 -0
  218. package/dist/memory/index.d.ts +23 -0
  219. package/dist/memory/index.js +23 -0
  220. package/dist/memory/memoryType.d.ts +7 -0
  221. package/dist/memory/memoryType.js +24 -0
  222. package/dist/memory/policy.d.ts +35 -0
  223. package/dist/memory/policy.js +35 -0
  224. package/dist/memory/retrieval.d.ts +21 -0
  225. package/dist/memory/retrieval.js +145 -0
  226. package/dist/testing/index.d.ts +8 -0
  227. package/dist/testing/index.js +8 -0
  228. package/dist/testing/recordSearchConformance.d.ts +43 -0
  229. package/dist/testing/recordSearchConformance.js +147 -0
  230. package/dist/viz/ascii.d.ts +7 -0
  231. package/dist/viz/ascii.js +60 -0
  232. package/dist/viz/health.d.ts +8 -0
  233. package/dist/viz/health.js +161 -0
  234. package/dist/viz/index.d.ts +10 -0
  235. package/dist/viz/index.js +10 -0
  236. package/dist/viz/matrix.d.ts +8 -0
  237. package/dist/viz/matrix.js +84 -0
  238. package/dist/viz/mermaid.d.ts +38 -0
  239. package/dist/viz/mermaid.js +706 -0
  240. package/package.json +82 -0
@@ -0,0 +1,21 @@
1
+ /**
2
+ * LockManager — namespace class extracting lockfile logic
3
+ * from ManifestInstance.
4
+ *
5
+ * Usage: `mi.lock.generate()` — equivalent to `mi.generateLock()`.
6
+ *
7
+ * This is an extraction (Chunk 2 of the kernel simplification plan).
8
+ * The original methods on ManifestInstance are preserved; both APIs
9
+ * return identical results.
10
+ */
11
+ import { type Lockfile } from "./lock.js";
12
+ import type { ManifestInstance } from "./instance.js";
13
+ export declare class LockManager {
14
+ private host;
15
+ constructor(host: ManifestInstance);
16
+ /**
17
+ * Generate a lockfile snapshot from the current documents.
18
+ * Equivalent to `mi.generateLock()`.
19
+ */
20
+ generate(): Lockfile;
21
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * LockManager — namespace class extracting lockfile logic
3
+ * from ManifestInstance.
4
+ *
5
+ * Usage: `mi.lock.generate()` — equivalent to `mi.generateLock()`.
6
+ *
7
+ * This is an extraction (Chunk 2 of the kernel simplification plan).
8
+ * The original methods on ManifestInstance are preserved; both APIs
9
+ * return identical results.
10
+ */
11
+ import { documentHash } from "./lock.js";
12
+ // ---------------------------------------------------------------------------
13
+ // LockManager
14
+ // ---------------------------------------------------------------------------
15
+ export class LockManager {
16
+ host;
17
+ constructor(host) {
18
+ this.host = host;
19
+ }
20
+ /**
21
+ * Generate a lockfile snapshot from the current documents.
22
+ * Equivalent to `mi.generateLock()`.
23
+ */
24
+ generate() {
25
+ const entries = this.host.documents.map((d) => {
26
+ const sha = documentHash(d.raw);
27
+ return {
28
+ name: d.name,
29
+ kind: d.kind,
30
+ apiVersion: d.apiVersion,
31
+ origin: d.origin,
32
+ path: "",
33
+ sha256: sha,
34
+ };
35
+ });
36
+ return {
37
+ scope: this.host.scope,
38
+ documents: entries,
39
+ lockVersion: 3,
40
+ generatedAt: new Date().toISOString(),
41
+ };
42
+ }
43
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Lockfile types and utilities — snapshot of resolved documents.
3
+ *
4
+ * 1:1 parity with Python lockfile structures.
5
+ */
6
+ export interface LockEntry {
7
+ name: string;
8
+ kind: string;
9
+ apiVersion: string;
10
+ origin: string;
11
+ path: string;
12
+ sha256: string;
13
+ }
14
+ export interface Lockfile {
15
+ scope: string;
16
+ documents: LockEntry[];
17
+ lockVersion: number;
18
+ generatedAt: string;
19
+ }
20
+ export interface VerifyResult {
21
+ added: string[];
22
+ removed: string[];
23
+ changed: string[];
24
+ ok: boolean;
25
+ }
26
+ /**
27
+ * Compute SHA-256 hash of a document's raw dict.
28
+ *
29
+ * Matches Python's: hashlib.sha256(json.dumps(raw, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
30
+ */
31
+ export declare function documentHash(raw: Record<string, unknown>): string;
32
+ export declare function writeLockfile(lock: Lockfile, path: string): void;
33
+ export declare function readLockfile(path: string): Lockfile;
34
+ export declare function verifyLock(documents: {
35
+ kind: string;
36
+ name: string;
37
+ raw: Record<string, unknown>;
38
+ }[], lockPath: string): VerifyResult;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Lockfile types and utilities — snapshot of resolved documents.
3
+ *
4
+ * 1:1 parity with Python lockfile structures.
5
+ */
6
+ import { readFileSync, writeFileSync, existsSync } from "node:fs";
7
+ import { sha256 } from "js-sha256";
8
+ import yaml from "js-yaml";
9
+ /**
10
+ * Serialize a value to JSON matching Python's json.dumps(sort_keys=True, ensure_ascii=False).
11
+ *
12
+ * Key differences from JSON.stringify:
13
+ * - Object keys are recursively sorted (not just top-level)
14
+ * - Separators use spaces: ", " between items and ": " between key-value pairs
15
+ * (Python's default separators)
16
+ *
17
+ * IMPORTANT: We cannot use JSON.stringify + regex replace because that would
18
+ * corrupt colons and commas inside string values (e.g., URLs like "http://host:8080").
19
+ * Python's json.dumps only adds spaces around STRUCTURAL separators, never inside strings.
20
+ */
21
+ function pythonJsonDumps(obj) {
22
+ if (obj === null)
23
+ return "null";
24
+ if (typeof obj === "boolean")
25
+ return obj ? "true" : "false";
26
+ if (typeof obj === "number")
27
+ return JSON.stringify(obj);
28
+ if (typeof obj === "string")
29
+ return JSON.stringify(obj);
30
+ if (Array.isArray(obj)) {
31
+ return "[" + obj.map(pythonJsonDumps).join(", ") + "]";
32
+ }
33
+ // Object with sorted keys
34
+ const keys = Object.keys(obj).sort();
35
+ const pairs = keys.map((k) => JSON.stringify(k) + ": " + pythonJsonDumps(obj[k]));
36
+ return "{" + pairs.join(", ") + "}";
37
+ }
38
+ /**
39
+ * Compute SHA-256 hash of a document's raw dict.
40
+ *
41
+ * Matches Python's: hashlib.sha256(json.dumps(raw, sort_keys=True, ensure_ascii=False).encode()).hexdigest()
42
+ */
43
+ export function documentHash(raw) {
44
+ const canonical = pythonJsonDumps(raw);
45
+ return sha256(canonical);
46
+ }
47
+ export function writeLockfile(lock, path) {
48
+ const sorted = [...lock.documents].sort((a, b) => a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind.localeCompare(b.kind));
49
+ const data = {
50
+ lockVersion: lock.lockVersion,
51
+ generated_at: lock.generatedAt,
52
+ scope: lock.scope,
53
+ documents: sorted.map(d => ({
54
+ name: d.name,
55
+ kind: d.kind,
56
+ apiVersion: d.apiVersion,
57
+ origin: d.origin,
58
+ path: d.path,
59
+ sha256: d.sha256,
60
+ })),
61
+ };
62
+ const content = `# Generated by dna install — DO NOT EDIT\n${yaml.dump(data, { sortKeys: false })}`;
63
+ writeFileSync(path, content);
64
+ }
65
+ export function readLockfile(path) {
66
+ if (!existsSync(path))
67
+ return { scope: "", documents: [], lockVersion: 3, generatedAt: "" };
68
+ const raw = yaml.load(readFileSync(path, "utf-8"));
69
+ if (!raw || !Array.isArray(raw.documents))
70
+ return { scope: "", documents: [], lockVersion: 3, generatedAt: "" };
71
+ const documents = raw.documents.map(d => ({
72
+ name: String(d.name ?? ""),
73
+ kind: String(d.kind ?? ""),
74
+ apiVersion: String(d.apiVersion ?? ""),
75
+ origin: String(d.origin ?? "local"),
76
+ path: String(d.path ?? ""),
77
+ sha256: String(d.sha256 ?? ""),
78
+ }));
79
+ return {
80
+ scope: String(raw.scope ?? ""),
81
+ documents,
82
+ lockVersion: Number(raw.lockVersion ?? 3),
83
+ generatedAt: String(raw.generated_at ?? ""),
84
+ };
85
+ }
86
+ export function verifyLock(documents, lockPath) {
87
+ const lock = readLockfile(lockPath);
88
+ const lockMap = new Map();
89
+ for (const e of lock.documents)
90
+ lockMap.set(`${e.kind}\0${e.name}`, e.sha256);
91
+ const currentMap = new Map();
92
+ for (const d of documents) {
93
+ const sha = documentHash(d.raw);
94
+ currentMap.set(`${d.kind}\0${d.name}`, sha);
95
+ }
96
+ const added = [];
97
+ const removed = [];
98
+ const changed = [];
99
+ for (const [key, sha] of currentMap) {
100
+ const [k, n] = key.split("\0");
101
+ if (!lockMap.has(key)) {
102
+ added.push(`${k}/${n}`);
103
+ continue;
104
+ }
105
+ if (lockMap.get(key) !== sha)
106
+ changed.push(`${k}/${n}`);
107
+ }
108
+ for (const [key] of lockMap) {
109
+ if (!currentMap.has(key)) {
110
+ const [k, n] = key.split("\0");
111
+ removed.push(`${k}/${n}`);
112
+ }
113
+ }
114
+ return { added, removed, changed, ok: added.length === 0 && removed.length === 0 && changed.length === 0 };
115
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Meta-kind machinery: DeclarativeKindPort synthesized from a
3
+ * TypedKindDefinition. 1:1 parity with Python dna.kernel.meta.
4
+ */
5
+ import type { Document } from "./document.js";
6
+ import { StudioUIMetadata } from "./studio_ui.js";
7
+ import type { TypedKindDefinition } from "./models.js";
8
+ import type { PreviewBlock } from "./preview.js";
9
+ import { type KindPort, type LayerPolicy, type StorageDescriptor, type TenantScope } from "./protocols.js";
10
+ /** Convert a literal YAML storage dict into a StorageDescriptor. */
11
+ export declare function storageDictToDescriptor(storage: Record<string, unknown>): StorageDescriptor;
12
+ /** Marker used by the 2-phase loader to distinguish synthetic ports from
13
+ * extension-registered ones for conflict resolution. */
14
+ export interface DeclarativeMarker {
15
+ readonly __declarative__: true;
16
+ }
17
+ export declare class DeclarativeKindPort implements KindPort, DeclarativeMarker {
18
+ readonly __declarative__: true;
19
+ readonly apiVersion: string;
20
+ readonly kind: string;
21
+ readonly alias: string;
22
+ readonly origin: string;
23
+ readonly docs?: string;
24
+ readonly isRoot: boolean;
25
+ readonly isPromptTarget: boolean;
26
+ readonly promptTargetPriority: number;
27
+ readonly flattenInContext: boolean;
28
+ readonly storage: StorageDescriptor;
29
+ readonly isRuntimeArtifact: boolean;
30
+ readonly plane: "composition" | "record";
31
+ readonly scope?: TenantScope;
32
+ readonly scopeInheritable: boolean;
33
+ readonly isOverlayable: boolean;
34
+ readonly embedFields: string[] | null;
35
+ private readonly _summary;
36
+ readonly volatileSpecFields: ReadonlySet<string>;
37
+ readonly graphStyle: {
38
+ fill: string;
39
+ stroke: string;
40
+ textColor: string;
41
+ };
42
+ readonly asciiIcon: string;
43
+ readonly displayLabel: string;
44
+ private readonly _depFilters;
45
+ private readonly _defaultAgent;
46
+ /** Public read-only view of the JSON Schema authored in the KindDefinition.
47
+ * Consumers like the Studio's NewDocumentWizard use this to pre-populate
48
+ * required fields with empty-but-valid stubs. */
49
+ readonly jsonSchema: Record<string, unknown>;
50
+ private readonly _validate;
51
+ private readonly _ajv;
52
+ readonly uiSchema?: Record<string, Record<string, unknown>>;
53
+ readonly ui?: StudioUIMetadata;
54
+ private readonly _describe;
55
+ private readonly _specDefaults;
56
+ private readonly _defaultAgentField;
57
+ readonly descriptionFallbackField?: string;
58
+ constructor(typedDef: TypedKindDefinition);
59
+ /** Load-time lint for `spec_defaults` (spec D5). Each default KEY must
60
+ * exist in schema.properties and its VALUE must validate against THAT
61
+ * property's subschema. `required` is intentionally IGNORED — defaults are
62
+ * a *partial* spec (autolab's real _DEFAULTS doesn't satisfy required).
63
+ * Twin of Python DeclarativeKindPort._lint_spec_defaults. */
64
+ private _lintSpecDefaults;
65
+ depFilters(): Record<string, string> | null;
66
+ getDefaultAgentName(doc: Document): string | null;
67
+ getLayerPolicies(_doc: Document): Record<string, LayerPolicy | string> | null;
68
+ parse(raw: Record<string, unknown>): unknown;
69
+ /** Display string for a doc (spec D3).
70
+ * - Template form (string): substitute `{field}` placeholders from the
71
+ * spec top level; a missing/None field renders as "".
72
+ * - Projection form ({path: field}): return the spec field verbatim (or
73
+ * null if absent).
74
+ * - No `describe` declared → null (today's behavior).
75
+ * Twin of Python DeclarativeKindPort.describe. */
76
+ describe(doc: Document): string | null;
77
+ private static readonly _PROJECTION_KEYS;
78
+ private static readonly _PROJECTION_MARKERS;
79
+ private static _isProjection;
80
+ /** Load-time lint for projection objects in `summary:` (spec D2). Unknown
81
+ * key → throw; exactly one resolver; `format`/`paths` exclusivity. Twin of
82
+ * Python `_lint_summary`. */
83
+ private static _lintSummary;
84
+ /** Dict-only walk over a dotted `a.b.c` path. Missing → null. */
85
+ private static _walkPath;
86
+ /** Decimal rounding that is byte-behavior-identical to CPython's built-in
87
+ * `round(value, ndigits)` — i.e. a faithful port of CPython `double_round`.
88
+ *
89
+ * CPython rounds the EXACT stored IEEE-754 double to `ndigits` decimal
90
+ * places, ties-to-even, on the *true binary* value. A naive
91
+ * `Math.round(value * 10^n) / 10^n` (round-half-away, and on the *scaled*
92
+ * double) diverges on the genuine half cases — e.g. `0.125@2` is exactly
93
+ * 1/8 so CPython ties to even → `0.12`, whereas `Math.round` gives `0.13`;
94
+ * and `2.675@2` stores as `2.67499…` so CPython → `2.67`. To match all of
95
+ * these we decompose the double into its exact rational `mantissa·2^exp2`,
96
+ * scale by `10^ndigits` with exact BigInt arithmetic, and round-half-to-even
97
+ * on the exact remainder. Verified against CPython `round` over a 20k-case
98
+ * Monte-Carlo (n∈{1,2,3,4}) plus the pinned hard cases: 0 mismatches.
99
+ *
100
+ * Real consumers only use round:4 (avg_score/cost); this keeps the deeper
101
+ * depths (round:2, the spec's #1 parity risk) identical too. */
102
+ private static _bankersRound;
103
+ private static _resolveProjection;
104
+ /** Declarative projection (F3 spec D2): when the KindDefinition declares
105
+ * `summary: {field: <plain default | projection object>}`, project the
106
+ * doc's spec. A PLAIN value keeps today's meaning (present field from
107
+ * spec, else the declared default). A PROJECTION object runs the closed
108
+ * vocabulary (count_of/path/paths/format + combinators). No declaration →
109
+ * null (today's behavior). Twin of Python DeclarativeKindPort.summary. */
110
+ summary(doc: Document): Record<string, unknown> | null;
111
+ promptTemplate(): string | null;
112
+ dependencies(): Record<string, string> | null;
113
+ schema(): Record<string, unknown> | null;
114
+ /**
115
+ * Preview blocks derived from the kind's JSON schema. Walks the
116
+ * top-level `properties` of `jsonSchema` and renders each one based on
117
+ * its declared type:
118
+ * - string with format=markdown OR maxLength>=400 → markdown block
119
+ * - string → fields entry
120
+ * - integer / number / boolean → fields entry
121
+ * - array of strings → fields entry (bullets)
122
+ * - array of objects / object → code block (json)
123
+ * - enum → fields entry
124
+ *
125
+ * Required fields surface first, optional after.
126
+ */
127
+ preview(doc: Document): PreviewBlock[];
128
+ static fromTyped(typedDef: TypedKindDefinition): DeclarativeKindPort;
129
+ }
130
+ /**
131
+ * Walk a JSON Schema's top-level `properties` and produce a uiSchema map
132
+ * keyed by field name. Required fields get `required: true` so the
133
+ * SchemaDrivenEditor can mark them visually if it chooses to.
134
+ */
135
+ export declare function deriveUiSchemaFromJsonSchema(jsonSchema: Record<string, unknown>): Record<string, Record<string, unknown>>;