pawsona 0.1.0a1__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pawsona contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: pawsona
3
+ Version: 0.1.0a1
4
+ Summary: Train personalities, not commands.
5
+ Author: esmacimsit
6
+ Maintainer: esmacimsit
7
+ License-Expression: MIT
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: PyYAML>=6.0.2
12
+ Dynamic: license-file
13
+
14
+ # Pawsona
15
+
16
+ Train personalities, not commands.
17
+
18
+ Pawsona is a terminal-based pet personality and training simulator inspired by reinforcement learning, memory, adaptation, generalization, and overfitting.
19
+
20
+ The first public version focuses on dogs. The behavior model is intentionally simple: it is a small scoring engine for playable training loops, not a biologically realistic simulator.
21
+
22
+ ## Current Status
23
+
24
+ This repository is in the early CLI phase. Pawsona can load built-in pet profiles, inspect their model state, create new YAML profiles, and generate the first simple behavior-model actions.
25
+
26
+ ## Try It
27
+
28
+ After release, the main install command will be:
29
+
30
+ ```bash
31
+ pip install pawsona
32
+ ```
33
+
34
+ Primary CLI:
35
+
36
+ ```bash
37
+ pawsona --help
38
+ ```
39
+
40
+ Short alias:
41
+
42
+ ```bash
43
+ paw --help
44
+ ```
45
+
46
+ If `paw` conflicts with another command on your machine, use `pawsona`.
47
+
48
+ ## Environment
49
+
50
+ Create and activate the conda environment:
51
+
52
+ ```bash
53
+ conda create -n paw python=3.11 pip
54
+ conda activate paw
55
+ ```
56
+
57
+ Install the project components from `requirements.txt`:
58
+
59
+ ```bash
60
+ python -m pip install -r requirements.txt
61
+ pawsona --help
62
+ ```
63
+
64
+ ## Inspect A Pet
65
+
66
+ ```bash
67
+ pawsona inspect hermes
68
+ pawsona inspect hera
69
+ ```
70
+
71
+ ## Create A Pet
72
+
73
+ ```bash
74
+ pawsona create
75
+ ```
76
+
77
+ Trait questions use a `1` to `5` scale and are normalized into `0.0` to `1.0` YAML values.
78
+
79
+ ## Generate An Action
80
+
81
+ ```bash
82
+ pawsona act hermes
83
+ pawsona act hera
84
+ ```
85
+
86
+ ## Train In The Terminal
87
+
88
+ ```bash
89
+ pawsona play hermes
90
+ pawsona play hera
91
+ ```
92
+
93
+ Training sessions run for 10 rounds by default. Feedback options are `reward`, `praise`, `ignore`, and `correct`.
94
+
95
+ Training updates are session-only until persistence lands in the next milestone.
96
+
97
+ ## Project Shape
98
+
99
+ ```text
100
+ pawsona/
101
+ cli.py
102
+ behavior.py
103
+ pet.py
104
+ simple_yaml.py
105
+ training.py
106
+ pets/
107
+ hermes.yaml
108
+ hera.yaml
109
+ template.yaml
110
+ community/
111
+ saves/
112
+ docs/
113
+ ```
@@ -0,0 +1,100 @@
1
+ # Pawsona
2
+
3
+ Train personalities, not commands.
4
+
5
+ Pawsona is a terminal-based pet personality and training simulator inspired by reinforcement learning, memory, adaptation, generalization, and overfitting.
6
+
7
+ The first public version focuses on dogs. The behavior model is intentionally simple: it is a small scoring engine for playable training loops, not a biologically realistic simulator.
8
+
9
+ ## Current Status
10
+
11
+ This repository is in the early CLI phase. Pawsona can load built-in pet profiles, inspect their model state, create new YAML profiles, and generate the first simple behavior-model actions.
12
+
13
+ ## Try It
14
+
15
+ After release, the main install command will be:
16
+
17
+ ```bash
18
+ pip install pawsona
19
+ ```
20
+
21
+ Primary CLI:
22
+
23
+ ```bash
24
+ pawsona --help
25
+ ```
26
+
27
+ Short alias:
28
+
29
+ ```bash
30
+ paw --help
31
+ ```
32
+
33
+ If `paw` conflicts with another command on your machine, use `pawsona`.
34
+
35
+ ## Environment
36
+
37
+ Create and activate the conda environment:
38
+
39
+ ```bash
40
+ conda create -n paw python=3.11 pip
41
+ conda activate paw
42
+ ```
43
+
44
+ Install the project components from `requirements.txt`:
45
+
46
+ ```bash
47
+ python -m pip install -r requirements.txt
48
+ pawsona --help
49
+ ```
50
+
51
+ ## Inspect A Pet
52
+
53
+ ```bash
54
+ pawsona inspect hermes
55
+ pawsona inspect hera
56
+ ```
57
+
58
+ ## Create A Pet
59
+
60
+ ```bash
61
+ pawsona create
62
+ ```
63
+
64
+ Trait questions use a `1` to `5` scale and are normalized into `0.0` to `1.0` YAML values.
65
+
66
+ ## Generate An Action
67
+
68
+ ```bash
69
+ pawsona act hermes
70
+ pawsona act hera
71
+ ```
72
+
73
+ ## Train In The Terminal
74
+
75
+ ```bash
76
+ pawsona play hermes
77
+ pawsona play hera
78
+ ```
79
+
80
+ Training sessions run for 10 rounds by default. Feedback options are `reward`, `praise`, `ignore`, and `correct`.
81
+
82
+ Training updates are session-only until persistence lands in the next milestone.
83
+
84
+ ## Project Shape
85
+
86
+ ```text
87
+ pawsona/
88
+ cli.py
89
+ behavior.py
90
+ pet.py
91
+ simple_yaml.py
92
+ training.py
93
+ pets/
94
+ hermes.yaml
95
+ hera.yaml
96
+ template.yaml
97
+ community/
98
+ saves/
99
+ docs/
100
+ ```
@@ -0,0 +1,3 @@
1
+ """Pawsona package."""
2
+
3
+ __version__ = "0.1.0a1"
@@ -0,0 +1,3 @@
1
+ from pawsona.cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,78 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from pawsona.pet import Pet
6
+
7
+
8
+ @dataclass(frozen=True)
9
+ class Scenario:
10
+ name: str
11
+ environment: str
12
+ cue: str
13
+ distraction: str
14
+ goal: str
15
+ target_action: str
16
+ target_skill: str
17
+
18
+
19
+ DEFAULT_SCENARIO = Scenario(
20
+ name="owner_arrives_home",
21
+ environment="home",
22
+ cue="greeting",
23
+ distraction="door_noise",
24
+ goal="stay calm when the owner arrives",
25
+ target_action="observe_calmly",
26
+ target_skill="settle",
27
+ )
28
+
29
+
30
+ def choose_action(pet: Pet, scenario: Scenario = DEFAULT_SCENARIO) -> tuple[str, dict[str, float]]:
31
+ scores = score_actions(pet, scenario)
32
+ action = max(scores, key=scores.get)
33
+ return action, scores
34
+
35
+
36
+ def score_actions(pet: Pet, scenario: Scenario = DEFAULT_SCENARIO) -> dict[str, float]:
37
+ traits = pet.traits
38
+ skills = pet.skills
39
+ memory = pet.memory
40
+
41
+ home_bias = memory.get(scenario.environment, 0.0)
42
+ distraction_bias = memory.get(scenario.distraction, 0.0)
43
+
44
+ scores = {
45
+ "observe_calmly": (
46
+ traits["self_control"] * 0.35
47
+ + skills["settle"] * 0.30
48
+ + traits["confidence"] * 0.15
49
+ + home_bias * 0.10
50
+ - traits["impulsivity"] * 0.20
51
+ ),
52
+ "jump_excitedly": (
53
+ traits["energy"] * 0.25
54
+ + traits["affection_seeking"] * 0.25
55
+ + traits["attachment"] * 0.20
56
+ + traits["impulsivity"] * 0.20
57
+ - skills["settle"] * 0.15
58
+ ),
59
+ "bark_at_noise": (
60
+ traits["vigilance"] * 0.35
61
+ + traits["sensitivity"] * 0.20
62
+ + max(distraction_bias, 0.0) * 0.15
63
+ - traits["confidence"] * 0.10
64
+ ),
65
+ "bring_toy": (
66
+ skills["fetch"] * 0.35
67
+ + traits["play_drive"] * 0.25
68
+ + traits["sociability"] * 0.10
69
+ + memory.get("toy", 0.0) * 0.10
70
+ ),
71
+ "return_to_owner": (
72
+ skills["recall"] * 0.35
73
+ + skills["focus"] * 0.20
74
+ + traits["trainability"] * 0.25
75
+ - traits["curiosity"] * 0.10
76
+ ),
77
+ }
78
+ return {action: round(score, 3) for action, score in scores.items()}
@@ -0,0 +1,39 @@
1
+ name: Hera
2
+ species: dog
3
+ breed: pug
4
+ age: 7
5
+ sex: female
6
+ neutered: true
7
+
8
+ traits:
9
+ energy: 0.9
10
+ confidence: 0.25
11
+ sociability: 0.85
12
+ attachment: 0.95
13
+ affection_seeking: 1.0
14
+ curiosity: 0.5
15
+ impulsivity: 0.9
16
+ self_control: 0.15
17
+ sensitivity: 0.8
18
+ trainability: 0.55
19
+ vigilance: 0.55
20
+ food_drive: 0.95
21
+ play_drive: 0.75
22
+
23
+ skills:
24
+ recall: 0.25
25
+ focus: 0.25
26
+ settle: 0.2
27
+ fetch: 0.2
28
+
29
+ memory:
30
+ home: 0.45
31
+ door_noise: 0.2
32
+ toy: 0.65
33
+ owner_arrives_home: 0.7
34
+ outside: 0.85
35
+ food: 0.95
36
+ sweets: 0.8
37
+ separation: -0.7
38
+ running: 0.8
39
+ pooping_outside: -0.2
@@ -0,0 +1,38 @@
1
+ name: Hermes
2
+ species: dog
3
+ breed: pug
4
+ age: 9
5
+ sex: male
6
+ neutered: false
7
+
8
+ traits:
9
+ energy: 0.25
10
+ confidence: 0.75
11
+ sociability: 0.35
12
+ attachment: 0.8
13
+ affection_seeking: 0.2
14
+ curiosity: 0.7
15
+ impulsivity: 0.2
16
+ self_control: 0.85
17
+ sensitivity: 0.9
18
+ trainability: 0.55
19
+ vigilance: 0.85
20
+ food_drive: 0.8
21
+ play_drive: 0.15
22
+
23
+ skills:
24
+ recall: 0.45
25
+ focus: 0.6
26
+ settle: 0.75
27
+ fetch: 0.2
28
+
29
+ memory:
30
+ home: 0.6
31
+ door_noise: 0.1
32
+ toy: 0.2
33
+ owner_arrives_home: 0.7
34
+ outside: 0.8
35
+ meat: 0.9
36
+ sweets: -0.5
37
+ human_distress: 0.8
38
+ clean_bedding: 0.7
@@ -0,0 +1,271 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ from pathlib import Path
5
+ from typing import Callable
6
+
7
+ from pawsona.behavior import DEFAULT_SCENARIO, choose_action
8
+ from pawsona.pet import SKILL_KEYS, TRAIT_KEYS, PetLoadError, load_pet, write_pet_profile
9
+ from pawsona.training import normalize_feedback, scenario_for_round, train_once
10
+
11
+
12
+ def build_parser() -> argparse.ArgumentParser:
13
+ parser = argparse.ArgumentParser(
14
+ prog="pawsona",
15
+ description="Train personalities, not commands.",
16
+ )
17
+ parser.add_argument(
18
+ "--pets-dir",
19
+ default="pets",
20
+ help="Directory containing pet YAML definitions.",
21
+ )
22
+
23
+ subparsers = parser.add_subparsers(dest="command")
24
+
25
+ inspect_parser = subparsers.add_parser(
26
+ "inspect",
27
+ help="Load and display a pet definition.",
28
+ )
29
+ inspect_parser.add_argument("pet", help="Pet name, for example: hermes")
30
+
31
+ create_parser = subparsers.add_parser(
32
+ "create",
33
+ help="Create a pet YAML profile through a short questionnaire.",
34
+ )
35
+ create_parser.add_argument(
36
+ "--force",
37
+ action="store_true",
38
+ help="Overwrite an existing pet YAML file.",
39
+ )
40
+
41
+ act_parser = subparsers.add_parser(
42
+ "act",
43
+ help="Generate an action from a pet profile.",
44
+ )
45
+ act_parser.add_argument("pet", help="Pet name, for example: hermes")
46
+
47
+ play_parser = subparsers.add_parser(
48
+ "play",
49
+ help="Run an interactive training session.",
50
+ )
51
+ play_parser.add_argument("pet", help="Pet name, for example: hermes")
52
+ play_parser.add_argument(
53
+ "--rounds",
54
+ type=int,
55
+ default=10,
56
+ help="Number of training rounds to run.",
57
+ )
58
+
59
+ return parser
60
+
61
+
62
+ def main(argv: list[str] | None = None) -> int:
63
+ parser = build_parser()
64
+ args = parser.parse_args(argv)
65
+
66
+ if args.command == "inspect":
67
+ return inspect_pet(args.pet, Path(args.pets_dir))
68
+ if args.command == "create":
69
+ return create_pet(Path(args.pets_dir), force=args.force)
70
+ if args.command == "act":
71
+ return act_pet(args.pet, Path(args.pets_dir))
72
+ if args.command == "play":
73
+ return play_pet(args.pet, Path(args.pets_dir), rounds=args.rounds)
74
+
75
+ parser.print_help()
76
+ return 0
77
+
78
+
79
+ def inspect_pet(name: str, pets_dir: Path) -> int:
80
+ try:
81
+ pet = load_pet(name, pets_dir)
82
+ except PetLoadError as error:
83
+ print(f"error: {error}")
84
+ return 1
85
+
86
+ print(f"Name: {pet.name}")
87
+ print(f"Species: {pet.species}")
88
+ print(f"Breed: {pet.breed}")
89
+ print(f"Age: {pet.age}")
90
+ print(f"Sex: {pet.sex}")
91
+ print(f"Neutered: {str(pet.neutered).lower()}")
92
+ print("Traits:")
93
+ for trait, value in sorted(pet.traits.items()):
94
+ print(f" {trait}: {value}")
95
+ print("Skills:")
96
+ for skill, value in sorted(pet.skills.items()):
97
+ print(f" {skill}: {value}")
98
+ print("Memory:")
99
+ for memory, value in sorted(pet.memory.items()):
100
+ print(f" {memory}: {value}")
101
+ return 0
102
+
103
+
104
+ def create_pet(pets_dir: Path, force: bool = False) -> int:
105
+ print("Create a Pawsona dog profile")
106
+ name = _ask_text("Name")
107
+ slug = _slugify(name)
108
+ path = pets_dir / f"{slug}.yaml"
109
+ if path.exists() and not force:
110
+ print(f"error: {path} already exists. Re-run with --force to overwrite.")
111
+ return 1
112
+
113
+ profile = {
114
+ "name": name,
115
+ "species": "dog",
116
+ "breed": _ask_text("Breed"),
117
+ "age": _ask_int("Age", minimum=0),
118
+ "sex": _ask_choice("Sex", {"female", "male", "unknown"}),
119
+ "neutered": _ask_bool("Neutered"),
120
+ "traits": {
121
+ trait: _normalize_scale(_ask_int(_trait_prompt(trait), minimum=1, maximum=5))
122
+ for trait in TRAIT_KEYS
123
+ },
124
+ "skills": {skill: 0.0 for skill in SKILL_KEYS},
125
+ "memory": {},
126
+ }
127
+
128
+ write_pet_profile(path, profile)
129
+ print(f"created: {path}")
130
+ return 0
131
+
132
+
133
+ def act_pet(name: str, pets_dir: Path) -> int:
134
+ try:
135
+ pet = load_pet(name, pets_dir)
136
+ except PetLoadError as error:
137
+ print(f"error: {error}")
138
+ return 1
139
+
140
+ action, scores = choose_action(pet)
141
+ print(f"Scenario: {DEFAULT_SCENARIO.name}")
142
+ print(f"{pet.name} action: {action}")
143
+ print("Scores:")
144
+ for score_name, score in sorted(scores.items(), key=lambda item: item[1], reverse=True):
145
+ print(f" {score_name}: {score}")
146
+ return 0
147
+
148
+
149
+ def play_pet(name: str, pets_dir: Path, rounds: int) -> int:
150
+ if rounds < 1:
151
+ print("error: --rounds must be 1 or greater")
152
+ return 1
153
+
154
+ try:
155
+ pet = load_pet(name, pets_dir)
156
+ except PetLoadError as error:
157
+ print(f"error: {error}")
158
+ return 1
159
+
160
+ print(f"Training {pet.name} for {rounds} rounds")
161
+ print("Feedback: 1 reward, 2 praise, 3 ignore, 4 correct, q quit")
162
+
163
+ completed_rounds = 0
164
+ for round_index in range(rounds):
165
+ scenario = scenario_for_round(round_index)
166
+ action, scores = choose_action(pet, scenario)
167
+
168
+ print("")
169
+ print(f"Round {round_index + 1}/{rounds}")
170
+ print(f"Scenario: {scenario.name}")
171
+ print(f"Environment: {scenario.environment}")
172
+ print(f"Goal: {scenario.goal}")
173
+ print(f"Distraction: {scenario.distraction}")
174
+ print(f"{pet.name} action: {action}")
175
+ print(f"Top score: {scores[action]}")
176
+
177
+ feedback = _ask_feedback()
178
+ if feedback is None:
179
+ break
180
+
181
+ pet, updates = train_once(pet, scenario, feedback)
182
+ completed_rounds += 1
183
+ print("Updates:")
184
+ for key, delta in updates.items():
185
+ print(f" {key} {delta:+.3f}")
186
+
187
+ print("")
188
+ print(f"Completed rounds: {completed_rounds}/{rounds}")
189
+ return 0
190
+
191
+
192
+ def _ask_text(prompt: str, input_fn: Callable[[str], str] = input) -> str:
193
+ while True:
194
+ value = input_fn(f"{prompt}: ").strip()
195
+ if value:
196
+ return value
197
+ print("Please enter a value.")
198
+
199
+
200
+ def _ask_int(
201
+ prompt: str,
202
+ minimum: int,
203
+ maximum: int | None = None,
204
+ input_fn: Callable[[str], str] = input,
205
+ ) -> int:
206
+ while True:
207
+ raw_value = input_fn(f"{prompt}: ").strip()
208
+ try:
209
+ value = int(raw_value)
210
+ except ValueError:
211
+ print("Please enter a whole number.")
212
+ continue
213
+ if value < minimum:
214
+ print(f"Please enter {minimum} or greater.")
215
+ continue
216
+ if maximum is not None and value > maximum:
217
+ print(f"Please enter {maximum} or lower.")
218
+ continue
219
+ return value
220
+
221
+
222
+ def _ask_bool(prompt: str, input_fn: Callable[[str], str] = input) -> bool:
223
+ while True:
224
+ value = input_fn(f"{prompt} [y/n]: ").strip().lower()
225
+ if value in {"y", "yes"}:
226
+ return True
227
+ if value in {"n", "no"}:
228
+ return False
229
+ print("Please answer y or n.")
230
+
231
+
232
+ def _ask_choice(
233
+ prompt: str,
234
+ choices: set[str],
235
+ input_fn: Callable[[str], str] = input,
236
+ ) -> str:
237
+ options = "/".join(sorted(choices))
238
+ while True:
239
+ value = input_fn(f"{prompt} [{options}]: ").strip().lower()
240
+ if value in choices:
241
+ return value
242
+ print(f"Please choose one of: {options}.")
243
+
244
+
245
+ def _ask_feedback(input_fn: Callable[[str], str] = input) -> str | None:
246
+ while True:
247
+ try:
248
+ value = input_fn("Your feedback: ").strip().lower()
249
+ except EOFError:
250
+ print("")
251
+ return None
252
+ if value in {"q", "quit", "exit"}:
253
+ return None
254
+ feedback = normalize_feedback(value)
255
+ if feedback is not None:
256
+ return feedback
257
+ print("Please choose 1, 2, 3, 4, or q.")
258
+
259
+
260
+ def _normalize_scale(value: int) -> float:
261
+ return round((value - 1) / 4, 2)
262
+
263
+
264
+ def _slugify(value: str) -> str:
265
+ slug = "".join(character.lower() if character.isalnum() else "_" for character in value)
266
+ return "_".join(part for part in slug.split("_") if part)
267
+
268
+
269
+ def _trait_prompt(trait: str) -> str:
270
+ label = trait.replace("_", " ")
271
+ return f"{label} (1-5)"
@@ -0,0 +1,170 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from importlib import resources
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ from pawsona.simple_yaml import load_yaml_mapping, load_yaml_text, write_yaml_mapping
9
+
10
+
11
+ class PetLoadError(Exception):
12
+ """Raised when a pet definition cannot be loaded."""
13
+
14
+
15
+ TRAIT_KEYS = (
16
+ "energy",
17
+ "confidence",
18
+ "sociability",
19
+ "attachment",
20
+ "affection_seeking",
21
+ "curiosity",
22
+ "impulsivity",
23
+ "self_control",
24
+ "sensitivity",
25
+ "trainability",
26
+ "vigilance",
27
+ "food_drive",
28
+ "play_drive",
29
+ )
30
+
31
+ SKILL_KEYS = (
32
+ "recall",
33
+ "focus",
34
+ "settle",
35
+ "fetch",
36
+ )
37
+
38
+
39
+ @dataclass(frozen=True)
40
+ class Pet:
41
+ name: str
42
+ species: str
43
+ breed: str
44
+ age: int
45
+ sex: str
46
+ neutered: bool
47
+ traits: dict[str, float]
48
+ skills: dict[str, float]
49
+ memory: dict[str, float]
50
+
51
+
52
+ def load_pet(name: str, pets_dir: Path) -> Pet:
53
+ path = _find_pet_file(name, pets_dir)
54
+ if path is not None:
55
+ data = _read_yaml(path)
56
+ return _parse_pet(data, path)
57
+
58
+ data = _read_builtin_pet(name)
59
+ if data is not None:
60
+ return _parse_pet(data, f"built-in pet '{name}'")
61
+
62
+ raise PetLoadError(f"could not find pet '{name}' in {pets_dir} or built-in pets")
63
+
64
+
65
+ def _find_pet_file(name: str, pets_dir: Path) -> Path | None:
66
+ candidates = [
67
+ pets_dir / f"{name}.yaml",
68
+ pets_dir / "community" / f"{name}.yaml",
69
+ ]
70
+ for candidate in candidates:
71
+ if candidate.exists():
72
+ return candidate
73
+ return None
74
+
75
+
76
+ def _read_builtin_pet(name: str) -> dict[str, Any] | None:
77
+ resource = resources.files("pawsona").joinpath("builtin_pets", f"{name}.yaml")
78
+ if not resource.is_file():
79
+ return None
80
+ try:
81
+ return load_yaml_text(resource.read_text(encoding="utf-8"), source=str(resource))
82
+ except ValueError as error:
83
+ raise PetLoadError(str(error)) from error
84
+
85
+
86
+ def _read_yaml(path: Path) -> dict[str, Any]:
87
+ try:
88
+ return load_yaml_mapping(path)
89
+ except ValueError as error:
90
+ raise PetLoadError(str(error)) from error
91
+
92
+
93
+ def write_pet_profile(path: Path, profile: dict[str, Any]) -> None:
94
+ write_yaml_mapping(path, profile)
95
+
96
+
97
+ def _parse_pet(data: dict[str, Any], path: Path | str) -> Pet:
98
+ try:
99
+ name = _require_string(data, "name")
100
+ species = _require_string(data, "species")
101
+ breed = _require_string(data, "breed")
102
+ age = _require_int(data, "age")
103
+ sex = _require_string(data, "sex")
104
+ neutered = _require_bool(data, "neutered")
105
+ traits = _require_number_map(data, "traits", required_keys=TRAIT_KEYS)
106
+ skills = _require_number_map(data, "skills", required_keys=SKILL_KEYS)
107
+ memory = _require_number_map(data, "memory")
108
+ except PetLoadError as error:
109
+ raise PetLoadError(f"{path}: {error}") from error
110
+
111
+ return Pet(
112
+ name=name,
113
+ species=species,
114
+ breed=breed,
115
+ age=age,
116
+ sex=sex,
117
+ neutered=neutered,
118
+ traits=traits,
119
+ skills=skills,
120
+ memory=memory,
121
+ )
122
+
123
+
124
+ def _require_string(data: dict[str, Any], key: str) -> str:
125
+ value = data.get(key)
126
+ if not isinstance(value, str) or not value.strip():
127
+ raise PetLoadError(f"'{key}' must be a non-empty string")
128
+ return value
129
+
130
+
131
+ def _require_int(data: dict[str, Any], key: str) -> int:
132
+ value = data.get(key)
133
+ if not isinstance(value, int) or isinstance(value, bool):
134
+ raise PetLoadError(f"'{key}' must be an integer")
135
+ if value < 0:
136
+ raise PetLoadError(f"'{key}' must be zero or greater")
137
+ return value
138
+
139
+
140
+ def _require_bool(data: dict[str, Any], key: str) -> bool:
141
+ value = data.get(key)
142
+ if not isinstance(value, bool):
143
+ raise PetLoadError(f"'{key}' must be true or false")
144
+ return value
145
+
146
+
147
+ def _require_number_map(
148
+ data: dict[str, Any],
149
+ key: str,
150
+ required_keys: tuple[str, ...] = (),
151
+ ) -> dict[str, float]:
152
+ value = data.get(key)
153
+ if not isinstance(value, dict):
154
+ raise PetLoadError(f"'{key}' must be a mapping")
155
+
156
+ missing = [required_key for required_key in required_keys if required_key not in value]
157
+ if missing:
158
+ raise PetLoadError(f"'{key}' is missing: {', '.join(missing)}")
159
+
160
+ result: dict[str, float] = {}
161
+ for item_key, item_value in value.items():
162
+ if not isinstance(item_key, str) or not item_key.strip():
163
+ raise PetLoadError(f"'{key}' keys must be non-empty strings")
164
+ if not isinstance(item_value, int | float) or isinstance(item_value, bool):
165
+ raise PetLoadError(f"'{key}.{item_key}' must be a number")
166
+ numeric_value = float(item_value)
167
+ if numeric_value < -1.0 or numeric_value > 1.0:
168
+ raise PetLoadError(f"'{key}.{item_key}' must be between -1.0 and 1.0")
169
+ result[item_key] = numeric_value
170
+ return result
@@ -0,0 +1,108 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any
5
+
6
+
7
+ def load_yaml_mapping(path: Path) -> dict[str, Any]:
8
+ return load_yaml_text(path.read_text(encoding="utf-8"), source=str(path))
9
+
10
+
11
+ def load_yaml_text(text: str, source: str = "<yaml>") -> dict[str, Any]:
12
+ try:
13
+ import yaml
14
+ except ImportError:
15
+ return _load_simple_yaml_text(text, source)
16
+
17
+ data = yaml.safe_load(text)
18
+
19
+ if not isinstance(data, dict):
20
+ raise ValueError(f"{source} must contain a YAML mapping")
21
+ return data
22
+
23
+
24
+ def write_yaml_mapping(path: Path, data: dict[str, Any]) -> None:
25
+ path.parent.mkdir(parents=True, exist_ok=True)
26
+ with path.open("w", encoding="utf-8") as file:
27
+ file.write(_dump_simple_yaml_mapping(data))
28
+
29
+
30
+ def _load_simple_yaml_mapping(path: Path) -> dict[str, Any]:
31
+ return _load_simple_yaml_text(path.read_text(encoding="utf-8"), str(path))
32
+
33
+
34
+ def _load_simple_yaml_text(text: str, source: str) -> dict[str, Any]:
35
+ root: dict[str, Any] = {}
36
+ current_map: dict[str, Any] | None = None
37
+
38
+ for line_number, raw_line in enumerate(text.splitlines(), 1):
39
+ line = raw_line.split("#", 1)[0].rstrip()
40
+ if not line:
41
+ continue
42
+
43
+ indent = len(line) - len(line.lstrip(" "))
44
+ stripped = line.strip()
45
+ if ":" not in stripped:
46
+ raise ValueError(f"{source}:{line_number}: expected 'key: value'")
47
+
48
+ key, raw_value = stripped.split(":", 1)
49
+ key = key.strip()
50
+ raw_value = raw_value.strip()
51
+ if not key:
52
+ raise ValueError(f"{source}:{line_number}: missing key")
53
+
54
+ if indent == 0:
55
+ if raw_value == "":
56
+ current_map = {}
57
+ root[key] = current_map
58
+ else:
59
+ current_map = None
60
+ root[key] = _parse_scalar(raw_value)
61
+ elif indent == 2:
62
+ if current_map is None:
63
+ raise ValueError(f"{source}:{line_number}: nested value without a parent")
64
+ current_map[key] = _parse_scalar(raw_value)
65
+ else:
66
+ raise ValueError(f"{source}:{line_number}: only two-space nesting is supported")
67
+
68
+ return root
69
+
70
+
71
+ def _parse_scalar(value: str) -> Any:
72
+ if value == "{}":
73
+ return {}
74
+ if value in {"true", "True"}:
75
+ return True
76
+ if value in {"false", "False"}:
77
+ return False
78
+ if value in {"null", "None", "~"}:
79
+ return None
80
+ try:
81
+ if "." in value:
82
+ return float(value)
83
+ return int(value)
84
+ except ValueError:
85
+ return value.strip("\"'")
86
+
87
+
88
+ def _dump_simple_yaml_mapping(data: dict[str, Any]) -> str:
89
+ lines: list[str] = []
90
+ for key, value in data.items():
91
+ if isinstance(value, dict):
92
+ if value:
93
+ lines.append(f"{key}:")
94
+ for nested_key, nested_value in value.items():
95
+ lines.append(f" {nested_key}: {_format_scalar(nested_value)}")
96
+ else:
97
+ lines.append(f"{key}: {{}}")
98
+ else:
99
+ lines.append(f"{key}: {_format_scalar(value)}")
100
+ if key in {"neutered", "traits", "skills"}:
101
+ lines.append("")
102
+ return "\n".join(lines).rstrip() + "\n"
103
+
104
+
105
+ def _format_scalar(value: Any) -> str:
106
+ if isinstance(value, bool):
107
+ return "true" if value else "false"
108
+ return str(value)
@@ -0,0 +1,145 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import replace
4
+
5
+ from pawsona.behavior import Scenario, choose_action
6
+ from pawsona.pet import Pet
7
+
8
+
9
+ SCENARIOS = (
10
+ Scenario(
11
+ name="owner_arrives_home",
12
+ environment="home",
13
+ cue="greeting",
14
+ distraction="door_noise",
15
+ goal="stay calm when the owner arrives",
16
+ target_action="observe_calmly",
17
+ target_skill="settle",
18
+ ),
19
+ Scenario(
20
+ name="recall_from_yard",
21
+ environment="outside",
22
+ cue="recall",
23
+ distraction="squirrel",
24
+ goal="return when called",
25
+ target_action="return_to_owner",
26
+ target_skill="recall",
27
+ ),
28
+ Scenario(
29
+ name="fetch_at_park",
30
+ environment="park",
31
+ cue="fetch",
32
+ distraction="squirrel",
33
+ goal="bring the toy back",
34
+ target_action="bring_toy",
35
+ target_skill="fetch",
36
+ ),
37
+ Scenario(
38
+ name="focus_near_food",
39
+ environment="kitchen",
40
+ cue="focus",
41
+ distraction="meat",
42
+ goal="keep attention on the owner",
43
+ target_action="return_to_owner",
44
+ target_skill="focus",
45
+ ),
46
+ Scenario(
47
+ name="settle_during_noise",
48
+ environment="home",
49
+ cue="settle",
50
+ distraction="door_noise",
51
+ goal="settle through a noise",
52
+ target_action="observe_calmly",
53
+ target_skill="settle",
54
+ ),
55
+ )
56
+
57
+ FEEDBACK_LABELS = {
58
+ "1": "reward",
59
+ "2": "praise",
60
+ "3": "ignore",
61
+ "4": "correct",
62
+ "reward": "reward",
63
+ "praise": "praise",
64
+ "ignore": "ignore",
65
+ "correct": "correct",
66
+ }
67
+
68
+ ACTION_SKILLS = {
69
+ "observe_calmly": "settle",
70
+ "jump_excitedly": "settle",
71
+ "bark_at_noise": "focus",
72
+ "bring_toy": "fetch",
73
+ "return_to_owner": "recall",
74
+ }
75
+
76
+
77
+ def scenario_for_round(round_index: int) -> Scenario:
78
+ return SCENARIOS[round_index % len(SCENARIOS)]
79
+
80
+
81
+ def normalize_feedback(value: str) -> str | None:
82
+ return FEEDBACK_LABELS.get(value.strip().lower())
83
+
84
+
85
+ def train_once(pet: Pet, scenario: Scenario, feedback: str) -> tuple[Pet, dict[str, float]]:
86
+ action, _scores = choose_action(pet, scenario)
87
+ skill_updates = _skill_updates(action, scenario, feedback)
88
+ memory_updates = _memory_updates(action, scenario, feedback)
89
+
90
+ skills = dict(pet.skills)
91
+ memory = dict(pet.memory)
92
+ applied: dict[str, float] = {}
93
+
94
+ for skill, delta in skill_updates.items():
95
+ old_value = skills.get(skill, 0.0)
96
+ new_value = _clamp(old_value + delta)
97
+ skills[skill] = new_value
98
+ applied[f"{skill}_skill"] = round(new_value - old_value, 3)
99
+
100
+ for key, delta in memory_updates.items():
101
+ old_value = memory.get(key, 0.0)
102
+ new_value = _clamp(old_value + delta, minimum=-1.0)
103
+ memory[key] = new_value
104
+ applied[f"{key}_memory"] = round(new_value - old_value, 3)
105
+
106
+ return replace(pet, skills=skills, memory=memory), applied
107
+
108
+
109
+ def _skill_updates(action: str, scenario: Scenario, feedback: str) -> dict[str, float]:
110
+ action_skill = ACTION_SKILLS.get(action, scenario.target_skill)
111
+
112
+ if feedback == "reward":
113
+ return {action_skill: 0.05}
114
+ if feedback == "praise":
115
+ return {action_skill: 0.03}
116
+ if feedback == "correct":
117
+ updates = {scenario.target_skill: 0.03}
118
+ if action != scenario.target_action:
119
+ updates[action_skill] = updates.get(action_skill, 0.0) - 0.02
120
+ return updates
121
+ return {scenario.target_skill: -0.005}
122
+
123
+
124
+ def _memory_updates(action: str, scenario: Scenario, feedback: str) -> dict[str, float]:
125
+ if feedback == "reward":
126
+ return {
127
+ scenario.name: 0.04,
128
+ scenario.environment: 0.02,
129
+ scenario.distraction: 0.01 if action == scenario.target_action else -0.02,
130
+ }
131
+ if feedback == "praise":
132
+ return {
133
+ scenario.name: 0.025,
134
+ scenario.environment: 0.015,
135
+ }
136
+ if feedback == "correct":
137
+ return {
138
+ scenario.name: -0.02,
139
+ scenario.distraction: -0.03,
140
+ }
141
+ return {scenario.name: -0.005}
142
+
143
+
144
+ def _clamp(value: float, minimum: float = 0.0, maximum: float = 1.0) -> float:
145
+ return round(max(minimum, min(maximum, value)), 3)
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: pawsona
3
+ Version: 0.1.0a1
4
+ Summary: Train personalities, not commands.
5
+ Author: esmacimsit
6
+ Maintainer: esmacimsit
7
+ License-Expression: MIT
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: PyYAML>=6.0.2
12
+ Dynamic: license-file
13
+
14
+ # Pawsona
15
+
16
+ Train personalities, not commands.
17
+
18
+ Pawsona is a terminal-based pet personality and training simulator inspired by reinforcement learning, memory, adaptation, generalization, and overfitting.
19
+
20
+ The first public version focuses on dogs. The behavior model is intentionally simple: it is a small scoring engine for playable training loops, not a biologically realistic simulator.
21
+
22
+ ## Current Status
23
+
24
+ This repository is in the early CLI phase. Pawsona can load built-in pet profiles, inspect their model state, create new YAML profiles, and generate the first simple behavior-model actions.
25
+
26
+ ## Try It
27
+
28
+ After release, the main install command will be:
29
+
30
+ ```bash
31
+ pip install pawsona
32
+ ```
33
+
34
+ Primary CLI:
35
+
36
+ ```bash
37
+ pawsona --help
38
+ ```
39
+
40
+ Short alias:
41
+
42
+ ```bash
43
+ paw --help
44
+ ```
45
+
46
+ If `paw` conflicts with another command on your machine, use `pawsona`.
47
+
48
+ ## Environment
49
+
50
+ Create and activate the conda environment:
51
+
52
+ ```bash
53
+ conda create -n paw python=3.11 pip
54
+ conda activate paw
55
+ ```
56
+
57
+ Install the project components from `requirements.txt`:
58
+
59
+ ```bash
60
+ python -m pip install -r requirements.txt
61
+ pawsona --help
62
+ ```
63
+
64
+ ## Inspect A Pet
65
+
66
+ ```bash
67
+ pawsona inspect hermes
68
+ pawsona inspect hera
69
+ ```
70
+
71
+ ## Create A Pet
72
+
73
+ ```bash
74
+ pawsona create
75
+ ```
76
+
77
+ Trait questions use a `1` to `5` scale and are normalized into `0.0` to `1.0` YAML values.
78
+
79
+ ## Generate An Action
80
+
81
+ ```bash
82
+ pawsona act hermes
83
+ pawsona act hera
84
+ ```
85
+
86
+ ## Train In The Terminal
87
+
88
+ ```bash
89
+ pawsona play hermes
90
+ pawsona play hera
91
+ ```
92
+
93
+ Training sessions run for 10 rounds by default. Feedback options are `reward`, `praise`, `ignore`, and `correct`.
94
+
95
+ Training updates are session-only until persistence lands in the next milestone.
96
+
97
+ ## Project Shape
98
+
99
+ ```text
100
+ pawsona/
101
+ cli.py
102
+ behavior.py
103
+ pet.py
104
+ simple_yaml.py
105
+ training.py
106
+ pets/
107
+ hermes.yaml
108
+ hera.yaml
109
+ template.yaml
110
+ community/
111
+ saves/
112
+ docs/
113
+ ```
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ pawsona/__init__.py
5
+ pawsona/__main__.py
6
+ pawsona/behavior.py
7
+ pawsona/cli.py
8
+ pawsona/pet.py
9
+ pawsona/simple_yaml.py
10
+ pawsona/training.py
11
+ pawsona.egg-info/PKG-INFO
12
+ pawsona.egg-info/SOURCES.txt
13
+ pawsona.egg-info/dependency_links.txt
14
+ pawsona.egg-info/entry_points.txt
15
+ pawsona.egg-info/requires.txt
16
+ pawsona.egg-info/top_level.txt
17
+ pawsona/builtin_pets/hera.yaml
18
+ pawsona/builtin_pets/hermes.yaml
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ paw = pawsona.cli:main
3
+ pawsona = pawsona.cli:main
@@ -0,0 +1 @@
1
+ PyYAML>=6.0.2
@@ -0,0 +1 @@
1
+ pawsona
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pawsona"
7
+ version = "0.1.0a1"
8
+ description = "Train personalities, not commands."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "esmacimsit" },
14
+ ]
15
+ maintainers = [
16
+ { name = "esmacimsit" },
17
+ ]
18
+ dependencies = [
19
+ "PyYAML>=6.0.2",
20
+ ]
21
+
22
+ [project.scripts]
23
+ pawsona = "pawsona.cli:main"
24
+ paw = "pawsona.cli:main"
25
+
26
+ [tool.setuptools.packages.find]
27
+ include = ["pawsona*"]
28
+
29
+ [tool.setuptools.package-data]
30
+ pawsona = ["builtin_pets/*.yaml"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+