create-principles-disciple 1.104.2 → 1.105.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.
Files changed (71) hide show
  1. package/core/dist/host/__tests__/host-adapter.test.js +12 -0
  2. package/core/dist/host/__tests__/host-adapter.test.js.map +1 -1
  3. package/core/dist/host/host-adapter.d.ts +4 -0
  4. package/core/dist/host/host-adapter.d.ts.map +1 -1
  5. package/core/dist/host/host-adapter.js +7 -0
  6. package/core/dist/host/host-adapter.js.map +1 -1
  7. package/core/dist/runtime-v2/__tests__/evidence-sanitizer.test.js +28 -0
  8. package/core/dist/runtime-v2/__tests__/evidence-sanitizer.test.js.map +1 -1
  9. package/core/dist/runtime-v2/__tests__/sqlite-connection-readonly.test.js +18 -0
  10. package/core/dist/runtime-v2/__tests__/sqlite-connection-readonly.test.js.map +1 -1
  11. package/core/dist/runtime-v2/evidence-sanitizer.d.ts.map +1 -1
  12. package/core/dist/runtime-v2/evidence-sanitizer.js +17 -1
  13. package/core/dist/runtime-v2/evidence-sanitizer.js.map +1 -1
  14. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +15 -0
  15. package/core/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
  16. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js +1 -1
  17. package/core/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  18. package/core/dist/runtime-v2/store/sqlite-connection.d.ts +3 -0
  19. package/core/dist/runtime-v2/store/sqlite-connection.d.ts.map +1 -1
  20. package/core/dist/runtime-v2/store/sqlite-connection.js +6 -3
  21. package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
  22. package/dist/installer.d.ts.map +1 -1
  23. package/dist/installer.js +52 -2
  24. package/dist/installer.js.map +1 -1
  25. package/dist/installers/codex-host-installer.d.ts +14 -0
  26. package/dist/installers/codex-host-installer.d.ts.map +1 -1
  27. package/dist/installers/codex-host-installer.js +53 -8
  28. package/dist/installers/codex-host-installer.js.map +1 -1
  29. package/dist/mvp-config.d.ts +20 -0
  30. package/dist/mvp-config.d.ts.map +1 -1
  31. package/dist/mvp-config.js +76 -0
  32. package/dist/mvp-config.js.map +1 -1
  33. package/dist/utils/config-file-io.d.ts +26 -0
  34. package/dist/utils/config-file-io.d.ts.map +1 -0
  35. package/dist/utils/config-file-io.js +128 -0
  36. package/dist/utils/config-file-io.js.map +1 -0
  37. package/host-runtime/dist/active-principle-prompt.d.ts +17 -0
  38. package/host-runtime/dist/active-principle-prompt.js +102 -0
  39. package/host-runtime/dist/index.d.ts +45 -0
  40. package/host-runtime/dist/index.js +148 -0
  41. package/host-runtime/dist/pd-config.d.ts +36 -0
  42. package/host-runtime/dist/pd-config.js +98 -0
  43. package/host-runtime/dist/production-pain-evidence.d.ts +24 -0
  44. package/host-runtime/dist/production-pain-evidence.js +293 -0
  45. package/host-runtime/dist/production-rulehost-gate.d.ts +23 -0
  46. package/host-runtime/dist/production-rulehost-gate.js +294 -0
  47. package/host-runtime/dist/rule-implementation-runtime.d.ts +25 -0
  48. package/host-runtime/dist/rule-implementation-runtime.js +114 -0
  49. package/host-runtime/package.json +37 -0
  50. package/package.json +2 -1
  51. package/pd-cli/dist/commands/health-codex.d.ts +7 -0
  52. package/pd-cli/dist/commands/health-codex.d.ts.map +1 -0
  53. package/pd-cli/dist/commands/health-codex.js +209 -0
  54. package/pd-cli/dist/commands/health-codex.js.map +1 -0
  55. package/pd-cli/dist/commands/health.d.ts +24 -0
  56. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  57. package/pd-cli/dist/commands/health.js +48 -0
  58. package/pd-cli/dist/commands/health.js.map +1 -1
  59. package/pd-cli/dist/index.js +2 -9
  60. package/pd-cli/dist/index.js.map +1 -1
  61. package/pd-cli/package.json +2 -0
  62. package/plugin/dist/bundle.js +615 -533
  63. package/plugin/dist/core/pd-config-loader.d.ts +7 -78
  64. package/plugin/dist/hooks/after-tool-call-helpers.d.ts +6 -2
  65. package/plugin/dist/hooks/gate.d.ts +29 -0
  66. package/plugin/dist/hooks/pain.d.ts +22 -0
  67. package/plugin/dist/hooks/prompt.d.ts +12 -2
  68. package/plugin/dist/host-runtime/openclaw-host-runtime.d.ts +19 -0
  69. package/plugin/dist/index.d.ts +8 -0
  70. package/plugin/openclaw.plugin.json +1 -1
  71. package/plugin/package.json +2 -1
