principles-disciple 1.201.0 → 1.202.0
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/dist/bundle.js +166 -166
- package/dist/commands/archive-impl.d.ts +18 -0
- package/dist/commands/capabilities.d.ts +3 -0
- package/dist/commands/context.d.ts +5 -0
- package/dist/commands/disable-impl.d.ts +22 -0
- package/dist/commands/evolution-status.d.ts +4 -0
- package/dist/commands/export.d.ts +2 -0
- package/dist/commands/focus.d.ts +14 -0
- package/dist/commands/pain.d.ts +6 -0
- package/dist/commands/principle-rollback.d.ts +4 -0
- package/dist/commands/promote-impl.d.ts +22 -0
- package/dist/commands/rollback-impl.d.ts +32 -0
- package/dist/commands/rollback.d.ts +19 -0
- package/dist/commands/samples.d.ts +2 -0
- package/dist/commands/strategy.d.ts +2 -0
- package/dist/commands/thinking-os.d.ts +2 -0
- package/dist/commands/workflow-debug.d.ts +4 -0
- package/dist/config/defaults/runtime.d.ts +58 -0
- package/dist/config/errors.d.ts +86 -0
- package/dist/config/index.d.ts +7 -0
- package/dist/constants/tools.d.ts +17 -0
- package/dist/core/__tests__/focus-history.test.d.ts +1 -0
- package/dist/core/behavior-example-pack-assembler.d.ts +38 -0
- package/dist/core/bootstrap-rules.d.ts +50 -0
- package/dist/core/code-implementation-storage.d.ts +71 -0
- package/dist/core/config-health.d.ts +17 -0
- package/dist/core/config-service.d.ts +15 -0
- package/dist/core/config.d.ts +111 -0
- package/dist/core/control-ui-db.d.ts +117 -0
- package/dist/core/correction-cue-learner.d.ts +33 -0
- package/dist/core/correction-types.d.ts +3 -0
- package/dist/core/detection-funnel.d.ts +47 -0
- package/dist/core/detection-service.d.ts +15 -0
- package/dist/core/dictionary-service.d.ts +15 -0
- package/dist/core/dictionary.d.ts +38 -0
- package/dist/core/empathy-keyword-matcher.d.ts +5 -0
- package/dist/core/empathy-types.d.ts +2 -0
- package/dist/core/event-log.d.ts +98 -0
- package/dist/core/evolution-engine.d.ts +119 -0
- package/dist/core/evolution-logger.d.ts +137 -0
- package/dist/core/evolution-reducer.d.ts +116 -0
- package/dist/core/evolution-types.d.ts +50 -0
- package/dist/core/file-store.d.ts +41 -0
- package/dist/core/focus-history.d.ts +50 -0
- package/dist/core/hygiene/tracker.d.ts +22 -0
- package/dist/core/init.d.ts +30 -0
- package/dist/core/intent-doc-reader-adapter.d.ts +36 -0
- package/dist/core/intent-doc-reader.d.ts +89 -0
- package/dist/core/migration.d.ts +6 -0
- package/dist/core/pain-diagnostic-gate.d.ts +45 -0
- package/dist/core/pain.d.ts +24 -0
- package/dist/core/path-resolver.d.ts +60 -0
- package/dist/core/paths.d.ts +59 -0
- package/dist/core/pd-config-loader.d.ts +96 -0
- package/dist/core/pd-task-reconciler.d.ts +89 -0
- package/dist/core/pd-task-service.d.ts +2 -0
- package/dist/core/pd-task-store.d.ts +5 -0
- package/dist/core/pd-task-types.d.ts +8 -0
- package/dist/core/principle-compiler/__tests__/compiler-replay-gate.test.d.ts +1 -0
- package/dist/core/principle-compiler/code-validator.d.ts +14 -0
- package/dist/core/principle-compiler/compiler.d.ts +45 -0
- package/dist/core/principle-compiler/index.d.ts +12 -0
- package/dist/core/principle-compiler/ledger-registrar.d.ts +28 -0
- package/dist/core/principle-compiler/template-generator.d.ts +7 -0
- package/dist/core/principle-injection.d.ts +10 -0
- package/dist/core/principle-internalization/filesystem-lifecycle-datasource.d.ts +15 -0
- package/dist/core/principle-internalization/lifecycle-read-model.d.ts +17 -0
- package/dist/core/principle-internalization/lifecycle-refresh.d.ts +2 -0
- package/dist/core/principle-internalization/principle-lifecycle-service.d.ts +28 -0
- package/dist/core/principle-training-state.d.ts +47 -0
- package/dist/core/principle-tree-ledger.d.ts +30 -0
- package/dist/core/profile.d.ts +62 -0
- package/dist/core/reflection/reflection-context.d.ts +31 -0
- package/dist/core/replay-engine.d.ts +12 -0
- package/dist/core/rule-context-assembler.d.ts +45 -0
- package/dist/core/rule-host.d.ts +178 -0
- package/dist/core/rule-implementation-runtime.d.ts +18 -0
- package/dist/core/runtime-v2-prompt-activation-reader.d.ts +22 -0
- package/dist/core/session-tracker.d.ts +119 -0
- package/dist/core/signal-collector-host.d.ts +113 -0
- package/dist/core/system-logger.d.ts +24 -0
- package/dist/core/thinking-models.d.ts +25 -0
- package/dist/core/thinking-os-parser.d.ts +35 -0
- package/dist/core/trajectory-types.d.ts +247 -0
- package/dist/core/trajectory.d.ts +279 -0
- package/dist/core/workflow-funnel-loader.d.ts +72 -0
- package/dist/core/workspace-context.d.ts +114 -0
- package/dist/core/workspace-dir-validation.d.ts +11 -0
- package/dist/core/workspace-guidance-migrator.d.ts +12 -0
- package/dist/hooks/after-tool-call-helpers.d.ts +97 -0
- package/dist/hooks/after-tool-call-types.d.ts +86 -0
- package/dist/hooks/gate-block-helper.d.ts +44 -0
- package/dist/hooks/gate.d.ts +16 -0
- package/dist/hooks/lifecycle.d.ts +5 -0
- package/dist/hooks/llm.d.ts +21 -0
- package/dist/hooks/message-sanitize.d.ts +24 -0
- package/dist/hooks/pain.d.ts +35 -0
- package/dist/hooks/prompt-helpers.d.ts +105 -0
- package/dist/hooks/prompt-types.d.ts +74 -0
- package/dist/hooks/prompt.d.ts +22 -0
- package/dist/hooks/raw-observation-adapter.d.ts +16 -0
- package/dist/hooks/raw-observation-types.d.ts +11 -0
- package/dist/hooks/trajectory-collector.d.ts +41 -0
- package/dist/hooks/trajectory-evidence.d.ts +11 -0
- package/dist/hooks/triage-adapter.d.ts +58 -0
- package/dist/hooks/trigger-cooldown-tracker.d.ts +42 -0
- package/dist/i18n/commands.d.ts +26 -0
- package/dist/index.d.ts +52 -0
- package/dist/openclaw-sdk.d.ts +338 -0
- package/dist/openclaw.plugin.json +1 -1
- package/dist/rulehost-evidence.d.ts +4 -0
- package/dist/service/correction-observer-service.d.ts +19 -0
- package/dist/service/evolution-dedup.d.ts +27 -0
- package/dist/service/evolution-worker.d.ts +105 -0
- package/dist/service/internalization-auto-consumer-service.d.ts +8 -0
- package/dist/service/keyword-optimization-service.d.ts +44 -0
- package/dist/service/phase3-input-filter.d.ts +73 -0
- package/dist/service/queue-io.d.ts +30 -0
- package/dist/service/queue-migration.d.ts +84 -0
- package/dist/service/runtime-summary-service.d.ts +156 -0
- package/dist/service/subagent-workflow/subagent-error-utils.d.ts +8 -0
- package/dist/service/subagent-workflow/types.d.ts +264 -0
- package/dist/service/subagent-workflow/workflow-store.d.ts +44 -0
- package/dist/service/trajectory-service.d.ts +2 -0
- package/dist/service/workflow-watchdog.d.ts +23 -0
- package/dist/types/event-types.d.ts +2 -0
- package/dist/types/hygiene-types.d.ts +2 -0
- package/dist/types/principle-tree-schema.d.ts +29 -0
- package/dist/types/queue.d.ts +2 -0
- package/dist/types/runtime-summary.d.ts +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/utils/file-lock.d.ts +68 -0
- package/dist/utils/hashing.d.ts +9 -0
- package/dist/utils/io.d.ts +11 -0
- package/dist/utils/node-vm-polyfill.d.ts +9 -0
- package/dist/utils/retry.d.ts +210 -0
- package/dist/utils/session-key.d.ts +10 -0
- package/dist/utils/workspace-resolver.d.ts +82 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PluginHookBeforePromptBuildEvent, PluginHookAgentContext, PluginHookBeforePromptBuildResult } from '../openclaw-sdk.js';
|
|
2
|
+
import type { ContextInjectionConfig } from '../types.js';
|
|
3
|
+
import type { PromptHookApi } from './prompt-types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Reset all module-level prompt state for a workspace.
|
|
6
|
+
* Intended for test isolation — call in beforeEach().
|
|
7
|
+
*/
|
|
8
|
+
export declare function resetPromptStateForTest(workspaceDir?: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* OpenClaw API Prompt Hook
|
|
11
|
+
* Constructs the system prompt injected into LLM context for Principles Disciple
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Loads context injection config from .pd/config.yaml via loadPdConfigForPlugin.
|
|
15
|
+
* The resolved config is computed by the core config layer (pd-config-effective.ts),
|
|
16
|
+
* which merges user partial input with DEFAULT_CONTEXT_INJECTION defaults.
|
|
17
|
+
* @internal Used by evolution engine for context settings
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadContextInjectionConfig(workspaceDir: string): ContextInjectionConfig;
|
|
20
|
+
export declare function handleBeforePromptBuild(event: PluginHookBeforePromptBuildEvent, ctx: PluginHookAgentContext & {
|
|
21
|
+
api?: PromptHookApi;
|
|
22
|
+
}): Promise<PluginHookBeforePromptBuildResult | void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw Observation Adapter — PRI-362 / PRI-446
|
|
3
|
+
*
|
|
4
|
+
* The source-kind resolution logic and RawObservation builders have been
|
|
5
|
+
* migrated to principles-core (runtime-v2/evidence-triage/observation-resolver.ts).
|
|
6
|
+
*
|
|
7
|
+
* This file is now a thin re-export adapter. It preserves the original export
|
|
8
|
+
* names (resolveSourceKind, buildToolFailureObservation, buildLlmDetectionObservation,
|
|
9
|
+
* RawObservation) so all existing import sites and the source-string
|
|
10
|
+
* characterization tests keep working without changes.
|
|
11
|
+
*
|
|
12
|
+
* ERR checklist:
|
|
13
|
+
* - ERR-011: re-export adapter, not a local re-definition of migrated logic.
|
|
14
|
+
*/
|
|
15
|
+
export { resolveSourceKind, buildToolFailureObservation, buildLlmDetectionObservation, buildEmpathyObservation, buildManualPainObservation, } from '@principles/core/runtime-v2';
|
|
16
|
+
export type { RawObservation } from './raw-observation-types.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw Observation Types — PRI-362 / PRI-446
|
|
3
|
+
*
|
|
4
|
+
* The RawObservation type has been migrated to principles-core
|
|
5
|
+
* (runtime-v2/evidence-triage/observation-resolver.ts). This file re-exports it
|
|
6
|
+
* so existing plugin import sites keep working unchanged.
|
|
7
|
+
*
|
|
8
|
+
* ERR checklist:
|
|
9
|
+
* - ERR-011: this is a re-export adapter, not a local re-definition.
|
|
10
|
+
*/
|
|
11
|
+
export type { RawObservation } from '@principles/core/runtime-v2';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trajectory Collector - message write trajectory recording
|
|
3
|
+
*
|
|
4
|
+
* Fallback trajectory collection when llm_output is blocked by missing
|
|
5
|
+
* allowConversationAccess. before_message_write is NOT in
|
|
6
|
+
* CONVERSATION_HOOK_NAMES so OpenClaw always delivers it.
|
|
7
|
+
*
|
|
8
|
+
* SQLite writes are enqueued to an async queue because before_message_write is
|
|
9
|
+
* a SYNCHRONOUS OpenClaw hook — the handler must return immediately. better-sqlite3
|
|
10
|
+
* is synchronous, so calling it directly would block the message-write main path.
|
|
11
|
+
* Trade-off: in degradation mode the last few queued writes may be lost on
|
|
12
|
+
* process exit; this is acceptable because degradation mode is already caused
|
|
13
|
+
* by a config problem (missing allowConversationAccess), and the primary
|
|
14
|
+
* llm_output path is authoritative when authorized.
|
|
15
|
+
*
|
|
16
|
+
* JSONL writing was removed (no consumers — verified zero readers across the
|
|
17
|
+
* codebase; PRI-347 already removed tool_call/llm_output JSONL writers).
|
|
18
|
+
*
|
|
19
|
+
* ERR-002: fallback errors are logged, never silent.
|
|
20
|
+
* ERR-001/005: content is sanitized before persisting.
|
|
21
|
+
*/
|
|
22
|
+
import type { PluginHookAgentContext, PluginHookBeforeMessageWriteEvent } from '../openclaw-sdk.js';
|
|
23
|
+
/**
|
|
24
|
+
* PRI-346: Message write hook with SQLite fallback trajectory recording.
|
|
25
|
+
*
|
|
26
|
+
* When allowConversationAccess is NOT set (unauthorized), llm_output is silently
|
|
27
|
+
* blocked by OpenClaw and trajectory.db has no data. This hook is NOT in
|
|
28
|
+
* CONVERSATION_HOOK_NAMES, so it always fires — making it the natural fallback.
|
|
29
|
+
*
|
|
30
|
+
* De-duplication: only writes to SQLite when llm_output is blocked (unauthorized).
|
|
31
|
+
* When llm_output is working (authorized), this hook is a no-op.
|
|
32
|
+
*
|
|
33
|
+
* SQLite writes are async-queued (see file header) to avoid blocking the sync hook.
|
|
34
|
+
*
|
|
35
|
+
* ERR-002: structured observability when fallback fires.
|
|
36
|
+
* ERR-001/005: content is sanitized before persisting.
|
|
37
|
+
*/
|
|
38
|
+
export declare function handleBeforeMessageWrite(event: PluginHookBeforeMessageWriteEvent, ctx: PluginHookAgentContext & {
|
|
39
|
+
workspaceDir?: string;
|
|
40
|
+
pluginConfig?: unknown;
|
|
41
|
+
}): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trajectory Evidence Builder — PRI-326
|
|
3
|
+
*
|
|
4
|
+
* Extracted from pain.ts to avoid circular imports between
|
|
5
|
+
* pain.ts and after-tool-call-helpers.ts.
|
|
6
|
+
*
|
|
7
|
+
* Pure data extraction — reads from trajectory DB, sanitizes, returns evidence entries.
|
|
8
|
+
*/
|
|
9
|
+
import type { PainEvidenceEntry } from '@principles/core/runtime-v2';
|
|
10
|
+
import type { WorkspaceContext } from '../core/workspace-context.js';
|
|
11
|
+
export declare function buildTrajectoryEvidence(wctx: WorkspaceContext, sessionId: string): PainEvidenceEntry[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Triage Adapter — PEAT-B1
|
|
3
|
+
*
|
|
4
|
+
* Plugin-side adapter that maps OpenClaw hook context to evidence triage input.
|
|
5
|
+
* Calls the pure triage policy from principles-core.
|
|
6
|
+
*
|
|
7
|
+
* This file lives in openclaw-plugin because it:
|
|
8
|
+
* - Maps hook-specific context (source strings, session state) to SourceKind
|
|
9
|
+
* - Wraps evaluatePainDiagnosticGate as a compatibility sub-policy
|
|
10
|
+
* - Knows about OpenClaw hook conventions (sessionId, toolName, etc.)
|
|
11
|
+
*
|
|
12
|
+
* It does NOT expose evaluatePainDiagnosticGate to core.
|
|
13
|
+
* Core only sees SourceKind and TriageResult.
|
|
14
|
+
*
|
|
15
|
+
* ERR checklist:
|
|
16
|
+
* - ERR-001: Source kind derived from runtime values with guards, not `as` casts.
|
|
17
|
+
* - ERR-002: Every triage result carries reason + nextAction.
|
|
18
|
+
* - ERR-024/025/048: Production-path tests cover this adapter.
|
|
19
|
+
*/
|
|
20
|
+
import { type TriageResult, type SourceKind } from '@principles/core/runtime-v2';
|
|
21
|
+
/**
|
|
22
|
+
* Map RawObservation to SourceKind.
|
|
23
|
+
*
|
|
24
|
+
* This is the unified entry point for source-kind classification.
|
|
25
|
+
* It replaces the scattered resolveSourceKindFrom* functions.
|
|
26
|
+
*
|
|
27
|
+
* PRI-360 S1: All source-kind resolution now goes through this single entry point.
|
|
28
|
+
*/
|
|
29
|
+
export { resolveSourceKind, buildToolFailureObservation, buildLlmDetectionObservation, type RawObservation } from './raw-observation-adapter.js';
|
|
30
|
+
/**
|
|
31
|
+
* Evaluate evidence triage for a given source kind and context.
|
|
32
|
+
*
|
|
33
|
+
* This is the main entry point for hooks. It calls the pure triage policy
|
|
34
|
+
* from principles-core and returns the result.
|
|
35
|
+
*
|
|
36
|
+
* The caller (hook) is responsible for:
|
|
37
|
+
* - Checking the painEvidenceAdmission feature flag
|
|
38
|
+
* - Acting on the triage result (proceed to diagnosis, store evidence, etc.)
|
|
39
|
+
* - Falling back to existing behavior when the flag is off
|
|
40
|
+
*/
|
|
41
|
+
export declare function evaluateEvidenceTriage(sourceKind: SourceKind, score: number, options?: {
|
|
42
|
+
isUnsafeHighConfidence?: boolean;
|
|
43
|
+
provenance?: 'openclaw_context_bound' | 'owner_reported_no_host_trace' | 'automatic_hook';
|
|
44
|
+
consecutiveErrors?: number;
|
|
45
|
+
isRisky?: boolean;
|
|
46
|
+
}): TriageResult;
|
|
47
|
+
/**
|
|
48
|
+
* Determine if a gate-blocked action is a high-confidence unsafe action.
|
|
49
|
+
*
|
|
50
|
+
* This is a heuristic that the plugin adapter owns. Core does not know about
|
|
51
|
+
* these heuristics — it only receives the boolean flag.
|
|
52
|
+
*
|
|
53
|
+
* Criteria for high-confidence unsafe:
|
|
54
|
+
* - Score >= 70 (high severity)
|
|
55
|
+
* - Tool is in the risky write set
|
|
56
|
+
* - Action would be irreversible (file deletion, force push, etc.)
|
|
57
|
+
*/
|
|
58
|
+
export declare function isHighConfidenceUnsafeAction(score: number, isRisky: boolean): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trigger Cooldown Tracker — PRI-363
|
|
3
|
+
*
|
|
4
|
+
* Manages cooldown state for trigger controller decisions.
|
|
5
|
+
*
|
|
6
|
+
* This is a plugin-layer concern because:
|
|
7
|
+
* - Core (trigger-controller) is stateless and pure
|
|
8
|
+
* - Cooldown state needs to persist across tool calls
|
|
9
|
+
* - The map is scoped to the plugin's lifecycle
|
|
10
|
+
*
|
|
11
|
+
* EP-05: Loop State Freshness — each check reads fresh state from the map.
|
|
12
|
+
* ERR-001: No `as` casts on map access.
|
|
13
|
+
* ERR-002: Every rejected decision includes reason + nextAction.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Check whether cooldown is currently active for a given episode.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isCooldownActive(source: string, sessionId: string | undefined, errorHash: string | undefined, cooldownMap: ReadonlyMap<string, number>): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Mark an episode as diagnosed (set cooldown timestamp).
|
|
21
|
+
*/
|
|
22
|
+
export declare function markEpisodeAsDiagnosed(source: string, sessionId: string | undefined, errorHash: string | undefined, cooldownMap: Map<string, number>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Clear all cooldown state (for tests).
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearCooldownState(cooldownMap: Map<string, number>): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get the cooldown timestamp for a given episode (for tests).
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCooldownTimestamp(source: string, sessionId: string | undefined, errorHash: string | undefined, cooldownMap: ReadonlyMap<string, number>): number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Check whether cooldown is currently active using the shared Map.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isSharedCooldownActive(source: string, sessionId: string | undefined, errorHash: string | undefined): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Mark an episode as diagnosed using the shared Map.
|
|
37
|
+
*/
|
|
38
|
+
export declare function markSharedEpisodeAsDiagnosed(source: string, sessionId: string | undefined, errorHash: string | undefined): void;
|
|
39
|
+
/**
|
|
40
|
+
* Clear all shared cooldown state (for tests).
|
|
41
|
+
*/
|
|
42
|
+
export declare function resetSharedCooldownForTest(): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command internationalization module.
|
|
3
|
+
* Provides localized descriptions for all plugin commands.
|
|
4
|
+
*/
|
|
5
|
+
export type SupportedLanguage = 'zh' | 'en';
|
|
6
|
+
/**
|
|
7
|
+
* Normalize language code to supported language.
|
|
8
|
+
* Handles variants like zh-CN, zh-TW, en-US, etc.
|
|
9
|
+
* @param lang - Language code (e.g., 'zh-CN', 'en-US', 'zh', 'en')
|
|
10
|
+
* @returns Normalized language ('zh' or 'en')
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeLanguage(lang: string): SupportedLanguage;
|
|
13
|
+
export declare const commandDescriptions: Record<string, Record<SupportedLanguage, string>>;
|
|
14
|
+
/**
|
|
15
|
+
* Get localized command description.
|
|
16
|
+
* @param name - Command name (e.g., 'pd-init')
|
|
17
|
+
* @param lang - Language code (e.g., 'zh-CN', 'en-US', 'zh', 'en')
|
|
18
|
+
* @returns Localized description or fallback to English then command name
|
|
19
|
+
*/
|
|
20
|
+
export declare function getCommandDescription(name: string, lang: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Get all command descriptions for a language.
|
|
23
|
+
* @param lang - Language code (e.g., 'zh-CN', 'en-US', 'zh', 'en')
|
|
24
|
+
* @returns Object mapping command names to descriptions
|
|
25
|
+
*/
|
|
26
|
+
export declare function getAllCommandDescriptions(lang: string): Record<string, string>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { OpenClawPluginApi } from './openclaw-sdk.js';
|
|
2
|
+
export { checkConversationAccessConfig, getPluginEntry, ensureConversationAccessInConfig } from './core/config-health.js';
|
|
3
|
+
export type { ConversationAccessCheckResult } from './core/config-health.js';
|
|
4
|
+
declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* PRI-305/PRI-307: Load feature flag from .pd/config.yaml instead of .pd/feature-flags.yaml.
|
|
7
|
+
* Delegates to the shared plugin config loader for consistency.
|
|
8
|
+
*/
|
|
9
|
+
declare function loadFeatureFlagFromWorkspace(workspaceDir: string, flagId: string, logger?: {
|
|
10
|
+
warn?: (msg: string) => void;
|
|
11
|
+
info?: (msg: string) => void;
|
|
12
|
+
}): {
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
source: string;
|
|
15
|
+
};
|
|
16
|
+
export interface EvolutionWorkerGateResult {
|
|
17
|
+
shouldStart: boolean;
|
|
18
|
+
flagSource: string;
|
|
19
|
+
disabledInfo: string | null;
|
|
20
|
+
}
|
|
21
|
+
export declare function shouldStartEvolutionWorker(workspaceDir: string, logger: {
|
|
22
|
+
info?: (msg: string) => void;
|
|
23
|
+
warn?: (msg: string) => void;
|
|
24
|
+
}): EvolutionWorkerGateResult;
|
|
25
|
+
export interface CorrectionObserverGateResult {
|
|
26
|
+
shouldStart: boolean;
|
|
27
|
+
flagSource: string;
|
|
28
|
+
disabledInfo: string | null;
|
|
29
|
+
}
|
|
30
|
+
export declare function shouldStartCorrectionObserver(workspaceDir: string, logger: {
|
|
31
|
+
info?: (msg: string) => void;
|
|
32
|
+
warn?: (msg: string) => void;
|
|
33
|
+
}): CorrectionObserverGateResult;
|
|
34
|
+
export interface InternalizationAutoConsumerGateResult {
|
|
35
|
+
shouldStart: boolean;
|
|
36
|
+
flagSource: string;
|
|
37
|
+
disabledInfo: string | null;
|
|
38
|
+
}
|
|
39
|
+
export declare function shouldStartInternalizationAutoConsumer(workspaceDir: string, logger: {
|
|
40
|
+
info?: (msg: string) => void;
|
|
41
|
+
warn?: (msg: string) => void;
|
|
42
|
+
}): InternalizationAutoConsumerGateResult;
|
|
43
|
+
declare const plugin: {
|
|
44
|
+
name: string;
|
|
45
|
+
description: string;
|
|
46
|
+
register(api: OpenClawPluginApi): void;
|
|
47
|
+
};
|
|
48
|
+
export { PrincipleTreeLedgerAdapter } from '@principles/core/runtime-v2';
|
|
49
|
+
export { loadFeatureFlagFromWorkspace, isRecord };
|
|
50
|
+
export { initTrajectorySchema } from './core/trajectory.js';
|
|
51
|
+
export { initWorkflowSchema } from './service/subagent-workflow/workflow-store.js';
|
|
52
|
+
export default plugin;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
export interface TokenUsage {
|
|
2
|
+
input?: number;
|
|
3
|
+
output?: number;
|
|
4
|
+
cacheRead?: number;
|
|
5
|
+
cacheWrite?: number;
|
|
6
|
+
total?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface PluginLogger {
|
|
9
|
+
debug: (...args: unknown[]) => void;
|
|
10
|
+
info: (...args: unknown[]) => void;
|
|
11
|
+
warn: (...args: unknown[]) => void;
|
|
12
|
+
error: (...args: unknown[]) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface AgentTool {
|
|
15
|
+
name: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
parameters?: unknown;
|
|
18
|
+
result?: unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface SubagentRunParams {
|
|
21
|
+
agentId: string;
|
|
22
|
+
prompt: string;
|
|
23
|
+
context?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
export interface SubagentRunResult {
|
|
26
|
+
runId: string;
|
|
27
|
+
}
|
|
28
|
+
export interface SubagentWaitResult {
|
|
29
|
+
status: 'ok' | 'error' | 'timeout';
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SubagentGetSessionMessagesResult {
|
|
33
|
+
messages: unknown[];
|
|
34
|
+
assistantTexts?: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface PluginRuntime {
|
|
37
|
+
state: Record<string, unknown>;
|
|
38
|
+
config?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface PluginCommandContext {
|
|
41
|
+
sessionId: string;
|
|
42
|
+
sessionKey: string;
|
|
43
|
+
agentId?: string;
|
|
44
|
+
workspaceDir?: string;
|
|
45
|
+
config?: Record<string, unknown>;
|
|
46
|
+
args?: string | string[];
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
export interface PluginCommandResult {
|
|
50
|
+
text?: string;
|
|
51
|
+
content?: string;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
export interface PluginCommandDefinition {
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
acceptsArgs?: boolean;
|
|
58
|
+
requireAuth?: boolean;
|
|
59
|
+
handler: (ctx: PluginCommandContext) => PluginCommandResult | Promise<PluginCommandResult>;
|
|
60
|
+
}
|
|
61
|
+
export interface OpenClawPluginService {
|
|
62
|
+
id: string;
|
|
63
|
+
start?: (ctx: OpenClawPluginServiceContext) => void | Promise<void>;
|
|
64
|
+
stop?: (ctx: OpenClawPluginServiceContext) => void | Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export interface OpenClawPluginApi {
|
|
67
|
+
id: string;
|
|
68
|
+
rootDir?: string;
|
|
69
|
+
pluginConfig?: Record<string, unknown>;
|
|
70
|
+
logger: PluginLogger;
|
|
71
|
+
config?: Record<string, unknown>;
|
|
72
|
+
runtime?: {
|
|
73
|
+
agent?: {
|
|
74
|
+
run?: (opts: {
|
|
75
|
+
sessionKey: string;
|
|
76
|
+
message: string;
|
|
77
|
+
lane?: string;
|
|
78
|
+
deliver?: boolean;
|
|
79
|
+
idempotencyKey?: string;
|
|
80
|
+
expectsCompletionMessage?: boolean;
|
|
81
|
+
extraSystemPrompt?: string;
|
|
82
|
+
}) => Promise<SubagentRunResult>;
|
|
83
|
+
resolveAgentWorkspaceDir?: (config: unknown, agentId: string) => string;
|
|
84
|
+
runEmbeddedPiAgent?: (_opts: {
|
|
85
|
+
sessionId: string;
|
|
86
|
+
sessionFile: string;
|
|
87
|
+
prompt: string;
|
|
88
|
+
extraSystemPrompt?: string;
|
|
89
|
+
config?: unknown;
|
|
90
|
+
provider?: string;
|
|
91
|
+
model?: string;
|
|
92
|
+
timeoutMs: number;
|
|
93
|
+
runId: string;
|
|
94
|
+
disableTools?: boolean;
|
|
95
|
+
}) => Promise<unknown>;
|
|
96
|
+
session?: {
|
|
97
|
+
resolveStorePath: () => string;
|
|
98
|
+
/** Row-scoped read (replaces deprecated loadSessionStore whole-store reads). */
|
|
99
|
+
getSessionEntry?: (params: {
|
|
100
|
+
sessionKey: string;
|
|
101
|
+
agentId?: string;
|
|
102
|
+
storePath?: string;
|
|
103
|
+
}) => Record<string, unknown> | undefined;
|
|
104
|
+
/** Row-scoped write (replaces deprecated saveSessionStore whole-store writes). */
|
|
105
|
+
patchSessionEntry?: (params: {
|
|
106
|
+
sessionKey: string;
|
|
107
|
+
agentId?: string;
|
|
108
|
+
storePath?: string;
|
|
109
|
+
replaceEntry?: boolean;
|
|
110
|
+
preserveActivity?: boolean;
|
|
111
|
+
update: (entry: Record<string, unknown>, context: {
|
|
112
|
+
existingEntry?: Record<string, unknown>;
|
|
113
|
+
}) => Promise<Partial<Record<string, unknown>> | null> | Partial<Record<string, unknown>> | null;
|
|
114
|
+
}) => Promise<Record<string, unknown> | null>;
|
|
115
|
+
/** Row-scoped upsert (replaces deprecated saveSessionStore whole-store writes). */
|
|
116
|
+
upsertSessionEntry?: (params: {
|
|
117
|
+
sessionKey: string;
|
|
118
|
+
agentId?: string;
|
|
119
|
+
storePath?: string;
|
|
120
|
+
entry: Record<string, unknown>;
|
|
121
|
+
}) => Promise<void>;
|
|
122
|
+
/** @deprecated Use getSessionEntry for reads. Kept for compat with older OpenClaw hosts. */
|
|
123
|
+
loadSessionStore: (storePath: string, opts?: {
|
|
124
|
+
skipCache?: boolean;
|
|
125
|
+
}) => Record<string, unknown>;
|
|
126
|
+
/** @deprecated Use patchSessionEntry/upsertSessionEntry for writes. Kept for compat with older OpenClaw hosts. */
|
|
127
|
+
saveSessionStore: (storePath: string, store: Record<string, unknown>) => Promise<void>;
|
|
128
|
+
resolveSessionFilePath: (sessionKey: string) => string;
|
|
129
|
+
config?: unknown;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
subagent?: {
|
|
133
|
+
run: (params: {
|
|
134
|
+
sessionKey: string;
|
|
135
|
+
message: string;
|
|
136
|
+
lane?: string;
|
|
137
|
+
deliver?: boolean;
|
|
138
|
+
idempotencyKey?: string;
|
|
139
|
+
expectsCompletionMessage?: boolean;
|
|
140
|
+
extraSystemPrompt?: string;
|
|
141
|
+
}) => Promise<SubagentRunResult>;
|
|
142
|
+
waitForRun: (params: {
|
|
143
|
+
runId: string;
|
|
144
|
+
timeoutMs?: number;
|
|
145
|
+
}) => Promise<SubagentWaitResult>;
|
|
146
|
+
getSessionMessages: (params: {
|
|
147
|
+
sessionKey: string;
|
|
148
|
+
limit?: number;
|
|
149
|
+
}) => Promise<SubagentGetSessionMessagesResult>;
|
|
150
|
+
deleteSession: (params: {
|
|
151
|
+
sessionKey: string;
|
|
152
|
+
deleteTranscript?: boolean;
|
|
153
|
+
}) => Promise<void>;
|
|
154
|
+
};
|
|
155
|
+
system?: {
|
|
156
|
+
runHeartbeatOnce?: (opts?: {
|
|
157
|
+
reason?: string;
|
|
158
|
+
}) => Promise<{
|
|
159
|
+
status: 'ran' | 'skipped' | 'failed';
|
|
160
|
+
durationMs?: number;
|
|
161
|
+
reason?: string;
|
|
162
|
+
}>;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
registerCommand: (cmd: PluginCommandDefinition) => void;
|
|
166
|
+
registerService: (service: OpenClawPluginService) => void;
|
|
167
|
+
registerTool: (tool: AgentTool) => void;
|
|
168
|
+
registerHttpRoute: (route: {
|
|
169
|
+
path: string;
|
|
170
|
+
auth?: 'plugin' | 'gateway';
|
|
171
|
+
match?: 'prefix' | 'exact';
|
|
172
|
+
handler: (req: unknown, res: {
|
|
173
|
+
json: (data: unknown) => void;
|
|
174
|
+
status: (code: number) => {
|
|
175
|
+
json: (data: unknown) => void;
|
|
176
|
+
};
|
|
177
|
+
text: (content: string, code?: number) => void;
|
|
178
|
+
}) => boolean | Promise<boolean>;
|
|
179
|
+
}) => void;
|
|
180
|
+
on: (event: string, handler: (...args: any[]) => unknown, opts?: {
|
|
181
|
+
priority?: number;
|
|
182
|
+
timeoutMs?: number;
|
|
183
|
+
}) => void;
|
|
184
|
+
}
|
|
185
|
+
export interface PluginHookBeforePromptBuildEvent {
|
|
186
|
+
prompt: string;
|
|
187
|
+
messages: unknown[];
|
|
188
|
+
}
|
|
189
|
+
export interface PluginHookBeforePromptBuildResult {
|
|
190
|
+
systemPrompt?: string;
|
|
191
|
+
prependContext?: string;
|
|
192
|
+
appendContext?: string;
|
|
193
|
+
prependSystemContext?: string;
|
|
194
|
+
appendSystemContext?: string;
|
|
195
|
+
}
|
|
196
|
+
export interface PluginHookBeforeToolCallEvent {
|
|
197
|
+
toolName: string;
|
|
198
|
+
params?: Record<string, unknown>;
|
|
199
|
+
toolArgs?: Record<string, unknown>;
|
|
200
|
+
agentId?: string;
|
|
201
|
+
sessionId?: string;
|
|
202
|
+
[key: string]: unknown;
|
|
203
|
+
}
|
|
204
|
+
export interface PluginHookBeforeToolCallResult {
|
|
205
|
+
toolArgs?: Record<string, unknown>;
|
|
206
|
+
skipToolCall?: boolean;
|
|
207
|
+
[key: string]: unknown;
|
|
208
|
+
}
|
|
209
|
+
export interface PluginHookToolContext {
|
|
210
|
+
agentId?: string;
|
|
211
|
+
sessionId?: string;
|
|
212
|
+
workspaceDir?: string;
|
|
213
|
+
logger?: Partial<PluginLogger>;
|
|
214
|
+
[key: string]: unknown;
|
|
215
|
+
}
|
|
216
|
+
export interface PluginHookAfterToolCallEvent {
|
|
217
|
+
toolName: string;
|
|
218
|
+
toolArgs?: Record<string, unknown>;
|
|
219
|
+
result?: unknown;
|
|
220
|
+
error?: unknown;
|
|
221
|
+
agentId?: string;
|
|
222
|
+
sessionId?: string;
|
|
223
|
+
durationMs?: number;
|
|
224
|
+
[key: string]: unknown;
|
|
225
|
+
}
|
|
226
|
+
export interface PluginHookBeforeResetEvent {
|
|
227
|
+
agentId?: string;
|
|
228
|
+
sessionId?: string;
|
|
229
|
+
messages?: unknown[];
|
|
230
|
+
reason?: string;
|
|
231
|
+
[key: string]: unknown;
|
|
232
|
+
}
|
|
233
|
+
export interface PluginHookBeforeCompactionEvent {
|
|
234
|
+
agentId?: string;
|
|
235
|
+
sessionId?: string;
|
|
236
|
+
[key: string]: unknown;
|
|
237
|
+
}
|
|
238
|
+
export interface PluginHookAfterCompactionEvent {
|
|
239
|
+
agentId?: string;
|
|
240
|
+
sessionId?: string;
|
|
241
|
+
sessionFile?: string;
|
|
242
|
+
messageCount?: number;
|
|
243
|
+
[key: string]: unknown;
|
|
244
|
+
}
|
|
245
|
+
export interface PluginHookSubagentEndedEvent {
|
|
246
|
+
targetSessionKey: string;
|
|
247
|
+
outcome: 'ok' | 'error' | 'timeout' | 'escalated' | 'deleted' | 'killed' | 'reset';
|
|
248
|
+
agentId?: string;
|
|
249
|
+
sessionId?: string;
|
|
250
|
+
[key: string]: unknown;
|
|
251
|
+
}
|
|
252
|
+
export interface PluginHookLlmOutputEvent {
|
|
253
|
+
output: string;
|
|
254
|
+
agentId?: string;
|
|
255
|
+
sessionId?: string;
|
|
256
|
+
runId?: string;
|
|
257
|
+
provider?: string;
|
|
258
|
+
model?: string;
|
|
259
|
+
usage?: TokenUsage;
|
|
260
|
+
assistantTexts?: string[];
|
|
261
|
+
trigger?: string;
|
|
262
|
+
lastAssistant?: unknown;
|
|
263
|
+
[key: string]: unknown;
|
|
264
|
+
}
|
|
265
|
+
export interface PluginHookSubagentSpawningEvent {
|
|
266
|
+
agentId: string;
|
|
267
|
+
childSessionKey: string;
|
|
268
|
+
sessionId?: string;
|
|
269
|
+
[key: string]: unknown;
|
|
270
|
+
}
|
|
271
|
+
export interface PluginHookSubagentSpawningResult {
|
|
272
|
+
status: 'ok' | 'error';
|
|
273
|
+
[key: string]: unknown;
|
|
274
|
+
}
|
|
275
|
+
export interface PluginHookSubagentContext {
|
|
276
|
+
agentId?: string;
|
|
277
|
+
sessionId?: string;
|
|
278
|
+
[key: string]: unknown;
|
|
279
|
+
}
|
|
280
|
+
export interface PluginHookAgentContext {
|
|
281
|
+
runId?: string;
|
|
282
|
+
jobId?: string;
|
|
283
|
+
trace?: unknown;
|
|
284
|
+
agentId?: string;
|
|
285
|
+
sessionKey?: string;
|
|
286
|
+
sessionId?: string;
|
|
287
|
+
workspaceDir?: string;
|
|
288
|
+
modelProviderId?: string;
|
|
289
|
+
modelId?: string;
|
|
290
|
+
messageProvider?: string;
|
|
291
|
+
channel?: string;
|
|
292
|
+
chatId?: string;
|
|
293
|
+
senderId?: string;
|
|
294
|
+
trigger?: string;
|
|
295
|
+
channelId?: string;
|
|
296
|
+
contextTokenBudget?: number;
|
|
297
|
+
contextWindowSource?: 'model' | 'config';
|
|
298
|
+
contextWindowReferenceTokens?: number;
|
|
299
|
+
senderExternalId?: string;
|
|
300
|
+
channelContext?: unknown;
|
|
301
|
+
logger?: Partial<PluginLogger>;
|
|
302
|
+
}
|
|
303
|
+
export interface PluginHookBeforeMessageWriteEvent {
|
|
304
|
+
message: {
|
|
305
|
+
role?: string;
|
|
306
|
+
content?: unknown;
|
|
307
|
+
};
|
|
308
|
+
agentId?: string;
|
|
309
|
+
sessionId?: string;
|
|
310
|
+
[key: string]: unknown;
|
|
311
|
+
}
|
|
312
|
+
export interface PluginHookBeforeMessageWriteResult {
|
|
313
|
+
message?: {
|
|
314
|
+
role?: string;
|
|
315
|
+
content?: unknown;
|
|
316
|
+
};
|
|
317
|
+
[key: string]: unknown;
|
|
318
|
+
}
|
|
319
|
+
export interface OpenClawPluginHttpRouteParams {
|
|
320
|
+
path: string;
|
|
321
|
+
auth?: 'plugin' | 'gateway';
|
|
322
|
+
match?: 'prefix' | 'exact';
|
|
323
|
+
handler: (req: unknown, res: {
|
|
324
|
+
json: (data: unknown) => void;
|
|
325
|
+
status: (code: number) => {
|
|
326
|
+
json: (data: unknown) => void;
|
|
327
|
+
};
|
|
328
|
+
text: (content: string, code?: number) => void;
|
|
329
|
+
}) => boolean | Promise<boolean>;
|
|
330
|
+
}
|
|
331
|
+
export interface OpenClawPluginServiceContext {
|
|
332
|
+
api?: OpenClawPluginApi;
|
|
333
|
+
workspaceDir?: string;
|
|
334
|
+
logger?: PluginLogger;
|
|
335
|
+
config?: Record<string, unknown>;
|
|
336
|
+
[key: string]: unknown;
|
|
337
|
+
}
|
|
338
|
+
export {};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "principles-disciple",
|
|
3
3
|
"name": "Principles Disciple",
|
|
4
4
|
"description": "Turn repeated Agent corrections into Owner-approved, observable, reversible behavior principles. Stop correcting the same AI behavior across sessions.",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.202.0",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onCapabilities": [
|
|
8
8
|
"hook"
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Side-effect-free public boundary for RuleHost evidence assembly. */
|
|
2
|
+
export { BehaviorExamplePackAssembler } from './core/behavior-example-pack-assembler.js';
|
|
3
|
+
export type { BehaviorExamplePackAssemblerInput, BehaviorExamplePackAssemblerOptions, } from './core/behavior-example-pack-assembler.js';
|
|
4
|
+
export { TrajectoryRegistry as RuleHostEvidenceRegistry } from './core/trajectory.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { OpenClawPluginServiceContext, PluginLogger } from '../openclaw-sdk.js';
|
|
2
|
+
import { WorkspaceContext } from '../core/workspace-context.js';
|
|
3
|
+
import { CorrectionObserver } from '@principles/core/runtime-v2';
|
|
4
|
+
export interface CorrectionObserverServiceShape {
|
|
5
|
+
id: string;
|
|
6
|
+
start: (ctx: OpenClawPluginServiceContext) => void;
|
|
7
|
+
stop?: (ctx: OpenClawPluginServiceContext) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* PRI-307: Resolve CorrectionObserver from .pd/config.yaml.
|
|
11
|
+
*
|
|
12
|
+
* States:
|
|
13
|
+
* - disabled: feature flag off → return null, no noisy logs
|
|
14
|
+
* - needs_setup: enabled but missing API key or profile → return null with structured reason
|
|
15
|
+
* - ready/not_ready: enabled and configured → return observer instance
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveCorrectionObserver(wctx: WorkspaceContext, logger?: Pick<PluginLogger, 'info' | 'warn' | 'error' | 'debug'>): CorrectionObserver | null;
|
|
18
|
+
export declare function runCorrectionObserverCycle(wctx: WorkspaceContext, logger: PluginLogger): Promise<void>;
|
|
19
|
+
export declare const CorrectionObserverService: CorrectionObserverServiceShape;
|