@myclaw163/clawclaw-cli 0.8.3 → 0.8.5
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 +4 -3
- package/docs/configuration.md +44 -26
- package/docs/custom-modules/README.md +7 -10
- package/docs/custom-modules/api-reference.md +3 -7
- package/docs/custom-modules/behavior.md +6 -4
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/trigger.md +1 -1
- package/docs/runtime/README.md +4 -4
- package/docs/runtime/official-perception-modules.md +2 -2
- package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
- package/package.json +9 -2
- package/scripts/build-official-hub-behaviors.mjs +136 -0
- package/scripts/build-official-hub-behaviors.test.mjs +178 -0
- package/scripts/enable_ccl_permissions.cjs +4 -2
- package/scripts/enable_ccl_permissions.test.mjs +8 -4
- package/scripts/postinstall.mjs +1 -4
- package/scripts/sync-bundled-skill.mjs +12 -159
- package/scripts/sync-bundled-skill.test.mjs +9 -74
- package/skills/clawclaw/SKILL.md +18 -13
- package/skills/clawclaw/references/BEHAVIORS.md +4 -4
- package/skills/clawclaw/references/COMMANDS.md +33 -18
- package/skills/clawclaw/references/GAME-MECHANICS.md +16 -18
- package/skills/clawclaw/references/HUB.md +25 -38
- package/skills/clawclaw/references/STREAM.md +9 -11
- package/src/behaviors/official-finite/do-task.ts +70 -0
- package/src/behaviors/official-finite/index.ts +0 -3
- package/src/commands/account.ts +58 -14
- package/src/commands/behavior.ts +116 -38
- package/src/commands/hub.ts +110 -153
- package/src/commands/load.ts +138 -33
- package/src/commands/perception.ts +55 -24
- package/src/commands/persona.ts +66 -20
- package/src/commands/skill.ts +12 -48
- package/src/commands/trigger.ts +68 -40
- package/src/hub-official-behaviors/kill-lone.ts +138 -0
- package/src/hub-official-behaviors/patrol.ts +30 -0
- package/src/hub-official-behaviors/shared.ts +125 -0
- package/src/hub-official-behaviors/task-only.ts +158 -0
- package/src/lib/account-guidance.ts +54 -9
- package/src/lib/agent-workspace-client.ts +135 -0
- package/src/lib/agent-workspace-runtime.ts +154 -0
- package/src/lib/agent-workspace-skills.ts +177 -0
- package/src/lib/agent-workspace-sync.ts +852 -0
- package/src/lib/gameplay-config.ts +29 -15
- package/src/lib/hub-client.ts +252 -34
- package/src/lib/hub-reminder.ts +22 -7
- package/src/lib/init-command.ts +0 -6
- package/src/lib/load-context.ts +12 -6
- package/src/lib/persona.ts +141 -69
- package/src/lib/server-status.ts +78 -0
- package/src/lib/skill-host.ts +160 -0
- package/src/lib/user-data.ts +197 -4
- package/src/pipeline/event-format.ts +20 -4
- package/src/pipeline/event-hints.ts +20 -6
- package/src/pipeline/game-sync-event-normalization.ts +9 -0
- package/src/pipeline/role-display.ts +22 -0
- package/src/runtime/clawclaw/agent-ability-state.ts +1 -21
- package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
- package/src/runtime/clawclaw/owner.ts +63 -19
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +8 -1
- package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +0 -1
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -9
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
- package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
- package/src/runtime/clawclaw-event-catalog.ts +2 -0
- package/src/runtime/framework/action-diagnostics.ts +1 -0
- package/src/runtime/framework/modules/runtime-module-loader.ts +0 -1
- package/src/sdk/action.ts +8 -6
- package/src/sdk/behavior-plugin/index.ts +1 -2
- package/src/sdk/behavior-toolkit/model.ts +2 -0
- package/src/sdk/module-input/index.ts +0 -2
- package/src/strategies/goals/crab-sabotage-top.ts +5 -61
- package/src/strategies/types.ts +0 -6
- package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
- package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
- package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
- package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
- package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
- package/src/behaviors/official-finite/index.test.ts +0 -202
- package/src/behaviors/official-finite/trigger-alarm.ts +0 -53
- package/src/channel/claude-channel-server.test.ts +0 -202
- package/src/commands/account.test.ts +0 -570
- package/src/commands/behavior.test.ts +0 -158
- package/src/commands/communication.test.ts +0 -282
- package/src/commands/competition.test.ts +0 -116
- package/src/commands/data.test.ts +0 -89
- package/src/commands/events-canonical-state.test.ts +0 -406
- package/src/commands/events.test.ts +0 -58
- package/src/commands/game/index.test.ts +0 -1251
- package/src/commands/game-map.test.ts +0 -69
- package/src/commands/hub.test.ts +0 -124
- package/src/commands/load.test.ts +0 -440
- package/src/commands/perception.test.ts +0 -75
- package/src/commands/setup/hermes.test.ts +0 -96
- package/src/commands/setup/openclaw.test.ts +0 -124
- package/src/commands/trigger.test.ts +0 -140
- package/src/commands/upgrade.test.ts +0 -82
- package/src/lib/account-guidance.test.ts +0 -36
- package/src/lib/auth.test.ts +0 -151
- package/src/lib/behavior-export.test.ts +0 -282
- package/src/lib/behavior-export.ts +0 -514
- package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
- package/src/lib/custom-tts.test.ts +0 -387
- package/src/lib/diagnostics-config.test.ts +0 -59
- package/src/lib/game-client-tts.test.ts +0 -151
- package/src/lib/game-client.test.ts +0 -250
- package/src/lib/gameplay-config.test.ts +0 -301
- package/src/lib/host-config-patcher.test.ts +0 -130
- package/src/lib/http-transport.test.ts +0 -124
- package/src/lib/hub-client.test.ts +0 -57
- package/src/lib/hub-install.test.ts +0 -135
- package/src/lib/hub-install.ts +0 -185
- package/src/lib/hub-unzip.test.ts +0 -69
- package/src/lib/init-command.test.ts +0 -103
- package/src/lib/load-context.test.ts +0 -62
- package/src/lib/match-state.test.ts +0 -134
- package/src/lib/official-resource-sync.test.ts +0 -199
- package/src/lib/official-resource-sync.ts +0 -221
- package/src/lib/perception-config.test.ts +0 -143
- package/src/lib/perception-export.test.ts +0 -145
- package/src/lib/perception-export.ts +0 -178
- package/src/lib/persona.test.ts +0 -84
- package/src/lib/room.test.ts +0 -88
- package/src/lib/server-registry.test.ts +0 -64
- package/src/lib/service-status.test.ts +0 -81
- package/src/lib/skill-version.test.ts +0 -48
- package/src/lib/trigger-config.test.ts +0 -102
- package/src/lib/trigger-export.test.ts +0 -80
- package/src/lib/trigger-export.ts +0 -210
- package/src/lib/user-data.test.ts +0 -121
- package/src/lib/workspace-argv.test.ts +0 -49
- package/src/pipeline/canonical-event-presentation.test.ts +0 -255
- package/src/pipeline/event-format.test.ts +0 -828
- package/src/pipeline/event-hints.test.ts +0 -316
- package/src/pipeline/game-sync-event-normalization.test.ts +0 -371
- package/src/pipeline/player-projection.test.ts +0 -247
- package/src/runtime/auto-upgrade.test.ts +0 -66
- package/src/runtime/canonical-event-emitter.test.ts +0 -70
- package/src/runtime/canonical-monitor.test.ts +0 -577
- package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -58
- package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
- package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
- package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
- package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
- package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
- package/src/runtime/clawclaw/notifications.test.ts +0 -47
- package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
- package/src/runtime/clawclaw/owner.test.ts +0 -203
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -304
- package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -40
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
- package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
- package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -854
- package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
- package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
- package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
- package/src/runtime/clawclaw-event-catalog.test.ts +0 -126
- package/src/runtime/framework/action-diagnostics.test.ts +0 -81
- package/src/runtime/framework/capability-registry.test.ts +0 -423
- package/src/runtime/framework/control-coordinator.test.ts +0 -675
- package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
- package/src/runtime/framework/events/event-ingress.test.ts +0 -203
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
- package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
- package/src/runtime/framework/mailbox/identity.test.ts +0 -38
- package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
- package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
- package/src/runtime/framework/participation-manager.test.ts +0 -108
- package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
- package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
- package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
- package/src/runtime/framework/state/history/state-history.test.ts +0 -251
- package/src/runtime/framework/state/state-core.test.ts +0 -197
- package/src/runtime/game-sync-protocol.test.ts +0 -123
- package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
- package/src/runtime/mailbox-host-relay.test.ts +0 -293
- package/src/runtime/observability/observability.test.ts +0 -583
- package/src/runtime/owner-control.test.ts +0 -153
- package/src/runtime/parent-process-watch.test.ts +0 -27
- package/src/runtime/pending-event-handoff.test.ts +0 -29
- package/src/runtime/raw-ws-log.test.ts +0 -102
- package/src/runtime/runtime-logger.test.ts +0 -58
- package/src/runtime/runtime-persistence.test.ts +0 -26
- package/src/runtime/runtime.test.ts +0 -1770
- package/src/runtime/ws-client.test.ts +0 -562
- package/src/sdk/behavior-plugin/index.test.ts +0 -74
- package/src/sdk/index.test.ts +0 -45
- package/src/sdk/module-input/index.test.ts +0 -49
- package/src/sdk/perception-plugin/index.test.ts +0 -22
- package/src/sdk/resource-metadata.test.ts +0 -40
- package/src/sdk/trigger-plugin/index.test.ts +0 -41
- package/src/short-command/classifier.test.ts +0 -107
- package/src/short-command/presenter.test.ts +0 -119
- package/src/short-command/runner.test.ts +0 -78
- package/src/short-command/sensitive-data-filter.test.ts +0 -56
- package/src/short-command/transport-response.test.ts +0 -39
- package/src/strategies/custom-module.test.ts +0 -268
- package/src/strategies/game-utils.test.ts +0 -306
- package/src/strategies/goals/avoid-players-top.test.ts +0 -96
- package/src/strategies/goals/crab-sabotage-top.test.ts +0 -145
- package/src/strategies/goals/kill-lone-top.test.ts +0 -97
- package/src/strategies/goals/kill-target-top.test.ts +0 -66
- package/src/strategies/goals/lone-kill-task-top.test.ts +0 -85
- package/src/strategies/goals/normal-shrimp-top.test.ts +0 -113
- package/src/strategies/goals/paradise-fish-top.test.ts +0 -204
- package/src/strategies/goals/task-only-top.test.ts +0 -89
- package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -139
- package/src/strategies/meeting-gate.test.ts +0 -59
- package/src/strategies/official-long-behavior.test.ts +0 -89
- package/src/strategies/pathfind/astar-path.test.ts +0 -198
- package/src/strategies/pathfind/escape-planner.test.ts +0 -223
- package/src/strategies/player-targets.test.ts +0 -10
- package/src/strategies/task-only.test.ts +0 -138
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync, 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
|
+
buildOfficialHubBehaviors,
|
|
7
|
+
OFFICIAL_HUB_BEHAVIORS,
|
|
8
|
+
} from './build-official-hub-behaviors.mjs';
|
|
9
|
+
import { listClawclawBehaviorSources } from '../src/runtime/clawclaw/plugins/behavior/behavior-source.js';
|
|
10
|
+
import { loadClawclawBehaviorModule } from '../src/runtime/clawclaw/plugins/behavior/behavior-module-loader.js';
|
|
11
|
+
|
|
12
|
+
const roots = [];
|
|
13
|
+
const rooms = [{
|
|
14
|
+
name: '厨房',
|
|
15
|
+
polygon: [[100, 0], [200, 0], [200, 100], [100, 100]],
|
|
16
|
+
bbox: { left: 100, top: 0, right: 200, bottom: 100 },
|
|
17
|
+
}, {
|
|
18
|
+
name: '酒吧',
|
|
19
|
+
polygon: [[300, 0], [400, 0], [400, 100], [300, 100]],
|
|
20
|
+
bbox: { left: 300, top: 0, right: 400, bottom: 100 },
|
|
21
|
+
}];
|
|
22
|
+
|
|
23
|
+
function api() {
|
|
24
|
+
const distance = (from, to) => Math.hypot(from.x - to.x, from.y - to.y);
|
|
25
|
+
return {
|
|
26
|
+
spatial: {
|
|
27
|
+
xPositive: 'right', yPositive: 'down', playerBodyLengthPx: 64, rooms,
|
|
28
|
+
roomAt: () => null, sideInRoom: () => null, placeLabel: () => '',
|
|
29
|
+
transitionIsMapped: () => true,
|
|
30
|
+
},
|
|
31
|
+
navigation: {
|
|
32
|
+
pathDistance: async (from, to) => distance(from, to),
|
|
33
|
+
pathDistances: async (queries) => queries.map(({ from, to }) => distance(from, to)),
|
|
34
|
+
},
|
|
35
|
+
observation: {
|
|
36
|
+
lastSeenPlayer: () => undefined,
|
|
37
|
+
lastSeenCorpse: () => undefined,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function state(overrides = {}) {
|
|
43
|
+
return {
|
|
44
|
+
game_id: 'game', tick: 1, phase: 'wandering',
|
|
45
|
+
you: {
|
|
46
|
+
player: { seat: 1, name: 'Self', is_alive: true },
|
|
47
|
+
x: 0, y: 0, room: '走廊', role: 'shrimp_generic', faction: 'lobster',
|
|
48
|
+
is_alive: true, activity: { kind: 'idle' }, tasks: [],
|
|
49
|
+
},
|
|
50
|
+
players: [], visible_players: [], visible_corpses: [],
|
|
51
|
+
...overrides,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function frame(gameState, input, epochId = 1) {
|
|
56
|
+
return {
|
|
57
|
+
epochId,
|
|
58
|
+
scope: { sessionId: 'session', segmentId: 'segment' },
|
|
59
|
+
nowMs: 1_000,
|
|
60
|
+
gameState,
|
|
61
|
+
events: [],
|
|
62
|
+
input,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
afterEach(() => {
|
|
67
|
+
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('official Hub Behavior bundling', () => {
|
|
71
|
+
it('builds six statically discoverable and dynamically loadable self-contained modules', async () => {
|
|
72
|
+
const root = mkdtempSync(join(tmpdir(), 'official-hub-behaviors-'));
|
|
73
|
+
roots.push(root);
|
|
74
|
+
const built = await buildOfficialHubBehaviors(root);
|
|
75
|
+
expect(built.map(({ id }) => id)).toEqual(OFFICIAL_HUB_BEHAVIORS.map(({ id }) => id));
|
|
76
|
+
expect(built.every(({ bytes }) => bytes < 50_000)).toBe(true);
|
|
77
|
+
|
|
78
|
+
const sources = listClawclawBehaviorSources(root);
|
|
79
|
+
expect(sources.map(({ id }) => id).sort()).toEqual(
|
|
80
|
+
OFFICIAL_HUB_BEHAVIORS.map(({ id }) => id).sort(),
|
|
81
|
+
);
|
|
82
|
+
const classes = new Map();
|
|
83
|
+
for (const source of sources) {
|
|
84
|
+
const text = readFileSync(source.sourcePath, 'utf8');
|
|
85
|
+
expect(text).not.toContain('clawclaw-internal:');
|
|
86
|
+
expect(text).not.toContain('clawclaw-walkable.bin');
|
|
87
|
+
expect(text).not.toContain('clawclaw-map.json');
|
|
88
|
+
expect(text).not.toMatch(/from\s+["']\.\.?\//);
|
|
89
|
+
const loaded = await loadClawclawBehaviorModule(source);
|
|
90
|
+
expect(loaded.manifest.id).toBe(source.id);
|
|
91
|
+
expect(typeof loaded.BehaviorClass.prototype.decide).toBe('function');
|
|
92
|
+
classes.set(source.id, loaded.BehaviorClass);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const patrol = new (classes.get('patrol'))();
|
|
96
|
+
await expect(patrol.decide(frame(state(), {}), api())).resolves.toEqual(
|
|
97
|
+
expect.objectContaining({ status: expect.any(Object) }),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const taskOnly = new (classes.get('task-only'))();
|
|
101
|
+
const longTaskState = state({
|
|
102
|
+
you: {
|
|
103
|
+
...state().you,
|
|
104
|
+
tasks: [{ task_id: 'wires', name: '接线', room: '走廊', x: 5, y: 0, is_fake_shrimp: false, status: 'normal' }],
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
await expect(taskOnly.decide(frame(longTaskState, {}), api())).resolves.toEqual(
|
|
108
|
+
expect.objectContaining({
|
|
109
|
+
actions: [expect.objectContaining({ action: 'task', task_name: '接线' })],
|
|
110
|
+
}),
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const doTask = new (classes.get('do_task'))();
|
|
114
|
+
const taskState = state({
|
|
115
|
+
you: {
|
|
116
|
+
...state().you,
|
|
117
|
+
tasks: [{ task_id: 'wires', name: '接线', room: '走廊', x: 5, y: 0, is_fake_shrimp: false, status: 'normal' }],
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
await expect(doTask.decide(frame(taskState, { task: 'wires', timeout_ms: 60_000 }), api()))
|
|
121
|
+
.resolves.toEqual(expect.objectContaining({
|
|
122
|
+
actions: [expect.objectContaining({ action: 'task', task_name: '接线' })],
|
|
123
|
+
}));
|
|
124
|
+
|
|
125
|
+
const report = new (classes.get('report_corpse'))();
|
|
126
|
+
const corpseState = state({
|
|
127
|
+
visible_corpses: [{ corpse_id: 'corpse-2', player: { seat: 2, name: 'Dead' }, x: 10, y: 0, room: '走廊', distance: 10 }],
|
|
128
|
+
});
|
|
129
|
+
await expect(report.decide(frame(corpseState, { corpse_seat: 2, timeout_ms: 45_000 }), api()))
|
|
130
|
+
.resolves.toEqual(expect.objectContaining({
|
|
131
|
+
actions: [expect.objectContaining({ action: 'report' })],
|
|
132
|
+
}));
|
|
133
|
+
|
|
134
|
+
const hunt = new (classes.get('hunt_player'))();
|
|
135
|
+
const huntingState = state({
|
|
136
|
+
you: { ...state().you, role: 'crab_generic', faction: 'crab', kills_remaining: 1, crab_teammates: [] },
|
|
137
|
+
players: [{ seat: 2, name: 'Target', known_status: { is_alive: true } }],
|
|
138
|
+
visible_players: [{ player: { seat: 2, name: 'Target' }, x: 10, y: 0, room: '走廊', distance: 10, is_alive: true }],
|
|
139
|
+
});
|
|
140
|
+
await expect(hunt.decide(frame(huntingState, {
|
|
141
|
+
player_seat: 2,
|
|
142
|
+
after_kill: 'replan',
|
|
143
|
+
timeout_ms: 60_000,
|
|
144
|
+
}), api())).resolves.toEqual(expect.objectContaining({
|
|
145
|
+
actions: [expect.objectContaining({ action: 'kill', target_seat: 2 })],
|
|
146
|
+
}));
|
|
147
|
+
|
|
148
|
+
const killLone = new (classes.get('kill-lone'))();
|
|
149
|
+
await expect(killLone.decide(frame(huntingState, {
|
|
150
|
+
protectedTargets: [],
|
|
151
|
+
huntTargets: [],
|
|
152
|
+
}), api())).resolves.toEqual(expect.objectContaining({
|
|
153
|
+
actions: [expect.objectContaining({ action: 'kill', target_seat: 2 })],
|
|
154
|
+
}));
|
|
155
|
+
|
|
156
|
+
const protectedKillLone = new (classes.get('kill-lone'))();
|
|
157
|
+
const protectedDecision = await protectedKillLone.decide(frame(huntingState, {
|
|
158
|
+
protectedTargets: [2],
|
|
159
|
+
huntTargets: [2],
|
|
160
|
+
}), api());
|
|
161
|
+
expect(protectedDecision?.actions ?? []).not.toContainEqual(expect.objectContaining({ action: 'kill' }));
|
|
162
|
+
|
|
163
|
+
const huntCrowd = new (classes.get('kill-lone'))();
|
|
164
|
+
const crowdState = state({
|
|
165
|
+
...huntingState,
|
|
166
|
+
visible_players: [
|
|
167
|
+
...huntingState.visible_players,
|
|
168
|
+
{ player: { seat: 3, name: 'Other' }, x: 20, y: 0, room: '走廊', distance: 20, is_alive: true },
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
await expect(huntCrowd.decide(frame(crowdState, {
|
|
172
|
+
protectedTargets: [],
|
|
173
|
+
huntTargets: [2],
|
|
174
|
+
}), api())).resolves.toEqual(expect.objectContaining({
|
|
175
|
+
actions: [expect.objectContaining({ action: 'kill', target_seat: 2 })],
|
|
176
|
+
}));
|
|
177
|
+
}, 30_000);
|
|
178
|
+
});
|
|
@@ -35,9 +35,11 @@ const REQUIRED_ALLOW = [
|
|
|
35
35
|
"Skill(clawclaw *)",
|
|
36
36
|
"Read(~/.claude/skills/clawclaw/**)",
|
|
37
37
|
"Read(~/.agents/skills/clawclaw/**)",
|
|
38
|
-
"Edit(~/.clawclaw/user-data/accounts/**/
|
|
38
|
+
"Edit(~/.clawclaw/user-data/accounts/**/personas/local/**)",
|
|
39
|
+
"Edit(~/.clawclaw/user-data/accounts/**/personas/hub/**)",
|
|
39
40
|
"Edit(~/.clawclaw/user-data/accounts/**/memory.md)",
|
|
40
|
-
"Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/
|
|
41
|
+
"Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/local/**)",
|
|
42
|
+
"Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/hub/**)",
|
|
41
43
|
"Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/memory.md)",
|
|
42
44
|
];
|
|
43
45
|
|
|
@@ -26,9 +26,11 @@ const requiredAllow = [
|
|
|
26
26
|
'Skill(clawclaw *)',
|
|
27
27
|
'Read(~/.claude/skills/clawclaw/**)',
|
|
28
28
|
'Read(~/.agents/skills/clawclaw/**)',
|
|
29
|
-
'Edit(~/.clawclaw/user-data/accounts/**/
|
|
29
|
+
'Edit(~/.clawclaw/user-data/accounts/**/personas/local/**)',
|
|
30
|
+
'Edit(~/.clawclaw/user-data/accounts/**/personas/hub/**)',
|
|
30
31
|
'Edit(~/.clawclaw/user-data/accounts/**/memory.md)',
|
|
31
|
-
'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/
|
|
32
|
+
'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/local/**)',
|
|
33
|
+
'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/hub/**)',
|
|
32
34
|
'Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/memory.md)',
|
|
33
35
|
];
|
|
34
36
|
|
|
@@ -97,9 +99,11 @@ describe('enable_ccl_permissions.cjs', () => {
|
|
|
97
99
|
const allow = readJson(settingsPath).permissions.allow;
|
|
98
100
|
expect(allow).toContain('Read(~/.claude/skills/clawclaw/**)');
|
|
99
101
|
expect(allow).toContain('Read(~/.agents/skills/clawclaw/**)');
|
|
100
|
-
expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/
|
|
102
|
+
expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/personas/local/**)');
|
|
103
|
+
expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/personas/hub/**)');
|
|
101
104
|
expect(allow).toContain('Edit(~/.clawclaw/user-data/accounts/**/memory.md)');
|
|
102
|
-
expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/
|
|
105
|
+
expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/local/**)');
|
|
106
|
+
expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/personas/hub/**)');
|
|
103
107
|
expect(allow).toContain('Edit(~/AppData/Roaming/clawclaw/user-data/accounts/**/memory.md)');
|
|
104
108
|
expect(allow.filter((entry) => /^(?:Read|Edit)\(/.test(entry))).not.toContainEqual(
|
|
105
109
|
expect.stringContaining('\\'),
|
package/scripts/postinstall.mjs
CHANGED
|
@@ -6,10 +6,7 @@ function main() {
|
|
|
6
6
|
if (process.env.npm_config_global !== 'true') return;
|
|
7
7
|
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
if (result.backupDir) {
|
|
11
|
-
console.warn(`[clawclaw-cli] Backed up existing clawclaw skill to: ${result.backupDir}`);
|
|
12
|
-
}
|
|
9
|
+
syncBundledSkill();
|
|
13
10
|
} catch (err) {
|
|
14
11
|
console.warn('[clawclaw-cli] CLI installed, but bundled agent skill was not updated.');
|
|
15
12
|
console.warn('[clawclaw-cli] Run: ccl upgrade skill');
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { spawnSync } from 'child_process';
|
|
2
|
-
import { createHash } from 'crypto';
|
|
3
2
|
import {
|
|
4
3
|
cpSync,
|
|
5
4
|
existsSync,
|
|
6
5
|
mkdirSync,
|
|
7
|
-
readdirSync,
|
|
8
6
|
readFileSync,
|
|
9
|
-
|
|
10
|
-
statSync,
|
|
11
|
-
writeFileSync,
|
|
7
|
+
rmSync,
|
|
12
8
|
} from 'fs';
|
|
13
9
|
import { homedir } from 'os';
|
|
14
|
-
import { basename, dirname, join,
|
|
10
|
+
import { basename, dirname, join, resolve } from 'path';
|
|
15
11
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
16
12
|
|
|
17
13
|
const SKILL_NAME = 'clawclaw';
|
|
18
14
|
const SKILLS_ADD_TIMEOUT_MS = 60_000;
|
|
19
15
|
|
|
20
|
-
function defaultBackupRoot() {
|
|
21
|
-
const appData = process.env.APPDATA?.trim();
|
|
22
|
-
if (appData) return resolve(appData, 'clawclaw', 'skill-backups');
|
|
23
|
-
return resolve(homedir(), '.clawclaw', 'skill-backups');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
16
|
function getOpenClawSkillsDir(homeDir = homedir()) {
|
|
27
17
|
for (const dir of ['.openclaw', '.clawdbot', '.moltbot']) {
|
|
28
18
|
const base = join(homeDir, dir);
|
|
@@ -43,141 +33,6 @@ function defaultCandidateSkillDirs() {
|
|
|
43
33
|
];
|
|
44
34
|
}
|
|
45
35
|
|
|
46
|
-
function formatTimestamp(date = new Date()) {
|
|
47
|
-
const pad = (n) => String(n).padStart(2, '0');
|
|
48
|
-
return `${date.getUTCFullYear()}${pad(date.getUTCMonth() + 1)}${pad(date.getUTCDate())}-${pad(date.getUTCHours())}${pad(date.getUTCMinutes())}${pad(date.getUTCSeconds())}Z`;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function chooseUniqueDir(baseDir) {
|
|
52
|
-
if (!existsSync(baseDir)) return baseDir;
|
|
53
|
-
for (let i = 1; i < 1000; i += 1) {
|
|
54
|
-
const candidate = `${baseDir}-${i}`;
|
|
55
|
-
if (!existsSync(candidate)) return candidate;
|
|
56
|
-
}
|
|
57
|
-
throw new Error(`unable to choose a unique backup directory under ${dirname(baseDir)}`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function readSkillVersion(skillDir) {
|
|
61
|
-
const md = join(skillDir, 'SKILL.md');
|
|
62
|
-
if (!existsSync(md)) return null;
|
|
63
|
-
const content = readFileSync(md, 'utf8');
|
|
64
|
-
const frontmatter = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
65
|
-
if (!frontmatter) return null;
|
|
66
|
-
const version = frontmatter[1].match(/^\s*version\s*:\s*["']?([^"'\r\n]+)["']?\s*$/im);
|
|
67
|
-
return version?.[1]?.trim() || null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function listFilesRecursive(dir, base = dir) {
|
|
71
|
-
const entries = readdirSync(dir, { withFileTypes: true })
|
|
72
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
73
|
-
const files = [];
|
|
74
|
-
for (const entry of entries) {
|
|
75
|
-
const abs = join(dir, entry.name);
|
|
76
|
-
if (entry.isDirectory()) {
|
|
77
|
-
files.push(...listFilesRecursive(abs, base));
|
|
78
|
-
} else if (entry.isFile()) {
|
|
79
|
-
files.push(abs);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (dir === base) files.sort((a, b) => relative(base, a).localeCompare(relative(base, b)));
|
|
83
|
-
return files;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function hashDirectory(dir) {
|
|
87
|
-
const hash = createHash('sha256');
|
|
88
|
-
for (const file of listFilesRecursive(dir)) {
|
|
89
|
-
const rel = relative(dir, file).split('\\').join('/');
|
|
90
|
-
hash.update(rel);
|
|
91
|
-
hash.update('\0');
|
|
92
|
-
hash.update(readFileSync(file));
|
|
93
|
-
hash.update('\0');
|
|
94
|
-
}
|
|
95
|
-
return hash.digest('hex');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function existingUniqueDirs(candidateDirs) {
|
|
99
|
-
const seen = new Set();
|
|
100
|
-
const dirs = [];
|
|
101
|
-
for (const dir of candidateDirs) {
|
|
102
|
-
const abs = resolve(dir);
|
|
103
|
-
if (!existsSync(abs)) continue;
|
|
104
|
-
if (!statSync(abs).isDirectory()) continue;
|
|
105
|
-
let key;
|
|
106
|
-
try {
|
|
107
|
-
key = realpathSync(abs);
|
|
108
|
-
} catch {
|
|
109
|
-
key = abs;
|
|
110
|
-
}
|
|
111
|
-
const normalized = key.toLowerCase();
|
|
112
|
-
if (seen.has(normalized)) continue;
|
|
113
|
-
seen.add(normalized);
|
|
114
|
-
dirs.push(abs);
|
|
115
|
-
}
|
|
116
|
-
return dirs;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function backupInstalledSkillTargets(options = {}) {
|
|
120
|
-
const candidateDirs = options.candidateDirs ?? defaultCandidateSkillDirs();
|
|
121
|
-
const sourceDir = options.sourceDir ? resolve(options.sourceDir) : null;
|
|
122
|
-
const existingDirs = existingUniqueDirs(candidateDirs);
|
|
123
|
-
if (existingDirs.length === 0) return null;
|
|
124
|
-
|
|
125
|
-
const backupRoot = resolve(options.backupRoot ?? defaultBackupRoot());
|
|
126
|
-
const backupDir = chooseUniqueDir(join(backupRoot, `${SKILL_NAME}-${formatTimestamp(options.now)}`));
|
|
127
|
-
|
|
128
|
-
const sourceHash = sourceDir && existsSync(sourceDir) ? hashDirectory(sourceDir) : null;
|
|
129
|
-
const backupSources = [];
|
|
130
|
-
for (const dir of existingDirs) {
|
|
131
|
-
const hash = hashDirectory(dir);
|
|
132
|
-
if (sourceHash && hash === sourceHash) continue;
|
|
133
|
-
backupSources.push({
|
|
134
|
-
dir,
|
|
135
|
-
hash,
|
|
136
|
-
oldSkillVersion: readSkillVersion(dir),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (backupSources.length === 0) return null;
|
|
140
|
-
|
|
141
|
-
mkdirSync(backupDir, { recursive: true });
|
|
142
|
-
const copyByHash = new Map();
|
|
143
|
-
const copies = [];
|
|
144
|
-
const entries = [];
|
|
145
|
-
for (const { dir, hash, oldSkillVersion } of backupSources) {
|
|
146
|
-
let copy = copyByHash.get(hash);
|
|
147
|
-
if (!copy) {
|
|
148
|
-
const name = `copy-${copies.length + 1}`;
|
|
149
|
-
const backupPath = join(backupDir, name);
|
|
150
|
-
cpSync(dir, backupPath, { recursive: true, dereference: true, errorOnExist: true });
|
|
151
|
-
copy = {
|
|
152
|
-
name,
|
|
153
|
-
backupPath,
|
|
154
|
-
hash,
|
|
155
|
-
oldSkillVersion,
|
|
156
|
-
};
|
|
157
|
-
copyByHash.set(hash, copy);
|
|
158
|
-
copies.push(copy);
|
|
159
|
-
}
|
|
160
|
-
entries.push({
|
|
161
|
-
sourcePath: dir,
|
|
162
|
-
copy: copy.name,
|
|
163
|
-
hash,
|
|
164
|
-
oldSkillVersion,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const manifest = {
|
|
169
|
-
skill: SKILL_NAME,
|
|
170
|
-
createdAt: new Date().toISOString(),
|
|
171
|
-
backupDir,
|
|
172
|
-
sourceDir,
|
|
173
|
-
newSkillVersion: sourceDir ? readSkillVersion(sourceDir) : null,
|
|
174
|
-
copies,
|
|
175
|
-
entries,
|
|
176
|
-
};
|
|
177
|
-
writeFileSync(join(backupDir, 'manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
|
|
178
|
-
return { backupDir, copies, entries };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
36
|
function resolveSkillsBin(installDir) {
|
|
182
37
|
const pkgPath = resolve(installDir, 'node_modules', 'skills', 'package.json');
|
|
183
38
|
if (!existsSync(pkgPath)) throw new Error(`skills package not found: ${pkgPath}`);
|
|
@@ -191,20 +46,13 @@ export function syncBundledSkill(options = {}) {
|
|
|
191
46
|
// Opt-out: hosts that own the clawclaw skill themselves (e.g. the claude-clawclaw
|
|
192
47
|
// channel plugin) set CLAWCLAW_NO_SKILL_SYNC=1 so the CLI never overwrites their skill.
|
|
193
48
|
if (process.env.CLAWCLAW_NO_SKILL_SYNC === '1') {
|
|
194
|
-
return { skipped: true,
|
|
49
|
+
return { skipped: true, updatedTargets: 0 };
|
|
195
50
|
}
|
|
196
51
|
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
197
52
|
const installDir = resolve(options.installDir ?? join(scriptDir, '..'));
|
|
198
53
|
const sourceDir = resolve(installDir, 'skills', SKILL_NAME);
|
|
199
54
|
if (!existsSync(sourceDir)) throw new Error(`bundled skill dir not found: ${sourceDir}`);
|
|
200
55
|
|
|
201
|
-
const backup = backupInstalledSkillTargets({
|
|
202
|
-
sourceDir,
|
|
203
|
-
backupRoot: options.backupRoot,
|
|
204
|
-
candidateDirs: options.candidateDirs,
|
|
205
|
-
now: options.now,
|
|
206
|
-
});
|
|
207
|
-
|
|
208
56
|
const skillsBin = resolveSkillsBin(installDir);
|
|
209
57
|
const spawn = options.spawnSync ?? spawnSync;
|
|
210
58
|
const result = spawn(
|
|
@@ -223,7 +71,15 @@ export function syncBundledSkill(options = {}) {
|
|
|
223
71
|
throw new Error(`skills add exited with code ${result.status}`);
|
|
224
72
|
}
|
|
225
73
|
|
|
226
|
-
|
|
74
|
+
const targets = options.candidateDirs ?? defaultCandidateSkillDirs();
|
|
75
|
+
for (const target of targets) {
|
|
76
|
+
const resolvedTarget = resolve(target);
|
|
77
|
+
if (existsSync(resolvedTarget)) rmSync(resolvedTarget, { recursive: true, force: true });
|
|
78
|
+
mkdirSync(dirname(resolvedTarget), { recursive: true });
|
|
79
|
+
cpSync(sourceDir, resolvedTarget, { recursive: true, dereference: true, errorOnExist: true });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { skipped: false, updatedTargets: targets.length };
|
|
227
83
|
}
|
|
228
84
|
|
|
229
85
|
function formatFailure(err) {
|
|
@@ -237,9 +93,6 @@ function main() {
|
|
|
237
93
|
console.error('[clawclaw-cli] skill sync skipped (CLAWCLAW_NO_SKILL_SYNC=1)');
|
|
238
94
|
return;
|
|
239
95
|
}
|
|
240
|
-
if (result.backupDir) {
|
|
241
|
-
console.error(`[clawclaw-cli] Backed up existing clawclaw skill to: ${result.backupDir}`);
|
|
242
|
-
}
|
|
243
96
|
} catch (err) {
|
|
244
97
|
console.error('[clawclaw-cli] Bundled agent skill was not updated.');
|
|
245
98
|
console.error('[clawclaw-cli] Run: ccl upgrade skill');
|
|
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from
|
|
|
2
2
|
import { tmpdir } from 'os';
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
-
import {
|
|
5
|
+
import { syncBundledSkill } from './sync-bundled-skill.mjs';
|
|
6
6
|
|
|
7
7
|
function writeSkill(dir, version, body) {
|
|
8
8
|
mkdirSync(dir, { recursive: true });
|
|
@@ -22,73 +22,7 @@ function writeInstallDir(root) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
describe('sync-bundled-skill', () => {
|
|
25
|
-
it('
|
|
26
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-backup-'));
|
|
27
|
-
const one = join(root, 'home', '.claude', 'skills', 'clawclaw');
|
|
28
|
-
const two = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
29
|
-
const three = join(root, 'home', '.openclaw', 'skills', 'clawclaw');
|
|
30
|
-
const newSkill = join(root, 'pkg', 'skills', 'clawclaw');
|
|
31
|
-
writeSkill(one, '4.8.17', 'same');
|
|
32
|
-
writeSkill(two, '4.8.17', 'same');
|
|
33
|
-
writeSkill(three, '4.8.16', 'different');
|
|
34
|
-
writeSkill(newSkill, '4.8.18', 'new');
|
|
35
|
-
|
|
36
|
-
const result = backupInstalledSkillTargets({
|
|
37
|
-
sourceDir: newSkill,
|
|
38
|
-
backupRoot: join(root, 'backups'),
|
|
39
|
-
candidateDirs: [one, two, three],
|
|
40
|
-
now: new Date('2026-06-11T08:09:10Z'),
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(result.backupDir).toBe(join(root, 'backups', 'clawclaw-20260611-080910Z'));
|
|
44
|
-
expect(result.copies).toHaveLength(2);
|
|
45
|
-
expect(result.entries).toHaveLength(3);
|
|
46
|
-
expect(result.entries[0].copy).toBe(result.entries[1].copy);
|
|
47
|
-
expect(result.entries[2].copy).not.toBe(result.entries[0].copy);
|
|
48
|
-
const manifest = JSON.parse(readFileSync(join(result.backupDir, 'manifest.json'), 'utf8'));
|
|
49
|
-
expect(manifest.newSkillVersion).toBe('4.8.18');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('does not back up installed skills that already match the bundled skill', () => {
|
|
53
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-backup-same-'));
|
|
54
|
-
const installed = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
55
|
-
const newSkill = join(root, 'pkg', 'skills', 'clawclaw');
|
|
56
|
-
writeSkill(installed, '4.8.18', 'new');
|
|
57
|
-
writeSkill(newSkill, '4.8.18', 'new');
|
|
58
|
-
|
|
59
|
-
const result = backupInstalledSkillTargets({
|
|
60
|
-
sourceDir: newSkill,
|
|
61
|
-
backupRoot: join(root, 'backups'),
|
|
62
|
-
candidateDirs: [installed],
|
|
63
|
-
now: new Date('2026-06-11T08:09:10Z'),
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
expect(result).toBeNull();
|
|
67
|
-
expect(existsSync(join(root, 'backups'))).toBe(false);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('backs up only installed skills that differ from the bundled skill', () => {
|
|
71
|
-
const root = mkdtempSync(join(tmpdir(), 'skill-backup-mixed-'));
|
|
72
|
-
const same = join(root, 'home', '.claude', 'skills', 'clawclaw');
|
|
73
|
-
const different = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
74
|
-
const newSkill = join(root, 'pkg', 'skills', 'clawclaw');
|
|
75
|
-
writeSkill(same, '4.8.18', 'new');
|
|
76
|
-
writeSkill(different, '4.8.17', 'old');
|
|
77
|
-
writeSkill(newSkill, '4.8.18', 'new');
|
|
78
|
-
|
|
79
|
-
const result = backupInstalledSkillTargets({
|
|
80
|
-
sourceDir: newSkill,
|
|
81
|
-
backupRoot: join(root, 'backups'),
|
|
82
|
-
candidateDirs: [same, different],
|
|
83
|
-
now: new Date('2026-06-11T08:09:10Z'),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
expect(result.copies).toHaveLength(1);
|
|
87
|
-
expect(result.entries).toHaveLength(1);
|
|
88
|
-
expect(result.entries[0].sourcePath).toBe(different);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('runs skills add after a successful backup', () => {
|
|
25
|
+
it('runs skills add and directly mirrors the bundled directory without a backup', () => {
|
|
92
26
|
const root = mkdtempSync(join(tmpdir(), 'skill-sync-'));
|
|
93
27
|
const installDir = writeInstallDir(root);
|
|
94
28
|
const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
@@ -103,7 +37,8 @@ describe('sync-bundled-skill', () => {
|
|
|
103
37
|
stdio: 'ignore',
|
|
104
38
|
});
|
|
105
39
|
|
|
106
|
-
expect(result
|
|
40
|
+
expect(result).toEqual({ skipped: false, updatedTargets: 1 });
|
|
41
|
+
expect(readFileSync(join(old, 'SKILL.md'), 'utf8')).toContain('\nnew\n');
|
|
107
42
|
expect(spawn).toHaveBeenCalledOnce();
|
|
108
43
|
expect(spawn.mock.calls[0][1].slice(1)).toEqual([
|
|
109
44
|
'add',
|
|
@@ -113,7 +48,7 @@ describe('sync-bundled-skill', () => {
|
|
|
113
48
|
]);
|
|
114
49
|
});
|
|
115
50
|
|
|
116
|
-
it('does not
|
|
51
|
+
it('does not consult the obsolete backup location', () => {
|
|
117
52
|
const root = mkdtempSync(join(tmpdir(), 'skill-backup-fail-'));
|
|
118
53
|
const installDir = writeInstallDir(root);
|
|
119
54
|
const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
@@ -128,11 +63,11 @@ describe('sync-bundled-skill', () => {
|
|
|
128
63
|
candidateDirs: [old],
|
|
129
64
|
spawnSync: spawn,
|
|
130
65
|
stdio: 'ignore',
|
|
131
|
-
})).toThrow();
|
|
132
|
-
expect(spawn).
|
|
66
|
+
})).not.toThrow();
|
|
67
|
+
expect(spawn).toHaveBeenCalledOnce();
|
|
133
68
|
});
|
|
134
69
|
|
|
135
|
-
it('
|
|
70
|
+
it('does not create a backup when skills add fails', () => {
|
|
136
71
|
const root = mkdtempSync(join(tmpdir(), 'skill-add-fail-'));
|
|
137
72
|
const installDir = writeInstallDir(root);
|
|
138
73
|
const old = join(root, 'home', '.codex', 'skills', 'clawclaw');
|
|
@@ -147,6 +82,6 @@ describe('sync-bundled-skill', () => {
|
|
|
147
82
|
spawnSync: spawn,
|
|
148
83
|
stdio: 'ignore',
|
|
149
84
|
})).toThrow(/skills add exited/);
|
|
150
|
-
expect(existsSync(backupRoot)).toBe(
|
|
85
|
+
expect(existsSync(backupRoot)).toBe(false);
|
|
151
86
|
});
|
|
152
87
|
});
|