@@ -1,96 +1,25 @@
1
- /**
2
- * PD Config Loader (Plugin I/O boundary) — PRI-307
3
- *
4
- * Reads `.pd/config.yaml`, validates via core, computes effective config.
5
- * Replaces the old `.pd/feature-flags.yaml` and `.state/workflows.yaml` reading
6
- * for plugin production paths.
7
- *
8
- * ADR-0016: PD owns exactly one user config file.
9
- * - Missing config → defaults with nextAction
10
- * - Malformed config → fail loud with errors and nextAction
11
- * - No secrets in output
12
- * - Observer disabled → no start / no noisy log cycling
13
- * - Observer enabled + missing setup → structured needs_setup + nextAction
14
- */
15
- import type { EffectivePdConfig } from '@principles/core/runtime-v2';
16
- export declare const PD_CONFIG_DIR = ".pd";
17
- export declare const PD_CONFIG_FILENAME = "config.yaml";
1
+ import { type PluginConfigLoadResult } from '@principles/host-runtime';
2
+ export { getPdConfigPath, loadFeatureFlagFromConfig, loadPdConfigForPlugin, PD_CONFIG_DIR, PD_CONFIG_FILENAME, } from '@principles/host-runtime';
3
+ export type { PluginConfigLoadResult } from '@principles/host-runtime';
18
4
  export type ObserverReadiness = 'disabled' | 'needs_setup' | 'ready' | 'not_ready' | 'config_malformed';
19
5
  export interface ObserverConfigResult {
20
- /** Whether the observer feature is enabled in config */
21
6
  enabled: boolean;
22
- /** Observer readiness state */
23
7
  readiness: ObserverReadiness;
24
- /** Config source: 'defaults' | 'user_config' | 'malformed' */
25
8
  source: string;
26
- /** Reason for current state */
27
9
  reason: string;
28
- /** What the user should do next */
29
10
  nextAction: string;
30
- /** The runtime profile ID for this observer, if configured */
31
11
  runtimeProfileId: string | null;
32
- /** The runtime profile type, if configured */
33
12
  runtimeProfileType: string | null;
34
- /** The apiKeyEnv for the runtime profile, if applicable */
35
13
  apiKeyEnv: string | null;
36
- /** Whether the apiKeyEnv is present in process.env */
37
14
  apiKeyPresent: boolean;
38
- /** Provider name from runtime profile */
39
15
  provider: string | null;
40
- /** Model name from runtime profile */
41
16
  model: string | null;
42
- /** Timeout from runtime profile */
43
17
  timeoutMs: number | null;
44
- /** Base URL from runtime profile */
45
18
  baseUrl: string | null;
46
- /** Config validation errors (only present when readiness=config_malformed) */
47
- configErrors?: Array<{
48
- path: string;
49
- reason: string;
50
- nextAction: string;
51
- }>;
19
+ configErrors?: PluginConfigLoadResult['errors'];
52
20
  }
