@myclaw163/clawclaw-cli 0.10.17 → 0.10.19
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/cli-runtime/commands/behavior.js +7 -0
- package/cli-runtime/commands/prepare.js +17 -15
- package/cli-runtime/lib/agent-workspace-runtime.js +37 -15
- package/cli-runtime/lib/user-data.js +3 -1
- package/cli-runtime/runtime/clawclaw/behavior-start-control.js +4 -2
- package/cli-runtime/runtime/clawclaw/behavior-trigger.js +17 -1
- package/cli-runtime/runtime/clawclaw/owner.js +12 -4
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-catalog.js +6 -0
- package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-plugin.js +49 -4
- package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +27 -2
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/sdk-sdk.js +1 -0
- package/docs/custom-modules/README.md +1 -1
- package/docs/custom-modules/api-reference.md +2 -2
- package/docs/custom-modules/behavior.md +6 -4
- package/docs/user-guide/README.md +1 -1
- package/docs/user-guide/api-reference.md +2 -2
- package/docs/user-guide/behavior.md +6 -4
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +2 -2
- package/skills/clawclaw/references/BEHAVIORS.md +2 -0
- package/skills/clawclaw-creator/SKILL.md +1 -1
- package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +6 -4
- package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +2 -2
- package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +1 -1
- package/src/commands/behavior.ts +7 -0
- package/src/commands/prepare.ts +16 -17
- package/src/lib/agent-workspace-runtime.ts +41 -25
- package/src/lib/user-data.ts +4 -1
- package/src/runtime/clawclaw/behavior-start-control.ts +3 -1
- package/src/runtime/clawclaw/behavior-trigger.ts +21 -1
- package/src/runtime/clawclaw/owner.ts +9 -4
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +8 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +60 -7
- package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +31 -4
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
## 长期、短期和反射
|
|
13
13
|
|
|
14
|
-
所有策略都继承 `ClawclawStrategy
|
|
14
|
+
所有策略都继承 `ClawclawStrategy`。每次启动时,CCL 会为策略分配一个运行层。
|
|
15
15
|
|
|
16
16
|
| 运行方式 | 代码值 | 用途 | 启动入口 |
|
|
17
17
|
|---|---|---|---|
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
|
|
22
22
|
控制优先级固定为 **反射 > 短期 > 长期**。例如:长期做任务 → 短期报尸,暂停做任务 → 反射撤离,暂停报尸 → 撤离结束后恢复仍有效的报尸 → 报尸结束后再恢复长期任务。
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
普通策略可以用 `ccl strategy start` 启动为 long 或 short。**同一文件具名导出 `Trigger` 的策略仅自动触发**。例如,撤离策略只会在同文件的感知发现玩家靠近并请求撤离后,参与 reflex 层的优先级仲裁。CCL 从文件导出识别规则,作者无需添加配置项。
|
|
25
|
+
|
|
26
|
+
`ccl strategy list` 和 `info` 用 `activation_mode: automatic_only` 标识这类策略。手动启动(包括会议期间排队)、其他策略的 `delegate` 和角色默认策略都只能选普通策略。
|
|
25
27
|
|
|
26
28
|
`long` 不要求永不结束,`short` 和 `reflex` 也不会自动知道业务目标何时完成。模块应在确认目标完成或失败后返回 `finish`;运行时限用于防止有限任务长期占用控制权。
|
|
27
29
|
|
|
@@ -101,7 +103,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
|
|
|
101
103
|
|
|
102
104
|
## 单文件反射与局中控制
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
|
|
105
107
|
|
|
106
108
|
```ts
|
|
107
109
|
import {
|
|
@@ -181,7 +183,7 @@ ccl strategy unwatch community.auto-escape
|
|
|
181
183
|
|
|
182
184
|
装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
|
|
183
185
|
|
|
184
|
-
`strategy update`
|
|
186
|
+
`strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。触发感知可以在命中时传入本次反射的目标,覆盖对应的本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
|
|
185
187
|
|
|
186
188
|
跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
|
|
187
189
|
|
package/package.json
CHANGED
package/skills/clawclaw/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clawclaw
|
|
3
3
|
description: ClawClaw/龙虾杀的完整玩法 Skill,仅在游戏事件流接通后读取。开局或恢复连接之前不要读取本 Skill,此阶段只读取 clawclaw-start。start/join 成功接流后立即调用本 Skill,不必等待匹配完成或身份分配。用于处理实时游戏事件、角色行动、策略、会议发言与投票、结算和复盘。资源创作使用 clawclaw-creator。
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.136
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀完整玩法(接流后调用)
|
|
@@ -155,7 +155,7 @@ ccl strategy idle 500
|
|
|
155
155
|
ccl aside "<仅用户/观战玩家可见的推理>"
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
-
用户要求检查或管理 Strategy 时,先用 `ccl strategy list` 取得当前目录,再对返回的纯本地条目使用 `info/disable/enable`;Hub enablement 由 Hub loadout 管理。list/info 只做静态 manifest 检查,绝不 import 或执行第三方源码。启用变更和源码/manifest 修改从下一次 Runtime
|
|
158
|
+
用户要求检查或管理 Strategy 时,先用 `ccl strategy list` 取得当前目录,再对返回的纯本地条目使用 `info/disable/enable`;Hub enablement 由 Hub loadout 管理。list/info 只做静态 manifest 检查,绝不 import 或执行第三方源码。启用变更和源码/manifest 修改从下一次 Runtime 起生效。`list/info` 中 `activation_mode: automatic_only` 表示仅由同文件的感知自动触发。这类策略用 `watch/unwatch` 开关自动反射,用 `update` 调参。手动启动普通策略使用 `ccl strategy start <id> --layer short|long --input '<JSON object>'`。同层一次只有一个 Activation:新 short 替换旧 short,新 long 替换旧 long;`accepted` 不等于完成。
|
|
159
159
|
|
|
160
160
|
### 3.5 游走阶段
|
|
161
161
|
|
|
@@ -62,6 +62,8 @@ ccl strategy info <behavior-id-from-list>
|
|
|
62
62
|
ccl strategy start <behavior-id-from-list> --layer short --input '<JSON object from info.inputs>'
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
请先查看 `ccl strategy info <id>` 的 `activation_mode`。`automatic_only` 仅允许同文件的感知触发,手动启动、委派和角色默认策略都应选择 `standard`。
|
|
66
|
+
|
|
65
67
|
会议中手动启动短策略时,`status: queued` 表示已选中并等待游荡。CCL 上报选中的策略名和描述,回到游荡才实际启动并计算运行时限。用 `ccl strategy status` 查看 `pending_short`,用 `ccl strategy cancel <request_id>` 取消。同一局的后续短策略请求替换待执行项。
|
|
66
68
|
|
|
67
69
|
启动输出的 `accepted` 只表示 Owner 接受请求,不表示行动成功。一个 short 运行时:
|
|
@@ -22,7 +22,7 @@ metadata:
|
|
|
22
22
|
| 教 Agent 分析、组织发言或执行一套流程 | Skill | [游戏 Skill](references/CUSTOM-SKILL-DEVELOPMENT.md) |
|
|
23
23
|
| 玩家声音、性格和表达风格 | 人设 | [人设 Markdown](references/CUSTOM-PERSONA-DEVELOPMENT.md) |
|
|
24
24
|
|
|
25
|
-
精确字段与签名查 [API 参考](references/CUSTOM-MODULE-API.md),不要一次加载所有教程。自动反射在同一个策略文件中添加继承 ClawclawPerception 的具名 Trigger
|
|
25
|
+
精确字段与签名查 [API 参考](references/CUSTOM-MODULE-API.md),不要一次加载所有教程。自动反射在同一个策略文件中添加继承 ClawclawPerception 的具名 Trigger,装配这一个 Strategy 资源后,只能由该感知请求启动策略。只需要修改当前局参数时,按现有模块的 manifest 使用 `ccl strategy update` / `ccl perception update`,不用新建源码。
|
|
26
26
|
|
|
27
27
|
## 2. 同步编辑基线,定位当前账号和原文件
|
|
28
28
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
## 长期、短期和反射
|
|
13
13
|
|
|
14
|
-
所有策略都继承 `ClawclawStrategy
|
|
14
|
+
所有策略都继承 `ClawclawStrategy`。每次启动时,CCL 会为策略分配一个运行层。
|
|
15
15
|
|
|
16
16
|
| 运行方式 | 代码值 | 用途 | 启动入口 |
|
|
17
17
|
|---|---|---|---|
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
|
|
22
22
|
控制优先级固定为 **反射 > 短期 > 长期**。例如:长期做任务 → 短期报尸,暂停做任务 → 反射撤离,暂停报尸 → 撤离结束后恢复仍有效的报尸 → 报尸结束后再恢复长期任务。
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
普通策略可以用 `ccl strategy start` 启动为 long 或 short。**同一文件具名导出 `Trigger` 的策略仅自动触发**。例如,撤离策略只会在同文件的感知发现玩家靠近并请求撤离后,参与 reflex 层的优先级仲裁。CCL 从文件导出识别规则,作者无需添加配置项。
|
|
25
|
+
|
|
26
|
+
`ccl strategy list` 和 `info` 用 `activation_mode: automatic_only` 标识这类策略。手动启动(包括会议期间排队)、其他策略的 `delegate` 和角色默认策略都只能选普通策略。
|
|
25
27
|
|
|
26
28
|
`long` 不要求永不结束,`short` 和 `reflex` 也不会自动知道业务目标何时完成。模块应在确认目标完成或失败后返回 `finish`;运行时限用于防止有限任务长期占用控制权。
|
|
27
29
|
|
|
@@ -101,7 +103,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
|
|
|
101
103
|
|
|
102
104
|
## 单文件反射与局中控制
|
|
103
105
|
|
|
104
|
-
|
|
106
|
+
一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
|
|
105
107
|
|
|
106
108
|
```ts
|
|
107
109
|
import {
|
|
@@ -181,7 +183,7 @@ ccl strategy unwatch community.auto-escape
|
|
|
181
183
|
|
|
182
184
|
装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
|
|
183
185
|
|
|
184
|
-
`strategy update`
|
|
186
|
+
`strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。触发感知可以在命中时传入本次反射的目标,覆盖对应的本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
|
|
185
187
|
|
|
186
188
|
跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
|
|
187
189
|
|
|
@@ -404,7 +404,7 @@ interface StrategyDelegation {
|
|
|
404
404
|
}
|
|
405
405
|
```
|
|
406
406
|
|
|
407
|
-
|
|
407
|
+
当前 long Activation 可以用 `delegate` 将普通策略启动为 short。Runtime 会先通过 Strategy Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
|
|
408
408
|
|
|
409
409
|
#### `StrategyFinish`
|
|
410
410
|
|
|
@@ -685,7 +685,7 @@ import type {
|
|
|
685
685
|
|
|
686
686
|
## 策略内置触发感知
|
|
687
687
|
|
|
688
|
-
|
|
688
|
+
策略文件具名导出继承 `ClawclawPerception` 的 `Trigger` 后,只有这份感知可以请求启动本策略。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
|
|
689
689
|
|
|
690
690
|
`evaluate(input, api)` 接收 `PerceptionModuleInput`,通过 `input.frame`、`input.events`、`input.config` 和 `input.state` 读取观察、事实、配置和上次返回的私有状态。返回 `PerceptionModuleResult`,可含 `state`、`events` 和 `activations`。例如 `{ activations: [{ strategy: 'escape', input: { x: 2708, y: 2320 }, reason: 'player_nearby' }] }` 使用清单里的 `escape` 绑定,激活参数覆盖策略默认值。
|
|
691
691
|
|
|
@@ -75,7 +75,7 @@ flowchart LR
|
|
|
75
75
|
| `short` | 暂时完成一件有限工作 |
|
|
76
76
|
| `reflex` | 策略内置 Trigger 条件命中后请求优先执行即时反应 |
|
|
77
77
|
|
|
78
|
-
三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long
|
|
78
|
+
三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long`。普通策略可以手动启动为 long/short。带具名 `Trigger` 的策略仅由同文件的感知自动触发。角色默认策略从普通策略中选择。具体启动、暂停恢复与会议边界见[策略教程](./CUSTOM-BEHAVIOR-DEVELOPMENT.md#长期短期和反射)。
|
|
79
79
|
|
|
80
80
|
## 一个模块文件由什么组成
|
|
81
81
|
|
package/src/commands/behavior.ts
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
classifyStrategyLifecycle,
|
|
43
43
|
readCapabilityWorkspaceRegistry,
|
|
44
44
|
} from '../lib/capability-workspace.js';
|
|
45
|
+
import { strategyActivationError, strategyActivationMode } from '../runtime/clawclaw/behavior-trigger.js';
|
|
45
46
|
import { readFileSync } from 'node:fs';
|
|
46
47
|
import { selectCapability } from '../lib/capability-selection.js';
|
|
47
48
|
import { renameCapabilityOperationWhenIdle } from '../lib/capability-operation-rename.js';
|
|
@@ -130,6 +131,8 @@ function sourceEntry(
|
|
|
130
131
|
inputs: source.inputs,
|
|
131
132
|
produces: source.produces ?? [],
|
|
132
133
|
...(source.runtime === undefined ? {} : { runtime: source.runtime }),
|
|
134
|
+
activation_mode: strategyActivationMode(source),
|
|
135
|
+
...(source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {}),
|
|
133
136
|
strategy_type: classifyStrategyLifecycle(readFileSync(source.sourcePath, 'utf8')),
|
|
134
137
|
source: source.management.source,
|
|
135
138
|
managed_by: source.management.managedBy,
|
|
@@ -386,6 +389,8 @@ function createStrategyControlCommand(commandName: 'behavior' | 'strategy', depe
|
|
|
386
389
|
if (!hub && gameplay.disabled_behaviors.includes(id)) {
|
|
387
390
|
throw new Error(`Behavior '${id}' is disabled in user-data/gameplay.json.`);
|
|
388
391
|
}
|
|
392
|
+
const error = strategyActivationError(source);
|
|
393
|
+
if (error) throw new Error(`${id}: ${error}. 该策略仅自动触发,由同文件的感知请求启动。`);
|
|
389
394
|
await runOwnerCommand(`ccl ${commandName} start`, 'behavior_start', {
|
|
390
395
|
behavior: id,
|
|
391
396
|
layer: opts.layer,
|
|
@@ -448,6 +453,8 @@ function createStrategyControlCommand(commandName: 'behavior' | 'strategy', depe
|
|
|
448
453
|
if (entry.loadable !== true || (!hub && gameplay.disabled_behaviors.includes(id))) {
|
|
449
454
|
throw new Error(`Behavior '${id}' is not enabled and loadable.`);
|
|
450
455
|
}
|
|
456
|
+
const error = strategyActivationError(source);
|
|
457
|
+
if (error) throw new Error(`${id}: ${error}. 该策略仅自动触发,请选择普通策略作为角色默认策略。`);
|
|
451
458
|
const updated = updateGameplayConfig((current) => {
|
|
452
459
|
current.fallback_behaviors[role] = id;
|
|
453
460
|
}, workspaceDir, profile);
|
package/src/commands/prepare.ts
CHANGED
|
@@ -34,6 +34,7 @@ import { BEHAVIOR_PLUGIN_API_VERSION } from '../sdk/behavior-plugin/index.js';
|
|
|
34
34
|
import { TRIGGER_PLUGIN_API_VERSION } from '../sdk/trigger-plugin/index.js';
|
|
35
35
|
import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js';
|
|
36
36
|
import { expectedPerceptionApiVersion, isSupportedPerceptionSource } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
37
|
+
import { strategyActivationMode } from '../runtime/clawclaw/behavior-trigger.js';
|
|
37
38
|
import { resolveReactionBehavior } from '../runtime/clawclaw/reaction-behavior-resolution.js';
|
|
38
39
|
import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
|
|
39
40
|
import {
|
|
@@ -405,19 +406,19 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
|
|
|
405
406
|
...(operationName ? { id: operationName } : {}) });
|
|
406
407
|
}
|
|
407
408
|
if (activeWorkspace) {
|
|
408
|
-
const
|
|
409
|
+
const discoveredResources = new Set(hubBehaviors.map(source => source.management.resourceId));
|
|
409
410
|
for (const item of activeWorkspace.items.strategy) {
|
|
410
411
|
if (!item.runtimeEntryPath) {
|
|
411
412
|
capabilityWarnings.push(missingProjectionWarning('behavior', item));
|
|
412
413
|
continue;
|
|
413
414
|
}
|
|
415
|
+
if (discoveredResources.has(item.resourceId)) continue;
|
|
414
416
|
const path = resolveLocalAgentWorkspacePath(
|
|
415
417
|
workspaceDir,
|
|
416
418
|
profile,
|
|
417
419
|
activeWorkspace,
|
|
418
420
|
item.runtimeEntryPath,
|
|
419
421
|
);
|
|
420
|
-
if (discoveredPaths.has(resolve(path))) continue;
|
|
421
422
|
capabilityWarnings.push(warningFromStaticDiagnostic(
|
|
422
423
|
'behavior',
|
|
423
424
|
'hub',
|
|
@@ -442,6 +443,7 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
|
|
|
442
443
|
api_version: source.apiVersion ?? null,
|
|
443
444
|
expected_api_version: BEHAVIOR_PLUGIN_API_VERSION,
|
|
444
445
|
loadable,
|
|
446
|
+
activation_mode: strategyActivationMode(source),
|
|
445
447
|
...(loadable ? {} : {
|
|
446
448
|
compatibility_error: versionCompatible
|
|
447
449
|
? compatibilityError
|
|
@@ -502,12 +504,14 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
|
|
|
502
504
|
for (const role of CLAWCLAW_ROLE_IDS) {
|
|
503
505
|
const fallback = gameplay.fallback_behaviors[role];
|
|
504
506
|
if (fallback === null) continue;
|
|
505
|
-
|
|
507
|
+
const entry = behaviors.find(({ id }) => id === fallback);
|
|
508
|
+
if (!entry || entry.activation_mode === 'automatic_only') {
|
|
509
|
+
const unavailableReason = disabledBehaviors.has(fallback) ? 'local_disabled_or_unselected' : 'not_loaded';
|
|
506
510
|
configurationWarnings.push({
|
|
507
511
|
code: 'DEFAULT_LONG_BEHAVIOR_UNAVAILABLE',
|
|
508
512
|
role,
|
|
509
513
|
behavior_id: fallback,
|
|
510
|
-
reason:
|
|
514
|
+
reason: entry ? 'strategy_automatic_only' : unavailableReason,
|
|
511
515
|
});
|
|
512
516
|
}
|
|
513
517
|
}
|
|
@@ -517,15 +521,7 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
|
|
|
517
521
|
: [];
|
|
518
522
|
if (activeWorkspace) {
|
|
519
523
|
for (const source of hubPerceptions) {
|
|
520
|
-
const item = activeWorkspace.items.perception.find(
|
|
521
|
-
!!candidate.runtimeEntryPath
|
|
522
|
-
&& resolveLocalAgentWorkspacePath(
|
|
523
|
-
workspaceDir,
|
|
524
|
-
profile,
|
|
525
|
-
activeWorkspace!,
|
|
526
|
-
candidate.runtimeEntryPath,
|
|
527
|
-
) === source.sourcePath
|
|
528
|
-
));
|
|
524
|
+
const item = activeWorkspace.items.perception.find(candidate => candidate.resourceId === source.resourceId);
|
|
529
525
|
const workingPath = item
|
|
530
526
|
? resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item)
|
|
531
527
|
: undefined;
|
|
@@ -573,19 +569,19 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
|
|
|
573
569
|
...(operationName ? { id: operationName } : {}) });
|
|
574
570
|
}
|
|
575
571
|
if (activeWorkspace) {
|
|
576
|
-
const
|
|
572
|
+
const discoveredResources = new Set(hubPerceptions.map(source => source.resourceId));
|
|
577
573
|
for (const item of activeWorkspace.items.perception) {
|
|
578
574
|
if (!item.runtimeEntryPath) {
|
|
579
575
|
capabilityWarnings.push(missingProjectionWarning('perception', item));
|
|
580
576
|
continue;
|
|
581
577
|
}
|
|
578
|
+
if (discoveredResources.has(item.resourceId)) continue;
|
|
582
579
|
const path = resolveLocalAgentWorkspacePath(
|
|
583
580
|
workspaceDir,
|
|
584
581
|
profile,
|
|
585
582
|
activeWorkspace,
|
|
586
583
|
item.runtimeEntryPath,
|
|
587
584
|
);
|
|
588
|
-
if (discoveredPaths.has(resolve(path))) continue;
|
|
589
585
|
capabilityWarnings.push(warningFromStaticDiagnostic(
|
|
590
586
|
'perception',
|
|
591
587
|
'hub',
|
|
@@ -619,9 +615,11 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
|
|
|
619
615
|
if (!id) configurationWarnings.push({ code: 'PERCEPTION_BEHAVIOR_NOT_LOADED',
|
|
620
616
|
perception_id: source.id, binding: key, behavior_name: binding.name,
|
|
621
617
|
message: `Equip the paired strategy ${binding.name}; perception observation and notifications remain available.` });
|
|
618
|
+
const target = behaviors.find(entry => entry.id === id);
|
|
619
|
+
const available = !!target && target.activation_mode !== 'automatic_only';
|
|
622
620
|
return { perception_id: source.id, binding: key, behavior_id: id ?? binding.name,
|
|
623
|
-
available
|
|
624
|
-
...(
|
|
621
|
+
available, default_enabled: available,
|
|
622
|
+
...(available ? {} : { reason: target ? 'strategy_automatic_only' : 'behavior_not_loaded' }) };
|
|
625
623
|
}));
|
|
626
624
|
const perceptionEntry = (source: typeof enabledPerceptions[number]) => ({
|
|
627
625
|
id: source.id,
|
|
@@ -954,6 +952,7 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
|
|
|
954
952
|
name: localized.name,
|
|
955
953
|
description: source.description,
|
|
956
954
|
source: entry.source,
|
|
955
|
+
activation_mode: entry.activation_mode,
|
|
957
956
|
strategy_type: strategyLifecycle(source.sourcePath),
|
|
958
957
|
...(source.trigger ? { reflex: { available: true } }
|
|
959
958
|
: source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {}),
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
-
import { join,
|
|
2
|
+
import { join, basename } from 'node:path';
|
|
3
3
|
import type { AuthProfile } from './auth.js';
|
|
4
4
|
import {
|
|
5
5
|
localAgentWorkspaceSnapshotRoot,
|
|
6
6
|
readLocalAgentWorkspaceSnapshot,
|
|
7
7
|
resolveLocalAgentWorkspacePath,
|
|
8
8
|
resolveLocalAgentWorkspaceWorkingCopyPath,
|
|
9
|
+
type LocalAgentWorkspaceItem,
|
|
9
10
|
type LocalAgentWorkspaceSnapshot,
|
|
10
11
|
} from './agent-workspace-sync.js';
|
|
11
12
|
import { registerDiscoveredCapability } from './capability-workspace.js';
|
|
@@ -28,6 +29,36 @@ function currentSnapshot(
|
|
|
28
29
|
return snapshot ?? readLocalAgentWorkspaceSnapshot(workspaceDir, profile);
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
function existingFilePath(path: string): string | undefined {
|
|
33
|
+
try {
|
|
34
|
+
return realpathSync.native(path);
|
|
35
|
+
} catch {
|
|
36
|
+
// An unavailable projection stays undiscovered so prepare can report its diagnostic.
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function matchHubProjections<T extends { readonly sourcePath: string }>(
|
|
42
|
+
workspaceDir: string,
|
|
43
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
44
|
+
snapshot: LocalAgentWorkspaceSnapshot,
|
|
45
|
+
items: readonly LocalAgentWorkspaceItem[],
|
|
46
|
+
sources: readonly T[],
|
|
47
|
+
): { source: T; item: LocalAgentWorkspaceItem }[] {
|
|
48
|
+
const itemsByPath = new Map<string, LocalAgentWorkspaceItem>();
|
|
49
|
+
for (const item of items) {
|
|
50
|
+
if (!item.runtimeEntryPath) continue;
|
|
51
|
+
const projection = resolveLocalAgentWorkspacePath(workspaceDir, profile, snapshot, item.runtimeEntryPath);
|
|
52
|
+
const path = existingFilePath(projection);
|
|
53
|
+
if (path !== undefined) itemsByPath.set(path, item);
|
|
54
|
+
}
|
|
55
|
+
return sources.flatMap(source => {
|
|
56
|
+
const path = existingFilePath(source.sourcePath);
|
|
57
|
+
const item = path === undefined ? undefined : itemsByPath.get(path);
|
|
58
|
+
return item ? [{ source, item }] : [];
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
31
62
|
function assertUniqueBehaviorIds(
|
|
32
63
|
sources: readonly ResolvedClawclawBehaviorSource[],
|
|
33
64
|
origin: 'local' | 'hub',
|
|
@@ -69,22 +100,10 @@ export function listAgentWorkspaceBehaviorSources(
|
|
|
69
100
|
if (!active || active.items.strategy.length === 0) return [];
|
|
70
101
|
const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), 'runtime', 'behaviors');
|
|
71
102
|
if (!existsSync(root)) return [];
|
|
72
|
-
const
|
|
73
|
-
active.items.strategy
|
|
74
|
-
item.runtimeEntryPath
|
|
75
|
-
? [[realpathSync(resolveLocalAgentWorkspacePath(
|
|
76
|
-
workspaceDir,
|
|
77
|
-
profile,
|
|
78
|
-
active,
|
|
79
|
-
item.runtimeEntryPath,
|
|
80
|
-
)), item] as const]
|
|
81
|
-
: []
|
|
82
|
-
)),
|
|
103
|
+
const projections = matchHubProjections(
|
|
104
|
+
workspaceDir, profile, active, active.items.strategy, listClawclawBehaviorSources(root),
|
|
83
105
|
);
|
|
84
|
-
const sources =
|
|
85
|
-
.filter(source => itemByPath.has(realpathSync(source.sourcePath))).map((source) => {
|
|
86
|
-
const item = itemByPath.get(realpathSync(source.sourcePath));
|
|
87
|
-
if (!item) throw new Error(`agent_workspace_behavior_metadata_missing:${source.id}`);
|
|
106
|
+
const sources = projections.map(({ source, item }) => {
|
|
88
107
|
const trusted = item.sourceFiles[0]
|
|
89
108
|
&& item.resolution !== 'local_modified'
|
|
90
109
|
&& item.resolution !== 'concurrent_difference'
|
|
@@ -132,17 +151,14 @@ export function listAgentWorkspacePerceptionSources(
|
|
|
132
151
|
workspaceDir: string,
|
|
133
152
|
profile: Pick<AuthProfile, 'apiKey'>,
|
|
134
153
|
snapshot?: LocalAgentWorkspaceSnapshot,
|
|
135
|
-
): readonly ResolvedClawclawPerceptionSource[] {
|
|
154
|
+
): readonly (ResolvedClawclawPerceptionSource & { readonly resourceId: string })[] {
|
|
136
155
|
const active = currentSnapshot(workspaceDir, profile, snapshot);
|
|
137
156
|
if (!active || active.items.perception.length === 0) return [];
|
|
138
157
|
const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), 'runtime', 'perceptions');
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const namedSources = sources.map(source => {
|
|
144
|
-
const item = active.items.perception.find(item => item.runtimeEntryPath
|
|
145
|
-
&& resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item.runtimeEntryPath) === source.sourcePath)!;
|
|
158
|
+
const projections = matchHubProjections(
|
|
159
|
+
workspaceDir, profile, active, active.items.perception, listClawclawPerceptionSourcesInDirectory(root),
|
|
160
|
+
);
|
|
161
|
+
const namedSources = projections.map(({ source, item }) => {
|
|
146
162
|
const workingCopyPath = resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item)
|
|
147
163
|
?? join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'perceptions', item.resourceId,
|
|
148
164
|
item.sourceFiles[0]?.relativePath ?? basename(source.sourcePath));
|
|
@@ -156,7 +172,7 @@ export function listAgentWorkspacePerceptionSources(
|
|
|
156
172
|
...(item.forkReconciliation?.status === 'unresolved' ? { forkRelationshipUnresolved: true } : {}),
|
|
157
173
|
publisher: item.hub?.publisher ?? 'community', baseSha256: item.sourceFiles[0]?.sha256 },
|
|
158
174
|
});
|
|
159
|
-
return perceptionOperationName({ ...source, workingCopyPath }, entry);
|
|
175
|
+
return perceptionOperationName({ ...source, workingCopyPath, resourceId: item.resourceId }, entry);
|
|
160
176
|
});
|
|
161
177
|
const ids = new Set<string>();
|
|
162
178
|
for (const source of namedSources) {
|
package/src/lib/user-data.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
mkdirSync,
|
|
6
6
|
readdirSync,
|
|
7
7
|
readFileSync,
|
|
8
|
+
realpathSync,
|
|
8
9
|
writeFileSync,
|
|
9
10
|
} from 'fs';
|
|
10
11
|
import { createHash } from 'crypto';
|
|
@@ -75,7 +76,9 @@ export function getUserDataAgentWorkspaceDir(
|
|
|
75
76
|
workspaceDir: string,
|
|
76
77
|
profile: Pick<AuthProfile, 'apiKey'>,
|
|
77
78
|
): string {
|
|
78
|
-
|
|
79
|
+
const directory = join(getUserDataAccountDir(workspaceDir, profile), 'hub-loadout');
|
|
80
|
+
// Staging and validating an update must use the same directory the module scanner sees.
|
|
81
|
+
return existsSync(directory) ? realpathSync(directory) : directory;
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
export function getUserDataAgentWorkspaceCurrentFile(
|
|
@@ -99,13 +99,15 @@ export class DeferredMeetingShortStrategy {
|
|
|
99
99
|
|
|
100
100
|
constructor(
|
|
101
101
|
private readonly runtime: DeferredStartRuntime,
|
|
102
|
-
private readonly behavior: BehaviorStarter & Pick<ClawclawBehaviorPlugin, 'cancel'>,
|
|
102
|
+
private readonly behavior: BehaviorStarter & Pick<ClawclawBehaviorPlugin, 'cancel' | 'startError'>,
|
|
103
103
|
private readonly resolveDisplay: (request: BehaviorStartRequest) => ClawclawResolvedResourceMetadata | undefined,
|
|
104
104
|
) {}
|
|
105
105
|
|
|
106
106
|
async start(request: BehaviorStartRequest): Promise<OwnerControlResponse> {
|
|
107
107
|
const rejection = startRejection(this.runtime, request);
|
|
108
108
|
if (rejection) return rejection;
|
|
109
|
+
const error = this.behavior.startError(request.behavior);
|
|
110
|
+
if (error) return { ok: false, type: 'behavior_start', error };
|
|
109
111
|
if (request.layer !== 'short') return startOwnerBehavior(this.runtime, this.behavior, request);
|
|
110
112
|
const version = ++this.requestVersion;
|
|
111
113
|
const inMeeting = () => this.runtime.readState().state?.phase === 'meeting';
|
|
@@ -2,6 +2,26 @@ import { normalizePerceptionModuleManifest } from './perception-module-manifest.
|
|
|
2
2
|
import type { ResolvedClawclawBehaviorSource } from './plugins/behavior/behavior-source.js';
|
|
3
3
|
import type { ResolvedClawclawPerceptionSource } from './plugins/perception/perception-source.js';
|
|
4
4
|
|
|
5
|
+
type TriggerDeclaration = Pick<ResolvedClawclawBehaviorSource, 'trigger' | 'triggerError'>;
|
|
6
|
+
|
|
7
|
+
export function strategyActivationMode(source: TriggerDeclaration) {
|
|
8
|
+
return source.trigger || source.triggerError ? 'automatic_only' : 'standard';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function strategyActivationError(source: ResolvedClawclawBehaviorSource,
|
|
12
|
+
request?: Readonly<{ source: string; triggerId: string }>): string | undefined {
|
|
13
|
+
if (source.triggerError) return source.triggerError;
|
|
14
|
+
if (!source.trigger) return undefined;
|
|
15
|
+
if (request?.source === 'perception' && Object.keys(source.trigger.manifest.behaviors ?? {}).some(
|
|
16
|
+
key => request.triggerId === `perception:${strategyPerceptionId(source.id)}:${key}`,
|
|
17
|
+
)) return undefined;
|
|
18
|
+
return 'strategy_automatic_only';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function strategyPerceptionId(strategyId: string): string {
|
|
22
|
+
return 'strategy:' + strategyId;
|
|
23
|
+
}
|
|
24
|
+
|
|
5
25
|
export function normalizeStrategyPerception(value: unknown, strategyId: string) {
|
|
6
26
|
const manifest = normalizePerceptionModuleManifest(value);
|
|
7
27
|
const bindings = Object.values(manifest.behaviors ?? {});
|
|
@@ -15,7 +35,7 @@ export function normalizeStrategyPerception(value: unknown, strategyId: string)
|
|
|
15
35
|
export function strategyTriggerSource(source: ResolvedClawclawBehaviorSource): ResolvedClawclawPerceptionSource | undefined {
|
|
16
36
|
if (!source.trigger) return undefined;
|
|
17
37
|
const { manifest, sha256 } = source.trigger;
|
|
18
|
-
const id =
|
|
38
|
+
const id = strategyPerceptionId(source.id);
|
|
19
39
|
const name = manifest.name ?? manifest.id;
|
|
20
40
|
const behaviors = Object.fromEntries(Object.entries(manifest.behaviors!).map(([key, binding]) =>
|
|
21
41
|
[key, { ...binding, name: source.id }]));
|
|
@@ -280,13 +280,15 @@ export function roleFallbackBehaviors(
|
|
|
280
280
|
catalog: Pick<ClawclawBehaviorCatalog, 'list'>,
|
|
281
281
|
warning: ConfigurationWarning = () => {},
|
|
282
282
|
): ClawclawRoleFallbackBehaviors {
|
|
283
|
-
const
|
|
283
|
+
const entries = new Map(catalog.list().map(entry => [entry.id, entry]));
|
|
284
284
|
const result: Record<string, { behaviorId: string; input: Record<string, never> } | undefined> = {};
|
|
285
285
|
for (const role of CLAWCLAW_ROLE_IDS) {
|
|
286
286
|
const behaviorId = config.fallback_behaviors[role];
|
|
287
287
|
if (behaviorId === null) continue;
|
|
288
|
-
|
|
289
|
-
|
|
288
|
+
const entry = entries.get(behaviorId);
|
|
289
|
+
if (!entry?.loadable || entry.activationMode === 'automatic_only') {
|
|
290
|
+
warning('behavior_fallback_unavailable', { role, behavior_id: behaviorId,
|
|
291
|
+
...(entry?.activationMode === 'automatic_only' ? { reason: 'strategy_automatic_only' } : {}) });
|
|
290
292
|
continue;
|
|
291
293
|
}
|
|
292
294
|
result[role] = { behaviorId, input: {} };
|
|
@@ -1312,6 +1314,9 @@ export async function runClawclawOwner(
|
|
|
1312
1314
|
return { ok: false, type: 'behavior_fallback', error: 'stale_runtime_scope' };
|
|
1313
1315
|
}
|
|
1314
1316
|
const latest = readGameplayConfig(workspaceDir, options.profile);
|
|
1317
|
+
const selected = latest.fallback_behaviors[role as keyof typeof latest.fallback_behaviors];
|
|
1318
|
+
const error = request.action === 'set' && selected && behaviorCatalog.activationError(selected);
|
|
1319
|
+
if (error) return { ok: false, type: 'behavior_fallback', error };
|
|
1315
1320
|
const currentRole = readyRoleForScope(runtime!, expected);
|
|
1316
1321
|
if (currentRole === role) {
|
|
1317
1322
|
await assembly.behavior.noteAgentActivity();
|
|
@@ -1325,7 +1330,7 @@ export async function runClawclawOwner(
|
|
|
1325
1330
|
ok: true,
|
|
1326
1331
|
type: 'behavior_fallback',
|
|
1327
1332
|
role,
|
|
1328
|
-
fallback:
|
|
1333
|
+
fallback: selected,
|
|
1329
1334
|
};
|
|
1330
1335
|
}
|
|
1331
1336
|
if (request.type === 'behavior_idle') {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from './behavior-source.js';
|
|
14
14
|
import { prepareBehaviorInWorker } from './thread-behavior-executor.js';
|
|
15
15
|
import { deepFreezeBehaviorValue } from './behavior-manifest.js';
|
|
16
|
+
import { strategyActivationError, strategyActivationMode } from '../../behavior-trigger.js';
|
|
16
17
|
import { normalizeBehaviorInput } from '../../behavior-input-fields.js';
|
|
17
18
|
|
|
18
19
|
export interface ClawclawBehaviorCatalogEntry {
|
|
@@ -31,6 +32,7 @@ export interface ClawclawBehaviorCatalogEntry {
|
|
|
31
32
|
readonly produces?: readonly string[];
|
|
32
33
|
readonly runtime?: ResolvedClawclawBehaviorSource['runtime'];
|
|
33
34
|
readonly provenance?: ResolvedClawclawBehaviorSource['provenance'];
|
|
35
|
+
readonly activationMode?: ReturnType<typeof strategyActivationMode>;
|
|
34
36
|
readonly loadable: boolean;
|
|
35
37
|
readonly compatibilityError?: string;
|
|
36
38
|
}
|
|
@@ -60,6 +62,7 @@ function catalogEntry(source: ResolvedClawclawBehaviorSource): ClawclawBehaviorC
|
|
|
60
62
|
...(source.produces === undefined ? {} : { produces: source.produces }),
|
|
61
63
|
...(source.runtime === undefined ? {} : { runtime: source.runtime }),
|
|
62
64
|
...(source.provenance === undefined ? {} : { provenance: source.provenance }),
|
|
65
|
+
activationMode: strategyActivationMode(source),
|
|
63
66
|
loadable: compatibilityError === undefined,
|
|
64
67
|
...(compatibilityError === undefined ? {} : { compatibilityError }),
|
|
65
68
|
});
|
|
@@ -87,6 +90,11 @@ export class ClawclawBehaviorCatalog {
|
|
|
87
90
|
return this.sources.has(id);
|
|
88
91
|
}
|
|
89
92
|
|
|
93
|
+
activationError(id: string, request?: Readonly<{ source: string; triggerId: string }>): string | undefined {
|
|
94
|
+
const source = this.sources.get(id);
|
|
95
|
+
return source && strategyActivationError(source, request);
|
|
96
|
+
}
|
|
97
|
+
|
|
90
98
|
load(id: string): Promise<LoadedClawclawBehaviorModule> {
|
|
91
99
|
const source = this.sources.get(id);
|
|
92
100
|
if (!source) return Promise.reject(new Error(`Unknown behavior module '${id}'.`));
|