@myclaw163/clawclaw-cli 0.8.25 → 0.8.27
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 +7 -0
- package/docs/custom-modules/api-reference.md +43 -1
- package/docs/custom-modules/behavior.md +3 -0
- package/docs/custom-modules/examples/task-reminder.ts +17 -0
- package/docs/custom-modules/perception.md +7 -1
- package/docs/custom-modules/reminders.md +147 -0
- package/docs/custom-modules/skill.md +67 -0
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +25 -17
- package/skills/clawclaw/references/BEHAVIORS.md +2 -2
- package/skills/clawclaw/references/COMMANDS.md +2 -0
- package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +3 -0
- package/skills/clawclaw/references/CUSTOM-MODULE-API.md +43 -1
- package/skills/clawclaw/references/CUSTOM-MODULES.md +7 -0
- package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +11 -5
- package/skills/clawclaw/references/CUSTOM-REMINDER-DEVELOPMENT.md +147 -0
- package/skills/clawclaw/references/CUSTOM-SKILL-DEVELOPMENT.md +67 -0
- package/skills/clawclaw/references/HUB.md +14 -0
- package/skills/clawclaw/references/TACTICS.md +17 -15
- package/src/cli.ts +2 -14
- package/src/commands/capability.ts +21 -8
- package/src/commands/hub.ts +5 -4
- package/src/commands/load.ts +16 -3
- package/src/lib/agent-workspace-skills.ts +24 -3
- package/src/lib/capability-cloud-sync.ts +11 -2
- package/src/lib/capability-load-diagnostics.ts +1 -1
- package/src/lib/command-error.ts +22 -0
- package/src/lib/hub-client.ts +26 -2
- package/src/lib/hub-errors.ts +60 -0
- package/src/lib/perception-config.ts +1 -1
- package/src/lib/skill-host.ts +26 -0
- package/src/runtime/clawclaw/owner.ts +3 -1
- package/src/runtime/clawclaw/plugins/assembly.ts +17 -2
- package/src/runtime/clawclaw/plugins/behavior-input-source.ts +10 -0
- package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +137 -0
- package/src/runtime/clawclaw/plugins/derived-event/reminder-rules.ts +1 -0
- package/src/runtime/clawclaw/plugins/derived-event/reminder-runner.ts +59 -0
- package/src/runtime/clawclaw/plugins/derived-event/reminder-worker.ts +33 -0
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +7 -3
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +17 -1
- package/src/runtime/clawclaw/reminder-manifest.ts +28 -0
- package/src/runtime/clawclaw/runtime.ts +3 -0
- package/src/runtime/clawclaw-event-catalog.ts +4 -1
- package/src/runtime/framework/events/event-repository.ts +1 -0
- package/src/runtime/framework/events/memory-event-repository.ts +14 -0
- package/src/runtime/framework/events/sqlite-event-repository.ts +16 -0
- package/src/runtime/framework/events/types.ts +6 -0
- package/src/runtime/framework/persistence/memory-first-persistence.ts +3 -0
- package/src/runtime/framework/plugins/contracts.ts +3 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +19 -0
- package/src/runtime/framework/runtime.ts +1 -0
- package/src/sdk/perception-plugin/index.ts +2 -0
- package/src/sdk/perception-plugin/reminder-rules.ts +41 -0
- package/src/sdk/perception-plugin/reminder.ts +40 -0
package/src/commands/load.ts
CHANGED
|
@@ -204,9 +204,9 @@ function compactCapabilityWarning(warning: CapabilityLoadWarning): Record<string
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
function compactSkillChanges(changes: ReturnType<typeof syncAgentWorkspaceSkills>) {
|
|
207
|
-
const keys = ['added', 'updated', 'removed', 'preservedModified', 'failed'] as const;
|
|
207
|
+
const keys = ['added', 'updated', 'removed', 'preservedModified', 'failed', 'skipped'] as const;
|
|
208
208
|
const value = Object.fromEntries(keys.flatMap((key) => (
|
|
209
|
-
changes[key]
|
|
209
|
+
!changes[key]?.length ? [] : [[key, changes[key]]]
|
|
210
210
|
)));
|
|
211
211
|
return Object.keys(value).length > 0 || changes.requiresUserConfirmation
|
|
212
212
|
? {
|
|
@@ -594,6 +594,18 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
594
594
|
localPerceptions,
|
|
595
595
|
hubPerceptions,
|
|
596
596
|
);
|
|
597
|
+
const reminderTopics = new Map<string, string[]>();
|
|
598
|
+
for (const source of enabledPerceptions) {
|
|
599
|
+
if (!source.reminder || source.apiVersion !== PERCEPTION_PLUGIN_API_VERSION) continue;
|
|
600
|
+
const ids = reminderTopics.get(source.reminder.topic) ?? [];
|
|
601
|
+
ids.push(source.id); reminderTopics.set(source.reminder.topic, ids);
|
|
602
|
+
}
|
|
603
|
+
const conflictingPerceptions = new Set([...reminderTopics.values()].filter(ids => ids.length > 1).flat());
|
|
604
|
+
for (const source of enabledPerceptions.filter(source => conflictingPerceptions.has(source.id))) {
|
|
605
|
+
capabilityWarnings.push({ code: 'CAPABILITY_NOT_LOADED', capability_type: 'perception',
|
|
606
|
+
source: hubPerceptionIds.has(source.id) ? 'hub' : 'local', stage: 'selection', id: source.id,
|
|
607
|
+
reason: `perception_topic_conflict:${source.reminder!.topic}:${reminderTopics.get(source.reminder!.topic)!.join(',')}` });
|
|
608
|
+
}
|
|
597
609
|
const perceptionEntry = (source: typeof enabledPerceptions[number]) => ({
|
|
598
610
|
id: source.id,
|
|
599
611
|
name: source.name,
|
|
@@ -602,7 +614,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
602
614
|
...pluginApiVersionStatus('perception', PERCEPTION_PLUGIN_API_VERSION, source.apiVersion),
|
|
603
615
|
});
|
|
604
616
|
const perceptions = enabledPerceptions
|
|
605
|
-
.filter(({ apiVersion }) => apiVersion === PERCEPTION_PLUGIN_API_VERSION)
|
|
617
|
+
.filter(({ apiVersion, id }) => apiVersion === PERCEPTION_PLUGIN_API_VERSION && !conflictingPerceptions.has(id))
|
|
606
618
|
.map(perceptionEntry);
|
|
607
619
|
const incompatiblePerceptions = enabledPerceptions
|
|
608
620
|
.filter(({ apiVersion }) => apiVersion !== PERCEPTION_PLUGIN_API_VERSION)
|
|
@@ -830,6 +842,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
830
842
|
updated: [...new Set([...firstSkillChanges.updated, ...skillChanges.updated])],
|
|
831
843
|
removed: [...new Set([...firstSkillChanges.removed, ...skillChanges.removed])],
|
|
832
844
|
failed: [...firstSkillChanges.failed, ...skillChanges.failed],
|
|
845
|
+
skipped: skillChanges.skipped,
|
|
833
846
|
} : skillChanges);
|
|
834
847
|
const cloudConflicts = [...cloudRefreshChanges.conflicts, ...(cloudChanges?.conflicts ?? [])]
|
|
835
848
|
.filter((value, index, values) => values.findIndex((candidate) => (
|
|
@@ -27,6 +27,9 @@ import {
|
|
|
27
27
|
} from './user-data.js';
|
|
28
28
|
import {
|
|
29
29
|
agentSkillTargets,
|
|
30
|
+
realSkillTargets,
|
|
31
|
+
skillHostSkip,
|
|
32
|
+
type SkillHostSkip,
|
|
30
33
|
hashAgentSkillDirectory,
|
|
31
34
|
linkAgentSkillTarget,
|
|
32
35
|
overwriteAgentSkillTarget,
|
|
@@ -66,6 +69,7 @@ export interface AgentWorkspaceSkillChanges {
|
|
|
66
69
|
unchanged: string[];
|
|
67
70
|
preservedModified: string[];
|
|
68
71
|
failed: Array<{ name: string; action: 'add' | 'update' | 'remove'; error: string }>;
|
|
72
|
+
skipped?: SkillHostSkip[];
|
|
69
73
|
requiresUserConfirmation: boolean;
|
|
70
74
|
prompt?: string;
|
|
71
75
|
}
|
|
@@ -240,6 +244,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
240
244
|
const current = readManifest(workspaceDir, profile);
|
|
241
245
|
const next: ActiveSkillManifest = { format: 2, entries: {} };
|
|
242
246
|
const failed: AgentWorkspaceSkillChanges['failed'] = [];
|
|
247
|
+
const skipped: SkillHostSkip[] = [];
|
|
243
248
|
const hashDirectory = dependencies.hashDirectory ?? hashAgentSkillDirectory;
|
|
244
249
|
const overwriteTarget = dependencies.overwriteTarget ?? overwriteAgentSkillTarget;
|
|
245
250
|
const linkTarget = dependencies.linkTarget ?? linkAgentSkillTarget;
|
|
@@ -393,8 +398,12 @@ export function syncAgentWorkspaceSkills(
|
|
|
393
398
|
continue;
|
|
394
399
|
}
|
|
395
400
|
let linkFailed = false;
|
|
396
|
-
|
|
397
|
-
|
|
401
|
+
const hostTargets = targets(name);
|
|
402
|
+
const realTargets = realSkillTargets(hostTargets);
|
|
403
|
+
if (realTargets.length) skipped.push(skillHostSkip(name, realTargets));
|
|
404
|
+
for (const target of hostTargets) {
|
|
405
|
+
if (realTargets.includes(target)) continue;
|
|
406
|
+
const result = realTargets.length ? unlinkTarget(target) : linkTarget(canonical, target);
|
|
398
407
|
if (!result.ok) {
|
|
399
408
|
linkFailed = true;
|
|
400
409
|
failed.push({ name, action: previous ? 'update' : 'add', error: resultError(result) });
|
|
@@ -471,7 +480,10 @@ export function syncAgentWorkspaceSkills(
|
|
|
471
480
|
for (const [name] of Object.entries(current.entries)) {
|
|
472
481
|
if (name === 'clawclaw' || desired.has(name)) continue;
|
|
473
482
|
let failedRemoval = false;
|
|
483
|
+
const realTargets = realSkillTargets(targets(name));
|
|
484
|
+
if (realTargets.length) skipped.push(skillHostSkip(name, realTargets));
|
|
474
485
|
for (const target of targets(name)) {
|
|
486
|
+
if (realTargets.includes(target)) continue;
|
|
475
487
|
const result = unlinkTarget(target);
|
|
476
488
|
if (!result.ok) {
|
|
477
489
|
failedRemoval = true;
|
|
@@ -479,9 +491,17 @@ export function syncAgentWorkspaceSkills(
|
|
|
479
491
|
}
|
|
480
492
|
}
|
|
481
493
|
if (!failedRemoval) removed.push(name);
|
|
482
|
-
|
|
494
|
+
if (failedRemoval) next.entries[name] = current.entries[name]!;
|
|
483
495
|
}
|
|
484
496
|
|
|
497
|
+
// Unequipping may happen before a first successful load created a manifest.
|
|
498
|
+
// Keep reporting host-owned paths even in that case, without reopening selection.
|
|
499
|
+
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
500
|
+
if (entry.type !== 'skill' || entry.runtimeId === 'clawclaw'
|
|
501
|
+
|| desired.has(entry.runtimeId) || current.entries[entry.runtimeId]) continue;
|
|
502
|
+
const realTargets = realSkillTargets(targets(entry.runtimeId));
|
|
503
|
+
if (realTargets.length) skipped.push(skillHostSkip(entry.runtimeId, realTargets));
|
|
504
|
+
}
|
|
485
505
|
writeManifest(workspaceDir, profile, next);
|
|
486
506
|
return {
|
|
487
507
|
added,
|
|
@@ -490,6 +510,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
490
510
|
unchanged,
|
|
491
511
|
preservedModified,
|
|
492
512
|
failed,
|
|
513
|
+
skipped,
|
|
493
514
|
requiresUserConfirmation: false,
|
|
494
515
|
};
|
|
495
516
|
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { basename, dirname, extname, join, relative } from 'node:path';
|
|
9
9
|
import { createHash } from 'node:crypto';
|
|
10
10
|
import { ApiError } from './http-transport.js';
|
|
11
|
+
import { hubErrorFields, type HubErrorFields } from './hub-errors.js';
|
|
11
12
|
import type { AuthProfile } from './auth.js';
|
|
12
13
|
import {
|
|
13
14
|
capabilityWorkspacePath,
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
} from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
36
37
|
|
|
37
38
|
export interface CapabilityCloudSyncChange {
|
|
39
|
+
skill_name?: string | null;
|
|
38
40
|
type: CapabilityWorkspaceType;
|
|
39
41
|
id: string;
|
|
40
42
|
action: 'create' | 'version' | 'fork';
|
|
@@ -50,7 +52,7 @@ export interface CapabilityCloudSyncConflict {
|
|
|
50
52
|
reason: 'local_and_cloud_changed';
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
export interface CapabilityCloudSyncFailure {
|
|
55
|
+
export interface CapabilityCloudSyncFailure extends Partial<HubErrorFields> {
|
|
54
56
|
type: CapabilityWorkspaceType;
|
|
55
57
|
id: string;
|
|
56
58
|
action: 'create' | 'version' | 'fork' | 'equipment';
|
|
@@ -280,6 +282,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
280
282
|
id: entry.runtimeId,
|
|
281
283
|
action: 'fork',
|
|
282
284
|
error: `fork_source_backpack_restore_failed:${error instanceof Error ? error.message : String(error)}`,
|
|
285
|
+
...hubErrorFields(error),
|
|
283
286
|
});
|
|
284
287
|
continue;
|
|
285
288
|
}
|
|
@@ -294,6 +297,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
294
297
|
id: entry.runtimeId,
|
|
295
298
|
action: entry.hub?.publisher === 'self' ? 'version' : entry.hub ? 'fork' : 'create',
|
|
296
299
|
error: error instanceof Error ? error.message : String(error),
|
|
300
|
+
...hubErrorFields(error),
|
|
297
301
|
});
|
|
298
302
|
continue;
|
|
299
303
|
}
|
|
@@ -419,6 +423,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
419
423
|
action,
|
|
420
424
|
resource_id: mutation.resourceId,
|
|
421
425
|
version_id: mutation.versionId,
|
|
426
|
+
...(entry.type === 'skill' && mutation.skillName !== undefined ? { skill_name: mutation.skillName } : {}),
|
|
422
427
|
...(workspaceItemId ? { workspace_item_id: workspaceItemId } : {}),
|
|
423
428
|
});
|
|
424
429
|
if (!workspaceItemId) {
|
|
@@ -432,7 +437,8 @@ export async function syncCapabilitiesToCloud(
|
|
|
432
437
|
result.uploaded.at(-1)!.workspace_item_id = workspaceItemId;
|
|
433
438
|
} catch (error) {
|
|
434
439
|
result.failed.push({ type: entry.type, id: entry.runtimeId, action: 'equipment',
|
|
435
|
-
error: `resource_created_workspace_lookup_failed:${error instanceof Error ? error.message : String(error)}
|
|
440
|
+
error: `resource_created_workspace_lookup_failed:${error instanceof Error ? error.message : String(error)}`,
|
|
441
|
+
...hubErrorFields(error) });
|
|
436
442
|
}
|
|
437
443
|
}
|
|
438
444
|
if (action === 'create' && entry.origin === 'local' && entry.selection !== 'pending' && workspaceItemId) {
|
|
@@ -447,6 +453,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
447
453
|
error: `capability_cloud_equipment_sync_failed:${
|
|
448
454
|
error instanceof Error ? error.message : String(error)
|
|
449
455
|
}`,
|
|
456
|
+
...hubErrorFields(error),
|
|
450
457
|
});
|
|
451
458
|
}
|
|
452
459
|
}
|
|
@@ -467,6 +474,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
467
474
|
id: entry.runtimeId,
|
|
468
475
|
action: 'fork',
|
|
469
476
|
error: `fork_source_backpack_restore_failed:${error instanceof Error ? error.message : String(error)}`,
|
|
477
|
+
...hubErrorFields(error),
|
|
470
478
|
});
|
|
471
479
|
}
|
|
472
480
|
}
|
|
@@ -476,6 +484,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
476
484
|
id: entry.runtimeId,
|
|
477
485
|
action,
|
|
478
486
|
error: error instanceof Error ? error.message : String(error),
|
|
487
|
+
...hubErrorFields(error),
|
|
479
488
|
});
|
|
480
489
|
}
|
|
481
490
|
}
|
|
@@ -72,7 +72,7 @@ const MODULE_CONTRACTS: Record<ModuleCapabilityType, {
|
|
|
72
72
|
perception: {
|
|
73
73
|
expectedImport: '@myclaw163/clawclaw-cli/perception-plugin',
|
|
74
74
|
safeImport: /(?:@myclaw163\/clawclaw-cli|clawclaw-cli)\/perception-plugin/,
|
|
75
|
-
defaultClass: /export\s+default\s+class(?:\s+[A-Za-z_$][\w$]*)?\s+extends\s+(?:ClawclawPerception|ClawclawParallelPerception)/,
|
|
75
|
+
defaultClass: /export\s+default\s+class(?:\s+[A-Za-z_$][\w$]*)?\s+extends\s+(?:ClawclawPerception|ClawclawParallelPerception|ClawclawReminder)/,
|
|
76
76
|
manifest: /\bstatic\s+(?:readonly\s+)?manifest\s*=\s*\{/,
|
|
77
77
|
},
|
|
78
78
|
trigger: {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ApiError, formatApiError } from './http-transport.js';
|
|
2
|
+
import { invalidAccountMessage } from './account-guidance.js';
|
|
3
|
+
import { hubErrorFields } from './hub-errors.js';
|
|
4
|
+
|
|
5
|
+
export class CommandOutputError extends Error {
|
|
6
|
+
constructor(message: string, public readonly output: Record<string, unknown>) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'CommandOutputError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function formatCommandError(error: unknown): string {
|
|
13
|
+
if (error instanceof CommandOutputError) return JSON.stringify(error.output, null, 2);
|
|
14
|
+
if (error instanceof ApiError && error.status === 401) return invalidAccountMessage();
|
|
15
|
+
const hub = hubErrorFields(error);
|
|
16
|
+
if (hub) return JSON.stringify({ error: 'api_error', ...hub }, null, 2);
|
|
17
|
+
if (error instanceof ApiError) {
|
|
18
|
+
// HTTP 422 is a validation failure, not evidence of a malformed API key.
|
|
19
|
+
return formatApiError(error);
|
|
20
|
+
}
|
|
21
|
+
return error instanceof Error ? error.message : String(error);
|
|
22
|
+
}
|
package/src/lib/hub-client.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AuthStore } from './auth.js';
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { ServerRegistry } from './server-registry.js';
|
|
4
4
|
import { HttpTransport } from './http-transport.js';
|
|
5
|
+
import { isWorkspaceRevisionConflict } from './hub-errors.js';
|
|
5
6
|
|
|
6
7
|
export type ResourceType = 'skill' | 'strategy' | 'persona' | 'perception';
|
|
7
8
|
|
|
@@ -12,6 +13,7 @@ export interface ResourceStats {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export interface ResourceSummary {
|
|
16
|
+
skillName?: string | null;
|
|
15
17
|
id: string;
|
|
16
18
|
forkedFromResourceId?: string;
|
|
17
19
|
type: ResourceType;
|
|
@@ -61,6 +63,7 @@ export interface ListOptions {
|
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
export interface WorkspaceResourceSummary {
|
|
66
|
+
skillName?: string | null;
|
|
64
67
|
workspaceItemId: string;
|
|
65
68
|
forkedFromResourceId?: string;
|
|
66
69
|
resourceId: string;
|
|
@@ -127,6 +130,7 @@ interface RawVersion {
|
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
interface RawResource {
|
|
133
|
+
skill_name?: string | null;
|
|
130
134
|
id?: string;
|
|
131
135
|
forked_from_resource_id?: string | null;
|
|
132
136
|
resource_id: string;
|
|
@@ -144,6 +148,7 @@ interface RawResource {
|
|
|
144
148
|
}
|
|
145
149
|
|
|
146
150
|
interface RawWorkspaceItem {
|
|
151
|
+
skill_name?: string | null;
|
|
147
152
|
workspace_item_id: string;
|
|
148
153
|
forked_from_resource_id?: string | null;
|
|
149
154
|
resource_id: string;
|
|
@@ -169,6 +174,7 @@ export interface HubUploadedSourceFile {
|
|
|
169
174
|
}
|
|
170
175
|
|
|
171
176
|
export interface HubResourceMutationResult {
|
|
177
|
+
skillName?: string | null;
|
|
172
178
|
resourceId: string;
|
|
173
179
|
versionId: string;
|
|
174
180
|
workspaceItemId?: string;
|
|
@@ -188,6 +194,7 @@ function toSummary(resource: RawResource): ResourceSummary {
|
|
|
188
194
|
id: resource.resource_id ?? resource.id ?? '',
|
|
189
195
|
forkedFromResourceId: resource.forked_from_resource_id ?? undefined,
|
|
190
196
|
type: resource.resource_type,
|
|
197
|
+
skillName: resource.skill_name ?? null,
|
|
191
198
|
title: version.title,
|
|
192
199
|
description: version.description,
|
|
193
200
|
creator: owner.id ?? '',
|
|
@@ -321,6 +328,7 @@ export class HubClient {
|
|
|
321
328
|
forkedFromResourceId: item.forked_from_resource_id ?? undefined,
|
|
322
329
|
resourceId: item.resource_id,
|
|
323
330
|
resourceType: item.resource_type,
|
|
331
|
+
skillName: item.skill_name ?? null,
|
|
324
332
|
title: item.title ?? '',
|
|
325
333
|
versionId: item.version_id,
|
|
326
334
|
equipped: item.is_equipped === true,
|
|
@@ -358,11 +366,23 @@ export class HubClient {
|
|
|
358
366
|
return { updated: response.data.updated, versionId: response.data.version_id };
|
|
359
367
|
}
|
|
360
368
|
|
|
369
|
+
private async updateWorkspace<T>(path: string, body: unknown): Promise<T> {
|
|
370
|
+
try {
|
|
371
|
+
return await this.http.post<T>(path, body);
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (!isWorkspaceRevisionConflict(error)) throw error;
|
|
374
|
+
// Refresh once, then retry only this explicit operation. No background
|
|
375
|
+
// replay, extra request fields, or name-conflict replacement is allowed.
|
|
376
|
+
await this.http.get(`${BASE}/workspace/loadout`);
|
|
377
|
+
return this.http.post<T>(path, body);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
361
381
|
async updateWorkspaceEquipment(
|
|
362
382
|
workspaceItemId: string,
|
|
363
383
|
equipped: boolean,
|
|
364
384
|
): Promise<{ workspaceItemId: string; equipped: boolean; revision: number; changed: boolean }> {
|
|
365
|
-
const response = await this.
|
|
385
|
+
const response = await this.updateWorkspace<Envelope<{
|
|
366
386
|
workspace_item_id: string;
|
|
367
387
|
is_equipped: boolean;
|
|
368
388
|
revision: number;
|
|
@@ -387,7 +407,7 @@ export class HubClient {
|
|
|
387
407
|
if (input.strategyItemIds !== undefined) body.strategy_item_ids = input.strategyItemIds;
|
|
388
408
|
if (input.personaItemIds !== undefined) body.persona_item_ids = input.personaItemIds;
|
|
389
409
|
if (input.perceptionItemIds !== undefined) body.perception_item_ids = input.perceptionItemIds;
|
|
390
|
-
const response = await this.
|
|
410
|
+
const response = await this.updateWorkspace<Envelope<{ revision: number; changed: boolean }>>(
|
|
391
411
|
`${BASE}/workspace/loadout/update`,
|
|
392
412
|
body,
|
|
393
413
|
);
|
|
@@ -462,6 +482,7 @@ export class HubClient {
|
|
|
462
482
|
resource_id: string;
|
|
463
483
|
latest_version: { id: string };
|
|
464
484
|
workspace_item_id?: string;
|
|
485
|
+
skill_name?: string | null;
|
|
465
486
|
}>>(`${BASE}/resources/create`, {
|
|
466
487
|
resource_type: input.resourceType,
|
|
467
488
|
version_number: '1.0.0',
|
|
@@ -477,6 +498,7 @@ export class HubClient {
|
|
|
477
498
|
return {
|
|
478
499
|
resourceId: response.data.resource_id,
|
|
479
500
|
versionId: response.data.latest_version.id,
|
|
501
|
+
skillName: response.data.skill_name ?? null,
|
|
480
502
|
...(response.data.workspace_item_id ? { workspaceItemId: response.data.workspace_item_id } : {}),
|
|
481
503
|
};
|
|
482
504
|
}
|
|
@@ -494,6 +516,7 @@ export class HubClient {
|
|
|
494
516
|
const response = await this.http.post<Envelope<{
|
|
495
517
|
resource_id: string;
|
|
496
518
|
latest_version: { id: string };
|
|
519
|
+
skill_name?: string | null;
|
|
497
520
|
}>>(`${BASE}/resources/version/create`, {
|
|
498
521
|
resource_id: input.resourceId,
|
|
499
522
|
base_version_id: input.baseVersionId,
|
|
@@ -509,6 +532,7 @@ export class HubClient {
|
|
|
509
532
|
return {
|
|
510
533
|
resourceId: response.data.resource_id,
|
|
511
534
|
versionId: response.data.latest_version.id,
|
|
535
|
+
skillName: response.data.skill_name ?? null,
|
|
512
536
|
};
|
|
513
537
|
}
|
|
514
538
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ApiError, formatApiError } from './http-transport.js';
|
|
2
|
+
|
|
3
|
+
export interface HubErrorFields {
|
|
4
|
+
status: number;
|
|
5
|
+
code?: string;
|
|
6
|
+
message: string;
|
|
7
|
+
operation: string;
|
|
8
|
+
details?: Record<string, unknown>;
|
|
9
|
+
hint?: string;
|
|
10
|
+
retryable?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
14
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Preserve Hub business errors across direct commands and per-resource sync failures. */
|
|
18
|
+
export function hubErrorFields(error: unknown): HubErrorFields | undefined {
|
|
19
|
+
if (!(error instanceof ApiError) || !error.path.startsWith('/api/v1/hub/')) return undefined;
|
|
20
|
+
let body: unknown;
|
|
21
|
+
try { body = JSON.parse(error.body); } catch { /* retain the original response below */ }
|
|
22
|
+
const payload = record(body) && record(body.error) ? body.error : undefined;
|
|
23
|
+
const code = typeof payload?.code === 'string' ? payload.code : undefined;
|
|
24
|
+
const operation = error.path.split('?')[0]!;
|
|
25
|
+
const equipment = operation === '/api/v1/hub/workspace/equipment/update'
|
|
26
|
+
|| operation === '/api/v1/hub/workspace/loadout/update';
|
|
27
|
+
const create = operation === '/api/v1/hub/resources/create';
|
|
28
|
+
const version = operation === '/api/v1/hub/resources/version/create';
|
|
29
|
+
const result: HubErrorFields = {
|
|
30
|
+
status: error.status,
|
|
31
|
+
...(code ? { code } : {}),
|
|
32
|
+
message: typeof payload?.message === 'string' ? payload.message : formatApiError(error),
|
|
33
|
+
operation,
|
|
34
|
+
...(record(payload?.details) ? { details: payload.details } : {}),
|
|
35
|
+
};
|
|
36
|
+
if ((create || version) && code === 'INVALID_SKILL_NAME') {
|
|
37
|
+
result.hint = '请检查根 SKILL.md 的 UTF-8、YAML frontmatter 和 name,按服务端原因修正后再提交;本地文件已保留。';
|
|
38
|
+
} else if (create && code === 'SKILL_NAME_CONFLICT') {
|
|
39
|
+
result.hint = '你已有同名 Skill。请到 Hub 确认已有资源;更新它需明确选择该资源,新建则需修改新 Skill 的 name。不要按同名自动关联、覆盖或再次 fork。';
|
|
40
|
+
} else if (version && code === 'SKILL_NAME_IMMUTABLE') {
|
|
41
|
+
result.hint = '已有 Skill 不能通过新版本改名。请恢复原 name 后发版,或明确新建另一资源;修改 Hub 标题不能解决。本地文件已保留。';
|
|
42
|
+
} else if (version && code === 'SKILL_NAME_KEY_MISSING') {
|
|
43
|
+
result.hint = '该历史 Skill 尚未完成名称回填,请联系 Hub 运维处理后再发版;不要反复重试,本地修改已保留。';
|
|
44
|
+
} else if (equipment && code === 'SKILL_NAME_CONFLICT') {
|
|
45
|
+
result.hint = '已装配另一件同名 Skill。请用户到 Hub 处理装配冲突,完成后重新运行 ccl load;CCL 不自动卸载或替换任何 Skill,也不要用卸载后重装绕过此提示。';
|
|
46
|
+
} else if (equipment && code === 'INVALID_LOADOUT') {
|
|
47
|
+
result.hint = '装配选择无效,可能是同名 Skill、超出上限或类型不匹配。请按服务端原因到 Hub 修正选择,再运行 ccl load。';
|
|
48
|
+
} else if (equipment && code === 'WORKSPACE_REVISION_CONFLICT') {
|
|
49
|
+
result.hint = 'Workspace 装配正在被并发修改。请刷新最新装配状态后再重试本次明确操作;不要反复重放旧装配。';
|
|
50
|
+
result.retryable = true;
|
|
51
|
+
}
|
|
52
|
+
if (result.hint && result.retryable === undefined) result.retryable = false;
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isWorkspaceRevisionConflict(error: unknown): boolean {
|
|
57
|
+
const fields = hubErrorFields(error);
|
|
58
|
+
return fields?.status === 409 && fields.code === 'WORKSPACE_REVISION_CONFLICT'
|
|
59
|
+
&& fields.retryable === true;
|
|
60
|
+
}
|
|
@@ -61,7 +61,7 @@ export function readWorkspacePerceptionConfig(
|
|
|
61
61
|
];
|
|
62
62
|
const eventTypes = new Set<string>([
|
|
63
63
|
...CLAWCLAW_VISUAL_EVENT_TYPES,
|
|
64
|
-
...sources.flatMap((source) => [...source.manifest.produces]),
|
|
64
|
+
...sources.filter(source => !source.reminder).flatMap((source) => [...source.manifest.produces]),
|
|
65
65
|
]);
|
|
66
66
|
let maxBackfillVisualFrames: number | undefined;
|
|
67
67
|
if (configuredMaxBackfillVisualFrames !== undefined) {
|
package/src/lib/skill-host.ts
CHANGED
|
@@ -221,3 +221,29 @@ export function unlinkAgentSkillTarget(targetPath: string): SkillHostMutationRes
|
|
|
221
221
|
export function unregisterAgentSkill(name: string): SkillHostMutationResult {
|
|
222
222
|
return runSkillsCli(['remove', name, '-g', '-y']);
|
|
223
223
|
}
|
|
224
|
+
|
|
225
|
+
/** A host-owned real directory is never overwritten or removed by CCL. */
|
|
226
|
+
export function realSkillTargets(targets: readonly string[]): string[] {
|
|
227
|
+
return targets.filter(target => {
|
|
228
|
+
try { return !lstatSync(target).isSymbolicLink(); }
|
|
229
|
+
catch (error) {
|
|
230
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false;
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface SkillHostSkip {
|
|
237
|
+
name: string;
|
|
238
|
+
reason: 'local_skill_directory_exists';
|
|
239
|
+
paths: string[];
|
|
240
|
+
blocking: false;
|
|
241
|
+
message: string;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function skillHostSkip(name: string, paths: string[]): SkillHostSkip {
|
|
245
|
+
return {
|
|
246
|
+
name, reason: 'local_skill_directory_exists', paths, blocking: false,
|
|
247
|
+
message: 'Same-name local Skill paths were preserved. CCL Skill linking was skipped; gameplay may continue. The Agent host may still load the local Skill.',
|
|
248
|
+
};
|
|
249
|
+
}
|
|
@@ -828,6 +828,7 @@ export async function runClawclawOwner(
|
|
|
828
828
|
observability: telemetry,
|
|
829
829
|
runtimeEpochPlugins: epochPlugins,
|
|
830
830
|
visualEventDelivery: perceptionConfig.events.delivery,
|
|
831
|
+
reminderDelivery: true,
|
|
831
832
|
visualEventTypes: assembly.perception.produces.events,
|
|
832
833
|
behaviorEventTypes: assembly.behavior.produces?.events ?? [],
|
|
833
834
|
});
|
|
@@ -957,7 +958,8 @@ export async function runClawclawOwner(
|
|
|
957
958
|
? resolveClawclawResourceMetadata(source, DESKTOP_RESOURCE_LOCALE)
|
|
958
959
|
: null;
|
|
959
960
|
})(),
|
|
960
|
-
perceptions: assembly.perception.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
961
|
+
perceptions: [...assembly.perception.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
|
|
962
|
+
...assembly.reminders.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE)],
|
|
961
963
|
}),
|
|
962
964
|
eventDescriptors: () => assembly.perception
|
|
963
965
|
.localizedEventDescriptors(DESKTOP_RESOURCE_LOCALE)
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { GameClient } from '../../../lib/game-client.js';
|
|
2
|
+
import { ClawclawReminderPlugin, CLAWCLAW_REMINDER_PLUGIN_ID } from './derived-event/reminder-plugin.js';
|
|
3
|
+
import { listClawclawPerceptionSources } from './perception/perception-source.js';
|
|
4
|
+
import { DEFAULT_PERCEPTION_MODULES } from './perception/official-module-ids.js';
|
|
2
5
|
import type { RuntimeEpochPlugin } from '../../framework/plugins/index.js';
|
|
3
6
|
import {
|
|
4
7
|
CLAWCLAW_ACTION_PLUGIN_ID,
|
|
@@ -50,6 +53,7 @@ export interface ClawclawPluginAssembly {
|
|
|
50
53
|
action: ClawclawActionPlugin;
|
|
51
54
|
gameQuery: ClawclawGameQueryPlugin;
|
|
52
55
|
perception: ClawclawPerceptionPlugin;
|
|
56
|
+
reminders: ClawclawReminderPlugin;
|
|
53
57
|
trigger: ClawclawTriggerPlugin;
|
|
54
58
|
behavior: ClawclawBehaviorPlugin;
|
|
55
59
|
mailbox: ClawclawMailboxPlugin;
|
|
@@ -83,6 +87,16 @@ export function assembleClawclawPlugins(
|
|
|
83
87
|
if (!plugins.some((plugin) => plugin.id === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID)) {
|
|
84
88
|
plugins.push(new ClawclawDerivedEventPlugin());
|
|
85
89
|
}
|
|
90
|
+
const configuredReminders = plugins.find(plugin => plugin.id === CLAWCLAW_REMINDER_PLUGIN_ID);
|
|
91
|
+
if (configuredReminders && !(configuredReminders instanceof ClawclawReminderPlugin)) {
|
|
92
|
+
throw new Error(`Runtime Plugin ${CLAWCLAW_REMINDER_PLUGIN_ID} is not a ClawclawReminderPlugin.`);
|
|
93
|
+
}
|
|
94
|
+
const selected = new Set(options.perception?.modules ?? DEFAULT_PERCEPTION_MODULES);
|
|
95
|
+
const reminders = configuredReminders as ClawclawReminderPlugin | undefined ?? new ClawclawReminderPlugin({
|
|
96
|
+
sources: (options.perception?.moduleSources ?? listClawclawPerceptionSources(options.perception?.workspaceDir))
|
|
97
|
+
.filter(source => source.reminder && selected.has(source.id)),
|
|
98
|
+
});
|
|
99
|
+
if (!configuredReminders) plugins.push(reminders);
|
|
86
100
|
|
|
87
101
|
const configuredGameQuery = plugins.find((plugin) => plugin.id === CLAWCLAW_GAME_QUERY_PLUGIN_ID);
|
|
88
102
|
if (configuredGameQuery && !(configuredGameQuery instanceof ClawclawGameQueryPlugin)) {
|
|
@@ -123,6 +137,7 @@ export function assembleClawclawPlugins(
|
|
|
123
137
|
after: [
|
|
124
138
|
CLAWCLAW_ACTION_PLUGIN_ID,
|
|
125
139
|
CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
|
|
140
|
+
CLAWCLAW_REMINDER_PLUGIN_ID,
|
|
126
141
|
CLAWCLAW_GAME_QUERY_PLUGIN_ID,
|
|
127
142
|
CLAWCLAW_PERCEPTION_PLUGIN_ID,
|
|
128
143
|
CLAWCLAW_TRIGGER_PLUGIN_ID,
|
|
@@ -146,11 +161,11 @@ export function assembleClawclawPlugins(
|
|
|
146
161
|
}
|
|
147
162
|
const eventProducers = plugins
|
|
148
163
|
.filter((plugin) => plugin.id !== CLAWCLAW_MAILBOX_PLUGIN_ID)
|
|
149
|
-
.filter((plugin) => (plugin.produces?.events?.length ?? 0) > 0)
|
|
164
|
+
.filter((plugin) => (plugin.produces?.events?.length ?? 0) > 0 || (plugin.controlsEventDelivery?.length ?? 0) > 0)
|
|
150
165
|
.map((plugin) => plugin.id);
|
|
151
166
|
const mailbox = configuredMailbox as ClawclawMailboxPlugin | undefined
|
|
152
167
|
?? new ClawclawMailboxPlugin({ after: eventProducers });
|
|
153
168
|
if (!configuredMailbox) plugins.push(mailbox);
|
|
154
169
|
|
|
155
|
-
return { plugins, action, gameQuery, perception, trigger, behavior, mailbox };
|
|
170
|
+
return { plugins, action, gameQuery, perception, reminders, trigger, behavior, mailbox };
|
|
156
171
|
}
|
|
@@ -13,6 +13,16 @@ interface ParsedValue {
|
|
|
13
13
|
|
|
14
14
|
class LiteralParseError extends Error {}
|
|
15
15
|
|
|
16
|
+
/** Shared, non-evaluating parser for a complete module manifest literal. */
|
|
17
|
+
export function parseLiteralModuleManifest(source: string): Record<string, unknown> | null {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = parseValue(source, skipTrivia(source, 0));
|
|
20
|
+
if (skipTrivia(source, parsed.next) !== source.length || !parsed.value
|
|
21
|
+
|| typeof parsed.value !== 'object' || Array.isArray(parsed.value)) return null;
|
|
22
|
+
return parsed.value as Record<string, unknown>;
|
|
23
|
+
} catch { return null; }
|
|
24
|
+
}
|
|
25
|
+
|
|
16
26
|
function skipTrivia(source: string, start: number): number {
|
|
17
27
|
let cursor = start;
|
|
18
28
|
while (cursor < source.length) {
|