53
- export interface PluginConfigLoadResult {
54
- ok: boolean;
55
- effective: EffectivePdConfig;
56
- source: 'defaults' | 'user_config' | 'malformed';
57
- configPath: string;
58
- warnings: string[];
59
- errors: Array<{
60
- path: string;
61
- reason: string;
62
- nextAction: string;
63
- }>;
64
- }
65
- export declare function getPdConfigPath(workspaceDir: string): string;
66
- /**
67
- * Load and validate `.pd/config.yaml` from the workspace.
68
- * Never throws on malformed input. Always provides a usable fallback.
69
- */
70
- export declare function loadPdConfigForPlugin(workspaceDir: string): PluginConfigLoadResult;
71
- /**
72
- * Get a single feature flag's enabled state from .pd/config.yaml.
73
- * Replaces the old `loadFeatureFlagFromWorkspace` which read .pd/feature-flags.yaml.
74
- */
75
- export declare function loadFeatureFlagFromConfig(workspaceDir: string, flagId: string, logger?: {
76
- warn?: (msg: string) => void;
77
- info?: (msg: string) => void;
78
- }): {
79
- enabled: boolean;
80
- source: string;
81
- };
82
- /**
83
- * Resolve observer configuration from .pd/config.yaml.
84
- *
85
- * Returns structured state:
86
- * - config_malformed: config file is invalid — no guessing, fail loud
87
- * - disabled: observer feature flag is off OR agent.enabled=false → no start, no noisy logs
88
- * - needs_setup: observer enabled but runtime profile missing, API key not set, or unsupported profile type
89
- * - ready: observer enabled and fully configured (pi-ai with key present)
90
- * - not_ready: observer enabled, API key present, but runtime availability unknown
91
- */
92
21
  export declare function resolveObserverConfig(workspaceDir: string, observerFlagId: string, observerAgentName: string, _logger?: {
93
- warn?: (msg: string) => void;
94
- info?: (msg: string) => void;
95
- debug?: (msg: string) => void;
22
+ warn?: (message: string) => void;
23
+ info?: (message: string) => void;
24
+ debug?: (message: string) => void;
96
25
  }): ObserverConfigResult;
@@ -44,13 +44,17 @@ export declare function buildToolCallObservation(event: PluginHookAfterToolCallE
44
44
  */
45
45
  export declare function handleFrictionTrackingForFailure(sessionId: string, event: PluginHookAfterToolCallEvent, outcome: ToolCallOutcome, observation: ToolCallObservation, gfiBefore: number, workspaceDir: string, config: {
46
46
  get: (key: string) => unknown;
47
- }, wctx: WorkspaceContext): SessionState;
47
+ }, wctx: WorkspaceContext, options?: {
48
+ recordTrajectory?: boolean;
49
+ }): SessionState;
48
50
  /**
49
51
  * Handle friction relief and recording for a tool success.
50
52
  *
51
53
  * Relieves both tool_failure and dispatch_error GFI sources proportionally.
52
54
  */
53
- export declare function handleFrictionTrackingForSuccess(sessionId: string, event: PluginHookAfterToolCallEvent, outcome: ToolCallOutcome, observation: ToolCallObservation, gfiBefore: number, workspaceDir: string, wctx: WorkspaceContext): SessionState;
55
+ export declare function handleFrictionTrackingForSuccess(sessionId: string, event: PluginHookAfterToolCallEvent, outcome: ToolCallOutcome, observation: ToolCallObservation, gfiBefore: number, workspaceDir: string, wctx: WorkspaceContext, options?: {
56
+ recordTrajectory?: boolean;
57
+ }): SessionState;
54
58
  /**
55
59
  * Record hygiene tracking for memory/plan persistence actions on success.
56
60
  */
@@ -8,9 +8,38 @@
8
8
  * 1. Early Return: Skip if not write/bash/agent tool or no workspace
