@aifight/aifight 0.1.0-alpha.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 (176) hide show
  1. package/README.md +160 -0
  2. package/dist/bin.mjs +291 -0
  3. package/dist/index.mjs +107 -0
  4. package/dist/schemas/README.md +57 -0
  5. package/dist/schemas/common/README.md +40 -0
  6. package/dist/schemas/common/action.schema.json +19 -0
  7. package/dist/schemas/common/error.schema.json +23 -0
  8. package/dist/schemas/common/event.schema.json +33 -0
  9. package/dist/schemas/common/game_result.schema.json +31 -0
  10. package/dist/schemas/common/player_identity.schema.json +29 -0
  11. package/dist/schemas/common/player_info.schema.json +27 -0
  12. package/dist/schemas/common/rules.schema.json +34 -0
  13. package/dist/schemas/games/README.md +43 -0
  14. package/dist/schemas/games/coup/README.md +104 -0
  15. package/dist/schemas/games/coup/action.schema.json +198 -0
  16. package/dist/schemas/games/coup/event.schema.json +249 -0
  17. package/dist/schemas/games/coup/rules.schema.json +46 -0
  18. package/dist/schemas/games/coup/state.schema.json +123 -0
  19. package/dist/schemas/games/liars_dice/README.md +59 -0
  20. package/dist/schemas/games/liars_dice/action.schema.json +45 -0
  21. package/dist/schemas/games/liars_dice/event.schema.json +120 -0
  22. package/dist/schemas/games/liars_dice/rules.schema.json +36 -0
  23. package/dist/schemas/games/liars_dice/state.schema.json +72 -0
  24. package/dist/schemas/games/texas_holdem/README.md +58 -0
  25. package/dist/schemas/games/texas_holdem/action.schema.json +88 -0
  26. package/dist/schemas/games/texas_holdem/config.schema.json +30 -0
  27. package/dist/schemas/games/texas_holdem/event.schema.json +135 -0
  28. package/dist/schemas/games/texas_holdem/rules.schema.json +39 -0
  29. package/dist/schemas/games/texas_holdem/state.schema.json +98 -0
  30. package/dist/schemas/messages/README.md +98 -0
  31. package/dist/schemas/messages/client_action.schema.json +20 -0
  32. package/dist/schemas/messages/client_join_queue.schema.json +39 -0
  33. package/dist/schemas/messages/client_leave_queue.schema.json +18 -0
  34. package/dist/schemas/messages/client_match_confirm.schema.json +25 -0
  35. package/dist/schemas/messages/client_runtime_status.schema.json +46 -0
  36. package/dist/schemas/messages/server_action_request.schema.json +71 -0
  37. package/dist/schemas/messages/server_error.schema.json +16 -0
  38. package/dist/schemas/messages/server_event.schema.json +30 -0
  39. package/dist/schemas/messages/server_game_over.schema.json +49 -0
  40. package/dist/schemas/messages/server_game_start.schema.json +99 -0
  41. package/dist/schemas/messages/server_game_state.schema.json +33 -0
  42. package/dist/schemas/messages/server_match_cancelled.schema.json +51 -0
  43. package/dist/schemas/messages/server_match_confirm_request.schema.json +37 -0
  44. package/dist/schemas/messages/server_queue_joined.schema.json +26 -0
  45. package/dist/schemas/messages/server_queue_left.schema.json +24 -0
  46. package/dist/schemas/messages/server_readiness_check.schema.json +42 -0
  47. package/dist/schemas/messages/server_welcome.schema.json +49 -0
  48. package/dist/schemas/rest/README.md +85 -0
  49. package/dist/schemas/rest/agent_status_response.schema.json +34 -0
  50. package/dist/schemas/rest/claim_request.schema.json +20 -0
  51. package/dist/schemas/rest/claim_response.schema.json +24 -0
  52. package/dist/schemas/rest/error_response.schema.json +15 -0
  53. package/dist/schemas/rest/register_request.schema.json +35 -0
  54. package/dist/schemas/rest/register_response.schema.json +54 -0
  55. package/dist/types/account/credentials.d.ts +29 -0
  56. package/dist/types/account/errors.d.ts +61 -0
  57. package/dist/types/account/registration.d.ts +26 -0
  58. package/dist/types/agents/agent.d.ts +82 -0
  59. package/dist/types/agents/state-machine.d.ts +96 -0
  60. package/dist/types/bridge/config.d.ts +35 -0
  61. package/dist/types/bridge/hermes-provider.d.ts +9 -0
  62. package/dist/types/bridge/openclaw-provider.d.ts +9 -0
  63. package/dist/types/bridge/pairing.d.ts +18 -0
  64. package/dist/types/bridge/provider.d.ts +18 -0
  65. package/dist/types/bridge/runner.d.ts +30 -0
  66. package/dist/types/bridge/service.d.ts +55 -0
  67. package/dist/types/bridge/update-check.d.ts +23 -0
  68. package/dist/types/cli/agent-resolver.d.ts +25 -0
  69. package/dist/types/cli/argv.d.ts +13 -0
  70. package/dist/types/cli/commands/agent-list.d.ts +2 -0
  71. package/dist/types/cli/commands/agent-status.d.ts +2 -0
  72. package/dist/types/cli/commands/bridge-accept.d.ts +2 -0
  73. package/dist/types/cli/commands/bridge-challenge.d.ts +2 -0
  74. package/dist/types/cli/commands/bridge-connect.d.ts +2 -0
  75. package/dist/types/cli/commands/bridge-register.d.ts +2 -0
  76. package/dist/types/cli/commands/bridge-run.d.ts +7 -0
  77. package/dist/types/cli/commands/bridge-service.d.ts +3 -0
  78. package/dist/types/cli/commands/bridge-set.d.ts +2 -0
  79. package/dist/types/cli/commands/bridge-start.d.ts +2 -0
  80. package/dist/types/cli/commands/bridge-status.d.ts +2 -0
  81. package/dist/types/cli/commands/bridge-uninstall.d.ts +4 -0
  82. package/dist/types/cli/commands/config-init.d.ts +2 -0
  83. package/dist/types/cli/commands/config-probe.d.ts +2 -0
  84. package/dist/types/cli/commands/config-validate.d.ts +2 -0
  85. package/dist/types/cli/commands/daily-off.d.ts +2 -0
  86. package/dist/types/cli/commands/daily-on.d.ts +2 -0
  87. package/dist/types/cli/commands/daily-set.d.ts +2 -0
  88. package/dist/types/cli/commands/daily-show.d.ts +2 -0
  89. package/dist/types/cli/commands/doctor.d.ts +2 -0
  90. package/dist/types/cli/commands/init.d.ts +2 -0
  91. package/dist/types/cli/commands/join.d.ts +2 -0
  92. package/dist/types/cli/commands/leave.d.ts +2 -0
  93. package/dist/types/cli/commands/mcp.d.ts +2 -0
  94. package/dist/types/cli/commands/runtime-management.d.ts +16 -0
  95. package/dist/types/cli/commands/runtime-setup-state.d.ts +21 -0
  96. package/dist/types/cli/commands/runtime-setup.d.ts +23 -0
  97. package/dist/types/cli/commands/serve.d.ts +2 -0
  98. package/dist/types/cli/commands/service/launchd.d.ts +71 -0
  99. package/dist/types/cli/commands/service/platform.d.ts +69 -0
  100. package/dist/types/cli/commands/service/systemd.d.ts +55 -0
  101. package/dist/types/cli/commands/service/types.d.ts +64 -0
  102. package/dist/types/cli/commands/service-install.d.ts +29 -0
  103. package/dist/types/cli/commands/setup.d.ts +2 -0
  104. package/dist/types/cli/commands/shutdown.d.ts +2 -0
  105. package/dist/types/cli/commands/stubs.d.ts +24 -0
  106. package/dist/types/cli/commands/version.d.ts +2 -0
  107. package/dist/types/cli/control-client.d.ts +59 -0
  108. package/dist/types/cli/format.d.ts +52 -0
  109. package/dist/types/cli/main.d.ts +18 -0
  110. package/dist/types/cli/runtime-files.d.ts +11 -0
  111. package/dist/types/cli/shared.d.ts +74 -0
  112. package/dist/types/controlapi/profile-routes.d.ts +49 -0
  113. package/dist/types/controlapi/server.d.ts +3 -0
  114. package/dist/types/controlapi/types.d.ts +136 -0
  115. package/dist/types/daemon/agent-decision-adapter.d.ts +40 -0
  116. package/dist/types/daemon/lifecycle.d.ts +85 -0
  117. package/dist/types/daemon/router.d.ts +97 -0
  118. package/dist/types/daemon/runtime-files-write.d.ts +76 -0
  119. package/dist/types/decision/direct-model/anthropic.d.ts +12 -0
  120. package/dist/types/decision/direct-model/errors.d.ts +59 -0
  121. package/dist/types/decision/direct-model/openai.d.ts +12 -0
  122. package/dist/types/decision/direct-model/types.d.ts +20 -0
  123. package/dist/types/decision/parser-types.d.ts +31 -0
  124. package/dist/types/decision/prompt-builder.d.ts +10 -0
  125. package/dist/types/decision/provider.d.ts +50 -0
  126. package/dist/types/decision/types.d.ts +87 -0
  127. package/dist/types/games/_shared/player-info.d.ts +14 -0
  128. package/dist/types/games/coup/action-parser.d.ts +3 -0
  129. package/dist/types/games/coup/fallback.d.ts +8 -0
  130. package/dist/types/games/coup/state-formatter.d.ts +14 -0
  131. package/dist/types/games/liars_dice/action-parser.d.ts +3 -0
  132. package/dist/types/games/liars_dice/fallback.d.ts +8 -0
  133. package/dist/types/games/liars_dice/state-formatter.d.ts +14 -0
  134. package/dist/types/games/texas_holdem/action-parser.d.ts +3 -0
  135. package/dist/types/games/texas_holdem/fallback.d.ts +8 -0
  136. package/dist/types/games/texas_holdem/state-formatter.d.ts +14 -0
  137. package/dist/types/identity/identity-manager.d.ts +59 -0
  138. package/dist/types/index.d.ts +30 -0
  139. package/dist/types/llm/adapter-registry.d.ts +27 -0
  140. package/dist/types/llm/adapters/anthropic-messages.d.ts +2 -0
  141. package/dist/types/llm/adapters/deepseek-chat-completions.d.ts +2 -0
  142. package/dist/types/llm/adapters/openai-chat-compat.d.ts +2 -0
  143. package/dist/types/llm/adapters/openai-chat-completions.d.ts +2 -0
  144. package/dist/types/llm/adapters/openai-responses.d.ts +2 -0
  145. package/dist/types/llm/adapters/types.d.ts +128 -0
  146. package/dist/types/llm/capabilities/validate-capabilities.d.ts +68 -0
  147. package/dist/types/mcp/control-client.d.ts +54 -0
  148. package/dist/types/mcp/profile-tools.d.ts +10 -0
  149. package/dist/types/mcp/server.d.ts +10 -0
  150. package/dist/types/mcp/tools.d.ts +31 -0
  151. package/dist/types/mcp/types.d.ts +27 -0
  152. package/dist/types/profile/config-schema.d.ts +199 -0
  153. package/dist/types/profile/identity-schema.d.ts +75 -0
  154. package/dist/types/profile/index.d.ts +7 -0
  155. package/dist/types/profile/migrate.d.ts +16 -0
  156. package/dist/types/profile/profile-loader.d.ts +64 -0
  157. package/dist/types/profile/secret-ref.d.ts +82 -0
  158. package/dist/types/profile/soul.d.ts +46 -0
  159. package/dist/types/profile/strategy-schema.d.ts +70 -0
  160. package/dist/types/protocol/schemas.d.ts +11 -0
  161. package/dist/types/protocol/types.d.ts +1333 -0
  162. package/dist/types/reflection/proposal-store.d.ts +50 -0
  163. package/dist/types/reflection/reflection-engine.d.ts +81 -0
  164. package/dist/types/scheduler/daily.d.ts +47 -0
  165. package/dist/types/scheduler/types.d.ts +42 -0
  166. package/dist/types/session/match-session-manager.d.ts +113 -0
  167. package/dist/types/session/session-context-builder.d.ts +68 -0
  168. package/dist/types/store/errors.d.ts +23 -0
  169. package/dist/types/store/paths.d.ts +3 -0
  170. package/dist/types/store/schema.generated.d.ts +1 -0
  171. package/dist/types/store/sqlite.d.ts +36 -0
  172. package/dist/types/wsclient/client.d.ts +220 -0
  173. package/dist/types/wsclient/errors.d.ts +106 -0
  174. package/dist/types/wsclient/frame-handler.d.ts +20 -0
  175. package/dist/types/wsclient/reconnect.d.ts +84 -0
  176. package/package.json +53 -0
