@sharpee/stdlib 1.0.8 → 1.1.1

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 (2) hide show
  1. package/README.md +55 -66
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Standard library for the Sharpee IF Platform - 48 standard IF actions with four-phase pattern (validate/execute/report/blocked).
4
4
 
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @sharpee/stdlib
9
+ ```
10
+
5
11
  ## Overview
6
12
 
7
13
  The `@sharpee/stdlib` package provides the core IF functionality:
@@ -13,12 +19,12 @@ The `@sharpee/stdlib` package provides the core IF functionality:
13
19
 
14
20
  ## Architecture
15
21
 
16
- The stdlib implements Sharpee's three-phase command processing:
22
+ The stdlib implements Sharpee's command processing pipeline:
17
23
 
18
24
  ```
19
25
  Input Text
20
26
 
21
- [Parser] - Grammar analysis only
27
+ [Parser] - Grammar analysis only (@sharpee/parser-en-us)
22
28
 
23
29
  ParsedCommand - Structured but unresolved
24
30
 
@@ -26,26 +32,27 @@ ParsedCommand - Structured but unresolved
26
32
 
27
33
  ValidatedCommand - Ready for execution
28
34
 
29
- [Actions] - Business logic
35
+ [Actions] - Four-phase: validate/execute/report/blocked
30
36
 
31
37
  SemanticEvents - What happened
32
38
  ```
33
39
 
34
- ## Parser
40
+ ## Parser Contracts
35
41
 
36
- The parser performs purely grammatical analysis without world knowledge:
42
+ The concrete parser implementation lives in the language package
43
+ (`@sharpee/parser-en-us`). stdlib re-exports the parser and vocabulary
44
+ contracts (from `@sharpee/if-domain`) plus the `ParserFactory` used to register
45
+ and create parsers:
37
46
 
38
47
  ```typescript
39
- import { BasicParser } from '@sharpee/stdlib/parser';
48
+ import { ParserFactory } from '@sharpee/stdlib';
49
+ import { EnglishParser } from '@sharpee/parser-en-us';
50
+ import { EnglishLanguageProvider } from '@sharpee/lang-en-us';
40
51
 
41
- const parser = new BasicParser();
42
- parser.registerVocabulary(standardVocabulary);
52
+ ParserFactory.registerParser('en-US', EnglishParser);
53
+ const parser = ParserFactory.createParser('en-US', new EnglishLanguageProvider());
43
54
 
44
- const result = parser.parse("take the red ball");
45
- // Returns ParsedCommand with:
46
- // - action: "TAKE"
47
- // - directObject: { text: "red ball", candidates: ["ball", "red"] }
48
- // - pattern: "VERB_OBJ"
55
+ const result = parser.parse('take the red ball');
49
56
  ```
50
57
 
51
58
  ## Validator
@@ -53,7 +60,7 @@ const result = parser.parse("take the red ball");
53
60
  The validator resolves entities and checks preconditions:
54
61
 
55
62
  ```typescript
56
- import { CommandValidator } from '@sharpee/stdlib/validation';
63
+ import { CommandValidator } from '@sharpee/stdlib';
57
64
 
58
65
  const validator = new CommandValidator(world, actionRegistry);
59
66
 