9
9
  * 2. Rule Host: Dynamic principle-based evaluation (sole gate)
10
10
  */
11
+ import { WorkspaceContext } from '../core/workspace-context.js';
12
+ import type { RuleContextV2 } from '@principles/core/runtime-v2';
11
13
  import type { PluginHookBeforeToolCallEvent, PluginHookToolContext, PluginHookBeforeToolCallResult, PluginLogger } from '../openclaw-sdk.js';
14
+ import type { HostEventResult } from '@principles/core/host';
12
15
  export declare function handleBeforeToolCall(event: PluginHookBeforeToolCallEvent, ctx: PluginHookToolContext & {
13
16
  workspaceDir?: string;
14
17
  pluginConfig?: Record<string, unknown>;
15
18
  logger?: Partial<PluginLogger>;
16
19
  }): PluginHookBeforeToolCallResult | void;
20
+ export declare function buildOpenClawRuleInputEnrichment(event: PluginHookBeforeToolCallEvent, workspaceDir: string, sessionId: string | undefined): {
21
+ currentGfi: number;
22
+ recentThinking: boolean;
23
+ epTier: number;
24
+ bashRisk: "dangerous" | "normal" | "safe" | "unknown";
25
+ };
26
+ /**
27
+ * PRI-483 Phase 4 — Build RuleContextV2 for RuleHost.evaluate when the
28
+ * `rulecode_context_v2` feature flag is ON. Returns `undefined` when the flag
29
+ * is OFF (v1 zero-change — does NOT touch trajectory) or when config loading
30
+ * fails (conservative fail-soft: can't determine flag state → v1-style).
31
+ *
32
+ * ERR-024 prevention: context assembly failures never skip RuleHost.evaluate.
33
+ * - loadPdConfigForPlugin throws → return undefined (v1-style)
34
+ * - buildProductionRuleContext throws → return UNAVAILABLE_RULE_CONTEXT
35
+ * (structured unavailable so v2 rules see "context unavailable" and allow)
36
+ *
37
+ * Spec: docs/superpowers/specs/2026-06-27-rulecode-context-vision-design.md §5.3
38
+ */
39
+ export declare function buildRuleContextIfEnabled(wctx: WorkspaceContext, targetPath: string, sessionId: string | undefined, logger: {
40
+ warn?: (msg: string) => void;
41
+ } | undefined): RuleContextV2 | undefined;
42
+ export declare function handleSharedRuleHostResult(event: PluginHookBeforeToolCallEvent, ctx: PluginHookToolContext & {
43
+ workspaceDir: string;
44
+ logger?: Partial<PluginLogger>;
45
+ }, result: HostEventResult): void;
@@ -17,8 +17,17 @@
17
17
  import { WorkspaceContext } from '../core/workspace-context.js';
18
18
  import type { EvolutionLoopEvent } from '../core/evolution-types.js';
19
19
  import type { PluginHookAfterToolCallEvent, PluginHookToolContext, OpenClawPluginApi } from '../openclaw-sdk.js';
20
+ import type { ProductionPainEnrichment } from '@principles/host-runtime';
21
+ import type { HostEventResult } from '@principles/core/host';
20
22
  import { buildTrajectoryEvidence } from './trajectory-evidence.js';
21
23
  export { buildTrajectoryEvidence };
24
+ /**
25
+ * Host-owned best-effort continuation after durable shared persistence.
26
+ * The hook may return once SQLite commits, while rejections remain observable
27
+ * and tests/shutdown code can explicitly drain scheduled work.
28
+ */
29
+ export declare function schedulePainContinuation(workspaceDir: string, continuation: Promise<void>): void;
30
+ export declare function drainPainContinuationsForTest(): Promise<void>;
22
31
  export declare function emitPainDetectedEvent(wctx: WorkspaceContext, event: EvolutionLoopEvent, options?: {
23
32
  recordObservability?: boolean;
24
33
  }): Promise<void>;
