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.
- package/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/adapters/embedding/onnx.d.ts +32 -0
- package/dist/adapters/embedding/onnx.js +51 -0
- package/dist/adapters/filesystem/cache.d.ts +16 -0
- package/dist/adapters/filesystem/cache.js +113 -0
- package/dist/adapters/filesystem/index.d.ts +2 -0
- package/dist/adapters/filesystem/index.js +2 -0
- package/dist/adapters/filesystem/source.d.ts +82 -0
- package/dist/adapters/filesystem/source.js +357 -0
- package/dist/adapters/postgres/index.d.ts +2 -0
- package/dist/adapters/postgres/index.js +2 -0
- package/dist/adapters/postgres/migrations.d.ts +14 -0
- package/dist/adapters/postgres/migrations.js +88 -0
- package/dist/adapters/postgres/source.d.ts +172 -0
- package/dist/adapters/postgres/source.js +569 -0
- package/dist/adapters/resolvers/github.d.ts +12 -0
- package/dist/adapters/resolvers/github.js +47 -0
- package/dist/adapters/resolvers/http.d.ts +22 -0
- package/dist/adapters/resolvers/http.js +145 -0
- package/dist/adapters/resolvers/index.d.ts +3 -0
- package/dist/adapters/resolvers/index.js +3 -0
- package/dist/adapters/resolvers/local.d.ts +24 -0
- package/dist/adapters/resolvers/local.js +132 -0
- package/dist/adapters/search/driver.d.ts +45 -0
- package/dist/adapters/search/driver.js +138 -0
- package/dist/adapters/search/migrations.d.ts +26 -0
- package/dist/adapters/search/migrations.js +58 -0
- package/dist/adapters/search/rrf.d.ts +23 -0
- package/dist/adapters/search/rrf.js +42 -0
- package/dist/adapters/search/sqlite-vec.d.ts +66 -0
- package/dist/adapters/search/sqlite-vec.js +294 -0
- package/dist/bootstrap.d.ts +45 -0
- package/dist/bootstrap.js +134 -0
- package/dist/extensions/agentskills/DOCS.md +18 -0
- package/dist/extensions/agentskills.d.ts +28 -0
- package/dist/extensions/agentskills.js +252 -0
- package/dist/extensions/agentsmd/DOCS.md +18 -0
- package/dist/extensions/agentsmd.d.ts +22 -0
- package/dist/extensions/agentsmd.js +170 -0
- package/dist/extensions/audit/kinds/audit-log.kind.yaml +148 -0
- package/dist/extensions/audit.d.ts +25 -0
- package/dist/extensions/audit.js +62 -0
- package/dist/extensions/automation/kinds/automation.kind.yaml +296 -0
- package/dist/extensions/automation/query.d.ts +49 -0
- package/dist/extensions/automation/query.js +77 -0
- package/dist/extensions/automation/write-guards.d.ts +59 -0
- package/dist/extensions/automation/write-guards.js +153 -0
- package/dist/extensions/automation.d.ts +41 -0
- package/dist/extensions/automation.js +54 -0
- package/dist/extensions/collab.d.ts +16 -0
- package/dist/extensions/collab.js +79 -0
- package/dist/extensions/doc/kinds/doc.kind.yaml +118 -0
- package/dist/extensions/doc.d.ts +25 -0
- package/dist/extensions/doc.js +10 -0
- package/dist/extensions/eval/kinds/eval-baseline.kind.yaml +65 -0
- package/dist/extensions/eval/kinds/eval-case.kind.yaml +140 -0
- package/dist/extensions/eval/kinds/eval-run.kind.yaml +134 -0
- package/dist/extensions/eval/kinds/eval-suite.kind.yaml +87 -0
- package/dist/extensions/eval.d.ts +24 -0
- package/dist/extensions/eval.js +31 -0
- package/dist/extensions/evidence/kinds/evidence.kind.yaml +92 -0
- package/dist/extensions/evidence.d.ts +17 -0
- package/dist/extensions/evidence.js +94 -0
- package/dist/extensions/federation.d.ts +22 -0
- package/dist/extensions/federation.js +173 -0
- package/dist/extensions/guardrails/DOCS.md +20 -0
- package/dist/extensions/guardrails.d.ts +31 -0
- package/dist/extensions/guardrails.js +228 -0
- package/dist/extensions/helix/DOCS-Actor.md +20 -0
- package/dist/extensions/helix/DOCS-Agent.md +20 -0
- package/dist/extensions/helix/DOCS-UseCase.md +20 -0
- package/dist/extensions/helix/layers.d.ts +12 -0
- package/dist/extensions/helix/layers.js +18 -0
- package/dist/extensions/helix/write-guards.d.ts +70 -0
- package/dist/extensions/helix/write-guards.js +172 -0
- package/dist/extensions/helix.d.ts +29 -0
- package/dist/extensions/helix.js +963 -0
- package/dist/extensions/helix_extras.d.ts +124 -0
- package/dist/extensions/helix_extras.js +328 -0
- package/dist/extensions/hooks.d.ts +31 -0
- package/dist/extensions/hooks.js +247 -0
- package/dist/extensions/kinddef/DOCS.md +24 -0
- package/dist/extensions/kinddef.d.ts +40 -0
- package/dist/extensions/kinddef.js +171 -0
- package/dist/extensions/lesson.d.ts +6 -0
- package/dist/extensions/lesson.js +194 -0
- package/dist/extensions/modelreg/kinds/model-profile.kind.yaml +155 -0
- package/dist/extensions/modelreg.d.ts +30 -0
- package/dist/extensions/modelreg.js +38 -0
- package/dist/extensions/recognizer.d.ts +34 -0
- package/dist/extensions/recognizer.js +272 -0
- package/dist/extensions/research.d.ts +32 -0
- package/dist/extensions/research.js +292 -0
- package/dist/extensions/safety.d.ts +33 -0
- package/dist/extensions/safety.js +230 -0
- package/dist/extensions/sdlc/kinds/adr.kind.yaml +136 -0
- package/dist/extensions/sdlc/kinds/archive-proposal.kind.yaml +107 -0
- package/dist/extensions/sdlc/kinds/changelog.kind.yaml +108 -0
- package/dist/extensions/sdlc/kinds/cognitive-policy.kind.yaml +470 -0
- package/dist/extensions/sdlc/kinds/forecast.kind.yaml +125 -0
- package/dist/extensions/sdlc/kinds/insight.kind.yaml +87 -0
- package/dist/extensions/sdlc/kinds/kaizen.kind.yaml +106 -0
- package/dist/extensions/sdlc/kinds/lesson-learned.kind.yaml +270 -0
- package/dist/extensions/sdlc/kinds/narrative.kind.yaml +189 -0
- package/dist/extensions/sdlc/kinds/pattern-insight.kind.yaml +204 -0
- package/dist/extensions/sdlc/kinds/postmortem.kind.yaml +168 -0
- package/dist/extensions/sdlc/kinds/pre-mortem.kind.yaml +145 -0
- package/dist/extensions/sdlc/kinds/prompt-template.kind.yaml +109 -0
- package/dist/extensions/sdlc/kinds/retrospective.kind.yaml +186 -0
- package/dist/extensions/sdlc/kinds/risk-register.kind.yaml +178 -0
- package/dist/extensions/sdlc/kinds/saved-view.kind.yaml +127 -0
- package/dist/extensions/sdlc/kinds/status-report.kind.yaml +129 -0
- package/dist/extensions/sdlc/kinds/synthesis-run.kind.yaml +279 -0
- package/dist/extensions/sdlc/kinds/synthesizer-state.kind.yaml +196 -0
- package/dist/extensions/sdlc/kinds/workflow-event.kind.yaml +195 -0
- package/dist/extensions/sdlc.d.ts +32 -0
- package/dist/extensions/sdlc.js +1318 -0
- package/dist/extensions/soulspec/DOCS.md +19 -0
- package/dist/extensions/soulspec.d.ts +22 -0
- package/dist/extensions/soulspec.js +287 -0
- package/dist/extensions/tenant.d.ts +6 -0
- package/dist/extensions/tenant.js +291 -0
- package/dist/extensions/testkit.d.ts +24 -0
- package/dist/extensions/testkit.js +211 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +102 -0
- package/dist/kernel/_text.d.ts +28 -0
- package/dist/kernel/_text.js +42 -0
- package/dist/kernel/bundle-handle.d.ts +83 -0
- package/dist/kernel/bundle-handle.js +184 -0
- package/dist/kernel/capabilities.d.ts +157 -0
- package/dist/kernel/capabilities.js +109 -0
- package/dist/kernel/collaborator-ports.d.ts +91 -0
- package/dist/kernel/collaborator-ports.js +1 -0
- package/dist/kernel/composition-resolver.d.ts +215 -0
- package/dist/kernel/composition-resolver.js +558 -0
- package/dist/kernel/composition.d.ts +10 -0
- package/dist/kernel/composition.js +1 -0
- package/dist/kernel/descriptor-loader.d.ts +13 -0
- package/dist/kernel/descriptor-loader.js +48 -0
- package/dist/kernel/document.d.ts +43 -0
- package/dist/kernel/document.js +71 -0
- package/dist/kernel/embedding.d.ts +28 -0
- package/dist/kernel/embedding.js +78 -0
- package/dist/kernel/errors.d.ts +62 -0
- package/dist/kernel/errors.js +82 -0
- package/dist/kernel/events.d.ts +6 -0
- package/dist/kernel/events.js +21 -0
- package/dist/kernel/evidence-capture.d.ts +69 -0
- package/dist/kernel/evidence-capture.js +138 -0
- package/dist/kernel/fs.d.ts +20 -0
- package/dist/kernel/fs.js +128 -0
- package/dist/kernel/generic-rw.d.ts +33 -0
- package/dist/kernel/generic-rw.js +235 -0
- package/dist/kernel/hooks.d.ts +172 -0
- package/dist/kernel/hooks.js +256 -0
- package/dist/kernel/index.d.ts +624 -0
- package/dist/kernel/index.js +1638 -0
- package/dist/kernel/instance.d.ts +211 -0
- package/dist/kernel/instance.js +487 -0
- package/dist/kernel/kind-registry.d.ts +183 -0
- package/dist/kernel/kind-registry.js +710 -0
- package/dist/kernel/kind_base.d.ts +106 -0
- package/dist/kernel/kind_base.js +244 -0
- package/dist/kernel/layer-resolver.d.ts +48 -0
- package/dist/kernel/layer-resolver.js +284 -0
- package/dist/kernel/lock-manager.d.ts +21 -0
- package/dist/kernel/lock-manager.js +43 -0
- package/dist/kernel/lock.d.ts +38 -0
- package/dist/kernel/lock.js +115 -0
- package/dist/kernel/meta.d.ts +135 -0
- package/dist/kernel/meta.js +817 -0
- package/dist/kernel/models.d.ts +3089 -0
- package/dist/kernel/models.js +764 -0
- package/dist/kernel/navigator.d.ts +36 -0
- package/dist/kernel/navigator.js +132 -0
- package/dist/kernel/port-surface.d.ts +33 -0
- package/dist/kernel/port-surface.js +180 -0
- package/dist/kernel/preview.d.ts +60 -0
- package/dist/kernel/preview.js +54 -0
- package/dist/kernel/prompt-budget.d.ts +39 -0
- package/dist/kernel/prompt-budget.js +43 -0
- package/dist/kernel/prompt-builder.d.ts +25 -0
- package/dist/kernel/prompt-builder.js +237 -0
- package/dist/kernel/protocols.d.ts +751 -0
- package/dist/kernel/protocols.js +493 -0
- package/dist/kernel/reports.d.ts +26 -0
- package/dist/kernel/reports.js +215 -0
- package/dist/kernel/resolver.d.ts +146 -0
- package/dist/kernel/resolver.js +232 -0
- package/dist/kernel/resource.d.ts +57 -0
- package/dist/kernel/resource.js +97 -0
- package/dist/kernel/runtime.d.ts +16 -0
- package/dist/kernel/runtime.js +18 -0
- package/dist/kernel/safety-scanner.d.ts +38 -0
- package/dist/kernel/safety-scanner.js +228 -0
- package/dist/kernel/serialize-to-files.d.ts +29 -0
- package/dist/kernel/serialize-to-files.js +23 -0
- package/dist/kernel/spec-access.d.ts +23 -0
- package/dist/kernel/spec-access.js +40 -0
- package/dist/kernel/studio_ui.d.ts +88 -0
- package/dist/kernel/studio_ui.js +135 -0
- package/dist/kernel/templates.d.ts +77 -0
- package/dist/kernel/templates.js +116 -0
- package/dist/kernel/tool-registry.d.ts +52 -0
- package/dist/kernel/tool-registry.js +89 -0
- package/dist/kernel/write-pipeline.d.ts +65 -0
- package/dist/kernel/write-pipeline.js +271 -0
- package/dist/kernel/writer-helpers.d.ts +24 -0
- package/dist/kernel/writer-helpers.js +42 -0
- package/dist/memory/decay.d.ts +31 -0
- package/dist/memory/decay.js +97 -0
- package/dist/memory/ecphory.d.ts +25 -0
- package/dist/memory/ecphory.js +178 -0
- package/dist/memory/encodingContext.d.ts +21 -0
- package/dist/memory/encodingContext.js +62 -0
- package/dist/memory/index.d.ts +23 -0
- package/dist/memory/index.js +23 -0
- package/dist/memory/memoryType.d.ts +7 -0
- package/dist/memory/memoryType.js +24 -0
- package/dist/memory/policy.d.ts +35 -0
- package/dist/memory/policy.js +35 -0
- package/dist/memory/retrieval.d.ts +21 -0
- package/dist/memory/retrieval.js +145 -0
- package/dist/testing/index.d.ts +8 -0
- package/dist/testing/index.js +8 -0
- package/dist/testing/recordSearchConformance.d.ts +43 -0
- package/dist/testing/recordSearchConformance.js +147 -0
- package/dist/viz/ascii.d.ts +7 -0
- package/dist/viz/ascii.js +60 -0
- package/dist/viz/health.d.ts +8 -0
- package/dist/viz/health.js +161 -0
- package/dist/viz/index.d.ts +10 -0
- package/dist/viz/index.js +10 -0
- package/dist/viz/matrix.d.ts +8 -0
- package/dist/viz/matrix.js +84 -0
- package/dist/viz/mermaid.d.ts +38 -0
- package/dist/viz/mermaid.js +706 -0
- package/package.json +82 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigator — namespace class extracting navigation/display logic
|
|
3
|
+
* from ManifestInstance.
|
|
4
|
+
*
|
|
5
|
+
* Usage: `mi.nav.describe(...)`, `mi.nav.summary()`, `mi.nav.inventory()`, etc.
|
|
6
|
+
*
|
|
7
|
+
* This is an extraction (Chunk 2 of the kernel simplification plan).
|
|
8
|
+
* The original methods on ManifestInstance are preserved as one-line
|
|
9
|
+
* delegates; the canonical logic lives here.
|
|
10
|
+
*/
|
|
11
|
+
import { type PreviewBlock } from "./preview.js";
|
|
12
|
+
import type { ManifestInstance } from "./instance.js";
|
|
13
|
+
export declare class Navigator {
|
|
14
|
+
private host;
|
|
15
|
+
constructor(host: ManifestInstance);
|
|
16
|
+
/**
|
|
17
|
+
* Describe a single document.
|
|
18
|
+
* Equivalent to `mi.describe(kind, name)`.
|
|
19
|
+
*/
|
|
20
|
+
describe(kind: string, name: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Produce a text summary of the manifest.
|
|
23
|
+
* Equivalent to `mi.summary()`.
|
|
24
|
+
*/
|
|
25
|
+
summary(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Produce a structured inventory of the manifest.
|
|
28
|
+
* Equivalent to `mi.inventory()`.
|
|
29
|
+
*/
|
|
30
|
+
inventory(): Record<string, unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* Polymorphic per-kind preview.
|
|
33
|
+
* Equivalent to `mi.renderDoc(kind, name)`.
|
|
34
|
+
*/
|
|
35
|
+
renderDoc(kind: string, name: string): PreviewBlock[];
|
|
36
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigator — namespace class extracting navigation/display logic
|
|
3
|
+
* from ManifestInstance.
|
|
4
|
+
*
|
|
5
|
+
* Usage: `mi.nav.describe(...)`, `mi.nav.summary()`, `mi.nav.inventory()`, etc.
|
|
6
|
+
*
|
|
7
|
+
* This is an extraction (Chunk 2 of the kernel simplification plan).
|
|
8
|
+
* The original methods on ManifestInstance are preserved as one-line
|
|
9
|
+
* delegates; the canonical logic lives here.
|
|
10
|
+
*/
|
|
11
|
+
import { genericSpecDump } from "./preview.js";
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Navigator
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
export class Navigator {
|
|
16
|
+
host;
|
|
17
|
+
constructor(host) {
|
|
18
|
+
this.host = host;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Describe a single document.
|
|
22
|
+
* Equivalent to `mi.describe(kind, name)`.
|
|
23
|
+
*/
|
|
24
|
+
describe(kind, name) {
|
|
25
|
+
const doc = this.host._one(kind, name);
|
|
26
|
+
if (!doc)
|
|
27
|
+
return `${kind}/${name} not found`;
|
|
28
|
+
const kinds = this.host._kinds;
|
|
29
|
+
const kp = kinds.get(`${doc.apiVersion}\0${doc.kind}`);
|
|
30
|
+
if (kp) {
|
|
31
|
+
const custom = kp.describe(doc);
|
|
32
|
+
if (custom)
|
|
33
|
+
return custom;
|
|
34
|
+
}
|
|
35
|
+
const lines = [
|
|
36
|
+
`Name: ${doc.name}`,
|
|
37
|
+
`Kind: ${doc.kind}`,
|
|
38
|
+
`ApiVersion: ${doc.apiVersion}`,
|
|
39
|
+
];
|
|
40
|
+
const desc = doc.metadata.description;
|
|
41
|
+
if (desc) {
|
|
42
|
+
lines.push(`Description: ${desc}`);
|
|
43
|
+
}
|
|
44
|
+
return lines.join("\n");
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Produce a text summary of the manifest.
|
|
48
|
+
* Equivalent to `mi.summary()`.
|
|
49
|
+
*/
|
|
50
|
+
summary() {
|
|
51
|
+
const kinds = this.host.listKinds();
|
|
52
|
+
const lines = [`Scope: ${this.host.scope}`, `Kinds: ${kinds.length}`];
|
|
53
|
+
for (const k of kinds) {
|
|
54
|
+
const docs = this.host._all(k);
|
|
55
|
+
lines.push(` ${k}: ${docs.length} (${docs.map((d) => d.name).join(", ")})`);
|
|
56
|
+
}
|
|
57
|
+
return lines.join("\n");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Produce a structured inventory of the manifest.
|
|
61
|
+
* Equivalent to `mi.inventory()`.
|
|
62
|
+
*/
|
|
63
|
+
inventory() {
|
|
64
|
+
const kinds = this.host._kinds;
|
|
65
|
+
const kindsData = {};
|
|
66
|
+
for (const kindName of this.host.listKinds()) {
|
|
67
|
+
const docs = this.host._all(kindName);
|
|
68
|
+
const docEntries = [];
|
|
69
|
+
for (const doc of docs) {
|
|
70
|
+
const entry = {
|
|
71
|
+
name: doc.name,
|
|
72
|
+
description: doc.metadata.description ?? "",
|
|
73
|
+
};
|
|
74
|
+
const key = `${doc.apiVersion}\0${doc.kind}`;
|
|
75
|
+
const kp = kinds.get(key);
|
|
76
|
+
if (kp) {
|
|
77
|
+
const filters = kp.depFilters();
|
|
78
|
+
if (filters) {
|
|
79
|
+
const refs = {};
|
|
80
|
+
const spec = doc.spec;
|
|
81
|
+
for (const [specField] of Object.entries(filters)) {
|
|
82
|
+
const val = spec[specField];
|
|
83
|
+
if (val != null) {
|
|
84
|
+
refs[specField] = val;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (Object.keys(refs).length > 0) {
|
|
88
|
+
entry.refs = refs;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const extra = kp.summary(doc);
|
|
92
|
+
if (extra) {
|
|
93
|
+
Object.assign(entry, extra);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
docEntries.push(entry);
|
|
97
|
+
}
|
|
98
|
+
kindsData[kindName] = {
|
|
99
|
+
count: docs.length,
|
|
100
|
+
documents: docEntries,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const comp = this.host.compositionResult;
|
|
104
|
+
return {
|
|
105
|
+
scope: this.host.scope,
|
|
106
|
+
total_documents: this.host.documents.length,
|
|
107
|
+
kinds: kindsData,
|
|
108
|
+
composition: {
|
|
109
|
+
valid: comp.missing.length === 0,
|
|
110
|
+
resolved: comp.resolved,
|
|
111
|
+
missing: comp.missing,
|
|
112
|
+
warnings: comp.warnings,
|
|
113
|
+
deferred: comp.deferred,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Polymorphic per-kind preview.
|
|
119
|
+
* Equivalent to `mi.renderDoc(kind, name)`.
|
|
120
|
+
*/
|
|
121
|
+
renderDoc(kind, name) {
|
|
122
|
+
const doc = this.host._one(kind, name);
|
|
123
|
+
if (!doc)
|
|
124
|
+
return [];
|
|
125
|
+
const kinds = this.host._kinds;
|
|
126
|
+
const kp = kinds.get(`${doc.apiVersion}\0${doc.kind}`);
|
|
127
|
+
if (kp && typeof kp.preview === "function") {
|
|
128
|
+
return kp.preview(doc);
|
|
129
|
+
}
|
|
130
|
+
return genericSpecDump(doc);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PORT_SURFACE — static member manifest of the public port interfaces
|
|
3
|
+
* (s-dna-port-surface-parity).
|
|
4
|
+
*
|
|
5
|
+
* TS interfaces are erased at runtime, so the port-surface parity test
|
|
6
|
+
* can't introspect them the way the Python twin introspects its
|
|
7
|
+
* `typing.Protocol`s. Instead, this module declares each port's member
|
|
8
|
+
* list as a const — and BINDS it to the real interface at compile time:
|
|
9
|
+
*
|
|
10
|
+
* - every listed member must be a `keyof` the interface (no phantom
|
|
11
|
+
* members), and
|
|
12
|
+
* - the list must be EXHAUSTIVE (a member added to the interface but
|
|
13
|
+
* not listed here fails `tsc --noEmit` with the missing name in the
|
|
14
|
+
* error type).
|
|
15
|
+
*
|
|
16
|
+
* `tests/port-surface-parity.test.ts` then compares this manifest against
|
|
17
|
+
* the shared fixture `tests/parity-fixtures/port-surface-parity.json`
|
|
18
|
+
* (which the Py suite checks against the real Protocols) — so the two
|
|
19
|
+
* SDKs' port surfaces can only drift through an explicit, justified
|
|
20
|
+
* fixture edit.
|
|
21
|
+
*/
|
|
22
|
+
import type { BundleEntryReadable, KernelAttachable, Versionable } from "./capabilities.js";
|
|
23
|
+
/**
|
|
24
|
+
* Compile-time existence proof for the capability interfaces tracked as
|
|
25
|
+
* NAMES (not keys) in the fixture's `CapabilityProtocols` pseudo-port —
|
|
26
|
+
* deleting/renaming one breaks this alias.
|
|
27
|
+
*/
|
|
28
|
+
export type CapabilityProtocolsProof = [
|
|
29
|
+
BundleEntryReadable,
|
|
30
|
+
KernelAttachable,
|
|
31
|
+
Versionable
|
|
32
|
+
];
|
|
33
|
+
export declare const PORT_SURFACE: Readonly<Record<string, readonly string[]>>;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PORT_SURFACE — static member manifest of the public port interfaces
|
|
3
|
+
* (s-dna-port-surface-parity).
|
|
4
|
+
*
|
|
5
|
+
* TS interfaces are erased at runtime, so the port-surface parity test
|
|
6
|
+
* can't introspect them the way the Python twin introspects its
|
|
7
|
+
* `typing.Protocol`s. Instead, this module declares each port's member
|
|
8
|
+
* list as a const — and BINDS it to the real interface at compile time:
|
|
9
|
+
*
|
|
10
|
+
* - every listed member must be a `keyof` the interface (no phantom
|
|
11
|
+
* members), and
|
|
12
|
+
* - the list must be EXHAUSTIVE (a member added to the interface but
|
|
13
|
+
* not listed here fails `tsc --noEmit` with the missing name in the
|
|
14
|
+
* error type).
|
|
15
|
+
*
|
|
16
|
+
* `tests/port-surface-parity.test.ts` then compares this manifest against
|
|
17
|
+
* the shared fixture `tests/parity-fixtures/port-surface-parity.json`
|
|
18
|
+
* (which the Py suite checks against the real Protocols) — so the two
|
|
19
|
+
* SDKs' port surfaces can only drift through an explicit, justified
|
|
20
|
+
* fixture edit.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Compile-time exhaustive-keys binder. `keysOf<T>()([...])` only accepts
|
|
24
|
+
* an array whose entries are ALL keys of `T` and which covers EVERY key
|
|
25
|
+
* of `T` — otherwise the intersection with the `__missing_members__`
|
|
26
|
+
* brand fails to typecheck, naming the missing key(s) in the error.
|
|
27
|
+
*/
|
|
28
|
+
function keysOf() {
|
|
29
|
+
return (keys) => keys;
|
|
30
|
+
}
|
|
31
|
+
export const PORT_SURFACE = {
|
|
32
|
+
SourcePort: keysOf()([
|
|
33
|
+
"supportsReaders",
|
|
34
|
+
"loadBootstrapDocs",
|
|
35
|
+
"loadAll",
|
|
36
|
+
"resolveRef",
|
|
37
|
+
"loadLayer",
|
|
38
|
+
"close",
|
|
39
|
+
"listDocRefs",
|
|
40
|
+
"loadOne",
|
|
41
|
+
"query",
|
|
42
|
+
"count",
|
|
43
|
+
"capabilities",
|
|
44
|
+
]),
|
|
45
|
+
// OWN members only — the inherited SourcePort half is tracked above.
|
|
46
|
+
WritableSourcePort: keysOf()([
|
|
47
|
+
"saveDocument",
|
|
48
|
+
"deleteDocument",
|
|
49
|
+
"listVersions",
|
|
50
|
+
"getVersion",
|
|
51
|
+
"publish",
|
|
52
|
+
]),
|
|
53
|
+
CachePort: keysOf()([
|
|
54
|
+
"has",
|
|
55
|
+
"store",
|
|
56
|
+
"loadKey",
|
|
57
|
+
"loadAll",
|
|
58
|
+
]),
|
|
59
|
+
ResolverPort: keysOf()([
|
|
60
|
+
"resolve",
|
|
61
|
+
"cacheKey",
|
|
62
|
+
]),
|
|
63
|
+
ReaderPort: keysOf()([
|
|
64
|
+
"detect",
|
|
65
|
+
"read",
|
|
66
|
+
"_ownerContainer",
|
|
67
|
+
]),
|
|
68
|
+
WriterPort: keysOf()([
|
|
69
|
+
"canWrite",
|
|
70
|
+
"write",
|
|
71
|
+
"serialize",
|
|
72
|
+
]),
|
|
73
|
+
// The optional presentation slice KindPort extends. Py twin: the
|
|
74
|
+
// KindPresentation capability Protocol (typing-only, kept OFF the
|
|
75
|
+
// runtime_checkable KindPort so the H1 isinstance gate never requires
|
|
76
|
+
// these members) — s-dna-kindport-descriptor-schema.
|
|
77
|
+
KindPresentation: keysOf()([
|
|
78
|
+
"docs",
|
|
79
|
+
"descriptionFallbackField",
|
|
80
|
+
"uiSchema",
|
|
81
|
+
"graphStyle",
|
|
82
|
+
"asciiIcon",
|
|
83
|
+
"displayLabel",
|
|
84
|
+
"visibleInBackend",
|
|
85
|
+
"preview",
|
|
86
|
+
"graphMeta",
|
|
87
|
+
]),
|
|
88
|
+
KindPort: keysOf()([
|
|
89
|
+
"apiVersion",
|
|
90
|
+
"kind",
|
|
91
|
+
"alias",
|
|
92
|
+
"origin",
|
|
93
|
+
"scope",
|
|
94
|
+
"isRoot",
|
|
95
|
+
"isPromptTarget",
|
|
96
|
+
"promptTargetPriority",
|
|
97
|
+
"flattenInContext",
|
|
98
|
+
"storage",
|
|
99
|
+
"isRuntimeArtifact",
|
|
100
|
+
"isSchemaAffecting",
|
|
101
|
+
"isOverlayable",
|
|
102
|
+
"scopeInheritable",
|
|
103
|
+
"plane",
|
|
104
|
+
"depFilters",
|
|
105
|
+
"getDefaultAgentName",
|
|
106
|
+
"getLayerPolicies",
|
|
107
|
+
"parse",
|
|
108
|
+
"describe",
|
|
109
|
+
"summary",
|
|
110
|
+
"promptTemplate",
|
|
111
|
+
"schema",
|
|
112
|
+
"dependencies",
|
|
113
|
+
// Inherited KindPresentation slice (keyof includes extends-members;
|
|
114
|
+
// the exhaustive binder requires listing them here too).
|
|
115
|
+
"docs",
|
|
116
|
+
"descriptionFallbackField",
|
|
117
|
+
"uiSchema",
|
|
118
|
+
"graphStyle",
|
|
119
|
+
"asciiIcon",
|
|
120
|
+
"displayLabel",
|
|
121
|
+
"visibleInBackend",
|
|
122
|
+
"preview",
|
|
123
|
+
"graphMeta",
|
|
124
|
+
]),
|
|
125
|
+
ToolPort: keysOf()([
|
|
126
|
+
"name",
|
|
127
|
+
"group",
|
|
128
|
+
"description",
|
|
129
|
+
"summary",
|
|
130
|
+
"argsSchema",
|
|
131
|
+
"hitl",
|
|
132
|
+
"scope",
|
|
133
|
+
"source",
|
|
134
|
+
"getCallable",
|
|
135
|
+
]),
|
|
136
|
+
ExtensionHost: keysOf()([
|
|
137
|
+
"hooks",
|
|
138
|
+
"kind",
|
|
139
|
+
"kindFromDescriptor",
|
|
140
|
+
"reader",
|
|
141
|
+
"writer",
|
|
142
|
+
"on",
|
|
143
|
+
"onVeto",
|
|
144
|
+
"tool",
|
|
145
|
+
"compositionProfile",
|
|
146
|
+
]),
|
|
147
|
+
Extension: keysOf()([
|
|
148
|
+
"name",
|
|
149
|
+
"version",
|
|
150
|
+
"register",
|
|
151
|
+
"templates",
|
|
152
|
+
]),
|
|
153
|
+
RecordSearchProvider: keysOf()([
|
|
154
|
+
"search",
|
|
155
|
+
]),
|
|
156
|
+
EmbeddingPort: keysOf()([
|
|
157
|
+
"modelId",
|
|
158
|
+
"dims",
|
|
159
|
+
"embed",
|
|
160
|
+
]),
|
|
161
|
+
SourceCapabilities: keysOf()([
|
|
162
|
+
"source",
|
|
163
|
+
"drafts",
|
|
164
|
+
"versions",
|
|
165
|
+
"layers",
|
|
166
|
+
"bundleRead",
|
|
167
|
+
"bundleWrite",
|
|
168
|
+
"kernelAttachable",
|
|
169
|
+
"granularList",
|
|
170
|
+
"granularOne",
|
|
171
|
+
"queryPushdown",
|
|
172
|
+
]),
|
|
173
|
+
// Interface NAMES (see CapabilityProtocolsProof above for the
|
|
174
|
+
// compile-time existence binding).
|
|
175
|
+
CapabilityProtocols: [
|
|
176
|
+
"BundleEntryReadable",
|
|
177
|
+
"KernelAttachable",
|
|
178
|
+
"Versionable",
|
|
179
|
+
],
|
|
180
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document preview API.
|
|
3
|
+
*
|
|
4
|
+
* The Studio's "preview" pane consumes structured `PreviewBlock`s instead
|
|
5
|
+
* of raw markdown so each kind can render however makes sense (markdown,
|
|
6
|
+
* code, tabular fields). The polymorphism lives inside each KindPort
|
|
7
|
+
* (`KindPort.preview?`); this module is only the type definition,
|
|
8
|
+
* generic fallback, and a cross-document consumer scan.
|
|
9
|
+
*/
|
|
10
|
+
import type { Document } from "./document.js";
|
|
11
|
+
import type { ManifestInstance } from "./instance.js";
|
|
12
|
+
/**
|
|
13
|
+
* A single renderable section of a document preview. Documents can produce
|
|
14
|
+
* multiple blocks (e.g. a Soul has SOUL.md + STYLE.md + soul.json), which
|
|
15
|
+
* the Studio renders stacked.
|
|
16
|
+
*
|
|
17
|
+
* `kind` is the renderer hint:
|
|
18
|
+
* - "markdown" → MarkdownBlock (prose, headings, lists)
|
|
19
|
+
* - "code" → CodeBlock (yaml, json, plain text in monospace)
|
|
20
|
+
* - "fields" → FieldsBlock (key/value pairs)
|
|
21
|
+
* - "empty" → no body, just the title (used for empty states)
|
|
22
|
+
*/
|
|
23
|
+
export type PreviewBlockKind = "markdown" | "code" | "fields" | "empty";
|
|
24
|
+
export interface PreviewBlock {
|
|
25
|
+
kind: PreviewBlockKind;
|
|
26
|
+
/** Section header shown above the body. */
|
|
27
|
+
title: string;
|
|
28
|
+
/** Free-form body content. Type depends on `kind`. */
|
|
29
|
+
body?: string;
|
|
30
|
+
/** Used by code blocks to choose syntax highlighting. */
|
|
31
|
+
language?: string;
|
|
32
|
+
/** Used by fields blocks. Ordered. */
|
|
33
|
+
fields?: Array<{
|
|
34
|
+
label: string;
|
|
35
|
+
value: string;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Last-resort renderer used by `ManifestInstance.renderDoc` when the
|
|
40
|
+
* KindPort doesn't implement `preview()`. Always returns SOMETHING so the
|
|
41
|
+
* Studio never has a blank pane — even unknown kinds get a JSON dump of
|
|
42
|
+
* their spec.
|
|
43
|
+
*/
|
|
44
|
+
export declare function genericSpecDump(doc: Document): PreviewBlock[];
|
|
45
|
+
/**
|
|
46
|
+
* Walk every document in the manifest and return those that reference the
|
|
47
|
+
* given target via a dep_filters declaration on their KindPort.
|
|
48
|
+
*
|
|
49
|
+
* Uses `instance.iterDocDeps(doc)` under the hood — the kernel method
|
|
50
|
+
* that dynamically walks `KindPort.depFilters()` for each doc. No
|
|
51
|
+
* hardcoded field-to-kind map needed; any extension that declares its
|
|
52
|
+
* deps via depFilters participates automatically.
|
|
53
|
+
*/
|
|
54
|
+
export declare function findConsumers(instance: ManifestInstance, target: {
|
|
55
|
+
kind: string;
|
|
56
|
+
name: string;
|
|
57
|
+
}): Array<{
|
|
58
|
+
kind: string;
|
|
59
|
+
name: string;
|
|
60
|
+
}>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Last-resort renderer used by `ManifestInstance.renderDoc` when the
|
|
3
|
+
* KindPort doesn't implement `preview()`. Always returns SOMETHING so the
|
|
4
|
+
* Studio never has a blank pane — even unknown kinds get a JSON dump of
|
|
5
|
+
* their spec.
|
|
6
|
+
*/
|
|
7
|
+
export function genericSpecDump(doc) {
|
|
8
|
+
const spec = (doc.spec ?? {});
|
|
9
|
+
if (!spec || Object.keys(spec).length === 0) {
|
|
10
|
+
return [{ kind: "empty", title: `${doc.kind} (empty spec)` }];
|
|
11
|
+
}
|
|
12
|
+
return [
|
|
13
|
+
{
|
|
14
|
+
kind: "code",
|
|
15
|
+
title: `${doc.kind} spec`,
|
|
16
|
+
body: JSON.stringify(spec, null, 2),
|
|
17
|
+
language: "json",
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Walk every document in the manifest and return those that reference the
|
|
23
|
+
* given target via a dep_filters declaration on their KindPort.
|
|
24
|
+
*
|
|
25
|
+
* Uses `instance.iterDocDeps(doc)` under the hood — the kernel method
|
|
26
|
+
* that dynamically walks `KindPort.depFilters()` for each doc. No
|
|
27
|
+
* hardcoded field-to-kind map needed; any extension that declares its
|
|
28
|
+
* deps via depFilters participates automatically.
|
|
29
|
+
*/
|
|
30
|
+
export function findConsumers(instance, target) {
|
|
31
|
+
const out = [];
|
|
32
|
+
const seen = new Set();
|
|
33
|
+
const iterFn = instance.iterDocDeps;
|
|
34
|
+
for (const doc of instance.documents) {
|
|
35
|
+
if (doc.kind === target.kind && doc.name === target.name)
|
|
36
|
+
continue;
|
|
37
|
+
const deps = iterFn?.call(instance, doc) ?? [];
|
|
38
|
+
let hit = false;
|
|
39
|
+
for (const dep of deps) {
|
|
40
|
+
if (dep.targetKind !== target.kind)
|
|
41
|
+
continue;
|
|
42
|
+
if (dep.names.includes(target.name)) {
|
|
43
|
+
hit = true;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const key = `${doc.kind}/${doc.name}`;
|
|
48
|
+
if (hit && !seen.has(key)) {
|
|
49
|
+
seen.add(key);
|
|
50
|
+
out.push({ kind: doc.kind, name: doc.name });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt-budget estimation + enforcement helpers.
|
|
3
|
+
*
|
|
4
|
+
* 1:1 parity with Python `dna/kernel/prompt_budget.py`.
|
|
5
|
+
*
|
|
6
|
+
* Conservative token estimator + instruction-budget evaluator used by the
|
|
7
|
+
* write-path guard (`src/extensions/helix/write-guards.ts` ::
|
|
8
|
+
* promptBudgetGuard) that blocks a strict/voice Agent whose instruction
|
|
9
|
+
* exceeds its model's `instruction_token_cap`.
|
|
10
|
+
*
|
|
11
|
+
* CONTRACT — never hardcode token caps: the cap the evaluator receives
|
|
12
|
+
* ALWAYS comes from the ModelProfile registry
|
|
13
|
+
* (`kernel.modelProfile(idOrAlias)`), never from a literal in code.
|
|
14
|
+
* Motivated by a real outage: a 17269-token voice persona silently
|
|
15
|
+
* exceeded the realtime model's 16384-token session-instructions cap.
|
|
16
|
+
*/
|
|
17
|
+
/** Conservative (over-counts); mirrors the Python CHARS_PER_TOKEN. */
|
|
18
|
+
export declare const CHARS_PER_TOKEN = 3.5;
|
|
19
|
+
export declare class PromptBudgetExceededError extends Error {
|
|
20
|
+
readonly modelId: string;
|
|
21
|
+
readonly estimatedTokens: number;
|
|
22
|
+
readonly cap: number;
|
|
23
|
+
readonly agentName: string;
|
|
24
|
+
constructor(opts: {
|
|
25
|
+
modelId: string;
|
|
26
|
+
estimatedTokens: number;
|
|
27
|
+
cap: number;
|
|
28
|
+
agentName: string;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export declare function estimateTokens(charCount: number): number;
|
|
32
|
+
export interface BudgetVerdict {
|
|
33
|
+
exceeded: boolean;
|
|
34
|
+
estimatedTokens: number;
|
|
35
|
+
cap: number;
|
|
36
|
+
}
|
|
37
|
+
export declare function evaluateInstructionBudget(instruction: string, opts: {
|
|
38
|
+
cap: number;
|
|
39
|
+
}): BudgetVerdict;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt-budget estimation + enforcement helpers.
|
|
3
|
+
*
|
|
4
|
+
* 1:1 parity with Python `dna/kernel/prompt_budget.py`.
|
|
5
|
+
*
|
|
6
|
+
* Conservative token estimator + instruction-budget evaluator used by the
|
|
7
|
+
* write-path guard (`src/extensions/helix/write-guards.ts` ::
|
|
8
|
+
* promptBudgetGuard) that blocks a strict/voice Agent whose instruction
|
|
9
|
+
* exceeds its model's `instruction_token_cap`.
|
|
10
|
+
*
|
|
11
|
+
* CONTRACT — never hardcode token caps: the cap the evaluator receives
|
|
12
|
+
* ALWAYS comes from the ModelProfile registry
|
|
13
|
+
* (`kernel.modelProfile(idOrAlias)`), never from a literal in code.
|
|
14
|
+
* Motivated by a real outage: a 17269-token voice persona silently
|
|
15
|
+
* exceeded the realtime model's 16384-token session-instructions cap.
|
|
16
|
+
*/
|
|
17
|
+
/** Conservative (over-counts); mirrors the Python CHARS_PER_TOKEN. */
|
|
18
|
+
export const CHARS_PER_TOKEN = 3.5;
|
|
19
|
+
export class PromptBudgetExceededError extends Error {
|
|
20
|
+
modelId;
|
|
21
|
+
estimatedTokens;
|
|
22
|
+
cap;
|
|
23
|
+
agentName;
|
|
24
|
+
constructor(opts) {
|
|
25
|
+
super(`Agent '${opts.agentName}' instruction is ~${opts.estimatedTokens} tokens, ` +
|
|
26
|
+
`over the ${opts.cap}-token instruction cap of model '${opts.modelId}'. ` +
|
|
27
|
+
`Trim the instruction or move detail to tool-discoverable docs. ` +
|
|
28
|
+
`(The cap comes from the model's ModelProfile doc — update the ` +
|
|
29
|
+
`profile if the model's real cap changed; never hardcode caps.)`);
|
|
30
|
+
this.name = "PromptBudgetExceededError";
|
|
31
|
+
this.modelId = opts.modelId;
|
|
32
|
+
this.estimatedTokens = opts.estimatedTokens;
|
|
33
|
+
this.cap = opts.cap;
|
|
34
|
+
this.agentName = opts.agentName;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function estimateTokens(charCount) {
|
|
38
|
+
return Math.ceil(charCount / CHARS_PER_TOKEN);
|
|
39
|
+
}
|
|
40
|
+
export function evaluateInstructionBudget(instruction, opts) {
|
|
41
|
+
const tok = estimateTokens((instruction ?? "").length);
|
|
42
|
+
return { exceeded: tok > opts.cap, estimatedTokens: tok, cap: opts.cap };
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptBuilder — namespace class extracting prompt-related logic
|
|
3
|
+
* from ManifestInstance.
|
|
4
|
+
*
|
|
5
|
+
* Usage: `mi.prompt.build()` — equivalent to `mi.buildPrompt()`.
|
|
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 { ManifestInstance, BuildPromptOpts } from "./instance.js";
|
|
12
|
+
export declare class PromptBuilder {
|
|
13
|
+
private host;
|
|
14
|
+
constructor(host: ManifestInstance);
|
|
15
|
+
/**
|
|
16
|
+
* Build the final prompt string for the given (or default) agent.
|
|
17
|
+
* Equivalent to `mi.buildPrompt(opts)`.
|
|
18
|
+
*/
|
|
19
|
+
build(opts?: BuildPromptOpts): Promise<string>;
|
|
20
|
+
private _findAgent;
|
|
21
|
+
private _buildContext;
|
|
22
|
+
private _renderPrompt;
|
|
23
|
+
private _mustacheRender;
|
|
24
|
+
private static _getDescription;
|
|
25
|
+
}
|