@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.
Files changed (57) hide show
  1. package/LICENSE +89 -0
  2. package/README.md +62 -0
  3. package/package.json +57 -0
  4. package/src/applyset-diff-types.ts +158 -0
  5. package/src/applyset.ts +82 -0
  6. package/src/authoring-harness.ts +487 -0
  7. package/src/browser.ts +114 -0
  8. package/src/compose.ts +699 -0
  9. package/src/corpus.generated.ts +279 -0
  10. package/src/corpus.ts +1180 -0
  11. package/src/damage.ts +75 -0
  12. package/src/diagnostics.ts +59 -0
  13. package/src/diff-manifest-core.ts +393 -0
  14. package/src/diff-manifest.ts +5 -0
  15. package/src/docs-index.ts +105 -0
  16. package/src/dsl.ts +10 -0
  17. package/src/evaluate.ts +100 -0
  18. package/src/explain-core.ts +219 -0
  19. package/src/explain.ts +43 -0
  20. package/src/filter-manifest-core.ts +122 -0
  21. package/src/filter-manifest.ts +41 -0
  22. package/src/grants-core.ts +38 -0
  23. package/src/grants.ts +10 -0
  24. package/src/included-manifest-metadata-core.ts +63 -0
  25. package/src/included-manifest-metadata.ts +21 -0
  26. package/src/index.ts +30 -0
  27. package/src/inspect.ts +35 -0
  28. package/src/inspection.ts +239 -0
  29. package/src/lint.ts +540 -0
  30. package/src/manifest-text.ts +21 -0
  31. package/src/manifest.ts +403 -0
  32. package/src/metadata.ts +137 -0
  33. package/src/npc-dm-authority-projection.ts +95 -0
  34. package/src/npc-dm-documents.ts +339 -0
  35. package/src/npc-dm-presentation.ts +17 -0
  36. package/src/npc-dm-srd.ts +51 -0
  37. package/src/npc-dm-types.ts +723 -0
  38. package/src/npc-kinds.ts +404 -0
  39. package/src/npc-quests.ts +319 -0
  40. package/src/observation-tokens.browser.ts +31 -0
  41. package/src/observation-tokens.ts +27 -0
  42. package/src/owner-instance-read.ts +765 -0
  43. package/src/patch.ts +47 -0
  44. package/src/ref-tags.ts +149 -0
  45. package/src/reference.ts +48 -0
  46. package/src/row-identity.ts +105 -0
  47. package/src/row-kinds-data.ts +35 -0
  48. package/src/row-kinds.ts +93 -0
  49. package/src/scenario-guidance.ts +180 -0
  50. package/src/scoped-instance-read.ts +187 -0
  51. package/src/service-only-audience.ts +14 -0
  52. package/src/session-predicates.ts +6 -0
  53. package/src/spell.ts +119 -0
  54. package/src/tag-prefix-families.ts +143 -0
  55. package/src/tooling.browser.ts +397 -0
  56. package/src/tooling.ts +38 -0
  57. package/src/validate.ts +255 -0