@@ -85,21 +92,28 @@ const validated = validator.validate(parsedCommand, {
85
92
  Standard IF actions are included:
86
93
 
87
94
  ```typescript
88
- import {
95
+ import {
89
96
  takingAction,
90
97
  droppingAction,
91
98
  examiningAction,
92
99
  goingAction,
93
- openingAction
94
- } from '@sharpee/stdlib/actions';
100
+ openingAction
101
+ } from '@sharpee/stdlib';
95
102
 
96
- // Actions implement the Action interface:
103
+ // Actions implement the four-phase Action interface (ADR-051):
97
104
  interface Action {
98
105
  id: string;
99
- execute(command: ValidatedCommand, context: ActionContext): SemanticEvent[];
106
+ validate(context: ActionContext): ValidationResult; // checks, no mutations
107
+ execute(context: ActionContext): void; // mutations only
108
+ report(context: ActionContext): ISemanticEvent[]; // events from final state
109
+ blocked?(context: ActionContext, result: ValidationResult): ISemanticEvent[];
100
110
  }
101
111
  ```
102
112
 
113
+ > See `packages/stdlib/CLAUDE.md` for capability dispatch (ADR-090) — how
114
+ > entity-specific verbs (LOWER, TURN, WAVE) are handled via traits + behaviors
115
+ > rather than per-action branching.
116
+
103
117
  ### Available Actions (48 Total)
104
118
 
105
119
  **Movement**: going, entering, exiting, climbing
@@ -115,71 +129,46 @@ interface Action {
115
129
 
116
130
  ## Language System
117
131
 
118
- Message formatting and resolution:
119
-
120
- ```typescript
121
- import { IFMessageResolver } from '@sharpee/stdlib/messages';
132
+ stdlib does not contain English prose. Actions emit semantic events carrying
133
+ **message IDs** (defined in each action's `*-messages.ts`); the language package
134
+ (`@sharpee/lang-en-us`) maps those IDs to text via its formatter chain
135
+ (ADR-095/ADR-158). This keeps all user-facing text in the language layer.
122
136
 
123
- const resolver = new IFMessageResolver();
124
- resolver.registerBundle('en-US', enUSBundle);
137
+ ## Vocabulary Contracts
125
138
 
126
- // Format messages with parameters
127
- const message = resolver.resolve('item_taken', {
128
- item: 'golden key'
129
- });
130
- // "You take the golden key."
131
- ```
132
-
133
- ## Vocabulary
134
-
135
- Standard English vocabulary for IF:
136
-
137
- ```typescript
138
- import { standardVocabulary } from '@sharpee/stdlib/vocabulary';
139
-
140
- // Includes common IF words:
141
- // - Verbs: take, drop, examine, go, etc.
142
- // - Prepositions: in, on, under, with, etc.
143
- // - Articles: the, a, an
144
- // - Common nouns and adjectives
145
- ```
139
+ stdlib re-exports the vocabulary contracts and registry (from
140
+ `@sharpee/if-domain`) `VocabularyEntry`, `PartOfSpeech`, `VocabularyProvider`,
141
+ `vocabularyRegistry`, etc. The actual English word lists live in
142
+ `@sharpee/lang-en-us`.
146
143
 
147
144
  ## Integration Example
148
145
 
149
146
  ```typescript
150
- import {
151
- BasicParser,
147
+ import {
148
+ ParserFactory,
152
149
  CommandValidator,
153
- ActionRegistry,
154
- standardActions,
155
- standardVocabulary
150
+ StandardActionRegistry,
151
+ standardActions
156
152
  } from '@sharpee/stdlib';
153
+ import { EnglishParser } from '@sharpee/parser-en-us';
154
+ import { EnglishLanguageProvider } from '@sharpee/lang-en-us';
157
155
 
158
156
  // Set up parser
159
- const parser = new BasicParser();
160
- parser.registerVocabulary(standardVocabulary);
157
+ ParserFactory.registerParser('en-US', EnglishParser);
158
+ const parser = ParserFactory.createParser('en-US', new EnglishLanguageProvider());
161
159
 
162
160
  // Set up actions
163
- const actionRegistry = new ActionRegistry();
161
+ const actionRegistry = new StandardActionRegistry();
164
162
  standardActions.forEach(action => actionRegistry.register(action));
165
163
 
166
164
  // Set up validator
167
165
  const validator = new CommandValidator(world, actionRegistry);
168
-
169
- // Process a command
170
- const parsed = parser.parse("take brass key");
171
- if (parsed.success) {
172
- const validated = validator.validate(parsed.value, validationContext);
173
- if (validated.success) {
174
- const events = validated.value.actionHandler.execute(
175
- validated.value,
176
- actionContext
177
- );
178
- // Process events...
179
- }
180
- }
181
166
  ```
182
167
 
168
+ > In practice you rarely wire these by hand — `@sharpee/engine` and the build
169
+ > toolchain assemble the parser, validator, action registry, and language
170
+ > provider for you from the story's config.
171
+
183
172
  ## Design Philosophy
184
173
 
185
174
  The stdlib follows Sharpee's core principles:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sharpee/stdlib",
3
- "version": "1.0.8",
3
+ "version": "1.1.1",
4
4
  "description": "Standard library for Sharpee IF Platform - actions, commands, and game mechanics",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -12,12 +12,12 @@
12
12
  }
13
13
  },
14
14
  "dependencies": {
15
- "@sharpee/core": "^1.0.8",
16
- "@sharpee/if-domain": "^1.0.8",
17
- "@sharpee/if-services": "^1.0.8",
18
- "@sharpee/lang-en-us": "^1.0.8",
19
- "@sharpee/text-blocks": "^1.0.8",
20
- "@sharpee/world-model": "^1.0.8"
15
+ "@sharpee/core": "^1.1.1",
16
+ "@sharpee/if-domain": "^1.1.1",
17
+ "@sharpee/if-services": "^1.1.1",
18
+ "@sharpee/lang-en-us": "^1.1.1",
19
+ "@sharpee/text-blocks": "^1.1.1",
20
+ "@sharpee/world-model": "^1.1.1"
21
21
  },
22
22
  "keywords": [
23
23
  "interactive-fiction",