xonecas.io
5875
Os

ollama-space-molt-player / commit bf38cf9

refactor: simplify client architecture and integrate MCP support

- Remove abstraction layers: ws-client, api-definition, types, logging wrappers
- Consolidate WebSocket logic directly into game-client
- Remove redundant tests for deleted modules
- Add mcp-client for future MCP integration
- Streamline model configuration and logging
- Reduce codebase complexity per design principles

xonecas2026-02-03 bf38cf9c6e1c2e25e03011ee89500216a1dff2c7 parent 9595f0c

20 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

bun.lock+183−0
@@ -14,38 +14,221 @@
1414 "packages/client": {
1515 "name": "@spacemolt/client",
1616 "version": "0.1.0",
17+ "dependencies": {
18+ "@modelcontextprotocol/sdk": "^1.25.3",
19+ },
1720 "devDependencies": {
1821 "@types/bun": "latest",
1922 },
2023 },
2124 },
2225 "packages": {
26+ "@hono/node-server": ["@hono/node-server@1.19.9", "", { "peerDependencies": { "hono": "^4" } }, "sha512-vHL6w3ecZsky+8P5MD+eFfaGTyCeOHUIFYMGpQGbrBTSmNNoxv0if69rEZ5giu36weC5saFuznL411gRX7bJDw=="],
27+
2328 "@isaacs/balanced-match": ["@isaacs/balanced-match@4.0.1", "", {}, "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ=="],
2429
2530 "@isaacs/brace-expansion": ["@isaacs/brace-expansion@5.0.0", "", { "dependencies": { "@isaacs/balanced-match": "^4.0.1" } }, "sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA=="],
2631
32+ "@modelcontextprotocol/sdk": ["@modelcontextprotocol/sdk@1.25.3", "", { "dependencies": { "@hono/node-server": "^1.19.9", "ajv": "^8.17.1", "ajv-formats": "^3.0.1", "content-type": "^1.0.5", "cors": "^2.8.5", "cross-spawn": "^7.0.5", "eventsource": "^3.0.2", "eventsource-parser": "^3.0.0", "express": "^5.0.1", "express-rate-limit": "^7.5.0", "jose": "^6.1.1", "json-schema-typed": "^8.0.2", "pkce-challenge": "^5.0.0", "raw-body": "^3.0.0", "zod": "^3.25 || ^4.0", "zod-to-json-schema": "^3.25. …
33+
2734 "@spacemolt/client": ["@spacemolt/client@workspace:packages/client"],
2835
2936 "@types/bun": ["@types/bun@1.3.8", "", { "dependencies": { "bun-types": "1.3.8" } }, "sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA=="],
3037
3138 "@types/node": ["@types/node@25.2.0", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-DZ8VwRFUNzuqJ5khrvwMXHmvPe+zGayJhr2CDNiKB1WBE1ST8Djl00D0IC4vvNmHMdj6DlbYRIaFE7WHjlDl5w=="],
3239
40+ "accepts": ["accepts@2.0.0", "", { "dependencies": { "mime-types": "^3.0.0", "negotiator": "^1.0.0" } }, "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng=="],
41+
42+ "ajv": ["ajv@8.17.1", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g=="],
43+
44+ "ajv-formats": ["ajv-formats@3.0.1", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ=="],
45+
46+ "body-parser": ["body-parser@2.2.2", "", { "dependencies": { "bytes": "^3.1.2", "content-type": "^1.0.5", "debug": "^4.4.3", "http-errors": "^2.0.0", "iconv-lite": "^0.7.0", "on-finished": "^2.4.1", "qs": "^6.14.1", "raw-body": "^3.0.1", "type-is": "^2.0.1" } }, "sha512-oP5VkATKlNwcgvxi0vM0p/D3n2C3EReYVX+DNYs5TjZFn/oQt2j+4sVJtSMr18pdRr8wjTcBl6LoV+FUwzPmNA=="],
47+
3348 "bun-types": ["bun-types@1.3.8", "", { "dependencies": { "@types/node": "*" } }, "sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q=="],
3449
50+ "bytes": ["bytes@3.1.2", "", {}, "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="],
51+
52+ "call-bind-apply-helpers": ["call-bind-apply-helpers@1.0.2", "", { "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2" } }, "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ=="],
53+
54+ "call-bound": ["call-bound@1.0.4", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.2", "get-intrinsic": "^1.3.0" } }, "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg=="],
55+
56+ "content-disposition": ["content-disposition@1.0.1", "", {}, "sha512-oIXISMynqSqm241k6kcQ5UwttDILMK4BiurCfGEREw6+X9jkkpEe5T9FZaApyLGGOnFuyMWZpdolTXMtvEJ08Q=="],
57+
58+ "content-type": ["content-type@1.0.5", "", {}, "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA=="],
59+
60+ "cookie": ["cookie@0.7.2", "", {}, "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w=="],
61+
62+ "cookie-signature": ["cookie-signature@1.2.2", "", {}, "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg=="],
63+
64+ "cors": ["cors@2.8.6", "", { "dependencies": { "object-assign": "^4", "vary": "^1" } }, "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw=="],
65+
66+ "cross-spawn": ["cross-spawn@7.0.6", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="],
67+
68+ "debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="],
69+
70+ "depd": ["depd@2.0.0", "", {}, "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw=="],
71+
72+ "dunder-proto": ["dunder-proto@1.0.1", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" } }, "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A=="],
73+
74+ "ee-first": ["ee-first@1.1.1", "", {}, "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="],
75+
76+ "encodeurl": ["encodeurl@2.0.0", "", {}, "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg=="],
77+
78+ "es-define-property": ["es-define-property@1.0.1", "", {}, "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g=="],
79+
80+ "es-errors": ["es-errors@1.3.0", "", {}, "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw=="],
81+
82+ "es-object-atoms": ["es-object-atoms@1.1.1", "", { "dependencies": { "es-errors": "^1.3.0" } }, "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA=="],
83+
84+ "escape-html": ["escape-html@1.0.3", "", {}, "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="],
85+
86+ "etag": ["etag@1.8.1", "", {}, "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg=="],
87+
88+ "eventsource": ["eventsource@3.0.7", "", { "dependencies": { "eventsource-parser": "^3.0.1" } }, "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA=="],
89+
90+ "eventsource-parser": ["eventsource-parser@3.0.6", "", {}, "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg=="],
91+
92+ "express": ["express@5.2.1", "", { "dependencies": { "accepts": "^2.0.0", "body-parser": "^2.2.1", "content-disposition": "^1.0.0", "content-type": "^1.0.5", "cookie": "^0.7.1", "cookie-signature": "^1.2.1", "debug": "^4.4.0", "depd": "^2.0.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", "finalhandler": "^2.1.0", "fresh": "^2.0.0", "http-errors": "^2.0.0", "merge-descriptors": "^2.0.0", "mime-types": "^3.0.0", "on-finished": "^2.4.1", "once": "^1.4.0", "parseurl": "^1.3 …
93+
94+ "express-rate-limit": ["express-rate-limit@7.5.1", "", { "peerDependencies": { "express": ">= 4.11" } }, "sha512-7iN8iPMDzOMHPUYllBEsQdWVB6fPDMPqwjBaFrgr4Jgr/+okjvzAy+UHlYYL/Vs0OsOrMkwS6PJDkFlJwoxUnw=="],
95+
96+ "fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="],
97+
98+ "fast-uri": ["fast-uri@3.1.0", "", {}, "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA=="],
99+
100+ "finalhandler": ["finalhandler@2.1.1", "", { "dependencies": { "debug": "^4.4.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "on-finished": "^2.4.1", "parseurl": "^1.3.3", "statuses": "^2.0.1" } }, "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA=="],
101+
102+ "forwarded": ["forwarded@0.2.0", "", {}, "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow=="],
103+
104+ "fresh": ["fresh@2.0.0", "", {}, "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A=="],
105+
106+ "function-bind": ["function-bind@1.1.2", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="],
107+
108+ "get-intrinsic": ["get-intrinsic@1.3.0", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", "get-proto": "^1.0.1", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", "math-intrinsics": "^1.1.0" } }, "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ=="],
109+
110+ "get-proto": ["get-proto@1.0.1", "", { "dependencies": { "dunder-proto": "^1.0.1", "es-object-atoms": "^1.0.0" } }, "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g=="],
111+
35112 "glob": ["glob@13.0.0", "", { "dependencies": { "minimatch": "^10.1.1", "minipass": "^7.1.2", "path-scurry": "^2.0.0" } }, "sha512-tvZgpqk6fz4BaNZ66ZsRaZnbHvP/jG3uKJvAZOwEVUL4RTA5nJeeLYfyN9/VA8NX/V3IBG+hkeuGpKjvELkVhA=="],
36113
114+ "gopd": ["gopd@1.2.0", "", {}, "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg=="],
115+
116+ "has-symbols": ["has-symbols@1.1.0", "", {}, "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ=="],
117+
118+ "hasown": ["hasown@2.0.2", "", { "dependencies": { "function-bind": "^1.1.2" } }, "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ=="],
119+
120+ "hono": ["hono@4.11.7", "", {}, "sha512-l7qMiNee7t82bH3SeyUCt9UF15EVmaBvsppY2zQtrbIhl/yzBTny+YUxsVjSjQ6gaqaeVtZmGocom8TzBlA4Yw=="],
121+
122+ "http-errors": ["http-errors@2.0.1", "", { "dependencies": { "depd": "~2.0.0", "inherits": "~2.0.4", "setprototypeof": "~1.2.0", "statuses": "~2.0.2", "toidentifier": "~1.0.1" } }, "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ=="],
123+
124+ "iconv-lite": ["iconv-lite@0.7.2", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw=="],
125+
126+ "inherits": ["inherits@2.0.4", "", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="],
127+
128+ "ipaddr.js": ["ipaddr.js@1.9.1", "", {}, "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="],
129+
130+ "is-promise": ["is-promise@4.0.0", "", {}, "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ=="],
131+
132+ "isexe": ["isexe@2.0.0", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="],
133+
134+ "jose": ["jose@6.1.3", "", {}, "sha512-0TpaTfihd4QMNwrz/ob2Bp7X04yuxJkjRGi4aKmOqwhov54i6u79oCv7T+C7lo70MKH6BesI3vscD1yb/yzKXQ=="],
135+
136+ "json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="],
137+
138+ "json-schema-typed": ["json-schema-typed@8.0.2", "", {}, "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA=="],
139+
37140 "lru-cache": ["lru-cache@11.2.5", "", {}, "sha512-vFrFJkWtJvJnD5hg+hJvVE8Lh/TcMzKnTgCWmtBipwI5yLX/iX+5UB2tfuyODF5E7k9xEzMdYgGqaSb1c0c5Yw=="],
38141
142+ "math-intrinsics": ["math-intrinsics@1.1.0", "", {}, "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="],
143+
144+ "media-typer": ["media-typer@1.1.0", "", {}, "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw=="],
145+
146+ "merge-descriptors": ["merge-descriptors@2.0.0", "", {}, "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g=="],
147+
148+ "mime-db": ["mime-db@1.54.0", "", {}, "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ=="],
149+
150+ "mime-types": ["mime-types@3.0.2", "", { "dependencies": { "mime-db": "^1.54.0" } }, "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A=="],
151+
39152 "minimatch": ["minimatch@10.1.1", "", { "dependencies": { "@isaacs/brace-expansion": "^5.0.0" } }, "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ=="],
40153
41154 "minipass": ["minipass@7.1.2", "", {}, "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw=="],
42155
156+ "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
157+
158+ "negotiator": ["negotiator@1.0.0", "", {}, "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg=="],
159+
160+ "object-assign": ["object-assign@4.1.1", "", {}, "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg=="],
161+
162+ "object-inspect": ["object-inspect@1.13.4", "", {}, "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew=="],
163+
164+ "on-finished": ["on-finished@2.4.1", "", { "dependencies": { "ee-first": "1.1.1" } }, "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg=="],
165+
166+ "once": ["once@1.4.0", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="],
167+
168+ "parseurl": ["parseurl@1.3.3", "", {}, "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="],
169+
170+ "path-key": ["path-key@3.1.1", "", {}, "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q=="],
171+
43172 "path-scurry": ["path-scurry@2.0.1", "", { "dependencies": { "lru-cache": "^11.0.0", "minipass": "^7.1.2" } }, "sha512-oWyT4gICAu+kaA7QWk/jvCHWarMKNs6pXOGWKDTr7cw4IGcUbW+PeTfbaQiLGheFRpjo6O9J0PmyMfQPjH71oA=="],
44173
174+ "path-to-regexp": ["path-to-regexp@8.3.0", "", {}, "sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA=="],
175+
176+ "pkce-challenge": ["pkce-challenge@5.0.1", "", {}, "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ=="],
177+
45178 "prettier": ["prettier@3.8.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg=="],
46179
180+ "proxy-addr": ["proxy-addr@2.0.7", "", { "dependencies": { "forwarded": "0.2.0", "ipaddr.js": "1.9.1" } }, "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg=="],
181+
182+ "qs": ["qs@6.14.1", "", { "dependencies": { "side-channel": "^1.1.0" } }, "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ=="],
183+
184+ "range-parser": ["range-parser@1.2.1", "", {}, "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="],
185+
186+ "raw-body": ["raw-body@3.0.2", "", { "dependencies": { "bytes": "~3.1.2", "http-errors": "~2.0.1", "iconv-lite": "~0.7.0", "unpipe": "~1.0.0" } }, "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA=="],
187+
188+ "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="],
189+
190+ "router": ["router@2.2.0", "", { "dependencies": { "debug": "^4.4.0", "depd": "^2.0.0", "is-promise": "^4.0.0", "parseurl": "^1.3.3", "path-to-regexp": "^8.0.0" } }, "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ=="],
191+
192+ "safer-buffer": ["safer-buffer@2.1.2", "", {}, "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="],
193+
194+ "send": ["send@1.2.1", "", { "dependencies": { "debug": "^4.4.3", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", "fresh": "^2.0.0", "http-errors": "^2.0.1", "mime-types": "^3.0.2", "ms": "^2.1.3", "on-finished": "^2.4.1", "range-parser": "^1.2.1", "statuses": "^2.0.2" } }, "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ=="],
195+
196+ "serve-static": ["serve-static@2.2.1", "", { "dependencies": { "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "parseurl": "^1.3.3", "send": "^1.2.0" } }, "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw=="],
197+
198+ "setprototypeof": ["setprototypeof@1.2.0", "", {}, "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="],
199+
200+ "shebang-command": ["shebang-command@2.0.0", "", { "dependencies": { "shebang-regex": "^3.0.0" } }, "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA=="],
201+
202+ "shebang-regex": ["shebang-regex@3.0.0", "", {}, "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="],
203+
204+ "side-channel": ["side-channel@1.1.0", "", { "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3", "side-channel-list": "^1.0.0", "side-channel-map": "^1.0.1", "side-channel-weakmap": "^1.0.2" } }, "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw=="],
205+
206+ "side-channel-list": ["side-channel-list@1.0.0", "", { "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3" } }, "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA=="],
207+
208+ "side-channel-map": ["side-channel-map@1.0.1", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3" } }, "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA=="],
209+
210+ "side-channel-weakmap": ["side-channel-weakmap@1.0.2", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3", "side-channel-map": "^1.0.1" } }, "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A=="],
211+
212+ "statuses": ["statuses@2.0.2", "", {}, "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw=="],
213+
214+ "toidentifier": ["toidentifier@1.0.1", "", {}, "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="],
215+
216+ "type-is": ["type-is@2.0.1", "", { "dependencies": { "content-type": "^1.0.5", "media-typer": "^1.1.0", "mime-types": "^3.0.0" } }, "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw=="],
217+
47218 "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
48219
49220 "undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
221+
222+ "unpipe": ["unpipe@1.0.0", "", {}, "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ=="],
223+
224+ "vary": ["vary@1.1.2", "", {}, "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="],
225+
226+ "which": ["which@2.0.2", "", { "dependencies": { "isexe": "^2.0.0" }, "bin": { "node-which": "./bin/node-which" } }, "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA=="],
227+
228+ "wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
229+
230+ "zod": ["zod@4.3.6", "", {}, "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg=="],
231+
232+ "zod-to-json-schema": ["zod-to-json-schema@3.25.1", "", { "peerDependencies": { "zod": "^3.25 || ^4" } }, "sha512-pM/SU9d3YAggzi6MtR4h7ruuQlqKtad8e9S0fmxcMi+ueAK5Korys/aWcV9LIIHTVbj01NdzxcnXSN+O74ZIVA=="],
50233 }
51234 }
packages/client/package.json+3−1
@@ -11,7 +11,9 @@
1111 "start": "bun src/index.ts",
1212 "strip-comments": "bun ../../scripts/strip-comments.ts"
1313 },
14- "dependencies": {},
14+ "dependencies": {
15+ "@modelcontextprotocol/sdk": "^1.25.3"
16+ },
1517 "devDependencies": {
1618 "@types/bun": "latest"
1719 }
packages/client/src/api-definition.ts+0−264
@@ -1,264 +0,0 @@
1-import type { APIDefinition } from "./types.ts";
2-
3-export const GAME_API: APIDefinition = {
4- register: {
5- args: ["username", "empire"],
6- description:
7- "Register a new character. Empire options: solarian, voidborn, crimson, nebula, outerrim. Note: Currently only 'solarian' is available for new players.",
8- },
9- login: {
10- args: ["username", "token"],
11- description: "Login to existing account using saved credentials.",
12- },
13- logout: {
14- args: [],
15- description: "Disconnect and save state.",
16- },
17-
18- travel: {
19- args: ["target_poi"],
20- description:
21- "Travel to a point of interest in the current system. Use POI ID from current system.",
22- },
23- jump: {
24- args: ["target_system"],
25- description:
26- "Jump to an adjacent system. Takes 5 ticks and consumes 5 fuel. Use system ID from current system's connections.",
27- },
28- dock: {
29- args: [],
30- description: "Dock at current POI's station if available.",
31- },
32- undock: {
33- args: [],
34- description: "Leave docked station.",
35- },
36-
37- attack: {
38- args: ["target_id", "weapon_idx"],
39- description:
40- "Attack a player at current location. Target must be nearby. Weapon index starts at 0.",
41- },
42- scan: {
43- args: ["target_id"],
44- description: "Scan a player to reveal information about their ship.",
45- },
46-
47- mine: {
48- args: [],
49- description: "Extract resources from current POI if it contains mineable resources.",
50- },
51-
52- buy: {
53- args: ["listing_id", "quantity"],
54- description: "Buy items from NPC market at current station.",
55- },
56- sell: {
57- args: ["item_id", "quantity"],
58- description: "Sell items from cargo to NPC market at current station for credits.",
59- },
60- list_item: {
61- args: ["item_id", "quantity", "price_each"],
62- description: "List items on player marketplace. Other players can purchase them.",
63- },
64- cancel_list: {
65- args: ["listing_id"],
66- description: "Cancel your marketplace listing and retrieve items.",
67- },
68- buy_listing: {
69- args: ["listing_id", "quantity"],
70- description: "Purchase items from another player's marketplace listing.",
71- },
72- get_listings: {
73- args: [],
74- description:
75- "View all market listings at current station. Returns both NPC and player listings.",
76- },
77-
78- trade_offer: {
79- args: ["target_id", "offer_items", "offer_credits", "request_items", "request_credits"],
80- description: "Propose a trade with another player. Items format: [{item_id, quantity}]",
81- },
82- trade_accept: {
83- args: ["trade_id"],
84- description: "Accept a trade offer from another player.",
85- },
86- trade_decline: {
87- args: ["trade_id"],
88- description: "Decline a trade offer.",
89- },
90- trade_cancel: {
91- args: ["trade_id"],
92- description: "Cancel a trade offer you initiated.",
93- },
94- get_trades: {
95- args: [],
96- description: "View all pending trade offers.",
97- },
98-
99- get_wrecks: {
100- args: [],
101- description: "List ship wrecks at current POI that can be looted.",
102- },
103- loot_wreck: {
104- args: ["wreck_id", "item_id", "quantity"],
105- description: "Take specific items from a wreck.",
106- },
107- salvage_wreck: {
108- args: ["wreck_id"],
109- description: "Destroy wreck completely and receive salvage materials.",
110- },
111-
112- buy_ship: {
113- args: ["ship_class"],
114- description: "Purchase a new ship at current station. Must be docked at a station.",
115- },
116- install_mod: {
117- args: ["module_id", "slot_idx"],
118- description: "Install a module into ship. Must be docked. Module must be in cargo.",
119- },
120- uninstall_mod: {
121- args: ["slot_idx"],
122- description: "Remove a module from ship. Module goes to cargo.",
123- },
124- refuel: {
125- args: [],
126- description: "Refuel ship to maximum capacity. Must be docked at station.",
127- },
128- repair: {
129- args: [],
130- description: "Repair hull and shield damage. Must be docked at station.",
131- },
132-
133- craft: {
134- args: ["recipe_id"],
135- description:
136- "Craft an item using a recipe. Consumes materials from cargo. Must have required skill level.",
137- },
138-
139- chat: {
140- args: ["channel", "content", "target_id?"],
141- description:
142- "Send chat message. Channels: local, system, faction, private. Private requires target_id.",
143- },
144-
145- create_faction: {
146- args: ["name", "tag"],
147- description: "Create a new faction. Tag must be 4 characters. Costs credits.",
148- },
149- join_faction: {
150- args: ["faction_id"],
151- description: "Accept invitation to join a faction.",
152- },
153- leave_faction: {
154- args: [],
155- description: "Leave current faction.",
156- },
157- faction_invite: {
158- args: ["player_id"],
159- description: "Invite a player to your faction. Requires permissions.",
160- },
161- faction_kick: {
162- args: ["player_id"],
163- description: "Remove a member from faction. Requires permissions.",
164- },
165- faction_promote: {
166- args: ["player_id", "role_id"],
167- description: "Change a member's role. Requires permissions.",
168- },
169-
170- buy_insurance: {
171- args: ["coverage_percent"],
172- description: "Purchase ship insurance. Coverage: 50-100%. Pays out if ship is destroyed.",
173- },
174- claim_insurance: {
175- args: [],
176- description: "Claim insurance payout after ship destruction.",
177- },
178- set_home_base: {
179- args: [],
180- description: "Set current station as respawn point. Must be docked at station.",
181- },
182-
183- set_status: {
184- args: ["status_message", "clan_tag"],
185- description: "Update status message and clan tag visible to other players.",
186- },
187- set_colors: {
188- args: ["primary_color", "secondary_color"],
189- description: "Set ship colors. Format: #RRGGBB hex colors.",
190- },
191- set_anonymous: {
192- args: ["anonymous"],
193- description: "Toggle anonymity. When true, hides most information from other players.",
194- },
195-
196- get_status: {
197- args: [],
198- description: "Get current player and ship status. Includes credits, location, ship stats.",
199- },
200- get_system: {
201- args: [],
202- description:
203- "Get detailed information about current star system. Includes POIs and connections.",
204- },
205- get_poi: {
206- args: [],
207- description:
208- "Get information about current point of interest. Includes resources and nearby players.",
209- },
210- get_base: {
211- args: [],
212- description: "Get station information. Must be docked. Shows available services and inventory.",
213- },
214- get_ship: {
215- args: [],
216- description: "Get detailed ship information. Includes all stats, modules, and cargo.",
217- },
218- get_skills: {
219- args: [],
220- description:
221- "Get complete skill tree with all 89 skills, requirements, and your current levels.",
222- },
223- get_recipes: {
224- args: [],
225- description: "Get all available crafting recipes and their requirements.",
226- },
227- get_version: {
228- args: [],
229- description: "Get server version and game information.",
230- },
231- help: {
232- args: ["topic?"],
233- description: "Get help about a specific command or general game help.",
234- },
235-
236- forum_list: {
237- args: ["page", "category"],
238- description: "List forum threads. Categories: general, trading, factions, guides, bugs.",
239- },
240- forum_get_thread: {
241- args: ["thread_id"],
242- description: "Get full thread with all replies.",
243- },
244- forum_create_thread: {
245- args: ["title", "content", "category"],
246- description: "Create a new forum thread.",
247- },
248- forum_reply: {
249- args: ["thread_id", "content"],
250- description: "Reply to a forum thread.",
251- },
252- forum_upvote: {
253- args: ["thread_id?", "reply_id?"],
254- description: "Upvote a thread or reply. Provide one ID.",
255- },
256- forum_delete_thread: {
257- args: ["thread_id"],
258- description: "Delete your own forum thread.",
259- },
260- forum_delete_reply: {
261- args: ["reply_id"],
262- description: "Delete your own forum reply.",
263- },
264-};
packages/client/src/cli.ts+5−8
@@ -115,7 +115,7 @@ OPTIONS:
115115 --verbose Enable detailed logging (shows full message payloads)
116116 -a, --archetype <name> Restrict LLM to single archetype choice (diplomat, opportunist, agitator)
117117 --ollama-timeout <ms> Ollama API timeout in milliseconds (default: 30000)
118- -s, --server <url> WebSocket server URL (default: wss://game.spacemolt.com/ws)
118+ -s, --server <url> MCP server URL (default: https://game.spacemolt.com/mcp)
119119 -cw, --context-window <n> Number of recent messages to include in LLM context (default: 20)
120120
121121 ARCHETYPES:
@@ -129,20 +129,17 @@ ${getModelListText()}
129129 For full model details, see player-models.json at repo root.
130130
131131 EXAMPLES:
132- # Start new game with default model (lfm-thinking)
132+ # Start new game with default model (qwen3-8b)
133133 bun start
134134
135135 # Start with specific instance ID and archetype
136136 bun start --instance abc1 --archetype diplomat
137137
138138 # Use a different model configuration
139- bun start --model qwen3 --archetype diplomat
139+ bun start --model llama3.1-8b --archetype diplomat
140140
141- # Use DeepSeek for large context tasks
142- bun start --model deepseek-r1 --archetype agitator
143-
144- # Start with hint and custom model
145- bun start --hint "Focus on trading" --model qwen2.5
141+ # Start with hint
142+ bun start --hint "Focus on mining and trading"
146143
147144 # Update hint for existing instance
148145 bun start update-hint --instance abc1 --hint "New strategy: explore"
packages/client/src/game-client.ts+241−504
@@ -1,57 +1,43 @@
1-import { GAME_API } from "./api-definition.ts";
21 import { getArchetypeListText } from "./archetypes.ts";
32 import type { GameDatabase } from "./db.ts";
43 import {
5- logClientCommand,
6- logClientError,
74 logClientEvent,
8- logClientWarning,
9- logServerMessage,
5+ logClientError,
106 logThinking,
7+ logToolCall,
8+ logToolResult,
119 type LogContext,
1210 } from "./logging.ts";
1311 import { loadModelConfig } from "./model-config.ts";
14-import { OllamaClient } from "./ollama.ts";
15-import { PLAYER_API_REFERENCE, VALID_COMMAND_TYPES } from "./player-api-reference.ts";
16-import type {
17- BaseCommand,
18- ClientConfig,
19- ErrorMessage,
20- HistoryEntry,
21- LLMContext,
22- LoggedInMessage,
23- RegisteredMessage,
24- ServerMessage,
25- WelcomeMessage,
26-} from "./types.ts";
27-import { GameWebSocketClient } from "./ws-client.ts";
28-
29-const EMPIRES = ["solarian", "voidborn", "crimson", "nebula", "outerrim"];
12+import { MCPClient, type OllamaTool } from "./mcp-client.ts";
13+import { OllamaClient, type ChatMessage, type ToolCall } from "./ollama.ts";
14+import type { ClientConfig } from "./types.ts";
15+
16+interface ResolvedAccount {
17+ username: string;
18+ token: string;
19+ prompt: string;
20+ hint: string | null;
21+}
22+
23+const MAX_TOOL_ITERATIONS = 10;
24+const AGENT_LOOP_DELAY_MS = 1000;
3025
3126 export class GameClient {
3227 private db: GameDatabase;
33- private ws: GameWebSocketClient;
28+ private mcp: MCPClient;
3429 private ollama: OllamaClient;
3530 private config: ClientConfig;
36- private currentTick = 0;
37- private lastProcessedTick = -1;
38- private tickRate: number;
39- private watchdogTimer: Timer | null = null;
40- private isProcessingTick = false;
41- private waitingForRegistration = false;
42- private registrationData: { username: string; empire: string } | null = null;
31+ private messages: ChatMessage[] = [];
32+ private tools: OllamaTool[] = [];
33+ private running = false;
4334
4435 constructor(db: GameDatabase, config: ClientConfig) {
4536 this.db = db;
4637 this.config = config;
47- this.tickRate = config.tickRate;
4838
4939 const modelConfig = loadModelConfig(config.model);
5040
51- if (this.config.contextWindowSize === undefined) {
52- this.config.contextWindowSize = modelConfig.recommendedMessages ?? 12;
53- }
54-
5541 this.ollama = new OllamaClient({
5642 baseUrl: "http://localhost:11434",
5743 model: modelConfig.ollama.model,
@@ -59,576 +45,327 @@ export class GameClient {
5945 timeout: config.ollamaTimeout,
6046 });
6147
62- logClientEvent(this.getLogContext(), "Using model", {
48+ this.mcp = new MCPClient(config.serverUrl || "https://game.spacemolt.com/mcp");
49+
50+ logClientEvent(this.getLogContext(), "GameClient initialized", {
6351 model: config.model,
6452 ollama_model: modelConfig.ollama.model,
65- context_messages: config.contextWindowSize,
66- });
67-
68- this.ws = new GameWebSocketClient({
69- url: config.serverUrl || "wss://game.spacemolt.com/ws",
70- onMessage: (msg) => {
71- this.handleServerMessage(msg).catch((error) => {
72- logClientError(this.getLogContext(), "Unhandled error in message handler", error);
73- });
74- },
75- onConnect: () => this.handleConnect(),
76- onDisconnect: () => this.handleDisconnect(),
77- onError: (err) => this.handleError(err),
7853 });
7954 }
8055
8156 async start(): Promise<void> {
8257 logClientEvent(this.getLogContext(), "Starting game client");
8358
84- this.db.setLoggedOut(false);
85- await this.ws.connect();
86- }
59+ logClientEvent(this.getLogContext(), "Connecting to MCP server...");
60+ await this.mcp.connect();
61+ this.tools = this.mcp.getOllamaTools();
62+ logClientEvent(this.getLogContext(), "MCP connected", { tool_count: this.tools.length });
8763
88- stop(): void {
89- if (this.watchdogTimer) {
90- clearTimeout(this.watchdogTimer);
91- this.watchdogTimer = null;
92- }
93- this.ws.disconnect();
94- this.db.close();
95- logClientEvent(this.getLogContext(), "Client stopped");
96- }
64+ const username = this.db.getActiveUsername();
9765
98- private handleConnect(): void {
99- logClientEvent(this.getLogContext(), "Connected to server");
100- }
66+ if (username) {
67+ const instance = this.db.getInstance();
68+ const account: ResolvedAccount = {
69+ username: username.username,
70+ token: username.token,
71+ prompt: username.prompt,
72+ hint: instance.hint || this.config.hint || null,
73+ };
74+ await this.initializeWithAccount(account);
75+ } else {
76+ await this.initializeNewAccount();
77+ }
10178
102- private handleDisconnect(): void {
103- logClientWarning(this.getLogContext(), "Disconnected from server");
79+ this.running = true;
80+ await this.runAgentLoop();
10481 }
10582
106- private handleError(error: Error): void {
107- logClientError(this.getLogContext(), "Connection error", error);
108- this.db.saveMessage(this.currentTick, "client", {
109- error: "Connection error occurred",
110- code: "CONNECTION_ERROR",
111- });
83+ async stop(): Promise<void> {
84+ this.running = false;
85+ await this.mcp.disconnect();
86+ this.db.close();
87+ logClientEvent(this.getLogContext(), "Client stopped");
11288 }
11389
114- private async handleServerMessage(message: ServerMessage): Promise<void> {
115- try {
116- logServerMessage(this.getLogContext(), message);
117-
118- switch (message.type) {
119- case "welcome":
120- this.db.saveMessage(this.currentTick, "server", message);
121- await this.handleWelcome(message as WelcomeMessage);
122- break;
123- case "registered":
124- this.db.saveMessage(this.currentTick, "server", message);
125- await this.handleRegistered(message as RegisteredMessage);
126- break;
127- case "logged_in":
128- this.db.saveMessage(this.currentTick, "server", message);
129- this.handleLoggedIn(message as LoggedInMessage);
130- break;
131- case "tick":
132- case "state_update":
133- const shouldProcess = await this.handleTick(message as { payload: { tick: number } });
134- if (shouldProcess) {
135- this.db.saveMessage(this.currentTick, "server", message);
136- }
137- break;
138- case "error":
139- this.db.saveMessage(this.currentTick, "server", message);
140- this.handleServerError(message as ErrorMessage);
141- break;
142- case "ok":
143- this.db.saveMessage(this.currentTick, "server", message);
144- this.handleOk(message as { type: "ok"; payload: { action: string } });
145- break;
146- default:
147- this.db.saveMessage(this.currentTick, "server", message);
148- break;
149- }
150- } catch (error) {
151- logClientError(this.getLogContext(), `Error handling ${message.type} message`, error);
152- this.db.saveMessage(this.currentTick, "client", {
153- error: `Failed to handle ${message.type} message: ${error instanceof Error ? error.message : String(error)}`,
154- code: "MESSAGE_HANDLER_ERROR",
155- });
156- }
157- }
90+ private async initializeWithAccount(account: ResolvedAccount): Promise<void> {
91+ logClientEvent(this.getLogContext(account.username), "Resuming with existing account");
15892
159- private async handleWelcome(message: WelcomeMessage): Promise<void> {
160- this.tickRate = message.payload.tick_rate * 1000;
161- this.currentTick = message.payload.current_tick;
162- this.lastProcessedTick = this.currentTick - 1;
163- this.startWatchdog();
93+ const systemPrompt = this.buildSystemPrompt(account.prompt, account.hint);
94+ this.messages = [{ role: "system", content: systemPrompt }];
16495
165- const activeUsername = this.db.getActiveUsername();
166- const wasLoggedOut = this.db.isLoggedOut();
96+ this.loadMessageHistory();
16797
168- if (activeUsername && !wasLoggedOut) {
169- logClientEvent(this.getLogContext(activeUsername.username), "Auto-login", {
170- username: activeUsername.username,
171- });
172- this.ws.send({
173- type: "login",
174- payload: { username: activeUsername.username, token: activeUsername.token },
175- });
176- } else if (!activeUsername) {
177- await this.promptForRegistration().catch((error) => {
178- logClientError(this.getLogContext(), "Registration prompt error", error);
179- this.db.saveMessage(this.currentTick, "client", {
180- error: "Registration prompt failed",
181- code: "REGISTRATION_PROMPT_ERROR",
182- });
183- });
184- } else {
185- await this.promptForLogin(activeUsername.username, activeUsername.token).catch((error) => {
186- logClientError(this.getLogContext(activeUsername.username), "Login prompt error", error);
187- this.db.saveMessage(this.currentTick, "client", {
188- error: "Login prompt failed",
189- code: "LOGIN_PROMPT_ERROR",
190- });
191- });
192- }
98+ this.messages.push({
99+ role: "user",
100+ content: `You are resuming play as "${account.username}".
101+Use login(username="${account.username}", token="${account.token}") to authenticate, then continue playing.
102+After login, check your status with get_status() and decide what to do next.`,
103+ });
193104 }
194105
195- private async handleTick(message: { payload: { tick: number } }): Promise<boolean> {
196- const newTick = message.payload.tick;
106+ private async initializeNewAccount(): Promise<void> {
107+ logClientEvent(this.getLogContext(), "Creating new account");
197108
198- if (newTick <= this.lastProcessedTick) {
199- logClientWarning(this.getLogContext(), "Ignoring duplicate or stale tick", {
200- new_tick: newTick,
201- last_processed_tick: this.lastProcessedTick,
202- });
203- return false;
204- }
109+ const archetypeList = getArchetypeListText(this.config.archetype);
110+ const instanceSuffix = this.config.instanceId?.slice(0, 3).toLowerCase() || "xxx";
205111
206- if (this.isProcessingTick) {
207- logClientWarning(this.getLogContext(), "Skipping tick, still processing", {
208- skipped_tick: newTick,
209- current_tick: this.currentTick,
210- });
211- return false;
212- }
112+ const registrationPrompt = `You are about to create a new character in SpaceMolt - The Crustacean Cosmos.
213113
214- this.currentTick = newTick;
215- this.isProcessingTick = true;
114+Choose a personality archetype:
115+${archetypeList}
216116
217- this.startWatchdog();
117+Create your character:
118+1. Pick a creative username (will have "-${instanceSuffix}" appended automatically)
119+2. Choose empire: "solarian" (only one available currently)
120+3. Call register(username="YourName", empire="solarian")
218121
219- try {
220- await this.processTick();
221- this.lastProcessedTick = newTick;
222- } catch (error) {
223- logClientError(this.getLogContext(), "Tick processing error", error);
224- this.db.saveMessage(this.currentTick, "client", {
225- error: "Tick processing failed",
226- code: "TICK_PROCESSING_ERROR",
227- });
228- } finally {
229- this.isProcessingTick = false;
230- }
122+After registration succeeds, you'll receive a token. The system will save your credentials automatically.
123+Then check your status with get_status() and begin playing!`;
231124
232- return true;
125+ const systemPrompt = this.buildSystemPrompt("", this.config.hint);
126+ this.messages = [
127+ { role: "system", content: systemPrompt },
128+ { role: "user", content: registrationPrompt },
129+ ];
233130 }
234131
235- private async handleRegistered(message: RegisteredMessage): Promise<void> {
236- if (!this.registrationData) {
237- return;
238- }
239-
240- logClientEvent(this.getLogContext(this.registrationData.username), "Registration successful");
241-
242- const characterPrompt = await this.generateCharacterPrompt(
243- this.registrationData.username,
244- this.registrationData.empire,
245- );
132+ private buildSystemPrompt(characterPrompt: string, hint?: string | null): string {
133+ const parts: string[] = [];
246134
247- this.db.saveUsername(
248- this.registrationData.username,
249- message.payload.token,
250- characterPrompt,
251- message.payload.player_id,
252- this.currentTick,
253- );
135+ parts.push(`You are a player in SpaceMolt - The Crustacean Cosmos, an MMO for AI agents.`);
254136
255- logClientEvent(
256- this.getLogContext(this.registrationData.username),
257- "Character prompt generated and saved",
258- );
259-
260- this.waitingForRegistration = false;
261- this.registrationData = null;
262- }
263-
264- private shuffleArray<T>(array: T[]): T[] {
265- const shuffled = [...array];
266- for (let i = shuffled.length - 1; i > 0; i--) {
267- const j = Math.floor(Math.random() * (i + 1));
268- [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
137+ if (characterPrompt) {
138+ parts.push(`\nYour character:\n${characterPrompt}`);
269139 }
270- return shuffled;
271- }
272140
273- private getApiSubset<K extends keyof typeof PLAYER_API_REFERENCE>(
274- commands: K[],
275- ): Pick<typeof PLAYER_API_REFERENCE, K> {
276- return Object.fromEntries(commands.map((cmd) => [cmd, PLAYER_API_REFERENCE[cmd]])) as Pick<
277- typeof PLAYER_API_REFERENCE,
278- K
279- >;
280- }
281-
282- private async generateCharacterPrompt(username: string, empire: string): Promise<string> {
283- const archetypeList = getArchetypeListText(this.config.archetype);
141+ if (hint) {
142+ parts.push(`\nGuidance from your operator:\n${hint}`);
143+ }
284144
285- const promptGeneration = `You are creating a character for a sci-fi themed online multiplayer game called SpaceMolt. The character's name is "${username}" and they belong to the "${empire}" empire.
145+ parts.push(`
146+You have full agency. Make your own decisions. You are NOT an assistant - you are a player.
286147
287-Choose a personality archetype from this list:
288-${archetypeList}
148+Key behaviors:
149+- Use get_notifications() periodically to check for chat messages, combat alerts, trade offers
150+- If rate limited, wait and try again - the error tells you how long
151+- Be social! Chat with other players, form alliances, make enemies
152+- Keep a captain's log of your adventures with captains_log_add()
153+- Post on the forums to share discoveries and discuss strategy
289154
290-Generate a concise role playing character prompt (5 sentences max) that captures this character's personality, goals, and playstyle based on your chosen personality archetype.
155+You decide your goals: mining, trading, combat, exploration, faction politics - it's your game.`);
291156
292-Character prompt:`;
157+ return parts.join("\n");
158+ }
293159
294- try {
295- const result = await this.ollama.generate(promptGeneration);
160+ private async runAgentLoop(): Promise<void> {
161+ logClientEvent(this.getLogContext(), "Starting agent loop");
296162
297- if (result.thinking) {
298- logThinking(this.getLogContext(username), result.thinking);
163+ while (this.running) {
164+ try {
165+ await this.processOneRound();
166+ await this.delay(AGENT_LOOP_DELAY_MS);
167+ } catch (error) {
168+ logClientError(this.getLogContext(), "Agent loop error", error);
169+ await this.delay(5000);
299170 }
300-
301- return result.response;
302- } catch (error) {
303- logClientError(this.getLogContext(username), "Failed to generate prompt", error);
304- return `You are ${username}, a ${empire} player in SpaceMolt.`;
305171 }
306172 }
307173
308- private async promptForRegistration(): Promise<void> {
309- const minimalContext = {
310- api: this.getApiSubset(["register"]),
311- note: "You must register before you can play. Usernames MUST be alpha numeric and maximum 20 characters",
312- };
313-
314- const contextJson = JSON.stringify(minimalContext);
315- const shuffledEmpires = this.shuffleArray(EMPIRES);
316- const empireList = shuffledEmpires.join(", ");
317- const registrationPrompt = `You are playing a multiplayer space game called SpaceMolt, 🦞 **The Crustacean Cosmos** 🦞. You need to register a username to play.
318-
319-Game Context:
320-${contextJson}
321-
322-Choose a creative username.
323-Choose an empire from: ${empireList}
324-
325-CRITICAL: You must respond with a SINGLE, VALID JSON OBJECT
174+ private async processOneRound(): Promise<void> {
175+ let iterations = 0;
326176
327-JSON Format:
328-{"type": "register", "payload": {"username": "[your username]", "empire": "[your empire]"}}
177+ while (iterations < MAX_TOOL_ITERATIONS) {
178+ iterations++;
329179
330-Your JSON response:`;
331-
332- try {
333- const result = await this.ollama.generate(registrationPrompt);
180+ const result = await this.ollama.chat(this.messages, this.tools);
334181
335182 if (result.thinking) {
336183 logThinking(this.getLogContext(), result.thinking);
337184 }
338185
339- let command: BaseCommand;
340- try {
341- command = JSON.parse(result.response);
342- } catch {
343- command = this.extractJSON(result.response);
344- }
345-
346- if (command.type !== "register" || !command.payload) {
347- throw new Error("Invalid registration command: missing type or payload");
348- }
349-
350- const payload = command.payload as { username: string; empire: string };
351- if (!payload.username || !payload.empire) {
352- throw new Error("Invalid registration payload: missing username or empire");
353- }
186+ if (result.toolCalls.length > 0) {
187+ this.messages.push({
188+ role: "assistant",
189+ content: result.content,
190+ tool_calls: result.toolCalls,
Cut short: this commit's diff is over 1000 lines.
packages/client/src/logging.ts+29−324
Cut short: this commit's diff is over 1000 lines.
packages/client/src/mcp-client.ts+119−0
Cut short: this commit's diff is over 1000 lines.
packages/client/src/ollama.ts+55−36
Cut short: this commit's diff is over 1000 lines.
packages/client/src/player-api-reference.ts+0−155
Cut short: this commit's diff is over 1000 lines.
packages/client/src/types.ts+0−411
Cut short: this commit's diff is over 1000 lines.
packages/client/src/ws-client.ts+0−222
Cut short: this commit's diff is over 1000 lines.
packages/client/tests/json-extraction.test.ts+0−104
Cut short: this commit's diff is over 1000 lines.
packages/client/tests/logging.test.ts+0−25
Cut short: this commit's diff is over 1000 lines.
packages/client/tests/logout-reconnect.test.ts+0−108
Cut short: this commit's diff is over 1000 lines.
packages/client/tests/mock-server.ts+0−175
Cut short: this commit's diff is over 1000 lines.
packages/client/tests/model-config.test.ts+25−26
Cut short: this commit's diff is over 1000 lines.
packages/client/tests/ollama.test.ts+76−159
Cut short: this commit's diff is over 1000 lines.
packages/client/tests/ws-client.test.ts+0−189
Cut short: this commit's diff is over 1000 lines.
packages/client/tests/ws-message-handling.test.ts+0−225
Cut short: this commit's diff is over 1000 lines.
player-models.json+32−20
Cut short: this commit's diff is over 1000 lines.