package/LICENSE ADDED
@@ -0,0 +1,89 @@
1
+ # PolyForm Shield License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/shield/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
12
+
13
+ ## Distribution License
14
+
15
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
16
+
17
+ ## Notices
18
+
19
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
20
+
21
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
22
+
23
+ ## Changes and New Works License
24
+
25
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
+
27
+ ## Patent License
28
+
29
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
30
+
31
+ ## Noncompete
32
+
33
+ Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
34
+
35
+ ## Competition
36
+
37
+ Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
38
+
39
+ ## New Products
40
+
41
+ If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
42
+
43
+ ## Discontinued Products
44
+
45
+ You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
46
+
47
+ > Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
48
+
49
+ ## Sales of Business
50
+
51
+ If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
52
+
53
+ ## Fair Use
54
+
55
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
56
+
57
+ ## No Other Rights
58
+
59
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
60
+
61
+ ## Patent Defense
62
+
63
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
64
+
65
+ ## Violations
66
+
67
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
68
+
69
+ ## No Liability
70
+
71
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
72
+
73
+ ## Definitions
74
+
75
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
76
+
77
+ A **product** can be a good or service, or a combination of them.
78
+
79
+ **You** refers to the individual or entity agreeing to these terms.
80
+
81
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
82
+
83
+ **Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
84
+
85
+ **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
86
+
87
+ **Your licenses** are all the licenses granted to you for the software under these terms.
88
+
89
+ **Use** means anything you do with the software requiring one of your licenses.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @spellkave/world-author
2
+
3
+ Typed world-manifest authoring surface: builds manifest rows → a single-file
4
+ world manifest (TOML) for agent and code authors. The authoring counterpart to
5
+ [`@spellkave/sdk`](../spellkave-sdk)'s runtime actor surface.
6
+
7
+ ## Boundary (same as the SDK, sdk CLAUDE §1/§3)
8
+
9
+ This package serializes **typed rows**. It does **not** re-implement validation.
10
+ The Rust validator (`crates/spellkave-validate`, via `r_apply_world_manifest`) is
11
+ the source of truth; callers can use `spellkave-validate-wasm` for the same
12
+ parser/validator feedback before apply.
13
+
14
+ ## Bundle loading
15
+
16
+ `loadBundleChainDetailed({ rootManifestPath, resolveDependency })` loads an
17
+ explicitly named root and its dependency closure. It returns the familiar merged
18
+ row projection in `manifest` plus dependency-before-dependent `sources`; each
19
+ source preserves its absolute root path, declared bundle IDs, root
20
+ `schema_version`, `[metadata]`, and direct include paths. Its `fragments`
21
+ envelope retains each direct include's path, resolved path, and local
22
+ `[metadata]` tree in declaration order; the merged `manifest` remains a
23
+ row-only projection, so include metadata never becomes a second root. Direct
24
+ includes do not nest. `resolveDependency`
25
+ maps an authored dependency ID to its root TOML path. The legacy
26
+ `loadBundleChain(dir, fixturesRoot)` remains available for sibling
27
+ `<fixturesRoot>/<bundleId>/manifest.toml` layouts and returns only the merged
28
+ manifest.
29
+
30
+ ## Metadata values
31
+
32
+ `[metadata]` is an open JSON-compatible tree: strings, booleans, finite
33
+ numbers within JavaScript's safe integer range, arrays, and nested tables are
34
+ preserved through TOML → WASM JSON → TOML. TOML datetimes, `nan`/`inf`, JSON
35
+ `null`, and numbers outside ±9,007,199,254,740,991 are rejected rather than
36
+ silently changed. The schema version remains `1.0.0`: this is an additive
37
+ widening, so producers must not emit structured metadata until every deployed
38
+ consumer has updated from the former string-only reader.
39
+
40
+ Existing validator-control keys (`profile`, `entity_ids`, `fk_refs`, and their
41
+ related legacy CSV keys) remain strings. Supplying a structured value for one
42
+ is a fatal validation error; use a distinct open metadata key for new data.
43
+
44
+ ## Row vocabulary
45
+
46
+ The union of what the world-explorer co-evolution loops (#504) author:
47
+
48
+ - **Presence:** `entities`, `actors`, `actor_spatial_locations`
49
+ - **Actionable affordance chain:** `object_state_definitions`,
50
+ `capability_definitions`, `niche_definitions`, `spatial_niche_attachments`,
51
+ `outcome_templates`, `affordance_templates`, `action_definitions`,
52
+ `consequence_templates` (+ `SetEntityFlag` frame writes), `actor_capabilities`
53
+
54
+ Every array on `WorldManifest` is optional; `renderManifest` emits only the rows
55
+ present.
56
+
57
+ ## Commands
58
+
59
+ ```bash
60
+ npm run typecheck -w @spellkave/world-author
61
+ npm run test -w @spellkave/world-author
62
+ ```
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@spellkave/world-author",
3
+ "version": "0.0.0-bootstrap",
4
+ "description": "Typed world-manifest authoring surface — builds manifest rows -> TOML for agent/code authors, plus optional pre-flight validation. Validation is NOT a client-side reimplementation: it calls the SAME Rust validator (crates/spellkave-validate) compiled to wasm, so that crate stays the single source of truth (ADR-0009 D-2 preserved). Tracker: #504.",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "exports": {
9
+ "./npc-dm-documents": "./src/npc-dm-documents.ts",
10
+ "./npc-dm-presentation": "./src/npc-dm-presentation.ts",
11
+ "./npc-dm-srd": "./src/npc-dm-srd.ts",
12
+ "./npc-quests": "./src/npc-quests.ts",
13
+ "./npc-kinds": "./src/npc-kinds.ts",
14
+ "./corpus": "./src/corpus.ts",
15
+ ".": {
16
+ "types": "./src/index.ts",
17
+ "default": "./src/index.ts"
18
+ },
19
+ "./browser": {
20
+ "types": "./src/browser.ts",
21
+ "default": "./src/browser.ts"
22
+ },
23
+ "./tooling": {
24
+ "types": "./src/tooling.ts",
25
+ "browser": "./src/tooling.browser.ts",
26
+ "default": "./src/tooling.ts"
27
+ },
28
+ "./tooling-browser": {
29
+ "types": "./src/tooling.browser.ts",
30
+ "default": "./src/tooling.browser.ts"
31
+ },
32
+ "./observation-tokens": {
33
+ "types": "./src/observation-tokens.ts",
34
+ "browser": "./src/observation-tokens.browser.ts",
35
+ "default": "./src/observation-tokens.ts"
36
+ }
37
+ },
38
+ "files": [
39
+ "src"
40
+ ],
41
+ "dependencies": {
42
+ "@spellkave/tool-contracts": "0.0.0-bootstrap",
43
+ "smol-toml": "^1.9.1",
44
+ "@spellkave/validate-wasm": "0.1.0",
45
+ "@spellkave/authoring-wasm": "0.1.0"
46
+ },
47
+ "license": "PolyForm-Shield-1.0.0",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/b4mad-technologies/sk-sdk.git",
51
+ "directory": "packages/spellkave-world-author"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "registry": "https://registry.npmjs.org/"
56
+ }
57
+ }
@@ -0,0 +1,158 @@
1
+ // Wire shapes of `spellkave_authoring::diff_apply` (`sk diff` / `sk apply`,
2
+ // ADR-0145). Shared by the node (`applyset.ts`) and browser tooling entries.
3
+
4
+ import type { ApplysetPartEntry, ApplysetPartSource } from "./applyset";
5
+
6
+ export interface ApplysetRootInfo {
7
+ applyset: string | null;
8
+ /** Include paths in the root's declaration order (relative to its directory). */
9
+ includes: string[];
10
+ /** Bundles the root declares (the ones exported for drift). */
11
+ bundles: string[];
12
+ }
13
+
14
+ export type ApplysetBaseState = "known" | "unknown";
15
+
16
+ /** The server's applyset memory, as read through the live connection. */
17
+ export interface ApplysetMemory {
18
+ export_hashes?: Array<{ kind: string; key: string; export_hash: string }>;
19
+ root_path: string;
20
+ generation: number;
21
+ base_state: ApplysetBaseState;
22
+ parts: Array<{ path: string; entries: ApplysetPartEntry[] }>;
23
+ }
24
+
25
+ export interface ApplysetExtentScope {
26
+ publisher: boolean;
27
+ bundle_extents: string[];
28
+ memory: Array<{ applyset?: string; bundle_ids: string[] | null; entries: ApplysetPartEntry[] }>;
29
+ }
30
+
31
+ /** Public role facts and the connected sender's own live grants; no hidden subjects. */
32
+ export interface ApplysetAuthoritySnapshot {
33
+ extent_shapes?: Record<string, string>;
34
+ publisher: boolean;
35
+ scoped: boolean;
36
+ complete: boolean;
37
+ tick: number;
38
+ grants: Array<{
39
+ capability_id: string;
40
+ extent_kind_ref: string;
41
+ extent_ref: string;
42
+ expires_at_tick: number | null;
43
+ }>;
44
+ role_definitions: Array<{
45
+ role_id: string;
46
+ bundle_id: string;
47
+ display_name: string;
48
+ description: string;
49
+ capability_ids: string[];
50
+ }>;
51
+ role_aggregations: Array<{
52
+ role_id: string;
53
+ bundle_id: string;
54
+ description: string;
55
+ capability_ids: string[];
56
+ }>;
57
+ capability_definitions: Array<{
58
+ capability_id: string;
59
+ bundle_id: string;
60
+ actor_kind: string;
61
+ display_name: string;
62
+ description: string;
63
+ default_visibility: string;
64
+ }>;
65
+ bindings: Array<{
66
+ binding_id: string;
67
+ bundle_id: string;
68
+ role_id: string;
69
+ extent_kind_ref: string;
70
+ extent_ref: string;
71
+ realised: boolean;
72
+ }>;
73
+ }
74
+
75
+ export interface ApplysetAuthorityVerdict {
76
+ kind: string;
77
+ key: string;
78
+ code: string | null;
79
+ reason: string;
80
+ binding_id: string | null;
81
+ role_id: string | null;
82
+ extent_kind_ref: string | null;
83
+ extent_ref: string | null;
84
+ }
85
+
86
+ export interface ApplysetDiffInput {
87
+ applying_identity?: string;
88
+ force?: boolean;
89
+ places_read?: boolean;
90
+ not_exported?: Array<{ bundle_id: string; reason: string }>;
91
+ /** The root: its file name and text. */
92
+ root: ApplysetPartSource;
93
+ /** The root path the server records (relative to the worktree root). */
94
+ root_path: string;
95
+ /** Include file texts keyed by the path the root declares. */
96
+ files: Record<string, string>;
97
+ memory: ApplysetMemory | null;
98
+ prune: boolean;
99
+ /** Dependency bundles, for validation only. */
100
+ dependencies?: Array<{ root: ApplysetPartSource; fragments: ApplysetPartSource[] }>;
101
+ /** Live exports, for drift information only and prune place reconstruction. */
102
+ live?: Array<{ bundle_id: string; manifest_json: string }>;
103
+ /** Owner-subscription places for prune `entities` / `actor_spatial_locations`. */
104
+ live_places?: Array<{ kind: string; key: string; place_node_id: string }>;
105
+ extent_scope?: ApplysetExtentScope;
106
+ authority?: ApplysetAuthoritySnapshot;
107
+ }
108
+
109
+ export type ApplysetRowClass = "create" | "adopt" | "configure" | "move" | "prune" | "unchanged";
110
+ export type ApplysetLiveState = "same" | "drift" | "not_comparable";
111
+
112
+ export interface ApplysetClassifiedRow {
113
+ world_changed?: { state: "yes" | "no" } | { state: "unknown"; reason: string };
114
+ kind: string;
115
+ key: string;
116
+ bundle_id: string | null;
117
+ class: ApplysetRowClass;
118
+ part: string;
119
+ from_part?: string;
120
+ hash: string;
121
+ live?: ApplysetLiveState;
122
+ }
123
+
124
+ export interface ApplysetDiagnostic {
125
+ code: string;
126
+ severity: string;
127
+ message: string;
128
+ path: string;
129
+ hint?: string | null;
130
+ details?: unknown;
131
+ }
132
+
133
+ export interface ApplysetWarning {
134
+ code: string;
135
+ message: string;
136
+ details?: unknown;
137
+ }
138
+
139
+ export interface ApplysetDiffOutput {
140
+ seal_drift_not_checked?: string[];
141
+ conflicts: Array<{ kind: string; key: string; part: string; class: ApplysetRowClass }>;
142
+ not_checked: Array<{ kind: string; key: string; reason: string }>;
143
+ applyset: string;
144
+ root_path: string;
145
+ generation: number;
146
+ base_state: ApplysetBaseState | null;
147
+ rows: ApplysetClassifiedRow[];
148
+ parts: Array<{ path: string; entries: ApplysetPartEntry[] }>;
149
+ delta_toml: string;
150
+ send: boolean;
151
+ diagnostics: ApplysetDiagnostic[];
152
+ warnings: ApplysetWarning[];
153
+ values: Array<{ kind: string; key: string; part: string; live: string; file: string }>;
154
+ live_only: Array<{ kind: string; key: string; bundle_id: string | null }>;
155
+ extent_verdicts: Array<{ kind: string; key: string; code: string; owners: string[] }>;
156
+ placement_server_decides: Array<{ kind: string; key: string; bundle_id: string | null }>;
157
+ authority_verdicts?: ApplysetAuthorityVerdict[];
158
+ }
@@ -0,0 +1,82 @@
1
+ // Applyset part building and row identities (ADR-0145), computed in Rust
2
+ // (`spellkave-authoring`) and reached through wasm: TypeScript never derives a
3
+ // row's identity or hash itself (ADR-0144 D-5).
4
+
5
+ import {
6
+ applyset_root_info_json,
7
+ build_applyset_parts_json,
8
+ classify_and_build_delta_json,
9
+ live_manifest_row_identities_json,
10
+ manifest_row_identities_json,
11
+ } from "@spellkave/authoring-wasm";
12
+ import type {
13
+ ApplysetDiffInput,
14
+ ApplysetDiffOutput,
15
+ ApplysetRootInfo,
16
+ } from "./applyset-diff-types";
17
+
18
+ export type * from "./applyset-diff-types";
19
+
20
+ export interface ApplysetPartSource {
21
+ /** Path relative to the root's directory; the root's own file name for the root. */
22
+ path: string;
23
+ toml: string;
24
+ }
25
+
26
+ export interface ApplysetPartEntry {
27
+ kind: string;
28
+ key: string;
29
+ bundle_id: string | null;
30
+ hash: string;
31
+ export_hash?: string;
32
+ }
33
+
34
+ export interface ApplysetParts {
35
+ applyset: string;
36
+ root_path: string;
37
+ parts: Array<{ path: string; entries: ApplysetPartEntry[] }>;
38
+ duplicates: Array<{ kind: string; key: string; parts: string[]; identical: boolean }>;
39
+ untrackable: Array<{ part: string; kind: string; count: number }>;
40
+ /** A frame-write template whose blocks sit in more than one part (manifest-natural-keys 1.4). */
41
+ split_sets: Array<{ kind: string; key: string; parts: string[] }>;
42
+ }
43
+
44
+ export interface ManifestRowIdentities {
45
+ rows: ApplysetPartEntry[];
46
+ /** `[kind, count]` for kinds without a registered key. */
47
+ untrackable: Array<[string, number]>;
48
+ }
49
+
50
+ /** Parts of one applyset: the root and its include fragments in declaration order. */
51
+ export function buildApplysetParts(
52
+ root: ApplysetPartSource,
53
+ fragments: readonly ApplysetPartSource[],
54
+ ): ApplysetParts {
55
+ return JSON.parse(
56
+ build_applyset_parts_json(JSON.stringify({ root, fragments })),
57
+ ) as ApplysetParts;
58
+ }
59
+
60
+ /** Row identities and semantic hashes of one root manifest or include fragment. */
61
+ export function manifestRowIdentities(toml: string, isRoot: boolean): ManifestRowIdentities {
62
+ return JSON.parse(manifest_row_identities_json(toml, isRoot)) as ManifestRowIdentities;
63
+ }
64
+
65
+ /** The root's applyset name, include paths (declaration order) and declared bundles. */
66
+ export function applysetRootInfo(rootToml: string): ApplysetRootInfo {
67
+ return JSON.parse(applyset_root_info_json(rootToml)) as ApplysetRootInfo;
68
+ }
69
+
70
+ /**
71
+ * Classify the root's rows against the applyset memory and build the delta
72
+ * (`sk diff` / `sk apply`, ADR-0145). All of it runs in Rust
73
+ * (`spellkave-authoring` `diff_apply`); this is the JSON boundary only.
74
+ */
75
+ export function classifyAndBuildDelta(input: ApplysetDiffInput): ApplysetDiffOutput {
76
+ return JSON.parse(classify_and_build_delta_json(JSON.stringify(input))) as ApplysetDiffOutput;
77
+ }
78
+
79
+ /** Exact typed live identities, using the same Rust catalog as file identities. */
80
+ export function liveManifestRowIdentities(manifestJson: string): ManifestRowIdentities {
81
+ return JSON.parse(live_manifest_row_identities_json(manifestJson)) as ManifestRowIdentities;
82
+ }