@@ -33,3 +42,16 @@ export declare function handleAfterToolCall(event: PluginHookAfterToolCallEvent,
33
42
  workspaceDir?: string;
34
43
  pluginConfig?: Record<string, unknown>;
35
44
  }, api?: OpenClawPluginApi): void;
45
+ /**
46
+ * OpenClaw-owned enrichment for the shared ordinary after-tool kernel.
47
+ * Session/GFI, event-log, probation, PROFILE and hygiene behavior stays here;
48
+ * the shared runtime owns classification/admission and the atomic trajectory write.
49
+ */
50
+ export declare function prepareOrdinaryAfterToolCallForSharedRuntime(event: PluginHookAfterToolCallEvent, ctx: PluginHookToolContext & {
51
+ workspaceDir: string;
52
+ pluginConfig?: Record<string, unknown>;
53
+ }): ProductionPainEnrichment;
54
+ /** Restore OpenClaw-owned pain UX/diagnosis after the shared atomic evidence write. */
55
+ export declare function handleSharedPainEvidenceResult(event: PluginHookAfterToolCallEvent, ctx: PluginHookToolContext & {
56
+ workspaceDir: string;
57
+ }, result: HostEventResult): void;
@@ -1,6 +1,16 @@
1
- import type { PluginHookBeforePromptBuildEvent, PluginHookAgentContext, PluginHookBeforePromptBuildResult } from '../openclaw-sdk.js';
1
+ import type { PluginHookBeforePromptBuildEvent, PluginHookAgentContext, PluginHookBeforePromptBuildResult, PluginLogger } from '../openclaw-sdk.js';
2
+ import { WorkspaceContext } from '../core/workspace-context.js';
2
3
  import type { ContextInjectionConfig } from '../types.js';
4
+ import type { ActivePrinciplePromptResult } from '@principles/host-runtime';
3
5
  import type { PromptHookApi } from './prompt-types.js';