@@ -0,0 +1,199 @@
1
+ /**
2
+ * config-schema.ts
3
+ *
4
+ * TypeScript interfaces, types, and validator for the AIFight daemon's
5
+ * config.json file. Covers LLM provider configuration ONLY — no game
6
+ * strategy, no personality settings.
7
+ *
8
+ * Design principles:
9
+ * - Protocol-first (not vendor-first): the same model can be reached via
10
+ * multiple protocols; the protocol field dictates wire format.
11
+ * - SecretRef indirection: API keys are never stored as raw strings.
12
+ * - Normalized reasoning/thinking config that maps onto every provider.
13
+ * - Per-game routing with a fallback profile.
14
+ * - No runtime dependencies beyond Node built-ins.
15
+ */
16
+ /** Wire-level protocol used to call the LLM provider. */
17
+ export type Protocol = "anthropic_messages" | "openai_responses" | "openai_chat_completions" | "openai_chat_compat" | "deepseek_chat_completions" | "gemini_generate_content" | "gemini_openai_compat";
18
+ /** Reasoning/thinking effort level. "auto" lets the provider decide. */
19
+ export type ReasoningEffort = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" | "auto";
20
+ /** Games supported for per-game routing. */
21
+ export type GameType = "texas_holdem" | "liars_dice" | "coup";
22
+ /** How much of the prompt to persist in logs. */
23
+ export type PromptStoreMode = "full" | "redacted" | "none";
24
+ /** Read the secret from an environment variable. */
25
+ export interface SecretRefEnv {
26
+ type: "env";
27
+ /** Name of the environment variable (e.g. "ANTHROPIC_API_KEY"). */
28
+ name: string;
29
+ }
30
+ /** Read a specific key from a .env-style file. */
31
+ export interface SecretRefEnvFile {
32
+ type: "env_file";
33
+ /** Absolute or relative path to the env file. */
34
+ path: string;
35
+ /** Variable name inside the file. */
36
+ name: string;
37
+ }
38
+ /** Read the entire file content as the secret. */
39
+ export interface SecretRefFile {
40
+ type: "file";
41
+ /** Absolute or relative path to the file. */
42
+ path: string;
43
+ }
44
+ /** Read from the OS keychain (macOS Keychain, Windows Credential Manager, etc.). */
45
+ export interface SecretRefKeychain {
46
+ type: "keychain";
47
+ service: string;
48
+ account: string;
49
+ }
50
+ /** Obtain the secret by running an external command (e.g. `op run`). */
51
+ export interface SecretRefCommand {
52
+ type: "command";
53
+ command: string;
54
+ args?: string[];
55
+ /** Milliseconds to wait for the command to exit. Defaults to 5000. */
56
+ timeoutMs?: number;
57
+ }
58
+ export type SecretRef = SecretRefEnv | SecretRefEnvFile | SecretRefFile | SecretRefKeychain | SecretRefCommand;
59
+ export interface RequestConfig {
60
+ /**
61
+ * Sampling temperature. null means "use the provider default" (useful when
62
+ * thinking/extended-thinking is active, since many providers require
63
+ * temperature=1 in that mode).
64
+ */
65
+ temperature?: number | null;
66
+ /** Maximum output tokens per LLM call. */
67
+ maxTokens?: number;
68
+ /**
69
+ * Response format hint. "json" instructs the provider to return JSON where
70
+ * supported; "text" is plain text.
71
+ */
72
+ responseFormat?: "json" | "text";
73
+ }
74
+ export interface ThinkingConfig {
75
+ enabled: boolean;
76
+ /**
77
+ * "adaptive" — let the daemon decide per-request based on game complexity.
78
+ * "always" — always activate thinking.
79
+ * "never" — never activate thinking (overrides enabled=true).
80
+ */
81
+ mode?: "adaptive" | "always" | "never";
82
+ /** Effort level passed to the provider (provider-specific mapping applied). */
83
+ effort?: ReasoningEffort;
84
+ /** Hard cap on reasoning/thinking tokens (provider-specific field name). */
85
+ maxReasoningTokens?: number;
86
+ }
87
+ export interface TimeoutsConfig {
88
+ /** Total request timeout in milliseconds. */
89
+ requestMs?: number;
90
+ /** TCP connection timeout in milliseconds. */
91
+ connectMs?: number;
92
+ }
93
+ export interface RetriesConfig {
94
+ /** Maximum number of attempts (1 = no retry). */
95
+ maxAttempts?: number;
96
+ /** Base back-off in milliseconds (exponential back-off applied). */
97
+ backoffMs?: number;
98
+ }
99
+ export interface BudgetsConfig {
100
+ /** Abort a match if cumulative LLM cost exceeds this (USD). */
101
+ maxCostUSDPerMatch?: number;
102
+ /** Truncate / warn when a single decision consumes more than this many tokens. */
103
+ maxOutputTokensPerDecision?: number;
104
+ }
105
+ export interface LLMProfile {
106
+ /** Human-readable label shown in logs and the CLI. */
107
+ displayName?: string;
108
+ /** Wire protocol used to call this provider. */
109
+ protocol: Protocol;
110
+ /**
111
+ * Provider base URL. Omit to use the protocol's canonical default
112
+ * (e.g. https://api.anthropic.com for anthropic_messages).
113
+ */
114
+ baseURL?: string;
115
+ /** Indirection to the API key — never a raw string. */
116
+ apiKeyRef: SecretRef;
117
+ /**
118
+ * Model identifier in the provider's namespace
119
+ * (e.g. "claude-opus-4-7", "gpt-4o", "deepseek-chat").
120
+ */
121
+ model: string;
122
+ /** Sampling and format parameters. */
123
+ request?: RequestConfig;
124
+ /** Extended-thinking / reasoning configuration. */
125
+ thinking?: ThinkingConfig;
126
+ /** Network timeouts. */
127
+ timeouts?: TimeoutsConfig;
128
+ /** Retry policy on transient errors (429, 503, network). */
129
+ retries?: RetriesConfig;
130
+ /** Cost and token budgets that trigger warnings or hard stops. */
131
+ budgets?: BudgetsConfig;
132
+ }
133
+ export interface RoutingConfig {
134
+ /** Profile name used when no per-game route is configured. */
135
+ default: string;
136
+ /** Optional per-game overrides. Keys are GameType values. */
137
+ byGame?: Partial<Record<GameType, string>>;
138
+ /**
139
+ * Profile name to fall back to when the primary profile fails (rate limit,
140
+ * outage, budget exhaustion). Must differ from the profiles it backs up.
141
+ */
142
+ fallbackProfile?: string;
143
+ }
144
+ export interface LoggingConfig {
145
+ /**
146
+ * "full" — store the full prompt (may contain strategy details).
147
+ * "redacted" — store only metadata + token counts.
148
+ * "none" — do not log prompts.
149
+ */
150
+ storePrompts?: PromptStoreMode;
151
+ /** Whether to store the raw JSON response from the provider. */
152
+ storeRawProviderResponses?: boolean;
153
+ /** Whether to store the reasoning/thinking content (can be large). */
154
+ storeReasoningContent?: boolean;
155
+ }
156
+ export interface LLMConfig {
157
+ /** Schema version for forward compatibility. Currently must be 1. */
158
+ schemaVersion: 1;
159
+ /** Key into `profiles` that the daemon uses by default. */
160
+ activeProfile: string;
161
+ /** Map of profile name → profile definition. At least one entry required. */
162
+ profiles: Record<string, LLMProfile>;
163
+ /** Game-level routing rules. */
164
+ routing: RoutingConfig;
165
+ /** Logging preferences. */
166
+ logging?: LoggingConfig;
167
+ }
168
+ type ValidationResult = {
169
+ ok: true;
170
+ config: LLMConfig;
171
+ } | {
172
+ ok: false;
173
+ errors: string[];
174
+ };
175
+ /**
176
+ * Validate an unknown value (typically from JSON.parse) as an LLMConfig.
177
+ *
178
+ * Returns `{ ok: true, config }` on success, or
179
+ * `{ ok: false, errors }` with a list of human-readable messages on failure.
180
+ *
181
+ * Example:
182
+ * ```ts
183
+ * const raw = JSON.parse(fs.readFileSync("config.json", "utf8"));
184
+ * const result = validateConfig(raw);
185
+ * if (!result.ok) {
186
+ * console.error(result.errors.join("\n"));
187
+ * process.exit(1);
188
+ * }
189
+ * const config = result.config;
190
+ * ```
191
+ */
192
+ export declare function validateConfig(raw: unknown): ValidationResult;
193
+ /**
194
+ * A minimal valid LLMConfig that uses Claude claude-sonnet-4-6 via the
195
+ * Anthropic Messages API, reading the API key from the ANTHROPIC_API_KEY
196
+ * environment variable. Suitable as a starter template or fallback.
197
+ */
198
+ export declare const DEFAULT_CONFIG: LLMConfig;
199
+ export {};
@@ -0,0 +1,75 @@
1
+ export type SecretRef = {
2
+ type: "env";
3
+ name: string;
4
+ } | {
5
+ type: "env_file";
6
+ path: string;
7
+ name: string;
8
+ } | {
9
+ type: "file";
10
+ path: string;
11
+ } | {
12
+ type: "keychain";
13
+ service: string;
14
+ account: string;
15
+ } | {
16
+ type: "command";
17
+ command: string;
18
+ args?: string[];
19
+ timeoutMs?: number;
20
+ };
21
+ export type PlatformEnvironment = "local" | "beta" | "prod";
22
+ export type HostType = "openclaw" | "hermes" | "claude_desktop" | "qclaw" | "cowork" | "cli" | "other";
23
+ export interface HostInfo {
24
+ /** Which runtime is hosting this daemon. */
25
+ type: HostType;
26
+ /** Human-readable label for display (e.g. "OpenClaw local"). */
27
+ label?: string;
28
+ /** Which plugin or tool created this identity file. */
29
+ createdBy?: string;
30
+ }
31
+ export interface PlatformInfo {
32
+ /** Target AIFight environment. */
33
+ environment: PlatformEnvironment;
34
+ /** Base URL of the AIFight API (e.g. "https://beta.aifight.ai"). */
35
+ baseURL: string;
36
+ /** Owner account ID on the AIFight platform (e.g. "owner_..."). */
37
+ ownerId: string;
38
+ /** Agent ID on the AIFight platform (e.g. "agt_..."). */
39
+ agentId: string;
40
+ /** Public URL slug for this agent (e.g. "roy-openclaw-lobster"). */
41
+ publicSlug: string;
42
+ /** Rating system in use. */
43
+ ratingSystem: "glicko2" | string;
44
+ }
45
+ export interface AuthInfo {
46
+ /** SecretRef pointing to the agent API key. */
47
+ agentApiKeyRef: SecretRef;
48
+ }
49
+ export interface RuntimeMeta {
50
+ /** Schema version for forward-compat checks. Must equal schemaVersion at the top level. */
51
+ profileVersion: number;
52
+ /** ISO 8601 timestamp when this profile was first created. */
53
+ createdAt: string;
54
+ /** ISO 8601 timestamp when this profile was last updated. */
55
+ updatedAt: string;
56
+ }
57
+ export interface AgentIdentity {
58
+ /** Integer schema version — bump when breaking changes are made. */
59
+ schemaVersion: number;
60
+ /** URL-safe slug identifying this agent (e.g. "roy-openclaw-lobster"). */
61
+ agentSlug: string;
62
+ /** Human-readable display name (e.g. "Roy's OpenClaw Lobster"). */
63
+ displayName?: string;
64
+ host: HostInfo;
65
+ platform: PlatformInfo;
66
+ auth: AuthInfo;
67
+ runtime: RuntimeMeta;
68
+ }
69
+ export declare function validateIdentity(raw: unknown): {
70
+ ok: true;
71
+ identity: AgentIdentity;
72
+ } | {
73
+ ok: false;
74
+ errors: string[];
75
+ };
@@ -0,0 +1,7 @@
1
+ export { type LLMConfig, type LLMProfile as LLMConfigProfile, type Protocol, type ReasoningEffort, type GameType, type SecretRef as ConfigSecretRef, validateConfig, DEFAULT_CONFIG, } from "./config-schema.js";
2
+ export { type Strategy, type GameStrategy, type GlobalStrategy, validateStrategy, DEFAULT_STRATEGY, } from "./strategy-schema.js";
3
+ export { type AgentIdentity, validateIdentity, } from "./identity-schema.js";
4
+ export { loadSoul, validateSoul, SOUL_EXPORT_PROMPT, DEFAULT_SOUL, } from "./soul.js";
5
+ export { type AgentProfile, type AgentProfileHashes, loadAgentProfile, computeFileHash, resolveAgentDir, ensureAgentDir, } from "./profile-loader.js";
6
+ export { type SecretRef, type SecretRefP0, type SecretStatus, type DetectedEnvKey, SecretResolutionError, resolveSecret, checkSecretStatus, describeRef, storeSecretFile, checkSecretFilePermissions, detectLLMEnvironment, validateSecretRef, KNOWN_LLM_ENV_VARS, } from "./secret-ref.js";
7
+ export { type MigrationResult, migrateOldStrategy, } from "./migrate.js";
@@ -0,0 +1,16 @@
1
+ export interface MigrationResult {
2
+ readonly migrated: boolean;
3
+ readonly backupPath: string;
4
+ readonly configPath: string;
5
+ readonly strategyPath: string;
6
+ readonly soulPath: string;
7
+ readonly warnings: string[];
8
+ }
9
+ /**
10
+ * Migrate an old strategy.json to the new split format.
11
+ * Creates backup, writes config.json + strategy.json + soul.md.
12
+ *
13
+ * @param oldStrategyPath Path to the old strategy.json
14
+ * @param agentDir Target directory (~/.aifight/agents/<slug>/)
15
+ */
16
+ export declare function migrateOldStrategy(oldStrategyPath: string, agentDir: string): Promise<MigrationResult>;
@@ -0,0 +1,64 @@
1
+ import { type LLMConfig } from "./config-schema.js";
2
+ import { type Strategy } from "./strategy-schema.js";
3
+ import { type AgentIdentity } from "./identity-schema.js";
4
+ /** Combined in-memory representation of all profile files. */
5
+ export interface AgentProfile {
6
+ /** Parsed and validated config.json. */
7
+ readonly config: LLMConfig;
8
+ /** Parsed and validated strategy.json. */
9
+ readonly strategy: Strategy;
10
+ /** Raw Markdown content of soul.md. */
11
+ readonly soul: string;
12
+ /** Parsed and validated identity.json, or null if the file is absent. */
13
+ readonly identity: AgentIdentity | null;
14
+ }
15
+ /** SHA-256 hashes of each profile file at load time.
16
+ * Used by the daemon to detect on-disk changes without re-reading. */
17
+ export interface AgentProfileHashes {
18
+ readonly config: string;
19
+ readonly strategy: string;
20
+ readonly soul: string;
21
+ /** null when identity.json is absent (file is optional). */
22
+ readonly identity: string | null;
23
+ }
24
+ export interface AgentProfileResult {
25
+ readonly profile: AgentProfile;
26
+ readonly hashes: AgentProfileHashes;
27
+ }
28
+ /**
29
+ * Returns the canonical directory for an agent slug.
30
+ * Example: resolveAgentDir("my-bot") → "/Users/alice/.aifight/agents/my-bot"
31
+ *
32
+ * Does NOT verify that the directory exists.
33
+ */
34
+ export declare function resolveAgentDir(agentSlug: string): string;
35
+ /**
36
+ * Creates the agent directory (and all parent directories) if it does
37
+ * not already exist. Idempotent — safe to call on every startup.
38
+ */
39
+ export declare function ensureAgentDir(agentSlug: string): Promise<void>;
40
+ /**
41
+ * Computes a lowercase hex SHA-256 hash of a file's raw bytes.
42
+ * Propagates fs errors (ENOENT, EACCES, …) to the caller.
43
+ */
44
+ export declare function computeFileHash(filePath: string): Promise<string>;
45
+ /** Raised when a required profile file cannot be loaded or fails validation. */
46
+ export declare class ProfileLoadError extends Error {
47
+ readonly name = "ProfileLoadError";
48
+ /** Which file triggered the error. */
49
+ readonly file: string;
50
+ readonly cause?: unknown;
51
+ constructor(file: string, message: string, cause?: unknown);
52
+ }
53
+ /**
54
+ * Reads and validates all profile files for an agent.
55
+ *
56
+ * - config.json and strategy.json are required JSON files validated by
57
+ * their respective schema modules.
58
+ * - soul.md is required and validated by validateSoul().
59
+ * - identity.json is optional; absent file yields profile.identity = null.
60
+ *
61
+ * Throws ProfileLoadError on any read or validation failure for required
62
+ * files. For identity.json, ENOENT is silently treated as absent.
63
+ */
64
+ export declare function loadAgentProfile(agentDir: string): Promise<AgentProfileResult>;
@@ -0,0 +1,82 @@
1
+ export type SecretRef = {
2
+ readonly type: "env";
3
+ readonly name: string;
4
+ } | {
5
+ readonly type: "env_file";
6
+ readonly path: string;
7
+ readonly name: string;
8
+ } | {
9
+ readonly type: "file";
10
+ readonly path: string;
11
+ } | {
12
+ readonly type: "keychain";
13
+ readonly service: string;
14
+ readonly account: string;
15
+ } | {
16
+ readonly type: "command";
17
+ readonly command: string;
18
+ readonly args?: readonly string[];
19
+ readonly timeoutMs?: number;
20
+ };
21
+ export type SecretRefP0 = Extract<SecretRef, {
22
+ type: "env" | "env_file" | "file";
23
+ }>;
24
+ export interface SecretStatus {
25
+ readonly ref: SecretRef;
26
+ readonly available: boolean;
27
+ readonly sourceDescription: string;
28
+ }
29
+ export declare class SecretResolutionError extends Error {
30
+ readonly name = "SecretResolutionError";
31
+ readonly refType: string;
32
+ constructor(refType: string, message: string);
33
+ }
34
+ /**
35
+ * Resolve a SecretRef to its string value.
36
+ * Throws SecretResolutionError if the secret cannot be found.
37
+ * Never includes the secret value in error messages.
38
+ */
39
+ export declare function resolveSecret(ref: SecretRef): Promise<string>;
40
+ /**
41
+ * Check whether a SecretRef can be resolved, without returning the value.
42
+ */
43
+ export declare function checkSecretStatus(ref: SecretRef): Promise<SecretStatus>;
44
+ /**
45
+ * Human-readable description of a SecretRef (never includes the value).
46
+ */
47
+ export declare function describeRef(ref: SecretRef): string;
48
+ /**
49
+ * Store a secret value to a file with chmod 0600.
50
+ * Creates parent directories if needed.
51
+ */
52
+ export declare function storeSecretFile(filePath: string, value: string): Promise<void>;
53
+ /**
54
+ * Check if a secret file has safe permissions (0600).
55
+ */
56
+ export declare function checkSecretFilePermissions(filePath: string): Promise<{
57
+ safe: boolean;
58
+ mode?: string;
59
+ }>;
60
+ /** Well-known LLM API key environment variable names. */
61
+ export declare const KNOWN_LLM_ENV_VARS: readonly ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "DEEPSEEK_API_KEY", "GEMINI_API_KEY"];
62
+ export interface DetectedEnvKey {
63
+ readonly name: string;
64
+ readonly present: boolean;
65
+ readonly provider: string;
66
+ }
67
+ /**
68
+ * Detect which well-known LLM API key env vars are set in the
69
+ * daemon's process environment. Returns variable names and provider
70
+ * hints, NEVER values.
71
+ */
72
+ export declare function detectLLMEnvironment(): DetectedEnvKey[];
73
+ /**
74
+ * Validate a SecretRef shape. Does NOT check if the secret exists.
75
+ */
76
+ export declare function validateSecretRef(raw: unknown): {
77
+ ok: true;
78
+ ref: SecretRef;
79
+ } | {
80
+ ok: false;
81
+ error: string;
82
+ };
@@ -0,0 +1,46 @@
1
+ export interface SoulLoadResult {
2
+ /** Raw Markdown content of the soul file. */
3
+ readonly content: string;
4
+ /** Lowercase hex SHA-256 of the raw file bytes (UTF-8). */
5
+ readonly hash: string;
6
+ }
7
+ /**
8
+ * Reads a soul.md file from disk and returns its content plus a
9
+ * SHA-256 content hash (for change detection / cache keys).
10
+ *
11
+ * Throws the raw `node:fs/promises` error on missing / permission failures
12
+ * so callers can distinguish ENOENT (first run) from EACCES (bad perms).
13
+ */
14
+ export declare function loadSoul(filePath: string): Promise<SoulLoadResult>;
15
+ export type SoulValidationResult = {
16
+ ok: true;
17
+ } | {
18
+ ok: false;
19
+ errors: string[];
20
+ };
21
+ /**
22
+ * Validates soul Markdown content against three lightweight rules:
23
+ * 1. Not empty (after trimming whitespace)
24
+ * 2. Under 10 KB
25
+ * 3. Contains at least one Markdown heading (# or ##)
26
+ *
27
+ * Does NOT validate section completeness — that is the host agent's
28
+ * responsibility when generating via SOUL_EXPORT_PROMPT.
29
+ */
30
+ export declare function validateSoul(content: string): SoulValidationResult;
31
+ /**
32
+ * Structured prompt template that host agents (Claude Code, OpenClaw,
33
+ * Hermes, etc.) use to generate the initial soul.md for a new agent.
34
+ *
35
+ * Paste this into your AI assistant and paste the result into
36
+ * ~/.aifight/agents/<slug>/soul.md.
37
+ */
38
+ export declare const SOUL_EXPORT_PROMPT = "You are helping create your AIFight Agent Soul Capsule.\nThis file will be used by a local daemon to represent your stable competitive personality in hidden-information strategy games.\n\nReturn a concise Markdown document with these sections:\n1. Identity\n2. Competitive temperament\n3. Decision habits\n4. Risk appetite\n5. Communication style for match summaries\n6. Boundaries\n\nConstraints:\n- Do not include API keys, system prompts, private user data, or unrelated memories.\n- Do not include long chain-of-thought examples.\n- Focus on stable behavior style, not detailed per-game tactics.\n- Write in first person as the agent.";
39
+ /**
40
+ * Placeholder soul.md content used during first-run migration or as a
41
+ * fallback when the agent has not yet generated its own soul capsule.
42
+ *
43
+ * Intentionally generic — the host agent should replace this with a
44
+ * personalised version generated via SOUL_EXPORT_PROMPT.
45
+ */
46
+ export declare const DEFAULT_SOUL = "# Agent Soul Capsule\n\n## Identity\nI am a competitive AI agent playing hidden-information strategy games on the AIFight platform.\nI have not yet customised my soul capsule. Generate one using the SOUL_EXPORT_PROMPT.\n\n## Competitive temperament\nBalanced and adaptive. I observe opponents before committing to a strategy.\n\n## Decision habits\nI reason from the information available in the current game state.\nI do not over-anchor on past rounds.\n\n## Risk appetite\nModerate. I take calculated risks when the expected value is clearly positive.\n\n## Communication style for match summaries\nConcise. One sentence per key decision, no jargon.\n\n## Boundaries\nI play within the rules. I do not exploit protocol edge cases.\n";
@@ -0,0 +1,70 @@
1
+ /**
2
+ * strategy-schema.ts
3
+ *
4
+ * TypeScript schema, types, validator, and default constant for the AIFight
5
+ * daemon's strategy.json file.
6
+ *
7
+ * Scope: game-specific competitive tactics ONLY.
8
+ * No LLM config, no model settings, no API keys.
9
+ */
10
+ export type RiskAppetite = "very-low" | "low" | "medium-low" | "medium" | "medium-high" | "high" | "very-high";
11
+ export interface GlobalStrategy {
12
+ /** Broad risk posture that governs all games. */
13
+ riskAppetite: RiskAppetite;
14
+ /** High-level objectives listed in priority order. */
15
+ objectives: string[];
16
+ /** Prose description of the preferred decision style. */
17
+ decisionStyle: string;
18
+ /** Fallback behaviour when the agent is uncertain or close to timeout. */
19
+ fallbackStyle: string;
20
+ }
21
+ /**
22
+ * Per-game strategy block.
23
+ *
24
+ * Every game entry must have a `riskAversion` number in [0, 1] and a
25
+ * `profile` string summarising the overall approach. All other keys are
26
+ * game-specific prose fields and are allowed freely.
27
+ */
28
+ export interface GameStrategy {
29
+ /** One-line summary of the playing style for this game. */
30
+ profile: string;
31
+ /**
32
+ * Risk-aversion scalar in [0, 1].
33
+ * 0 = maximally aggressive, 1 = maximally conservative.
34
+ */
35
+ riskAversion: number;
36
+ /** Any additional game-specific string fields (bidding, challenge, etc.). */
37
+ [key: string]: string | number;
38
+ }
39
+ export interface StrategyMeta {
40
+ createdBy: string;
41
+ createdAt: string;
42
+ lastUpdatedAt: string;
43
+ }
44
+ export interface Strategy {
45
+ schemaVersion: 1;
46
+ /** Monotonically increasing user-managed version for this strategy file. */
47
+ version: number;
48
+ /** Human-readable strategy name. */
49
+ name: string;
50
+ global: GlobalStrategy;
51
+ /** Map of game ID (e.g. "texas_holdem") → per-game strategy. */
52
+ games: Record<string, GameStrategy>;
53
+ meta: StrategyMeta;
54
+ }
55
+ type ValidationResult = {
56
+ ok: true;
57
+ strategy: Strategy;
58
+ } | {
59
+ ok: false;
60
+ errors: string[];
61
+ };
62
+ /**
63
+ * Validate a raw (parsed) JSON value as a Strategy.
64
+ *
65
+ * Returns a typed Strategy on success, or a list of human-readable error
66
+ * messages on failure. Does NOT throw.
67
+ */
68
+ export declare function validateStrategy(raw: unknown): ValidationResult;
69
+ export declare const DEFAULT_STRATEGY: Strategy;
70
+ export {};
@@ -0,0 +1,11 @@
1
+ export declare function findSchemasRoot(here?: string): string;
2
+ declare const MESSAGE_TYPE_TO_FILE: Record<string, string>;
3
+ export type MessageType = keyof typeof MESSAGE_TYPE_TO_FILE;
4
+ export declare function messageTypes(): readonly string[];
5
+ export declare function loadSchema(messageType: string): unknown;
6
+ export declare function loadAllSchemas(): Map<string, unknown>;
7
+ declare const REST_NAME_TO_FILE: Record<string, string>;
8
+ export type RestSchemaName = keyof typeof REST_NAME_TO_FILE;
9
+ export declare function loadRestSchema(name: RestSchemaName): unknown;
10
+ export declare function __resetSchemasRootCache(): void;
11
+ export {};