@spellkave/world-author 0.0.0-bootstrap
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 +89 -0
- package/README.md +62 -0
- package/package.json +57 -0
- package/src/applyset-diff-types.ts +158 -0
- package/src/applyset.ts +82 -0
- package/src/authoring-harness.ts +487 -0
- package/src/browser.ts +114 -0
- package/src/compose.ts +699 -0
- package/src/corpus.generated.ts +279 -0
- package/src/corpus.ts +1180 -0
- package/src/damage.ts +75 -0
- package/src/diagnostics.ts +59 -0
- package/src/diff-manifest-core.ts +393 -0
- package/src/diff-manifest.ts +5 -0
- package/src/docs-index.ts +105 -0
- package/src/dsl.ts +10 -0
- package/src/evaluate.ts +100 -0
- package/src/explain-core.ts +219 -0
- package/src/explain.ts +43 -0
- package/src/filter-manifest-core.ts +122 -0
- package/src/filter-manifest.ts +41 -0
- package/src/grants-core.ts +38 -0
- package/src/grants.ts +10 -0
- package/src/included-manifest-metadata-core.ts +63 -0
- package/src/included-manifest-metadata.ts +21 -0
- package/src/index.ts +30 -0
- package/src/inspect.ts +35 -0
- package/src/inspection.ts +239 -0
- package/src/lint.ts +540 -0
- package/src/manifest-text.ts +21 -0
- package/src/manifest.ts +403 -0
- package/src/metadata.ts +137 -0
- package/src/npc-dm-authority-projection.ts +95 -0
- package/src/npc-dm-documents.ts +339 -0
- package/src/npc-dm-presentation.ts +17 -0
- package/src/npc-dm-srd.ts +51 -0
- package/src/npc-dm-types.ts +723 -0
- package/src/npc-kinds.ts +404 -0
- package/src/npc-quests.ts +319 -0
- package/src/observation-tokens.browser.ts +31 -0
- package/src/observation-tokens.ts +27 -0
- package/src/owner-instance-read.ts +765 -0
- package/src/patch.ts +47 -0
- package/src/ref-tags.ts +149 -0
- package/src/reference.ts +48 -0
- package/src/row-identity.ts +105 -0
- package/src/row-kinds-data.ts +35 -0
- package/src/row-kinds.ts +93 -0
- package/src/scenario-guidance.ts +180 -0
- package/src/scoped-instance-read.ts +187 -0
- package/src/service-only-audience.ts +14 -0
- package/src/session-predicates.ts +6 -0
- package/src/spell.ts +119 -0
- package/src/tag-prefix-families.ts +143 -0
- package/src/tooling.browser.ts +397 -0
- package/src/tooling.ts +38 -0
- package/src/validate.ts +255 -0
package/src/inspect.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parse_manifest_toml_to_json } from "@spellkave/validate-wasm";
|
|
2
|
+
import { inspectRowRefs, inspectSchemaManifest, type ManifestInspection } from "./inspection";
|
|
3
|
+
import { ROW_KIND_NATURAL_KEY } from "./row-kinds";
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
findRowByCompositeKey,
|
|
7
|
+
type InboundRowRef,
|
|
8
|
+
inspectSchemaManifest,
|
|
9
|
+
type ManifestInspection,
|
|
10
|
+
type ManifestSummary,
|
|
11
|
+
type OutboundRowRef,
|
|
12
|
+
outboundRefsExcluding,
|
|
13
|
+
refTagOutboundRefs,
|
|
14
|
+
} from "./inspection";
|
|
15
|
+
|
|
16
|
+
export function inspectManifest(toml: string): ManifestInspection {
|
|
17
|
+
return inspectSchemaManifest(
|
|
18
|
+
JSON.parse(parse_manifest_toml_to_json(toml)) as Record<string, unknown>,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* `inspectRowRefs` pre-bound to the package's own `ROW_KIND_NATURAL_KEY` —
|
|
24
|
+
* the entry point every consumer outside this package should call (e.g.
|
|
25
|
+
* `spellkave_query`'s `refs` output); `inspectRowRefs` itself stays
|
|
26
|
+
* dependency-free (a plain `Record<string, unknown>` walk, no wasm import)
|
|
27
|
+
* so it can be unit-tested without the wasm boundary.
|
|
28
|
+
*/
|
|
29
|
+
export function inspectRowReferences(
|
|
30
|
+
manifest: Record<string, unknown>,
|
|
31
|
+
kind: string,
|
|
32
|
+
id: string,
|
|
33
|
+
): ReturnType<typeof inspectRowRefs> {
|
|
34
|
+
return inspectRowRefs(manifest, ROW_KIND_NATURAL_KEY, kind, id);
|
|
35
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { type RefTagFamily, resolveRefTagValue } from "./ref-tags";
|
|
2
|
+
import { bundleScope, resolveTagPrefixFamily, visibleRefTagFamilies } from "./tag-prefix-families";
|
|
3
|
+
|
|
4
|
+
export interface ManifestInspection {
|
|
5
|
+
manifest: Record<string, unknown>;
|
|
6
|
+
summary: ManifestSummary;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ManifestSummary {
|
|
10
|
+
bundleIds: string[];
|
|
11
|
+
rowKinds: Record<string, number>;
|
|
12
|
+
rowRefs: Record<string, string[]>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
16
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Field-name heuristic shared by outbound/inbound ref computation: an `*_id`/`*_key`/`*_ref`-suffixed (or bare `id`) string field, excluding `bundle_id`/`source` (provenance, not a reference). */
|
|
20
|
+
function isRefField(key: string): boolean {
|
|
21
|
+
if (key === "bundle_id" || key === "source") return false;
|
|
22
|
+
return key === "id" || key.endsWith("_id") || key.endsWith("_key") || key.endsWith("_ref");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function stringRefs(row: Record<string, unknown>): string[] {
|
|
26
|
+
const refs: string[] = [];
|
|
27
|
+
for (const [key, value] of Object.entries(row)) {
|
|
28
|
+
if (typeof value !== "string") continue;
|
|
29
|
+
if (isRefField(key)) refs.push(`${key}=${value}`);
|
|
30
|
+
}
|
|
31
|
+
return refs;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** One row's outbound reference: a field on it pointing at another row's natural key value. */
|
|
35
|
+
export interface OutboundRowRef {
|
|
36
|
+
field: string;
|
|
37
|
+
value: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** One row elsewhere in the manifest whose own outbound ref points AT the queried row. */
|
|
41
|
+
export interface InboundRowRef {
|
|
42
|
+
kind: string;
|
|
43
|
+
id: string;
|
|
44
|
+
field: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Both ref directions for one authored row, `{kind, id}` — the #1968
|
|
49
|
+
* definition-lookup gap's ref-traversal capability (`spellkave_query`'s
|
|
50
|
+
* `refs` output). `outbound`: fields on THIS row pointing elsewhere, reusing
|
|
51
|
+
* `stringRefs`'s existing heuristic. `inbound`: every OTHER row anywhere in
|
|
52
|
+
* `manifest` whose own outbound ref points at `id` — built by inverting the
|
|
53
|
+
* outbound edge list once per call (no index persisted; a query call is not
|
|
54
|
+
* a hot path).
|
|
55
|
+
*
|
|
56
|
+
* Both directions exclude the row's OWN natural-key field (`ROW_KIND_
|
|
57
|
+
* NATURAL_KEY[kind]`) from counting as a "ref" — that field is the row's
|
|
58
|
+
* identity, not a pointer to something else, so without this exclusion
|
|
59
|
+
* every row would trivially "reference itself" (its own `capability_id`
|
|
60
|
+
* column satisfies the same `*_id`-suffix heuristic `stringRefs` uses for
|
|
61
|
+
* every other field) and inbound lookups would report a row as its own
|
|
62
|
+
* referrer. This is a deliberate refinement over `stringRefs`'s raw output
|
|
63
|
+
* (which the pre-existing per-kind `ManifestSummary.rowRefs` still returns
|
|
64
|
+
* unfiltered, unchanged, for full backward compatibility with `spellkave_
|
|
65
|
+
* manifest_inspect` callers) — see `inspectSchemaManifest` above.
|
|
66
|
+
*/
|
|
67
|
+
/**
|
|
68
|
+
* Outbound refs for ONE already-resolved row, generalized over an arbitrary
|
|
69
|
+
* exclusion set rather than `inspectRowRefs`'s single `rowKindNaturalKey[kind]`
|
|
70
|
+
* field (finding #9, srd-cc battle-test ledger, 2026-07-26): a composite-keyed
|
|
71
|
+
* satellite row (e.g. a `*_tag` row, identity = `{parent_field, "tag"}`) has
|
|
72
|
+
* TWO identity fields, not one, so `inspectRowRefs`'s own single-field
|
|
73
|
+
* exclusion can't be reused as-is for it. Same `isRefField` heuristic,
|
|
74
|
+
* factored out so both callers (this file's `inspectRowRefs`, and
|
|
75
|
+
* `spellkave_query`'s composite-key detail path) share one exclusion rule
|
|
76
|
+
* rather than drifting. Inbound-ref discovery for composite-keyed rows is
|
|
77
|
+
* NOT covered here — see the composite-key detail caller's own doc comment
|
|
78
|
+
* for why that half is deferred.
|
|
79
|
+
*/
|
|
80
|
+
export function outboundRefsExcluding(
|
|
81
|
+
row: Record<string, unknown>,
|
|
82
|
+
excludeFields: readonly string[],
|
|
83
|
+
): OutboundRowRef[] {
|
|
84
|
+
const excluded = new Set(excludeFields);
|
|
85
|
+
const outbound: OutboundRowRef[] = [];
|
|
86
|
+
for (const [field, value] of Object.entries(row)) {
|
|
87
|
+
if (typeof value !== "string") continue;
|
|
88
|
+
if (excluded.has(field)) continue; // identity, not a reference
|
|
89
|
+
if (isRefField(field)) outbound.push({ field, value });
|
|
90
|
+
}
|
|
91
|
+
return outbound;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Outbound refs for a `*_tag` satellite row's `tag` VALUE (finding #2,
|
|
96
|
+
* srd-cc battle-test ledger, 2026-07-27; design draft `packages/spellkave-
|
|
97
|
+
* srd-cc/ledger/designs/finding-02-typed-tag-refs.md`): `outboundRefsExcluding`'s
|
|
98
|
+
* `isRefField` heuristic never recognizes `tag` as a ref field — it's a bare
|
|
99
|
+
* field name, not `*_id`/`*_key`/`*_ref` — even when its STRING VALUE encodes
|
|
100
|
+
* a pointer (e.g. `srd.ability.wis`) at a prefix in the CALLER-SUPPLIED
|
|
101
|
+
* `refTagFamilies` list. This resolves that value against the family's
|
|
102
|
+
* `targetKind` and, if it resolves, reports the RESOLVED FULL ROW ID (e.g.
|
|
103
|
+
* `srd/wis`), not the bare tag value `wis` — so a caller can immediately
|
|
104
|
+
* chase it by re-querying `{kind: targetKind, id: resolvedId}` (`spellkave_
|
|
105
|
+
* query`'s own documented "chase a reference" idiom). Yields nothing for a
|
|
106
|
+
* row with no `tag` field, an unrecognized prefix, an empty/omitted
|
|
107
|
+
* `refTagFamilies` list, or a value that doesn't resolve (that last case is
|
|
108
|
+
* `./lint.ts`'s `dangling-ref-tag`'s job to flag, not this function's).
|
|
109
|
+
*
|
|
110
|
+
* `refTagFamilies` is never seeded by this package (`./ref-tags.ts`'s
|
|
111
|
+
* header) — defaults to empty, so a caller that doesn't opt in (today,
|
|
112
|
+
* `@spellkave/tool-authoring`'s `spellkave_query` composite-key detail
|
|
113
|
+
* path, pending a manifest-level tag-vocabulary declaration surface
|
|
114
|
+
* proposed via OpenSpec) gets no ref-tag resolution, not a crash.
|
|
115
|
+
*/
|
|
116
|
+
export function refTagOutboundRefs(
|
|
117
|
+
manifest: Record<string, unknown>,
|
|
118
|
+
row: Record<string, unknown>,
|
|
119
|
+
refTagFamilies: readonly RefTagFamily[] = [],
|
|
120
|
+
): OutboundRowRef[] {
|
|
121
|
+
const tag = row.tag;
|
|
122
|
+
if (typeof tag !== "string") return [];
|
|
123
|
+
const family = resolveTagPrefixFamily(
|
|
124
|
+
tag,
|
|
125
|
+
visibleRefTagFamilies(
|
|
126
|
+
manifest,
|
|
127
|
+
typeof row.bundle_id === "string" ? row.bundle_id : undefined,
|
|
128
|
+
refTagFamilies,
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
if (family === undefined) return [];
|
|
132
|
+
const visible =
|
|
133
|
+
family.declaringBundleId === undefined
|
|
134
|
+
? undefined
|
|
135
|
+
: bundleScope(manifest, family.declaringBundleId);
|
|
136
|
+
const resolved = resolveRefTagValue(
|
|
137
|
+
manifest,
|
|
138
|
+
family.targetKind,
|
|
139
|
+
family.naturalKeyField,
|
|
140
|
+
tag.slice(family.prefix.length),
|
|
141
|
+
tag,
|
|
142
|
+
visible,
|
|
143
|
+
);
|
|
144
|
+
return resolved === undefined
|
|
145
|
+
? []
|
|
146
|
+
: [{ field: `tag:${family.prefix.slice(0, -1)}`, value: resolved }];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Find ONE row of `kind` by its ordered composite-key VALUES (finding #9,
|
|
151
|
+
* srd-cc battle-test ledger, 2026-07-26) — the composite-key sibling of the
|
|
152
|
+
* single-field `row[keyField] === id` lookup `inspectRowRefs`/`spellkave_
|
|
153
|
+
* query`'s natural-key detail path already does. `keyParts[i]` must equal
|
|
154
|
+
* `row[compositeFields[i]]` for every field, in order — an exact match, no
|
|
155
|
+
* partial/prefix lookup. Manifest semantics (which row a composite key
|
|
156
|
+
* resolves to), kept separate from HOW a caller encodes that key as one
|
|
157
|
+
* opaque string id — that encoding is a tool-facing UX decision, not a
|
|
158
|
+
* manifest fact, so it stays in the caller (`spellkave_query`'s own
|
|
159
|
+
* composite-id join/split).
|
|
160
|
+
*/
|
|
161
|
+
export function findRowByCompositeKey(
|
|
162
|
+
manifest: Record<string, unknown>,
|
|
163
|
+
kind: string,
|
|
164
|
+
compositeFields: readonly string[],
|
|
165
|
+
keyParts: readonly string[],
|
|
166
|
+
): Record<string, unknown> | undefined {
|
|
167
|
+
const rows = manifest[kind];
|
|
168
|
+
if (!Array.isArray(rows)) return undefined;
|
|
169
|
+
return (rows as Record<string, unknown>[]).find(
|
|
170
|
+
(row) => isRecord(row) && compositeFields.every((field, i) => row[field] === keyParts[i]),
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function inspectRowRefs(
|
|
175
|
+
manifest: Record<string, unknown>,
|
|
176
|
+
rowKindNaturalKey: Readonly<Record<string, string>>,
|
|
177
|
+
kind: string,
|
|
178
|
+
id: string,
|
|
179
|
+
): { outbound: OutboundRowRef[]; inbound: InboundRowRef[] } {
|
|
180
|
+
const keyField = rowKindNaturalKey[kind];
|
|
181
|
+
const rowsOf = (k: string): Record<string, unknown>[] => {
|
|
182
|
+
const rows = manifest[k];
|
|
183
|
+
return Array.isArray(rows) ? (rows as Record<string, unknown>[]) : [];
|
|
184
|
+
};
|
|
185
|
+
const own = keyField !== undefined ? rowsOf(kind).find((r) => r[keyField] === id) : undefined;
|
|
186
|
+
|
|
187
|
+
const outbound: OutboundRowRef[] =
|
|
188
|
+
own !== undefined ? outboundRefsExcluding(own, keyField !== undefined ? [keyField] : []) : [];
|
|
189
|
+
|
|
190
|
+
const inbound: InboundRowRef[] = [];
|
|
191
|
+
for (const [otherKind, rows] of Object.entries(manifest)) {
|
|
192
|
+
if (!Array.isArray(rows)) continue;
|
|
193
|
+
const otherKeyField = rowKindNaturalKey[otherKind];
|
|
194
|
+
for (const row of rows) {
|
|
195
|
+
if (!isRecord(row)) continue;
|
|
196
|
+
const otherId =
|
|
197
|
+
otherKeyField !== undefined && typeof row[otherKeyField] === "string"
|
|
198
|
+
? (row[otherKeyField] as string)
|
|
199
|
+
: undefined;
|
|
200
|
+
if (otherId === undefined) continue;
|
|
201
|
+
for (const [field, value] of Object.entries(row)) {
|
|
202
|
+
if (typeof value !== "string" || value !== id) continue;
|
|
203
|
+
if (field === otherKeyField) continue; // identity, not a reference
|
|
204
|
+
if (!isRefField(field)) continue;
|
|
205
|
+
if (otherKind === kind && otherId === id) continue; // never a row's own field pointing at itself
|
|
206
|
+
inbound.push({ kind: otherKind, id: otherId, field });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return { outbound, inbound };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function inspectSchemaManifest(manifest: Record<string, unknown>): ManifestInspection {
|
|
215
|
+
const rowKinds: Record<string, number> = {};
|
|
216
|
+
const rowRefs: Record<string, string[]> = {};
|
|
217
|
+
|
|
218
|
+
for (const [kind, rows] of Object.entries(manifest)) {
|
|
219
|
+
if (!Array.isArray(rows)) continue;
|
|
220
|
+
rowKinds[kind] = rows.length;
|
|
221
|
+
const refs = rows.flatMap((row) => (isRecord(row) ? stringRefs(row) : []));
|
|
222
|
+
if (refs.length > 0) rowRefs[kind] = refs;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const bundles = Array.isArray(manifest.bundles) ? manifest.bundles : [];
|
|
226
|
+
const bundleIds = bundles
|
|
227
|
+
.filter(isRecord)
|
|
228
|
+
.map((bundle) => bundle.bundle_id)
|
|
229
|
+
.filter((id): id is string => typeof id === "string");
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
manifest,
|
|
233
|
+
summary: {
|
|
234
|
+
bundleIds,
|
|
235
|
+
rowKinds,
|
|
236
|
+
rowRefs,
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|