@myclaw163/clawclaw-cli 0.8.2 → 0.8.3
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/docs/configuration.md +1 -1
- package/docs/custom-modules/README.md +2 -2
- package/docs/custom-modules/api-reference.md +17 -3
- package/docs/custom-modules/behavior.md +7 -3
- package/docs/custom-modules/perception.md +26 -3
- package/docs/custom-modules/trigger.md +1 -1
- package/docs/runtime/README.md +1 -1
- package/docs/runtime/behavior-runtime.md +6 -2
- package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +27 -34
- package/skills/clawclaw/references/COMMANDS.md +1 -1
- package/skills/clawclaw/references/STREAM.md +20 -3
- package/src/commands/load.ts +8 -3
- package/src/commands/trigger.ts +12 -5
- package/src/lib/clawclaw-skill-spectate-guidance.test.ts +21 -0
- package/src/lib/trigger-export.test.ts +80 -0
- package/src/lib/trigger-export.ts +210 -0
- package/src/lib/user-data.test.ts +4 -0
- package/src/lib/user-data.ts +4 -0
- package/src/pipeline/event-format.test.ts +62 -0
- package/src/pipeline/event-format.ts +31 -1
- package/src/pipeline/event-hints.test.ts +4 -0
- package/src/runtime/clawclaw/agent-ability-state.ts +89 -0
- package/src/runtime/clawclaw/agent-event-policy.test.ts +4 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +4 -0
- package/src/runtime/clawclaw/behavior-decision.test.ts +14 -0
- package/src/runtime/clawclaw/behavior-decision.ts +8 -1
- package/src/runtime/clawclaw/behavior-input.test.ts +22 -0
- package/src/runtime/clawclaw/behavior-input.ts +3 -0
- package/src/runtime/clawclaw/owner.test.ts +16 -0
- package/src/runtime/clawclaw/owner.ts +21 -8
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +1 -1
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +246 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +135 -6
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +118 -1
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +13 -2
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +156 -0
- package/src/runtime/clawclaw-event-catalog.test.ts +4 -0
- package/src/runtime/clawclaw-event-catalog.ts +4 -0
- package/src/sdk/behavior-plugin/index.ts +10 -0
- package/src/sdk/module-input/index.ts +16 -0
package/src/commands/trigger.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { AuthStore, type AuthProfile } from '../lib/auth.js';
|
|
|
3
3
|
import { syncOfficialBehaviors, listWorkspaceClawclawBehaviorSources } from '../lib/behavior-export.js';
|
|
4
4
|
import { readGameplayConfig, updateGameplayConfig } from '../lib/gameplay-config.js';
|
|
5
5
|
import { getWorkspaceDir } from '../lib/init-command.js';
|
|
6
|
+
import {
|
|
7
|
+
listWorkspaceClawclawTriggerSources,
|
|
8
|
+
syncOfficialTriggers,
|
|
9
|
+
} from '../lib/trigger-export.js';
|
|
6
10
|
import {
|
|
7
11
|
toTriggerRegistrationOverrides,
|
|
8
12
|
type GameplayTriggerConfig,
|
|
@@ -17,7 +21,6 @@ import { TRIGGER_PLUGIN_API_VERSION, MAX_TRIGGER_RUNTIME_MS } from '../sdk/trigg
|
|
|
17
21
|
import { BEHAVIOR_PLUGIN_API_VERSION } from '../sdk/behavior-plugin/index.js';
|
|
18
22
|
import { behaviorSourceCompatibilityError } from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
|
|
19
23
|
import { normalizeBehaviorInput } from '../runtime/clawclaw/behavior-input-fields.js';
|
|
20
|
-
import { listClawclawTriggerSources } from '../runtime/clawclaw/plugins/trigger/trigger-source.js';
|
|
21
24
|
import { sendProfileOwnerControlRequest } from '../runtime/owner-control.js';
|
|
22
25
|
|
|
23
26
|
const OWNER_CONTROL_TIMEOUT_MS = 30_000;
|
|
@@ -58,7 +61,7 @@ function parseSafeInteger(value: string, field: string, minimum: number, maximum
|
|
|
58
61
|
|
|
59
62
|
function triggerSources(workspaceDir: string) {
|
|
60
63
|
ensureUserDataLayout(workspaceDir);
|
|
61
|
-
return
|
|
64
|
+
return listWorkspaceClawclawTriggerSources(workspaceDir);
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
function persistedOverride(id: string, config: GameplayTriggerConfig | undefined) {
|
|
@@ -108,7 +111,7 @@ function triggerEntry(
|
|
|
108
111
|
rearm: override?.rearm ?? source.manifest.defaultRearm,
|
|
109
112
|
max_runtime_ms: override?.maxRuntimeMs ?? source.manifest.defaultMaxRuntimeMs,
|
|
110
113
|
},
|
|
111
|
-
source: 'community',
|
|
114
|
+
source: source.provenance?.kind === 'official' ? 'official' : 'community',
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
117
|
|
|
@@ -165,6 +168,7 @@ async function updateTrigger(
|
|
|
165
168
|
dependencies: TriggerCommandDependencies,
|
|
166
169
|
): Promise<void> {
|
|
167
170
|
const workspaceDir = getWorkspaceDir();
|
|
171
|
+
await syncOfficialTriggers({ workspaceDir });
|
|
168
172
|
const source = triggerSources(workspaceDir).find((candidate) => candidate.id === id);
|
|
169
173
|
if (!source) throw new Error(`Unknown or ambiguous trigger module '${id}'.`);
|
|
170
174
|
const before = readGameplayConfig(workspaceDir);
|
|
@@ -198,8 +202,9 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
|
|
|
198
202
|
|
|
199
203
|
trigger.addCommand(new Command('list')
|
|
200
204
|
.description('List statically discovered Trigger modules')
|
|
201
|
-
.action(() => {
|
|
205
|
+
.action(async () => {
|
|
202
206
|
const workspaceDir = getWorkspaceDir();
|
|
207
|
+
await syncOfficialTriggers({ workspaceDir });
|
|
203
208
|
const gameplay = readGameplayConfig(workspaceDir);
|
|
204
209
|
const sources = triggerSources(workspaceDir);
|
|
205
210
|
console.log(JSON.stringify({
|
|
@@ -213,8 +218,9 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
|
|
|
213
218
|
.description('Show one statically discovered Trigger manifest and effective configuration')
|
|
214
219
|
.argument('<id>', 'Trigger id')
|
|
215
220
|
.allowExcessArguments(false)
|
|
216
|
-
.action((id: string) => {
|
|
221
|
+
.action(async (id: string) => {
|
|
217
222
|
const workspaceDir = getWorkspaceDir();
|
|
223
|
+
await syncOfficialTriggers({ workspaceDir });
|
|
218
224
|
const gameplay = readGameplayConfig(workspaceDir);
|
|
219
225
|
const source = triggerSources(workspaceDir).find((candidate) => candidate.id === id);
|
|
220
226
|
if (!source) throw new Error(`Unknown or ambiguous trigger module '${id}'.`);
|
|
@@ -227,6 +233,7 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
|
|
|
227
233
|
.allowExcessArguments(false)
|
|
228
234
|
.action(async (id: string) => {
|
|
229
235
|
const workspaceDir = getWorkspaceDir();
|
|
236
|
+
await syncOfficialTriggers({ workspaceDir });
|
|
230
237
|
const source = triggerSources(workspaceDir).find((candidate) => candidate.id === id);
|
|
231
238
|
if (!source) throw new Error(`Unknown or ambiguous trigger module '${id}'.`);
|
|
232
239
|
const gameplay = readGameplayConfig(workspaceDir);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
function skillText(path: string): string {
|
|
6
|
+
return readFileSync(join(process.cwd(), 'skills', 'clawclaw', path), 'utf8');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('official ClawClaw Skill spectate guidance', () => {
|
|
10
|
+
it('leaves host-specific spectate-link guidance to CCL Event presentation', () => {
|
|
11
|
+
const skill = skillText('SKILL.md');
|
|
12
|
+
const commands = skillText(join('references', 'COMMANDS.md'));
|
|
13
|
+
const stream = skillText(join('references', 'STREAM.md'));
|
|
14
|
+
|
|
15
|
+
expect(skill).not.toMatch(/分享给用户作为 markdown 链接/u);
|
|
16
|
+
expect(skill).not.toMatch(/有 `url` 就按上条完整分享/u);
|
|
17
|
+
expect(skill).not.toMatch(/事件里有 `url` \/ `spectate_url` 时按原样分享/u);
|
|
18
|
+
expect(commands).not.toMatch(/分享完整房间码和可用的完整观战链接/u);
|
|
19
|
+
expect(stream).not.toMatch(/详情带完整 `url` 时直接分享/u);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import {
|
|
6
|
+
listOfficialTriggerDefinitions,
|
|
7
|
+
listWorkspaceClawclawTriggerSources,
|
|
8
|
+
rewriteBuiltinTriggerImports,
|
|
9
|
+
syncOfficialTriggers,
|
|
10
|
+
} from './trigger-export.js';
|
|
11
|
+
import { getUserDataOfficialTriggersManifestFile } from './user-data.js';
|
|
12
|
+
|
|
13
|
+
const roots: string[] = [];
|
|
14
|
+
|
|
15
|
+
function workspace(): string {
|
|
16
|
+
const root = mkdtempSync(join(tmpdir(), 'ccl-trigger-export-'));
|
|
17
|
+
roots.push(root);
|
|
18
|
+
return root;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('official Trigger materialization', () => {
|
|
26
|
+
it('keeps the reviewed official registry empty without inventing modules', async () => {
|
|
27
|
+
const root = workspace();
|
|
28
|
+
const result = await syncOfficialTriggers({ workspaceDir: root });
|
|
29
|
+
|
|
30
|
+
expect(listOfficialTriggerDefinitions()).toEqual([]);
|
|
31
|
+
expect(result).toEqual({
|
|
32
|
+
added: [],
|
|
33
|
+
updated: [],
|
|
34
|
+
unchanged: [],
|
|
35
|
+
preservedModified: [],
|
|
36
|
+
preservedUntracked: [],
|
|
37
|
+
preservedDeleted: [],
|
|
38
|
+
});
|
|
39
|
+
expect(listWorkspaceClawclawTriggerSources(root)).toEqual([]);
|
|
40
|
+
expect(existsSync(getUserDataOfficialTriggersManifestFile(root))).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('rewrites a future bundled Trigger to the public SDK boundary', () => {
|
|
44
|
+
const source = `
|
|
45
|
+
import { ClawclawTrigger } from '../contracts.js';
|
|
46
|
+
export class DangerTrigger extends ClawclawTrigger {
|
|
47
|
+
static override readonly manifest = {
|
|
48
|
+
apiVersion: 1,
|
|
49
|
+
id: 'danger.nearby',
|
|
50
|
+
name: 'Danger nearby',
|
|
51
|
+
description: 'Detect danger.',
|
|
52
|
+
inputs: [],
|
|
53
|
+
consumes: ['player_entered_view'],
|
|
54
|
+
defaultBehavior: 'flee',
|
|
55
|
+
defaultBehaviorInput: {},
|
|
56
|
+
defaultReflexPriority: 10,
|
|
57
|
+
defaultCooldownMs: 500,
|
|
58
|
+
defaultRearm: 'after_clear',
|
|
59
|
+
defaultMaxRuntimeMs: 5000,
|
|
60
|
+
} as const;
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
|
|
64
|
+
const rewritten = rewriteBuiltinTriggerImports(
|
|
65
|
+
source,
|
|
66
|
+
{ id: 'danger.nearby', className: 'DangerTrigger' },
|
|
67
|
+
'0.8.2',
|
|
68
|
+
);
|
|
69
|
+
expect(rewritten).toContain("from '@myclaw163/clawclaw-cli/trigger-plugin'");
|
|
70
|
+
expect(rewritten).toContain('export default class DangerTrigger');
|
|
71
|
+
expect(rewritten).toContain('official Trigger danger.nearby@0.8.2');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('rejects an id until it enters the reviewed registry', async () => {
|
|
75
|
+
await expect(syncOfficialTriggers({
|
|
76
|
+
workspaceDir: workspace(),
|
|
77
|
+
ids: ['danger.nearby'],
|
|
78
|
+
})).rejects.toThrow("Built-in Trigger module 'danger.nearby' not found.");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// Materialize bundled official Trigger modules into the unified user-owned
|
|
2
|
+
// directory. The registry is intentionally empty until concrete Trigger
|
|
3
|
+
// semantics are reviewed; keeping the full pipeline here makes that addition
|
|
4
|
+
// a resource change rather than another Runtime architecture change.
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { dirname, join, resolve } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { getWorkspaceDir } from './init-command.js';
|
|
9
|
+
import {
|
|
10
|
+
hashOfficialResourceContent,
|
|
11
|
+
readOfficialResourceManifest,
|
|
12
|
+
syncOfficialResources,
|
|
13
|
+
type OfficialResourceSyncResult,
|
|
14
|
+
} from './official-resource-sync.js';
|
|
15
|
+
import {
|
|
16
|
+
ensureUserDataLayout,
|
|
17
|
+
getUserDataOfficialTriggersManifestFile,
|
|
18
|
+
getUserDataTriggersDir,
|
|
19
|
+
} from './user-data.js';
|
|
20
|
+
import {
|
|
21
|
+
listClawclawTriggerSources,
|
|
22
|
+
type ResolvedClawclawTriggerSource,
|
|
23
|
+
} from '../runtime/clawclaw/plugins/trigger/trigger-source.js';
|
|
24
|
+
|
|
25
|
+
const OFFICIAL_TRIGGER_EXPORT_FORMAT = 1;
|
|
26
|
+
|
|
27
|
+
export interface OfficialTriggerDefinition {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly fileName: string;
|
|
30
|
+
readonly className: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface BundledTriggerSource extends OfficialTriggerDefinition {
|
|
34
|
+
readonly path: string;
|
|
35
|
+
readonly source: string;
|
|
36
|
+
readonly sourceHash: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface OfficialTriggerProvenance {
|
|
40
|
+
readonly kind: 'official';
|
|
41
|
+
readonly source: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type WorkspaceClawclawTriggerSource = ResolvedClawclawTriggerSource & Readonly<{
|
|
45
|
+
provenance?: Readonly<OfficialTriggerProvenance>;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
// Concrete official Trigger modules are deliberately pending product review.
|
|
49
|
+
const OFFICIAL_TRIGGER_DEFINITIONS: readonly OfficialTriggerDefinition[] = Object.freeze([]);
|
|
50
|
+
|
|
51
|
+
function bundledTriggersDir(): string {
|
|
52
|
+
return join(
|
|
53
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
54
|
+
'..',
|
|
55
|
+
'runtime',
|
|
56
|
+
'clawclaw',
|
|
57
|
+
'plugins',
|
|
58
|
+
'trigger',
|
|
59
|
+
'modules',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function readPackageVersion(): string {
|
|
64
|
+
try {
|
|
65
|
+
const path = join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'package.json');
|
|
66
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8')) as { version?: unknown };
|
|
67
|
+
return typeof parsed.version === 'string' ? parsed.version : '0.0.0';
|
|
68
|
+
} catch {
|
|
69
|
+
return '0.0.0';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function listBundledTriggerSources(): BundledTriggerSource[] {
|
|
74
|
+
const root = bundledTriggersDir();
|
|
75
|
+
return OFFICIAL_TRIGGER_DEFINITIONS.map((definition) => {
|
|
76
|
+
const path = join(root, definition.fileName);
|
|
77
|
+
if (!existsSync(path)) throw new Error(`Bundled Trigger source for '${definition.id}' is missing.`);
|
|
78
|
+
const source = readFileSync(path, 'utf8');
|
|
79
|
+
return {
|
|
80
|
+
...definition,
|
|
81
|
+
path,
|
|
82
|
+
source,
|
|
83
|
+
sourceHash: hashOfficialResourceContent(
|
|
84
|
+
`${source}\0trigger-export-v${OFFICIAL_TRIGGER_EXPORT_FORMAT}`,
|
|
85
|
+
),
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Public metadata for tooling; currently returns an empty reviewed registry. */
|
|
91
|
+
export function listOfficialTriggerDefinitions(): readonly Readonly<{
|
|
92
|
+
id: string;
|
|
93
|
+
fileName: string;
|
|
94
|
+
className: string;
|
|
95
|
+
sourceHash: string;
|
|
96
|
+
}>[] {
|
|
97
|
+
return listBundledTriggerSources().map((source) => Object.freeze({
|
|
98
|
+
id: source.id,
|
|
99
|
+
fileName: source.fileName,
|
|
100
|
+
className: source.className,
|
|
101
|
+
sourceHash: source.sourceHash,
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Converts one package-owned Trigger into a standalone public-SDK source. */
|
|
106
|
+
export function rewriteBuiltinTriggerImports(
|
|
107
|
+
source: string,
|
|
108
|
+
definition: Pick<OfficialTriggerDefinition, 'id' | 'className'>,
|
|
109
|
+
version: string,
|
|
110
|
+
): string {
|
|
111
|
+
const manifestId = /\bstatic\s+(?:override\s+)?(?:readonly\s+)?manifest\s*=\s*\{[\s\S]*?\bid\s*:\s*(['"])(.*?)\1/.exec(source)?.[2];
|
|
112
|
+
if (manifestId !== definition.id) {
|
|
113
|
+
throw new Error(`Bundled Trigger metadata does not match '${definition.id}'.`);
|
|
114
|
+
}
|
|
115
|
+
const classPattern = new RegExp(
|
|
116
|
+
`export\\s+(?:default\\s+)?class\\s+${definition.className}\\s+extends\\s+ClawclawTrigger\\b`,
|
|
117
|
+
);
|
|
118
|
+
if (!classPattern.test(source)) {
|
|
119
|
+
throw new Error(`Bundled Trigger '${definition.id}' has an unexpected class export.`);
|
|
120
|
+
}
|
|
121
|
+
const rewritten = source
|
|
122
|
+
.replace(
|
|
123
|
+
/from\s+['"]\.\.?\/[^'"]+['"]/g,
|
|
124
|
+
`from '@myclaw163/clawclaw-cli/trigger-plugin'`,
|
|
125
|
+
)
|
|
126
|
+
.replace(
|
|
127
|
+
new RegExp(`export\\s+class\\s+${definition.className}\\b`),
|
|
128
|
+
`export default class ${definition.className}`,
|
|
129
|
+
)
|
|
130
|
+
.replace(
|
|
131
|
+
new RegExp(`\\n?export\\s+default\\s+${definition.className}\\s*;?\\s*$`),
|
|
132
|
+
'\n',
|
|
133
|
+
);
|
|
134
|
+
return `// Materialized from official Trigger ${definition.id}@${version} - customize freely\n${rewritten}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function materializeTrigger(source: BundledTriggerSource, version: string): string {
|
|
138
|
+
return rewriteBuiltinTriggerImports(source.source, source, version);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface SyncOfficialTriggersOptions {
|
|
142
|
+
readonly workspaceDir?: string;
|
|
143
|
+
readonly ids?: readonly string[];
|
|
144
|
+
readonly force?: boolean;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function syncOfficialTriggers(
|
|
148
|
+
options: SyncOfficialTriggersOptions = {},
|
|
149
|
+
): Promise<OfficialResourceSyncResult> {
|
|
150
|
+
const workspaceDir = options.workspaceDir ?? getWorkspaceDir();
|
|
151
|
+
ensureUserDataLayout(workspaceDir);
|
|
152
|
+
const destinationDir = getUserDataTriggersDir(workspaceDir);
|
|
153
|
+
const installedSources = new Map(
|
|
154
|
+
listClawclawTriggerSources(destinationDir).map((source) => [source.id, source]),
|
|
155
|
+
);
|
|
156
|
+
return syncOfficialResources({
|
|
157
|
+
sources: listBundledTriggerSources(),
|
|
158
|
+
manifestPath: getUserDataOfficialTriggersManifestFile(workspaceDir),
|
|
159
|
+
destinationPath: (source) => join(destinationDir, `${source.id}.ts`),
|
|
160
|
+
hasUntrackedConflict: (source, destination) => {
|
|
161
|
+
const installed = installedSources.get(source.id);
|
|
162
|
+
return installed !== undefined && resolve(installed.sourcePath) !== resolve(destination);
|
|
163
|
+
},
|
|
164
|
+
materialize: materializeTrigger,
|
|
165
|
+
version: readPackageVersion(),
|
|
166
|
+
ids: options.ids,
|
|
167
|
+
force: options.force,
|
|
168
|
+
restoreMissingTracked: true,
|
|
169
|
+
notFoundMessage: (id) => `Built-in Trigger module '${id}' not found.`,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function trustedOfficialTrigger(
|
|
174
|
+
workspaceDir: string,
|
|
175
|
+
source: ResolvedClawclawTriggerSource,
|
|
176
|
+
bundled: ReadonlyMap<string, BundledTriggerSource>,
|
|
177
|
+
): WorkspaceClawclawTriggerSource {
|
|
178
|
+
const official = bundled.get(source.id);
|
|
179
|
+
if (!official) return source;
|
|
180
|
+
const canonicalPath = resolve(getUserDataTriggersDir(workspaceDir), `${source.id}.ts`);
|
|
181
|
+
if (resolve(source.sourcePath) !== canonicalPath) return source;
|
|
182
|
+
const entry = readOfficialResourceManifest(
|
|
183
|
+
getUserDataOfficialTriggersManifestFile(workspaceDir),
|
|
184
|
+
)[source.id];
|
|
185
|
+
if (!entry || entry.sourceHash !== official.sourceHash || !entry.installedHash) return source;
|
|
186
|
+
let installed: string;
|
|
187
|
+
try {
|
|
188
|
+
installed = readFileSync(source.sourcePath, 'utf8');
|
|
189
|
+
} catch {
|
|
190
|
+
return source;
|
|
191
|
+
}
|
|
192
|
+
const expected = materializeTrigger(official, entry.version ?? '0.0.0');
|
|
193
|
+
if (hashOfficialResourceContent(installed) !== entry.installedHash || installed !== expected) return source;
|
|
194
|
+
return Object.freeze({
|
|
195
|
+
...source,
|
|
196
|
+
provenance: Object.freeze({
|
|
197
|
+
kind: 'official',
|
|
198
|
+
source: `triggers/${official.fileName}`,
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Discover unified Trigger sources and prove official provenance by exact content. */
|
|
204
|
+
export function listWorkspaceClawclawTriggerSources(
|
|
205
|
+
workspaceDir = getWorkspaceDir(),
|
|
206
|
+
): WorkspaceClawclawTriggerSource[] {
|
|
207
|
+
const bundled = new Map(listBundledTriggerSources().map((source) => [source.id, source]));
|
|
208
|
+
return listClawclawTriggerSources(getUserDataTriggersDir(workspaceDir))
|
|
209
|
+
.map((source) => trustedOfficialTrigger(workspaceDir, source, bundled));
|
|
210
|
+
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
getUserDataMemoryFile,
|
|
13
13
|
getUserDataPerceptionsDir,
|
|
14
14
|
getUserDataPersonaFile,
|
|
15
|
+
getUserDataOfficialTriggersManifestFile,
|
|
15
16
|
getUserDataTriggersDir,
|
|
16
17
|
} from './user-data.js';
|
|
17
18
|
|
|
@@ -74,6 +75,9 @@ describe('user-data layout migration', () => {
|
|
|
74
75
|
expect(existsSync(getUserDataBehaviorsDir(ws))).toBe(true);
|
|
75
76
|
expect(existsSync(getUserDataPerceptionsDir(ws))).toBe(true);
|
|
76
77
|
expect(existsSync(getUserDataTriggersDir(ws))).toBe(true);
|
|
78
|
+
expect(getUserDataOfficialTriggersManifestFile(ws)).toBe(
|
|
79
|
+
join(getUserDataTriggersDir(ws), '.official-manifest.json'),
|
|
80
|
+
);
|
|
77
81
|
expect(existsSync(join(ws, 'user-data', 'strategies'))).toBe(false);
|
|
78
82
|
expect(existsSync(join(ws, 'user-data', 'intents'))).toBe(false);
|
|
79
83
|
expect(existsSync(join(ws, 'strategies', 'custom.ts'))).toBe(true);
|
package/src/lib/user-data.ts
CHANGED
|
@@ -97,6 +97,10 @@ export function getUserDataOfficialPerceptionsManifestFile(workspaceDir: string)
|
|
|
97
97
|
return join(getUserDataPerceptionsDir(workspaceDir), '.official-manifest.json');
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
export function getUserDataOfficialTriggersManifestFile(workspaceDir: string): string {
|
|
101
|
+
return join(getUserDataTriggersDir(workspaceDir), '.official-manifest.json');
|
|
102
|
+
}
|
|
103
|
+
|
|
100
104
|
export function getUserDataHubDir(workspaceDir: string): string {
|
|
101
105
|
return join(getUserDataDir(workspaceDir), 'hub');
|
|
102
106
|
}
|
|
@@ -703,6 +703,68 @@ describe('event-format', () => {
|
|
|
703
703
|
expect(BACKEND_EVENT_HINT_FORMATTERS.octopus_time_start(event, {})).toContain('emergency timeout');
|
|
704
704
|
});
|
|
705
705
|
|
|
706
|
+
it('formats emergency countdown and ability transition facts', () => {
|
|
707
|
+
expect(formatEventMessage({
|
|
708
|
+
type: 'emergency_countdown_warning',
|
|
709
|
+
tick: 12,
|
|
710
|
+
task_name: '修复供氧',
|
|
711
|
+
threshold_secs: 30,
|
|
712
|
+
remaining_secs: 29.8,
|
|
713
|
+
})).toBe('t12 emergency_countdown_warning 紧急任务修复供氧只剩29.8秒(30秒提醒)。');
|
|
714
|
+
expect(formatEventMessage({
|
|
715
|
+
type: 'ability.ready',
|
|
716
|
+
tick: 13,
|
|
717
|
+
ability_id: 'kill',
|
|
718
|
+
ability_name: '攻击',
|
|
719
|
+
})).toBe('t13 ability.ready 能力“攻击”现在可以使用。');
|
|
720
|
+
expect(formatEventMessage({
|
|
721
|
+
type: 'ability.exhausted',
|
|
722
|
+
tick: 14,
|
|
723
|
+
ability_id: 'kill',
|
|
724
|
+
ability_name: '攻击',
|
|
725
|
+
})).toBe('t14 ability.exhausted 能力“攻击”已无剩余次数。');
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
it('includes current emergency and stateful abilities in Agent State', () => {
|
|
729
|
+
const state = compactStateForEvents({
|
|
730
|
+
phase: 'wandering',
|
|
731
|
+
tick: 88,
|
|
732
|
+
you: {
|
|
733
|
+
player: { name: 'me', seat: 1 },
|
|
734
|
+
role: 'shrimp_pistol',
|
|
735
|
+
is_alive: true,
|
|
736
|
+
kill_cooldown_secs: 0,
|
|
737
|
+
kills_remaining: 1,
|
|
738
|
+
},
|
|
739
|
+
emergency: {
|
|
740
|
+
active: true,
|
|
741
|
+
task_name: '修复供氧',
|
|
742
|
+
room: '制氧舱',
|
|
743
|
+
x: 120,
|
|
744
|
+
y: 240,
|
|
745
|
+
remaining_secs: 27.5,
|
|
746
|
+
internal_id: 'must-not-leak',
|
|
747
|
+
},
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
expect(state?.emergency).toEqual({
|
|
751
|
+
active: true,
|
|
752
|
+
task_name: '修复供氧',
|
|
753
|
+
room: '制氧舱',
|
|
754
|
+
x: 120,
|
|
755
|
+
y: 240,
|
|
756
|
+
remaining_secs: 27.5,
|
|
757
|
+
});
|
|
758
|
+
expect(state?.abilities).toEqual([{
|
|
759
|
+
id: 'kill',
|
|
760
|
+
name: '攻击',
|
|
761
|
+
ready: true,
|
|
762
|
+
cooldown_remaining_secs: 0,
|
|
763
|
+
remaining_uses: 1,
|
|
764
|
+
effective_range_px: 160,
|
|
765
|
+
}]);
|
|
766
|
+
});
|
|
767
|
+
|
|
706
768
|
it('tells every surviving role that emergency repair is real and available', () => {
|
|
707
769
|
const hint = BACKEND_EVENT_HINT_FORMATTERS.emergency_started({
|
|
708
770
|
type: 'emergency_started',
|
|
@@ -2,6 +2,7 @@ import { projectPlayers } from './player-projection.js';
|
|
|
2
2
|
import { headingDirection } from '../runtime/clawclaw/plugins/perception/shared/math.js';
|
|
3
3
|
import { isRoomMode } from '../lib/room.js';
|
|
4
4
|
import { isSelfKillerMurderWitnessed } from './event-hints.js';
|
|
5
|
+
import { projectAgentAbilities } from '../runtime/clawclaw/agent-ability-state.js';
|
|
5
6
|
|
|
6
7
|
export interface EventFormatContext {
|
|
7
8
|
summary?: any | null;
|
|
@@ -424,6 +425,8 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
424
425
|
return '章鱼时间开始:存活人数已降至3人或更少,章鱼存活60秒将获胜;会议已禁用,但虾方任务完成或紧急任务超时仍可先结束本局。';
|
|
425
426
|
case 'emergency_started':
|
|
426
427
|
return `紧急任务:${firstString(event, ['task_name'])}在${firstString(event, ['room'])},${text(event.timeout_secs, '?')}秒内处理。`;
|
|
428
|
+
case 'emergency_countdown_warning':
|
|
429
|
+
return `紧急任务${firstString(event, ['task_name'])}只剩${text(event.remaining_secs, '?')}秒(${text(event.threshold_secs, '?')}秒提醒)。`;
|
|
427
430
|
case 'emergency_resolved':
|
|
428
431
|
if (event.reason === 'meeting_started') {
|
|
429
432
|
return `会议开始,紧急任务${firstString(event, ['task_name'])}已自动解除。`;
|
|
@@ -434,6 +437,12 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
434
437
|
return `紧急任务已解决:${firstString(event, ['task_name'])}。`;
|
|
435
438
|
case 'emergency_interrupted':
|
|
436
439
|
return `${playerLabel(event.actor_name, firstNumber(event, ['actor_seat', 'seat']), ctx)}在处理${firstString(event, ['task_name'])}时死亡,紧急任务仍未解除。`;
|
|
440
|
+
case 'ability.ready':
|
|
441
|
+
return `能力“${firstString(event, ['ability_name', 'ability_id'])}”现在可以使用。`;
|
|
442
|
+
case 'ability.remaining_uses_changed':
|
|
443
|
+
return `能力“${firstString(event, ['ability_name', 'ability_id'])}”剩余${text(event.remaining_uses, '?')}次。`;
|
|
444
|
+
case 'ability.exhausted':
|
|
445
|
+
return `能力“${firstString(event, ['ability_name', 'ability_id'])}”已无剩余次数。`;
|
|
437
446
|
case 'meeting_briefing': {
|
|
438
447
|
const callerName = firstString(event, ['meeting_caller_name', 'caller', 'actor_name']);
|
|
439
448
|
const caller = playerLabel(callerName, firstNumber(event, ['meeting_caller_seat', 'caller_seat', 'actor_seat']), ctx);
|
|
@@ -819,6 +828,23 @@ export function compactEventFields(
|
|
|
819
828
|
});
|
|
820
829
|
}
|
|
821
830
|
|
|
831
|
+
function compactEmergencyState(summary: Record<string, any>): Record<string, any> | undefined {
|
|
832
|
+
const emergency = summary.emergency
|
|
833
|
+
&& typeof summary.emergency === 'object'
|
|
834
|
+
&& !Array.isArray(summary.emergency)
|
|
835
|
+
? summary.emergency as Record<string, any>
|
|
836
|
+
: null;
|
|
837
|
+
if (!emergency || typeof emergency.active !== 'boolean') return undefined;
|
|
838
|
+
return cleanObject({
|
|
839
|
+
active: emergency.active,
|
|
840
|
+
task_name: stringValue(emergency.task_name),
|
|
841
|
+
room: stringValue(emergency.room),
|
|
842
|
+
x: numberValue(emergency.x),
|
|
843
|
+
y: numberValue(emergency.y),
|
|
844
|
+
remaining_secs: numberValue(emergency.remaining_secs),
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
|
|
822
848
|
/** Compact, decision-oriented projection used by realtime Agent adapters. */
|
|
823
849
|
export function compactStateForChannel(
|
|
824
850
|
summary: any | null | undefined,
|
|
@@ -918,6 +944,8 @@ export function compactStateForChannel(
|
|
|
918
944
|
cooldown_remaining_secs: numberValue(crabSabotage.cooldown_remaining_secs),
|
|
919
945
|
})
|
|
920
946
|
: undefined,
|
|
947
|
+
emergency: compactEmergencyState(summary),
|
|
948
|
+
abilities: projectAgentAbilities(summary),
|
|
921
949
|
urgent: summary.urgent,
|
|
922
950
|
automation: summary.automation,
|
|
923
951
|
});
|
|
@@ -1021,6 +1049,8 @@ export function compactStateForEvents(
|
|
|
1021
1049
|
cooldown_remaining_secs: numberValue(crabSabotage.cooldown_remaining_secs),
|
|
1022
1050
|
})
|
|
1023
1051
|
: undefined,
|
|
1052
|
+
emergency: compactEmergencyState(summary),
|
|
1053
|
+
abilities: projectAgentAbilities(summary),
|
|
1024
1054
|
urgent: summary.urgent,
|
|
1025
1055
|
automation: summary.automation,
|
|
1026
1056
|
});
|
|
@@ -1054,7 +1084,7 @@ export function shortStateText(summary: any | null | undefined): string {
|
|
|
1054
1084
|
? summary.players.filter((player: any) => player?.known_status?.is_alive !== false).length
|
|
1055
1085
|
: undefined;
|
|
1056
1086
|
if (aliveCount !== undefined) parts.push(`alive=${aliveCount}`);
|
|
1057
|
-
if (summary.urgent?.emergency_active) parts.push('urgent=emergency');
|
|
1087
|
+
if (summary.emergency?.active === true || summary.urgent?.emergency_active) parts.push('urgent=emergency');
|
|
1058
1088
|
if (summary.urgent?.corpse_nearby) parts.push('urgent=corpse');
|
|
1059
1089
|
return parts.join('; ');
|
|
1060
1090
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export type AgentAbilityId = 'kill' | 'trigger_alarm';
|
|
2
|
+
|
|
3
|
+
export interface AgentAbilityState extends Record<string, unknown> {
|
|
4
|
+
id: AgentAbilityId;
|
|
5
|
+
name: string;
|
|
6
|
+
ready: boolean;
|
|
7
|
+
cooldown_remaining_secs?: number;
|
|
8
|
+
remaining_uses: number | null;
|
|
9
|
+
effective_range_px?: number;
|
|
10
|
+
status?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const KILL_ROLES = new Set([
|
|
14
|
+
'crab_generic',
|
|
15
|
+
'neutral_octopus',
|
|
16
|
+
'shrimp_warrior',
|
|
17
|
+
'shrimp_pistol',
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const LONG_RANGE_KILL_ROLES = new Set([
|
|
21
|
+
'shrimp_warrior',
|
|
22
|
+
'shrimp_pistol',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
function finiteNumber(value: unknown): number | undefined {
|
|
26
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function nonEmptyString(value: unknown): string | undefined {
|
|
30
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Project only the stateful abilities that the current Game State can describe
|
|
35
|
+
* authoritatively. Reporting/body interactions have no independent cooldown or
|
|
36
|
+
* charge state in this contract, so they are intentionally absent.
|
|
37
|
+
*/
|
|
38
|
+
export function projectAgentAbilities(summary: Record<string, any>): AgentAbilityState[] | undefined {
|
|
39
|
+
const you = summary.you && typeof summary.you === 'object' && !Array.isArray(summary.you)
|
|
40
|
+
? summary.you as Record<string, any>
|
|
41
|
+
: null;
|
|
42
|
+
if (!you) return undefined;
|
|
43
|
+
|
|
44
|
+
const role = nonEmptyString(you.role);
|
|
45
|
+
const alive = you.is_alive !== false;
|
|
46
|
+
const actionablePhase = summary.phase === 'wandering';
|
|
47
|
+
const abilities: AgentAbilityState[] = [];
|
|
48
|
+
const killCooldown = finiteNumber(you.kill_cooldown_secs);
|
|
49
|
+
const killsRemaining = finiteNumber(you.kills_remaining);
|
|
50
|
+
if ((role && KILL_ROLES.has(role)) || killCooldown !== undefined || killsRemaining !== undefined) {
|
|
51
|
+
const remainingUses = killsRemaining === undefined ? null : Math.max(0, Math.trunc(killsRemaining));
|
|
52
|
+
abilities.push({
|
|
53
|
+
id: 'kill',
|
|
54
|
+
name: role === 'shrimp_pistol' ? '攻击' : '击杀',
|
|
55
|
+
ready: actionablePhase
|
|
56
|
+
&& alive
|
|
57
|
+
&& killCooldown !== undefined
|
|
58
|
+
&& killCooldown <= 0
|
|
59
|
+
&& remainingUses !== 0,
|
|
60
|
+
...(killCooldown === undefined
|
|
61
|
+
? {}
|
|
62
|
+
: { cooldown_remaining_secs: Math.max(0, killCooldown) }),
|
|
63
|
+
remaining_uses: remainingUses,
|
|
64
|
+
effective_range_px: role && LONG_RANGE_KILL_ROLES.has(role) ? 160 : 80,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const sabotage = summary.crab_sabotage
|
|
69
|
+
&& typeof summary.crab_sabotage === 'object'
|
|
70
|
+
&& !Array.isArray(summary.crab_sabotage)
|
|
71
|
+
? summary.crab_sabotage as Record<string, any>
|
|
72
|
+
: null;
|
|
73
|
+
const sabotageStatus = nonEmptyString(sabotage?.status);
|
|
74
|
+
if (sabotageStatus) {
|
|
75
|
+
const cooldown = finiteNumber(sabotage?.cooldown_remaining_secs);
|
|
76
|
+
abilities.push({
|
|
77
|
+
id: 'trigger_alarm',
|
|
78
|
+
name: '触发警报',
|
|
79
|
+
ready: actionablePhase && alive && sabotageStatus === 'ready',
|
|
80
|
+
...(cooldown === undefined
|
|
81
|
+
? {}
|
|
82
|
+
: { cooldown_remaining_secs: Math.max(0, cooldown) }),
|
|
83
|
+
remaining_uses: null,
|
|
84
|
+
status: sabotageStatus,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return abilities.length > 0 ? abilities : undefined;
|
|
89
|
+
}
|
|
@@ -19,6 +19,10 @@ describe('ClawClaw Monitor Event policy', () => {
|
|
|
19
19
|
'kill',
|
|
20
20
|
'killed',
|
|
21
21
|
'murder_witnessed',
|
|
22
|
+
'emergency_countdown_warning',
|
|
23
|
+
'ability.ready',
|
|
24
|
+
'ability.remaining_uses_changed',
|
|
25
|
+
'ability.exhausted',
|
|
22
26
|
'behavior.completed',
|
|
23
27
|
'behavior.failed',
|
|
24
28
|
'behavior.cancelled',
|