@myclaw163/clawclaw-cli 0.10.15 → 0.10.16

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.
Files changed (50) hide show
  1. package/README.md +1 -1
  2. package/cli-runtime/runtime/clawclaw/behavior-reflex-control.js +27 -36
  3. package/cli-runtime/runtime/clawclaw/behavior-trigger.js +25 -46
  4. package/cli-runtime/runtime/clawclaw/owner.js +7 -6
  5. package/cli-runtime/runtime/clawclaw/plugins/assembly.js +8 -7
  6. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-source.js +6 -5
  7. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +5 -2
  8. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-runner.js +2 -1
  9. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.js +7 -1
  10. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.ts +7 -1
  11. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-module-loader.js +7 -17
  12. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-plugin.js +3 -30
  13. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.js +0 -2
  14. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +0 -2
  15. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +58 -1
  16. package/docs/custom-modules/README.md +1 -2
  17. package/docs/custom-modules/api-reference.md +8 -10
  18. package/docs/custom-modules/behavior.md +21 -23
  19. package/docs/custom-modules/examples/auto-escape.ts +17 -19
  20. package/docs/custom-modules/perception.md +2 -2
  21. package/docs/runtime/README.md +1 -1
  22. package/docs/runtime/behavior-runtime.md +4 -5
  23. package/docs/runtime/components-and-boundaries.md +4 -5
  24. package/docs/runtime/events-and-state.md +1 -1
  25. package/docs/runtime/owner-lifecycle-and-observability.md +2 -2
  26. package/docs/user-guide/README.md +1 -1
  27. package/docs/user-guide/api-reference.md +8 -10
  28. package/docs/user-guide/behavior.md +21 -23
  29. package/docs/user-guide/perception.md +2 -2
  30. package/package.json +1 -1
  31. package/skills/clawclaw/SKILL.md +3 -3
  32. package/skills/clawclaw/references/BEHAVIORS.md +1 -1
  33. package/skills/clawclaw-creator/SKILL.md +1 -1
  34. package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +21 -23
  35. package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +8 -10
  36. package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +1 -2
  37. package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +2 -2
  38. package/src/runtime/clawclaw/behavior-reflex-control.ts +26 -22
  39. package/src/runtime/clawclaw/behavior-trigger.ts +20 -41
  40. package/src/runtime/clawclaw/owner.ts +7 -6
  41. package/src/runtime/clawclaw/plugins/assembly.ts +11 -8
  42. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +7 -6
  43. package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +6 -2
  44. package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +2 -1
  45. package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +7 -1
  46. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +1 -0
  47. package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +8 -19
  48. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +4 -37
  49. package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +0 -2
  50. package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +0 -2