6
+ import type { InjectablePrinciple } from '../core/principle-injection.js';
7
+ export interface LegacyPrinciplePromptSelection {
8
+ active: InjectablePrinciple[];
9
+ probation: InjectablePrinciple[];
10
+ content: string;
11
+ selectedIds: ReadonlySet<string>;
12
+ }
13
+ export declare function selectLegacyPrinciplesForPrompt(workspaceDir: string, reducer: Pick<WorkspaceContext['evolutionReducer'], 'getActivePrinciples' | 'getProbationPrinciples'>, logger?: PluginLogger): LegacyPrinciplePromptSelection;
4
14
  /**
5
15
  * Reset all module-level prompt state for a workspace.
6
16
  * Intended for test isolation — call in beforeEach().
@@ -19,4 +29,4 @@ export declare function resetPromptStateForTest(workspaceDir?: string): void;
19
29
  export declare function loadContextInjectionConfig(workspaceDir: string): ContextInjectionConfig;
20
30
  export declare function handleBeforePromptBuild(event: PluginHookBeforePromptBuildEvent, ctx: PluginHookAgentContext & {
21
31
  api?: PromptHookApi;
22
- }): Promise<PluginHookBeforePromptBuildResult | void>;
32
+ }, sharedActivePrinciplePrompt?: ActivePrinciplePromptResult, preparedLegacyPrinciples?: LegacyPrinciplePromptSelection): Promise<PluginHookBeforePromptBuildResult | void>;
@@ -0,0 +1,19 @@
1
+ import { type ActivePrinciplePromptResult, type HostRuntime, type ProductionRuleContextRequest, type ProductionPainEnrichment } from '@principles/host-runtime';
2
+ import type { HostEventResult } from '@principles/core/host';
3
+ import type { PluginHookAgentContext, PluginHookAfterToolCallEvent, PluginHookBeforePromptBuildEvent, PluginHookBeforePromptBuildResult, PluginHookBeforeToolCallEvent, PluginHookBeforeToolCallResult, PluginHookToolContext } from '../openclaw-sdk.js';
4
+ export interface OpenClawHostRuntimeOptions {
5
+ beforePromptBuild(event: PluginHookBeforePromptBuildEvent, context: PluginHookAgentContext, prompt: ActivePrinciplePromptResult): Promise<PluginHookBeforePromptBuildResult | void>;
6
+ promptExcludePrincipleIds?(event: PluginHookBeforePromptBuildEvent, context: PluginHookAgentContext): ReadonlySet<string>;
7
+ ruleContextProvider?(event: PluginHookBeforeToolCallEvent, context: PluginHookToolContext, request: ProductionRuleContextRequest): unknown | Promise<unknown>;
8
+ ruleInputEnrichmentProvider?(event: PluginHookBeforeToolCallEvent, context: PluginHookToolContext, request: ProductionRuleContextRequest): unknown | Promise<unknown>;
9
+ onBeforeToolResult?(event: PluginHookBeforeToolCallEvent, context: PluginHookToolContext, result: HostEventResult): PluginHookBeforeToolCallResult | void;
10
+ painEnrichmentProvider?(event: PluginHookAfterToolCallEvent, context: PluginHookToolContext): ProductionPainEnrichment | Promise<ProductionPainEnrichment>;
11
+ onAfterToolResult?(event: PluginHookAfterToolCallEvent, context: PluginHookToolContext, result: HostEventResult): void | Promise<void>;
12
+ }
13
+ export interface OpenClawHostRuntime {
14
+ readonly runtime: HostRuntime;
15
+ dispatchBeforePromptBuild(event: PluginHookBeforePromptBuildEvent, context: PluginHookAgentContext): Promise<PluginHookBeforePromptBuildResult | void>;
16
+ dispatchBeforeToolCall(event: PluginHookBeforeToolCallEvent, context: PluginHookToolContext): Promise<PluginHookBeforeToolCallResult | void>;
17
+ dispatchAfterToolCall(event: PluginHookAfterToolCallEvent, context: PluginHookToolContext): Promise<void>;
18
+ }
19
+ export declare function createOpenClawHostRuntime(options: OpenClawHostRuntimeOptions): OpenClawHostRuntime;
@@ -40,6 +40,14 @@ export declare function shouldStartInternalizationAutoConsumer(workspaceDir: str
40
40
  info?: (msg: string) => void;
41
41
  warn?: (msg: string) => void;
42
42
  }): InternalizationAutoConsumerGateResult;
43
+ export declare function shouldUseSharedHostRuntime(workspaceDir: string, logger: {
44
+ info?: (msg: string) => void;
45
+ warn?: (msg: string) => void;
46
+ }): {
47
+ enabled: boolean;
48
+ source: string;
49
+ rollbackReason: string | null;
50
+ };
43
51
  declare const plugin: {
44
52
  name: string;
45
53
  description: string;
@@ -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.202.1",
5
+ "version": "1.203.0",
6
6
  "activation": {
7
7
  "onCapabilities": [
8
8
  "hook"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "principles-disciple",
3
- "version": "1.202.1",
3
+ "version": "1.203.0",
4
4
  "description": "Turn repeated Agent corrections into Owner-approved, observable, reversible behavior principles. Stop correcting the same AI behavior across sessions.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -62,6 +62,7 @@
62
62
  "test": "vitest run",
63
63
  "test:unit": "vitest run --config vitest.unit.config.ts tests/core tests/service tests/hooks tests/commands tests/utils tests/scripts --exclude tests/commands/evolver.test.ts",
64
64
  "test:integration": "vitest run tests/integration/",
65
+ "test:host-runtime-parity": "vitest run --config vitest.parity.config.ts tests/bdd/openclaw-shared-host-runtime-parity.steps.test.ts tests/package/published-host-runtime-bundle.test.ts",
65
66
  "test:coverage": "vitest run --coverage",
66
67
  "test:all": "vitest run",
67
68
  "lint": "eslint \"src/**/*.ts\"",