@myclaw163/clawclaw-cli 0.10.8 → 0.10.9
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 +6 -4
- package/docs/configuration.md +4 -7
- package/docs/custom-modules/README.md +1 -1
- package/docs/custom-modules/behavior.md +2 -2
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/skill.md +6 -5
- package/docs/runtime/README.md +1 -1
- package/docs/runtime/agent-notifications.md +1 -1
- package/docs/runtime/official-perception-modules.md +2 -2
- package/docs/user-guide/README.md +1 -1
- package/docs/user-guide/behavior.md +3 -2
- package/docs/user-guide/desktop-auth.md +1 -1
- package/docs/user-guide/installation.md +7 -6
- package/docs/user-guide/perception.md +1 -1
- package/docs/user-guide/skill.md +6 -5
- package/package.json +1 -1
- package/scripts/check-skill-command-surface.mjs +7 -2
- package/scripts/enable_ccl_permissions.cjs +4 -0
- package/skills/clawclaw/SKILL.md +23 -187
- package/skills/clawclaw/references/BEHAVIORS.md +7 -7
- package/skills/clawclaw/references/CHANNELS.md +1 -1
- package/skills/clawclaw/references/COMMANDS.md +20 -18
- package/skills/clawclaw/references/HUB.md +15 -15
- package/skills/clawclaw/references/STREAM.md +1 -1
- package/skills/clawclaw-creator/SKILL.md +27 -25
- package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +9 -9
- package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +5 -5
- package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +14 -13
- package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +7 -7
- package/skills/clawclaw-creator/references/CUSTOM-PERSONA-DEVELOPMENT.md +6 -6
- package/skills/clawclaw-creator/references/CUSTOM-SKILL-DEVELOPMENT.md +11 -10
- package/skills/clawclaw-creator/references/SYNC-AND-REPORT.md +21 -19
- package/skills/clawclaw-start/SKILL.md +49 -0
- package/skills/clawclaw-start/references/STARTUP.md +176 -0
- package/src/cli.ts +2 -0
- package/src/commands/behavior.ts +1 -1
- package/src/commands/communication.ts +1 -1
- package/src/commands/hub.ts +2 -2
- package/src/commands/load.ts +30 -984
- package/src/commands/prepare.ts +1002 -0
- package/src/commands/skill.ts +1 -1
- package/src/lib/account-guidance.ts +5 -3
- package/src/lib/hub-errors.ts +2 -2
- package/src/lib/load-context.ts +11 -7
- package/src/lib/load-startup-context.ts +85 -0
- package/src/lib/load-startup.ts +47 -0
- package/src/lib/package-skills.ts +1 -1
- package/src/lib/skill-name-conflicts.ts +1 -1
- package/src/pipeline/event-hints.ts +2 -2
- package/src/runtime/auto-upgrade.ts +1 -1
- package/src/runtime/clawclaw/owner.ts +0 -7
- package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.ts +3 -3
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-JMX6D6A3.js +0 -260
package/src/commands/skill.ts
CHANGED
|
@@ -46,7 +46,7 @@ export function createSkillCommand(): Command {
|
|
|
46
46
|
// ─── install ───
|
|
47
47
|
cmd.command('install [path]')
|
|
48
48
|
.description('Register a skill directory with the agent. Use --builtin for all bundled ClawClaw skills.')
|
|
49
|
-
.option('--builtin', 'install the bundled gameplay and creator skills shipped with this CLI')
|
|
49
|
+
.option('--builtin', 'install the bundled startup, gameplay and creator skills shipped with this CLI')
|
|
50
50
|
.option('-g, --global', 'install globally', true)
|
|
51
51
|
.option('-y, --yes', 'skip confirmation prompts', true)
|
|
52
52
|
.action(async (rawPath: string | undefined, opts: { builtin?: boolean; global?: boolean; yes?: boolean }) => {
|
|
@@ -9,7 +9,7 @@ export const INVITE_RETRY_COMMAND = 'ccl account register --invite-code <code>';
|
|
|
9
9
|
export const NAMED_INVITE_RETRY_COMMAND = 'ccl account register --name <name> --invite-code <code>';
|
|
10
10
|
|
|
11
11
|
export const POST_REGISTRATION_NEXT_STEP =
|
|
12
|
-
'Ask the player whether to start matchmaking now. If yes, run `ccl
|
|
12
|
+
'Ask the player whether to start matchmaking now. If yes, run `ccl prepare` first. When participation.status is `idle`, launch `ccl start match` with the host stream tool; if participation already exists, attach with `ccl join` instead.';
|
|
13
13
|
|
|
14
14
|
// Player-facing scripts, spoken verbatim by the Agent. This is the only place
|
|
15
15
|
// registration wording is defined, so the gated and ungated flows cannot drift.
|
|
@@ -54,7 +54,7 @@ export function registrationCheckOutput(result: RegistrationCheckResult): Record
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
type NoAccountAction = 'load' | 'gameStart' | 'accountInfo';
|
|
57
|
+
type NoAccountAction = 'prepare' | 'load' | 'gameStart' | 'accountInfo';
|
|
58
58
|
|
|
59
59
|
// Safety net for a caller that registered without checking the policy first.
|
|
60
60
|
// No account was created, so the only thing missing is the code.
|
|
@@ -76,7 +76,9 @@ export function noAccountMessage(action: NoAccountAction): string {
|
|
|
76
76
|
? 'Cannot start matchmaking: no local ClawClaw account is configured.'
|
|
77
77
|
: action === 'accountInfo'
|
|
78
78
|
? 'No local ClawClaw account is configured.'
|
|
79
|
-
:
|
|
79
|
+
: action === 'prepare'
|
|
80
|
+
? 'Cannot prepare gameplay resources: no local ClawClaw account is configured.'
|
|
81
|
+
: 'Cannot load persona/memory: no local ClawClaw account is configured.';
|
|
80
82
|
return [
|
|
81
83
|
firstLine,
|
|
82
84
|
REGISTRATION_PROMPT,
|
package/src/lib/hub-errors.ts
CHANGED
|
@@ -42,9 +42,9 @@ export function hubErrorFields(error: unknown): HubErrorFields | undefined {
|
|
|
42
42
|
} else if (version && code === 'SKILL_NAME_KEY_MISSING') {
|
|
43
43
|
result.hint = '该历史 Skill 尚未完成名称回填,请联系 Hub 运维处理后再发版;不要反复重试,本地修改已保留。';
|
|
44
44
|
} else if (equipment && code === 'SKILL_NAME_CONFLICT') {
|
|
45
|
-
result.hint = '已装配另一件同名 Skill。请用户到 Hub 处理装配冲突,完成后重新运行 ccl
|
|
45
|
+
result.hint = '已装配另一件同名 Skill。请用户到 Hub 处理装配冲突,完成后重新运行 ccl prepare;CCL 不自动卸载或替换任何 Skill,也不要用卸载后重装绕过此提示。';
|
|
46
46
|
} else if (equipment && code === 'INVALID_LOADOUT') {
|
|
47
|
-
result.hint = '装配选择无效,可能是同名 Skill、超出上限或类型不匹配。请按服务端原因到 Hub 修正选择,再运行 ccl
|
|
47
|
+
result.hint = '装配选择无效,可能是同名 Skill、超出上限或类型不匹配。请按服务端原因到 Hub 修正选择,再运行 ccl prepare。';
|
|
48
48
|
} else if (equipment && code === 'WORKSPACE_REVISION_CONFLICT') {
|
|
49
49
|
result.hint = 'Workspace 装配正在被并发修改。请刷新最新装配状态后再重试本次明确操作;不要反复重放旧装配。';
|
|
50
50
|
result.retryable = true;
|
package/src/lib/load-context.ts
CHANGED
|
@@ -30,20 +30,20 @@ function ensureMemoryFile(path: string): void {
|
|
|
30
30
|
if (!existsSync(path)) writeFileSync(path, '');
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function loadPersonaSnapshot(authStore = new AuthStore()): LoadedFileSnapshot {
|
|
33
|
+
export function loadPersonaSnapshot(authStore = new AuthStore(), includeContent = true): LoadedFileSnapshot {
|
|
34
34
|
const resolved = resolveActivePersonaFile(authStore);
|
|
35
35
|
const exists = resolved.path !== null && existsSync(resolved.path);
|
|
36
36
|
return {
|
|
37
37
|
path: resolved.path,
|
|
38
38
|
exists,
|
|
39
|
-
content: resolved.path ? readPersonaFile(resolved.path) : '',
|
|
39
|
+
content: includeContent && resolved.path ? readPersonaFile(resolved.path) : '',
|
|
40
40
|
source: resolved.source,
|
|
41
41
|
...(resolved.id ? { id: resolved.id } : {}),
|
|
42
42
|
...(resolved.resourceId ? { resource_id: resolved.resourceId } : {}),
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export function loadMemorySnapshot(authStore = new AuthStore()): LoadedFileSnapshot {
|
|
46
|
+
export function loadMemorySnapshot(authStore = new AuthStore(), includeContent = true): LoadedFileSnapshot {
|
|
47
47
|
const profile = authStore.getActive();
|
|
48
48
|
if (!profile) throw new Error(accountRequiredMessage('Not logged in.'));
|
|
49
49
|
const path = getProfileMemoryFile(profile);
|
|
@@ -52,7 +52,7 @@ export function loadMemorySnapshot(authStore = new AuthStore()): LoadedFileSnaps
|
|
|
52
52
|
return {
|
|
53
53
|
path,
|
|
54
54
|
exists,
|
|
55
|
-
content: exists ? readFileSync(path, 'utf8') : '',
|
|
55
|
+
content: includeContent && exists ? readFileSync(path, 'utf8') : '',
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -81,9 +81,13 @@ export function limitMemoryForAgent(
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
export function loadContext(
|
|
84
|
+
export function loadContext(
|
|
85
|
+
authStore = new AuthStore(),
|
|
86
|
+
options: { includeContent?: boolean } = {},
|
|
87
|
+
): LoadContextSnapshot {
|
|
88
|
+
const includeContent = options.includeContent !== false;
|
|
85
89
|
return {
|
|
86
|
-
persona: loadPersonaSnapshot(authStore),
|
|
87
|
-
memory: limitMemoryForAgent(loadMemorySnapshot(authStore)),
|
|
90
|
+
persona: loadPersonaSnapshot(authStore, includeContent),
|
|
91
|
+
memory: limitMemoryForAgent(loadMemorySnapshot(authStore, includeContent)),
|
|
88
92
|
};
|
|
89
93
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdirSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import type { AuthProfile } from './auth.js';
|
|
5
|
+
import { getUserDataAccountDir } from './user-data.js';
|
|
6
|
+
|
|
7
|
+
const REF = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
8
|
+
const SCHEMA = 'ccl.startup-context.v1';
|
|
9
|
+
const RETAINED_CONTEXTS = 32;
|
|
10
|
+
|
|
11
|
+
export interface DeferredLoadContext {
|
|
12
|
+
sync: Record<string, unknown>;
|
|
13
|
+
changes?: Record<string, unknown>;
|
|
14
|
+
capabilities: Record<string, unknown>;
|
|
15
|
+
configuration_warnings: readonly Record<string, unknown>[];
|
|
16
|
+
persona_available: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface StoredContext extends DeferredLoadContext {
|
|
20
|
+
schema: typeof SCHEMA;
|
|
21
|
+
context_ref: string;
|
|
22
|
+
prepared_at: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function directory(workspace: string, profile: Pick<AuthProfile, 'apiKey'>): string {
|
|
26
|
+
return join(getUserDataAccountDir(workspace, profile), 'startup-contexts');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Save notices and capability metadata without persona/memory text or a reusable participation snapshot. */
|
|
30
|
+
export function saveStartupContext(
|
|
31
|
+
workspace: string,
|
|
32
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
33
|
+
context: DeferredLoadContext,
|
|
34
|
+
): { context_ref: string; prepared_at: string } {
|
|
35
|
+
const root = directory(workspace, profile);
|
|
36
|
+
mkdirSync(root, { recursive: true });
|
|
37
|
+
const context_ref = randomUUID();
|
|
38
|
+
const prepared_at = new Date().toISOString();
|
|
39
|
+
const value: StoredContext = { schema: SCHEMA, context_ref, prepared_at, ...context };
|
|
40
|
+
writeFileSync(join(root, `${context_ref}.json`), JSON.stringify(value), { flag: 'wx', mode: 0o600 });
|
|
41
|
+
const pointer = join(root, `${context_ref}.pointer`);
|
|
42
|
+
writeFileSync(pointer, context_ref, { flag: 'wx', mode: 0o600 });
|
|
43
|
+
renameSync(pointer, join(root, 'latest'));
|
|
44
|
+
const previous = readdirSync(root).filter(name => name.endsWith('.json')
|
|
45
|
+
&& REF.test(name.slice(0, -5)) && name !== `${context_ref}.json`)
|
|
46
|
+
.map(name => ({ name, modified: statSync(join(root, name)).mtimeMs }))
|
|
47
|
+
.sort((a, b) => b.modified - a.modified);
|
|
48
|
+
for (const file of previous.slice(RETAINED_CONTEXTS - 1)) unlinkSync(join(root, file.name));
|
|
49
|
+
return { context_ref, prepared_at };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
53
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Retrieve one exact preparation under the active account without running synchronization again. */
|
|
57
|
+
export function readStartupContext(
|
|
58
|
+
workspace: string,
|
|
59
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
60
|
+
requestedRef?: string,
|
|
61
|
+
): StoredContext {
|
|
62
|
+
let ref = requestedRef;
|
|
63
|
+
if (ref === undefined) {
|
|
64
|
+
try { ref = readFileSync(join(directory(workspace, profile), 'latest'), 'utf8').trim(); }
|
|
65
|
+
catch { throw new Error('No prepared context for this account. Run ccl prepare before ccl load.'); }
|
|
66
|
+
}
|
|
67
|
+
if (!REF.test(ref)) throw new Error('Invalid startup context reference. Use the context_ref returned by ccl prepare.');
|
|
68
|
+
let value: unknown;
|
|
69
|
+
try { value = JSON.parse(readFileSync(join(directory(workspace, profile), `${ref}.json`), 'utf8')); }
|
|
70
|
+
catch { throw new Error('Startup context is unavailable for this account. Do not repeat start/join; retain already received context and report the missing reference.'); }
|
|
71
|
+
if (!record(value) || value.schema !== SCHEMA || value.context_ref !== ref
|
|
72
|
+
|| typeof value.prepared_at !== 'string' || typeof value.persona_available !== 'boolean'
|
|
73
|
+
|| !record(value.sync) || !record(value.capabilities)
|
|
74
|
+
|| (value.changes !== undefined && !record(value.changes))
|
|
75
|
+
|| !Array.isArray(value.configuration_warnings) || !value.configuration_warnings.every(record)) {
|
|
76
|
+
throw new Error('Invalid stored startup context. Do not repeat start/join.');
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
schema: SCHEMA, context_ref: ref, prepared_at: value.prepared_at,
|
|
80
|
+
sync: value.sync, capabilities: value.capabilities,
|
|
81
|
+
...(value.changes ? { changes: value.changes } : {}),
|
|
82
|
+
configuration_warnings: value.configuration_warnings,
|
|
83
|
+
persona_available: value.persona_available,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CapabilityWorkspaceType } from './capability-workspace.js';
|
|
2
|
+
|
|
3
|
+
interface ResourceChoice {
|
|
4
|
+
type: CapabilityWorkspaceType;
|
|
5
|
+
id: string;
|
|
6
|
+
selection_ref: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ContentConflict {
|
|
10
|
+
type: CapabilityWorkspaceType;
|
|
11
|
+
id: string;
|
|
12
|
+
resource_id: string;
|
|
13
|
+
selection_ref?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface SyncFailure {
|
|
17
|
+
type: CapabilityWorkspaceType;
|
|
18
|
+
id: string;
|
|
19
|
+
action: string;
|
|
20
|
+
code?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type StartupBlocker =
|
|
24
|
+
| ({ code: 'CAPABILITY_SELECTION_REQUIRED' } & ResourceChoice)
|
|
25
|
+
| ({ code: 'CAPABILITY_CONTENT_CONFLICT' } & ContentConflict)
|
|
26
|
+
| { code: 'SKILL_NAME_CONFLICT'; type: CapabilityWorkspaceType; id: string };
|
|
27
|
+
|
|
28
|
+
/** Preserve resource choices that must be handled before starting, including personas. */
|
|
29
|
+
export function summarizeStartupBlockers(
|
|
30
|
+
selections: readonly ResourceChoice[],
|
|
31
|
+
conflicts: readonly ContentConflict[],
|
|
32
|
+
failures: readonly SyncFailure[],
|
|
33
|
+
): { blockers: StartupBlocker[] } {
|
|
34
|
+
return {
|
|
35
|
+
blockers: [
|
|
36
|
+
...selections.map(({ type, id, selection_ref }): StartupBlocker => ({
|
|
37
|
+
code: 'CAPABILITY_SELECTION_REQUIRED', type, id, selection_ref,
|
|
38
|
+
})),
|
|
39
|
+
...conflicts.map(({ type, id, resource_id, selection_ref }): StartupBlocker => ({
|
|
40
|
+
code: 'CAPABILITY_CONTENT_CONFLICT', type, id, resource_id,
|
|
41
|
+
...(selection_ref ? { selection_ref } : {}),
|
|
42
|
+
})),
|
|
43
|
+
...failures.filter(value => value.action === 'equipment' && value.code === 'SKILL_NAME_CONFLICT')
|
|
44
|
+
.map(({ type, id }): StartupBlocker => ({ code: 'SKILL_NAME_CONFLICT', type, id })),
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { basename } from 'node:path';
|
|
2
2
|
|
|
3
3
|
/** Package-owned teaching skills are independent of an account's Hub loadout. */
|
|
4
|
-
export const PACKAGE_MANAGED_SKILL_NAMES = ['clawclaw', 'clawclaw-creator'] as const;
|
|
4
|
+
export const PACKAGE_MANAGED_SKILL_NAMES = ['clawclaw', 'clawclaw-creator', 'clawclaw-start'] as const;
|
|
5
5
|
|
|
6
6
|
export function reservedSkillName(name: string | null, directory?: string): string | undefined {
|
|
7
7
|
const key = name?.trim().toLowerCase();
|
|
@@ -69,7 +69,7 @@ export function skillNameConflicts(candidates: readonly SkillNameCandidate[]): S
|
|
|
69
69
|
}
|
|
70
70
|
return [...groups].filter(([, group]) => group.length > 1).map(([name, group]) => ({
|
|
71
71
|
code: 'SKILL_NAME_CONFLICT', name, blocking: true, candidates: group,
|
|
72
|
-
hint: 'Only one Skill with this name may be equipped. Choose which resource to keep and unequip the others using their selection_ref (or in Hub), then run ccl
|
|
72
|
+
hint: 'Only one Skill with this name may be equipped. Choose which resource to keep and unequip the others using their selection_ref (or in Hub), then run ccl prepare. No Skill is renamed or replaced automatically.',
|
|
73
73
|
}));
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -312,7 +312,7 @@ export const LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS: Readonly<Record<string, Even
|
|
|
312
312
|
case 'COMPETITION_NOT_OPEN':
|
|
313
313
|
return 'Tell the user competition is not open now and use `competition.daily_windows` for the opening windows. Do not start normal matchmaking unless the user asks.';
|
|
314
314
|
case 'ALREADY_IN_GAME':
|
|
315
|
-
return 'Tell the user this account is already in a game. Run `ccl
|
|
315
|
+
return 'Tell the user this account is already in a game. Run `ccl prepare` to confirm the existing participation, then attach with `ccl join` instead of starting another match.';
|
|
316
316
|
default:
|
|
317
317
|
return 'Tell the user competition matchmaking failed. Do not start normal matchmaking unless the user asks.';
|
|
318
318
|
}
|
|
@@ -356,7 +356,7 @@ export const LOCAL_LIFECYCLE_EVENT_HINT_FORMATTERS: Readonly<Record<string, Even
|
|
|
356
356
|
: 'The user left this game from the web page. Stop playing and do not start another match unless the user asks.'
|
|
357
357
|
),
|
|
358
358
|
room_lobby_reconnect_failed: () => (
|
|
359
|
-
'The room round ended, but Lobby reattachment failed and this runtime is exiting. Ask whether to recover or leave the room; to recover, run `ccl
|
|
359
|
+
'The room round ended, but Lobby reattachment failed and this runtime is exiting. Ask whether to recover or leave the room; to recover, run `ccl prepare` and, if participation still exists, attach with `ccl join`. Do not start normal matchmaking.'
|
|
360
360
|
),
|
|
361
361
|
room_lobby_missing: () => (
|
|
362
362
|
'The room round ended and the account is no longer in the familiar room. Do not start normal matchmaking; ask the user what to do next.'
|
|
@@ -15,7 +15,7 @@ export function shouldSkipAutoUpgrade(packageVersion = readPackageVersion()): bo
|
|
|
15
15
|
return Boolean(packageVersion?.includes('-'));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/** Run during `ccl load
|
|
18
|
+
/** Run during `ccl prepare` (formerly load), before game start and event streaming begin. */
|
|
19
19
|
export function runAutoUpgradeOnLoad(options?: { packageVersion?: string; notify?: (message: string) => void }): void {
|
|
20
20
|
if (shouldSkipAutoUpgrade(options?.packageVersion)) return;
|
|
21
21
|
|
|
@@ -780,7 +780,6 @@ export async function runClawclawOwner(
|
|
|
780
780
|
cclEventsMailbox = new AgentMailboxCoordinator({
|
|
781
781
|
repository: mailboxRepository,
|
|
782
782
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
783
|
-
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
784
783
|
presentEvent: ownerAgentEventPresenter('ccl_events', !!options.desktopEvents),
|
|
785
784
|
compactState: compactStateForEvents,
|
|
786
785
|
admitEvent: isClawclawAgentNotification,
|
|
@@ -815,7 +814,6 @@ export async function runClawclawOwner(
|
|
|
815
814
|
admitEvent: isClawclawAgentNotification,
|
|
816
815
|
repository: mailboxRepository,
|
|
817
816
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
818
|
-
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
819
817
|
presentEvent: ownerAgentEventPresenter('desktop_ipc', true),
|
|
820
818
|
compactState: () => null,
|
|
821
819
|
consumerId: DESKTOP_IPC_MAILBOX_CONSUMER_ID,
|
|
@@ -873,7 +871,6 @@ export async function runClawclawOwner(
|
|
|
873
871
|
if (channelPolicy.enabled) {
|
|
874
872
|
channelAdapter = new ClaudeChannelMailboxAdapter({
|
|
875
873
|
notificationOnly: true,
|
|
876
|
-
onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
|
|
877
874
|
repository: mailboxRepository,
|
|
878
875
|
readyView: () => runtime!.readReadyView(0, 1),
|
|
879
876
|
diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
|
|
@@ -961,10 +958,6 @@ export async function runClawclawOwner(
|
|
|
961
958
|
mailboxRepository,
|
|
962
959
|
'short',
|
|
963
960
|
MONITOR_MAILBOX_CONSUMER_ID,
|
|
964
|
-
undefined,
|
|
965
|
-
(eventIds) => {
|
|
966
|
-
perceptionReportAdapter.reportDelivered(mailboxService!.monitorDeliveredEvents(eventIds));
|
|
967
|
-
},
|
|
968
961
|
);
|
|
969
962
|
relayAbort = new AbortController();
|
|
970
963
|
relayAlive = true;
|
package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.ts
CHANGED
|
@@ -43,7 +43,7 @@ function uuidForEvent(event: CanonicalEvent): string {
|
|
|
43
43
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/** Best-effort
|
|
46
|
+
/** Best-effort reporting of newly committed perceptions, independent of Agent delivery. */
|
|
47
47
|
export class GameSyncPerceptionReportAdapter implements ClawclawMailboxDriver {
|
|
48
48
|
readonly adapter: ClawclawMailboxAdapterDescriptor = {
|
|
49
49
|
id: 'clawclaw.mailbox.adapter.game-sync-perception-report',
|
|
@@ -56,8 +56,8 @@ export class GameSyncPerceptionReportAdapter implements ClawclawMailboxDriver {
|
|
|
56
56
|
|
|
57
57
|
constructor(private readonly options: GameSyncPerceptionReportAdapterOptions) {}
|
|
58
58
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
59
|
+
/** Mailbox calls this after the producing epoch's Ready boundary is committed. */
|
|
60
|
+
observeEvents(events: readonly CanonicalEvent[]): void {
|
|
61
61
|
if (this.stopped) return;
|
|
62
62
|
let skipped = 0;
|
|
63
63
|
const reports: GameSyncPerceptionReport[] = [];
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
// src/sdk/perception-plugin/module.ts
|
|
2
|
-
var PERCEPTION_MODULE_API_VERSION = 3;
|
|
3
|
-
|
|
4
|
-
// src/sdk/perception-plugin/index.ts
|
|
5
|
-
import { Perception } from "@myclaw163/game-agent-runtime/sdk/perception.js";
|
|
6
|
-
|
|
7
|
-
// src/sdk/perception-plugin/reaction.ts
|
|
8
|
-
var ClawclawReaction = class {
|
|
9
|
-
static manifest;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/sdk/perception-plugin/reminder.ts
|
|
13
|
-
var REMINDER_PLUGIN_API_VERSION = 2;
|
|
14
|
-
var ClawclawReminder = class {
|
|
15
|
-
static manifest;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// src/sdk/perception-plugin/reminder-rules.ts
|
|
19
|
-
var TASK_LIFECYCLE_FACT_TYPES = [
|
|
20
|
-
"task_started",
|
|
21
|
-
"task_progress",
|
|
22
|
-
"task_assigned",
|
|
23
|
-
"task_completed",
|
|
24
|
-
"task_interrupted",
|
|
25
|
-
"task_sabotaged"
|
|
26
|
-
];
|
|
27
|
-
var TASK_REMINDER_FACT_TYPES = [
|
|
28
|
-
...TASK_LIFECYCLE_FACT_TYPES,
|
|
29
|
-
"role_assigned",
|
|
30
|
-
"emergency_started",
|
|
31
|
-
"emergency_resolved",
|
|
32
|
-
"emergency_interrupted",
|
|
33
|
-
"meeting_briefing"
|
|
34
|
-
];
|
|
35
|
-
var REMINDER_FACT_TYPES = [...TASK_REMINDER_FACT_TYPES, "wandering_speech"];
|
|
36
|
-
function isReminderMode(value) {
|
|
37
|
-
return value === "wake" || value === "silent" || value === "state_only";
|
|
38
|
-
}
|
|
39
|
-
function defaultConfig(topic) {
|
|
40
|
-
if (topic !== "tasks") throw new Error("Unsupported reminder topic; countdown and ability notifications are owned by CCL.");
|
|
41
|
-
return {
|
|
42
|
-
started: "state_only",
|
|
43
|
-
progress: "state_only",
|
|
44
|
-
added: "silent",
|
|
45
|
-
completed: "silent",
|
|
46
|
-
interrupted: "wake",
|
|
47
|
-
sabotaged: "wake",
|
|
48
|
-
removed: "silent",
|
|
49
|
-
updated: "silent"
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function validateDefaultConfig(topic, input) {
|
|
53
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("Reminder config must be an object.");
|
|
54
|
-
const defaults = defaultConfig(topic);
|
|
55
|
-
for (const key of Object.keys(input)) if (!Object.hasOwn(defaults, key)) throw new Error("Unknown reminder option: " + key);
|
|
56
|
-
const value = { ...defaults, ...input };
|
|
57
|
-
if (!Object.values(value).every(isReminderMode)) throw new Error("Reminder mode must be wake, silent, or state_only.");
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
var kinds = {
|
|
61
|
-
task_started: "started",
|
|
62
|
-
task_progress: "progress",
|
|
63
|
-
task_assigned: "added",
|
|
64
|
-
task_completed: "completed",
|
|
65
|
-
task_interrupted: "interrupted",
|
|
66
|
-
task_sabotaged: "sabotaged"
|
|
67
|
-
};
|
|
68
|
-
var labels = {
|
|
69
|
-
started: "\u5F00\u59CB\u4EFB\u52A1",
|
|
70
|
-
progress: "\u4EFB\u52A1\u8FDB\u5EA6\u53D8\u5316",
|
|
71
|
-
added: "\u65B0\u589E\u4EFB\u52A1",
|
|
72
|
-
completed: "\u4EFB\u52A1\u5B8C\u6210",
|
|
73
|
-
interrupted: "\u4EFB\u52A1\u4E2D\u65AD",
|
|
74
|
-
sabotaged: "\u7834\u574F\u4EFB\u52A1\u5B8C\u6210",
|
|
75
|
-
removed: "\u4EFB\u52A1\u4E0D\u518D\u51FA\u73B0\u5728\u5217\u8868",
|
|
76
|
-
updated: "\u4EFB\u52A1\u4FE1\u606F\u53D8\u5316"
|
|
77
|
-
};
|
|
78
|
-
function record(value) {
|
|
79
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
80
|
-
}
|
|
81
|
-
function speechReminder(input) {
|
|
82
|
-
if (Object.keys(input.config).some((key) => key !== "receive") || input.config.receive !== void 0 && typeof input.config.receive !== "boolean") {
|
|
83
|
-
throw new Error("Speech reminder config must contain only a boolean receive.");
|
|
84
|
-
}
|
|
85
|
-
if (input.config.receive === false) return { events: [] };
|
|
86
|
-
const self = input.gameState?.you?.player;
|
|
87
|
-
return { events: input.facts.flatMap((fact) => {
|
|
88
|
-
if (fact.type !== "wandering_speech" || fact.replayed) return [];
|
|
89
|
-
const actor = record(fact.payload.actor);
|
|
90
|
-
const seat = actor.seat ?? fact.payload.actor_seat;
|
|
91
|
-
const name = actor.name ?? fact.payload.actor_name;
|
|
92
|
-
const own = seat !== void 0 && self?.seat !== void 0 ? seat === self.seat : typeof name === "string" && self?.name !== void 0 && name === self.name;
|
|
93
|
-
if (own || typeof fact.payload.text !== "string" || !fact.payload.text.trim()) return [];
|
|
94
|
-
return [{
|
|
95
|
-
type: "reminder.speech",
|
|
96
|
-
key: `fact:${fact.eventId}`,
|
|
97
|
-
wakeAgent: true,
|
|
98
|
-
payload: { ...fact.payload, text: fact.payload.text, source_event_id: fact.eventId }
|
|
99
|
-
}];
|
|
100
|
-
}) };
|
|
101
|
-
}
|
|
102
|
-
function defaultReminder(topic, input) {
|
|
103
|
-
if (topic === "speech") return speechReminder(input);
|
|
104
|
-
const config = validateDefaultConfig(topic, input.config);
|
|
105
|
-
const events = [];
|
|
106
|
-
if (input.boundary) return { events };
|
|
107
|
-
const emit = (kind, key, data, eventId) => {
|
|
108
|
-
const mode = config[kind];
|
|
109
|
-
if (mode === "state_only") return;
|
|
110
|
-
const { tasks: _tasks, delta: _delta, newly_assigned_task: _assigned, ...detail } = data;
|
|
111
|
-
const name = String(detail.task_name ?? detail.name ?? "");
|
|
112
|
-
const actor = record(detail.actor);
|
|
113
|
-
const seat = actor.seat ?? detail.actor_seat;
|
|
114
|
-
const who = seat !== void 0 && seat !== input.gameState?.you?.player?.seat ? `${seat}\u53F7\u73A9\u5BB6\uFF1A` : "";
|
|
115
|
-
const room = detail.room ? `\uFF08${String(detail.room)}\uFF09` : "";
|
|
116
|
-
events.push({
|
|
117
|
-
type: "reminder.task",
|
|
118
|
-
key,
|
|
119
|
-
wakeAgent: mode === "wake",
|
|
120
|
-
payload: { ...detail, kind, source_event_id: eventId, text: `${who}${labels[kind]}\uFF1A${name}${room}\u3002` }
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
for (const fact of input.facts) {
|
|
124
|
-
const kind = kinds[fact.type];
|
|
125
|
-
if (kind) emit(kind, `fact:${fact.eventId}`, { ...fact.payload }, fact.eventId);
|
|
126
|
-
}
|
|
127
|
-
return { events };
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/sdk/perception-plugin/math.ts
|
|
131
|
-
var TICK_MS = 100;
|
|
132
|
-
var MOVE_MIN_PX = 18;
|
|
133
|
-
var STEP_MOVE_MIN_PX = 4;
|
|
134
|
-
var STILL_STEP_MAX_PX = 3;
|
|
135
|
-
function vector(from, to) {
|
|
136
|
-
return { x: to.x - from.x, y: to.y - from.y };
|
|
137
|
-
}
|
|
138
|
-
function length(value) {
|
|
139
|
-
return Math.hypot(value.x, value.y);
|
|
140
|
-
}
|
|
141
|
-
function distance(a, b) {
|
|
142
|
-
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
143
|
-
}
|
|
144
|
-
function dot(a, b) {
|
|
145
|
-
return a.x * b.x + a.y * b.y;
|
|
146
|
-
}
|
|
147
|
-
function cross(a, b) {
|
|
148
|
-
return a.x * b.y - a.y * b.x;
|
|
149
|
-
}
|
|
150
|
-
function unit(value) {
|
|
151
|
-
const magnitude = length(value);
|
|
152
|
-
return magnitude <= 0 ? { x: 0, y: 0 } : { x: value.x / magnitude, y: value.y / magnitude };
|
|
153
|
-
}
|
|
154
|
-
function cosine(a, b) {
|
|
155
|
-
const denominator = length(a) * length(b);
|
|
156
|
-
return denominator <= 0 ? 0 : dot(a, b) / denominator;
|
|
157
|
-
}
|
|
158
|
-
function angleDegrees(a, b) {
|
|
159
|
-
return Math.acos(Math.max(-1, Math.min(1, cosine(a, b)))) * (180 / Math.PI);
|
|
160
|
-
}
|
|
161
|
-
function direction(from, to, minimum = MOVE_MIN_PX) {
|
|
162
|
-
const dx = to.x - from.x;
|
|
163
|
-
const dy = to.y - from.y;
|
|
164
|
-
if (Math.hypot(dx, dy) < minimum) return "\u539F\u5730";
|
|
165
|
-
const horizontal = Math.abs(dx) >= minimum / 2 ? dx > 0 ? "\u53F3" : "\u5DE6" : "";
|
|
166
|
-
const vertical = Math.abs(dy) >= minimum / 2 ? dy > 0 ? "\u4E0B" : "\u4E0A" : "";
|
|
167
|
-
return `${horizontal}${vertical}` || "\u539F\u5730";
|
|
168
|
-
}
|
|
169
|
-
function headingDirection(from, to, minimum = MOVE_MIN_PX) {
|
|
170
|
-
const dx = to.x - from.x;
|
|
171
|
-
const dy = to.y - from.y;
|
|
172
|
-
if (Math.hypot(dx, dy) < minimum) return "\u539F\u5730";
|
|
173
|
-
const octant = Math.round(Math.atan2(dy, dx) / (Math.PI / 4));
|
|
174
|
-
const directions = [
|
|
175
|
-
"\u53F3",
|
|
176
|
-
"\u53F3\u4E0B",
|
|
177
|
-
"\u4E0B",
|
|
178
|
-
"\u5DE6\u4E0B",
|
|
179
|
-
"\u5DE6",
|
|
180
|
-
"\u5DE6\u4E0A",
|
|
181
|
-
"\u4E0A",
|
|
182
|
-
"\u53F3\u4E0A"
|
|
183
|
-
];
|
|
184
|
-
return directions[(octant + directions.length) % directions.length];
|
|
185
|
-
}
|
|
186
|
-
function actorLabel(actor) {
|
|
187
|
-
if (actor.observer) return "\u4F60";
|
|
188
|
-
if (actor.seat !== void 0) return `${actor.seat}\u53F7`;
|
|
189
|
-
return actor.name ?? actor.id;
|
|
190
|
-
}
|
|
191
|
-
function actorValue(actor) {
|
|
192
|
-
return actor.seat ?? actor.id;
|
|
193
|
-
}
|
|
194
|
-
function timeRange(fromTick, toTick) {
|
|
195
|
-
const format = (tick) => {
|
|
196
|
-
const total = Math.max(0, Math.floor(tick * TICK_MS / 1e3));
|
|
197
|
-
return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
|
|
198
|
-
};
|
|
199
|
-
const from = format(fromTick);
|
|
200
|
-
const to = format(toTick);
|
|
201
|
-
return from === to ? from : `${from}-${to}`;
|
|
202
|
-
}
|
|
203
|
-
function round1(value) {
|
|
204
|
-
return Math.round(value * 10) / 10;
|
|
205
|
-
}
|
|
206
|
-
function positionCopy(position) {
|
|
207
|
-
return { x: position.x, y: position.y, room: position.room };
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// src/sdk/perception-plugin/index.ts
|
|
211
|
-
var PERCEPTION_PLUGIN_API_VERSION = 2;
|
|
212
|
-
function evaluateReminder(topic, input) {
|
|
213
|
-
return defaultReminder(topic, "events" in input ? { ...input, facts: input.events } : input);
|
|
214
|
-
}
|
|
215
|
-
var ClawclawPerception = class extends Perception {
|
|
216
|
-
static manifest;
|
|
217
|
-
/** API v3 combines observation, notification and fixed Behavior activation. */
|
|
218
|
-
evaluate(_input, _api) {
|
|
219
|
-
throw new Error("PERCEPTION_EVALUATE_NOT_IMPLEMENTED");
|
|
220
|
-
}
|
|
221
|
-
/** @deprecated API v2 compatibility; new modules implement evaluate(). */
|
|
222
|
-
update(frame, api) {
|
|
223
|
-
throw new Error("PERCEPTION_UPDATE_NOT_IMPLEMENTED");
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
var ClawclawParallelPerception = class extends ClawclawPerception {
|
|
227
|
-
update() {
|
|
228
|
-
throw new Error("parallel_perception_uses_analyze_and_commit");
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
export {
|
|
233
|
-
PERCEPTION_MODULE_API_VERSION,
|
|
234
|
-
ClawclawReaction,
|
|
235
|
-
REMINDER_PLUGIN_API_VERSION,
|
|
236
|
-
ClawclawReminder,
|
|
237
|
-
TICK_MS,
|
|
238
|
-
MOVE_MIN_PX,
|
|
239
|
-
STEP_MOVE_MIN_PX,
|
|
240
|
-
STILL_STEP_MAX_PX,
|
|
241
|
-
vector,
|
|
242
|
-
length,
|
|
243
|
-
distance,
|
|
244
|
-
dot,
|
|
245
|
-
cross,
|
|
246
|
-
unit,
|
|
247
|
-
cosine,
|
|
248
|
-
angleDegrees,
|
|
249
|
-
direction,
|
|
250
|
-
headingDirection,
|
|
251
|
-
actorLabel,
|
|
252
|
-
actorValue,
|
|
253
|
-
timeRange,
|
|
254
|
-
round1,
|
|
255
|
-
positionCopy,
|
|
256
|
-
PERCEPTION_PLUGIN_API_VERSION,
|
|
257
|
-
evaluateReminder,
|
|
258
|
-
ClawclawPerception,
|
|
259
|
-
ClawclawParallelPerception
|
|
260
|
-
};
|