@@ -1,5 +1,5 @@
1
- import { createHash, randomUUID } from 'node:crypto';
2
- import { readFileSync, realpathSync } from 'node:fs';
1
+ import { randomUUID } from 'node:crypto';
2
+ import { realpathSync } from 'node:fs';
3
3
  import { isDeepStrictEqual } from 'node:util';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import {
@@ -14,7 +14,6 @@ import {
14
14
  runtimeModuleThreadLoaderConfig,
15
15
  type RuntimeModuleThreadLoaderConfig,
16
16
  } from '../../../framework/modules/runtime-module-loader.js';
17
- import { normalizeStrategyTriggerManifest } from '../../behavior-trigger.js';
18
17
  import { assertPluginApiVersion } from '../plugin-api-version.js';
19
18
  import type { ResolvedClawclawTriggerSource } from './trigger-source.js';
20
19
 
@@ -89,15 +88,13 @@ export function validateClawclawTriggerModule(
89
88
  loaded: Readonly<Record<string, unknown>>,
90
89
  source: ResolvedClawclawTriggerSource,
91
90
  ): ClawclawTriggerClass {
92
- const entry = source.embedded ? 'Trigger' : 'default';
91
+ const entry = 'default';
93
92
  if (typeof loaded[entry] !== 'function') {
94
- throw new Error(`Trigger module '${source.id}' has no ${entry} class.`);
93
+ throw new Error(`Trigger module '${source.id}' has no default class.`);
95
94
  }
96
95
  const ModuleClass = loaded[entry] as unknown as ClawclawTriggerClass;
97
- const manifest = source.embedded
98
- ? normalizeStrategyTriggerManifest(ModuleClass.manifest)
99
- : normalizedManifest(ModuleClass.manifest);
100
- if (!isDeepStrictEqual(manifest, source.embedded?.manifest ?? source.manifest)) {
96
+ const manifest = normalizedManifest(ModuleClass.manifest);
97
+ if (!isDeepStrictEqual(manifest, source.manifest)) {
101
98
  throw new Error(`Trigger module '${source.id}' changed after static discovery.`);
102
99
  }
103
100
  return ModuleClass;
@@ -105,12 +102,6 @@ export function validateClawclawTriggerModule(
105
102
 
106
103
 
107
104
 
108
- export function assertTriggerSourceDigest(source: ResolvedClawclawTriggerSource): void {
109
- if (source.embedded && createHash('sha256').update(readFileSync(source.sourcePath)).digest('hex') !== source.embedded.sha256) {
110
- throw new Error('strategy_trigger_source_changed');
111
- }
112
- }
113
-
114
105
  /** One Runtime-scoped direct importer. Disabled Trigger sources never reach it. */
115
106
  export class TriggerModuleLoader {
116
107
  private readonly runtimeId = randomUUID();
@@ -141,10 +132,8 @@ export class TriggerModuleLoader {
141
132
  }
142
133
  let pending = this.loaded.get(source.id);
143
134
  if (pending) return pending;
144
- pending = Promise.resolve().then(() => {
145
- assertTriggerSourceDigest(source);
146
- return importRuntimeModule(new URL(this.sourceUrl(source)));
147
- }).then((loaded) => validateClawclawTriggerModule(loaded, source));
135
+ pending = importRuntimeModule(new URL(this.sourceUrl(source)))
136
+ .then((loaded) => validateClawclawTriggerModule(loaded, source));
148
137
  this.loaded.set(source.id, pending);
149
138
  return pending;
150
139
  }
@@ -1,4 +1,3 @@
1
- import { isDeepStrictEqual } from 'node:util';
2
1
  import { isNotificationTurn } from '../../notification-turn.js';
3
2
  import type {
4
3
  ClawclawTrigger,
@@ -47,7 +46,6 @@ export const DEFAULT_TRIGGER_PLUGIN_TIMEOUT_MS = 2_000;
47
46
  interface EffectiveTriggerConfig {
48
47
  readonly source: ResolvedClawclawTriggerSource;
49
48
  readonly enabled: boolean;
50
- readonly waitingForInput: boolean;
51
49
  readonly scope?: Readonly<{ sessionId: string; segmentId: string }>;
52
50
  readonly input: Readonly<Record<string, unknown>>;
53
51
  readonly behavior: string;
@@ -129,10 +127,7 @@ function normalizeRegistration(value: ClawclawTriggerRegistration): EffectiveTri
129
127
  const { source } = value;
130
128
  const manifest = source.manifest;
131
129
  if (!source || source.id !== manifest.id) throw new Error('trigger_source_identity_invalid');
132
- const input = source.embedded || value.enabled
133
- ? normalizeBehaviorInput(value.input ?? {}, manifest.inputs, { allowMissingRequired: !!source.embedded })
134
- : Object.freeze(structuredClone(value.input ?? {}));
135
- const waitingForInput = !!source.embedded && manifest.inputs.some(field => field.required && !Object.hasOwn(input, field.id));
130
+ const input = value.enabled ? normalizeBehaviorInput(value.input ?? {}, manifest.inputs) : Object.freeze(structuredClone(value.input ?? {}));
136
131
  const behavior = value.behavior ?? manifest.defaultBehavior;
137
132
  const behaviorInput = {
138
133
  ...structuredClone(manifest.defaultBehaviorInput),
@@ -158,7 +153,6 @@ function normalizeRegistration(value: ClawclawTriggerRegistration): EffectiveTri
158
153
  return Object.freeze({
159
154
  source,
160
155
  enabled: value.enabled,
161
- waitingForInput,
162
156
  scope: value.scope,
163
157
  input,
164
158
  behavior,
@@ -242,7 +236,7 @@ function triggerLifecycle(frame: Readonly<ObservationFrame>): string {
242
236
  }
243
237
 
244
238
  /**
245
- * Ordered Trigger host. Trigger and Perception project the same Source frame
239
+ * Compatibility host for previously installed standalone Trigger resources. Trigger and Perception project the same Source frame
246
240
  * independently and have no scheduler dependency on each other. Trigger
247
241
  * delegates at most one same-epoch Reflex request to the narrow Behavior
248
242
  * activation boundary.
@@ -263,7 +257,6 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
263
257
  readonly failurePolicy = 'failed_completion' as const;
264
258
 
265
259
  private registrations: Map<string, EffectiveTriggerConfig>;
266
- private readonly embeddedDefaults: ReadonlyMap<string, EffectiveTriggerConfig>;
267
260
  private readonly pendingActivations = new Map<string, string>();
268
261
  private readonly invalidInputs = new Map<string, string>();
269
262
  private readonly loader: TriggerModuleLoader;
@@ -283,7 +276,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
283
276
  private configGeneration = 1;
284
277
  private currentScope?: Readonly<{ sessionId: string; segmentId: string }>;
285
278
  private isEnabled(config: EffectiveTriggerConfig): boolean {
286
- return config.enabled && !config.waitingForInput && (!config.scope || config.scope.sessionId === this.currentScope?.sessionId
279
+ return config.enabled && (!config.scope || config.scope.sessionId === this.currentScope?.sessionId
287
280
  && config.scope.segmentId === this.currentScope?.segmentId);
288
281
  }
289
282
  private started = false;
@@ -296,7 +289,6 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
296
289
  this.memory = options.memory ?? new ClawclawStrategyMemory();
297
290
  this.after = [...(options.after ?? [])];
298
291
  this.registrations = normalizeRegistrations(options.triggers ?? []);
299
- this.embeddedDefaults = new Map([...this.registrations].filter(([, config]) => config.source.embedded));
300
292
  this.loader = options.loader ?? new TriggerModuleLoader();
301
293
  this.driver = options.driver;
302
294
  this.threaded = options.threaded ?? options.loader === undefined;
@@ -315,26 +307,6 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
315
307
 
316
308
  configure(triggers: readonly ClawclawTriggerRegistration[]): void {
317
309
  const next = normalizeRegistrations(triggers);
318
- for (const [id, config] of this.registrations) if (config.source.embedded) next.set(id, config);
319
- this.replaceRegistrations(next);
320
- }
321
-
322
- configureEmbedded(
323
- behaviorId: string, patch: { enabled?: boolean; input?: Readonly<Record<string, unknown>> },
324
- ): void {
325
- const id = 'behavior:' + behaviorId;
326
- const config = this.registrations.get(id);
327
- if (!config?.source.embedded) return;
328
- const updated = normalizeRegistration({ source: config.source,
329
- enabled: patch.enabled ?? config.enabled, input: patch.input ?? config.input });
330
- if (isDeepStrictEqual(config, updated)) return;
331
- const next = new Map(this.registrations);
332
- next.set(id, updated);
333
- this.replaceRegistrations(next);
334
- }
335
-
336
- /** Replace effective config and invalidate computations from the previous generation. */
337
- private replaceRegistrations(next: Map<string, EffectiveTriggerConfig>): void {
338
310
  for (const [id, config] of next) {
339
311
  if (config.enabled && !this.registrations.get(id)?.enabled) {
340
312
  const state = this.states.get(id);
@@ -361,8 +333,6 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
361
333
  descriptors(): readonly Readonly<{
362
334
  id: string;
363
335
  enabled: boolean;
364
- waitingForInput: boolean;
365
- embedded: boolean;
366
336
  armed: boolean;
367
337
  cooldownRemainingMs: number;
368
338
  behavior: string;
@@ -374,8 +344,6 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
374
344
  return [...this.registrations.values()].map((entry) => Object.freeze({
375
345
  id: entry.source.id,
376
346
  enabled: this.isEnabled(entry),
377
- waitingForInput: entry.waitingForInput,
378
- embedded: !!entry.source.embedded,
379
347
  armed: this.states.get(entry.source.id)?.armed ?? true,
380
348
  cooldownRemainingMs: Math.max(0, entry.cooldownMs - (Date.now() - (this.states.get(entry.source.id)?.lastAcceptedAtMs ?? 0))),
381
349
  behavior: entry.behavior,
@@ -852,7 +820,6 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
852
820
  this.states.clear();
853
821
  this.pendingActivations.clear();
854
822
  this.invalidInputs.clear();
855
- for (const [id, config] of this.embeddedDefaults) this.registrations.set(id, config);
856
823
  this.observationMemory.clear();
857
824
  this.clearFrameBoundary();
858
825
  this.threadPool = undefined;
@@ -863,7 +830,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
863
830
  }
864
831
 
865
832
  private memoryNamespace(source: ResolvedClawclawTriggerSource): string {
866
- return source.embedded ? source.id : 'trigger:' + source.id;
833
+ return 'trigger:' + source.id;
867
834
  }
868
835
 
869
836
  private async ensureThreadPool(
@@ -17,7 +17,6 @@ import {
17
17
  type ClawclawResourceLocalizations,
18
18
  type ClawclawTriggerManifest,
19
19
  type TriggerRearm,
20
- type StrategyTriggerManifest,
21
20
  } from '../../../../sdk/trigger-plugin/index.js';
22
21
  import {
23
22
  normalizeBehaviorInput,
@@ -42,7 +41,6 @@ export interface ResolvedClawclawTriggerSource {
42
41
  readonly manifest: ClawclawTriggerManifest;
43
42
  readonly sourcePath: string;
44
43
  readonly sourceRoot: string;
45
- readonly embedded?: Readonly<{ manifest: Required<Omit<StrategyTriggerManifest, 'id'>>; sha256: string }>;
46
44
  }
47
45
 
48
46
  interface ParsedValue {
@@ -10,7 +10,6 @@ import { createBehaviorReadApi } from '../../behavior-read-api.js';
10
10
  import { ClawclawBehaviorObservationMemory } from '../../behavior-observation-memory.js';
11
11
  import { assertRuntimeModuleOutputSize } from '../../../framework/modules/runtime-module-output.js';
12
12
  import {
13
- assertTriggerSourceDigest,
14
13
  validateClawclawTriggerModule,
15
14
  type TriggerThreadModuleSpec,
16
15
  } from './trigger-module-loader.js';
@@ -79,7 +78,6 @@ const modules = new Map<string, ClawclawTrigger>();
79
78
  const observationMemories = new Map<string, ClawclawBehaviorObservationMemory>();
80
79
  try {
81
80
  for (const spec of data.modules) {
82
- assertTriggerSourceDigest(spec.source);
83
81
  const loaded = await import(spec.sourceUrl) as Record<string, unknown>;
84
82
  const ModuleClass = validateClawclawTriggerModule(loaded, spec.source);
85
83
  classes.set(spec.triggerId, ModuleClass);