@aifight/aifight 0.1.0-alpha.7 → 0.1.0-alpha.8
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.
- package/README.md +51 -0
- package/dist/bin.mjs +171 -137
- package/dist/index.mjs +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/types/agents/agent.d.ts +0 -82
- package/dist/types/agents/state-machine.d.ts +0 -96
- package/dist/types/bridge/auto-update.d.ts +0 -53
- package/dist/types/bridge/config.d.ts +0 -35
- package/dist/types/bridge/hermes-provider.d.ts +0 -9
- package/dist/types/bridge/openclaw-provider.d.ts +0 -9
- package/dist/types/bridge/pairing.d.ts +0 -18
- package/dist/types/bridge/provider.d.ts +0 -18
- package/dist/types/bridge/runner.d.ts +0 -30
- package/dist/types/bridge/service.d.ts +0 -55
- package/dist/types/bridge/update-check.d.ts +0 -23
- package/dist/types/cli/agent-resolver.d.ts +0 -25
- package/dist/types/cli/argv.d.ts +0 -13
- package/dist/types/cli/commands/agent-list.d.ts +0 -2
- package/dist/types/cli/commands/agent-status.d.ts +0 -2
- package/dist/types/cli/commands/bridge-accept.d.ts +0 -2
- package/dist/types/cli/commands/bridge-challenge.d.ts +0 -2
- package/dist/types/cli/commands/bridge-connect.d.ts +0 -2
- package/dist/types/cli/commands/bridge-register.d.ts +0 -7
- package/dist/types/cli/commands/bridge-run.d.ts +0 -7
- package/dist/types/cli/commands/bridge-service.d.ts +0 -5
- package/dist/types/cli/commands/bridge-set.d.ts +0 -2
- package/dist/types/cli/commands/bridge-start.d.ts +0 -2
- package/dist/types/cli/commands/bridge-status.d.ts +0 -2
- package/dist/types/cli/commands/bridge-uninstall.d.ts +0 -4
- package/dist/types/cli/commands/bridge-update.d.ts +0 -2
- package/dist/types/cli/commands/config-init.d.ts +0 -2
- package/dist/types/cli/commands/config-probe.d.ts +0 -2
- package/dist/types/cli/commands/config-validate.d.ts +0 -2
- package/dist/types/cli/commands/daily-off.d.ts +0 -2
- package/dist/types/cli/commands/daily-on.d.ts +0 -2
- package/dist/types/cli/commands/daily-set.d.ts +0 -2
- package/dist/types/cli/commands/daily-show.d.ts +0 -2
- package/dist/types/cli/commands/doctor.d.ts +0 -2
- package/dist/types/cli/commands/init.d.ts +0 -2
- package/dist/types/cli/commands/join.d.ts +0 -2
- package/dist/types/cli/commands/leave.d.ts +0 -2
- package/dist/types/cli/commands/mcp.d.ts +0 -2
- package/dist/types/cli/commands/runtime-management.d.ts +0 -18
- package/dist/types/cli/commands/runtime-setup-state.d.ts +0 -21
- package/dist/types/cli/commands/runtime-setup.d.ts +0 -25
- package/dist/types/cli/commands/serve.d.ts +0 -2
- package/dist/types/cli/commands/service/launchd.d.ts +0 -71
- package/dist/types/cli/commands/service/platform.d.ts +0 -69
- package/dist/types/cli/commands/service/systemd.d.ts +0 -55
- package/dist/types/cli/commands/service/types.d.ts +0 -64
- package/dist/types/cli/commands/service-install.d.ts +0 -29
- package/dist/types/cli/commands/setup.d.ts +0 -2
- package/dist/types/cli/commands/shutdown.d.ts +0 -2
- package/dist/types/cli/commands/stubs.d.ts +0 -24
- package/dist/types/cli/commands/version.d.ts +0 -2
- package/dist/types/cli/control-client.d.ts +0 -59
- package/dist/types/cli/format.d.ts +0 -52
- package/dist/types/cli/main.d.ts +0 -18
- package/dist/types/cli/runtime-files.d.ts +0 -11
- package/dist/types/cli/shared.d.ts +0 -74
- package/dist/types/controlapi/profile-routes.d.ts +0 -49
- package/dist/types/controlapi/server.d.ts +0 -3
- package/dist/types/controlapi/types.d.ts +0 -136
- package/dist/types/daemon/agent-decision-adapter.d.ts +0 -40
- package/dist/types/daemon/lifecycle.d.ts +0 -85
- package/dist/types/daemon/router.d.ts +0 -97
- package/dist/types/daemon/runtime-files-write.d.ts +0 -76
- package/dist/types/identity/identity-manager.d.ts +0 -59
- package/dist/types/llm/adapter-registry.d.ts +0 -27
- package/dist/types/llm/adapters/anthropic-messages.d.ts +0 -2
- package/dist/types/llm/adapters/deepseek-chat-completions.d.ts +0 -2
- package/dist/types/llm/adapters/openai-chat-compat.d.ts +0 -2
- package/dist/types/llm/adapters/openai-chat-completions.d.ts +0 -2
- package/dist/types/llm/adapters/openai-responses.d.ts +0 -2
- package/dist/types/llm/adapters/types.d.ts +0 -128
- package/dist/types/llm/capabilities/validate-capabilities.d.ts +0 -68
- package/dist/types/mcp/control-client.d.ts +0 -54
- package/dist/types/mcp/profile-tools.d.ts +0 -10
- package/dist/types/mcp/server.d.ts +0 -10
- package/dist/types/mcp/tools.d.ts +0 -31
- package/dist/types/mcp/types.d.ts +0 -27
- package/dist/types/profile/config-schema.d.ts +0 -199
- package/dist/types/profile/identity-schema.d.ts +0 -75
- package/dist/types/profile/index.d.ts +0 -7
- package/dist/types/profile/migrate.d.ts +0 -16
- package/dist/types/profile/profile-loader.d.ts +0 -64
- package/dist/types/profile/secret-ref.d.ts +0 -82
- package/dist/types/profile/soul.d.ts +0 -46
- package/dist/types/profile/strategy-schema.d.ts +0 -70
- package/dist/types/reflection/proposal-store.d.ts +0 -50
- package/dist/types/reflection/reflection-engine.d.ts +0 -81
- package/dist/types/scheduler/daily.d.ts +0 -47
- package/dist/types/scheduler/types.d.ts +0 -42
- package/dist/types/session/match-session-manager.d.ts +0 -113
- package/dist/types/session/session-context-builder.d.ts +0 -68
|
@@ -1,64 +0,0 @@
|
|
|
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>;
|
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
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";
|
|
@@ -1,70 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { ReflectionProposal } from "./reflection-engine.js";
|
|
2
|
-
export declare class ProposalStoreError extends Error {
|
|
3
|
-
readonly name = "ProposalStoreError";
|
|
4
|
-
readonly kind: "not_found" | "already_applied" | "patch_failed" | "validation_failed" | "io_error";
|
|
5
|
-
readonly cause?: unknown;
|
|
6
|
-
constructor(kind: ProposalStoreError["kind"], message: string, cause?: unknown);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Serialises a proposal to
|
|
10
|
-
* `~/.aifight/agents/<slug>/proposals/<timestamp>-<matchId>.proposal.json`.
|
|
11
|
-
*
|
|
12
|
-
* Creates the proposals directory if it does not exist.
|
|
13
|
-
* Returns the absolute path of the written file.
|
|
14
|
-
*/
|
|
15
|
-
export declare function saveProposal(agentSlug: string, proposal: ReflectionProposal): Promise<string>;
|
|
16
|
-
export interface ListProposalsFilter {
|
|
17
|
-
status?: ReflectionProposal["status"];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Returns all proposals for an agent, optionally filtered by status.
|
|
21
|
-
* Results are sorted by createdAt ascending (oldest first).
|
|
22
|
-
* Returns [] when the proposals directory does not exist.
|
|
23
|
-
*/
|
|
24
|
-
export declare function listProposals(agentSlug: string, filter?: ListProposalsFilter): Promise<ReflectionProposal[]>;
|
|
25
|
-
/**
|
|
26
|
-
* Reads a specific proposal by proposalId.
|
|
27
|
-
* Scans the proposals directory (linear scan; proposal counts are small).
|
|
28
|
-
* Throws ProposalStoreError("not_found") when no match is found.
|
|
29
|
-
*/
|
|
30
|
-
export declare function getProposal(agentSlug: string, proposalId: string): Promise<ReflectionProposal>;
|
|
31
|
-
/**
|
|
32
|
-
* Applies a pending proposal to the agent's profile files.
|
|
33
|
-
*
|
|
34
|
-
* For each target:
|
|
35
|
-
* - Reads the current file.
|
|
36
|
-
* - Applies the patch (json_patch or text_replace).
|
|
37
|
-
* - Validates the result (validateStrategy / validateSoul).
|
|
38
|
-
* - Backs up the old file to versions/<name>.v<N>.<ext>.
|
|
39
|
-
* - Atomically writes the new file.
|
|
40
|
-
*
|
|
41
|
-
* Updates the proposal status to "applied" and sets appliedAt.
|
|
42
|
-
* Throws ProposalStoreError on any failure (no partial writes on error).
|
|
43
|
-
*/
|
|
44
|
-
export declare function applyProposal(agentSlug: string, proposalId: string): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Marks a proposal as rejected without modifying any profile files.
|
|
47
|
-
* reason is ignored (proposals are immutable JSON; rejection just sets status).
|
|
48
|
-
*/
|
|
49
|
-
export declare function rejectProposal(agentSlug: string, proposalId: string, _reason?: string): Promise<void>;
|
|
50
|
-
export type { ReflectionProposal, ProposalTarget } from "./reflection-engine.js";
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/** One turn's decision, as stored in decisions.jsonl by the daemon. */
|
|
2
|
-
export interface DecisionRecord {
|
|
3
|
-
/** Zero-based turn index within the match. */
|
|
4
|
-
turnIndex: number;
|
|
5
|
-
/** The action string that was ultimately submitted. */
|
|
6
|
-
selectedAction: string;
|
|
7
|
-
/** Whether the action was accepted by the server as legal. */
|
|
8
|
-
actionValid: boolean;
|
|
9
|
-
/** True when the LLM failed and the runtime fell back to heuristics. */
|
|
10
|
-
fallbackUsed: boolean;
|
|
11
|
-
/** Short prose summary of the LLM's stated reasoning, if captured. */
|
|
12
|
-
reasonSummary?: string;
|
|
13
|
-
/** Wall-clock ms from action_request receipt to action submission. */
|
|
14
|
-
latencyMs: number;
|
|
15
|
-
}
|
|
16
|
-
export interface MatchReflectionInput {
|
|
17
|
-
agentSlug: string;
|
|
18
|
-
matchId: string;
|
|
19
|
-
game: string;
|
|
20
|
-
result: "win" | "loss" | "draw";
|
|
21
|
-
ratingDelta: number;
|
|
22
|
-
newRating: number;
|
|
23
|
-
opponentName: string;
|
|
24
|
-
opponentModel?: string;
|
|
25
|
-
replayUrl: string;
|
|
26
|
-
/** All decisions recorded during the match (from decisions.jsonl). */
|
|
27
|
-
decisions: DecisionRecord[];
|
|
28
|
-
/** Raw event log from events.jsonl (opaque; used for pattern detection). */
|
|
29
|
-
events: unknown[];
|
|
30
|
-
totalCostUSD?: number;
|
|
31
|
-
totalLatencyMs?: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Generates a concise Markdown match recap suitable for writing to summary.md.
|
|
35
|
-
*
|
|
36
|
-
* Language: Chinese primary, English technical terms.
|
|
37
|
-
* Target length: ~20-35 lines regardless of match length.
|
|
38
|
-
*/
|
|
39
|
-
export declare function generateMatchSummary(input: MatchReflectionInput): string;
|
|
40
|
-
export interface ProposalTarget {
|
|
41
|
-
/** Which file this patch applies to. */
|
|
42
|
-
file: "strategy.json" | "soul.md";
|
|
43
|
-
/**
|
|
44
|
-
* "json_patch" → patch is a JSON Patch array (RFC 6902).
|
|
45
|
-
* "text_replace" → patch is { old: string; new: string }.
|
|
46
|
-
*/
|
|
47
|
-
type: "json_patch" | "text_replace";
|
|
48
|
-
patch: unknown;
|
|
49
|
-
}
|
|
50
|
-
export interface ReflectionProposal {
|
|
51
|
-
schemaVersion: 1;
|
|
52
|
-
/** UUID v4 generated at creation time. */
|
|
53
|
-
proposalId: string;
|
|
54
|
-
/** The daemon's session ID when the match was played. */
|
|
55
|
-
localSessionId: string;
|
|
56
|
-
agentSlug: string;
|
|
57
|
-
matchId: string;
|
|
58
|
-
targets: ProposalTarget[];
|
|
59
|
-
/** Human-readable explanation of why this proposal was generated. */
|
|
60
|
-
rationale: string;
|
|
61
|
-
/** Description of what could go wrong if applied. */
|
|
62
|
-
risk: string;
|
|
63
|
-
status: "pending" | "applied" | "rejected";
|
|
64
|
-
createdAt: string;
|
|
65
|
-
appliedAt?: string;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Analyses a completed match and produces a strategy improvement proposal,
|
|
69
|
-
* or returns null when no confident improvement can be identified.
|
|
70
|
-
*
|
|
71
|
-
* Heuristics (in priority order):
|
|
72
|
-
* 1. High fallback rate (>20%) → propose lowering riskAversion for the game
|
|
73
|
-
* to avoid timeout-prone positions.
|
|
74
|
-
* 2. Loss with zero fallbacks → inspect riskAversion; if too aggressive
|
|
75
|
-
* propose nudging it up slightly.
|
|
76
|
-
* 3. Win with high invalid-action rate → propose adding strategy notes.
|
|
77
|
-
* 4. Very slow average latency → propose a soul.md note on timeout awareness.
|
|
78
|
-
*
|
|
79
|
-
* Returns null when no heuristic fires with sufficient confidence.
|
|
80
|
-
*/
|
|
81
|
-
export declare function generateReflectionProposal(input: MatchReflectionInput, localSessionId?: string): ReflectionProposal | null;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { AgentInstanceSnapshot } from "../agents/agent";
|
|
2
|
-
import type { DailyScheduleConfig, DailySchedulerNotifyEvent, DailySchedulerSnapshot } from "./types";
|
|
3
|
-
export interface SchedulerAgentTarget {
|
|
4
|
-
readonly name: string;
|
|
5
|
-
joinQueue(game: string, mode?: string): void;
|
|
6
|
-
snapshot(): AgentInstanceSnapshot;
|
|
7
|
-
onState(handler: (snapshot: AgentInstanceSnapshot) => void): () => void;
|
|
8
|
-
}
|
|
9
|
-
export type SchedulerTimerHandle = unknown;
|
|
10
|
-
export interface SchedulerClock {
|
|
11
|
-
readonly now: () => number;
|
|
12
|
-
readonly setTimeout: (cb: () => void, ms: number) => SchedulerTimerHandle;
|
|
13
|
-
readonly clearTimeout: (h: SchedulerTimerHandle) => void;
|
|
14
|
-
}
|
|
15
|
-
export interface DailySchedulerOptions {
|
|
16
|
-
readonly agent: SchedulerAgentTarget;
|
|
17
|
-
/** Initial schedule snapshot taken once at construction; copied into
|
|
18
|
-
* the scheduler's internal `currentSchedule` field. After construction
|
|
19
|
-
* the only way to change schedule is `scheduler.setSchedule(cfg)`.
|
|
20
|
-
* rev2 fix #3 single authority. */
|
|
21
|
-
readonly initialSchedule?: DailyScheduleConfig | null;
|
|
22
|
-
/** Optional health gate. Resolves true → join allowed; false / throw →
|
|
23
|
-
* skip + notify. Scheduler does NOT hold a DecisionProvider instance
|
|
24
|
-
* (rev1 decision #7). */
|
|
25
|
-
readonly healthCheck?: () => Promise<boolean>;
|
|
26
|
-
/** Default = real wall clock + globalThis.{setTimeout, clearTimeout}. */
|
|
27
|
-
readonly clock?: SchedulerClock;
|
|
28
|
-
readonly onNotify?: (event: DailySchedulerNotifyEvent) => void;
|
|
29
|
-
}
|
|
30
|
-
export interface DailyScheduler {
|
|
31
|
-
start(): void;
|
|
32
|
-
stop(): void;
|
|
33
|
-
snapshot(): DailySchedulerSnapshot;
|
|
34
|
-
/** rev2 fix #3 — single authority: replace internal `currentSchedule`.
|
|
35
|
-
* `cfg` is sync-validated; invalid throws DailySchedulerError. `null`
|
|
36
|
-
* means "no schedule" (scheduler keeps running; every fire goes to
|
|
37
|
-
* skip_disabled). NOT equivalent to stop(). */
|
|
38
|
-
setSchedule(cfg: DailyScheduleConfig | null): void;
|
|
39
|
-
}
|
|
40
|
-
export type DailySchedulerErrorKind = "invalid_timezone" | "invalid_count" | "invalid_min_interval" | "invalid_state";
|
|
41
|
-
export declare class DailySchedulerError extends Error {
|
|
42
|
-
readonly name = "DailySchedulerError";
|
|
43
|
-
readonly kind: DailySchedulerErrorKind;
|
|
44
|
-
readonly cause: unknown;
|
|
45
|
-
constructor(kind: DailySchedulerErrorKind, message: string, cause?: unknown);
|
|
46
|
-
}
|
|
47
|
-
export declare function createDailyScheduler(opts: DailySchedulerOptions): DailyScheduler;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { GameType } from "../decision/types";
|
|
2
|
-
export interface DailyGameQuota {
|
|
3
|
-
/** Non-negative integer. 0 = this game is configured but not scheduled. */
|
|
4
|
-
readonly count: number;
|
|
5
|
-
}
|
|
6
|
-
export interface DailyScheduleConfig {
|
|
7
|
-
/** Master toggle. false → scheduler stays idle; existing config retained. */
|
|
8
|
-
readonly enabled: boolean;
|
|
9
|
-
/** IANA timezone name, e.g. "Asia/Shanghai" / "UTC". Day boundary is computed in this timezone. */
|
|
10
|
-
readonly timezone: string;
|
|
11
|
-
/** Per-game daily count. Empty object ⇔ disabled (no work). */
|
|
12
|
-
readonly days: Partial<Record<GameType, DailyGameQuota>>;
|
|
13
|
-
/** Minimum delay between any two `joinQueue` calls. Default 60. */
|
|
14
|
-
readonly minIntervalSec?: number;
|
|
15
|
-
}
|
|
16
|
-
export interface DailySchedulerSnapshot {
|
|
17
|
-
/** Whether start() has been called and stop() has not. */
|
|
18
|
-
readonly running: boolean;
|
|
19
|
-
/** Local YYYY-MM-DD in opts.config.timezone (or null when scheduler stopped). */
|
|
20
|
-
readonly today: string | null;
|
|
21
|
-
/** Remaining quota per game today (config.days minus today's fired count). */
|
|
22
|
-
readonly remaining: Partial<Record<GameType, number>>;
|
|
23
|
-
/** Most recent fire attempt outcome (or null pre-first-fire). */
|
|
24
|
-
readonly lastAttempt: DailySchedulerLastAttempt | null;
|
|
25
|
-
/** Estimated millis until next fire (relative to clock.now()), or null when no fire scheduled. */
|
|
26
|
-
readonly nextFireInMs: number | null;
|
|
27
|
-
}
|
|
28
|
-
export interface DailySchedulerLastAttempt {
|
|
29
|
-
readonly atMs: number;
|
|
30
|
-
readonly game: GameType;
|
|
31
|
-
readonly outcome: "join_succeeded" | "join_threw" | `skip_${string}`;
|
|
32
|
-
readonly cause?: unknown;
|
|
33
|
-
}
|
|
34
|
-
export interface DailySchedulerNotifyEvent {
|
|
35
|
-
readonly level: "info" | "warning" | "error";
|
|
36
|
-
readonly code: DailySchedulerNotifyCode;
|
|
37
|
-
readonly message: string;
|
|
38
|
-
readonly agent?: string;
|
|
39
|
-
readonly game?: GameType;
|
|
40
|
-
readonly cause?: unknown;
|
|
41
|
-
}
|
|
42
|
-
export type DailySchedulerNotifyCode = "started" | "stopped" | "schedule_changed" | "day_rolled_over" | "join_attempted" | "join_succeeded" | "join_threw" | "skip_disabled" | "skip_no_quota" | "skip_agent_not_started" | "skip_agent_stopped" | "skip_state_unavailable" | "skip_transport_disconnected" | "skip_state_busy" | "skip_min_interval" | "skip_health_check" | "health_check_threw" | "snapshot_threw" | "internal_error";
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { UsageRecord } from "../llm/adapters/types.js";
|
|
2
|
-
export type SessionStatus = "created" | "active" | "waiting_action" | "completed" | "abandoned";
|
|
3
|
-
export interface MatchSession {
|
|
4
|
-
/** Locally generated UUID — stable across reconnects */
|
|
5
|
-
localSessionId: string;
|
|
6
|
-
/** Platform match ID from match_found / game_start */
|
|
7
|
-
platformMatchId: string;
|
|
8
|
-
/** Platform per-player session ID (present after game_start) */
|
|
9
|
-
platformSessionId?: string;
|
|
10
|
-
/** Agent slug (matches directory name) */
|
|
11
|
-
agentSlug: string;
|
|
12
|
-
/** Game identifier, e.g. "texas_holdem" */
|
|
13
|
-
gameId: string;
|
|
14
|
-
/** Environment tag: "production" | "beta" | "local" */
|
|
15
|
-
environment: string;
|
|
16
|
-
/** Lifecycle status */
|
|
17
|
-
status: SessionStatus;
|
|
18
|
-
/** SHA-256 of config.json at session creation time */
|
|
19
|
-
configHash: string;
|
|
20
|
-
/** SHA-256 of strategy.json (current game section) at session creation time */
|
|
21
|
-
strategyHash: string;
|
|
22
|
-
/** SHA-256 of soul.md at session creation time */
|
|
23
|
-
soulHash: string;
|
|
24
|
-
/** Provider profile ID used for this session */
|
|
25
|
-
providerProfileId: string;
|
|
26
|
-
/** ISO-8601 creation timestamp */
|
|
27
|
-
createdAt: string;
|
|
28
|
-
/** ISO-8601 last-update timestamp */
|
|
29
|
-
updatedAt: string;
|
|
30
|
-
}
|
|
31
|
-
export interface DecisionRecord {
|
|
32
|
-
/** Zero-based turn index within the match */
|
|
33
|
-
turnIndex: number;
|
|
34
|
-
/** Raw JSON string of legal actions array (stored as string to avoid parsing issues) */
|
|
35
|
-
legalActionsJson: string;
|
|
36
|
-
/** The action string returned to the platform */
|
|
37
|
-
selectedAction: string;
|
|
38
|
-
/** Whether the action passed platform validation */
|
|
39
|
-
actionValid: boolean;
|
|
40
|
-
/** True if a fallback action was used (LLM failed, timed out, or returned invalid) */
|
|
41
|
-
fallbackUsed: boolean;
|
|
42
|
-
/** Provider profile ID used for this decision */
|
|
43
|
-
providerProfileId: string;
|
|
44
|
-
/** Short one-line rationale extracted from LLM response (if available) */
|
|
45
|
-
reasonSummary?: string;
|
|
46
|
-
/** End-to-end decision latency in ms (LLM call + parse) */
|
|
47
|
-
latencyMs: number;
|
|
48
|
-
/** ISO-8601 timestamp */
|
|
49
|
-
timestamp: string;
|
|
50
|
-
}
|
|
51
|
-
/** Resolve the session directory for a given agent slug + match ID. */
|
|
52
|
-
export declare function resolveSessionDir(agentSlug: string, matchId: string): string;
|
|
53
|
-
export interface CreateSessionOpts {
|
|
54
|
-
platformMatchId: string;
|
|
55
|
-
platformSessionId?: string;
|
|
56
|
-
agentSlug: string;
|
|
57
|
-
gameId: string;
|
|
58
|
-
environment: string;
|
|
59
|
-
configHash: string;
|
|
60
|
-
strategyHash: string;
|
|
61
|
-
soulHash: string;
|
|
62
|
-
providerProfileId: string;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Creates the session directory and writes session.json.
|
|
66
|
-
* Returns the newly created MatchSession and the resolved session directory.
|
|
67
|
-
*/
|
|
68
|
-
export declare function createSession(opts: CreateSessionOpts): Promise<{
|
|
69
|
-
session: MatchSession;
|
|
70
|
-
sessionDir: string;
|
|
71
|
-
}>;
|
|
72
|
-
/**
|
|
73
|
-
* Loads an existing session from session.json.
|
|
74
|
-
* Throws if session.json is missing or malformed.
|
|
75
|
-
*/
|
|
76
|
-
export declare function loadSession(sessionDir: string): Promise<MatchSession>;
|
|
77
|
-
/**
|
|
78
|
-
* Updates only the `status` and `updatedAt` fields of session.json.
|
|
79
|
-
*/
|
|
80
|
-
export declare function updateSessionStatus(sessionDir: string, status: SessionStatus): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Appends a raw platform event (any object) to events.jsonl.
|
|
83
|
-
* The event is stored as-is; no schema is enforced here.
|
|
84
|
-
*/
|
|
85
|
-
export declare function appendEvent(sessionDir: string, event: unknown): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Appends a decision record to decisions.jsonl.
|
|
88
|
-
*/
|
|
89
|
-
export declare function appendDecision(sessionDir: string, decision: DecisionRecord): Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* Appends a usage record to usage.jsonl.
|
|
92
|
-
*/
|
|
93
|
-
export declare function appendUsage(sessionDir: string, usage: UsageRecord): Promise<void>;
|
|
94
|
-
/**
|
|
95
|
-
* Saves provider-specific continuation state (e.g. conversation thread IDs).
|
|
96
|
-
* Scoped to this match session only — never persisted globally.
|
|
97
|
-
*/
|
|
98
|
-
export declare function saveProviderState(sessionDir: string, state: unknown): Promise<void>;
|
|
99
|
-
/**
|
|
100
|
-
* Loads provider continuation state.
|
|
101
|
-
* Returns null if provider-state.json does not exist yet.
|
|
102
|
-
*/
|
|
103
|
-
export declare function loadProviderState(sessionDir: string): Promise<unknown | null>;
|
|
104
|
-
/**
|
|
105
|
-
* Writes the human-readable post-match summary to summary.md.
|
|
106
|
-
* Called once on game_over.
|
|
107
|
-
*/
|
|
108
|
-
export declare function writeSummary(sessionDir: string, summaryMd: string): Promise<void>;
|
|
109
|
-
/**
|
|
110
|
-
* Lists all session directories for an agent, sorted by name (match ID).
|
|
111
|
-
* Returns absolute paths.
|
|
112
|
-
*/
|
|
113
|
-
export declare function listSessions(agentSlug: string): Promise<string[]>;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The JSON object structure the LLM must return for every decision.
|
|
3
|
-
* Stored as a constant so it can be embedded verbatim in the prompt and
|
|
4
|
-
* referenced from tests without duplication.
|
|
5
|
-
*/
|
|
6
|
-
export declare const DECISION_OUTPUT_SCHEMA: {
|
|
7
|
-
readonly action: "string — exact action token from the legal_actions list";
|
|
8
|
-
readonly args: "object | null — action-specific parameters (omit or null if none required)";
|
|
9
|
-
readonly confidence: "number 0.0–1.0 — your confidence in this action being correct";
|
|
10
|
-
readonly reason_summary: "string — one short sentence: what you chose and the primary reason";
|
|
11
|
-
readonly risk_assessment: "low | medium | high — expected downside risk of this move";
|
|
12
|
-
};
|
|
13
|
-
export interface SessionContext {
|
|
14
|
-
/** Full system prompt (blocks 1–4 + 7: invariants, soul, strategy, anti-injection) */
|
|
15
|
-
systemPrompt: string;
|
|
16
|
-
/** Full user prompt (blocks 5–6: current state + legal actions + output contract) */
|
|
17
|
-
userPrompt: string;
|
|
18
|
-
/** Number of characters used by recent events (for diagnostics) */
|
|
19
|
-
recentEventsChars: number;
|
|
20
|
-
/** Whether recent events were truncated */
|
|
21
|
-
recentEventsTruncated: boolean;
|
|
22
|
-
}
|
|
23
|
-
export interface BuildSessionContextOpts {
|
|
24
|
-
/** Agent soul capsule: full text of soul.md */
|
|
25
|
-
soulMd: string;
|
|
26
|
-
/** Game strategy: the section of strategy.json relevant to this game (serialized) */
|
|
27
|
-
strategyText: string;
|
|
28
|
-
/** Game ID, e.g. "texas_holdem" */
|
|
29
|
-
gameId: string;
|
|
30
|
-
/** Platform match ID (for logging context, never injected into trusted block) */
|
|
31
|
-
platformMatchId: string;
|
|
32
|
-
/**
|
|
33
|
-
* Recent platform events from this session's events.jsonl, serialized to a
|
|
34
|
-
* human-readable string. The caller is responsible for summarizing / selecting
|
|
35
|
-
* which events to include. This text is wrapped in untrusted delimiters.
|
|
36
|
-
*/
|
|
37
|
-
recentEventsText: string;
|
|
38
|
-
/**
|
|
39
|
-
* Current game state from the action_request message.
|
|
40
|
-
* Typically a JSON-serializable object; passed as JSON string.
|
|
41
|
-
*/
|
|
42
|
-
currentStateJson: string;
|
|
43
|
-
/**
|
|
44
|
-
* Legal actions array from the action_request message.
|
|
45
|
-
* Must be a valid JSON array string.
|
|
46
|
-
*/
|
|
47
|
-
legalActionsJson: string;
|
|
48
|
-
/** Turn index within the match (zero-based) */
|
|
49
|
-
turnIndex: number;
|
|
50
|
-
/** Provider profile ID (included in context for transparency) */
|
|
51
|
-
providerProfileId: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Assembles the complete system + user prompt pair for a single decision.
|
|
55
|
-
*
|
|
56
|
-
* Prompt assembly order:
|
|
57
|
-
* System:
|
|
58
|
-
* 1. Invariant instructions (AIFight decision engine contract)
|
|
59
|
-
* 2. Agent soul capsule (soul.md)
|
|
60
|
-
* 3. Game strategy (strategy.json section for current game)
|
|
61
|
-
* 4. Anti-injection rule
|
|
62
|
-
* 7. Output contract (required JSON response schema)
|
|
63
|
-
* User:
|
|
64
|
-
* 5. Match context (recent events from this session only)
|
|
65
|
-
* 6. Current state from platform (action_request.state)
|
|
66
|
-
* + Legal actions (strict JSON array)
|
|
67
|
-
*/
|
|
68
|
-
export declare function buildSessionContext(opts: BuildSessionContextOpts): SessionContext;
|